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 9 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
1 change: 0 additions & 1 deletion library/alloctests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

// Allow testing this library
extern crate alloc as realalloc;
#[macro_use]
extern crate std;
#[cfg(test)]
extern crate test;
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
15 changes: 15 additions & 0 deletions library/std/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ pub mod rust_2021 {
#[stable(feature = "prelude_2021", since = "1.55.0")]
#[doc(no_inline)]
pub use core::prelude::rust_2021::*;

// There are two different panic macros, one in `core` and one in `std`. They are slightly
// different. For `std` we explicitly want the one defined in `std`.
#[stable(feature = "prelude_2021", since = "1.55.0")]
pub use super::v1::panic;
}

/// The 2024 version of the prelude of The Rust Standard Library.
Expand All @@ -159,6 +164,11 @@ pub mod rust_2024 {
#[stable(feature = "prelude_2024", since = "1.85.0")]
#[doc(no_inline)]
pub use core::prelude::rust_2024::*;

// There are two different panic macros, one in `core` and one in `std`. They are slightly
// different. For `std` we explicitly want the one defined in `std`.
#[stable(feature = "prelude_2024", since = "1.85.0")]
pub use super::v1::panic;
}

/// The Future version of the prelude of The Rust Standard Library.
Expand All @@ -174,4 +184,9 @@ pub mod rust_future {
#[unstable(feature = "prelude_next", issue = "none")]
#[doc(no_inline)]
pub use core::prelude::rust_future::*;

// There are two different panic macros, one in `core` and one in `std`. They are slightly
// different. For `std` we explicitly want the one defined in `std`.
#[unstable(feature = "prelude_next", issue = "none")]
pub use super::v1::panic;
}
59 changes: 55 additions & 4 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,39 @@ 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, 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 {}
#[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_std::{vec, panic};

#[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 +84,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 @@ -94,7 +94,6 @@ macro_rules! panic {
}

//- /lib.rs crate:foo deps:core
#[macro_use]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be undone, the test does not run against the standard library here

extern crate core;

fn foo() {
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)*));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be undone, the test does not run against the standard library here

})
}

Expand Down
1 change: 0 additions & 1 deletion tests/pretty/asm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-mode:expanded
//@ pp-exact:asm.pp
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/autodiff_forward.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(autodiff)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-mode:expanded
//@ pretty-compare-only
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/autodiff_reverse.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(autodiff)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-mode:expanded
//@ pretty-compare-only
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/cast-lt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:expanded
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/dollar-crate.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:expanded
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/expanded-and-path-remap-80832.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
// Test for issue 80832
//
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/format-args-str-escape.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:expanded
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/hir-fn-params.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/hir-fn-variadic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(c_variadic)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;

extern "C" {
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/hir-lifetimes.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![allow(unused)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;

struct Foo<'a> {
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/hir-pretty-attr.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/hir-pretty-loop.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/hir-struct-expr.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/issue-12590-c.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:expanded
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/issue-4264.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ pretty-compare-only
//@ pretty-mode:hir,typed
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/issue-85089.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
// Test to print lifetimes on HIR pretty-printing.

Expand Down
1 change: 0 additions & 1 deletion tests/pretty/postfix-match/precedence.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![feature(postfix_match)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;

use std::ops::Add;
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/tests-are-sorted.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ compile-flags: --crate-type=lib --test --remap-path-prefix={{src-base}}/=/the/src/ --remap-path-prefix={{src-base}}\=/the/src/
//@ pretty-compare-only
Expand Down
1 change: 0 additions & 1 deletion tests/ui/asm/unpretty-expanded.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ needs-asm-support
//@ check-pass
Expand Down
Loading