File tree 3 files changed +38
-8
lines changed
src/test/ui/rfc-2632-const-trait-impl
3 files changed +38
-8
lines changed Original file line number Diff line number Diff line change 1
1
#![ feature( const_trait_impl) ]
2
+ #![ feature( const_fn_trait_bound) ]
2
3
3
4
trait Tr {
4
5
fn req ( & self ) ;
@@ -18,11 +19,6 @@ impl const Tr for S {
18
19
fn req ( & self ) { }
19
20
} //~^^ ERROR const trait implementations may not use non-const default functions
20
21
21
- impl const Tr for u8 {
22
- fn req ( & self ) { }
23
- fn prov ( & self ) { }
24
- }
25
-
26
22
impl const Tr for u16 {
27
23
fn prov ( & self ) { }
28
24
fn default ( ) { }
Original file line number Diff line number Diff line change 1
1
error: const trait implementations may not use non-const default functions
2
- --> $DIR/impl-with-default-fn.rs:17 :1
2
+ --> $DIR/impl-with-default-fn-fail .rs:18 :1
3
3
|
4
4
LL | / impl const Tr for S {
5
5
LL | | fn req(&self) {}
9
9
= note: `prov` not implemented
10
10
11
11
error: const trait implementations may not use non-const default functions
12
- --> $DIR/impl-with-default-fn.rs:32 :1
12
+ --> $DIR/impl-with-default-fn-fail .rs:28 :1
13
13
|
14
14
LL | / impl const Tr for u32 {
15
15
LL | | fn req(&self) {}
@@ -20,7 +20,7 @@ LL | | }
20
20
= note: `prov` not implemented
21
21
22
22
error[E0046]: not all trait items implemented, missing: `req`
23
- --> $DIR/impl-with-default-fn.rs:26 :1
23
+ --> $DIR/impl-with-default-fn-fail .rs:22 :1
24
24
|
25
25
LL | fn req(&self);
26
26
| -------------- `req` from trait
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+
3
+ #![ feature( const_trait_impl) ]
4
+ #![ feature( const_fn_trait_bound) ]
5
+
6
+ trait Tr {
7
+ fn req ( & self ) ;
8
+
9
+ fn prov ( & self ) {
10
+ println ! ( "lul" ) ;
11
+ self . req ( ) ;
12
+ }
13
+
14
+ #[ default_method_body_is_const]
15
+ fn default ( ) { }
16
+ }
17
+
18
+ impl const Tr for u8 {
19
+ fn req ( & self ) { }
20
+ fn prov ( & self ) { }
21
+ }
22
+
23
+ macro_rules! impl_tr {
24
+ ( $ty: ty) => {
25
+ impl const Tr for $ty {
26
+ fn req( & self ) { }
27
+ fn prov( & self ) { }
28
+ }
29
+ }
30
+ }
31
+
32
+ impl_tr ! ( u64 ) ;
33
+
34
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments