Skip to content

Commit 09e3989

Browse files
committedJul 26, 2019
Auto merge of #62086 - petrochenkov:builtout, r=eddyb
Define built-in macros through libcore This PR defines built-in macros through libcore using a scheme similar to lang items (attribute `#[rustc_builtin_macro]`). All the macro properties (stability, visibility, etc.) are taken from the source code in libcore, with exception of the expander function transforming input tokens/AST into output tokens/AST, which is still provided by the compiler. The macros are made available to user code through the standard library prelude (`{core,std}::prelude::v1`), so they are still always in scope. As a result **built-in macros now have stable absolute addresses in the library**, like `core::prelude::v1::line!()`, this is an insta-stable change. Right now `prelude::v1` is the only publicly available absolute address for these macros, but eventually they can be moved into more appropriate locations with library team approval (e.g. `Clone` derive -> `core::clone::Clone`). Now when built-in macros have canonical definitions they can be imported or reexported without issues (#61687). Other changes: - You can now define a derive macro with a name matching one of the built-in derives (#52269). This was an artificial restriction that could be worked around with import renaming anyway. Known regressions: - Empty library crate with a crate-level `#![test]` attribute no longer compiles without `--test`. Previously it didn't compile *with* `--test` or with the bin crate type. Fixes #61687 Fixes #61804 r? @eddyb
2 parents c43753f + 8eaf17b commit 09e3989

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+499
-969
lines changed
 

‎src/libcore/macros.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,13 @@ macro_rules! uninit_array {
657657
);
658658
}
659659

660-
/// Built-in macros to the compiler itself.
660+
/// Definitions of built-in macros.
661661
///
662-
/// These macros do not have any corresponding definition with a `macro_rules!`
663-
/// macro, but are documented here. Their implementations can be found hardcoded
664-
/// into libsyntax itself.
665-
#[cfg(rustdoc)]
666-
mod builtin {
662+
/// Most of the macro properties (stability, visibility, etc.) are taken from the source code here,
663+
/// with exception of expansion functions transforming macro inputs into outputs,
664+
/// those functions are provided by the compiler.
665+
#[cfg(not(bootstrap))]
666+
pub(crate) mod builtin {
667667

668668
/// Causes compilation to fail with the given error message when encountered.
669669
///
@@ -950,7 +950,7 @@ mod builtin {
950950

951951
/// Same as `column`, but less likely to be shadowed.
952952
#[unstable(feature = "__rust_unstable_column", issue = "0",
953-
reason = "internal implementation detail of the `column` macro")]
953+
reason = "internal implementation detail of the `panic` macro")]
954954
#[rustc_builtin_macro]
955955
#[rustc_macro_transparency = "semitransparent"]
956956
pub macro __rust_unstable_column() { /* compiler built-in */ }

‎src/libcore/prelude/v1.rs

+47
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,50 @@ pub use crate::option::Option::{self, Some, None};
4444
#[stable(feature = "core_prelude", since = "1.4.0")]
4545
#[doc(no_inline)]
4646
pub use crate::result::Result::{self, Ok, Err};
47+
48+
// Re-exported built-in macros
49+
#[cfg(not(bootstrap))]
50+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
51+
#[allow(deprecated)]
52+
#[doc(no_inline)]
53+
pub use crate::macros::builtin::{
54+
Clone,
55+
Copy,
56+
Debug,
57+
Decodable,
58+
Default,
59+
Encodable,
60+
Eq,
61+
Hash,
62+
Ord,
63+
PartialEq,
64+
PartialOrd,
65+
RustcDecodable,
66+
RustcEncodable,
67+
__rust_unstable_column,
68+
asm,
69+
assert,
70+
bench,
71+
cfg,
72+
column,
73+
compile_error,
74+
concat,
75+
concat_idents,
76+
env,
77+
file,
78+
format_args,
79+
format_args_nl,
80+
global_allocator,
81+
global_asm,
82+
include,
83+
include_bytes,
84+
include_str,
85+
line,
86+
log_syntax,
87+
module_path,
88+
option_env,
89+
stringify,
90+
test,
91+
test_case,
92+
trace_macros,
93+
};

0 commit comments

Comments
 (0)