@@ -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 ;
@@ -202,6 +201,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
202201 PatKind :: Tuple ( elements, ddpos) => {
203202 self . check_pat_tuple ( pat. span , elements, ddpos, expected, pat_info)
204203 }
204+ PatKind :: Box ( inner) if self . tcx . features ( ) . deref_patterns => {
205+ self . check_pat_deref ( pat. span , inner, expected, pat_info)
206+ }
205207 PatKind :: Box ( inner) => self . check_pat_box ( pat. span , inner, expected, pat_info) ,
206208 PatKind :: Ref ( inner, mutbl) => self . check_pat_ref ( pat, inner, mutbl, expected, pat_info) ,
207209 PatKind :: Slice ( before, slice, after) => {
@@ -1966,6 +1968,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19661968 box_ty
19671969 }
19681970
1971+ fn check_pat_deref (
1972+ & self ,
1973+ span : Span ,
1974+ inner : & ' tcx Pat < ' tcx > ,
1975+ expected : Ty < ' tcx > ,
1976+ pat_info : PatInfo < ' tcx , ' _ > ,
1977+ ) -> Ty < ' tcx > {
1978+ let tcx = self . tcx ;
1979+ // FIXME(deref_patterns): use `DerefPure` for soundness
1980+ // FIXME(deref_patterns): use `DerefMut` when required
1981+ // <expected as Deref>::Target
1982+ let ty = Ty :: new_projection (
1983+ tcx,
1984+ tcx. require_lang_item ( hir:: LangItem :: DerefTarget , Some ( span) ) ,
1985+ [ expected] ,
1986+ ) ;
1987+ let ty = self . normalize ( span, ty) ;
1988+ let ty = self . try_structurally_resolve_type ( span, ty) ;
1989+ self . check_pat ( inner, ty, pat_info) ;
1990+ expected
1991+ }
1992+
19691993 // Precondition: Pat is Ref(inner)
19701994 fn check_pat_ref (
19711995 & self ,
0 commit comments