@@ -18,8 +18,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
1818use rustc_span:: hygiene:: DesugaringKind ;
1919use rustc_span:: source_map:: Spanned ;
2020use 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 } ;
2322use rustc_target:: abi:: FieldIdx ;
2423use rustc_trait_selection:: traits:: { ObligationCause , Pattern } ;
2524use ty:: VariantDef ;
@@ -211,6 +210,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
211210 PatKind :: Tuple ( elements, ddpos) => {
212211 self . check_pat_tuple ( pat. span , elements, ddpos, expected, pat_info)
213212 }
213+ PatKind :: Box ( inner) if self . tcx . features ( ) . deref_patterns => {
214+ self . check_pat_deref ( pat. span , inner, expected, pat_info)
215+ }
214216 PatKind :: Box ( inner) => self . check_pat_box ( pat. span , inner, expected, pat_info) ,
215217 PatKind :: Ref ( inner, mutbl) => self . check_pat_ref ( pat, inner, mutbl, expected, pat_info) ,
216218 PatKind :: Slice ( before, slice, after) => {
@@ -1975,6 +1977,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19751977 box_ty
19761978 }
19771979
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+ // <expected as Deref>::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+
19782002 // Precondition: Pat is Ref(inner)
19792003 fn check_pat_ref (
19802004 & self ,
0 commit comments