@@ -23,6 +23,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
23
23
use std:: cmp;
24
24
use syntax:: ast;
25
25
use syntax:: codemap:: Spanned ;
26
+ use syntax:: feature_gate;
26
27
use syntax:: ptr:: P ;
27
28
use syntax_pos:: Span ;
28
29
@@ -68,7 +69,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
68
69
PatKind :: Binding ( ..) |
69
70
PatKind :: Ref ( ..) => false ,
70
71
} ;
71
- if is_non_ref_pat && tcx . sess . features . borrow ( ) . match_default_bindings {
72
+ if is_non_ref_pat {
72
73
debug ! ( "pattern is non reference pattern" ) ;
73
74
let mut exp_ty = self . resolve_type_vars_with_obligations ( & expected) ;
74
75
@@ -113,10 +114,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
113
114
}
114
115
} ;
115
116
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
+ }
120
135
}
121
136
}
122
137
@@ -325,8 +340,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
325
340
if let Some ( mut err) = err {
326
341
if is_arg {
327
342
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 )
330
345
{
331
346
err. help ( & format ! ( "did you mean `{}: &{}`?" ,
332
347
& snippet[ 1 ..] ,
0 commit comments