@@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashMap;
1616use rustc_errors:: { error_code, pluralize, struct_span_err, Applicability } ;
1717use rustc_parse:: validate_attr;
1818use rustc_session:: lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ;
19- use rustc_session:: lint:: LintBuffer ;
19+ use rustc_session:: lint:: { BuiltinLintDiagnostics , LintBuffer } ;
2020use rustc_session:: Session ;
2121use rustc_span:: symbol:: { kw, sym, Ident } ;
2222use rustc_span:: Span ;
@@ -213,14 +213,14 @@ impl<'a> AstValidator<'a> {
213213 err. emit ( ) ;
214214 }
215215
216- fn check_decl_no_pat ( decl : & FnDecl , mut report_err : impl FnMut ( Span , bool ) ) {
216+ fn check_decl_no_pat ( decl : & FnDecl , mut report_err : impl FnMut ( Span , Option < Ident > , bool ) ) {
217217 for Param { pat, .. } in & decl. inputs {
218218 match pat. kind {
219219 PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Not ) , _, None ) | PatKind :: Wild => { }
220- PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Mut ) , _ , None ) => {
221- report_err ( pat. span , true )
220+ PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Mut ) , ident , None ) => {
221+ report_err ( pat. span , Some ( ident ) , true )
222222 }
223- _ => report_err ( pat. span , false ) ,
223+ _ => report_err ( pat. span , None , false ) ,
224224 }
225225 }
226226 }
@@ -834,7 +834,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
834834 match ty. kind {
835835 TyKind :: BareFn ( ref bfty) => {
836836 self . check_fn_decl ( & bfty. decl , SelfSemantic :: No ) ;
837- Self :: check_decl_no_pat ( & bfty. decl , |span, _| {
837+ Self :: check_decl_no_pat ( & bfty. decl , |span, _, _ | {
838838 struct_span_err ! (
839839 self . session,
840840 span,
@@ -1289,7 +1289,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12891289
12901290 // Functions without bodies cannot have patterns.
12911291 if let FnKind :: Fn ( ctxt, _, sig, _, None ) = fk {
1292- Self :: check_decl_no_pat ( & sig. decl , |span, mut_ident| {
1292+ Self :: check_decl_no_pat ( & sig. decl , |span, ident , mut_ident| {
12931293 let ( code, msg, label) = match ctxt {
12941294 FnCtxt :: Foreign => (
12951295 error_code ! ( E0130 ) ,
@@ -1303,7 +1303,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13031303 ) ,
13041304 } ;
13051305 if mut_ident && matches ! ( ctxt, FnCtxt :: Assoc ( _) ) {
1306- self . lint_buffer . buffer_lint ( PATTERNS_IN_FNS_WITHOUT_BODY , id, span, msg) ;
1306+ if let Some ( ident) = ident {
1307+ let diag = BuiltinLintDiagnostics :: PatternsInFnsWithoutBody ( span, ident) ;
1308+ self . lint_buffer . buffer_lint_with_diagnostic (
1309+ PATTERNS_IN_FNS_WITHOUT_BODY ,
1310+ id,
1311+ span,
1312+ msg,
1313+ diag,
1314+ )
1315+ }
13071316 } else {
13081317 self . err_handler ( )
13091318 . struct_span_err ( span, msg)
0 commit comments