Skip to content

Commit 35f1338

Browse files
committed
Explicitly export core and std macros
Currently all core and std macros are automatically added to the prelude via #[macro_use]. However a situation arose where we want to add a new macro `assert_matches` but don't want to pull it into the standard prelude for compatibility reasons. By explicitly exporting the macros found in the core and std crates we get to decide on a per macro basis and can later add them via the rust_20xx preludes.
1 parent a17780d commit 35f1338

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

compiler/rustc_builtin_macros/src/standard_library_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn inject(
4343

4444
let item = cx.item(
4545
span,
46-
thin_vec![cx.attr_word(sym::macro_use, span)],
46+
ast::AttrVec::new(),
4747
ast::ItemKind::ExternCrate(None, Ident::new(name, ident_span)),
4848
);
4949

library/core/src/prelude/v1.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ pub use crate::hash::macros::Hash;
6060
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
6161
#[doc(no_inline)]
6262
pub use crate::{
63-
assert, cfg, column, compile_error, concat, env, file, format_args,
64-
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
65-
stringify, trace_macros,
63+
assert, assert_eq, assert_ne, cfg, column, compile_error, concat, debug_assert, debug_assert_eq, debug_assert_ne, env, file, format_args, include, include_bytes, include_str, line, matches, module_path, option_env, panic, stringify, todo, r#try, unimplemented, unreachable, write, writeln,
6664
};
6765

66+
#[unstable(feature = "ub_checks", issue = "none")]
67+
#[doc(no_inline)]
68+
pub use crate::assert_unsafe_precondition;
69+
70+
#[unstable(feature = "cfg_match", issue = "115585")]
71+
#[doc(no_inline)]
72+
pub use crate::cfg_match;
73+
6874
#[unstable(
6975
feature = "concat_bytes",
7076
issue = "87555",
@@ -73,6 +79,47 @@ pub use crate::{
7379
#[doc(no_inline)]
7480
pub use crate::concat_bytes;
7581

82+
#[unstable(
83+
feature = "concat_idents",
84+
issue = "29599",
85+
reason = "`concat_idents` is not stable enough for use and is subject to change"
86+
)]
87+
#[doc(no_inline)]
88+
pub use crate::concat_idents;
89+
90+
#[unstable(feature = "const_format_args", issue = "none")]
91+
#[doc(no_inline)]
92+
pub use crate::const_format_args;
93+
94+
#[unstable(
95+
feature = "format_args_nl",
96+
issue = "none",
97+
reason = "`format_args_nl` is only for internal \
98+
language use and is subject to change"
99+
)]
100+
#[doc(no_inline)]
101+
pub use crate::format_args_nl;
102+
103+
#[unstable(
104+
feature = "log_syntax",
105+
issue = "29598",
106+
reason = "`log_syntax!` is not stable enough for use and is subject to change"
107+
)]
108+
#[doc(no_inline)]
109+
pub use crate::log_syntax;
110+
111+
#[unstable(feature = "pattern_type_macro", issue = "123646")]
112+
#[doc(no_inline)]
113+
pub use crate::pattern_type;
114+
115+
#[unstable(
116+
feature = "trace_macros",
117+
issue = "29598",
118+
reason = "`trace_macros` is not stable enough for use and is subject to change"
119+
)]
120+
#[doc(no_inline)]
121+
pub use crate::trace_macros;
122+
76123
// Do not `doc(no_inline)` so that they become doc items on their own
77124
// (no public module for them to be re-exported from).
78125
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

library/proc_macro/src/bridge/symbol.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
use std::cell::RefCell;
1313
use std::num::NonZero;
1414
use std::str;
15+
use std::fmt;
1516

16-
use super::*;
17+
// Explicit import to avoid macro namespace collision.
18+
use super::{arena, client, DecodeMut, Encode, fxhash, Mark, Marked, Reader, server, Unmark, Writer};
1719

1820
/// Handle for a symbol string stored within the Interner.
1921
#[derive(Copy, Clone, PartialEq, Eq, Hash)]

library/std/src/prelude/v1.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,25 @@ pub use crate::option::Option::{self, None, Some};
4343
#[doc(no_inline)]
4444
pub use crate::result::Result::{self, Err, Ok};
4545

46-
// Re-exported built-in macros
46+
// Re-exported built-in macros and traits
4747
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
4848
#[doc(no_inline)]
4949
pub use core::prelude::v1::{
50-
assert, cfg, column, compile_error, concat, env, file, format_args,
51-
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
52-
stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd,
50+
assert, assert_eq, assert_ne, cfg, column, compile_error, concat, debug_assert, debug_assert_eq, debug_assert_ne, env, file, format_args, include, include_bytes, include_str, line, matches,
51+
module_path, option_env, panic, stringify, todo, r#try, unimplemented, unreachable, write,
52+
writeln, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd,
5353
};
5454

55+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
56+
#[doc(no_inline)]
57+
pub use crate::{
58+
dbg, eprint, eprintln, format, is_x86_feature_detected, print, println, thread_local, vec,
59+
};
60+
61+
#[unstable(feature = "cfg_match", issue = "115585")]
62+
#[doc(no_inline)]
63+
pub use core::prelude::v1::cfg_match;
64+
5565
#[unstable(
5666
feature = "concat_bytes",
5767
issue = "87555",
@@ -60,6 +70,43 @@ pub use core::prelude::v1::{
6070
#[doc(no_inline)]
6171
pub use core::prelude::v1::concat_bytes;
6272

73+
#[unstable(
74+
feature = "concat_idents",
75+
issue = "29599",
76+
reason = "`concat_idents` is not stable enough for use and is subject to change"
77+
)]
78+
#[doc(no_inline)]
79+
pub use core::prelude::v1::concat_idents;
80+
81+
#[unstable(feature = "const_format_args", issue = "none")]
82+
#[doc(no_inline)]
83+
pub use core::prelude::v1::const_format_args;
84+
85+
#[unstable(
86+
feature = "format_args_nl",
87+
issue = "none",
88+
reason = "`format_args_nl` is only for internal \
89+
language use and is subject to change"
90+
)]
91+
#[doc(no_inline)]
92+
pub use core::prelude::v1::format_args_nl;
93+
94+
#[unstable(
95+
feature = "log_syntax",
96+
issue = "29598",
97+
reason = "`log_syntax!` is not stable enough for use and is subject to change"
98+
)]
99+
#[doc(no_inline)]
100+
pub use core::prelude::v1::log_syntax;
101+
102+
#[unstable(
103+
feature = "trace_macros",
104+
issue = "29598",
105+
reason = "`trace_macros` is not stable enough for use and is subject to change"
106+
)]
107+
#[doc(no_inline)]
108+
pub use core::prelude::v1::trace_macros;
109+
63110
// Do not `doc(no_inline)` so that they become doc items on their own
64111
// (no public module for them to be re-exported from).
65112
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

0 commit comments

Comments
 (0)