Skip to content

Commit 44f416a

Browse files
authored
Unrolled build for #143927
Rollup merge of #143927 - oli-obk:const-dyn-trait-hir-ty, r=fmease Preserve constness in trait objects up to hir ty lowering r? ``@compiler-errors`` While we don't support `dyn const Trait`, we can at least also inform the user that `const Trait` is only legal for `#[const_trait] trait Trait {}`
2 parents a9fb610 + 000e67a commit 44f416a

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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,

tests/ui/traits/const-traits/const-trait-bounds-trait-objects.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ fn main() {
1414
trait NonConst {}
1515
const 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
1718
const fn take(_: &dyn [const] NonConst) {}
1819
//~^ ERROR `[const]` is not allowed here
20+
//~| ERROR `[const]` can only be applied to `#[const_trait]` traits

tests/ui/traits/const-traits/const-trait-bounds-trait-objects.stderr

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,34 @@ LL | const fn handle(_: &dyn const NonConst) {}
1919
| ^^^^^^^^^^^^^^
2020

2121
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
2323
|
2424
LL | 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

0 commit comments

Comments
 (0)