Fix imports of built-in macros (mostly)#61877
Fix imports of built-in macros (mostly)#61877petrochenkov wants to merge 3 commits intorust-lang:masterfrom
Conversation
| // #[repr(transparent)] on unions. | ||
| (active, transparent_unions, "1.37.0", Some(60405), None), | ||
|
|
||
| // `use builtin_macro`. |
There was a problem hiding this comment.
| // `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.
I don't understand what this comment means. Can you illustrate the difference?
There was a problem hiding this comment.
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.
Oh I see; I read .stderr sloppily... thanks!
There was a problem hiding this comment.
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
DefIds fromLOCAL_CRATEand theirDefIndexes occupy a continuous fixed-size range immediately followingGlobalMetaDataentries.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 aDefIdat all. I didn't try it yet, but perhaps I should.Caveats:
DefIds.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 haveDefIdfrom 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