Conversation
|
Some changes occurred to diagnostic attributes. cc @mejrs Some changes occurred in compiler/rustc_attr_parsing |
This comment has been minimized.
This comment has been minimized.
|
(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) }; |
There was a problem hiding this comment.
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, _| { |
There was a problem hiding this comment.
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_lintthat takes a closure with the special argument - My idea in the next comment, with making session the first argument
There was a problem hiding this comment.
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, ()> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
It's not the current crate name but other crates name. So Session wouldn't solve our issue here.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I don't think we need to fully remove the help message, only change it to not have the crate name in it
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) }; |
There was a problem hiding this comment.
Same thing here about `static being questionable and the safety comment and about unsafe being sad
There was a problem hiding this comment.
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.
| sess: &Session, | ||
| inst: &impl Fn(EscapeQuotes) -> String, | ||
| ) -> lints::UnexpectedCfgCargoHelp { | ||
| ) -> errors::UnexpectedCfgCargoHelp { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
There is no clear pattern of where you put Diagnostic types. By default, it's mostly in crate::errors, even if it's lints.
There was a problem hiding this comment.
One of the things on my todo list is do find a better name for these modules, perhaps diagnostics.rs
…ify code when `Session` is not needed
|
|
|
Not ready yet. Just cleaning up a few things. Still need to update the |
View all comments
Part of #153099.
The
AttributeLintKindtype is finally gone! \o/Diff is this big because I moved a file and a lot of
Diagnostictypes. :')r? @JonathanBrouwer