Skip to content

Commit 14db115

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 8fb32ab commit 14db115

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
@@ -61,11 +61,17 @@ pub use crate::hash::macros::Hash;
6161
#[allow(deprecated)]
6262
#[doc(no_inline)]
6363
pub use crate::{
64-
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
65-
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
66-
stringify, trace_macros,
64+
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,
6765
};
6866

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

83+
#[unstable(
84+
feature = "concat_idents",
85+
issue = "29599",
86+
reason = "`concat_idents` is not stable enough for use and is subject to change"
87+
)]
88+
#[doc(no_inline)]
89+
pub use crate::concat_idents;
90+
91+
#[unstable(feature = "const_format_args", issue = "none")]
92+
#[doc(no_inline)]
93+
pub use crate::const_format_args;
94+
95+
#[unstable(
96+
feature = "format_args_nl",
97+
issue = "none",
98+
reason = "`format_args_nl` is only for internal \
99+
language use and is subject to change"
100+
)]
101+
#[doc(no_inline)]
102+
pub use crate::format_args_nl;
103+
104+
#[unstable(
105+
feature = "log_syntax",
106+
issue = "29598",
107+
reason = "`log_syntax!` is not stable enough for use and is subject to change"
108+
)]
109+
#[doc(no_inline)]
110+
pub use crate::log_syntax;
111+
112+
#[unstable(feature = "pattern_type_macro", issue = "123646")]
113+
#[doc(no_inline)]
114+
pub use crate::pattern_type;
115+
116+
#[unstable(
117+
feature = "trace_macros",
118+
issue = "29598",
119+
reason = "`trace_macros` is not stable enough for use and is subject to change"
120+
)]
121+
#[doc(no_inline)]
122+
pub use crate::trace_macros;
123+
77124
// Do not `doc(no_inline)` so that they become doc items on their own
78125
// (no public module for them to be re-exported from).
79126
#[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,16 +43,26 @@ 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
#[allow(deprecated)]
4949
#[doc(no_inline)]
5050
pub use core::prelude::v1::{
51-
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
52-
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
53-
stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd,
51+
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,
52+
module_path, option_env, panic, stringify, todo, r#try, unimplemented, unreachable, write,
53+
writeln, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd,
5454
};
5555

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

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

0 commit comments

Comments
 (0)