Add barest-bones deref patterns · rust-lang/rust@120d357 (original) (raw)

`@@ -18,8 +18,7 @@ use rustc_span::edit_distance::find_best_match_for_name;

`

18

18

`use rustc_span:🪥:DesugaringKind;

`

19

19

`use rustc_span::source_map::Spanned;

`

20

20

`use rustc_span::symbol::{kw, sym, Ident};

`

21

``

`-

use rustc_span::Span;

`

22

``

`-

use rustc_span::{BytePos, DUMMY_SP};

`

``

21

`+

use rustc_span::{BytePos, Span, DUMMY_SP};

`

23

22

`use rustc_target::abi::FieldIdx;

`

24

23

`use rustc_trait_selection::traits::{ObligationCause, Pattern};

`

25

24

`use ty::VariantDef;

`

`@@ -211,6 +210,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

211

210

`PatKind::Tuple(elements, ddpos) => {

`

212

211

`self.check_pat_tuple(pat.span, elements, ddpos, expected, pat_info)

`

213

212

`}

`

``

213

`+

PatKind::Box(inner) if self.tcx.features().deref_patterns => {

`

``

214

`+

self.check_pat_deref(pat.span, inner, expected, pat_info)

`

``

215

`+

}

`

214

216

`PatKind::Box(inner) => self.check_pat_box(pat.span, inner, expected, pat_info),

`

215

217

`PatKind::Ref(inner, mutbl) => self.check_pat_ref(pat, inner, mutbl, expected, pat_info),

`

216

218

`PatKind::Slice(before, slice, after) => {

`

`@@ -1975,6 +1977,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

1975

1977

` box_ty

`

1976

1978

`}

`

1977

1979

``

``

1980

`+

fn check_pat_deref(

`

``

1981

`+

&self,

`

``

1982

`+

span: Span,

`

``

1983

`+

inner: &'tcx Pat<'tcx>,

`

``

1984

`+

expected: Ty<'tcx>,

`

``

1985

`+

pat_info: PatInfo<'tcx, '_>,

`

``

1986

`+

) -> Ty<'tcx> {

`

``

1987

`+

let tcx = self.tcx;

`

``

1988

`` +

// FIXME(deref_patterns): use DerefPure for soundness

``

``

1989

`` +

// FIXME(deref_patterns): use DerefMut when required

``

``

1990

`+

// ::Target

`

``

1991

`+

let ty = Ty::new_projection(

`

``

1992

`+

tcx,

`

``

1993

`+

tcx.require_lang_item(hir::LangItem::DerefTarget, Some(span)),

`

``

1994

`+

[expected],

`

``

1995

`+

);

`

``

1996

`+

let ty = self.normalize(span, ty);

`

``

1997

`+

let ty = self.try_structurally_resolve_type(span, ty);

`

``

1998

`+

self.check_pat(inner, ty, pat_info);

`

``

1999

`+

expected

`

``

2000

`+

}

`

``

2001

+

1978

2002

`// Precondition: Pat is Ref(inner)

`

1979

2003

`fn check_pat_ref(

`

1980

2004

`&self,

`