Skip to content

Remove AttributeLintKind#155760

Open
GuillaumeGomez wants to merge 5 commits intorust-lang:mainfrom
GuillaumeGomez:rm-attributelintkind
Open

Remove AttributeLintKind#155760
GuillaumeGomez wants to merge 5 commits intorust-lang:mainfrom
GuillaumeGomez:rm-attributelintkind

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez commented Apr 25, 2026

View all comments

Part of #153099.

The AttributeLintKind type is finally gone! \o/

Diff is this big because I moved a file and a lot of Diagnostic types. :')

r? @JonathanBrouwer

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

Some changes occurred to diagnostic attributes.

cc @mejrs

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 25, 2026
@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this Apr 25, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

(Assigning myself for the suspicious infrastructural changes in the first commit.)

let Self { callback, info } = self;
// FIXME: remove this transmute once lifetime coercion blocker is solved.
let info: rustc_session::SessionAndCrateName<'static> =
unsafe { std::mem::transmute(info) };
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is does not sound correct to me that the lifetime is static here, shouldn't this be the lifetime of the session?
I'm also missing a safety comment (and kinda sad that we need unsafe for this in the first place)

cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
move |dcx, level| {
move |dcx, level, _| {
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also kinda sad that all the calls need to ignore the third argument now except the few cursed ones that need it.
Some alternatives are:

  • Create a separate function next to emit_dyn_lint that takes a closure with the special argument
  • My idea in the next comment, with making session the first argument

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a different function is likely better. For the session idea, answered in the other comment.

pub span: MultiSpan,
pub callback: Box<
dyn for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static,
dyn for<'a> Fn(DiagCtxtHandle<'a>, Level, &dyn std::any::Any) -> Diag<'a, ()>
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the big problem is the crate name, we could just pass Session here without a dyn Any. How much would the diagnostics regress if we just don't make crate name available anymore? I think that shouldn't be too bad, and would prevent us from adding all this ugly code

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case maybe we could even replace the DiagCtxtHandle<'a> with &'a Session since I think you can get the DiagCtxtHandle<'a> from the session

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the current crate name but other crates name. So Session wouldn't solve our issue here.

Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm saying is I believe there's only one diagnostic that needs the crate name, would it be that bad to just remove the crate name from the help message where it's used

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tests/ui/check-cfg/report-in-external-macros.rs#cargo it would do:

33	   |
34	   = note: no expected values for `feature`
-	   = note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate
-	   = help: try referring to `cfg_macro::my_lib_macro_feature` crate for guidance on how handle this unexpected cfg
-	   = help: the macro `cfg_macro::my_lib_macro_feature` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro`
38	   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
39	   = note: this warning originates in the macro `cfg_macro::my_lib_macro_feature` (in Nightly builds, run with -Z macro-backtrace for more info)

I personally don't care but maybe @Urgau has another opinion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to fully remove the help message, only change it to not have the crate name in it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do away with just the macro name in most places in the diagnostic, except for the part where we tell people to update there dependency: cargo update -p cfg_macro.

We obviously should not suggest cargo update, that's too big of a hammer.

If it's too big of a hassle to keep a TyCtxt for the diagnostic, we can probably remove the suggestion to update the crate. That suggestion was added when we stabilized --check-cfg, at a time when basically no crate was --check-cfg compatible yet; the stabilization happened over 1 year ago, so the suggestion is probably no longer relevant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note for myself, it means we can remove:

-      = help: the macro `cfg_macro::my_lib_macro_feature` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro`

};
let sess = SessionAndCrateName { sess: self.sess, crate_name };
// FIXME: remove this transmute call once lifetime coercion issue is fixed.
let sess: SessionAndCrateName<'static> = unsafe { std::mem::transmute(sess) };
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here about `static being questionable and the safety comment and about unsafe being sad

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, some deeper investigations is needed. At the beginning, I simply used tcx.sess and no transmute was needed because lifetime coercion was working fine. But for SessionAndCrateName, coercion doesn't work. I have some suspicions about the closure. Anyway, to be investigated.

@JonathanBrouwer JonathanBrouwer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 25, 2026
sess: &Session,
inst: &impl Fn(EscapeQuotes) -> String,
) -> lints::UnexpectedCfgCargoHelp {
) -> errors::UnexpectedCfgCargoHelp {
Copy link
Copy Markdown
Member

@Urgau Urgau Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I find it weird that the unexpected_cfgs diagnostic structs are in an errors module, while we are talking about a warn-by-default lint. I would expected only hard errors in an errors module, not warnings.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no clear pattern of where you put Diagnostic types. By default, it's mostly in crate::errors, even if it's lints.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things on my todo list is do find a better name for these modules, perhaps diagnostics.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would second such MCP.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

triagebot.toml has been modified, there may have been changes to the review queue.

cc @davidtwco, @wesleywiser

@rustbot rustbot added the A-meta Area: Issues & PRs about the rust-lang/rust repository itself label Apr 25, 2026
@GuillaumeGomez
Copy link
Copy Markdown
Member Author

Not ready yet. Just cleaning up a few things. Still need to update the check_cfg code to remove the need for TyCtxt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-meta Area: Issues & PRs about the rust-lang/rust repository itself S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants