diff options
| author | Ralf Jung <post@ralfj.de> | 2024-02-10 16:59:21 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-02-10 17:00:24 +0100 |
| commit | 29db7890baacf18cd11c6fa530baf5ec82673f52 (patch) | |
| tree | 57b3f2c7c7ad5400b0f2de2dcaeb7a97a75db58f | |
| parent | 0809f78c190eb9fdf36353d423147827610f33c9 (diff) | |
| download | rust-29db7890baacf18cd11c6fa530baf5ec82673f52.tar.gz rust-29db7890baacf18cd11c6fa530baf5ec82673f52.zip | |
interpret/visitor: ensure we only see normalized types
| -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. _ => {} }; |
