Skip to content

Commit 6cfd474

Browse files
authored
Rollup merge of rust-lang#62240 - arielb1:resolve-wf-fields, r=pnkfelix
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 rust-lang#61402. Closes rust-lang#62212 - this PR fixes the root cause.
2 parents 740d5bd + a02d436 commit 6cfd474

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
@@ -1104,6 +1104,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11041104
let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id_from_hir_id(field.hir_id));
11051105
let field_ty = self.normalize_associated_types_in(field.span,
11061106
&field_ty);
1107+
let field_ty = self.resolve_vars_if_possible(&field_ty);
1108+
debug!("non_enum_variant: type of field {:?} is {:?}", field, field_ty);
11071109
AdtField { ty: field_ty, span: field.span }
11081110
})
11091111
.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)