Skip to content

Add information about group a lint belongs to #140794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ pub struct LintStore {
lint_groups: FxIndexMap<&'static str, LintGroup>,
}

impl LintStoreMarker for LintStore {}
impl LintStoreMarker for LintStore {
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = rustc_session::LintGroup> + '_> {
Box::new(self.get_lint_groups().map(|(name, lints, is_externally_loaded)| {
rustc_session::LintGroup { name, lints, is_externally_loaded }
}))
}
}

/// The target of the `by_name` map, which accounts for renaming/deprecation.
#[derive(Debug)]
Expand Down
35 changes: 33 additions & 2 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,34 @@ impl LintExpectation {
}

fn explain_lint_level_source(
sess: &Session,
lint: &'static Lint,
level: Level,
src: LintLevelSource,
err: &mut Diag<'_, ()>,
) {
/// Find the name of the lint group that contains the given lint.
/// Assumes the lint only belongs to one group.
fn lint_group_name(
lint: &'static Lint,
sess: &Session,
allow_external: bool,
) -> Option<&'static str> {
let mut lint_groups_iter = sess.lint_groups_iter();
let lint_id = LintId::of(lint);
lint_groups_iter
.find(|lint_group| {
if !allow_external && lint_group.is_externally_loaded {
return false;
}
lint_group
.lints
.iter()
.find(|lint_group_lint| **lint_group_lint == lint_id)
.is_some()
})
.map(|lint_group| lint_group.name)
}
let name = lint.name_lower();
if let Level::Allow = level {
// Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
Expand All @@ -224,7 +247,15 @@ fn explain_lint_level_source(
}
match src {
LintLevelSource::Default => {
err.note_once(format!("`#[{}({})]` on by default", level.as_str(), name));
let level_str = level.as_str();
match lint_group_name(lint, sess, false) {
Some(group_name) => {
err.note_once(format!("`#[{level_str}({name})]` (part of `#[{level_str}({group_name})]`) on by default"));
}
None => {
err.note_once(format!("`#[{level_str}({name})]` on by default"));
}
}
}
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
let flag = orig_level.to_cmd_flag();
Expand Down Expand Up @@ -428,7 +459,7 @@ pub fn lint_level(
decorate(&mut err);
}

explain_lint_level_source(lint, level, src, &mut err);
explain_lint_level_source(sess, lint, level, src, &mut err);
err.emit()
}
lint_level_impl(sess, lint, level, span, Box::new(decorate))
Expand Down
19 changes: 18 additions & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::config::{
SwitchWithOptPath,
};
use crate::filesearch::FileSearch;
use crate::lint::LintId;
use crate::parse::{ParseSess, add_feature_diagnostics};
use crate::search_paths::SearchPath;
use crate::{errors, filesearch, lint};
Expand Down Expand Up @@ -137,7 +138,10 @@ pub struct CompilerIO {
pub temps_dir: Option<PathBuf>,
}

pub trait LintStoreMarker: Any + DynSync + DynSend {}
pub trait LintStoreMarker: Any + DynSync + DynSend {
/// Provides a way to access lint groups without depending on `rustc_lint`
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_>;
}

/// Represents the data associated with a compilation
/// session for a single crate.
Expand Down Expand Up @@ -243,6 +247,12 @@ impl CodegenUnits {
}
}

pub struct LintGroup {
pub name: &'static str,
pub lints: Vec<LintId>,
pub is_externally_loaded: bool,
}

impl Session {
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
self.miri_unleashed_features.lock().push((span, feature_gate));
Expand Down Expand Up @@ -608,6 +618,13 @@ impl Session {
(&*self.target.staticlib_prefix, &*self.target.staticlib_suffix)
}
}

pub fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_> {
match self.lint_store {
Some(ref lint_store) => lint_store.lint_groups_iter(),
None => Box::new(std::iter::empty()),
}
}
}

// JUSTIFICATION: defn of the suggested wrapper fns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ LL | if X.is_some() {
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
= note: `#[deny(static_mut_refs)]` on by default
= note: `#[deny(static_mut_refs)]` (part of `#[deny(rust_2024_compatibility)]`) on by default

error: aborting due to 26 previous errors

22 changes: 11 additions & 11 deletions tests/ui/abi/unsupported.aarch64.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | fn ptx_ptr(f: extern "ptx-kernel" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target
--> $DIR/unsupported.rs:40:1
Expand Down Expand Up @@ -215,7 +215,7 @@ LL | fn ptx_ptr(f: extern "ptx-kernel" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "aapcs" is not supported on this target
Expand All @@ -226,7 +226,7 @@ LL | fn aapcs_ptr(f: extern "aapcs" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "msp430-interrupt" is not supported on this target
Expand All @@ -237,7 +237,7 @@ LL | fn msp430_ptr(f: extern "msp430-interrupt" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "avr-interrupt" is not supported on this target
Expand All @@ -248,7 +248,7 @@ LL | fn avr_ptr(f: extern "avr-interrupt" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "riscv-interrupt-m" is not supported on this target
Expand All @@ -259,7 +259,7 @@ LL | fn riscv_ptr(f: extern "riscv-interrupt-m" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "x86-interrupt" is not supported on this target
Expand All @@ -270,7 +270,7 @@ LL | fn x86_ptr(f: extern "x86-interrupt" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "thiscall" is not supported on this target
Expand All @@ -281,7 +281,7 @@ LL | fn thiscall_ptr(f: extern "thiscall" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "stdcall" is not supported on this target
Expand All @@ -292,7 +292,7 @@ LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
Expand All @@ -303,7 +303,7 @@ LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "C-cmse-nonsecure-entry" is not supported on this target
Expand All @@ -314,5 +314,5 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

20 changes: 10 additions & 10 deletions tests/ui/abi/unsupported.arm.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | fn ptx_ptr(f: extern "ptx-kernel" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target
--> $DIR/unsupported.rs:40:1
Expand Down Expand Up @@ -194,7 +194,7 @@ LL | fn ptx_ptr(f: extern "ptx-kernel" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "msp430-interrupt" is not supported on this target
Expand All @@ -205,7 +205,7 @@ LL | fn msp430_ptr(f: extern "msp430-interrupt" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "avr-interrupt" is not supported on this target
Expand All @@ -216,7 +216,7 @@ LL | fn avr_ptr(f: extern "avr-interrupt" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "riscv-interrupt-m" is not supported on this target
Expand All @@ -227,7 +227,7 @@ LL | fn riscv_ptr(f: extern "riscv-interrupt-m" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "x86-interrupt" is not supported on this target
Expand All @@ -238,7 +238,7 @@ LL | fn x86_ptr(f: extern "x86-interrupt" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "thiscall" is not supported on this target
Expand All @@ -249,7 +249,7 @@ LL | fn thiscall_ptr(f: extern "thiscall" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "stdcall" is not supported on this target
Expand All @@ -260,7 +260,7 @@ LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
Expand All @@ -271,7 +271,7 @@ LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Future breakage diagnostic:
warning: the calling convention "C-cmse-nonsecure-entry" is not supported on this target
Expand All @@ -282,5 +282,5 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` (part of `#[warn(future_incompatible)]`) on by default

Loading
Loading