Skip to content

Commit 3fa7739

Browse files
committed
remove unnecessary checks
1 parent 5692677 commit 3fa7739

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,28 @@ 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 {
292+
ProjectionElem::Field(..) => {
293+
let base_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
294+
if !is_ty_const_destruct(tcx, base_ty, body) && in_move {
283295
return Err((
284296
span,
285297
"cannot drop locals with a non constant destructor in const fn".into(),
286298
));
287299
}
288-
289-
let base_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
290300
if let Some(def) = base_ty.ty_adt_def() {
291301
// No union field accesses in `const fn`
292302
if def.is_union() {
@@ -328,7 +338,7 @@ fn check_terminator<'tcx>(
328338
"cannot drop locals with a non constant destructor in const fn".into(),
329339
));
330340
}
331-
check_place(tcx, *place, span, body, false)
341+
Ok(())
332342
},
333343
TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body),
334344
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {

0 commit comments

Comments
 (0)