Skip to content

Commit a02d436

Browse files
committed
wfcheck: resolve the type-vars in AdtField types
Normalization can leave some type-vars unresolved in its return type. Make sure to resolve them so we have an infcx-independent type that can be used with `needs_drop`. Fixes #61402.
1 parent 9a90d03 commit a02d436

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/librustc_typeck/check/wfcheck.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11031103
let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id_from_hir_id(field.hir_id));
11041104
let field_ty = self.normalize_associated_types_in(field.span,
11051105
&field_ty);
1106+
let field_ty = self.resolve_vars_if_possible(&field_ty);
1107+
debug!("non_enum_variant: type of field {:?} is {:?}", field, field_ty);
11061108
AdtField { ty: field_ty, span: field.span }
11071109
})
11081110
.collect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// If a struct is packed and its last field has drop glue, then that
2+
// field needs to be Sized (to allow it to be destroyed out-of-place).
3+
//
4+
// This is checked by the compiler during wfcheck. That check used
5+
// to have problems with associated types in the last field - test
6+
// that this doesn't ICE.
7+
8+
#![allow(unused_imports, dead_code)]
9+
10+
pub struct S;
11+
12+
pub trait Trait<R> { type Assoc; }
13+
14+
impl<X> Trait<X> for S { type Assoc = X; }
15+
16+
#[repr(C, packed)]
17+
struct PackedAssocSized {
18+
pos: Box<<S as Trait<usize>>::Assoc>,
19+
}
20+
21+
fn main() { println!("Hello, world!"); }

0 commit comments

Comments
 (0)