diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-11 23:19:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-11 23:19:09 +0100 |
| commit | 90b4e4116f2de9f548b3d894349a97441c4979eb (patch) | |
| tree | bba461b2b997d2a1731a2ef31764013c023e62b6 /compiler/rustc_const_eval | |
| parent | 3d7d709925294ae6d7304242d21a3b5cd3676c15 (diff) | |
| parent | 29db7890baacf18cd11c6fa530baf5ec82673f52 (diff) | |
| download | rust-90b4e4116f2de9f548b3d894349a97441c4979eb.tar.gz rust-90b4e4116f2de9f548b3d894349a97441c4979eb.zip | |
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`
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/projection.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/visitor.rs | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs index 3a441c1d649..7b68a37fdf3 100644 --- a/compiler/rustc_const_eval/src/interpret/projection.rs +++ b/compiler/rustc_const_eval/src/interpret/projection.rs @@ -149,6 +149,8 @@ where "`field` projection called on a slice -- call `index` projection instead" ); 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); // Offset may need adjustment for unsized fields. diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index de0590a4b14..340a496a689 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -153,6 +153,16 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { // We visited all parts of this one. 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. _ => {} }; |
