Skip to content

Commit 3698e03

Browse files
committed
Remove span from UpvarCapture::ByValue
This span is unused and is superseded by capture_kind_expr_id in CaptureInfo
1 parent e012a19 commit 3698e03

File tree

11 files changed

+28
-45
lines changed

11 files changed

+28
-45
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
712712
}) => {
713713
capture_reason = format!("mutable borrow of `{}`", upvar);
714714
}
715-
ty::UpvarCapture::ByValue(_) => {
715+
ty::UpvarCapture::ByValue => {
716716
capture_reason = format!("possible mutation of `{}`", upvar);
717717
}
718718
_ => bug!("upvar `{}` borrowed, but not mutably", upvar),

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
186186
.map(|captured_place| {
187187
let capture = captured_place.info.capture_kind;
188188
let by_ref = match capture {
189-
ty::UpvarCapture::ByValue(_) => false,
189+
ty::UpvarCapture::ByValue => false,
190190
ty::UpvarCapture::ByRef(..) => true,
191191
};
192192
Upvar { place: captured_place.clone(), by_ref }

compiler/rustc_middle/src/ty/closure.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ pub enum UpvarCapture<'tcx> {
5656
/// Upvar is captured by value. This is always true when the
5757
/// closure is labeled `move`, but can also be true in other cases
5858
/// depending on inference.
59-
///
60-
/// If the upvar was inferred to be captured by value (e.g. `move`
61-
/// was not used), then the `Span` points to a usage that
62-
/// required it. There may be more than one such usage
63-
/// (e.g. `|| { a; a; }`), in which case we pick an
64-
/// arbitrary one.
65-
ByValue(Option<Span>),
59+
ByValue,
6660

6761
/// Upvar is captured by reference.
6862
ByRef(UpvarBorrow<'tcx>),

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
266266
// we need to deref it
267267
upvar_resolved_place_builder = match capture.info.capture_kind {
268268
ty::UpvarCapture::ByRef(_) => upvar_resolved_place_builder.deref(),
269-
ty::UpvarCapture::ByValue(_) => upvar_resolved_place_builder,
269+
ty::UpvarCapture::ByValue => upvar_resolved_place_builder,
270270
};
271271

272272
let next_projection = capture.place.projections.len();

compiler/rustc_mir_build/src/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
930930
let mut projs = closure_env_projs.clone();
931931
projs.push(ProjectionElem::Field(Field::new(i), ty));
932932
match capture {
933-
ty::UpvarCapture::ByValue(_) => {}
933+
ty::UpvarCapture::ByValue => {}
934934
ty::UpvarCapture::ByRef(..) => {
935935
projs.push(ProjectionElem::Deref);
936936
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ impl<'tcx> Cx<'tcx> {
11081108
let temp_lifetime = self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
11091109

11101110
match upvar_capture {
1111-
ty::UpvarCapture::ByValue(_) => captured_place_expr,
1111+
ty::UpvarCapture::ByValue => captured_place_expr,
11121112
ty::UpvarCapture::ByRef(upvar_borrow) => {
11131113
let borrow_kind = match upvar_borrow.kind {
11141114
ty::BorrowKind::ImmBorrow => BorrowKind::Shared,

compiler/rustc_passes/src/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
726726
);
727727
self.acc(self.exit_ln, var, ACC_READ | ACC_USE);
728728
}
729-
ty::UpvarCapture::ByValue(_) => {}
729+
ty::UpvarCapture::ByValue => {}
730730
}
731731
}
732732
}
@@ -1481,7 +1481,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
14811481
for (&var_hir_id, min_capture_list) in closure_min_captures {
14821482
for captured_place in min_capture_list {
14831483
match captured_place.info.capture_kind {
1484-
ty::UpvarCapture::ByValue(_) => {}
1484+
ty::UpvarCapture::ByValue => {}
14851485
ty::UpvarCapture::ByRef(..) => continue,
14861486
};
14871487
let span = captured_place.get_capture_kind_span(self.ir.tcx);

compiler/rustc_typeck/src/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
867867
all_captures_are_imm_borrow = false;
868868
}
869869
}
870-
ty::UpvarCapture::ByValue(_) => {
870+
ty::UpvarCapture::ByValue => {
871871
all_captures_are_imm_borrow = false;
872872
}
873873
}

compiler/rustc_typeck/src/check/upvar.rs

+17-28
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
409409
};
410410

411411
let updated = match capture_info.capture_kind {
412-
ty::UpvarCapture::ByValue(..) => match closure_kind {
412+
ty::UpvarCapture::ByValue => match closure_kind {
413413
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => {
414414
(ty::ClosureKind::FnOnce, Some((usage_span, place.clone())))
415415
}
@@ -1086,7 +1086,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10861086
for captured_place in root_var_min_capture_list.iter() {
10871087
match captured_place.info.capture_kind {
10881088
// Only care about captures that are moved into the closure
1089-
ty::UpvarCapture::ByValue(..) => {
1089+
ty::UpvarCapture::ByValue => {
10901090
projections_list.push(captured_place.place.projections.as_slice());
10911091
diagnostics_info.insert(UpvarMigrationInfo::CapturingPrecise {
10921092
source_expr: captured_place.info.path_expr_id,
@@ -1481,7 +1481,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14811481
// at the first Deref in `adjust_upvar_borrow_kind_for_consume` and then moved into
14821482
// the closure.
14831483
hir::CaptureBy::Value if !place.deref_tys().any(ty::TyS::is_ref) => {
1484-
ty::UpvarCapture::ByValue(None)
1484+
ty::UpvarCapture::ByValue
14851485
}
14861486
hir::CaptureBy::Value | hir::CaptureBy::Ref => {
14871487
let origin = UpvarRegion(upvar_id, closure_span);
@@ -1678,7 +1678,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
16781678
capture_kind: UpvarCapture<'tcx>,
16791679
) -> Ty<'tcx> {
16801680
match capture_kind {
1681-
ty::UpvarCapture::ByValue(_) => ty,
1681+
ty::UpvarCapture::ByValue => ty,
16821682
ty::UpvarCapture::ByRef(borrow) => tcx
16831683
.mk_ref(borrow.region, ty::TypeAndMut { ty: ty, mutbl: borrow.kind.to_mutbl_lossy() }),
16841684
}
@@ -1756,12 +1756,10 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
17561756

17571757
debug!(?upvar_id);
17581758

1759-
let usage_span = tcx.hir().span(diag_expr_id);
1760-
17611759
let capture_info = ty::CaptureInfo {
17621760
capture_kind_expr_id: Some(diag_expr_id),
17631761
path_expr_id: Some(diag_expr_id),
1764-
capture_kind: ty::UpvarCapture::ByValue(Some(usage_span)),
1762+
capture_kind: ty::UpvarCapture::ByValue,
17651763
};
17661764

17671765
let curr_info = self.capture_information[&place_with_id.place];
@@ -1841,7 +1839,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
18411839

18421840
debug!(?curr_capture_info);
18431841

1844-
if let ty::UpvarCapture::ByValue(_) = curr_capture_info.capture_kind {
1842+
if let ty::UpvarCapture::ByValue = curr_capture_info.capture_kind {
18451843
// It's already captured by value, we don't need to do anything here
18461844
return;
18471845
} 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> {
19611959
},
19621960

19631961
// Just truncating the place will never cause capture kind to be updated to ByValue
1964-
ty::UpvarCapture::ByValue(..) => unreachable!(),
1962+
ty::UpvarCapture::ByValue => unreachable!(),
19651963
}
19661964
}
19671965

@@ -1980,7 +1978,7 @@ fn restrict_precision_for_drop_types<'a, 'tcx>(
19801978
) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) {
19811979
let is_copy_type = fcx.infcx.type_is_copy_modulo_regions(fcx.param_env, place.ty(), span);
19821980

1983-
if let (false, UpvarCapture::ByValue(..)) = (is_copy_type, curr_mode) {
1981+
if let (false, UpvarCapture::ByValue) = (is_copy_type, curr_mode) {
19841982
for i in 0..place.projections.len() {
19851983
match place.ty_before_projection(i).kind() {
19861984
ty::Adt(def, _) if def.destructor(fcx.tcx).is_some() => {
@@ -2070,9 +2068,7 @@ fn adjust_for_move_closure<'tcx>(
20702068
truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx);
20712069
}
20722070

2073-
// AMAN: I think we don't need the span inside the ByValue anymore
2074-
// we have more detailed span in CaptureInfo
2075-
(place, ty::UpvarCapture::ByValue(None))
2071+
(place, ty::UpvarCapture::ByValue)
20762072
}
20772073

20782074
/// Adjust closure capture just that if taking ownership of data, only move data
@@ -2085,7 +2081,7 @@ fn adjust_for_non_move_closure<'tcx>(
20852081
place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref);
20862082

20872083
match kind {
2088-
ty::UpvarCapture::ByValue(..) => {
2084+
ty::UpvarCapture::ByValue => {
20892085
if let Some(idx) = contains_deref {
20902086
truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx);
20912087
}
@@ -2128,7 +2124,7 @@ fn construct_capture_kind_reason_string<'tcx>(
21282124
let place_str = construct_place_string(tcx, place);
21292125

21302126
let capture_kind_str = match capture_info.capture_kind {
2131-
ty::UpvarCapture::ByValue(_) => "ByValue".into(),
2127+
ty::UpvarCapture::ByValue => "ByValue".into(),
21322128
ty::UpvarCapture::ByRef(borrow) => format!("{:?}", borrow.kind),
21332129
};
21342130

@@ -2149,7 +2145,7 @@ fn construct_capture_info_string<'tcx>(
21492145
let place_str = construct_place_string(tcx, place);
21502146

21512147
let capture_kind_str = match capture_info.capture_kind {
2152-
ty::UpvarCapture::ByValue(_) => "ByValue".into(),
2148+
ty::UpvarCapture::ByValue => "ByValue".into(),
21532149
ty::UpvarCapture::ByRef(borrow) => format!("{:?}", borrow.kind),
21542150
};
21552151
format!("{} -> {}", place_str, capture_kind_str)
@@ -2240,18 +2236,11 @@ fn determine_capture_info<'tcx>(
22402236
// If the capture kind is equivalent then, we don't need to escalate and can compare the
22412237
// expressions.
22422238
let eq_capture_kind = match (capture_info_a.capture_kind, capture_info_b.capture_kind) {
2243-
(ty::UpvarCapture::ByValue(_), ty::UpvarCapture::ByValue(_)) => {
2244-
// We don't need to worry about the spans being ignored here.
2245-
//
2246-
// The expr_id in capture_info corresponds to the span that is stored within
2247-
// ByValue(span) and therefore it gets handled with priortizing based on
2248-
// expressions below.
2249-
true
2250-
}
2239+
(ty::UpvarCapture::ByValue, ty::UpvarCapture::ByValue) => true,
22512240
(ty::UpvarCapture::ByRef(ref_a), ty::UpvarCapture::ByRef(ref_b)) => {
22522241
ref_a.kind == ref_b.kind
22532242
}
2254-
(ty::UpvarCapture::ByValue(_), _) | (ty::UpvarCapture::ByRef(_), _) => false,
2243+
(ty::UpvarCapture::ByValue, _) | (ty::UpvarCapture::ByRef(_), _) => false,
22552244
};
22562245

22572246
if eq_capture_kind {
@@ -2263,8 +2252,8 @@ fn determine_capture_info<'tcx>(
22632252
// We select the CaptureKind which ranks higher based the following priority order:
22642253
// ByValue > MutBorrow > UniqueImmBorrow > ImmBorrow
22652254
match (capture_info_a.capture_kind, capture_info_b.capture_kind) {
2266-
(ty::UpvarCapture::ByValue(_), _) => capture_info_a,
2267-
(_, ty::UpvarCapture::ByValue(_)) => capture_info_b,
2255+
(ty::UpvarCapture::ByValue, _) => capture_info_a,
2256+
(_, ty::UpvarCapture::ByValue) => capture_info_b,
22682257
(ty::UpvarCapture::ByRef(ref_a), ty::UpvarCapture::ByRef(ref_b)) => {
22692258
match (ref_a.kind, ref_b.kind) {
22702259
// Take LHS:
@@ -2319,7 +2308,7 @@ fn truncate_place_to_len_and_update_capture_kind<'tcx>(
23192308
}
23202309

23212310
ty::UpvarCapture::ByRef(..) => {}
2322-
ty::UpvarCapture::ByValue(..) => {}
2311+
ty::UpvarCapture::ByValue => {}
23232312
}
23242313

23252314
place.projections.truncate(len);

compiler/rustc_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
796796
);
797797

798798
match capture_info.capture_kind {
799-
ty::UpvarCapture::ByValue(_) => {
799+
ty::UpvarCapture::ByValue => {
800800
self.delegate_consume(&place_with_id, place_with_id.hir_id);
801801
}
802802
ty::UpvarCapture::ByRef(upvar_borrow) => {

src/tools/clippy/clippy_utils/src/lib.rs

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

0 commit comments

Comments
 (0)