Skip to content

Commit f65cc8e

Browse files
Auto merge of #139493 - Voultapher:explicitly-export-core-and-std-macros, r=<try>
Explicitly export core and std macros
2 parents 6f34f4e + df215cc commit f65cc8e

File tree

72 files changed

+180
-93
lines changed

Some content is hidden

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

72 files changed

+180
-93
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/alloctests/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#![feature(negative_impls)]
5757
#![feature(never_type)]
5858
#![feature(optimize_attribute)]
59+
#![feature(prelude_import)]
5960
#![feature(rustc_allow_const_fn_unstable)]
6061
#![feature(rustc_attrs)]
6162
#![feature(staged_api)]
@@ -65,11 +66,17 @@
6566

6667
// Allow testing this library
6768
extern crate alloc as realalloc;
68-
#[macro_use]
69+
70+
// This is needed to provide macros to the directly imported alloc modules below.
6971
extern crate std;
72+
#[prelude_import]
73+
#[allow(unused_imports)]
74+
use std::prelude::rust_2024::*;
75+
7076
#[cfg(test)]
7177
extern crate test;
7278
mod testing;
79+
7380
use realalloc::*;
7481

7582
// We are directly including collections, raw_vec, and wtf8 here as they use non-public
@@ -93,8 +100,7 @@ pub(crate) mod test_helpers {
93100
let mut hasher = std::hash::RandomState::new().build_hasher();
94101
std::panic::Location::caller().hash(&mut hasher);
95102
let hc64 = hasher.finish();
96-
let seed_vec =
97-
hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<crate::vec::Vec<u8>>();
103+
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<std::vec::Vec<u8>>();
98104
let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
99105
rand::SeedableRng::from_seed(seed)
100106
}

library/core/src/prelude/v1.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,29 @@ pub use crate::hash::macros::Hash;
5959

6060
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
6161
#[doc(no_inline)]
62+
#[allow(deprecated)]
6263
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,
64+
assert, assert_eq, assert_ne, cfg, column, compile_error, concat, debug_assert, debug_assert_eq, debug_assert_ne, file, format_args, include, include_bytes, include_str, line, matches, module_path, option_env, stringify, todo, r#try, unimplemented, unreachable, write, writeln,
6665
};
6766

67+
// These macros needs special handling, so that we don't export it *and* the modules of the same
68+
// name. We only want the macro in the prelude.
69+
mod ambiguous_macro_only {
70+
#[allow(hidden_glob_reexports)]
71+
mod env {}
72+
#[allow(hidden_glob_reexports)]
73+
mod panic {}
74+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
75+
pub use crate::*;
76+
}
77+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
78+
#[doc(no_inline)]
79+
pub use self::ambiguous_macro_only::{env, panic};
80+
81+
#[unstable(feature = "cfg_select", issue = "115585")]
82+
#[doc(no_inline)]
83+
pub use crate::cfg_select;
84+
6885
#[unstable(
6986
feature = "concat_bytes",
7087
issue = "87555",
@@ -73,6 +90,30 @@ pub use crate::{
7390
#[doc(no_inline)]
7491
pub use crate::concat_bytes;
7592

93+
#[unstable(feature = "const_format_args", issue = "none")]
94+
#[doc(no_inline)]
95+
pub use crate::const_format_args;
96+
97+
#[unstable(
98+
feature = "log_syntax",
99+
issue = "29598",
100+
reason = "`log_syntax!` is not stable enough for use and is subject to change"
101+
)]
102+
#[doc(no_inline)]
103+
pub use crate::log_syntax;
104+
105+
#[unstable(feature = "pattern_type_macro", issue = "123646")]
106+
#[doc(no_inline)]
107+
pub use crate::pattern_type;
108+
109+
#[unstable(
110+
feature = "trace_macros",
111+
issue = "29598",
112+
reason = "`trace_macros` is not stable enough for use and is subject to change"
113+
)]
114+
#[doc(no_inline)]
115+
pub use crate::trace_macros;
116+
76117
// Do not `doc(no_inline)` so that they become doc items on their own
77118
// (no public module for them to be re-exported from).
78119
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

library/proc_macro/src/bridge/symbol.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
1212
use std::cell::RefCell;
1313
use std::num::NonZero;
14-
use std::str;
14+
use std::{fmt, str};
1515

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

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

library/std/src/prelude/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ pub mod rust_2021 {
145145
#[stable(feature = "prelude_2021", since = "1.55.0")]
146146
#[doc(no_inline)]
147147
pub use core::prelude::rust_2021::*;
148+
149+
// There are two different panic macros, one in `core` and one in `std`. They are slightly
150+
// different. For `std` we explicitly want the one defined in `std`.
151+
#[stable(feature = "prelude_2021", since = "1.55.0")]
152+
pub use super::v1::panic;
148153
}
149154

