File tree 5 files changed +100
-0
lines changed
src/test/ui/rfc-2632-const-trait-impl
5 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( const_trait_impl) ]
2
+
3
+ trait Foo {
4
+ fn a ( & self ) ;
5
+ }
6
+ trait Bar : ~const Foo { }
7
+
8
+ const fn foo < T : Bar > ( x : & T ) {
9
+ x. a ( ) ;
10
+ //~^ ERROR the trait bound
11
+ //~| ERROR cannot call
12
+ }
13
+
14
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0277]: the trait bound `T: ~const Foo` is not satisfied
2
+ --> $DIR/super-traits-fail-2.rs:9:7
3
+ |
4
+ LL | x.a();
5
+ | ^^^ the trait `~const Foo` is not implemented for `T`
6
+ |
7
+ note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
8
+ --> $DIR/super-traits-fail-2.rs:9:7
9
+ |
10
+ LL | x.a();
11
+ | ^^^
12
+
13
+ error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
14
+ --> $DIR/super-traits-fail-2.rs:9:7
15
+ |
16
+ LL | x.a();
17
+ | ^^^
18
+ |
19
+ = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
20
+
21
+ error: aborting due to 2 previous errors
22
+
23
+ Some errors have detailed explanations: E0015, E0277.
24
+ For more information about an error, try `rustc --explain E0015`.
Original file line number Diff line number Diff line change
1
+ #![ feature( const_trait_impl) ]
2
+
3
+ trait Foo {
4
+ fn a ( & self ) ;
5
+ }
6
+ trait Bar : ~const Foo { }
7
+
8
+ struct S ;
9
+ impl Foo for S {
10
+ fn a ( & self ) { }
11
+ }
12
+
13
+ impl const Bar for S { }
14
+ //~^ ERROR the trait bound
15
+
16
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0277]: the trait bound `S: ~const Foo` is not satisfied
2
+ --> $DIR/super-traits-fail.rs:13:12
3
+ |
4
+ LL | impl const Bar for S {}
5
+ | ^^^ the trait `~const Foo` is not implemented for `S`
6
+ |
7
+ note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
8
+ --> $DIR/super-traits-fail.rs:13:12
9
+ |
10
+ LL | impl const Bar for S {}
11
+ | ^^^
12
+ note: required by a bound in `Bar`
13
+ --> $DIR/super-traits-fail.rs:6:12
14
+ |
15
+ LL | trait Bar: ~const Foo {}
16
+ | ^^^^^^^^^^ required by this bound in `Bar`
17
+ help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
18
+ |
19
+ LL | impl const Bar for S where S: ~const Foo {}
20
+ | +++++++++++++++++++
21
+
22
+ error: aborting due to previous error
23
+
24
+ For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+ #![ feature( const_trait_impl) ]
3
+
4
+ trait Foo {
5
+ fn a ( & self ) ;
6
+ }
7
+ trait Bar : ~const Foo { }
8
+
9
+ struct S ;
10
+ impl const Foo for S {
11
+ fn a ( & self ) { }
12
+ }
13
+
14
+ impl const Bar for S { }
15
+
16
+ const fn foo < T : ~const Bar > ( t : & T ) {
17
+ t. a ( ) ;
18
+ }
19
+
20
+ const _: ( ) = foo ( & S ) ;
21
+
22
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments