Skip to content

Commit a495fa0

Browse files
committed
remove unnecessary checks
1 parent 5692677 commit a495fa0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,21 @@ fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, b
275275
fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>, in_move: bool) -> McfResult {
276276
let mut cursor = place.projection.as_ref();
277277

278+
if let [proj_base] = cursor
279+
&& let ProjectionElem::Field(_, ty) = proj_base
280+
&& !is_ty_const_destruct(tcx, *ty, body)
281+
&& in_move
282+
{
283+
return Err((
284+
span,
285+
"cannot drop locals with a non constant destructor in const fn".into(),
286+
));
287+
}
288+
278289
while let [ref proj_base @ .., elem] = *cursor {
279290
cursor = proj_base;
280291
match elem {
281-
ProjectionElem::Field(_, ty) => {
282-
if !is_ty_const_destruct(tcx, ty, body) && in_move {
283-
return Err((
284-
span,
285-
"cannot drop locals with a non constant destructor in const fn".into(),
286-
));
287-
}
288-
292+
ProjectionElem::Field(..) => {
289293
let base_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
290294
if let Some(def) = base_ty.ty_adt_def() {
291295
// No union field accesses in `const fn`
@@ -328,7 +332,7 @@ fn check_terminator<'tcx>(
328332
"cannot drop locals with a non constant destructor in const fn".into(),
329333
));
330334
}
331-
check_place(tcx, *place, span, body, false)
335+
Ok(())
332336
},
333337
TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body),
334338
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {

0 commit comments

Comments
 (0)