Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,10 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
.type_of(field_def.did)
.instantiate(tcx, args)
.skip_norm_wip();
// Lifetimes stored in valtree constants are erased, so avoid
// relating those erased regions with the field's original
// regions during well-formedness checking.
let field_ty = tcx.erase_and_anonymize_regions(field_ty);
let predicate = ty::PredicateKind::Clause(
ty::ClauseKind::ConstArgHasType(field_val, field_ty),
);
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/const-generics/mgca/valtree-erased-region-issue-159688.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ check-fail

#![feature(min_generic_const_args)]
#![feature(min_adt_const_params)]
#![expect(incomplete_features)]

pub struct Foo {
slice: &'static [u8],
}

#[derive(PartialEq, Eq)]
pub struct Foo_<const F: Foo>;
//~^ ERROR `Foo` must implement `ConstParamTy`
//~| ERROR `Foo` must implement `ConstParamTy`
//~| ERROR `Foo` must implement `ConstParamTy`
//~| ERROR `Foo` must implement `ConstParamTy`

impl
Foo_<
{
Foo {
slice: &[1, 2, 3],
}
},
>
{
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/valtree-erased-region-issue-159688.rs:12:26
|
LL | pub struct Foo_<const F: Foo>;
| ^^^
|
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct
|
LL + #[derive(ConstParamTy, PartialEq, Eq)]
LL | pub struct Foo {
|

error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/valtree-erased-region-issue-159688.rs:12:26
|
LL | pub struct Foo_<const F: Foo>;
| ^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct
|
LL + #[derive(ConstParamTy, PartialEq, Eq)]
LL | pub struct Foo {
|

error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/valtree-erased-region-issue-159688.rs:12:26
|
LL | pub struct Foo_<const F: Foo>;
| ^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct
|
LL + #[derive(ConstParamTy, PartialEq, Eq)]
LL | pub struct Foo {
|

error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/valtree-erased-region-issue-159688.rs:12:26
|
LL | pub struct Foo_<const F: Foo>;
| ^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct
|
LL + #[derive(ConstParamTy, PartialEq, Eq)]
LL | pub struct Foo {
|

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0741`.
Loading