150155
/// The 2024 version of the prelude of The Rust Standard Library.
@@ -159,6 +164,11 @@ pub mod rust_2024 {
159164
#[stable(feature = "prelude_2024", since = "1.85.0")]
160165
#[doc(no_inline)]
161166
pub use core::prelude::rust_2024::*;
167+
168+
// There are two different panic macros, one in `core` and one in `std`. They are slightly
169+
// different. For `std` we explicitly want the one defined in `std`.
170+
#[stable(feature = "prelude_2024", since = "1.85.0")]
171+
pub use super::v1::panic;
162172
}
163173

164174
/// The Future version of the prelude of The Rust Standard Library.
@@ -174,4 +184,9 @@ pub mod rust_future {
174184
#[unstable(feature = "prelude_next", issue = "none")]
175185
#[doc(no_inline)]
176186
pub use core::prelude::rust_future::*;
187+
188+
// There are two different panic macros, one in `core` and one in `std`. They are slightly
189+
// different. For `std` we explicitly want the one defined in `std`.
190+
#[unstable(feature = "prelude_next", issue = "none")]
191+
pub use super::v1::panic;
177192
}

library/std/src/prelude/v1.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,44 @@ 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)]
49+
#[allow(deprecated)]
4950
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,
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, stringify, todo, r#try, unimplemented, unreachable, write,
53+
writeln, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd,
5354
};
5455

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, hash_map
60+
};
61+
62+
// These macros needs special handling, so that we don't export it *and* the modules of the same
63+
// name. We only want the macro in the prelude.
64+
mod ambiguous_macro_only_std {
65+
#[allow(hidden_glob_reexports)]
66+
mod vec {}
67+
#[allow(hidden_glob_reexports)]
68+
mod panic {}
69+
// Building std without the allow exported_private_dependencies will create warnings, but then
70+
// clippy claims its a useless_attribute. So silence both.
71+
#[allow(clippy::useless_attribute)]
72+
#[allow(exported_private_dependencies)]
73+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
74+
pub use crate::*;
75+
}
76+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
77+
#[doc(no_inline)]
78+
pub use self::ambiguous_macro_only_std::{vec, panic};
79+
80+
#[unstable(feature = "cfg_select", issue = "115585")]
81+
#[doc(no_inline)]
82+
pub use core::prelude::v1::cfg_select;
83+
5584
#[unstable(
5685
feature = "concat_bytes",
5786
issue = "87555",
@@ -60,6 +89,26 @@ pub use core::prelude::v1::{
6089
#[doc(no_inline)]
6190
pub use core::prelude::v1::concat_bytes;
6291

92+
#[unstable(feature = "const_format_args", issue = "none")]
93+
#[doc(no_inline)]
94+
pub use core::prelude::v1::const_format_args;
95+
96+
#[unstable(
97+
feature = "log_syntax",
98+
issue = "29598",
99+
reason = "`log_syntax!` is not stable enough for use and is subject to change"
100+
)]
101+
#[doc(no_inline)]
102+
pub use core::prelude::v1::log_syntax;
103+
104+
#[unstable(
105+
feature = "trace_macros",
106+
issue = "29598",
107+
reason = "`trace_macros` is not stable enough for use and is subject to change"
108+
)]
109+
#[doc(no_inline)]
110+
pub use core::prelude::v1::trace_macros;
111+
63112
// Do not `doc(no_inline)` so that they become doc items on their own
64113
// (no public module for them to be re-exported from).
65114
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

library/std/src/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ use crate::path::Path;
169169
use crate::sys::pipe::{AnonPipe, read2};
170170
use crate::sys::process as imp;
171171
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
172-
use crate::{fmt, fs, str};
172+
use crate::{fmt, format_args_nl, fs, str};
173173

174174
/// Representation of a running or exited child process.
175175
///

tests/pretty/asm.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(prelude_import)]
22
#![no_std]
3-
#[macro_use]
43
extern crate std;
54
#[prelude_import]
65
use ::std::prelude::rust_2015::*;

tests/pretty/autodiff/autodiff_forward.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//@ needs-enzyme
44

55
#![feature(autodiff)]
6-
#[macro_use]
6+
#[prelude_import]
7+
use ::std::prelude::rust_2015::*;
78
extern crate std;
89
#[prelude_import]
910
use ::std::prelude::rust_2015::*;

tests/pretty/autodiff/autodiff_reverse.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//@ needs-enzyme
44

55
#![feature(autodiff)]
6-
#[macro_use]
6+
#[prelude_import]
7+
use ::std::prelude::rust_2015::*;
78
extern crate std;
89
#[prelude_import]
910
use ::std::prelude::rust_2015::*;

0 commit comments

Comments
 (0)