@@ -18,8 +18,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
18
18
use rustc_span:: hygiene:: 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 ;
@@ -202,6 +201,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
202
201
PatKind :: Tuple ( elements, ddpos) => {
203
202
self . check_pat_tuple ( pat. span , elements, ddpos, expected, pat_info)
204
203
}
204
+ PatKind :: Box ( inner) if self . tcx . features ( ) . deref_patterns => {
205
+ self . check_pat_deref ( pat. span , inner, expected, pat_info)
206
+ }
205
207
PatKind :: Box ( inner) => self . check_pat_box ( pat. span , inner, expected, pat_info) ,
206
208
PatKind :: Ref ( inner, mutbl) => self . check_pat_ref ( pat, inner, mutbl, expected, pat_info) ,
207
209
PatKind :: Slice ( before, slice, after) => {
@@ -1966,6 +1968,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1966
1968
box_ty
1967
1969
}
1968
1970
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
+
1969
1993
// Precondition: Pat is Ref(inner)
1970
1994
fn check_pat_ref (
1971
1995
& self ,
0 commit comments