Skip to content

Commit

Permalink
Fix error after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Mar 15, 2021
1 parent 22eaffe commit 189d206
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 39 deletions.
7 changes: 3 additions & 4 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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,
);
}
Expand Down
31 changes: 12 additions & 19 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 5 additions & 14 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub enum ExprKind<'thir, 'tcx> {
substs: UpvarSubsts<'tcx>,
upvars: &'thir [Expr<'thir, 'tcx>],
movability: Option<hir::Movability>,
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>,
Expand Down
3 changes: 3 additions & 0 deletions src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<'_, '_> {
Expand Down

0 comments on commit 189d206

Please sign in to comment.