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

Use try_normalize_erasing_regions in needs_drop #91462

Closed
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
8 changes: 6 additions & 2 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,14 @@ impl<'tcx> ty::TyS<'tcx> {
[component_ty] => component_ty,
_ => self,
};

// This doesn't depend on regions, so try to minimize distinct
// query keys used.
let erased = tcx.normalize_erasing_regions(param_env, query_ty);
tcx.needs_drop_raw(param_env.and(erased))
// If normalization fails, we just use `query_ty`.
let query_ty =
tcx.try_normalize_erasing_regions(param_env, query_ty).unwrap_or(query_ty);

tcx.needs_drop_raw(param_env.and(query_ty))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ where
Ok(tys) => tys,
};
for required_ty in tys {
let required =
tcx.normalize_erasing_regions(self.param_env, required_ty);
let required = tcx
.try_normalize_erasing_regions(self.param_env, required_ty)
.unwrap_or(required_ty);

queue_type(self, required);
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/union/issue-81199.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[repr(C)]
union PtrRepr<T: ?Sized> {
const_ptr: *const T,
mut_ptr: *mut T,
components: PtrComponents<T>,
//~^ ERROR the trait bound
}

#[repr(C)]
struct PtrComponents<T: Pointee + ?Sized> {
data_address: *const (),
metadata: <T as Pointee>::Metadata,
}



pub trait Pointee {
type Metadata;
}

fn main() {}
29 changes: 29 additions & 0 deletions src/test/ui/union/issue-81199.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0277]: the trait bound `T: Pointee` is not satisfied in `PtrComponents<T>`
--> $DIR/issue-81199.rs:5:17
|
LL | components: PtrComponents<T>,
| ^^^^^^^^^^^^^^^^ within `PtrComponents<T>`, the trait `Pointee` is not implemented for `T`
|
note: required because it appears within the type `PtrComponents<T>`
--> $DIR/issue-81199.rs:10:8
|
LL | struct PtrComponents<T: Pointee + ?Sized> {
| ^^^^^^^^^^^^^
= note: no field of a union may have a dynamically sized type
= help: change the field's type to have a statically known size
help: consider further restricting this bound
|
LL | union PtrRepr<T: ?Sized + Pointee> {
| +++++++++
help: borrowed types always have a statically known size
|
LL | components: &PtrComponents<T>,
| +
help: the `Box` type always has a statically known size and allocates its contents in the heap
|
LL | components: Box<PtrComponents<T>>,
| ++++ +

error: aborting due to previous error

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