Closed
Description
use column; // error: cannot import a built-in macro
fn main() {}
The reason behind this error is that if you import something with a DefId
, that DefId
should be supported by all stages of compilation (metadata emitting specifically), but built-in macros don't have such a DefId
.
The crate ID in their DefId
has special value CrateNum::BuiltinMacros
that is supported only inside rustc_resolve and causes ICEs every time it leaves it.
Activity
petrochenkov commentedon Jun 9, 2019
Possible fix 1.
Use
LOCAL_CRATE
as aCrateNum
in built-in macros'DefId
s.Built-in macros have fixed def-indices, so we should be able to recognize a built-in macro when loading metadata from other crate and thus know how to expand it.
Using
LOCAL_CRATE
will mean that each crate reexporting built-in macros will reexport it's own different version (with a separateDefId
).This is not correct and observable through import conflicts (imports of the same macro will conflict while they shouldn't).
This can perhaps be fixed by changing
DefId
s (resetting crate num toLOCAL_CRATE
) on the fly during metadata loading (?). Not sure.petrochenkov commentedon Jun 9, 2019
Possible fix 2.
Introduce a special
CrateNum
for things defined by the language rather than any crate and support it through the whole compilation (akaCrateNum::BuiltinMacros
done right).Built-in types could potentially use it as well if it becomes necessary for them to have
DefId
s.petrochenkov commentedon Jun 9, 2019
The primary motivation for fixing this is reexporting built-in macros from the standard library.
This way those macros will have a reliable way to call them (e.g.
::std::column!()
) from other macros (the__rust_unstable_column!()
problem) even without having stable def-site hygiene in the language.feature(builtin_macro_imports)
#61875petrochenkov commentedon Jun 15, 2019
Fixed in #62086
Rollup merge of rust-lang#62086 - petrochenkov:builtout, r=eddyb
Auto merge of #62086 - petrochenkov:builtout, r=eddyb