1
Fork 0

Remove span from UpvarCapture::ByValue

This span is unused and is superseded by capture_kind_expr_id in CaptureInfo
This commit is contained in:
Gary Guo 2021-10-09 22:11:13 +01:00
parent e012a191d7
commit 3698e03fb6
11 changed files with 28 additions and 45 deletions

View file

@ -712,7 +712,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}) => { }) => {
capture_reason = format!("mutable borrow of `{}`", upvar); capture_reason = format!("mutable borrow of `{}`", upvar);
} }
ty::UpvarCapture::ByValue(_) => { ty::UpvarCapture::ByValue => {
capture_reason = format!("possible mutation of `{}`", upvar); capture_reason = format!("possible mutation of `{}`", upvar);
} }
_ => bug!("upvar `{}` borrowed, but not mutably", upvar), _ => bug!("upvar `{}` borrowed, but not mutably", upvar),

View file

@ -186,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
.map(|captured_place| { .map(|captured_place| {
let capture = captured_place.info.capture_kind; let capture = captured_place.info.capture_kind;
let by_ref = match capture { let by_ref = match capture {
ty::UpvarCapture::ByValue(_) => false, ty::UpvarCapture::ByValue => false,
ty::UpvarCapture::ByRef(..) => true, ty::UpvarCapture::ByRef(..) => true,
}; };
Upvar { place: captured_place.clone(), by_ref } Upvar { place: captured_place.clone(), by_ref }

View file

@ -56,13 +56,7 @@ pub enum UpvarCapture<'tcx> {
/// Upvar is captured by value. This is always true when the /// Upvar is captured by value. This is always true when the
/// closure is labeled `move`, but can also be true in other cases /// closure is labeled `move`, but can also be true in other cases
/// depending on inference. /// depending on inference.
/// ByValue,
/// If the upvar was inferred to be captured by value (e.g. `move`
/// was not used), then the `Span` points to a usage that
/// required it. There may be more than one such usage
/// (e.g. `|| { a; a; }`), in which case we pick an
/// arbitrary one.
ByValue(Option<Span>),
/// Upvar is captured by reference. /// Upvar is captured by reference.
ByRef(UpvarBorrow<'tcx>), ByRef(UpvarBorrow<'tcx>),

View file

@ -266,7 +266,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
// we need to deref it // we need to deref it
upvar_resolved_place_builder = match capture.info.capture_kind { upvar_resolved_place_builder = match capture.info.capture_kind {
ty::UpvarCapture::ByRef(_) => upvar_resolved_place_builder.deref(), ty::UpvarCapture::ByRef(_) => upvar_resolved_place_builder.deref(),
ty::UpvarCapture::ByValue(_) => upvar_resolved_place_builder, ty::UpvarCapture::ByValue => upvar_resolved_place_builder,
}; };
let next_projection = capture.place.projections.len(); let next_projection = capture.place.projections.len();

View file

@ -930,7 +930,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let mut projs = closure_env_projs.clone(); let mut projs = closure_env_projs.clone();
projs.push(ProjectionElem::Field(Field::new(i), ty)); projs.push(ProjectionElem::Field(Field::new(i), ty));
match capture { match capture {
ty::UpvarCapture::ByValue(_) => {} ty::UpvarCapture::ByValue => {}
ty::UpvarCapture::ByRef(..) => { ty::UpvarCapture::ByRef(..) => {
projs.push(ProjectionElem::Deref); projs.push(ProjectionElem::Deref);
} }

View file

@ -1108,7 +1108,7 @@ impl<'tcx> Cx<'tcx> {
let temp_lifetime = self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); let temp_lifetime = self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
match upvar_capture { match upvar_capture {
ty::UpvarCapture::ByValue(_) => captured_place_expr, ty::UpvarCapture::ByValue => captured_place_expr,
ty::UpvarCapture::ByRef(upvar_borrow) => { ty::UpvarCapture::ByRef(upvar_borrow) => {
let borrow_kind = match upvar_borrow.kind { let borrow_kind = match upvar_borrow.kind {
ty::BorrowKind::ImmBorrow => BorrowKind::Shared, ty::BorrowKind::ImmBorrow => BorrowKind::Shared,

View file

@ -726,7 +726,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
); );
self.acc(self.exit_ln, var, ACC_READ | ACC_USE); self.acc(self.exit_ln, var, ACC_READ | ACC_USE);
} }
ty::UpvarCapture::ByValue(_) => {} ty::UpvarCapture::ByValue => {}
} }
} }
} }
@ -1481,7 +1481,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
for (&var_hir_id, min_capture_list) in closure_min_captures { for (&var_hir_id, min_capture_list) in closure_min_captures {
for captured_place in min_capture_list { for captured_place in min_capture_list {
match captured_place.info.capture_kind { match captured_place.info.capture_kind {
ty::UpvarCapture::ByValue(_) => {} ty::UpvarCapture::ByValue => {}
ty::UpvarCapture::ByRef(..) => continue, ty::UpvarCapture::ByRef(..) => continue,
}; };
let span = captured_place.get_capture_kind_span(self.ir.tcx); let span = captured_place.get_capture_kind_span(self.ir.tcx);

View file

@ -867,7 +867,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
all_captures_are_imm_borrow = false; all_captures_are_imm_borrow = false;
} }
} }
ty::UpvarCapture::ByValue(_) => { ty::UpvarCapture::ByValue => {
all_captures_are_imm_borrow = false; all_captures_are_imm_borrow = false;
} }
} }

