Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
72b6825
test `#[naked]` with `#[link_section = "..."]` on windows
folkertdev Mar 30, 2026
edad629
Remove `BuiltinLintDiag::ElidedLifetimesInPaths` variant
GuillaumeGomez Apr 6, 2026
e03e00f
Remove `BuiltinLintDiag::UnusedImports` variant
GuillaumeGomez Apr 6, 2026
12457f8
Remove `BuiltinLintDiag::NamedArgumentUsedPositionally` variant
GuillaumeGomez Apr 6, 2026
caeaf19
Remove `BuiltinLintDiag`
GuillaumeGomez Apr 6, 2026
aa9da4b
Hexagon inline asm: add reg_pair, vreg, vreg_pair, and qreg register …
androm3da Apr 2, 2026
574d877
Parenthesize block-like expressions in index base of pretty printer
aytey Mar 18, 2026
56f43b5
Parenthesize block-like expressions in call callee of pretty printer
aytey Apr 8, 2026
27e3d26
rename test
aytey Apr 8, 2026
1e8c6f0
Nooooo my workflow relied on programs using `niko` as an identifier
jdonszelmann Apr 6, 2026
fbdcd19
make `expected_literal` positive
jdonszelmann Apr 6, 2026
092f0ca
Clarify that `core::range::RangeInclusive` does not have special syntax
shepmaster Apr 8, 2026
eef4363
Clarify that `core::range::{Range,RangeFrom,RangeToInclusive}` do not…
shepmaster Apr 8, 2026
1d0d172
Rollup merge of #154912 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
JonathanBrouwer Apr 8, 2026
b040d54
Rollup merge of #154598 - folkertdev:windows-naked-link-section, r=ma…
JonathanBrouwer Apr 8, 2026
3fb712c
Rollup merge of #154719 - androm3da:hexagon-inline-asm-register-class…
JonathanBrouwer Apr 8, 2026
8be4c46
Rollup merge of #154057 - aytey:fix-block-index-paren, r=fmease
JonathanBrouwer Apr 8, 2026
83e8133
Rollup merge of #154893 - jdonszelmann:expected-literal-positive, r=J…
JonathanBrouwer Apr 8, 2026
efa9224
Rollup merge of #155002 - shepmaster:clarify-new-range, r=tgross35
JonathanBrouwer Apr 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove BuiltinLintDiag::UnusedImports variant
  • Loading branch information
GuillaumeGomez committed Apr 6, 2026
commit e03e00f9e3bf197a47566ef71cb6b51cbbd5b211
25 changes: 0 additions & 25 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,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::UnusedImports {
remove_whole_use,
num_to_remove,
remove_spans,
test_module_span,
span_snippets,
} => {
let sugg = if remove_whole_use {
lints::UnusedImportsSugg::RemoveWholeUse { span: remove_spans[0] }
} else {
lints::UnusedImportsSugg::RemoveImports { remove_spans, num_to_remove }
};
let test_module_span =
test_module_span.map(|span| self.sess.source_map().guess_head_span(span));

lints::UnusedImports {
sugg,
test_module_span,
num_snippets: span_snippets.len(),
span_snippets: DiagArgValue::StrListSepByAnd(
span_snippets.into_iter().map(Cow::Owned).collect(),
),
}
.into_diag(dcx, level)
}
BuiltinLintDiag::NamedArgumentUsedPositionally {
position_sp_to_replace,
position_sp_for_msg,
Expand Down
44 changes: 0 additions & 44 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3039,50 +3039,6 @@ pub(crate) struct IllFormedAttributeInputHelp {
pub lint: String,
}

#[derive(Diagnostic)]
#[diag(
"{$num_snippets ->
[one] unused import: {$span_snippets}
*[other] unused imports: {$span_snippets}
}"
)]
pub(crate) struct UnusedImports {
#[subdiagnostic]
pub sugg: UnusedImportsSugg,
#[help("if this is a test module, consider adding a `#[cfg(test)]` to the containing module")]
pub test_module_span: Option<Span>,

pub span_snippets: DiagArgValue,
pub num_snippets: usize,
}

