File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
compiler/rustc_hir_analysis/src/hir_ty_lowering
tests/ui/traits/const-traits Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
49
49
} = self . lower_poly_trait_ref (
50
50
& trait_bound. trait_ref ,
51
51
trait_bound. span ,
52
- hir :: BoundConstness :: Never ,
52
+ trait_bound . modifiers . constness ,
53
53
hir:: BoundPolarity :: Positive ,
54
54
dummy_self,
55
55
& mut user_written_bounds,
Original file line number Diff line number Diff line change @@ -14,5 +14,7 @@ fn main() {
14
14
trait NonConst { }
15
15
const fn handle ( _: & dyn const NonConst ) { }
16
16
//~^ ERROR const trait bounds are not allowed in trait object types
17
+ //~| ERROR `const` can only be applied to `#[const_trait]` traits
17
18
const fn take ( _: & dyn [ const ] NonConst ) { }
18
19
//~^ ERROR `[const]` is not allowed here
20
+ //~| ERROR `[const]` can only be applied to `#[const_trait]` traits
Original file line number Diff line number Diff line change @@ -19,12 +19,34 @@ LL | const fn handle(_: &dyn const NonConst) {}
19
19
| ^^^^^^^^^^^^^^
20
20
21
21
error: `[const]` is not allowed here
22
- --> $DIR/const-trait-bounds-trait-objects.rs:17 :23
22
+ --> $DIR/const-trait-bounds-trait-objects.rs:18 :23
23
23
|
24
24
LL | const fn take(_: &dyn [const] NonConst) {}
25
25
| ^^^^^^^
26
26
|
27
27
= note: trait objects cannot have `[const]` trait bounds
28
28
29
- error: aborting due to 4 previous errors
29
+ error: `const` can only be applied to `#[const_trait]` traits
30
+ --> $DIR/const-trait-bounds-trait-objects.rs:15:25
31
+ |
32
+ LL | const fn handle(_: &dyn const NonConst) {}
33
+ | ^^^^^ can't be applied to `NonConst`
34
+ |
35
+ help: mark `NonConst` as `#[const_trait]` to allow it to have `const` implementations
36
+ |
37
+ LL | #[const_trait] trait NonConst {}
38
+ | ++++++++++++++
39
+
40
+ error: `[const]` can only be applied to `#[const_trait]` traits
41
+ --> $DIR/const-trait-bounds-trait-objects.rs:18:23
42
+ |
43
+ LL | const fn take(_: &dyn [const] NonConst) {}
44
+ | ^^^^^^^ can't be applied to `NonConst`
45
+ |
46
+ help: mark `NonConst` as `#[const_trait]` to allow it to have `const` implementations
47
+ |
48
+ LL | #[const_trait] trait NonConst {}
49
+ | ++++++++++++++
50
+
51
+ error: aborting due to 6 previous errors
30
52
You can’t perform that action at this time.
0 commit comments