handle associated types correctly in null pointer optimization
Fixes #27532 Thanks @eefriedman for the test.
This commit is contained in:
parent
34942331a3
commit
c533f963d9
@ -462,8 +462,7 @@ fn find_discr_field_candidate<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
// let's recurse and find out
|
||||
ty::TyStruct(def, substs) => {
|
||||
for (j, field) in def.struct_variant().fields.iter().enumerate() {
|
||||
// TODO(#27532)
|
||||
let field_ty = field.ty(tcx, substs);
|
||||
let field_ty = monomorphize::field_ty(tcx, substs, field);
|
||||
if let Some(mut fpath) = find_discr_field_candidate(tcx, field_ty, path.clone()) {
|
||||
fpath.push(j);
|
||||
return Some(fpath);
|
||||
|
@ -18,6 +18,10 @@ use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
trait Trait { fn dummy(&self) { } }
|
||||
trait Mirror { type Image; }
|
||||
impl<T> Mirror for T { type Image = T; }
|
||||
struct ParamTypeStruct<T>(T);
|
||||
struct AssocTypeStruct<T>(<T as Mirror>::Image);
|
||||
|
||||
fn main() {
|
||||
// Functions
|
||||
@ -66,4 +70,7 @@ fn main() {
|
||||
// Should apply to types that have NonZero transitively
|
||||
assert_eq!(size_of::<String>(), size_of::<Option<String>>());
|
||||
|
||||
// Should apply to types where the pointer is substituted
|
||||
assert_eq!(size_of::<&u8>(), size_of::<Option<ParamTypeStruct<&u8>>>());
|
||||
assert_eq!(size_of::<&u8>(), size_of::<Option<AssocTypeStruct<&u8>>>());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user