Ty::new_ref and Ty::new_ptr stop using TypeAndMut
This commit is contained in:
parent
81e7e80990
commit
f0f224a37f
23 changed files with 68 additions and 125 deletions
|
@ -572,20 +572,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
|
|
||||||
mir::Rvalue::Ref(_, bk, place) => {
|
mir::Rvalue::Ref(_, bk, place) => {
|
||||||
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
|
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
|
||||||
Ty::new_ref(
|
Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, bk.to_mutbl_lossy())
|
||||||
tcx,
|
|
||||||
tcx.lifetimes.re_erased,
|
|
||||||
ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() },
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
self.codegen_place_to_pointer(bx, place, mk_ref)
|
self.codegen_place_to_pointer(bx, place, mk_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)),
|
mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)),
|
||||||
mir::Rvalue::AddressOf(mutability, place) => {
|
mir::Rvalue::AddressOf(mutability, place) => {
|
||||||
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
|
let mk_ptr =
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl: mutability })
|
move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| Ty::new_ptr(tcx, ty, mutability);
|
||||||
};
|
|
||||||
self.codegen_place_to_pointer(bx, place, mk_ptr)
|
self.codegen_place_to_pointer(bx, place, mk_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ pub fn check_intrinsic_type(
|
||||||
ty::BoundRegion { var: ty::BoundVar::from_u32(2), kind: ty::BrEnv },
|
ty::BoundRegion { var: ty::BoundVar::from_u32(2), kind: ty::BrEnv },
|
||||||
);
|
);
|
||||||
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
|
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
|
||||||
(Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
|
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2299,14 +2299,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
self.lower_delegation_ty(*sig_id, *idx, hir_ty.span)
|
self.lower_delegation_ty(*sig_id, *idx, hir_ty.span)
|
||||||
}
|
}
|
||||||
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)),
|
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)),
|
||||||
hir::TyKind::Ptr(mt) => {
|
hir::TyKind::Ptr(mt) => Ty::new_ptr(tcx, self.lower_ty(mt.ty), mt.mutbl),
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.lower_ty(mt.ty), mutbl: mt.mutbl })
|
|
||||||
}
|
|
||||||
hir::TyKind::Ref(region, mt) => {
|
hir::TyKind::Ref(region, mt) => {
|
||||||
let r = self.lower_lifetime(region, None);
|
let r = self.lower_lifetime(region, None);
|
||||||
debug!(?r);
|
debug!(?r);
|
||||||
let t = self.lower_ty_common(mt.ty, true, false);
|
let t = self.lower_ty_common(mt.ty, true, false);
|
||||||
Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
|
Ty::new_ref(tcx, r, t, mt.mutbl)
|
||||||
}
|
}
|
||||||
hir::TyKind::Never => tcx.types.never,
|
hir::TyKind::Never => tcx.types.never,
|
||||||
hir::TyKind::Tup(fields) => {
|
hir::TyKind::Tup(fields) => {
|
||||||
|
|
|
@ -334,11 +334,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
|
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
|
||||||
if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind()
|
if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind()
|
||||||
&& fcx.can_coerce(
|
&& fcx.can_coerce(
|
||||||
Ty::new_ref(
|
Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, expr_ty, mutbl),
|
||||||
fcx.tcx,
|
|
||||||
fcx.tcx.lifetimes.re_erased,
|
|
||||||
TypeAndMut { ty: expr_ty, mutbl },
|
|
||||||
),
|
|
||||||
self.cast_ty,
|
self.cast_ty,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -354,7 +350,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
if !sugg_mutref
|
if !sugg_mutref
|
||||||
&& sugg == None
|
&& sugg == None
|
||||||
&& fcx.can_coerce(
|
&& fcx.can_coerce(
|
||||||
Ty::new_ref(fcx.tcx, reg, TypeAndMut { ty: self.expr_ty, mutbl }),
|
Ty::new_ref(fcx.tcx, reg, self.expr_ty, mutbl),
|
||||||
self.cast_ty,
|
self.cast_ty,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -362,11 +358,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
}
|
}
|
||||||
} else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind()
|
} else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind()
|
||||||
&& fcx.can_coerce(
|
&& fcx.can_coerce(
|
||||||
Ty::new_ref(
|
Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, self.expr_ty, mutbl),
|
||||||
fcx.tcx,
|
|
||||||
fcx.tcx.lifetimes.re_erased,
|
|
||||||
TypeAndMut { ty: self.expr_ty, mutbl },
|
|
||||||
),
|
|
||||||
self.cast_ty,
|
self.cast_ty,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -861,7 +853,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
// from a region pointer to a vector.
|
// from a region pointer to a vector.
|
||||||
|
|
||||||
// Coerce to a raw pointer so that we generate AddressOf in MIR.
|
// Coerce to a raw pointer so that we generate AddressOf in MIR.
|
||||||
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr);
|
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr.ty, m_expr.mutbl);
|
||||||
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
|
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
bug!(
|
bug!(
|
||||||
|
|
|
@ -55,7 +55,7 @@ use rustc_middle::ty::adjustment::{
|
||||||
use rustc_middle::ty::error::TypeError;
|
use rustc_middle::ty::error::TypeError;
|
||||||
use rustc_middle::ty::relate::RelateResult;
|
use rustc_middle::ty::relate::RelateResult;
|
||||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||||
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeAndMut};
|
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::DesugaringKind;
|
use rustc_span::DesugaringKind;
|
||||||
|
@ -440,10 +440,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
let derefd_ty_a = Ty::new_ref(
|
let derefd_ty_a = Ty::new_ref(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
r,
|
r,
|
||||||
TypeAndMut {
|
referent_ty,
|
||||||
ty: referent_ty,
|
mutbl_b, // [1] above
|
||||||
mutbl: mutbl_b, // [1] above
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
match self.unify(derefd_ty_a, b) {
|
match self.unify(derefd_ty_a, b) {
|
||||||
Ok(ok) => {
|
Ok(ok) => {
|
||||||
|
@ -558,11 +556,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
Adjustment { kind: Adjust::Deref(None), target: ty_a },
|
Adjustment { kind: Adjust::Deref(None), target: ty_a },
|
||||||
Adjustment {
|
Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)),
|
||||||
target: Ty::new_ref(
|
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
|
||||||
self.tcx,
|
|
||||||
r_borrow,
|
|
||||||
ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a },
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -573,7 +567,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
Adjustment { kind: Adjust::Deref(None), target: ty_a },
|
Adjustment { kind: Adjust::Deref(None), target: ty_a },
|
||||||
Adjustment {
|
Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
|
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
|
||||||
target: Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mt_b, ty: ty_a }),
|
target: Ty::new_ptr(self.tcx, ty_a, mt_b),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -990,7 +984,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
coerce_mutbls(mt_a.mutbl, mutbl_b)?;
|
coerce_mutbls(mt_a.mutbl, mutbl_b)?;
|
||||||
|
|
||||||
// Check that the types which they point at are compatible.
|
// Check that the types which they point at are compatible.
|
||||||
let a_unsafe = Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty });
|
let a_unsafe = Ty::new_ptr(self.tcx, mt_a.ty, mutbl_b);
|
||||||
// Although references and unsafe ptrs have the same
|
// Although references and unsafe ptrs have the same
|
||||||
// representation, we still register an Adjust::DerefRef so that
|
// representation, we still register an Adjust::DerefRef so that
|
||||||
// regionck knows that the region for `a` must be valid here.
|
// regionck knows that the region for `a` must be valid here.
|
||||||
|
|
|
@ -442,12 +442,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let ty =
|
let ty =
|
||||||
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
|
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
|
||||||
|
|
||||||
let tm = ty::TypeAndMut { ty, mutbl };
|
|
||||||
match kind {
|
match kind {
|
||||||
_ if tm.ty.references_error() => Ty::new_misc_error(self.tcx),
|
_ if ty.references_error() => Ty::new_misc_error(self.tcx),
|
||||||
hir::BorrowKind::Raw => {
|
hir::BorrowKind::Raw => {
|
||||||
self.check_named_place_expr(oprnd);
|
self.check_named_place_expr(oprnd);
|
||||||
Ty::new_ptr(self.tcx, tm)
|
Ty::new_ptr(self.tcx, ty, mutbl)
|
||||||
}
|
}
|
||||||
hir::BorrowKind::Ref => {
|
hir::BorrowKind::Ref => {
|
||||||
// Note: at this point, we cannot say what the best lifetime
|
// Note: at this point, we cannot say what the best lifetime
|
||||||
|
@ -465,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// whose address was taken can actually be made to live as long
|
// whose address was taken can actually be made to live as long
|
||||||
// as it needs to live.
|
// as it needs to live.
|
||||||
let region = self.next_region_var(infer::AddrOfRegion(expr.span));
|
let region = self.next_region_var(infer::AddrOfRegion(expr.span));
|
||||||
Ty::new_ref(self.tcx, region, tm)
|
Ty::new_ref(self.tcx, region, ty, mutbl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3225,7 +3224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No);
|
self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No);
|
||||||
}
|
}
|
||||||
ty::Ref(_, base_ty, mutbl) => {
|
ty::Ref(_, base_ty, mutbl) => {
|
||||||
let ptr_ty = Ty::new_ptr(self.tcx, ty::TypeAndMut { ty: base_ty, mutbl });
|
let ptr_ty = Ty::new_ptr(self.tcx, base_ty, mutbl);
|
||||||
self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No);
|
self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -268,11 +268,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, '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(
|
let ref_ty = Ty::new_ref(self.tcx(), deref.region, target, deref.mutbl);
|
||||||
self.tcx(),
|
|
||||||
deref.region,
|
|
||||||
ty::TypeAndMut { ty: target, mutbl: deref.mutbl },
|
|
||||||
);
|
|
||||||
self.cat_rvalue(expr.hir_id, ref_ty)
|
self.cat_rvalue(expr.hir_id, ref_ty)
|
||||||
} else {
|
} else {
|
||||||
previous()?
|
previous()?
|
||||||
|
@ -479,7 +475,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
||||||
let ty::Ref(region, _, mutbl) = *base_ty.kind() else {
|
let ty::Ref(region, _, mutbl) = *base_ty.kind() else {
|
||||||
span_bug!(expr.span, "cat_overloaded_place: base is not a reference");
|
span_bug!(expr.span, "cat_overloaded_place: base is not a reference");
|
||||||
};
|
};
|
||||||
let ref_ty = Ty::new_ref(self.tcx(), region, ty::TypeAndMut { ty: place_ty, mutbl });
|
let ref_ty = Ty::new_ref(self.tcx(), region, place_ty, mutbl);
|
||||||
|
|
||||||
let base = self.cat_rvalue(expr.hir_id, ref_ty);
|
let base = self.cat_rvalue(expr.hir_id, ref_ty);
|
||||||
self.cat_deref(expr, base)
|
self.cat_deref(expr, base)
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
// Type we're wrapping in a reference, used later for unsizing
|
// Type we're wrapping in a reference, used later for unsizing
|
||||||
let base_ty = target;
|
let base_ty = target;
|
||||||
|
|
||||||
target = Ty::new_ref(self.tcx, region, ty::TypeAndMut { mutbl, ty: target });
|
target = Ty::new_ref(self.tcx, region, target, mutbl);
|
||||||
|
|
||||||
// Method call receivers are the primary use case
|
// Method call receivers are the primary use case
|
||||||
// for two-phase borrows.
|
// for two-phase borrows.
|
||||||
|
@ -208,11 +208,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
base_ty
|
base_ty
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
target = Ty::new_ref(
|
target = Ty::new_ref(self.tcx, region, unsized_ty, mutbl.into());
|
||||||
self.tcx,
|
|
||||||
region,
|
|
||||||
ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty },
|
|
||||||
);
|
|
||||||
adjustments.push(Adjustment {
|
adjustments.push(Adjustment {
|
||||||
kind: Adjust::Pointer(PointerCoercion::Unsize),
|
kind: Adjust::Pointer(PointerCoercion::Unsize),
|
||||||
target,
|
target,
|
||||||
|
|
|
@ -200,11 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if let Some(span) = result.illegal_sized_bound {
|
if let Some(span) = result.illegal_sized_bound {
|
||||||
let mut needs_mut = false;
|
let mut needs_mut = false;
|
||||||
if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
|
if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
|
||||||
let trait_type = Ty::new_ref(
|
let trait_type = Ty::new_ref(self.tcx, *region, *t_type, mutability.invert());
|
||||||
self.tcx,
|
|
||||||
*region,
|
|
||||||
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
|
|
||||||
);
|
|
||||||
// We probe again to see if there might be a borrow mutability discrepancy.
|
// We probe again to see if there might be a borrow mutability discrepancy.
|
||||||
match self.lookup_probe(
|
match self.lookup_probe(
|
||||||
segment.ident,
|
segment.ident,
|
||||||
|
|
|
@ -1213,7 +1213,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
// In general, during probing we erase regions.
|
// In general, during probing we erase regions.
|
||||||
let region = tcx.lifetimes.re_erased;
|
let region = tcx.lifetimes.re_erased;
|
||||||
|
|
||||||
let autoref_ty = Ty::new_ref(tcx, region, ty::TypeAndMut { ty: self_ty, mutbl });
|
let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
|
||||||
self.pick_method(autoref_ty, unstable_candidates).map(|r| {
|
self.pick_method(autoref_ty, unstable_candidates).map(|r| {
|
||||||
r.map(|mut pick| {
|
r.map(|mut pick| {
|
||||||
pick.autoderefs = step.autoderefs;
|
pick.autoderefs = step.autoderefs;
|
||||||
|
|
|
@ -304,11 +304,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() {
|
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() {
|
||||||
if needs_mut {
|
if needs_mut {
|
||||||
let trait_type = Ty::new_ref(
|
let trait_type =
|
||||||
self.tcx,
|
Ty::new_ref(self.tcx, *region, *t_type, mutability.invert());
|
||||||
*region,
|
|
||||||
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
|
|
||||||
);
|
|
||||||
let msg = format!("you need `{trait_type}` instead of `{rcvr_ty}`");
|
let msg = format!("you need `{trait_type}` instead of `{rcvr_ty}`");
|
||||||
let mut kind = &self_expr.kind;
|
let mut kind = &self_expr.kind;
|
||||||
while let hir::ExprKind::AddrOf(_, _, expr)
|
while let hir::ExprKind::AddrOf(_, _, expr)
|
||||||
|
|
|
@ -508,11 +508,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
suggest_deref_binop(&mut err, *lhs_deref_ty);
|
suggest_deref_binop(&mut err, *lhs_deref_ty);
|
||||||
} else {
|
} else {
|
||||||
let lhs_inv_mutbl = mutbl.invert();
|
let lhs_inv_mutbl = mutbl.invert();
|
||||||
let lhs_inv_mutbl_ty = Ty::new_ref(
|
let lhs_inv_mutbl_ty =
|
||||||
self.tcx,
|
Ty::new_ref(self.tcx, *region, *lhs_deref_ty, lhs_inv_mutbl);
|
||||||
*region,
|
|
||||||
ty::TypeAndMut { ty: *lhs_deref_ty, mutbl: lhs_inv_mutbl },
|
|
||||||
);
|
|
||||||
|
|
||||||
suggest_different_borrow(
|
suggest_different_borrow(
|
||||||
&mut err,
|
&mut err,
|
||||||
|
@ -524,11 +521,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
if let Ref(region, rhs_deref_ty, mutbl) = rhs_ty.kind() {
|
if let Ref(region, rhs_deref_ty, mutbl) = rhs_ty.kind() {
|
||||||
let rhs_inv_mutbl = mutbl.invert();
|
let rhs_inv_mutbl = mutbl.invert();
|
||||||
let rhs_inv_mutbl_ty = Ty::new_ref(
|
let rhs_inv_mutbl_ty =
|
||||||
self.tcx,
|
Ty::new_ref(self.tcx, *region, *rhs_deref_ty, rhs_inv_mutbl);
|
||||||
*region,
|
|
||||||
ty::TypeAndMut { ty: *rhs_deref_ty, mutbl: rhs_inv_mutbl },
|
|
||||||
);
|
|
||||||
|
|
||||||
suggest_different_borrow(
|
suggest_different_borrow(
|
||||||
&mut err,
|
&mut err,
|
||||||
|
|
|
@ -2057,8 +2057,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// Create a reference type with a fresh region variable.
|
/// Create a reference type with a fresh region variable.
|
||||||
fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> {
|
fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
let region = self.next_region_var(infer::PatternRegion(span));
|
let region = self.next_region_var(infer::PatternRegion(span));
|
||||||
let mt = ty::TypeAndMut { ty, mutbl };
|
Ty::new_ref(self.tcx, region, ty, mutbl)
|
||||||
Ty::new_ref(self.tcx, region, mt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_resolve_slice_ty_to_array_ty(
|
fn try_resolve_slice_ty_to_array_ty(
|
||||||
|
|
|
@ -162,11 +162,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
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(*region, AutoBorrowMutability::Not)),
|
||||||
target: Ty::new_ref(
|
target: Ty::new_imm_ref(self.tcx, *region, adjusted_ty),
|
||||||
self.tcx,
|
|
||||||
*region,
|
|
||||||
ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty },
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
span_bug!(expr.span, "input to index is not a ref?");
|
span_bug!(expr.span, "input to index is not a ref?");
|
||||||
|
@ -400,11 +396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
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(*region, mutbl));
|
||||||
adjustment.target = Ty::new_ref(
|
adjustment.target = Ty::new_ref(self.tcx, *region, source, mutbl.into());
|
||||||
self.tcx,
|
|
||||||
*region,
|
|
||||||
ty::TypeAndMut { ty: source, mutbl: mutbl.into() },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
source = adjustment.target;
|
source = adjustment.target;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1780,11 +1780,9 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
match capture_kind {
|
match capture_kind {
|
||||||
ty::UpvarCapture::ByValue => ty,
|
ty::UpvarCapture::ByValue => ty,
|
||||||
ty::UpvarCapture::ByRef(kind) => Ty::new_ref(
|
ty::UpvarCapture::ByRef(kind) => {
|
||||||
tcx,
|
Ty::new_ref(tcx, region.unwrap(), ty, kind.to_mutbl_lossy())
|
||||||
region.unwrap(),
|
}
|
||||||
ty::TypeAndMut { ty: ty, mutbl: kind.to_mutbl_lossy() },
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1046,10 +1046,10 @@ fn get_nullable_type<'tcx>(
|
||||||
}
|
}
|
||||||
ty::Int(ty) => Ty::new_int(tcx, ty),
|
ty::Int(ty) => Ty::new_int(tcx, ty),
|
||||||
ty::Uint(ty) => Ty::new_uint(tcx, ty),
|
ty::Uint(ty) => Ty::new_uint(tcx, ty),
|
||||||
ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut),
|
ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut.ty, ty_mut.mutbl),
|
||||||
// As these types are always non-null, the nullable equivalent of
|
// As these types are always non-null, the nullable equivalent of
|
||||||
// `Option<T>` of these types are their raw pointer counterparts.
|
// `Option<T>` of these types are their raw pointer counterparts.
|
||||||
ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl }),
|
ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty, mutbl),
|
||||||
// There is no nullable equivalent for Rust's function pointers,
|
// There is no nullable equivalent for Rust's function pointers,
|
||||||
// you must use an `Option<fn(..) -> _>` to represent it.
|
// you must use an `Option<fn(..) -> _>` to represent it.
|
||||||
ty::FnPtr(..) => ty,
|
ty::FnPtr(..) => ty,
|
||||||
|
|
|
@ -170,11 +170,11 @@ impl<'tcx> Rvalue<'tcx> {
|
||||||
Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did),
|
Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did),
|
||||||
Rvalue::Ref(reg, bk, ref place) => {
|
Rvalue::Ref(reg, bk, ref place) => {
|
||||||
let place_ty = place.ty(local_decls, tcx).ty;
|
let place_ty = place.ty(local_decls, tcx).ty;
|
||||||
Ty::new_ref(tcx, reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() })
|
Ty::new_ref(tcx, reg, place_ty, bk.to_mutbl_lossy())
|
||||||
}
|
}
|
||||||
Rvalue::AddressOf(mutability, ref place) => {
|
Rvalue::AddressOf(mutability, ref place) => {
|
||||||
let place_ty = place.ty(local_decls, tcx).ty;
|
let place_ty = place.ty(local_decls, tcx).ty;
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: place_ty, mutbl: mutability })
|
Ty::new_ptr(tcx, place_ty, mutability)
|
||||||
}
|
}
|
||||||
Rvalue::Len(..) => tcx.types.usize,
|
Rvalue::Len(..) => tcx.types.usize,
|
||||||
Rvalue::Cast(.., ty) => ty,
|
Rvalue::Cast(.., ty) => ty,
|
||||||
|
|
|
@ -460,7 +460,7 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
||||||
|
|
||||||
let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?;
|
let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?;
|
||||||
|
|
||||||
Ok(Ty::new_ptr(tcx, ty::TypeAndMut { mutbl: a_mutbl, ty }))
|
Ok(Ty::new_ptr(tcx, ty, a_mutbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
|
(&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
|
||||||
|
@ -478,7 +478,7 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
||||||
let r = relation.relate(a_r, b_r)?;
|
let r = relation.relate(a_r, b_r)?;
|
||||||
let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?;
|
let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?;
|
||||||
|
|
||||||
Ok(Ty::new_ref(tcx, r, ty::TypeAndMut { mutbl: a_mutbl, ty }))
|
Ok(Ty::new_ref(tcx, r, ty, a_mutbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
|
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
|
||||||
|
|
|
@ -1587,33 +1587,38 @@ impl<'tcx> Ty<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
|
pub fn new_ref(
|
||||||
Ty::new(tcx, Ref(r, tm.ty, tm.mutbl))
|
tcx: TyCtxt<'tcx>,
|
||||||
|
r: Region<'tcx>,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
mutbl: ty::Mutability,
|
||||||
|
) -> Ty<'tcx> {
|
||||||
|
Ty::new(tcx, Ref(r, ty, mutbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_mut_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn new_mut_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
Ty::new_ref(tcx, r, TypeAndMut { ty, mutbl: hir::Mutability::Mut })
|
Ty::new_ref(tcx, r, ty, hir::Mutability::Mut)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_imm_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn new_imm_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
Ty::new_ref(tcx, r, TypeAndMut { ty, mutbl: hir::Mutability::Not })
|
Ty::new_ref(tcx, r, ty, hir::Mutability::Not)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_ptr(tcx: TyCtxt<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
|
pub fn new_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mutbl: ty::Mutability) -> Ty<'tcx> {
|
||||||
Ty::new(tcx, RawPtr(tm))
|
Ty::new(tcx, RawPtr(ty::TypeAndMut { ty, mutbl }))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_mut_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn new_mut_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: hir::Mutability::Mut })
|
Ty::new_ptr(tcx, ty, hir::Mutability::Mut)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_imm_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn new_imm_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: hir::Mutability::Not })
|
Ty::new_ptr(tcx, ty, hir::Mutability::Not)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -125,11 +125,7 @@ impl<'tcx> Cx<'tcx> {
|
||||||
|
|
||||||
expr = Expr {
|
expr = Expr {
|
||||||
temp_lifetime,
|
temp_lifetime,
|
||||||
ty: Ty::new_ref(
|
ty: Ty::new_ref(self.tcx, deref.region, expr.ty, deref.mutbl),
|
||||||
self.tcx,
|
|
||||||
deref.region,
|
|
||||||
ty::TypeAndMut { ty: expr.ty, mutbl: deref.mutbl },
|
|
||||||
),
|
|
||||||
span,
|
span,
|
||||||
kind: ExprKind::Borrow {
|
kind: ExprKind::Borrow {
|
||||||
borrow_kind: deref.mutbl.to_borrow_kind(),
|
borrow_kind: deref.mutbl.to_borrow_kind(),
|
||||||
|
@ -1021,7 +1017,7 @@ impl<'tcx> Cx<'tcx> {
|
||||||
let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else {
|
let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else {
|
||||||
span_bug!(span, "overloaded_place: receiver is not a reference");
|
span_bug!(span, "overloaded_place: receiver is not a reference");
|
||||||
};
|
};
|
||||||
let ref_ty = Ty::new_ref(self.tcx, region, ty::TypeAndMut { ty: place_ty, mutbl });
|
let ref_ty = Ty::new_ref(self.tcx, region, place_ty, mutbl);
|
||||||
|
|
||||||
// construct the complete expression `foo()` for the overloaded call,
|
// construct the complete expression `foo()` for the overloaded call,
|
||||||
// which will yield the &T type
|
// which will yield the &T type
|
||||||
|
|
|
@ -94,7 +94,7 @@ use rustc_middle::mir::interpret::GlobalAlloc;
|
||||||
use rustc_middle::mir::visit::*;
|
use rustc_middle::mir::visit::*;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_span::def_id::DefId;
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT};
|
use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT};
|
||||||
|
@ -451,11 +451,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||||
AddressKind::Ref(bk) => Ty::new_ref(
|
AddressKind::Ref(bk) => Ty::new_ref(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
self.tcx.lifetimes.re_erased,
|
self.tcx.lifetimes.re_erased,
|
||||||
ty::TypeAndMut { ty: mplace.layout.ty, mutbl: bk.to_mutbl_lossy() },
|
mplace.layout.ty,
|
||||||
|
bk.to_mutbl_lossy(),
|
||||||
),
|
),
|
||||||
AddressKind::Address(mutbl) => {
|
AddressKind::Address(mutbl) => Ty::new_ptr(self.tcx, mplace.layout.ty, mutbl),
|
||||||
Ty::new_ptr(self.tcx, TypeAndMut { ty: mplace.layout.ty, mutbl })
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let layout = self.ecx.layout_of(ty).ok()?;
|
let layout = self.ecx.layout_of(ty).ok()?;
|
||||||
ImmTy::from_immediate(pointer, layout).into()
|
ImmTy::from_immediate(pointer, layout).into()
|
||||||
|
|
|
@ -820,11 +820,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
||||||
let ty = local_decls[place.local].ty;
|
let ty = local_decls[place.local].ty;
|
||||||
let span = statement.source_info.span;
|
let span = statement.source_info.span;
|
||||||
|
|
||||||
let ref_ty = Ty::new_ref(
|
let ref_ty =
|
||||||
tcx,
|
Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, borrow_kind.to_mutbl_lossy());
|
||||||
tcx.lifetimes.re_erased,
|
|
||||||
ty::TypeAndMut { ty, mutbl: borrow_kind.to_mutbl_lossy() },
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut projection = vec![PlaceElem::Deref];
|
let mut projection = vec![PlaceElem::Deref];
|
||||||
projection.extend(place.projection);
|
projection.extend(place.projection);
|
||||||
|
|
|
@ -31,8 +31,8 @@ use rustc_middle::traits::IsConstable;
|
||||||
use rustc_middle::ty::error::TypeError::{self, Sorts};
|
use rustc_middle::ty::error::TypeError::{self, Sorts};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs,
|
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs,
|
||||||
InferTy, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeAndMut, TypeFoldable, TypeFolder,
|
InferTy, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
|
||||||
TypeSuperFoldable, TypeVisitableExt, TypeckResults,
|
TypeVisitableExt, TypeckResults,
|
||||||
};
|
};
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
|
@ -482,7 +482,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
if let Some(steps) =
|
if let Some(steps) =
|
||||||
autoderef.into_iter().enumerate().find_map(|(steps, (ty, obligations))| {
|
autoderef.into_iter().enumerate().find_map(|(steps, (ty, obligations))| {
|
||||||
// Re-add the `&`
|
// Re-add the `&`
|
||||||
let ty = Ty::new_ref(self.tcx, region, TypeAndMut { ty, mutbl });
|
let ty = Ty::new_ref(self.tcx, region, ty, mutbl);
|
||||||
|
|
||||||
// Remapping bound vars here
|
// Remapping bound vars here
|
||||||
let real_trait_pred_and_ty = real_trait_pred
|
let real_trait_pred_and_ty = real_trait_pred
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue