Rollup merge of #120885 - RalfJung:normal-visitor, r=compiler-errors

interpret/visitor: ensure we only see normalized types

[Prior discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Normalization.20after.20field.20projection)
r? `@compiler-errors`
This commit is contained in:
Matthias Krüger 2024-02-11 23:19:09 +01:00 committed by GitHub
commit 90b4e4116f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -149,6 +149,8 @@ pub fn project_field<P: Projectable<'tcx, M::Provenance>>(
"`field` projection called on a slice -- call `index` projection instead" "`field` projection called on a slice -- call `index` projection instead"
); );
let offset = base.layout().fields.offset(field); let offset = base.layout().fields.offset(field);
// Computing the layout does normalization, so we get a normalized type out of this
// even if the field type is non-normalized (possible e.g. via associated types).
let field_layout = base.layout().field(self, field); let field_layout = base.layout().field(self, field);
// Offset may need adjustment for unsized fields. // Offset may need adjustment for unsized fields.

View File

@ -153,6 +153,16 @@ fn walk_value(&mut self, v: &Self::V) -> InterpResult<'tcx> {
// We visited all parts of this one. // We visited all parts of this one.
return Ok(()); return Ok(());
} }
// Non-normalized types should never show up here.
ty::Param(..)
| ty::Alias(..)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(..)
| ty::Error(..) => throw_inval!(TooGeneric),
// The rest is handled below.
_ => {} _ => {}
}; };