@@ -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 }
@@ -815,7 +815,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
815815 match ty. kind {
816816 TyKind :: BareFn ( ref bfty) => {
817817 self . check_fn_decl ( & bfty. decl , SelfSemantic :: No ) ;
818- Self :: check_decl_no_pat ( & bfty. decl , |span, _| {
818+ Self :: check_decl_no_pat ( & bfty. decl , |span, _, _ | {
819819 struct_span_err ! (
820820 self . session,
821821 span,
@@ -1285,7 +1285,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12851285
12861286 // Functions without bodies cannot have patterns.
12871287 if let FnKind :: Fn ( ctxt, _, sig, _, None ) = fk {
1288- Self :: check_decl_no_pat ( & sig. decl , |span, mut_ident| {
1288+ Self :: check_decl_no_pat ( & sig. decl , |span, ident , mut_ident| {
12891289 let ( code, msg, label) = match ctxt {
12901290 FnCtxt :: Foreign => (
12911291 error_code ! ( E0130 ) ,
@@ -1299,7 +1299,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12991299 ) ,
13001300 } ;
13011301 if mut_ident && matches ! ( ctxt, FnCtxt :: Assoc ( _) ) {
1302- self . lint_buffer . buffer_lint ( PATTERNS_IN_FNS_WITHOUT_BODY , id, span, msg) ;
1302+ if let Some ( ident) = ident {
1303+ let diag = BuiltinLintDiagnostics :: PatternsInFnsWithoutBody ( span, ident) ;
1304+ self . lint_buffer . buffer_lint_with_diagnostic (
1305+ PATTERNS_IN_FNS_WITHOUT_BODY ,
1306+ id,
1307+ span,
1308+ msg,
1309+ diag,
1310+ )
1311+ }
13031312 } else {
13041313 self . err_handler ( )
13051314 . struct_span_err ( span, msg)
0 commit comments