Auto merge of #132301 - compiler-errors:adjust, r=lcnr

Remove region from adjustments

It's not necessary to store this region, because it's only used in THIR and MemCat/ExprUse, both of which already basically only deal with erased regions anyways.
This commit is contained in:
bors 2024-10-31 10:17:49 +00:00
commit 9ccfedf186
18 changed files with 65 additions and 64 deletions

View File

@ -1525,7 +1525,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
matches!( matches!(
adj.kind, adj.kind,
ty::adjustment::Adjust::Borrow(ty::adjustment::AutoBorrow::Ref( ty::adjustment::Adjust::Borrow(ty::adjustment::AutoBorrow::Ref(
_,
ty::adjustment::AutoBorrowMutability::Not ty::adjustment::AutoBorrowMutability::Not
| ty::adjustment::AutoBorrowMutability::Mut { | ty::adjustment::AutoBorrowMutability::Mut {
allow_two_phase_borrow: ty::adjustment::AllowTwoPhase::No allow_two_phase_borrow: ty::adjustment::AllowTwoPhase::No

View File

@ -50,8 +50,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.try_overloaded_deref(autoderef.span(), source).and_then( self.try_overloaded_deref(autoderef.span(), source).and_then(
|InferOk { value: method, obligations: o }| { |InferOk { value: method, obligations: o }| {
obligations.extend(o); obligations.extend(o);
if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() { // FIXME: we should assert the sig is &T here... there's no reason for this to be fallible.
Some(OverloadedDeref { region, mutbl, span: autoderef.span() }) if let ty::Ref(_, _, mutbl) = *method.sig.output().kind() {
Some(OverloadedDeref { mutbl, span: autoderef.span() })
} else { } else {
None None
} }

View File

@ -307,7 +307,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if borrow { if borrow {
// Check for &self vs &mut self in the method signature. Since this is either // Check for &self vs &mut self in the method signature. Since this is either
// the Fn or FnMut trait, it should be one of those. // the Fn or FnMut trait, it should be one of those.
let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() else { let ty::Ref(_, _, mutbl) = method.sig.inputs()[0].kind() else {
bug!("Expected `FnMut`/`Fn` to take receiver by-ref/by-mut") bug!("Expected `FnMut`/`Fn` to take receiver by-ref/by-mut")
}; };
@ -317,7 +317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::No); let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::No);
autoref = Some(Adjustment { autoref = Some(Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target: method.sig.inputs()[0], target: method.sig.inputs()[0],
}); });
} }

View File

@ -113,7 +113,7 @@ fn identity(_: Ty<'_>) -> Vec<Adjustment<'_>> {
vec![] vec![]
} }
fn simple<'tcx>(kind: Adjust<'tcx>) -> impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>> { fn simple<'tcx>(kind: Adjust) -> impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>> {
move |target| vec![Adjustment { kind, target }] move |target| vec![Adjustment { kind, target }]
} }
@ -484,14 +484,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// Now apply the autoref. We have to extract the region out of // Now apply the autoref. We have to extract the region out of
// the final ref type we got. // the final ref type we got.
let ty::Ref(r_borrow, _, _) = ty.kind() else { let ty::Ref(..) = ty.kind() else {
span_bug!(span, "expected a ref type, got {:?}", ty); span_bug!(span, "expected a ref type, got {:?}", ty);
}; };
let mutbl = AutoBorrowMutability::new(mutbl_b, self.allow_two_phase); let mutbl = AutoBorrowMutability::new(mutbl_b, self.allow_two_phase);
adjustments.push(Adjustment { adjustments.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), target: ty });
kind: Adjust::Borrow(AutoBorrow::Ref(*r_borrow, mutbl)),
target: ty,
});
debug!("coerce_borrowed_pointer: succeeded ty={:?} adjustments={:?}", ty, adjustments); debug!("coerce_borrowed_pointer: succeeded ty={:?} adjustments={:?}", ty, adjustments);
@ -547,7 +544,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No); let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No);
Some((Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { Some((Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b), target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
})) }))
} }
@ -827,7 +824,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
}; };
let (pin, a_region, a_ty, mut_a) = extract_pin_mut(a)?; let (pin, a_region, a_ty, mut_a) = extract_pin_mut(a)?;
let (_, b_region, _b_ty, mut_b) = extract_pin_mut(b)?; let (_, _, _b_ty, mut_b) = extract_pin_mut(b)?;
coerce_mutbls(mut_a, mut_b)?; coerce_mutbls(mut_a, mut_b)?;
@ -841,7 +838,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we // To complete the reborrow, we need to make sure we can unify the inner types, and if so we
// add the adjustments. // add the adjustments.
self.unify_and(a, b, |_inner_ty| { self.unify_and(a, b, |_inner_ty| {
vec![Adjustment { kind: Adjust::ReborrowPin(b_region, mut_b), target: b }] vec![Adjustment { kind: Adjust::ReborrowPin(mut_b), target: b }]
}) })
} }
@ -1321,7 +1318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let noop = match self.typeck_results.borrow().expr_adjustments(expr) { let noop = match self.typeck_results.borrow().expr_adjustments(expr) {
&[ &[
Adjustment { kind: Adjust::Deref(_), .. }, Adjustment { kind: Adjust::Deref(_), .. },
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl_adj)), .. }, Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl_adj)), .. },
] => { ] => {
match *self.node_ty(expr.hir_id).kind() { match *self.node_ty(expr.hir_id).kind() {
ty::Ref(_, _, mt_orig) => { ty::Ref(_, _, mt_orig) => {

View File

@ -781,7 +781,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
self.walk_autoref(expr, &place_with_id, autoref); self.walk_autoref(expr, &place_with_id, autoref);
} }
adjustment::Adjust::ReborrowPin(_, mutbl) => { adjustment::Adjust::ReborrowPin(mutbl) => {
// Reborrowing a Pin is like a combinations of a deref and a borrow, so we do // Reborrowing a Pin is like a combinations of a deref and a borrow, so we do
// both. // both.
let bk = match mutbl { let bk = match mutbl {
@ -804,7 +804,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
&self, &self,
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
base_place: &PlaceWithHirId<'tcx>, base_place: &PlaceWithHirId<'tcx>,
autoref: &adjustment::AutoBorrow<'tcx>, autoref: &adjustment::AutoBorrow,
) { ) {
debug!( debug!(
"walk_autoref(expr.hir_id={} base_place={:?} autoref={:?})", "walk_autoref(expr.hir_id={} base_place={:?} autoref={:?})",
@ -812,7 +812,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
); );
match *autoref { match *autoref {
adjustment::AutoBorrow::Ref(_, m) => { adjustment::AutoBorrow::Ref(m) => {
self.delegate.borrow_mut().borrow( self.delegate.borrow_mut().borrow(
base_place, base_place,
base_place.hir_id, base_place.hir_id,
@ -1283,7 +1283,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
adjustment::Adjust::Deref(overloaded) => { adjustment::Adjust::Deref(overloaded) => {
// Equivalent to *expr or something similar. // Equivalent to *expr or something similar.
let base = if let Some(deref) = overloaded { let base = if let Some(deref) = overloaded {
let ref_ty = Ty::new_ref(self.cx.tcx(), deref.region, target, deref.mutbl); let ref_ty = Ty::new_ref(
self.cx.tcx(),
self.cx.tcx().lifetimes.re_erased,
target,
deref.mutbl,
);
self.cat_rvalue(expr.hir_id, ref_ty) self.cat_rvalue(expr.hir_id, ref_ty)
} else { } else {
previous()? previous()?

View File

@ -264,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let autoborrow_mut = adj.iter().any(|adj| { let autoborrow_mut = adj.iter().any(|adj| {
matches!(adj, &Adjustment { matches!(adj, &Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. })), kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })),
.. ..
}) })
}); });

View File

@ -200,10 +200,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// for two-phase borrows. // for two-phase borrows.
let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::Yes); let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::Yes);
adjustments.push(Adjustment { adjustments
kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)), .push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), target });
target,
});
if unsize { if unsize {
let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() { let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
@ -250,7 +248,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
_ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"), _ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"),
}; };
adjustments.push(Adjustment { kind: Adjust::ReborrowPin(region, mutbl), target }); adjustments.push(Adjustment { kind: Adjust::ReborrowPin(mutbl), target });
} }
None => {} None => {}
} }

