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> + '_ {
4949 } = self . lower_poly_trait_ref (
5050 & trait_bound. trait_ref ,
5151 trait_bound. span ,
52- hir :: BoundConstness :: Never ,
52+ trait_bound . modifiers . constness ,
5353 hir:: BoundPolarity :: Positive ,
5454 dummy_self,
5555 & mut user_written_bounds,
Original file line number Diff line number Diff line change @@ -14,5 +14,7 @@ fn main() {
1414trait NonConst { }
1515const fn handle ( _: & dyn const NonConst ) { }
1616//~^ ERROR const trait bounds are not allowed in trait object types
17+ //~| ERROR `const` can only be applied to `#[const_trait]` traits
1718const fn take ( _: & dyn [ const ] NonConst ) { }
1819//~^ 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) {}
1919 | ^^^^^^^^^^^^^^
2020
2121error: `[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
2323 |
2424LL | const fn take(_: &dyn [const] NonConst) {}
2525 | ^^^^^^^
2626 |
2727 = note: trait objects cannot have `[const]` trait bounds
2828
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
3052
You can’t perform that action at this time.
0 commit comments