Skip to content

Explicitly export core and std macros #139493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);

Expand Down
53 changes: 50 additions & 3 deletions library/core/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")]
Expand Down
7 changes: 5 additions & 2 deletions library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
57 changes: 53 additions & 4 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)*));
})
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/hygiene/format-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![allow(non_upper_case_globals)]
#![feature(format_args_nl)]

use std::format_args_nl;

static arg0: () = ();

fn main() {
Expand Down
Loading