#[derive(Subdiagnostic)]
pub(crate) enum UnusedImportsSugg {
#[suggestion(
"remove the whole `use` item",
applicability = "machine-applicable",
code = "",
style = "tool-only"
)]
RemoveWholeUse {
#[primary_span]
span: Span,
},
#[multipart_suggestion(
"{$num_to_remove ->
[one] remove the unused import
*[other] remove the unused imports
}",
applicability = "machine-applicable",
style = "tool-only"
)]
RemoveImports {
#[suggestion_part(code = "")]
remove_spans: Vec<Span>,
num_to_remove: usize,
},
}

#[derive(Diagnostic)]
#[diag("named argument `{$named_arg_name}` is not used by name")]
pub(crate) struct NamedArgumentUsedPositionally {
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,6 @@ pub enum DeprecatedSinceKind {
// becomes hacky (and it gets allocated).
#[derive(Debug)]
pub enum BuiltinLintDiag {
UnusedImports {
remove_whole_use: bool,
num_to_remove: usize,
remove_spans: Vec<Span>,
test_module_span: Option<Span>,
span_snippets: Vec<String>,
},
NamedArgumentUsedPositionally {
/// Span where the named argument is used by position and will be replaced with the named
/// argument name
Expand Down
35 changes: 26 additions & 9 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
// - `check_unused` finally emits the diagnostics based on the data generated
// in the last step

use std::borrow::Cow;

use rustc_ast as ast;
use rustc_ast::visit::{self, Visitor};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::MultiSpan;
use rustc_errors::{DiagArgValue, Diagnostic, MultiSpan};
use rustc_hir::def::{DefKind, Res};
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::{
MACRO_USE_EXTERN_CRATE, UNUSED_EXTERN_CRATES, UNUSED_IMPORTS, UNUSED_QUALIFICATIONS,
};
Expand Down Expand Up @@ -496,16 +497,32 @@ impl Resolver<'_, '_> {
}
};

visitor.r.lint_buffer.buffer_lint(
visitor.r.lint_buffer.dyn_buffer_lint_any(
UNUSED_IMPORTS,
unused.use_tree_id,
ms,
BuiltinLintDiag::UnusedImports {
remove_whole_use,
num_to_remove,
remove_spans,
test_module_span,
span_snippets,
move |dcx, level, sess| {
let sugg = if remove_whole_use {
errors::UnusedImportsSugg::RemoveWholeUse { span: remove_spans[0] }
} else {
errors::UnusedImportsSugg::RemoveImports { remove_spans, num_to_remove }
};
let test_module_span = test_module_span.map(|span| {
sess.downcast_ref::<rustc_session::Session>()
.expect("expected a `Session`")
.source_map()
.guess_head_span(span)
});

errors::UnusedImports {
sugg,
test_module_span,
num_snippets: span_snippets.len(),
span_snippets: DiagArgValue::StrListSepByAnd(
span_snippets.into_iter().map(Cow::Owned).collect(),
),
}
.into_diag(dcx, level)
},
);
}
Expand Down
46 changes: 45 additions & 1 deletion compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_errors::codes::*;
use rustc_errors::formatting::DiagMessageAddArg;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, Diagnostic, ElidedLifetimeInPathSubdiag,
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, ElidedLifetimeInPathSubdiag,
EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
Expand Down Expand Up @@ -1747,3 +1747,47 @@ pub(crate) struct ElidedLifetimesInPaths {
#[subdiagnostic]
pub subdiag: rustc_errors::ElidedLifetimeInPathSubdiag,
}

#[derive(Diagnostic)]
#[diag(
"{$num_snippets ->
[one] unused import: {$span_snippets}
*[other] unused imports: {$span_snippets}
}"
)]
pub(crate) struct UnusedImports {
#[subdiagnostic]
pub sugg: UnusedImportsSugg,
#[help("if this is a test module, consider adding a `#[cfg(test)]` to the containing module")]
pub test_module_span: Option<Span>,

pub span_snippets: DiagArgValue,
pub num_snippets: usize,
}

#[derive(Subdiagnostic)]
pub(crate) enum UnusedImportsSugg {
#[suggestion(
"remove the whole `use` item",
applicability = "machine-applicable",
code = "",
style = "tool-only"
)]
RemoveWholeUse {
#[primary_span]
span: Span,
},
#[multipart_suggestion(
"{$num_to_remove ->
[one] remove the unused import
*[other] remove the unused imports
}",
applicability = "machine-applicable",
style = "tool-only"
)]
RemoveImports {
#[suggestion_part(code = "")]
remove_spans: Vec<Span>,
num_to_remove: usize,
},
}