Skip to content

Commit b996427

Browse files
committed
Auto merge of #153621 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Remove `TyCtxt::node_span_lint` method Part of #153099. One less obstacle before we can remove `lint_level` function. :) r? @JonathanBrouwer
2 parents 3bc6ea5 + 4d7624e commit b996427

6 files changed

Lines changed: 35 additions & 47 deletions

File tree

compiler/rustc_middle/src/lint.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ fn explain_lint_level_source(
298298
/// If you are looking to implement a lint, look for higher level functions,
299299
/// for example:
300300
/// - [`TyCtxt::emit_node_span_lint`]
301-
/// - [`TyCtxt::node_span_lint`]
302301
/// - [`TyCtxt::node_lint`]
303302
/// - `LintContext::opt_span_lint`
304303
///
@@ -488,7 +487,6 @@ pub fn lint_level(
488487
/// for example:
489488
///
490489
/// - [`TyCtxt::emit_node_span_lint`]
491-
/// - [`TyCtxt::node_span_lint`]
492490
/// - [`TyCtxt::node_lint`]
493491
/// - `LintContext::opt_span_lint`
494492
///

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,21 +2542,6 @@ impl<'tcx> TyCtxt<'tcx> {
25422542
diag_lint_level(self.sess, lint, level, Some(span.into()), decorator)
25432543
}
25442544

2545-
/// Emit a lint at the appropriate level for a hir node, with an associated span.
2546-
///
2547-
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
2548-
#[track_caller]
2549-
pub fn node_span_lint(
2550-
self,
2551-
lint: &'static Lint,
2552-
hir_id: HirId,
2553-
span: impl Into<MultiSpan>,
2554-
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
2555-
) {
2556-
let level = self.lint_level_at_node(lint, hir_id);
2557-
lint_level(self.sess, lint, level, Some(span.into()), decorate);
2558-
}
2559-
25602545
/// Find the appropriate span where `use` and outer attributes can be inserted at.
25612546
pub fn crate_level_attribute_injection_span(self) -> Span {
25622547
let node = self.hir_node(hir::CRATE_HIR_ID);

src/librustdoc/passes/lint/bare_urls.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::mem;
66
use std::sync::LazyLock;
77

88
use regex::Regex;
9-
use rustc_errors::Applicability;
9+
use rustc_errors::{Applicability, DiagDecorator};
1010
use rustc_hir::HirId;
1111
use rustc_resolve::rustdoc::pulldown_cmark::{Event, Parser, Tag};
1212
use rustc_resolve::rustdoc::source_span_for_markdown_range;
@@ -24,30 +24,35 @@ pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &
2424
let maybe_sp = source_span_for_markdown_range(cx.tcx, dox, &range, &item.attrs.doc_strings)
2525
.map(|(sp, _)| sp);
2626
let sp = maybe_sp.unwrap_or_else(|| item.attr_span(cx.tcx));
27-
cx.tcx.node_span_lint(crate::lint::BARE_URLS, hir_id, sp, |lint| {
28-
lint.primary_message(msg)
29-
.note("bare URLs are not automatically turned into clickable links");
30-
// The fallback of using the attribute span is suitable for
31-
// highlighting where the error is, but not for placing the < and >
32-
if let Some(sp) = maybe_sp {
33-
if let Some(without_brackets) = without_brackets {
34-
lint.multipart_suggestion(
35-
"use an automatic link instead",
36-
vec![(sp, format!("<{without_brackets}>"))],
37-
Applicability::MachineApplicable,
38-
);
39-
} else {
40-
lint.multipart_suggestion(
41-
"use an automatic link instead",
42-
vec![
43-
(sp.shrink_to_lo(), "<".to_string()),
44-
(sp.shrink_to_hi(), ">".to_string()),
45-
],
46-
Applicability::MachineApplicable,
47-
);
27+
cx.tcx.emit_node_span_lint(
28+
crate::lint::BARE_URLS,
29+
hir_id,
30+
sp,
31+
DiagDecorator(|lint| {
32+
lint.primary_message(msg)
33+
.note("bare URLs are not automatically turned into clickable links");
34+
// The fallback of using the attribute span is suitable for
35+
// highlighting where the error is, but not for placing the < and >
36+
if let Some(sp) = maybe_sp {
37+
if let Some(without_brackets) = without_brackets {
38+
lint.multipart_suggestion(
39+
"use an automatic link instead",
40+
vec![(sp, format!("<{without_brackets}>"))],
41+
Applicability::MachineApplicable,
42+
);
43+
} else {
44+
lint.multipart_suggestion(
45+
"use an automatic link instead",
46+
vec![
47+
(sp.shrink_to_lo(), "<".to_string()),
48+
(sp.shrink_to_hi(), ">".to_string()),
49+
],
50+
Applicability::MachineApplicable,
51+
);
52+
}
4853
}
49-
}
50-
});
54+
}),
55+
);
5156
};
5257

5358
let mut p = Parser::new_ext(dox, main_body_opts()).into_offset_iter();

src/tools/clippy/clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ path = "rustc_lint::context::LintContext::span_lint"
1313
reason = "this function does not add a link to our documentation; please use the `clippy_utils::diagnostics::span_lint*` functions instead"
1414

1515
[[disallowed-methods]]
16-
path = "rustc_middle::ty::context::TyCtxt::node_span_lint"
16+
path = "rustc_middle::ty::context::TyCtxt::emit_node_span_lint"
1717
reason = "this function does not add a link to our documentation; please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead"

src/tools/clippy/clippy_utils/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,14 @@ pub fn span_lint_hir_and_then(
326326
f: impl FnOnce(&mut Diag<'_, ()>),
327327
) {
328328
#[expect(clippy::disallowed_methods)]
329-
cx.tcx.node_span_lint(lint, hir_id, sp, |diag| {
329+
cx.tcx.emit_node_span_lint(lint, hir_id, sp, rustc_errors::DiagDecorator(|diag| {
330330
diag.primary_message(msg);
331331
f(diag);
332332
docs_link(diag, lint);
333333

334334
#[cfg(debug_assertions)]
335335
validate_diag(diag);
336-
});
336+
}));
337337
}
338338

339339
/// Add a span lint with a suggestion on how to fix it.

src/tools/clippy/tests/ui-internal/disallow_span_lint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate rustc_hir;
66
extern crate rustc_lint;
77
extern crate rustc_middle;
88

9-
use rustc_errors::{DiagMessage, MultiSpan};
9+
use rustc_errors::{DiagDecorator, DiagMessage, MultiSpan};
1010
use rustc_hir::hir_id::HirId;
1111
use rustc_lint::{Lint, LintContext};
1212
use rustc_middle::ty::TyCtxt;
@@ -19,10 +19,10 @@ pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into<MultiSpan>,
1919
}
2020

2121
pub fn b(tcx: TyCtxt<'_>, lint: &'static Lint, hir_id: HirId, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) {
22-
tcx.node_span_lint(lint, hir_id, span, |lint| {
22+
tcx.emit_node_span_lint(lint, hir_id, span, DiagDecorator(|lint| {
2323
//~^ disallowed_methods
2424
lint.primary_message(msg);
25-
});
25+
}));
2626
}
2727

2828
fn main() {}

0 commit comments

Comments
 (0)