View file

@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
let updated = match capture_info.capture_kind { let updated = match capture_info.capture_kind {
ty::UpvarCapture::ByValue(..) => match closure_kind { ty::UpvarCapture::ByValue => match closure_kind {
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => { ty::ClosureKind::Fn | ty::ClosureKind::FnMut => {
(ty::ClosureKind::FnOnce, Some((usage_span, place.clone()))) (ty::ClosureKind::FnOnce, Some((usage_span, place.clone())))
} }
@ -1086,7 +1086,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
for captured_place in root_var_min_capture_list.iter() { for captured_place in root_var_min_capture_list.iter() {
match captured_place.info.capture_kind { match captured_place.info.capture_kind {
// Only care about captures that are moved into the closure // Only care about captures that are moved into the closure
ty::UpvarCapture::ByValue(..) => { ty::UpvarCapture::ByValue => {
projections_list.push(captured_place.place.projections.as_slice()); projections_list.push(captured_place.place.projections.as_slice());
diagnostics_info.insert(UpvarMigrationInfo::CapturingPrecise { diagnostics_info.insert(UpvarMigrationInfo::CapturingPrecise {
source_expr: captured_place.info.path_expr_id, source_expr: captured_place.info.path_expr_id,
@ -1481,7 +1481,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// at the first Deref in `adjust_upvar_borrow_kind_for_consume` and then moved into // at the first Deref in `adjust_upvar_borrow_kind_for_consume` and then moved into
// the closure. // the closure.
hir::CaptureBy::Value if !place.deref_tys().any(ty::TyS::is_ref) => { hir::CaptureBy::Value if !place.deref_tys().any(ty::TyS::is_ref) => {
ty::UpvarCapture::ByValue(None) ty::UpvarCapture::ByValue
} }
hir::CaptureBy::Value | hir::CaptureBy::Ref => { hir::CaptureBy::Value | hir::CaptureBy::Ref => {
let origin = UpvarRegion(upvar_id, closure_span); let origin = UpvarRegion(upvar_id, closure_span);
@ -1678,7 +1678,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
capture_kind: UpvarCapture<'tcx>, capture_kind: UpvarCapture<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
match capture_kind { match capture_kind {
ty::UpvarCapture::ByValue(_) => ty, ty::UpvarCapture::ByValue => ty,
ty::UpvarCapture::ByRef(borrow) => tcx ty::UpvarCapture::ByRef(borrow) => tcx
.mk_ref(borrow.region, ty::TypeAndMut { ty: ty, mutbl: borrow.kind.to_mutbl_lossy() }), .mk_ref(borrow.region, ty::TypeAndMut { ty: ty, mutbl: borrow.kind.to_mutbl_lossy() }),
} }
@ -1756,12 +1756,10 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
debug!(?upvar_id); debug!(?upvar_id);
let usage_span = tcx.hir().span(diag_expr_id);
let capture_info = ty::CaptureInfo { let capture_info = ty::CaptureInfo {
capture_kind_expr_id: Some(diag_expr_id), capture_kind_expr_id: Some(diag_expr_id),
path_expr_id: Some(diag_expr_id), path_expr_id: Some(diag_expr_id),
capture_kind: ty::UpvarCapture::ByValue(Some(usage_span)), capture_kind: ty::UpvarCapture::ByValue,
}; };
let curr_info = self.capture_information[&place_with_id.place]; let curr_info = self.capture_information[&place_with_id.place];
@ -1841,7 +1839,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
debug!(?curr_capture_info); debug!(?curr_capture_info);
if let ty::UpvarCapture::ByValue(_) = curr_capture_info.capture_kind { if let ty::UpvarCapture::ByValue = curr_capture_info.capture_kind {
// It's already captured by value, we don't need to do anything here // It's already captured by value, we don't need to do anything here
return; return;
} else if let ty::UpvarCapture::ByRef(curr_upvar_borrow) = curr_capture_info.capture_kind { } else if let ty::UpvarCapture::ByRef(curr_upvar_borrow) = curr_capture_info.capture_kind {
@ -1961,7 +1959,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
}, },
// Just truncating the place will never cause capture kind to be updated to ByValue // Just truncating the place will never cause capture kind to be updated to ByValue
ty::UpvarCapture::ByValue(..) => unreachable!(), ty::UpvarCapture::ByValue => unreachable!(),
} }
} }
@ -1980,7 +1978,7 @@ fn restrict_precision_for_drop_types<'a, 'tcx>(
) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) {
let is_copy_type = fcx.infcx.type_is_copy_modulo_regions(fcx.param_env, place.ty(), span); let is_copy_type = fcx.infcx.type_is_copy_modulo_regions(fcx.param_env, place.ty(), span);
if let (false, UpvarCapture::ByValue(..)) = (is_copy_type, curr_mode) { if let (false, UpvarCapture::ByValue) = (is_copy_type, curr_mode) {
for i in 0..place.projections.len() { for i in 0..place.projections.len() {
match place.ty_before_projection(i).kind() { match place.ty_before_projection(i).kind() {
ty::Adt(def, _) if def.destructor(fcx.tcx).is_some() => { ty::Adt(def, _) if def.destructor(fcx.tcx).is_some() => {
@ -2070,9 +2068,7 @@ fn adjust_for_move_closure<'tcx>(
truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx); truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx);
} }
// AMAN: I think we don't need the span inside the ByValue anymore (place, ty::UpvarCapture::ByValue)
// we have more detailed span in CaptureInfo
(place, ty::UpvarCapture::ByValue(None))
} }
/// Adjust closure capture just that if taking ownership of data, only move data /// Adjust closure capture just that if taking ownership of data, only move data
@ -2085,7 +2081,7 @@ fn adjust_for_non_move_closure<'tcx>(
place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref); place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref);
match kind { match kind {
ty::UpvarCapture::ByValue(..) => { ty::UpvarCapture::ByValue => {
if let Some(idx) = contains_deref { if let Some(idx) = contains_deref {
truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx); truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx);
} }
@ -2128,7 +2124,7 @@ fn construct_capture_kind_reason_string<'tcx>(
let place_str = construct_place_string(tcx, place); let place_str = construct_place_string(tcx, place);
let capture_kind_str = match capture_info.capture_kind { let capture_kind_str = match capture_info.capture_kind {
ty::UpvarCapture::ByValue(_) => "ByValue".into(), ty::UpvarCapture::ByValue => "ByValue".into(),
ty::UpvarCapture::ByRef(borrow) => format!("{:?}", borrow.kind), ty::UpvarCapture::ByRef(borrow) => format!("{:?}", borrow.kind),
}; };
@ -2149,7 +2145,7 @@ fn construct_capture_info_string<'tcx>(
let place_str = construct_place_string(tcx, place); let place_str = construct_place_string(tcx, place);
let capture_kind_str = match capture_info.capture_kind { let capture_kind_str = match capture_info.capture_kind {
ty::UpvarCapture::ByValue(_) => "ByValue".into(), ty::UpvarCapture::ByValue => "ByValue".into(),
ty::UpvarCapture::ByRef(borrow) => format!("{:?}", borrow.kind), ty::UpvarCapture::ByRef(borrow) => format!("{:?}", borrow.kind),
}; };
format!("{} -> {}", place_str, capture_kind_str) format!("{} -> {}", place_str, capture_kind_str)
@ -2240,18 +2236,11 @@ fn determine_capture_info<'tcx>(
// If the capture kind is equivalent then, we don't need to escalate and can compare the // If the capture kind is equivalent then, we don't need to escalate and can compare the
// expressions. // expressions.
let eq_capture_kind = match (capture_info_a.capture_kind, capture_info_b.capture_kind) { let eq_capture_kind = match (capture_info_a.capture_kind, capture_info_b.capture_kind) {
(ty::UpvarCapture::ByValue(_), ty::UpvarCapture::ByValue(_)) => { (ty::UpvarCapture::ByValue, ty::UpvarCapture::ByValue) => true,
// We don't need to worry about the spans being ignored here.
//
// The expr_id in capture_info corresponds to the span that is stored within
// ByValue(span) and therefore it gets handled with priortizing based on
// expressions below.
true
}
(ty::UpvarCapture::ByRef(ref_a), ty::UpvarCapture::ByRef(ref_b)) => { (ty::UpvarCapture::ByRef(ref_a), ty::UpvarCapture::ByRef(ref_b)) => {
ref_a.kind == ref_b.kind ref_a.kind == ref_b.kind
} }
(ty::UpvarCapture::ByValue(_), _) | (ty::UpvarCapture::ByRef(_), _) => false, (ty::UpvarCapture::ByValue, _) | (ty::UpvarCapture::ByRef(_), _) => false,
}; };
if eq_capture_kind { if eq_capture_kind {
@ -2263,8 +2252,8 @@ fn determine_capture_info<'tcx>(
// We select the CaptureKind which ranks higher based the following priority order: // We select the CaptureKind which ranks higher based the following priority order:
// ByValue > MutBorrow > UniqueImmBorrow > ImmBorrow // ByValue > MutBorrow > UniqueImmBorrow > ImmBorrow
match (capture_info_a.capture_kind, capture_info_b.capture_kind) { match (capture_info_a.capture_kind, capture_info_b.capture_kind) {
(ty::UpvarCapture::ByValue(_), _) => capture_info_a, (ty::UpvarCapture::ByValue, _) => capture_info_a,
(_, ty::UpvarCapture::ByValue(_)) => capture_info_b, (_, ty::UpvarCapture::ByValue) => capture_info_b,
(ty::UpvarCapture::ByRef(ref_a), ty::UpvarCapture::ByRef(ref_b)) => { (ty::UpvarCapture::ByRef(ref_a), ty::UpvarCapture::ByRef(ref_b)) => {
match (ref_a.kind, ref_b.kind) { match (ref_a.kind, ref_b.kind) {
// Take LHS: // Take LHS:
@ -2319,7 +2308,7 @@ fn truncate_place_to_len_and_update_capture_kind<'tcx>(
} }
ty::UpvarCapture::ByRef(..) => {} ty::UpvarCapture::ByRef(..) => {}
ty::UpvarCapture::ByValue(..) => {} ty::UpvarCapture::ByValue => {}
} }
place.projections.truncate(len); place.projections.truncate(len);

View file

@ -796,7 +796,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
); );
match capture_info.capture_kind { match capture_info.capture_kind {
ty::UpvarCapture::ByValue(_) => { ty::UpvarCapture::ByValue => {
self.delegate_consume(&place_with_id, place_with_id.hir_id); self.delegate_consume(&place_with_id, place_with_id.hir_id);
} }
ty::UpvarCapture::ByRef(upvar_borrow) => { ty::UpvarCapture::ByRef(upvar_borrow) => {

View file

@ -969,7 +969,7 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) ->
}; };
if !self.locals.contains(&local_id) { if !self.locals.contains(&local_id) {
let capture = match capture.info.capture_kind { let capture = match capture.info.capture_kind {
UpvarCapture::ByValue(_) => CaptureKind::Value, UpvarCapture::ByValue => CaptureKind::Value,
UpvarCapture::ByRef(borrow) => match borrow.kind { UpvarCapture::ByRef(borrow) => match borrow.kind {
BorrowKind::ImmBorrow => CaptureKind::Ref(Mutability::Not), BorrowKind::ImmBorrow => CaptureKind::Ref(Mutability::Not),
BorrowKind::UniqueImmBorrow | BorrowKind::MutBorrow => { BorrowKind::UniqueImmBorrow | BorrowKind::MutBorrow => {