Skip to content

Fall back to old metadata computation when type references errors #109101

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

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,11 @@ where
*/
};

let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type() {
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type()
// Projection eagerly bails out when the pointee references errors,
// fall back to structurally deducing metadata.
&& !pointee.references_error()
{
let metadata = tcx.normalize_erasing_regions(
cx.param_env(),
tcx.mk_projection(metadata_def_id, [pointee]),
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ fn layout_of_uncached<'tcx>(

let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);

let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type() {
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type()
// Projection eagerly bails out when the pointee references errors,
// fall back to structurally deducing metadata.
&& !pointee.references_error()
{
let metadata_ty = tcx.normalize_erasing_regions(
param_env,
tcx.mk_projection(metadata_def_id, [pointee]),
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/layout/transmute-to-tail-with-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Trait<T> {}

struct Bar(Box<dyn Trait<T>>);
//~^ ERROR cannot find type `T` in this scope

fn main() {
let x: Bar = unsafe { std::mem::transmute(()) };
}
14 changes: 14 additions & 0 deletions tests/ui/layout/transmute-to-tail-with-err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0412]: cannot find type `T` in this scope
--> $DIR/transmute-to-tail-with-err.rs:3:26
|
LL | struct Bar(Box<dyn Trait<T>>);
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | struct Bar<T>(Box<dyn Trait<T>>);
| +++

error: aborting due to previous error

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