Skip to content

Commit 0cb22a6

Browse files
committed
very verbose error handling
1 parent 22b1acb commit 0cb22a6

File tree

1 file changed

+86
-20
lines changed
  • compiler/rustc_mir_dataflow/src/move_paths

1 file changed

+86
-20
lines changed

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,35 +125,88 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
125125
},
126126
));
127127
}
128-
_ => (),
128+
ty::Adt(adt, _) => {
129+
if !adt.is_box() {
130+
bug!("Adt should be a box type");
131+
}
132+
}
133+
ty::Bool
134+
| ty::Char
135+
| ty::Int(_)
136+
| ty::Uint(_)
137+
| ty::Float(_)
138+
| ty::Foreign(_)
139+
| ty::Str
140+
| ty::Array(_, _)
141+
| ty::Slice(_)
142+
| ty::FnDef(_, _)
143+
| ty::FnPtr(_)
144+
| ty::Dynamic(_, _, _)
145+
| ty::Closure(_, _)
146+
| ty::Generator(_, _, _)
147+
| ty::GeneratorWitness(_)
148+
| ty::GeneratorWitnessMIR(_, _)
149+
| ty::Never
150+
| ty::Tuple(_)
151+
| ty::Alias(_, _)
152+
| ty::Param(_)
153+
| ty::Bound(_, _)
154+
| ty::Infer(_)
155+
| ty::Error(_)
156+
| ty::Placeholder(_) => bug!("Place has a wrong type {place_ty:#?}"),
129157
},
130-
ProjectionElem::Field(_, _)
131-
| ProjectionElem::OpaqueCast(_)
132-
| ProjectionElem::Downcast(_, _) => match place_ty.kind() {
133-
ty::Adt(adt, _) if adt.has_dtor(tcx) && !adt.is_box() => {
158+
ProjectionElem::Field(_, _) => match place_ty.kind() {
159+
ty::Adt(adt, _) if adt.has_dtor(tcx) => {
134160
return Err(MoveError::cannot_move_out_of(
135161
self.loc,
136162
InteriorOfTypeWithDestructor { container_ty: place_ty },
137163
));
138164
}
139-
ty::Adt(adt, _) if adt.is_union() => {
140-
union_path.get_or_insert(base);
165+
ty::Adt(adt, _) => {
166+
if adt.is_union() {
167+
union_path.get_or_insert(base);
168+
}
141169
}
142-
143-
_ => (),
170+
ty::Closure(_, _) | ty::Generator(_, _, _) | ty::Tuple(_) => (),
171+
ty::Bool
172+
| ty::Char
173+
| ty::Int(_)
174+
| ty::Uint(_)
175+
| ty::Float(_)
176+
| ty::Foreign(_)
177+
| ty::Str
178+
| ty::Array(_, _)
179+
| ty::Slice(_)
180+
| ty::RawPtr(_)
181+
| ty::Ref(_, _, _)
182+
| ty::FnDef(_, _)
183+
| ty::FnPtr(_)
184+
| ty::Dynamic(_, _, _)
185+
| ty::GeneratorWitness(_)
186+
| ty::GeneratorWitnessMIR(_, _)
187+
| ty::Never
188+
| ty::Alias(_, _)
189+
| ty::Param(_)
190+
| ty::Bound(_, _)
191+
| ty::Infer(_)
192+
| ty::Error(_)
193+
| ty::Placeholder(_) => bug!("Place has a wrong type {place_ty:#?}"),
144194
},
145-
ProjectionElem::ConstantIndex { .. }
146-
| ProjectionElem::Index(_)
147-
| ProjectionElem::Subslice { .. } => match place_ty.kind() {
148-
ty::Slice(_) => {
149-
return Err(MoveError::cannot_move_out_of(
150-
self.loc,
151-
InteriorOfSliceOrArray {
152-
ty: place_ty,
153-
is_index: matches!(elem, ProjectionElem::Index(..)),
154-
},
155-
));
195+
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
196+
match place_ty.kind() {
197+
ty::Slice(_) => {
198+
return Err(MoveError::cannot_move_out_of(
199+
self.loc,
200+
InteriorOfSliceOrArray {
201+
ty: place_ty,
202+
is_index: matches!(elem, ProjectionElem::Index(..)),
203+
},
204+
));
205+
}
206+
_ => (),
156207
}
208+
}
209+
ProjectionElem::Index(_) => match place_ty.kind() {
157210
ty::Array(..) => {
158211
if let ProjectionElem::Index(..) = elem {
159212
return Err(MoveError::cannot_move_out_of(
@@ -162,8 +215,21 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
162215
));
163216
}
164217
}
218+
ty::Slice(_) => {
219+
return Err(MoveError::cannot_move_out_of(
220+
self.loc,
221+
InteriorOfSliceOrArray {
222+
ty: place_ty,
223+
is_index: matches!(elem, ProjectionElem::Index(..)),
224+
},
225+
));
226+
}
165227
_ => (),
166228
},
229+
// `OpaqueCast` only transmutes the type, so no moves there and
230+
// `Downcast` only changes information about a `Place` without moving
231+
// So it's safe to skip these.
232+
ProjectionElem::OpaqueCast(_) | ProjectionElem::Downcast(_, _) => (),
167233
}
168234
if union_path.is_none() {
169235
// inlined from add_move_path because of a borrowck conflict with the iterator

0 commit comments

Comments
 (0)