Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 599ffab

Browse files
Remove region from adjustments
1 parent 9f57edf commit 599ffab

File tree

18 files changed

+65
-64
lines changed

18 files changed

+65
-64
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
15241524
matches!(
15251525
adj.kind,
15261526
ty::adjustment::Adjust::Borrow(ty::adjustment::AutoBorrow::Ref(
1527-
_,
15281527
ty::adjustment::AutoBorrowMutability::Not
15291528
| ty::adjustment::AutoBorrowMutability::Mut {
15301529
allow_two_phase_borrow: ty::adjustment::AllowTwoPhase::No

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5050
self.try_overloaded_deref(autoderef.span(), source).and_then(
5151
|InferOk { value: method, obligations: o }| {
5252
obligations.extend(o);
53-
if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() {
54-
Some(OverloadedDeref { region, mutbl, span: autoderef.span() })
53+
// FIXME: we should assert the sig is &T here... there's no reason for this to be fallible.
54+
if let ty::Ref(_, _, mutbl) = *method.sig.output().kind() {
55+
Some(OverloadedDeref { mutbl, span: autoderef.span() })
5556
} else {
5657
None
5758
}

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
307307
if borrow {
308308
// Check for &self vs &mut self in the method signature. Since this is either
309309
// the Fn or FnMut trait, it should be one of those.
310-
let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() else {
310+
let ty::Ref(_, _, mutbl) = method.sig.inputs()[0].kind() else {
311311
bug!("Expected `FnMut`/`Fn` to take receiver by-ref/by-mut")
312312
};
313313

@@ -317,7 +317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
317317
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::No);
318318

319319
autoref = Some(Adjustment {
320-
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
320+
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
321321
target: method.sig.inputs()[0],
322322
});
323323
}

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn identity(_: Ty<'_>) -> Vec<Adjustment<'_>> {
113113
vec![]
114114
}
115115

116-
fn simple<'tcx>(kind: Adjust<'tcx>) -> impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>> {
116+
fn simple<'tcx>(kind: Adjust) -> impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>> {
117117
move |target| vec![Adjustment { kind, target }]
118118
}
119119

@@ -484,14 +484,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
484484

485485
// Now apply the autoref. We have to extract the region out of
486486
// the final ref type we got.
487-
let ty::Ref(r_borrow, _, _) = ty.kind() else {
487+
let ty::Ref(..) = ty.kind() else {
488488
span_bug!(span, "expected a ref type, got {:?}", ty);
489489
};
490490
let mutbl = AutoBorrowMutability::new(mutbl_b, self.allow_two_phase);
491-
adjustments.push(Adjustment {
492-
kind: Adjust::Borrow(AutoBorrow::Ref(*r_borrow, mutbl)),
493-
target: ty,
494-
});
491+
adjustments.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), target: ty });
495492

496493
debug!("coerce_borrowed_pointer: succeeded ty={:?} adjustments={:?}", ty, adjustments);
497494

@@ -547,7 +544,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
547544
let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No);
548545

549546
Some((Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment {
550-
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)),
547+
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
551548
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
552549
}))
553550
}
@@ -827,7 +824,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
827824
};
828825

829826
let (pin, a_region, a_ty, mut_a) = extract_pin_mut(a)?;
830-
let (_, b_region, _b_ty, mut_b) = extract_pin_mut(b)?;
827+
let (_, _, _b_ty, mut_b) = extract_pin_mut(b)?;
831828

832829
coerce_mutbls(mut_a, mut_b)?;
833830

@@ -841,7 +838,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
841838
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
842839
// add the adjustments.
843840
self.unify_and(a, b, |_inner_ty| {
844-
vec![Adjustment { kind: Adjust::ReborrowPin(b_region, mut_b), target: b }]
841+
vec![Adjustment { kind: Adjust::ReborrowPin(mut_b), target: b }]
845842
})
846843
}
847844

