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
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,17 @@ 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, env, file, format_args, include, include_bytes, include_str, line, matches, module_path, option_env, panic, stringify, todo, r#try, unimplemented, unreachable, write, writeln,
};

#[unstable(feature = "ub_checks", issue = "none")]
#[doc(no_inline)]
pub use crate::assert_unsafe_precondition;

#[unstable(feature = "cfg_match", issue = "115585")]
#[doc(no_inline)]
pub use crate::cfg_match;

#[unstable(
feature = "concat_bytes",
issue = "87555",
Expand All @@ -74,6 +80,47 @@ 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 = "format_args_nl",
issue = "none",
reason = "`format_args_nl` is only for internal \
language use and is subject to change"
)]
#[doc(no_inline)]
pub use crate::format_args_nl;

#[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
4 changes: 3 additions & 1 deletion library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use std::cell::RefCell;
use std::num::NonZero;
use std::str;
use std::fmt;

use super::*;
// Explicit import to avoid macro namespace collision.
use super::{arena, client, DecodeMut, Encode, fxhash, Mark, Marked, Reader, server, Unmark, Writer};
Copy link
Member

Choose a reason for hiding this comment

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

What collision is this? Is this something that user code is likely to encounter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the error that I get when not making this change:

error[E0659]: `panic` is ambiguous
   --> library/proc_macro/src/bridge/symbol.rs:41:17
    |
41  |                 panic!("`{}` cannot be a raw identifier", string);
    |                 ^^^^^ ambiguous name
    |
    = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
note: `panic` could refer to the macro imported here
   --> library/proc_macro/src/bridge/symbol.rs:19:5
    |
19  | use super::*;
    |     ^^^^^^^^
    = help: consider adding an explicit import of `panic` to disambiguate
    = help: or use `self::panic` to refer to this macro unambiguously
note: `panic` could also refer to the macro defined here
   --> /rust/library/std/src/prelude/mod.rs:157:13
    |
157 |     pub use super::v1::*;
    |             ^^^^^^^^^

My reasoning is a follows, this special proc macro is built together with std which gives access to std via super, causing the import ambiguity. I don't think this is an issue for user code since normal crates can't access std via super - I checked - and I assume normal proc macros can't either, but I'm no expert in that area.


/// Handle for a symbol string stored within the Interner.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
Expand Down
55 changes: 51 additions & 4 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@ 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, 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 +71,43 @@ 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 = "format_args_nl",
issue = "none",
reason = "`format_args_nl` is only for internal \
language use and is subject to change"
)]
#[doc(no_inline)]
pub use core::prelude::v1::format_args_nl;

#[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
Loading