Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle normalization failure in struct_tail_erasing_lifetimes #124548

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 17 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,23 @@ impl<'tcx> SizeSkeleton<'tcx> {
match *ty.kind() {
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
let non_zero = !ty.is_unsafe_ptr();
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);

let tail = tcx.struct_tail_with_normalize(
pointee,
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
Ok(ty) => ty,
Err(e) => Ty::new_error_with_message(
tcx,
DUMMY_SP,
format!(
"normalization failed for {} but no errors reported",
e.get_type_for_failure()
),
),
},
|| {},
);

match tail.kind() {
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
debug_assert!(tail.has_non_region_param());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ known-bug: #113272
trait Trait {
type RefTarget;
}

impl Trait for () where Missing: Trait {}
//~^ ERROR cannot find type `Missing` in this scope
//~| ERROR not all trait items implemented, missing: `RefTarget`

struct Other {
data: <() as Trait>::RefTarget,
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/structs/ice-struct-tail-normalization-113272.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/ice-struct-tail-normalization-113272.rs:5:25
|
LL | impl Trait for () where Missing: Trait {}
| ^^^^^^^ not found in this scope

error[E0046]: not all trait items implemented, missing: `RefTarget`
--> $DIR/ice-struct-tail-normalization-113272.rs:5:1
|
LL | type RefTarget;
| -------------- `RefTarget` from trait
...
LL | impl Trait for () where Missing: Trait {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0046, E0412.
For more information about an error, try `rustc --explain E0046`.
Loading