From 189d2065229944258fe8f621c5e1ec4386b637d4 Mon Sep 17 00:00:00 2001 From: Roxane Date: Sun, 14 Mar 2021 23:53:43 -0400 Subject: [PATCH] Fix error after rebase --- .../src/build/expr/as_rvalue.rs | 7 ++--- .../rustc_mir_build/src/build/matches/mod.rs | 31 +++++++------------ .../rustc_mir_build/src/build/matches/test.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 19 +++--------- compiler/rustc_mir_build/src/thir/mod.rs | 2 +- .../clippy_lints/src/loops/mut_range_bound.rs | 3 ++ 6 files changed, 25 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 53c87d71e13..ce816b6229e 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -165,7 +165,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields)) } - ExprKind::Closure { closure_id, substs, upvars, movability, fake_reads } => { + ExprKind::Closure { closure_id, substs, upvars, movability, ref fake_reads } => { // Convert the closure fake reads, if any, from `ExprRef` to mir `Place` // and push the fake reads. // This must come before creating the operands. This is required in case @@ -179,7 +179,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // match x { _ => () } // fake read of `x` // }; // ``` - // FIXME(RFC2229): Remove feature gate once diagnostics are improved if this.tcx.features().capture_disjoint_fields { for (thir_place, cause, hir_id) in fake_reads.into_iter() { @@ -193,8 +192,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { place_builder_resolved.into_place(this.tcx, this.typeck_results); this.cfg.push_fake_read( block, - this.source_info(this.tcx.hir().span(hir_id)), - cause, + this.source_info(this.tcx.hir().span(*hir_id)), + *cause, mir_place, ); } diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 6e8b25c9162..73fd3f0feb5 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -97,8 +97,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let scrutinee_place = unpack!(block = self.lower_scrutinee(block, scrutinee, scrutinee_span,)); - let mut arm_candidates = - self.create_match_candidates(scrutinee_place.clone(), &arms.clone()); + let mut arm_candidates = self.create_match_candidates(scrutinee_place.clone(), &arms); let match_has_guard = arms.iter().any(|arm| arm.guard.is_some()); let mut candidates = @@ -244,8 +243,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let arm_source_info = self.source_info(arm.span); let arm_scope = (arm.scope, arm_source_info); self.in_scope(arm_scope, arm.lint_level, |this| { - let body = arm.body; - // `try_upvars_resolved` may fail if it is unable to resolve the given // `PlaceBuilder` inside a closure. In this case, we don't want to include // a scrutinee place. `scrutinee_place_builder` will fail to be resolved @@ -264,7 +261,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .try_upvars_resolved(this.tcx, this.typeck_results) { scrutinee_place = - scrutinee_builder.clone().into_place(this.tcx, this.typeck_results); + scrutinee_builder.into_place(this.tcx, this.typeck_results); opt_scrutinee_place = Some((Some(&scrutinee_place), scrutinee_span)); } let scope = this.declare_bindings( @@ -524,9 +521,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if let Ok(match_pair_resolved) = initializer.clone().try_upvars_resolved(self.tcx, self.typeck_results) { - let place = match_pair_resolved - .clone() - .into_place(self.tcx, self.typeck_results); + let place = + match_pair_resolved.into_place(self.tcx, self.typeck_results); *match_place = Some(place); } } else { @@ -1480,7 +1476,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } TestKind::Switch { adt_def: _, ref mut variants } => { for candidate in candidates.iter() { - if !self.add_variants_to_switch(&match_place.clone(), candidate, variants) { + if !self.add_variants_to_switch(&match_place, candidate, variants) { break; } } @@ -1493,8 +1489,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if let Ok(match_place_resolved) = match_place.clone().try_upvars_resolved(self.tcx, self.typeck_results) { - let resolved_place = - match_place_resolved.clone().into_place(self.tcx, self.typeck_results); + let resolved_place = match_place_resolved.into_place(self.tcx, self.typeck_results); fb.insert(resolved_place); } } @@ -1577,7 +1572,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { target_blocks }; - self.perform_test(block, match_place.clone(), &test, make_target_blocks); + self.perform_test(block, match_place, &test, make_target_blocks); } /// Determine the fake borrows that are needed from a set of places that @@ -1811,9 +1806,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } Guard::IfLet(pat, scrutinee) => { let scrutinee_span = scrutinee.span; - let scrutinee_place_builder = unpack!( - block = self.lower_scrutinee(block, scrutinee.clone(), scrutinee_span) - ); + let scrutinee_place_builder = + unpack!(block = self.lower_scrutinee(block, scrutinee, scrutinee_span)); let mut guard_candidate = Candidate::new(scrutinee_place_builder.clone(), &pat, false); let wildcard = Pat::wildcard_from_ty(pat.ty); @@ -1827,12 +1821,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); let mut opt_scrutinee_place: Option<(Option<&Place<'tcx>>, Span)> = None; let scrutinee_place: Place<'tcx>; - if let Ok(scrutinee_builder) = scrutinee_place_builder - .clone() - .try_upvars_resolved(self.tcx, self.typeck_results) + if let Ok(scrutinee_builder) = + scrutinee_place_builder.try_upvars_resolved(self.tcx, self.typeck_results) { scrutinee_place = - scrutinee_builder.clone().into_place(self.tcx, self.typeck_results); + scrutinee_builder.into_place(self.tcx, self.typeck_results); opt_scrutinee_place = Some((Some(&scrutinee_place), scrutinee_span)); } self.declare_bindings( diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index b13a0ef8201..6820d4ba35a 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -158,7 +158,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) { let place: Place<'tcx>; if let Ok(test_place_builder) = - place_builder.clone().try_upvars_resolved(self.tcx, self.typeck_results) + place_builder.try_upvars_resolved(self.tcx, self.typeck_results) { place = test_place_builder.into_place(self.tcx, self.typeck_results); } else { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 2f58f2975b1..43d63d59ed9 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -455,28 +455,19 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> { ); // Convert the closure fake reads, if any, from hir `Place` to ExprRef - let fake_reads = match self.typeck_results().closure_fake_reads.get(&def_id) { + let fake_reads = match self.typeck_results.closure_fake_reads.get(&def_id) { Some(fake_reads) => fake_reads .iter() .map(|(place, cause, hir_id)| { - ( - self.arena - .alloc(self.convert_captured_hir_place(expr, place.clone())), - *cause, - *hir_id, - ) + let expr = self.convert_captured_hir_place(expr, place.clone()); + let expr_ref: &'thir Expr<'thir, 'tcx> = self.arena.alloc(expr); + (expr_ref, *cause, *hir_id) }) .collect(), None => Vec::new(), }; - ExprKind::Closure { - closure_id: def_id, - substs, - upvars, - movability, - fake_reads: fake_reads, - } + ExprKind::Closure { closure_id: def_id, substs, upvars, movability, fake_reads } } hir::ExprKind::Path(ref qpath) => { diff --git a/compiler/rustc_mir_build/src/thir/mod.rs b/compiler/rustc_mir_build/src/thir/mod.rs index 71d3093854d..6f20195db0b 100644 --- a/compiler/rustc_mir_build/src/thir/mod.rs +++ b/compiler/rustc_mir_build/src/thir/mod.rs @@ -281,7 +281,7 @@ pub enum ExprKind<'thir, 'tcx> { substs: UpvarSubsts<'tcx>, upvars: &'thir [Expr<'thir, 'tcx>], movability: Option, - fake_reads: Vec<(&'thir mut Expr<'thir, 'tcx>, FakeReadCause, hir::HirId)>, + fake_reads: Vec<(&'thir Expr<'thir, 'tcx>, FakeReadCause, hir::HirId)>, }, Literal { literal: &'tcx Const<'tcx>, diff --git a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs index 3ae592950f1..cb56512db60 100644 --- a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs +++ b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs @@ -4,6 +4,7 @@ use if_chain::if_chain; use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; +use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; use rustc_span::source_map::Span; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -106,6 +107,8 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { } } } + + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _:HirId) { } } impl MutatePairDelegate<'_, '_> {