Rollup merge of #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 #61402.

Closes #62212 - this PR fixes the root cause.
This commit is contained in:
Mazdak Farrokhzad 2019-07-04 01:38:44 +02:00 committed by GitHub
commit 6cfd474e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -1104,6 +1104,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id_from_hir_id(field.hir_id));
let field_ty = self.normalize_associated_types_in(field.span,
&field_ty);
let field_ty = self.resolve_vars_if_possible(&field_ty);
debug!("non_enum_variant: type of field {:?} is {:?}", field, field_ty);
AdtField { ty: field_ty, span: field.span }
})
.collect();

View File

@ -0,0 +1,21 @@
// If a struct is packed and its last field has drop glue, then that
// field needs to be Sized (to allow it to be destroyed out-of-place).
//
// This is checked by the compiler during wfcheck. That check used
// to have problems with associated types in the last field - test
// that this doesn't ICE.
#![allow(unused_imports, dead_code)]
pub struct S;
pub trait Trait<R> { type Assoc; }
impl<X> Trait<X> for S { type Assoc = X; }
#[repr(C, packed)]
struct PackedAssocSized {
pos: Box<<S as Trait<usize>>::Assoc>,
}
fn main() { println!("Hello, world!"); }