about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-09-16 19:07:01 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-10-01 10:03:06 +0000
commit7e90a4184437fb39904288106cfb4bfab322e18a (patch)
tree82d4445603e1db9ea2d3b9cd17d43b9acf90a644
parenta8f7e244b785feb1b1d696abf0a7efb5cb7aed30 (diff)
downloadrust-7e90a4184437fb39904288106cfb4bfab322e18a.tar.gz
rust-7e90a4184437fb39904288106cfb4bfab322e18a.zip
clippy: adopt to the new lint API
-rw-r--r--src/tools/clippy/clippy_lints/src/module_style.rs19
-rw-r--r--src/tools/clippy/clippy_utils/src/diagnostics.rs46
2 files changed, 29 insertions, 36 deletions
diff --git a/src/tools/clippy/clippy_lints/src/module_style.rs b/src/tools/clippy/clippy_lints/src/module_style.rs
index 22071ab3044..102b9fbae83 100644
--- a/src/tools/clippy/clippy_lints/src/module_style.rs
+++ b/src/tools/clippy/clippy_lints/src/module_style.rs
@@ -117,11 +117,13 @@ impl EarlyLintPass for ModStyle {
                     cx.struct_span_lint(
                         SELF_NAMED_MODULE_FILES,
                         Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
-                        |build| {
-                            let mut lint =
-                                build.build(&format!("`mod.rs` files are required, found `{}`", path.display()));
-                            lint.help(&format!("move `{}` to `{}`", path.display(), correct.display(),));
-                            lint.emit();
+                        format!("`mod.rs` files are required, found `{}`", path.display()),
+                        |lint| {
+                            lint.help(format!(
+                                "move `{}` to `{}`",
+                                path.display(),
+                                correct.display(),
+                            ))
                         },
                     );
                 }
@@ -156,11 +158,8 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source
         cx.struct_span_lint(
             MOD_MODULE_FILES,
             Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
-            |build| {
-                let mut lint = build.build(&format!("`mod.rs` files are not allowed, found `{}`", path.display()));
-                lint.help(&format!("move `{}` to `{}`", path.display(), mod_file.display(),));
-                lint.emit();
-            },
+            format!("`mod.rs` files are not allowed, found `{}`", path.display()),
+            |lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())),
         );
     }
 }
diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs
index ad95369b9ef..78960d1ab1d 100644
--- a/src/tools/clippy/clippy_utils/src/diagnostics.rs
+++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs
@@ -47,10 +47,9 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
 ///    |     ^^^^^^^^^^^^^^^^^^^^^^^
 /// ```
 pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) {
-    cx.struct_span_lint(lint, sp, |diag| {
-        let mut diag = diag.build(msg);
-        docs_link(&mut diag, lint);
-        diag.emit();
+    cx.struct_span_lint(lint, sp, msg, |diag| {
+        docs_link(diag, lint);
+        diag
     });
 }
 
@@ -82,15 +81,14 @@ pub fn span_lint_and_help<'a, T: LintContext>(
     help_span: Option<Span>,
     help: &str,
 ) {
-    cx.struct_span_lint(lint, span, |diag| {
-        let mut diag = diag.build(msg);
+    cx.struct_span_lint(lint, span, msg, |diag| {
         if let Some(help_span) = help_span {
             diag.span_help(help_span, help);
         } else {
             diag.help(help);
         }
-        docs_link(&mut diag, lint);
-        diag.emit();
+        docs_link(diag, lint);
+        diag
     });
 }
 
@@ -125,15 +123,14 @@ pub fn span_lint_and_note<'a, T: LintContext>(
     note_span: Option<Span>,
     note: &str,
 ) {
-    cx.struct_span_lint(lint, span, |diag| {
-        let mut diag = diag.build(msg);
+    cx.struct_span_lint(lint, span, msg, |diag| {
         if let Some(note_span) = note_span {
             diag.span_note(note_span, note);
         } else {
             diag.note(note);
         }
-        docs_link(&mut diag, lint);
-        diag.emit();
+        docs_link(diag, lint);
+        diag
     });
 }
 
@@ -147,19 +144,17 @@ where
     S: Into<MultiSpan>,
     F: FnOnce(&mut Diagnostic),
 {
-    cx.struct_span_lint(lint, sp, |diag| {
-        let mut diag = diag.build(msg);
-        f(&mut diag);
-        docs_link(&mut diag, lint);
-        diag.emit();
+    cx.struct_span_lint(lint, sp, msg, |diag| {
+        f(diag);
+        docs_link(diag, lint);
+        diag
     });
 }
 
 pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
-    cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
-        let mut diag = diag.build(msg);
-        docs_link(&mut diag, lint);
-        diag.emit();
+    cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
+        docs_link(diag, lint);
+        diag
     });
 }
 
@@ -171,11 +166,10 @@ pub fn span_lint_hir_and_then(
     msg: &str,
     f: impl FnOnce(&mut Diagnostic),
 ) {
-    cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
-        let mut diag = diag.build(msg);
-        f(&mut diag);
-        docs_link(&mut diag, lint);
-        diag.emit();
+    cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
+        f(diag);
+        docs_link(diag, lint);
+        diag
     });
 }