-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix imports of built-in macros (mostly) #61877
Conversation
@@ -570,6 +570,9 @@ declare_features! ( | |||
// #[repr(transparent)] on unions. | |||
(active, transparent_unions, "1.37.0", Some(60405), None), | |||
|
|||
// `use builtin_macro`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// `use builtin_macro`. | |
// Allows `use builtin_macro;`. |
@@ -0,0 +1,10 @@ | |||
// FIXME: Individual imports of built-in macros are not stability checked right now, | |||
// so the whole feature is gated instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this comment means. Can you illustrate the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use concat_idents as unstable;
below should produce a "concat_idents
is unstable" error, but it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see; I read .stderr
sloppily... thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahaha, concat_idents
and friends are actually stable themselves, they just report feature errors as a part of their expansion.
I'll fix this, but #61898 is a pre-requisite.
I'm going to try the |
Something I really wanted years ago was to move the "definitions" of builtin types into libcore. So I'm wondering, can we put |
That's an interesting idea. |
For built-in types it was tried in #32274. For built-in macros it may work generally better because they are not so fundamentally tied to the compiler, the compiler just provides expander functions for them, otherwise they are usual macros. |
Built-in macros introduced through |
Nit: I feel like these should be lang items -- I'm not sure why we have so many categories of "special thing known to the compiler" but I think we should centralize on one of them. |
@nikomatsakis IMO we should distinguish between "this is exposing a compiler primitive to the library" and "this is exposing a library entity to the compiler", only the latter of which needs to be unique. |
syntax: Factor out common fields from `SyntaxExtension` variants And some other related cleanups. Continuation of rust-lang#61606. This will also help to unblock rust-lang#61877.
syntax: Factor out common fields from `SyntaxExtension` variants And some other related cleanups. Continuation of rust-lang#61606. This will also help to unblock rust-lang#61877.
☔ The latest upstream changes (presumably #61945) made this pull request unmergeable. Please resolve the merge conflicts. |
Yess, I have been thinking exactly about this when adding primitives names resolution to rust-analyzer. It also helps with goto definition UX in IDEs, because you have the actual source to go to. It probably shouldn't be literally libcore though, because |
|
Nope, EDIT: worst case, this will change and we can reexport those items in |
Now waiting on #62042 |
#62086 confirmed that the idea with defining built-in macros through libcore is viable, so I'll close this PR. |
Built-in macros now have
DefId
s fromLOCAL_CRATE
and theirDefIndex
es occupy a continuous fixed-size range immediately followingGlobalMetaData
entries.This way they can be used in imports without causing ICEs due to
CrateNum::BuiltinMacros
.I tried a few different approaches mentioned in #61687, but this one seems to be the least ugly and painful.
EDIT: One more alternative is to follow the example of
Res::PrimTy(hir::PrimTy)
and introduceRes::BuiltinMacro(usize)
so that built-in macros don't need aDefId
at all. I didn't try it yet, but perhaps I should.Caveats:
DefId
s.This can be observable in corner cases (e.g. glob vs glob conflicts, see the test
import-builtin-macros-bug.rs
).I tried to convert
(THAT_CRATE, DefIndex)
into(LOCAL_CRATE, DefIndex)
for built-in macros immediately during decoding, but apparently there are assumptions that entries from other crates cannot haveDefId
from the current crate after decoding, so it caused ICEs.use concat_idents;
does not produce a feature error) so the whole feature is gated instead.The primary motivation for the fix is reexporting built-in macros from the standard library and we can use unstable features in the standard library.
The proper solution to this (and multiple other) problems is moving stability/deprecation checking into resolve.
Closes #61687
cc #61875
r? @eddyb