diff --git a/compiler/rustc_builtin_macros/src/standard_library_imports.rs b/compiler/rustc_builtin_macros/src/standard_library_imports.rs index a1ee53b7ca21f..748dacc284e9e 100644 --- a/compiler/rustc_builtin_macros/src/standard_library_imports.rs +++ b/compiler/rustc_builtin_macros/src/standard_library_imports.rs @@ -43,7 +43,7 @@ pub fn inject( let item = cx.item( span, - thin_vec![cx.attr_word(sym::macro_use, span)], + ast::AttrVec::new(), ast::ItemKind::ExternCrate(None, Ident::new(name, ident_span)), ); diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index c5975c0305031..c012ba6ea01f6 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -61,11 +61,26 @@ pub use crate::hash::macros::Hash; #[allow(deprecated)] #[doc(no_inline)] pub use crate::{ - assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env, - stringify, trace_macros, + 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, }; +// These macros needs special handling, so that we don't export it *and* the modules of the same +// name. We only want the macro in the prelude. +mod ambiguous_macro_only { + #[allow(hidden_glob_reexports)] + mod env {} + #[allow(hidden_glob_reexports)] + mod panic {} + #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] + pub use crate::*; +} +#[stable(feature = "builtin_macro_prelude", since = "1.38.0")] +pub use self::ambiguous_macro_only::{env, panic}; + +#[unstable(feature = "cfg_match", issue = "115585")] +#[doc(no_inline)] +pub use crate::cfg_match; + #[unstable( feature = "concat_bytes", issue = "87555", @@ -74,6 +89,38 @@ pub use crate::{ #[doc(no_inline)] pub use crate::concat_bytes; +#[unstable( + feature = "concat_idents", + issue = "29599", + reason = "`concat_idents` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use crate::concat_idents; + +#[unstable(feature = "const_format_args", issue = "none")] +#[doc(no_inline)] +pub use crate::const_format_args; + +#[unstable( + feature = "log_syntax", + issue = "29598", + reason = "`log_syntax!` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use crate::log_syntax; + +#[unstable(feature = "pattern_type_macro", issue = "123646")] +#[doc(no_inline)] +pub use crate::pattern_type; + +#[unstable( + feature = "trace_macros", + issue = "29598", + reason = "`trace_macros` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use crate::trace_macros; + // Do not `doc(no_inline)` so that they become doc items on their own // (no public module for them to be re-exported from). #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/bridge/symbol.rs index 6a1cecd69fb5f..6ff480460e6f3 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/bridge/symbol.rs @@ -11,9 +11,12 @@ use std::cell::RefCell; use std::num::NonZero; -use std::str; +use std::{fmt, str}; -use super::*; +// Explicit import to avoid macro namespace collision. +use super::{ + DecodeMut, Encode, Mark, Marked, Reader, Unmark, Writer, arena, client, fxhash, server, +}; /// Handle for a symbol string stored within the Interner. #[derive(Copy, Clone, PartialEq, Eq, Hash)] diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 4217f65864072..729843deaf952 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -43,16 +43,37 @@ pub use crate::option::Option::{self, None, Some}; #[doc(no_inline)] pub use crate::result::Result::{self, Err, Ok}; -// Re-exported built-in macros +// Re-exported built-in macros and traits #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[allow(deprecated)] #[doc(no_inline)] pub use core::prelude::v1::{ - assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env, - stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, + 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, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, }; +#[stable(feature = "builtin_macro_prelude", since = "1.38.0")] +#[doc(no_inline)] +pub use crate::{ + dbg, eprint, eprintln, format, is_x86_feature_detected, print, println, thread_local, +}; + +// These macros needs special handling, so that we don't export it *and* the modules of the same +// name. We only want the macro in the prelude. +mod ambiguous_macro_only_std { + #[allow(hidden_glob_reexports)] + mod vec {} + #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] + pub use crate::*; +} +#[stable(feature = "builtin_macro_prelude", since = "1.38.0")] +pub use self::ambiguous_macro_only_std::vec; + +#[unstable(feature = "cfg_match", issue = "115585")] +#[doc(no_inline)] +pub use core::prelude::v1::cfg_match; + #[unstable( feature = "concat_bytes", issue = "87555", @@ -61,6 +82,34 @@ pub use core::prelude::v1::{ #[doc(no_inline)] pub use core::prelude::v1::concat_bytes; +#[unstable( + feature = "concat_idents", + issue = "29599", + reason = "`concat_idents` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use core::prelude::v1::concat_idents; + +#[unstable(feature = "const_format_args", issue = "none")] +#[doc(no_inline)] +pub use core::prelude::v1::const_format_args; + +#[unstable( + feature = "log_syntax", + issue = "29598", + reason = "`log_syntax!` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use core::prelude::v1::log_syntax; + +#[unstable( + feature = "trace_macros", + issue = "29598", + reason = "`trace_macros` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use core::prelude::v1::trace_macros; + // Do not `doc(no_inline)` so that they become doc items on their own // (no public module for them to be re-exported from). #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 3b765a9537bc9..5e5cb8b394175 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -171,7 +171,7 @@ use crate::sys::process as imp; #[stable(feature = "command_access", since = "1.57.0")] pub use crate::sys_common::process::CommandEnvs; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; -use crate::{fmt, fs, str}; +use crate::{fmt, format_args_nl, fs, str}; /// Representation of a running or exited child process. /// diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index c943d3ad4d056..b024b62f3ec2e 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -7,6 +7,7 @@ use std::collections::VecDeque; use std::fmt::{Display, Write}; +use std::format_args_nl; use rustc_data_structures::fx::FxIndexMap; use rustc_lexer::{Cursor, LiteralKind, TokenKind}; diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tests.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tests.rs index 8f69bb8230000..21196ecf94688 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tests.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tests.rs @@ -445,7 +445,7 @@ fn test_string_highlighting() { //- minicore: fmt, assert, asm, concat, panic macro_rules! println { ($($arg:tt)*) => ({ - $crate::io::_print(format_args_nl!($($arg)*)); + $crate::io::_print(std::format_args_nl!($($arg)*)); }) } diff --git a/tests/ui/hygiene/format-args.rs b/tests/ui/hygiene/format-args.rs index ff08aecfd9eb7..f845f5d8a4c8f 100644 --- a/tests/ui/hygiene/format-args.rs +++ b/tests/ui/hygiene/format-args.rs @@ -3,6 +3,8 @@ #![allow(non_upper_case_globals)] #![feature(format_args_nl)] +use std::format_args_nl; + static arg0: () = (); fn main() {