diff options
| author | Jannis Christopher Köhl <mail@koehl.dev> | 2022-11-09 18:21:42 +0100 |
|---|---|---|
| committer | Jannis Christopher Köhl <mail@koehl.dev> | 2022-11-09 18:21:42 +0100 |
| commit | 9766ee0b2040d93c7ff4af237c3c839d54adf8ea (patch) | |
| tree | 16004fc510ef6d40424a563df191f59343361ef1 /compiler/rustc_mir_dataflow | |
| parent | bfbca6c75c1502b14ffda12afa2b688fe42288fc (diff) | |
| download | rust-9766ee0b2040d93c7ff4af237c3c839d54adf8ea.tar.gz rust-9766ee0b2040d93c7ff4af237c3c839d54adf8ea.zip | |
Fix struct field tracking and add tests for it
Diffstat (limited to 'compiler/rustc_mir_dataflow')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/value_analysis.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index f428cd5ee82..17d349fb526 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -151,9 +151,7 @@ pub trait ValueAnalysis<'tcx> { ) -> ValueOrPlace<Self::Value> { match rvalue { Rvalue::Use(operand) => self.handle_operand(operand, state), - Rvalue::CopyForDeref(place) => { - self.handle_operand(&Operand::Copy(*place), state) - } + Rvalue::CopyForDeref(place) => self.handle_operand(&Operand::Copy(*place), state), Rvalue::Ref(..) | Rvalue::AddressOf(..) => { // We don't track such places. ValueOrPlace::top() @@ -638,9 +636,7 @@ impl Map { return; } projection.push(PlaceElem::Field(field, ty)); - self.register_with_filter_rec( - tcx, local, projection, ty, filter, exclude, - ); + self.register_with_filter_rec(tcx, local, projection, ty, filter, exclude); projection.pop(); }); } @@ -842,13 +838,17 @@ fn iter_fields<'tcx>( } } ty::Adt(def, substs) => { + if def.is_union() { + return; + } for (v_index, v_def) in def.variants().iter_enumerated() { + let variant = if def.is_struct() { None } else { Some(v_index) }; for (f_index, f_def) in v_def.fields.iter().enumerate() { let field_ty = f_def.ty(tcx, substs); let field_ty = tcx .try_normalize_erasing_regions(ty::ParamEnv::reveal_all(), field_ty) .unwrap_or(field_ty); - f(Some(v_index), f_index.into(), field_ty); + f(variant, f_index.into(), field_ty); } } } |
