X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Fclippy%2Fclippy_utils%2Fsrc%2Fdiagnostics.rs;h=ad95369b9ef707091919fa59ea167a906c35e14e;hb=92b702e90d4f38f1d8b492915c7caa6d2902beb7;hp=78960d1ab1da558bc3220852f6d97305c9182f2f;hpb=13f47f608e8e9fcdd60f64688e12f5f4c2f7c317;p=rust.git diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs index 78960d1ab1d..ad95369b9ef 100644 --- a/src/tools/clippy/clippy_utils/src/diagnostics.rs +++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs @@ -47,9 +47,10 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { /// | ^^^^^^^^^^^^^^^^^^^^^^^ /// ``` pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into, msg: &str) { - cx.struct_span_lint(lint, sp, msg, |diag| { - docs_link(diag, lint); - diag + cx.struct_span_lint(lint, sp, |diag| { + let mut diag = diag.build(msg); + docs_link(&mut diag, lint); + diag.emit(); }); } @@ -81,14 +82,15 @@ pub fn span_lint_and_help<'a, T: LintContext>( help_span: Option, help: &str, ) { - cx.struct_span_lint(lint, span, msg, |diag| { + cx.struct_span_lint(lint, span, |diag| { + let mut diag = diag.build(msg); if let Some(help_span) = help_span { diag.span_help(help_span, help); } else { diag.help(help); } - docs_link(diag, lint); - diag + docs_link(&mut diag, lint); + diag.emit(); }); } @@ -123,14 +125,15 @@ pub fn span_lint_and_note<'a, T: LintContext>( note_span: Option, note: &str, ) { - cx.struct_span_lint(lint, span, msg, |diag| { + cx.struct_span_lint(lint, span, |diag| { + let mut diag = diag.build(msg); if let Some(note_span) = note_span { diag.span_note(note_span, note); } else { diag.note(note); } - docs_link(diag, lint); - diag + docs_link(&mut diag, lint); + diag.emit(); }); } @@ -144,17 +147,19 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: &str S: Into, F: FnOnce(&mut Diagnostic), { - cx.struct_span_lint(lint, sp, msg, |diag| { - f(diag); - docs_link(diag, lint); - diag + cx.struct_span_lint(lint, sp, |diag| { + let mut diag = diag.build(msg); + f(&mut diag); + docs_link(&mut diag, lint); + diag.emit(); }); } 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, msg, |diag| { - docs_link(diag, lint); - diag + cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { + let mut diag = diag.build(msg); + docs_link(&mut diag, lint); + diag.emit(); }); } @@ -166,10 +171,11 @@ pub fn span_lint_hir_and_then( msg: &str, f: impl FnOnce(&mut Diagnostic), ) { - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| { - f(diag); - docs_link(diag, lint); - diag + 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(); }); }