View File

@ -256,23 +256,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(method) => { Ok(method) => {
let by_ref_binop = !op.node.is_by_value(); let by_ref_binop = !op.node.is_by_value();
if is_assign == IsAssign::Yes || by_ref_binop { if is_assign == IsAssign::Yes || by_ref_binop {
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() { if let ty::Ref(_, _, mutbl) = method.sig.inputs()[0].kind() {
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes); let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes);
let autoref = Adjustment { let autoref = Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target: method.sig.inputs()[0], target: method.sig.inputs()[0],
}; };
self.apply_adjustments(lhs_expr, vec![autoref]); self.apply_adjustments(lhs_expr, vec![autoref]);
} }
} }
if by_ref_binop { if by_ref_binop {
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[1].kind() { if let ty::Ref(_, _, mutbl) = method.sig.inputs()[1].kind() {
// Allow two-phase borrows for binops in initial deployment // Allow two-phase borrows for binops in initial deployment
// since they desugar to methods // since they desugar to methods
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes); let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes);
let autoref = Adjustment { let autoref = Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target: method.sig.inputs()[1], target: method.sig.inputs()[1],
}; };
// HACK(eddyb) Bypass checks due to reborrows being in // HACK(eddyb) Bypass checks due to reborrows being in

View File

@ -29,9 +29,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ok = self.try_overloaded_deref(expr.span, oprnd_ty)?; let ok = self.try_overloaded_deref(expr.span, oprnd_ty)?;
let method = self.register_infer_ok_obligations(ok); let method = self.register_infer_ok_obligations(ok);
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { if let ty::Ref(_, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
self.apply_adjustments(oprnd_expr, vec![Adjustment { self.apply_adjustments(oprnd_expr, vec![Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)),
target: method.sig.inputs()[0], target: method.sig.inputs()[0],
}]); }]);
} else { } else {
@ -158,7 +158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut adjustments = self.adjust_steps(autoderef); let mut adjustments = self.adjust_steps(autoderef);
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
adjustments.push(Adjustment { adjustments.push(Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)),
target: Ty::new_imm_ref(self.tcx, *region, adjusted_ty), target: Ty::new_imm_ref(self.tcx, *region, adjusted_ty),
}); });
} else { } else {
@ -289,9 +289,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
{ {
let method = self.register_infer_ok_obligations(ok); let method = self.register_infer_ok_obligations(ok);
if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() { let ty::Ref(_, _, mutbl) = *method.sig.output().kind() else {
*deref = OverloadedDeref { region, mutbl, span: deref.span }; span_bug!(
} self.tcx.def_span(method.def_id),
"expected DerefMut to return a &mut"
);
};
*deref = OverloadedDeref { mutbl, span: deref.span };
// If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514). // If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
// This helps avoid accidental drops. // This helps avoid accidental drops.
if inside_union if inside_union
@ -390,7 +394,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// not the case today. // not the case today.
allow_two_phase_borrow: AllowTwoPhase::No, allow_two_phase_borrow: AllowTwoPhase::No,
}; };
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)); adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(mutbl));
adjustment.target = Ty::new_ref(self.tcx, *region, source, mutbl.into()); adjustment.target = Ty::new_ref(self.tcx, *region, source, mutbl.into());
} }
source = adjustment.target; source = adjustment.target;

