Skip to content

Commit 0bb876e

Browse files
Layout of &dyn Trait<[type error]> is still wide
1 parent f1b1ed7 commit 0bb876e

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

compiler/rustc_middle/src/ty/layout.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,11 @@ where
730730
*/
731731
};
732732

733-
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type() {
733+
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type()
734+
// Projection eagerly bails out when the pointee references errors,
735+
// fall back to structurally deducing metadata.
736+
&& !pointee.references_error()
737+
{
734738
let metadata = tcx.normalize_erasing_regions(
735739
cx.param_env(),
736740
tcx.mk_projection(metadata_def_id, [pointee]),

compiler/rustc_ty_utils/src/layout.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ fn layout_of_uncached<'tcx>(
156156

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

159-
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type() {
159+
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type()
160+
// Projection eagerly bails out when the pointee references errors,
161+
// fall back to structurally deducing metadata.
162+
&& !pointee.references_error()
163+
{
160164
let metadata_ty = tcx.normalize_erasing_regions(
161165
param_env,
162166
tcx.mk_projection(metadata_def_id, [pointee]),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Trait<T> {}
2+
3+
struct Bar(Box<dyn Trait<T>>);
4+
//~^ ERROR cannot find type `T` in this scope
5+
6+
fn main() {
7+
let x: Bar = unsafe { std::mem::transmute(()) };
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0412]: cannot find type `T` in this scope
2+
--> $DIR/transmute-to-tail-with-err.rs:3:26
3+
|
4+
LL | struct Bar(Box<dyn Trait<T>>);
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | struct Bar<T>(Box<dyn Trait<T>>);
10+
| +++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)