Skip to content

Commit fb020a9

Browse files
committed
Use emit_span_lint instead of emit_diag_lint
These functions are subtly different, where the latter doesn't suppress lints when emitted from within macros.
1 parent 69fa356 commit fb020a9

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/hir_lints/c_str_literal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ impl<'tcx> LateLintPass<'tcx> for CStrLiteralLint<'tcx> {
7979

8080
if let Some(arg) = self.extract_arg(expn_data.call_site) {
8181
if arg.starts_with('"') && arg.ends_with('"') {
82-
cx.emit_diag_lint(
82+
cx.emit_span_lint(
8383
C_STR_LITERAL,
84+
expn_data.call_site,
8485
CStrLiteral {
8586
span: expn_data.call_site,
8687
macro_name: self.cx.item_name(c_str),

src/hir_lints/not_using_prelude.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
66
use rustc_hir::{Item, ItemKind, UseKind};
77
use rustc_lint::{LateContext, LateLintPass, LintContext};
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
9-
use rustc_span::{Span, Symbol, sym};
9+
use rustc_span::{Symbol, sym};
1010

1111
use crate::ctxt::AnalysisCtxt;
1212

@@ -28,8 +28,6 @@ impl_lint_pass!(NotUsingPrelude<'_> => [NOT_USING_PRELUDE]);
2828
#[diag("this item is available via prelude")]
2929
#[help("import with `{$crate_name}::prelude::*` instead")]
3030
struct NotUsingPreludeLint {
31-
#[primary_span]
32-
pub span: Span,
3331
pub crate_name: Symbol,
3432
}
3533

@@ -66,12 +64,10 @@ impl<'tcx> LateLintPass<'tcx> for NotUsingPrelude<'tcx> {
6664
let cnum = prelude.get(&imported_def_id).copied().unwrap();
6765
let crate_name = self.cx.crate_name(cnum);
6866

69-
cx.emit_diag_lint(
67+
cx.emit_span_lint(
7068
NOT_USING_PRELUDE,
71-
NotUsingPreludeLint {
72-
span: item.span,
73-
crate_name,
74-
},
69+
item.span,
70+
NotUsingPreludeLint { crate_name },
7571
);
7672
}
7773
}

0 commit comments

Comments
 (0)