Skip to content

Commit c4a2fc4

Browse files
committed
Auto merge of #120017 - nnethercote:lint-api, r=oli-obk
Fix naming in the lint API Methods for emit lints are named very inconsistently. This PR fixes that up. r? `@compiler-errors`
2 parents 689e07e + 78430fb commit c4a2fc4

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

clippy.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ avoid-breaking-exported-api = false
22

33
# use the various `span_lint_*` methods instead, which also add a link to the docs
44
disallowed-methods = [
5-
"rustc_lint::context::LintContext::struct_span_lint",
6-
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir"
5+
"rustc_lint::context::LintContext::span_lint",
6+
"rustc_middle::ty::context::TyCtxt::node_span_lint"
77
]

clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ impl CompilerLintFunctions {
4141
pub fn new() -> Self {
4242
let mut map = FxHashMap::default();
4343
map.insert("span_lint", "utils::span_lint");
44-
map.insert("struct_span_lint", "utils::span_lint");
4544
map.insert("lint", "utils::span_lint");
4645
map.insert("span_lint_note", "utils::span_lint_and_note");
4746
map.insert("span_lint_help", "utils::span_lint_and_help");

clippy_utils/src/diagnostics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
4747
/// ```
4848
pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) {
4949
#[expect(clippy::disallowed_methods)]
50-
cx.struct_span_lint(lint, sp, msg.to_string(), |diag| {
50+
cx.span_lint(lint, sp, msg.to_string(), |diag| {
5151
docs_link(diag, lint);
5252
});
5353
}
@@ -81,7 +81,7 @@ pub fn span_lint_and_help<T: LintContext>(
8181
help: &str,
8282
) {
8383
#[expect(clippy::disallowed_methods)]
84-
cx.struct_span_lint(lint, span, msg.to_string(), |diag| {
84+
cx.span_lint(lint, span, msg.to_string(), |diag| {
8585
let help = help.to_string();
8686
if let Some(help_span) = help_span {
8787
diag.span_help(help_span, help.to_string());
@@ -124,7 +124,7 @@ pub fn span_lint_and_note<T: LintContext>(
124124
note: &str,
125125
) {
126126
#[expect(clippy::disallowed_methods)]
127-
cx.struct_span_lint(lint, span, msg.to_string(), |diag| {
127+
cx.span_lint(lint, span, msg.to_string(), |diag| {
128128
let note = note.to_string();
129129
if let Some(note_span) = note_span {
130130
diag.span_note(note_span, note);
@@ -146,15 +146,15 @@ where
146146
F: FnOnce(&mut Diagnostic),
147147
{
148148
#[expect(clippy::disallowed_methods)]
149-
cx.struct_span_lint(lint, sp, msg.to_string(), |diag| {
149+
cx.span_lint(lint, sp, msg.to_string(), |diag| {
150150
f(diag);
151151
docs_link(diag, lint);
152152
});
153153
}
154154

155155
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
156156
#[expect(clippy::disallowed_methods)]
157-
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| {
157+
cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| {
158158
docs_link(diag, lint);
159159
});
160160
}
@@ -168,7 +168,7 @@ pub fn span_lint_hir_and_then(
168168
f: impl FnOnce(&mut Diagnostic),
169169
) {
170170
#[expect(clippy::disallowed_methods)]
171-
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| {
171+
cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| {
172172
f(diag);
173173
docs_link(diag, lint);
174174
});

tests/ui-internal/disallow_struct_span_lint.rs renamed to tests/ui-internal/disallow_span_lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_lint::{Lint, LintContext};
1111
use rustc_middle::ty::TyCtxt;
1212

1313
pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
14-
cx.struct_span_lint(lint, span, msg, |_| {});
14+
cx.span_lint(lint, span, msg, |_| {});
1515
}
1616

1717
pub fn b(
@@ -21,7 +21,7 @@ pub fn b(
2121
span: impl Into<MultiSpan>,
2222
msg: impl Into<DiagnosticMessage>,
2323
) {
24-
tcx.struct_span_lint_hir(lint, hir_id, span, msg, |_| {});
24+
tcx.node_span_lint(lint, hir_id, span, msg, |_| {});
2525
}
2626

2727
fn main() {}

tests/ui-internal/disallow_struct_span_lint.stderr renamed to tests/ui-internal/disallow_span_lint.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: use of a disallowed method `rustc_lint::context::LintContext::struct_span_lint`
1+
error: use of a disallowed method `rustc_lint::context::LintContext::span_lint`
22
--> $DIR/disallow_struct_span_lint.rs:14:5
33
|
4-
LL | cx.struct_span_lint(lint, span, msg, |_| {});
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | cx.span_lint(lint, span, msg, |_| {});
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::disallowed-methods` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]`
99

10-
error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::struct_span_lint_hir`
10+
error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::node_span_lint`
1111
--> $DIR/disallow_struct_span_lint.rs:24:5
1212
|
13-
LL | tcx.struct_span_lint_hir(lint, hir_id, span, msg, |_| {});
13+
LL | tcx.node_span_lint(lint, hir_id, span, msg, |_| {});
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)