@@ -1321,7 +1318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13211318
let noop = match self.typeck_results.borrow().expr_adjustments(expr) {
13221319
&[
13231320
Adjustment { kind: Adjust::Deref(_), .. },
1324-
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl_adj)), .. },
1321+
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl_adj)), .. },
13251322
] => {
13261323
match *self.node_ty(expr.hir_id).kind() {
13271324
ty::Ref(_, _, mt_orig) => {

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
781781
self.walk_autoref(expr, &place_with_id, autoref);
782782
}
783783

784-
adjustment::Adjust::ReborrowPin(_, mutbl) => {
784+
adjustment::Adjust::ReborrowPin(mutbl) => {
785785
// Reborrowing a Pin is like a combinations of a deref and a borrow, so we do
786786
// both.
787787
let bk = match mutbl {
@@ -804,15 +804,15 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
804804
&self,
805805
expr: &hir::Expr<'_>,
806806
base_place: &PlaceWithHirId<'tcx>,
807-
autoref: &adjustment::AutoBorrow<'tcx>,
807+
autoref: &adjustment::AutoBorrow,
808808
) {
809809
debug!(
810810
"walk_autoref(expr.hir_id={} base_place={:?} autoref={:?})",
811811
expr.hir_id, base_place, autoref
812812
);
813813

814814
match *autoref {
815-
adjustment::AutoBorrow::Ref(_, m) => {
815+
adjustment::AutoBorrow::Ref(m) => {
816816
self.delegate.borrow_mut().borrow(
817817
base_place,
818818
base_place.hir_id,
@@ -1283,7 +1283,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12831283
adjustment::Adjust::Deref(overloaded) => {
12841284
// Equivalent to *expr or something similar.
12851285
let base = if let Some(deref) = overloaded {
1286-
let ref_ty = Ty::new_ref(self.cx.tcx(), deref.region, target, deref.mutbl);
1286+
let ref_ty = Ty::new_ref(
1287+
self.cx.tcx(),
1288+
self.cx.tcx().lifetimes.re_erased,
1289+
target,
1290+
deref.mutbl,
1291+
);
12871292
self.cat_rvalue(expr.hir_id, ref_ty)
12881293
} else {
12891294
previous()?

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
264264

265265
let autoborrow_mut = adj.iter().any(|adj| {
266266
matches!(adj, &Adjustment {
267-
kind: Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. })),
267+
kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })),
268268
..
269269
})
270270
});

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
200200
// for two-phase borrows.
201201
let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::Yes);
202202

203-
adjustments.push(Adjustment {
204-
kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
205-
target,
206-
});
203+
adjustments
204+
.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), target });
207205

208206
if unsize {
209207
let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
@@ -250,7 +248,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
250248
_ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"),
251249
};
252250

253-
adjustments.push(Adjustment { kind: Adjust::ReborrowPin(region, mutbl), target });
251+
adjustments.push(Adjustment { kind: Adjust::ReborrowPin(mutbl), target });
254252
}
255253
None => {}
256254
}

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
256256
Ok(method) => {
257257
let by_ref_binop = !op.node.is_by_value();
258258
if is_assign == IsAssign::Yes || by_ref_binop {
259-
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() {
259+
if let ty::Ref(_, _, mutbl) = method.sig.inputs()[0].kind() {
260260
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes);
261261
let autoref = Adjustment {
262-
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
262+
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
263263
target: method.sig.inputs()[0],
264264
};
265265
self.apply_adjustments(lhs_expr, vec![autoref]);
266266
}
267267
}
268268
if by_ref_binop {
269-
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[1].kind() {
269+
if let ty::Ref(_, _, mutbl) = method.sig.inputs()[1].kind() {
270270
// Allow two-phase borrows for binops in initial deployment
271271
// since they desugar to methods
272272
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes);
273273

274274
let autoref = Adjustment {
275-
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
275+
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
276276
target: method.sig.inputs()[1],
277277
};
278278
// HACK(eddyb) Bypass checks due to reborrows being in

compiler/rustc_hir_typeck/src/place_op.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2929

3030
let ok = self.try_overloaded_deref(expr.span, oprnd_ty)?;
3131
let method = self.register_infer_ok_obligations(ok);
32-
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
32+
if let ty::Ref(_, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
3333
self.apply_adjustments(oprnd_expr, vec![Adjustment {
34-
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)),
34+
kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)),
3535
target: method.sig.inputs()[0],
3636
}]);
3737
} else {
@@ -158,7 +158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
158158
let mut adjustments = self.adjust_steps(autoderef);
159159
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
160160
adjustments.push(Adjustment {
161-
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)),
161+
kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)),
162162
target: Ty::new_imm_ref(self.tcx, *region, adjusted_ty),
163163
});
164164
} else {
@@ -289,9 +289,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
289289
)
290290
{
291291
let method = self.register_infer_ok_obligations(ok);
292-
if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() {
293-
*deref = OverloadedDeref { region, mutbl, span: deref.span };
294-
}
292+
let ty::Ref(_, _, mutbl) = *method.sig.output().kind() else {
293+
span_bug!(
294+
self.tcx.def_span(method.def_id),
295+
"expected DerefMut to return a &mut"
296+
);
297+
};
298+
*deref = OverloadedDeref { mutbl, span: deref.span };
295299
// If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
296300
// This helps avoid accidental drops.
297301
if inside_union
@@ -391,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
391395
// not the case today.
392396
allow_two_phase_borrow: AllowTwoPhase::No,
393397
};
394-
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl));
398+
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(mutbl));
395399
adjustment.target = Ty::new_ref(self.tcx, *region, source, mutbl.into());
396400
}
397401
source = adjustment.target;

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
16101610
}
16111611

16121612
for adj in cx.typeck_results().expr_adjustments(e) {
1613-
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
1613+
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(m)) = adj.kind {
16141614
match m {
16151615
adjustment::AutoBorrowMutability::Not => {
16161616
cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag);

0 commit comments

Comments
 (0)