refactor: remove Ty::pinned_ref in favor of Ty::maybe_pinned_ref
Also returns the `Region` of the reference type.
This commit is contained in:
parent
35a31ba763
commit
4ae5b43b0f
3 changed files with 12 additions and 20 deletions
|
|
@ -2841,7 +2841,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// the bad interactions of the given hack detailed in (note_1).
|
||||
debug!("check_pat_ref: expected={:?}", expected);
|
||||
match expected.maybe_pinned_ref() {
|
||||
Some((r_ty, r_pinned, r_mutbl))
|
||||
Some((r_ty, r_pinned, r_mutbl, _))
|
||||
if ((ref_pat_matches_mut_ref && r_mutbl >= pat_mutbl)
|
||||
|| r_mutbl == pat_mutbl)
|
||||
&& pat_pinned == r_pinned =>
|
||||
|
|
|
|||
|
|
@ -1336,25 +1336,17 @@ impl<'tcx> Ty<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pinned_ref(self) -> Option<(Ty<'tcx>, ty::Mutability)> {
|
||||
if let Adt(def, args) = self.kind()
|
||||
&& def.is_pin()
|
||||
&& let &ty::Ref(_, ty, mutbl) = args.type_at(0).kind()
|
||||
{
|
||||
return Some((ty, mutbl));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn maybe_pinned_ref(self) -> Option<(Ty<'tcx>, ty::Pinnedness, ty::Mutability)> {
|
||||
match *self.kind() {
|
||||
pub fn maybe_pinned_ref(
|
||||
self,
|
||||
) -> Option<(Ty<'tcx>, ty::Pinnedness, ty::Mutability, Region<'tcx>)> {
|
||||
match self.kind() {
|
||||
Adt(def, args)
|
||||
if def.is_pin()
|
||||
&& let ty::Ref(_, ty, mutbl) = *args.type_at(0).kind() =>
|
||||
&& let &ty::Ref(region, ty, mutbl) = args.type_at(0).kind() =>
|
||||
{
|
||||
Some((ty, ty::Pinnedness::Pinned, mutbl))
|
||||
Some((ty, ty::Pinnedness::Pinned, mutbl, region))
|
||||
}
|
||||
ty::Ref(_, ty, mutbl) => Some((ty, ty::Pinnedness::Not, mutbl)),
|
||||
&Ref(region, ty, mutbl) => Some((ty, ty::Pinnedness::Not, mutbl, region)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ use std::iter::once;
|
|||
|
||||
use rustc_abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx};
|
||||
use rustc_arena::DroplessArena;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{self as hir, HirId};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_middle::middle::stability::EvalResult;
|
||||
use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary};
|
||||
|
|
@ -471,9 +471,9 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
|
|||
PatKind::Deref { pin, subpattern } => {
|
||||
fields = vec![self.lower_pat(subpattern).at_index(0)];
|
||||
arity = 1;
|
||||
ctor = match pin {
|
||||
hir::Pinnedness::Not if ty.is_ref() => Ref,
|
||||
hir::Pinnedness::Pinned if let Some((inner_ty, _)) = ty.pinned_ref() => {
|
||||
ctor = match (pin, ty.maybe_pinned_ref()) {
|
||||
(ty::Pinnedness::Not, Some((_, ty::Pinnedness::Not, _, _))) => Ref,
|
||||
(ty::Pinnedness::Pinned, Some((inner_ty, ty::Pinnedness::Pinned, _, _))) => {
|
||||
self.internal_state.has_lowered_deref_pat.set(true);
|
||||
DerefPattern(RevealedTy(inner_ty))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue