Auto merge of #10989 - ericmarkmartin:use-placeref-abstraction, r=Manishearth

Use placeref abstraction

rust-lang/rust#80647 suggests refactoring certain patterns with MIR places to use higher-level abstractions provided by the [`Place`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.Place.html)/[`PlaceRef`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.PlaceRef.html). While working on that issue, I found a couple candidates for such refactoring in clippy.

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: none
This commit is contained in:
bors 2023-06-20 04:43:38 +00:00
commit 1919dff4ee
3 changed files with 16 additions and 15 deletions

View file

@ -284,13 +284,10 @@ fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, b
}
fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult {
let mut cursor = place.projection.as_ref();
while let [ref proj_base @ .., elem] = *cursor {
cursor = proj_base;
for (base, elem) in place.as_ref().iter_projections() {
match elem {
ProjectionElem::Field(..) => {
let base_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
let base_ty = base.ty(body, tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
// No union field accesses in `const fn`
if def.is_union() {