@@ -23,6 +23,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
2323use std:: cmp;
2424use syntax:: ast;
2525use syntax:: codemap:: Spanned ;
26+ use syntax:: feature_gate;
2627use syntax:: ptr:: P ;
2728use syntax_pos:: Span ;
2829
@@ -68,7 +69,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6869 PatKind :: Binding ( ..) |
6970 PatKind :: Ref ( ..) => false ,
7071 } ;
71- if is_non_ref_pat && tcx . sess . features . borrow ( ) . match_default_bindings {
72+ if is_non_ref_pat {
7273 debug ! ( "pattern is non reference pattern" ) ;
7374 let mut exp_ty = self . resolve_type_vars_with_obligations ( & expected) ;
7475
@@ -113,10 +114,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
113114 }
114115 } ;
115116 if pat_adjustments. len ( ) > 0 {
116- debug ! ( "default binding mode is now {:?}" , def_bm) ;
117- self . inh . tables . borrow_mut ( )
118- . pat_adjustments_mut ( )
119- . insert ( pat. hir_id , pat_adjustments) ;
117+ if tcx. sess . features . borrow ( ) . match_default_bindings {
118+ debug ! ( "default binding mode is now {:?}" , def_bm) ;
119+ self . inh . tables . borrow_mut ( )
120+ . pat_adjustments_mut ( )
121+ . insert ( pat. hir_id , pat_adjustments) ;
122+ } else {
123+ let mut err = feature_gate:: feature_err (
124+ & tcx. sess . parse_sess ,
125+ "match_default_bindings" ,
126+ pat. span ,
127+ feature_gate:: GateIssue :: Language ,
128+ "non-reference pattern used to match a reference" ,
129+ ) ;
130+ if let Ok ( snippet) = tcx. sess . codemap ( ) . span_to_snippet ( pat. span ) {
131+ err. span_suggestion ( pat. span , "consider using" , format ! ( "&{}" , & snippet) ) ;
132+ }
133+ err. emit ( ) ;
134+ }
120135 }
121136 }
122137
@@ -325,8 +340,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
325340 if let Some ( mut err) = err {
326341 if is_arg {
327342 if let PatKind :: Binding ( ..) = inner. node {
328- if let Ok ( snippet) = self . sess ( ) . codemap ( )
329- . span_to_snippet ( pat. span )
343+ if let Ok ( snippet) = tcx . sess . codemap ( )
344+ . span_to_snippet ( pat. span )
330345 {
331346 err. help ( & format ! ( "did you mean `{}: &{}`?" ,
332347 & snippet[ 1 ..] ,
0 commit comments