Remove BuiltinLintDiag::AbsPathWithModule

This commit is contained in:
Guillaume Gomez
2026-03-25 17:36:26 +01:00
parent 13373707ae
commit 99f9ba0a33
5 changed files with 42 additions and 47 deletions
@@ -24,28 +24,6 @@ pub struct DecorateBuiltinLint<'sess, 'tcx> {
impl<'a> Diagnostic<'a, ()> for DecorateBuiltinLint<'_, '_> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
match self.diagnostic {
BuiltinLintDiag::AbsPathWithModule(mod_span) => {
let (replacement, applicability) =
match self.sess.source_map().span_to_snippet(mod_span) {
Ok(ref s) => {
// FIXME(Manishearth) ideally the emitting code
// can tell us whether or not this is global
let opt_colon =
if s.trim_start().starts_with("::") { "" } else { "::" };
(format!("crate{opt_colon}{s}"), Applicability::MachineApplicable)
}
Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
};
lints::AbsPathWithModule {
sugg: lints::AbsPathWithModuleSugg {
span: mod_span,
applicability,
replacement,
},
}
.into_diag(dcx, level)
}
BuiltinLintDiag::ElidedLifetimesInPaths(
n,
path_span,
-19
View File
@@ -3011,25 +3011,6 @@ pub(crate) struct IllFormedAttributeInput {
pub docs: &'static str,
}
#[derive(Diagnostic)]
#[diag(
"absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition"
)]
pub(crate) struct AbsPathWithModule {
#[subdiagnostic]
pub sugg: AbsPathWithModuleSugg,
}
#[derive(Subdiagnostic)]
#[suggestion("use `crate`", code = "{replacement}")]
pub(crate) struct AbsPathWithModuleSugg {
#[primary_span]
pub span: Span,
#[applicability]
pub applicability: Applicability,
pub replacement: String,
}
#[derive(Diagnostic)]
#[diag("hidden lifetime parameters in types are deprecated")]
pub(crate) struct ElidedLifetimesInPaths {
-1
View File
@@ -656,7 +656,6 @@ pub enum DeprecatedSinceKind {
// becomes hacky (and it gets allocated).
#[derive(Debug)]
pub enum BuiltinLintDiag {
AbsPathWithModule(Span),
ElidedLifetimesInPaths(usize, Span, bool, Span),
UnusedImports {
remove_whole_use: bool,
+23 -5
View File
@@ -11,7 +11,7 @@
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, MultiSpan, SuggestionStyle,
Applicability, Diag, DiagCtxtHandle, Diagnostic, ErrorGuaranteed, MultiSpan, SuggestionStyle,
struct_span_code_err,
};
use rustc_feature::BUILTIN_ATTRIBUTES;
@@ -23,7 +23,6 @@
use rustc_middle::bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::{
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, AMBIGUOUS_GLOB_IMPORTS, AMBIGUOUS_IMPORT_VISIBILITIES,
AMBIGUOUS_PANIC_IMPORTS, MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
@@ -510,12 +509,31 @@ pub(crate) fn lint_if_path_starts_with_module(
return;
}
let diag = BuiltinLintDiag::AbsPathWithModule(root_span);
self.lint_buffer.buffer_lint(
let (replacement, applicability) =
match self.tcx.sess.source_map().span_to_snippet(root_span) {
Ok(ref s) => {
// FIXME(Manishearth) ideally the emitting code
// can tell us whether or not this is global
let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" };
(format!("crate{opt_colon}{s}"), Applicability::MachineApplicable)
}
Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
};
self.lint_buffer.dyn_buffer_lint(
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
node_id,
root_span,
diag,
move |dcx, level| {
errors::AbsPathWithModule {
sugg: errors::AbsPathWithModuleSugg {
span: root_span,
applicability,
replacement,
},
}
.into_diag(dcx, level)
},
);
}
+19
View File
@@ -1721,3 +1721,22 @@ pub(crate) struct SingleUseLifetimeSugg {
pub replace_lt: String,
}
#[derive(Diagnostic)]
#[diag(
"absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition"
)]
pub(crate) struct AbsPathWithModule {
#[subdiagnostic]
pub sugg: AbsPathWithModuleSugg,
}
#[derive(Subdiagnostic)]
#[suggestion("use `crate`", code = "{replacement}")]
pub(crate) struct AbsPathWithModuleSugg {
#[primary_span]
pub span: Span,
#[applicability]
pub applicability: Applicability,
pub replacement: String,
}