Add new ambiguity error for tools#158146
Conversation
This implements the ambiguity error and stop the tool attributes from being affected by `#[no_implicit_prelude]` per the RFC. To avoid widespread ambiguity errors, the attribute tools are only resolved if they are resolved as part of macro path. `registered_tool_decls` is adjusted to use plain symbol instead of `IdentKey`; previously `ModuleGlobs` will adjust the ctxt to `ExpnId::root` so was comparing ignoring the ctxt anyway.
This is a mistake in the RFC, the relevant comment - https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rfcs/pull/3808#discussion_r2075190210. |
|
Introduction of the new Another relevant comment chain - https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rfcs/pull/3808#discussion_r2075215063
From the PR description it looks like we cannot actually pull it off. |
|
cc @jyn514 |
I'd like to experiment with this myself a bit, probably this weekend. |
Yes, I also dislike this part, but it feels to me that otherwise this is going to be a significant breakage. The fact that rustc itself breaks due to
The error is between tool vs modules in rustc. But in the wild perhaps Instead of tweaking the ambiguity rules, I wonder if we should just handle the resolution of attributes differently?
And raise an ambiguity error if both resolves. This way the tools are no longer in any namespace. I feel that this also a more logical way of handling built-in attributes -- they really feel that they are part of the language and should not be in the macro namespace. |
That's exactly what we are doing for built-in attributes right now. If we introduce the notion of built-in tool attributes for |
Well, technically there is a way to avoid breakage - by keeping the currently implemented rules :) But it contradicts to this key point of the RFC:
Basically if rustfmt sees rustfmt treats So the choices are either
Sigh. |
|
Note: other attributes that are recognized textually (derive helpers - by proc macros, or built-ins - by the compiler) currently follow the key point of the RFC. |
Is this exclusively for the benefit of tools that run pre-(name res/expansion)? Or are there other benefits as well? |
|
@mejrs |
|
If tool-attributes are always resolved regardless the attribute exists or not (and error raised if there's ambiguity), adding new diagnostics attribute won't be a breaking change (but it will be a breaking change for the initial resolver change, or a new pre-defined tool is added). However the point of adding built-in attribute being a breaking change still stands. Another approach is to add an ambiguity warning when a macro attribute conflicts with a tool attribute, and we still prefer the macro attribute? |
Tracking issue: #66079
This implements the resolution changes of RFC 3808.
A new ambiguity error is added, and the tool attributes is no longer being affected by
#[no_implicit_prelude]per the RFC. This is a breaking change.To avoid widespread ambiguity errors, the attribute tools are only resolved if they are resolved as part of macro path (this could be further split to just attribute macros, but at which point we are kind of adding a new type of namespace?
Mark as draft until the implementation detail is agreed and a crater run is conducted.
r? @petrochenkov