Skip to content

Commit 8c081f6

Browse files
authored
Rollup merge of rust-lang#70815 - RalfJung:layout-debug, r=jonas-schievink
Enable layout debugging for `impl Trait` type aliases I also made it print the actual type name that the alias picks under the hood.
2 parents 4827aa6 + 8f6c109 commit 8c081f6

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/librustc_passes/layout_test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> {
2727
ItemKind::TyAlias(..)
2828
| ItemKind::Enum(..)
2929
| ItemKind::Struct(..)
30-
| ItemKind::Union(..) => {
30+
| ItemKind::Union(..)
31+
| ItemKind::OpaqueTy(..) => {
3132
for attr in self.tcx.get_attrs(item_def_id).iter() {
3233
if attr.check_name(sym::rustc_layout) {
3334
self.dump_layout_of(item_def_id, item, attr);
@@ -84,7 +85,7 @@ impl LayoutTest<'tcx> {
8485
sym::debug => {
8586
self.tcx.sess.span_err(
8687
item.span,
87-
&format!("layout debugging: {:#?}", *ty_layout),
88+
&format!("layout debugging for type {:?}: {:#?}", ty, *ty_layout),
8889
);
8990
}
9091

src/test/ui/layout/debug.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// normalize-stderr-test "pref: Align \{\n *pow2: [1-3],\n *\}" -> "pref: $$PREF_ALIGN"
2-
#![feature(never_type, rustc_attrs)]
2+
#![feature(never_type, rustc_attrs, type_alias_impl_trait)]
33
#![crate_type = "lib"]
44

55
#[rustc_layout(debug)]
@@ -13,3 +13,10 @@ union U { f1: (i32, i32), f3: i32 } //~ ERROR: layout debugging
1313

1414
#[rustc_layout(debug)]
1515
type Test = Result<i32, i32>; //~ ERROR: layout debugging
16+
17+
#[rustc_layout(debug)]
18+
type T = impl std::fmt::Debug; //~ ERROR: layout debugging
19+
20+
fn f() -> T {
21+
0i32
22+
}

src/test/ui/layout/debug.stderr

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: layout debugging: Layout {
1+
error: layout debugging for type E: Layout {
22
fields: Arbitrary {
33
offsets: [
44
Size {
@@ -110,7 +110,7 @@ error: layout debugging: Layout {
110110
LL | enum E { Foo, Bar(!, i32, i32) }
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112112

113-
error: layout debugging: Layout {
113+
error: layout debugging for type S: Layout {
114114
fields: Arbitrary {
115115
offsets: [
116116
Size {
@@ -164,7 +164,7 @@ error: layout debugging: Layout {
164164
LL | struct S { f1: i32, f2: (), f3: i32 }
165165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166166

167-
error: layout debugging: Layout {
167+
error: layout debugging for type U: Layout {
168168
fields: Union(
169169
2,
170170
),
@@ -190,7 +190,7 @@ error: layout debugging: Layout {
190190
LL | union U { f1: (i32, i32), f3: i32 }
191191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192192

193-
error: layout debugging: Layout {
193+
error: layout debugging for type std::result::Result<i32, i32>: Layout {
194194
fields: Arbitrary {
195195
offsets: [
196196
Size {
@@ -315,5 +315,37 @@ error: layout debugging: Layout {
315315
LL | type Test = Result<i32, i32>;
316316
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
317317

318-
error: aborting due to 4 previous errors
318+
error: layout debugging for type i32: Layout {
319+
fields: Union(
320+
0,
321+
),
322+
variants: Single {
323+
index: 0,
324+
},
325+
abi: Scalar(
326+
Scalar {
327+
value: Int(
328+
I32,
329+
true,
330+
),
331+
valid_range: 0..=4294967295,
332+
},
333+
),
334+
largest_niche: None,
335+
align: AbiAndPrefAlign {
336+
abi: Align {
337+
pow2: 2,
338+
},
339+
pref: $PREF_ALIGN,
340+
},
341+
size: Size {
342+
raw: 4,
343+
},
344+
}
345+
--> $DIR/debug.rs:18:1
346+
|
347+
LL | type T = impl std::fmt::Debug;
348+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
349+
350+
error: aborting due to 5 previous errors
319351

0 commit comments

Comments
 (0)