File: tilde-const-invalid-places.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (61 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![feature(const_trait_impl)]

#[const_trait]
trait Trait {}

// Regression test for issue #90052.
fn non_const_function<T: ~const Trait>() {} //~ ERROR `~const` is not allowed

struct Struct<T: ~const Trait> { field: T } //~ ERROR `~const` is not allowed here
struct TupleStruct<T: ~const Trait>(T); //~ ERROR `~const` is not allowed here
struct UnitStruct<T: ~const Trait>; //~ ERROR `~const` is not allowed here
//~^ ERROR  parameter `T` is never used

enum Enum<T: ~const Trait> { Variant(T) } //~ ERROR `~const` is not allowed here

union Union<T: ~const Trait> { field: T } //~ ERROR `~const` is not allowed here
//~^ ERROR field must implement `Copy`

type Type<T: ~const Trait> = T; //~ ERROR `~const` is not allowed here

const CONSTANT<T: ~const Trait>: () = (); //~ ERROR `~const` is not allowed here
//~^ ERROR generic const items are experimental

trait NonConstTrait {
    type Type<T: ~const Trait>: ~const Trait;
    //~^ ERROR `~const` is not allowed
    //~| ERROR `~const` is not allowed
    fn non_const_function<T: ~const Trait>(); //~ ERROR `~const` is not allowed
    const CONSTANT<T: ~const Trait>: (); //~ ERROR `~const` is not allowed
    //~^ ERROR generic const items are experimental
}

impl NonConstTrait for () {
    type Type<T: ~const Trait> = (); //~ ERROR `~const` is not allowed
    //~^ ERROR overflow evaluating the requirement `(): Trait`
    fn non_const_function<T: ~const Trait>() {} //~ ERROR `~const` is not allowed
    const CONSTANT<T: ~const Trait>: () = (); //~ ERROR `~const` is not allowed
    //~^ ERROR generic const items are experimental
}

struct Implementor;

impl Implementor {
    type Type<T: ~const Trait> = (); //~ ERROR `~const` is not allowed
    //~^ ERROR inherent associated types are unstable
    fn non_const_function<T: ~const Trait>() {} //~ ERROR `~const` is not allowed
    const CONSTANT<T: ~const Trait>: () = (); //~ ERROR `~const` is not allowed
    //~^ ERROR generic const items are experimental
}

// non-const traits
trait Child0: ~const Trait {} //~ ERROR `~const` is not allowed
trait Child1 where Self: ~const Trait {} //~ ERROR `~const` is not allowed

// non-const impl
impl<T: ~const Trait> Trait for T {} //~ ERROR `~const` is not allowed

// inherent impl (regression test for issue #117004)
impl<T: ~const Trait> Struct<T> {} //~ ERROR `~const` is not allowed

fn main() {}