View File

@ -1610,7 +1610,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
} }
for adj in cx.typeck_results().expr_adjustments(e) { for adj in cx.typeck_results().expr_adjustments(e) {
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind { if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(m)) = adj.kind {
match m { match m {
adjustment::AutoBorrowMutability::Not => { adjustment::AutoBorrowMutability::Not => {
cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag); cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag);

View File

@ -82,7 +82,7 @@ pub enum PointerCoercion {
/// `Box<[i32]>` is an `Adjust::Unsize` with the target `Box<[i32]>`. /// `Box<[i32]>` is an `Adjust::Unsize` with the target `Box<[i32]>`.
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] #[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
pub struct Adjustment<'tcx> { pub struct Adjustment<'tcx> {
pub kind: Adjust<'tcx>, pub kind: Adjust,
pub target: Ty<'tcx>, pub target: Ty<'tcx>,
} }
@ -93,20 +93,20 @@ impl<'tcx> Adjustment<'tcx> {
} }
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
pub enum Adjust<'tcx> { pub enum Adjust {
/// Go from ! to any type. /// Go from ! to any type.
NeverToAny, NeverToAny,
/// Dereference once, producing a place. /// Dereference once, producing a place.
Deref(Option<OverloadedDeref<'tcx>>), Deref(Option<OverloadedDeref>),
/// Take the address and produce either a `&` or `*` pointer. /// Take the address and produce either a `&` or `*` pointer.
Borrow(AutoBorrow<'tcx>), Borrow(AutoBorrow),
Pointer(PointerCoercion), Pointer(PointerCoercion),
/// Take a pinned reference and reborrow as a `Pin<&mut T>` or `Pin<&T>`. /// Take a pinned reference and reborrow as a `Pin<&mut T>` or `Pin<&T>`.
ReborrowPin(ty::Region<'tcx>, hir::Mutability), ReborrowPin(hir::Mutability),
} }
/// An overloaded autoderef step, representing a `Deref(Mut)::deref(_mut)` /// An overloaded autoderef step, representing a `Deref(Mut)::deref(_mut)`
@ -115,17 +115,16 @@ pub enum Adjust<'tcx> {
/// being those shared by both the receiver and the returned reference. /// being those shared by both the receiver and the returned reference.
#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)] #[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
#[derive(TypeFoldable, TypeVisitable)] #[derive(TypeFoldable, TypeVisitable)]
pub struct OverloadedDeref<'tcx> { pub struct OverloadedDeref {
pub region: ty::Region<'tcx>,
pub mutbl: hir::Mutability, pub mutbl: hir::Mutability,
/// The `Span` associated with the field access or method call /// The `Span` associated with the field access or method call
/// that triggered this overloaded deref. /// that triggered this overloaded deref.
pub span: Span, pub span: Span,
} }
impl<'tcx> OverloadedDeref<'tcx> { impl OverloadedDeref {
/// Get the zst function item type for this method call. /// Get the zst function item type for this method call.
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> Ty<'tcx> { pub fn method_call<'tcx>(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> Ty<'tcx> {
let trait_def_id = match self.mutbl { let trait_def_id = match self.mutbl {
hir::Mutability::Not => tcx.require_lang_item(LangItem::Deref, None), hir::Mutability::Not => tcx.require_lang_item(LangItem::Deref, None),
hir::Mutability::Mut => tcx.require_lang_item(LangItem::DerefMut, None), hir::Mutability::Mut => tcx.require_lang_item(LangItem::DerefMut, None),
@ -187,9 +186,9 @@ impl From<AutoBorrowMutability> for hir::Mutability {
#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)] #[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
#[derive(TypeFoldable, TypeVisitable)] #[derive(TypeFoldable, TypeVisitable)]
pub enum AutoBorrow<'tcx> { pub enum AutoBorrow {
/// Converts from T to &T. /// Converts from T to &T.
Ref(ty::Region<'tcx>, AutoBorrowMutability), Ref(AutoBorrowMutability),
/// Converts from T to *T. /// Converts from T to *T.
RawPtr(hir::Mutability), RawPtr(hir::Mutability),

View File

@ -140,7 +140,7 @@ impl<'tcx> Cx<'tcx> {
expr = Expr { expr = Expr {
temp_lifetime, temp_lifetime,
ty: Ty::new_ref(self.tcx, deref.region, expr.ty, deref.mutbl), ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, deref.mutbl),
span, span,
kind: ExprKind::Borrow { kind: ExprKind::Borrow {
borrow_kind: deref.mutbl.to_borrow_kind(), borrow_kind: deref.mutbl.to_borrow_kind(),
@ -152,14 +152,14 @@ impl<'tcx> Cx<'tcx> {
self.overloaded_place(hir_expr, adjustment.target, Some(call), expr, deref.span) self.overloaded_place(hir_expr, adjustment.target, Some(call), expr, deref.span)
} }
Adjust::Borrow(AutoBorrow::Ref(_, m)) => ExprKind::Borrow { Adjust::Borrow(AutoBorrow::Ref(m)) => ExprKind::Borrow {
borrow_kind: m.to_borrow_kind(), borrow_kind: m.to_borrow_kind(),
arg: self.thir.exprs.push(expr), arg: self.thir.exprs.push(expr),
}, },
Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => { Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => {
ExprKind::RawBorrow { mutability, arg: self.thir.exprs.push(expr) } ExprKind::RawBorrow { mutability, arg: self.thir.exprs.push(expr) }
} }
Adjust::ReborrowPin(region, mutbl) => { Adjust::ReborrowPin(mutbl) => {
debug!("apply ReborrowPin adjustment"); debug!("apply ReborrowPin adjustment");
// Rewrite `$expr` as `Pin { __pointer: &(mut)? *($expr).__pointer }` // Rewrite `$expr` as `Pin { __pointer: &(mut)? *($expr).__pointer }`
@ -197,7 +197,8 @@ impl<'tcx> Cx<'tcx> {
hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default }, hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
hir::Mutability::Not => BorrowKind::Shared, hir::Mutability::Not => BorrowKind::Shared,
}; };
let new_pin_target = Ty::new_ref(self.tcx, region, ptr_target_ty, mutbl); let new_pin_target =
Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, ptr_target_ty, mutbl);
let expr = self.thir.exprs.push(Expr { let expr = self.thir.exprs.push(Expr {
temp_lifetime, temp_lifetime,
ty: new_pin_target, ty: new_pin_target,

View File

@ -551,10 +551,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
] => "", ] => "",
[ [
.., ..,
Adjustment { Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mut_)), target: _ },
kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)),
target: _,
},
] => hir::Mutability::from(*mut_).ref_prefix_str(), ] => hir::Mutability::from(*mut_).ref_prefix_str(),
_ => "", _ => "",
}; };

View File

@ -418,7 +418,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
let (required_refs, msg) = if can_auto_borrow { let (required_refs, msg) = if can_auto_borrow {
(1, if deref_count == 1 { borrow_msg } else { deref_msg }) (1, if deref_count == 1 { borrow_msg } else { deref_msg })
} else if let Some(&Adjustment { } else if let Some(&Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, mutability)), kind: Adjust::Borrow(AutoBorrow::Ref(mutability)),
.. ..
}) = next_adjust }) = next_adjust
&& matches!(mutability, AutoBorrowMutability::Mut { .. }) && matches!(mutability, AutoBorrowMutability::Mut { .. })

View File

@ -53,7 +53,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<
[] => AdjustKind::None, [] => AdjustKind::None,
&[ &[
Adjustment { Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
.. ..
}, },
] => AdjustKind::borrow(mutbl), ] => AdjustKind::borrow(mutbl),
@ -62,7 +62,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<
kind: Adjust::Deref(_), .. kind: Adjust::Deref(_), ..
}, },
Adjustment { Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target, target,
}, },
] => { ] => {

View File

@ -199,7 +199,7 @@ fn is_ref_iterable<'tcx>(
kind: Adjust::Deref(_), .. kind: Adjust::Deref(_), ..
}, },
Adjustment { Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target, target,
}, },
.., ..,
@ -236,7 +236,7 @@ fn is_ref_iterable<'tcx>(
}, },
&[ &[
Adjustment { Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target, target,
}, },
.., ..,

View File

@ -137,7 +137,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
_ if matches!( _ if matches!(
typeck.expr_adjustments(prev_expr).first(), typeck.expr_adjustments(prev_expr).first(),
Some(Adjustment { Some(Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Not)) kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not))
| Adjust::Deref(_), | Adjust::Deref(_),
.. ..
}) })
@ -230,7 +230,7 @@ fn check_use<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (UseKind<'tcx>,
if use_cx if use_cx
.adjustments .adjustments
.first() .first()
.is_some_and(|a| matches!(a.kind, Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Not)))) => .is_some_and(|a| matches!(a.kind, Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)))) =>
{ {
UseKind::AutoBorrowed UseKind::AutoBorrowed
}, },

View File

@ -110,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
) || cx.typeck_results().expr_adjustments(expr).first().map_or(false, |a| { ) || cx.typeck_results().expr_adjustments(expr).first().map_or(false, |a| {
matches!( matches!(
a.kind, a.kind,
Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. })) Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. }))
) )
}) || (matches!( }) || (matches!(
cx.typeck_results().expr_ty(indexed).ref_mutability(), cx.typeck_results().expr_ty(indexed).ref_mutability(),