From ebe6e88b71c2372e594f167c25499d8433e5037a Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Mon, 7 Apr 2025 19:30:51 +0200 Subject: [PATCH 01/24] Explicitly export core and std macros Currently all core and std macros are automatically added to the prelude via #[macro_use]. However a situation arose where we want to add a new macro `assert_matches` but don't want to pull it into the standard prelude for compatibility reasons. By explicitly exporting the macros found in the core and std crates we get to decide on a per macro basis and can later add them via the rust_20xx preludes. --- .../src/standard_library_imports.rs | 2 +- library/core/src/prelude/v1.rs | 53 +++++++++++++++++- library/proc_macro/src/bridge/symbol.rs | 4 +- library/std/src/prelude/v1.rs | 55 +++++++++++++++++-- 4 files changed, 105 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/standard_library_imports.rs b/compiler/rustc_builtin_macros/src/standard_library_imports.rs index 2068b5ca54dd0..9f22d9eacb33c 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 a4be66b90cab3..c67a482729a02 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -60,11 +60,17 @@ pub use crate::hash::macros::Hash; #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[doc(no_inline)] pub use crate::{ - assert, cfg, column, compile_error, concat, 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", @@ -73,6 +79,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")] diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/bridge/symbol.rs index 57ca7db9fcdd7..bb5ba1227b974 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/bridge/symbol.rs @@ -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}; /// 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 70c1113155656..e38a93f0373d1 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -43,15 +43,25 @@ 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")] #[doc(no_inline)] pub use core::prelude::v1::{ - assert, cfg, column, compile_error, concat, 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", @@ -60,6 +70,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")] From 806dc90bd08bfd41545fc325ccba353d1d2d80ac Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Tue, 8 Apr 2025 10:55:39 +0200 Subject: [PATCH 02/24] Apply review comments --- library/core/src/prelude/v1.rs | 13 ------------- library/std/src/prelude/v1.rs | 9 --------- library/std/src/process.rs | 2 +- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index c67a482729a02..fa367baac1aaa 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -63,10 +63,6 @@ pub use crate::{ 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; @@ -91,15 +87,6 @@ pub use crate::concat_idents; #[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", diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index e38a93f0373d1..8b702a9ddffb9 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -82,15 +82,6 @@ pub use core::prelude::v1::concat_idents; #[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", diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 5c0ac526a36c9..acbe5827863be 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -169,7 +169,7 @@ use crate::path::Path; use crate::sys::pipe::{AnonPipe, read2}; use crate::sys::process as imp; 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. /// From cb32e72cb0c3c0d3b64aeda8888e87a39cf5add1 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Tue, 8 Apr 2025 11:03:08 +0200 Subject: [PATCH 03/24] Fix formatting tidy issues --- library/proc_macro/src/bridge/symbol.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/bridge/symbol.rs index bb5ba1227b974..e0f3a6a2860b2 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/bridge/symbol.rs @@ -11,11 +11,12 @@ use std::cell::RefCell; use std::num::NonZero; -use std::str; -use std::fmt; +use std::{fmt, str}; // Explicit import to avoid macro namespace collision. -use super::{arena, client, DecodeMut, Encode, fxhash, Mark, Marked, Reader, server, Unmark, Writer}; +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)] From 990d71bffb88afabdb5e69a6d4e76195e9ed34c0 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Tue, 8 Apr 2025 19:52:28 +0200 Subject: [PATCH 04/24] Special case vec macro --- library/std/src/prelude/v1.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 8b702a9ddffb9..7363b3cc151b6 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -55,9 +55,20 @@ pub use core::prelude::v1::{ #[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, + dbg, eprint, eprintln, format, is_x86_feature_detected, print, println, thread_local, }; +// The `vec` macro needs special handling, so that we don't export it *and* the `std::vec` module at +// the same time. We only want the macro in the prelude. +mod vec_macro_only { + #[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::vec_macro_only::vec; + #[unstable(feature = "cfg_match", issue = "115585")] #[doc(no_inline)] pub use core::prelude::v1::cfg_match; From 4dbcf1438a35c67bc44ec38605d67f5f67508148 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Wed, 9 Apr 2025 08:48:43 +0200 Subject: [PATCH 05/24] Explicitly import format_args_nl --- .../rust-analyzer/crates/ide/src/syntax_highlighting/tests.rs | 2 +- tests/ui/hygiene/format-args.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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 8198701d68432..a7a0f180899af 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 @@ -446,7 +446,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() { From ee1b44c84f30b77ccc771f2729eb82c2e17e000d Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Wed, 9 Apr 2025 08:59:57 +0200 Subject: [PATCH 06/24] Exclude panic and env namespaces from prelude --- library/core/src/prelude/v1.rs | 15 ++++++++++++++- library/std/src/prelude/v1.rs | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index fa367baac1aaa..078211fdf8be3 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -60,9 +60,22 @@ pub use crate::hash::macros::Hash; #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[doc(no_inline)] pub use crate::{ - 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, + 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; diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 7363b3cc151b6..669212a442e89 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -58,16 +58,16 @@ pub use crate::{ dbg, eprint, eprintln, format, is_x86_feature_detected, print, println, thread_local, }; -// The `vec` macro needs special handling, so that we don't export it *and* the `std::vec` module at -// the same time. We only want the macro in the prelude. -mod vec_macro_only { +// 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::vec_macro_only::vec; +pub use self::ambiguous_macro_only_std::vec; #[unstable(feature = "cfg_match", issue = "115585")] #[doc(no_inline)] From 101897fe50fdf0686a629322d6dcdf8cb6f62d9d Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Fri, 11 Apr 2025 15:23:34 +0200 Subject: [PATCH 07/24] Explicitly use std panic over core panic --- library/std/src/prelude/mod.rs | 15 +++++++++++++++ library/std/src/prelude/v1.rs | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/library/std/src/prelude/mod.rs b/library/std/src/prelude/mod.rs index 5f7097c26e228..8a0a293c4e1d1 100644 --- a/library/std/src/prelude/mod.rs +++ b/library/std/src/prelude/mod.rs @@ -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. @@ -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. @@ -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; } diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 669212a442e89..af201843ed669 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -48,14 +48,14 @@ pub use crate::result::Result::{self, Err, Ok}; #[doc(no_inline)] pub use core::prelude::v1::{ 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, + 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, + 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 @@ -63,11 +63,13 @@ pub use crate::{ 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; +pub use self::ambiguous_macro_only_std::{vec, panic}; #[unstable(feature = "cfg_match", issue = "115585")] #[doc(no_inline)] From 284ef992eca447c745e9f8b7e989b8000d5e1647 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Fri, 11 Apr 2025 15:57:10 +0200 Subject: [PATCH 08/24] Remove #[macro_use] std/core from tests --- library/alloctests/lib.rs | 1 - .../ide-diagnostics/src/handlers/unresolved_macro_call.rs | 1 - tests/pretty/asm.pp | 3 ++- tests/pretty/autodiff/autodiff_forward.pp | 3 ++- tests/pretty/autodiff/autodiff_reverse.pp | 3 ++- tests/pretty/cast-lt.pp | 3 ++- tests/pretty/dollar-crate.pp | 3 ++- tests/pretty/expanded-and-path-remap-80832.pp | 3 ++- tests/pretty/format-args-str-escape.pp | 3 ++- tests/pretty/hir-fn-params.pp | 1 + tests/pretty/hir-fn-variadic.pp | 1 + tests/pretty/hir-lifetimes.pp | 1 + tests/pretty/hir-pretty-attr.pp | 1 + tests/pretty/hir-pretty-loop.pp | 1 + tests/pretty/hir-struct-expr.pp | 1 + tests/pretty/issue-12590-c.pp | 3 ++- tests/pretty/issue-4264.pp | 1 + tests/pretty/issue-85089.pp | 1 + tests/pretty/postfix-match/precedence.pp | 3 ++- tests/pretty/tests-are-sorted.pp | 3 ++- tests/ui/asm/unpretty-expanded.stdout | 3 ++- .../return-type-notation/unpretty-parenthesized.stdout | 3 ++- tests/ui/codemap_tests/unicode.expanded.stdout | 3 ++- tests/ui/const-generics/defaults/pretty-printing-ast.stdout | 3 ++- tests/ui/deriving/built-in-proc-macro-scope.stdout | 3 ++- tests/ui/deriving/deriving-all-codegen.stdout | 4 ++-- tests/ui/deriving/deriving-coerce-pointee-expanded.stdout | 3 ++- tests/ui/deriving/proc-macro-attribute-mixing.stdout | 3 ++- tests/ui/feature-gates/feature-gate-format_args_nl.rs | 2 ++ tests/ui/lint/dead-code/with-core-crate.rs | 1 - .../no_ice_for_partial_compiler_runs.stdout | 3 ++- tests/ui/macros/genercs-in-path-with-prettry-hir.stdout | 1 + .../non-consuming-methods-have-optimized-codegen.stdout | 3 ++- tests/ui/match/issue-82392.stdout | 1 + tests/ui/proc-macro/meta-macro-hygiene.stdout | 3 ++- tests/ui/proc-macro/nonterminal-token-hygiene.stdout | 3 ++- tests/ui/proc-macro/quote/debug.stdout | 3 ++- tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout | 3 ++- tests/ui/type-alias-impl-trait/issue-60662.stdout | 1 + tests/ui/unpretty/bad-literal.stdout | 1 + tests/ui/unpretty/debug-fmt-hir.stdout | 1 + tests/ui/unpretty/deprecated-attr.stdout | 1 + tests/ui/unpretty/diagnostic-attr.stdout | 1 + tests/ui/unpretty/exhaustive.expanded.stdout | 3 ++- tests/ui/unpretty/flattened-format-args.stdout | 1 + tests/ui/unpretty/interpolation-expanded.stdout | 5 +++-- tests/ui/unpretty/let-else-hir.stdout | 1 + tests/ui/unpretty/self-hir.stdout | 1 + tests/ui/unpretty/unpretty-expr-fn-arg.stdout | 1 + 49 files changed, 74 insertions(+), 31 deletions(-) diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 0201c8752210c..378b0d313497e 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -65,7 +65,6 @@ // Allow testing this library extern crate alloc as realalloc; -#[macro_use] extern crate std; #[cfg(test)] extern crate test; diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs index a87b8c42ac1d0..241a42e5fda43 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs @@ -93,7 +93,6 @@ macro_rules! panic { } //- /lib.rs crate:foo deps:core -#[macro_use] extern crate core; fn foo() { diff --git a/tests/pretty/asm.pp b/tests/pretty/asm.pp index dca28f99a37d5..2ec58a449e124 100644 --- a/tests/pretty/asm.pp +++ b/tests/pretty/asm.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/autodiff/autodiff_forward.pp b/tests/pretty/autodiff/autodiff_forward.pp index 6eddb5669c7ab..e3400516212f1 100644 --- a/tests/pretty/autodiff/autodiff_forward.pp +++ b/tests/pretty/autodiff/autodiff_forward.pp @@ -3,7 +3,8 @@ //@ needs-enzyme #![feature(autodiff)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/autodiff/autodiff_reverse.pp b/tests/pretty/autodiff/autodiff_reverse.pp index 8f598b865c7b2..c9dd6d5b0e878 100644 --- a/tests/pretty/autodiff/autodiff_reverse.pp +++ b/tests/pretty/autodiff/autodiff_reverse.pp @@ -3,7 +3,8 @@ //@ needs-enzyme #![feature(autodiff)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/cast-lt.pp b/tests/pretty/cast-lt.pp index e82636edca7e5..ce6d440000cd8 100644 --- a/tests/pretty/cast-lt.pp +++ b/tests/pretty/cast-lt.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/dollar-crate.pp b/tests/pretty/dollar-crate.pp index 31a55ec2bdaa8..b6aad86cf704d 100644 --- a/tests/pretty/dollar-crate.pp +++ b/tests/pretty/dollar-crate.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/expanded-and-path-remap-80832.pp b/tests/pretty/expanded-and-path-remap-80832.pp index 6206498e4a2be..f028e446864c3 100644 --- a/tests/pretty/expanded-and-path-remap-80832.pp +++ b/tests/pretty/expanded-and-path-remap-80832.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/format-args-str-escape.pp b/tests/pretty/format-args-str-escape.pp index d0bd7cf0c72a3..bb4872edff6e3 100644 --- a/tests/pretty/format-args-str-escape.pp +++ b/tests/pretty/format-args-str-escape.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/hir-fn-params.pp b/tests/pretty/hir-fn-params.pp index fb4ea0304e5a9..67106f0de716b 100644 --- a/tests/pretty/hir-fn-params.pp +++ b/tests/pretty/hir-fn-params.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-fn-params.pp diff --git a/tests/pretty/hir-fn-variadic.pp b/tests/pretty/hir-fn-variadic.pp index c0f5b7069a2d7..473f3f08cc480 100644 --- a/tests/pretty/hir-fn-variadic.pp +++ b/tests/pretty/hir-fn-variadic.pp @@ -7,6 +7,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; extern "C" { unsafe fn foo(x: i32, va1: ...); diff --git a/tests/pretty/hir-lifetimes.pp b/tests/pretty/hir-lifetimes.pp index 00c052d3f7986..1f29bf93d2dab 100644 --- a/tests/pretty/hir-lifetimes.pp +++ b/tests/pretty/hir-lifetimes.pp @@ -9,6 +9,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; struct Foo<'a> { x: &'a u32, diff --git a/tests/pretty/hir-pretty-attr.pp b/tests/pretty/hir-pretty-attr.pp index 01bfe2c095476..cdfebb2b1b746 100644 --- a/tests/pretty/hir-pretty-attr.pp +++ b/tests/pretty/hir-pretty-attr.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-pretty-attr.pp diff --git a/tests/pretty/hir-pretty-loop.pp b/tests/pretty/hir-pretty-loop.pp index a0830c5188ada..659ca6aa72bd6 100644 --- a/tests/pretty/hir-pretty-loop.pp +++ b/tests/pretty/hir-pretty-loop.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-pretty-loop.pp diff --git a/tests/pretty/hir-struct-expr.pp b/tests/pretty/hir-struct-expr.pp index bb222dc2e5f10..edc7e020f84d7 100644 --- a/tests/pretty/hir-struct-expr.pp +++ b/tests/pretty/hir-struct-expr.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-struct-expr.pp diff --git a/tests/pretty/issue-12590-c.pp b/tests/pretty/issue-12590-c.pp index 0df095b0ee554..412031d9031b5 100644 --- a/tests/pretty/issue-12590-c.pp +++ b/tests/pretty/issue-12590-c.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/issue-4264.pp b/tests/pretty/issue-4264.pp index 1344923f4c47c..74d1360fb9eb8 100644 --- a/tests/pretty/issue-4264.pp +++ b/tests/pretty/issue-4264.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ pretty-compare-only //@ pretty-mode:hir,typed //@ pp-exact:issue-4264.pp diff --git a/tests/pretty/issue-85089.pp b/tests/pretty/issue-85089.pp index 28a85bdf4ad8b..bfd79f7392417 100644 --- a/tests/pretty/issue-85089.pp +++ b/tests/pretty/issue-85089.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; // Test to print lifetimes on HIR pretty-printing. //@ pretty-compare-only diff --git a/tests/pretty/postfix-match/precedence.pp b/tests/pretty/postfix-match/precedence.pp index b6ff45daea120..36972df44d725 100644 --- a/tests/pretty/postfix-match/precedence.pp +++ b/tests/pretty/postfix-match/precedence.pp @@ -1,7 +1,8 @@ #![feature(prelude_import)] #![no_std] #![feature(postfix_match)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index 9e1566b2eff3b..b3a4edd8b7950 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/asm/unpretty-expanded.stdout b/tests/ui/asm/unpretty-expanded.stdout index 7678f6bc3450c..c159270e96f29 100644 --- a/tests/ui/asm/unpretty-expanded.stdout +++ b/tests/ui/asm/unpretty-expanded.stdout @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout index 7499df5be5da1..9af994c50193e 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout @@ -1,5 +1,6 @@ #![feature(prelude_import)] -#[macro_use] +#[prelude_import] +use std::prelude::rust_2021::*; extern crate std; #[prelude_import] use std::prelude::rust_2021::*; diff --git a/tests/ui/codemap_tests/unicode.expanded.stdout b/tests/ui/codemap_tests/unicode.expanded.stdout index af375108b4780..10b2eea138e53 100644 --- a/tests/ui/codemap_tests/unicode.expanded.stdout +++ b/tests/ui/codemap_tests/unicode.expanded.stdout @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/const-generics/defaults/pretty-printing-ast.stdout b/tests/ui/const-generics/defaults/pretty-printing-ast.stdout index 030fcec9cf2a7..bf64725b728b9 100644 --- a/tests/ui/const-generics/defaults/pretty-printing-ast.stdout +++ b/tests/ui/const-generics/defaults/pretty-printing-ast.stdout @@ -6,7 +6,8 @@ //@ edition: 2015 #![crate_type = "lib"] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/deriving/built-in-proc-macro-scope.stdout b/tests/ui/deriving/built-in-proc-macro-scope.stdout index 4fbce5edb8194..44aa4ba3e79db 100644 --- a/tests/ui/deriving/built-in-proc-macro-scope.stdout +++ b/tests/ui/deriving/built-in-proc-macro-scope.stdout @@ -6,7 +6,8 @@ //@ edition:2015 #![feature(derive_coerce_pointee)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index 4c60b1cf4275f..92358d39a8d1e 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -17,8 +17,8 @@ #![crate_type = "lib"] #![allow(dead_code)] #![allow(deprecated)] -#![feature(derive_from)] -#[macro_use] +#[prelude_import] +use std::prelude::rust_2021::*; extern crate std; #[prelude_import] use std::prelude::rust_2021::*; diff --git a/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout index 89300a5c6d0ca..ca0979263fbf0 100644 --- a/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout +++ b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout @@ -4,7 +4,8 @@ //@ compile-flags: -Zunpretty=expanded //@ edition: 2015 #![feature(derive_coerce_pointee)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/deriving/proc-macro-attribute-mixing.stdout b/tests/ui/deriving/proc-macro-attribute-mixing.stdout index b81110682d68f..647a34ecca1db 100644 --- a/tests/ui/deriving/proc-macro-attribute-mixing.stdout +++ b/tests/ui/deriving/proc-macro-attribute-mixing.stdout @@ -12,7 +12,8 @@ //@ edition: 2015 #![feature(derive_coerce_pointee)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/feature-gates/feature-gate-format_args_nl.rs b/tests/ui/feature-gates/feature-gate-format_args_nl.rs index aeee2fbad9071..5b3c5de0aec28 100644 --- a/tests/ui/feature-gates/feature-gate-format_args_nl.rs +++ b/tests/ui/feature-gates/feature-gate-format_args_nl.rs @@ -1,3 +1,5 @@ +use std::format_args_nl; + fn main() { format_args_nl!(""); //~ ERROR `format_args_nl` is only for internal language use } diff --git a/tests/ui/lint/dead-code/with-core-crate.rs b/tests/ui/lint/dead-code/with-core-crate.rs index 0a94b528f3339..9ccb6aecb75fb 100644 --- a/tests/ui/lint/dead-code/with-core-crate.rs +++ b/tests/ui/lint/dead-code/with-core-crate.rs @@ -1,7 +1,6 @@ #![deny(dead_code)] #![allow(unreachable_code)] -#[macro_use] extern crate core; fn foo() { //~ ERROR function `foo` is never used diff --git a/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout b/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout index 80abac44ca84c..fbc5abfb20c65 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout +++ b/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout index ba93384644d59..98200ada95728 100644 --- a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ edition: 2015 diff --git a/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout b/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout index e29655faabe58..0b5d9defa765f 100644 --- a/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout +++ b/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout @@ -5,7 +5,8 @@ //@ edition: 2015 #![feature(core_intrinsics, generic_assert)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/match/issue-82392.stdout b/tests/ui/match/issue-82392.stdout index d7eef0497392b..284ab0463d775 100644 --- a/tests/ui/match/issue-82392.stdout +++ b/tests/ui/match/issue-82392.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; // https://github.com/rust-lang/rust/issues/82329 //@ compile-flags: -Zunpretty=hir,typed //@ check-pass diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 452598c372c17..3acc22c705e64 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -16,7 +16,8 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro // in the stdout #![no_std /* 0#0 */] -#[macro_use /* 0#1 */] +#[prelude_import /* 0#1 */] +use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; extern crate core /* 0#1 */; #[prelude_import /* 0#1 */] use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index e10a5199f1793..6455386873c87 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -36,7 +36,8 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ #![feature /* 0#0 */(decl_macro)] #![no_std /* 0#0 */] -#[macro_use /* 0#1 */] +#[prelude_import /* 0#1 */] +use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; extern crate core /* 0#2 */; #[prelude_import /* 0#1 */] use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; diff --git a/tests/ui/proc-macro/quote/debug.stdout b/tests/ui/proc-macro/quote/debug.stdout index 77c52f02a33c1..9a9f4b0401f12 100644 --- a/tests/ui/proc-macro/quote/debug.stdout +++ b/tests/ui/proc-macro/quote/debug.stdout @@ -12,7 +12,8 @@ #![feature(proc_macro_quote)] #![crate_type = "proc-macro"] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout index 66ba726fb9a49..9e6b56142b630 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/type-alias-impl-trait/issue-60662.stdout b/tests/ui/type-alias-impl-trait/issue-60662.stdout index 7ad29c88bcfe5..93d2e1d6df976 100644 --- a/tests/ui/type-alias-impl-trait/issue-60662.stdout +++ b/tests/ui/type-alias-impl-trait/issue-60662.stdout @@ -7,6 +7,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; trait Animal { } diff --git a/tests/ui/unpretty/bad-literal.stdout b/tests/ui/unpretty/bad-literal.stdout index 1f697aff27c9b..47c52adcb58fa 100644 --- a/tests/ui/unpretty/bad-literal.stdout +++ b/tests/ui/unpretty/bad-literal.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-fail //@ edition: 2015 diff --git a/tests/ui/unpretty/debug-fmt-hir.stdout b/tests/ui/unpretty/debug-fmt-hir.stdout index 9c79421e32aba..5256169539e59 100644 --- a/tests/ui/unpretty/debug-fmt-hir.stdout +++ b/tests/ui/unpretty/debug-fmt-hir.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/deprecated-attr.stdout b/tests/ui/unpretty/deprecated-attr.stdout index 26cc74c11604d..43aa96df8c574 100644 --- a/tests/ui/unpretty/deprecated-attr.stdout +++ b/tests/ui/unpretty/deprecated-attr.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/diagnostic-attr.stdout b/tests/ui/unpretty/diagnostic-attr.stdout index 4822cf4700b94..be502ba05dd5a 100644 --- a/tests/ui/unpretty/diagnostic-attr.stdout +++ b/tests/ui/unpretty/diagnostic-attr.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/exhaustive.expanded.stdout b/tests/ui/unpretty/exhaustive.expanded.stdout index a12ea0786f910..e86cff64e3323 100644 --- a/tests/ui/unpretty/exhaustive.expanded.stdout +++ b/tests/ui/unpretty/exhaustive.expanded.stdout @@ -30,7 +30,8 @@ #![feature(try_blocks)] #![feature(yeet_expr)] #![allow(incomplete_features)] -#[macro_use] +#[prelude_import] +use std::prelude::rust_2024::*; extern crate std; #[prelude_import] use std::prelude::rust_2024::*; diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index 233c9f1c91bd7..c595f8218c479 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir -Zflatten-format-args=yes //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/interpolation-expanded.stdout b/tests/ui/unpretty/interpolation-expanded.stdout index 7284a89e7a9b0..e73b7d44c583e 100644 --- a/tests/ui/unpretty/interpolation-expanded.stdout +++ b/tests/ui/unpretty/interpolation-expanded.stdout @@ -10,7 +10,8 @@ // synthesizing parentheses indiscriminately; only where necessary. #![feature(if_let_guard)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2024::*; extern crate std; #[prelude_import] use std::prelude::rust_2024::*; @@ -61,7 +62,7 @@ fn local() { macro_rules! let_expr_else_return { ($pat:pat, $expr:expr) => { let $pat = $expr else { return; }; }; } - let + let no_paren = void() else { return; }; } diff --git a/tests/ui/unpretty/let-else-hir.stdout b/tests/ui/unpretty/let-else-hir.stdout index 14270a5720274..b091fbe746c21 100644 --- a/tests/ui/unpretty/let-else-hir.stdout +++ b/tests/ui/unpretty/let-else-hir.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/self-hir.stdout b/tests/ui/unpretty/self-hir.stdout index b190565dcc472..c0656416afb06 100644 --- a/tests/ui/unpretty/self-hir.stdout +++ b/tests/ui/unpretty/self-hir.stdout @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout index c04909a736136..fa543b85fb517 100644 --- a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout +++ b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout @@ -12,6 +12,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; fn main() ({ } as ()) From 840868d1f0db57a38f37763befe3d34d2b64c274 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Wed, 25 Jun 2025 13:15:35 +0200 Subject: [PATCH 09/24] Update prelude macros --- library/core/src/prelude/v1.rs | 13 +++---------- library/std/src/prelude/v1.rs | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index 078211fdf8be3..014d1e8225a46 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -59,6 +59,7 @@ pub use crate::hash::macros::Hash; #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[doc(no_inline)] +#[allow(deprecated)] pub use crate::{ 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, }; @@ -76,9 +77,9 @@ mod ambiguous_macro_only { #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] pub use self::ambiguous_macro_only::{env, panic}; -#[unstable(feature = "cfg_match", issue = "115585")] +#[unstable(feature = "cfg_select", issue = "115585")] #[doc(no_inline)] -pub use crate::cfg_match; +pub use crate::cfg_select; #[unstable( feature = "concat_bytes", @@ -88,14 +89,6 @@ pub use crate::cfg_match; #[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; diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index af201843ed669..3c4fe8b7d8428 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -46,6 +46,7 @@ pub use crate::result::Result::{self, Err, Ok}; // Re-exported built-in macros and traits #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[doc(no_inline)] +#[allow(deprecated)] pub use core::prelude::v1::{ 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, @@ -71,9 +72,9 @@ mod ambiguous_macro_only_std { #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] pub use self::ambiguous_macro_only_std::{vec, panic}; -#[unstable(feature = "cfg_match", issue = "115585")] +#[unstable(feature = "cfg_select", issue = "115585")] #[doc(no_inline)] -pub use core::prelude::v1::cfg_match; +pub use core::prelude::v1::cfg_select; #[unstable( feature = "concat_bytes", @@ -83,14 +84,6 @@ pub use core::prelude::v1::cfg_match; #[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; From cceb01569a9fa6cbcb70ad49c26461348060ac10 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Wed, 25 Jun 2025 13:30:12 +0200 Subject: [PATCH 10/24] Fix feature-gate-format_args_nl UI test --- tests/ui/feature-gates/feature-gate-format_args_nl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/feature-gates/feature-gate-format_args_nl.rs b/tests/ui/feature-gates/feature-gate-format_args_nl.rs index 5b3c5de0aec28..4749eea13a6db 100644 --- a/tests/ui/feature-gates/feature-gate-format_args_nl.rs +++ b/tests/ui/feature-gates/feature-gate-format_args_nl.rs @@ -1,4 +1,4 @@ -use std::format_args_nl; +use std::format_args_nl; //~ ERROR `format_args_nl` is only for internal language use fn main() { format_args_nl!(""); //~ ERROR `format_args_nl` is only for internal language use From 6a5db2fce4dcbd4bf46b8e75db32c6b31e584b56 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Wed, 25 Jun 2025 17:08:47 +0200 Subject: [PATCH 11/24] Apply review comments --- .../ide-diagnostics/src/handlers/unresolved_macro_call.rs | 1 + .../rust-analyzer/crates/ide/src/syntax_highlighting/tests.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs index 241a42e5fda43..a87b8c42ac1d0 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs @@ -93,6 +93,7 @@ macro_rules! panic { } //- /lib.rs crate:foo deps:core +#[macro_use] extern crate core; fn foo() { 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 a7a0f180899af..8198701d68432 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 @@ -446,7 +446,7 @@ fn test_string_highlighting() { //- minicore: fmt, assert, asm, concat, panic macro_rules! println { ($($arg:tt)*) => ({ - $crate::io::_print(std::format_args_nl!($($arg)*)); + $crate::io::_print(format_args_nl!($($arg)*)); }) } From c37fee27d736b08e1fc904853de59aa5330aae50 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Mon, 7 Jul 2025 11:06:40 +0200 Subject: [PATCH 12/24] Fix macro import in alloctests --- library/alloctests/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 378b0d313497e..e7492b005bf8e 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -56,6 +56,7 @@ #![feature(negative_impls)] #![feature(never_type)] #![feature(optimize_attribute)] +#![feature(prelude_import)] #![feature(rustc_allow_const_fn_unstable)] #![feature(rustc_attrs)] #![feature(staged_api)] @@ -65,10 +66,17 @@ // Allow testing this library extern crate alloc as realalloc; + +// This is needed to provide macros to the directly imported alloc modules below. +#[prelude_import] +#[allow(unused_imports)] +use std::prelude::rust_2024::*; extern crate std; + #[cfg(test)] extern crate test; mod testing; + use realalloc::*; // We are directly including collections, raw_vec, and wtf8 here as they use non-public @@ -92,8 +100,7 @@ pub(crate) mod test_helpers { let mut hasher = std::hash::RandomState::new().build_hasher(); std::panic::Location::caller().hash(&mut hasher); let hc64 = hasher.finish(); - let seed_vec = - hc64.to_le_bytes().into_iter().chain(0u8..8).collect::>(); + let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::>(); let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap(); rand::SeedableRng::from_seed(seed) } From 0ba79595f8916be8781180e27557f7182a14d8b2 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Thu, 10 Jul 2025 13:15:48 +0200 Subject: [PATCH 13/24] Fix rustdoc macro inlining issues Missing `#[doc(no_inline)]` for ambiguous_macro_only_std resulted in new and broken doc html files. --- library/core/src/prelude/v1.rs | 1 + library/std/src/prelude/v1.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index 014d1e8225a46..77dc10d165cfe 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -75,6 +75,7 @@ mod ambiguous_macro_only { pub use crate::*; } #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] +#[doc(no_inline)] pub use self::ambiguous_macro_only::{env, panic}; #[unstable(feature = "cfg_select", issue = "115585")] diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 3c4fe8b7d8428..4b2214d7b2d6f 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -70,6 +70,7 @@ mod ambiguous_macro_only_std { pub use crate::*; } #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] +#[doc(no_inline)] pub use self::ambiguous_macro_only_std::{vec, panic}; #[unstable(feature = "cfg_select", issue = "115585")] From c7af19f36a15831e51ebace4f0d24f05189aff64 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Thu, 10 Jul 2025 18:08:53 +0200 Subject: [PATCH 14/24] Adapt pretty tests expected outputs --- tests/pretty/autodiff/inherent_impl.pp | 3 ++- tests/pretty/hir-delegation.pp | 1 + tests/pretty/hir-if-else.pp | 1 + tests/pretty/if-else.pp | 3 ++- tests/pretty/never-pattern.pp | 3 ++- tests/pretty/pin-ergonomics-hir.pp | 1 + tests/pretty/shebang-at-top.pp | 3 ++- 7 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/pretty/autodiff/inherent_impl.pp b/tests/pretty/autodiff/inherent_impl.pp index 36a9222640ae5..fc3e8960b3ad7 100644 --- a/tests/pretty/autodiff/inherent_impl.pp +++ b/tests/pretty/autodiff/inherent_impl.pp @@ -3,7 +3,8 @@ //@ needs-enzyme #![feature(autodiff)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/hir-delegation.pp b/tests/pretty/hir-delegation.pp index f8ad02f2fccce..cc2c9fcb3dc96 100644 --- a/tests/pretty/hir-delegation.pp +++ b/tests/pretty/hir-delegation.pp @@ -8,6 +8,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; fn b(e: C) { } diff --git a/tests/pretty/hir-if-else.pp b/tests/pretty/hir-if-else.pp index af5d31b07cb18..324fa295849c4 100644 --- a/tests/pretty/hir-if-else.pp +++ b/tests/pretty/hir-if-else.pp @@ -2,6 +2,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-if-else.pp diff --git a/tests/pretty/if-else.pp b/tests/pretty/if-else.pp index f29b693e571eb..49c5159e0e9cd 100644 --- a/tests/pretty/if-else.pp +++ b/tests/pretty/if-else.pp @@ -1,6 +1,7 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/never-pattern.pp b/tests/pretty/never-pattern.pp index 1ce332ea50643..6ba5fa3f3a338 100644 --- a/tests/pretty/never-pattern.pp +++ b/tests/pretty/never-pattern.pp @@ -7,7 +7,8 @@ #![allow(incomplete_features)] #![feature(never_patterns)] #![feature(never_type)] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/pin-ergonomics-hir.pp b/tests/pretty/pin-ergonomics-hir.pp index beca5988017dc..1cb7f94ad649e 100644 --- a/tests/pretty/pin-ergonomics-hir.pp +++ b/tests/pretty/pin-ergonomics-hir.pp @@ -8,6 +8,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +extern crate std; use std::pin::Pin; diff --git a/tests/pretty/shebang-at-top.pp b/tests/pretty/shebang-at-top.pp index 197def4a154b1..c27ac52d0960d 100644 --- a/tests/pretty/shebang-at-top.pp +++ b/tests/pretty/shebang-at-top.pp @@ -1,7 +1,8 @@ #!/usr/bin/env rust #![feature(prelude_import)] #![no_std] -#[macro_use] +#[prelude_import] +use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; From 55e83f9e3331a7efbc0fe31740c57cd0f599c101 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Thu, 14 Aug 2025 12:37:27 +0200 Subject: [PATCH 15/24] Silence unproblematic warning --- library/std/src/prelude/v1.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 4b2214d7b2d6f..27bf745f640a5 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -66,6 +66,7 @@ mod ambiguous_macro_only_std { mod vec {} #[allow(hidden_glob_reexports)] mod panic {} + #[allow(exported_private_dependencies)] #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] pub use crate::*; } From d89124aaa5581100441f0e23e5f94917d9cfddb9 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Thu, 14 Aug 2025 12:43:04 +0200 Subject: [PATCH 16/24] Bless UI tests --- tests/ui/asm/unpretty-expanded.stdout | 2 -- .../unpretty-parenthesized.stdout | 2 -- tests/ui/codemap_tests/unicode.expanded.stdout | 2 -- .../defaults/pretty-printing-ast.stdout | 2 -- .../ui/deriving/built-in-proc-macro-scope.stdout | 2 -- tests/ui/deriving/deriving-all-codegen.stdout | 2 -- .../deriving-coerce-pointee-expanded.stdout | 2 -- .../deriving/proc-macro-attribute-mixing.stdout | 2 -- .../feature-gate-format_args_nl.stderr | 13 +++++++++++-- tests/ui/imports/glob-shadowing.stderr | 10 ++++++---- .../local-modularized-tricky-fail-1.stderr | 10 ++++++---- tests/ui/imports/shadow_builtin_macros.stderr | 15 +++++++++------ tests/ui/lint/dead-code/with-core-crate.stderr | 2 +- .../no_ice_for_partial_compiler_runs.stdout | 2 -- .../genercs-in-path-with-prettry-hir.stdout | 2 -- ...onsuming-methods-have-optimized-codegen.stdout | 2 -- tests/ui/match/issue-82392.stdout | 2 -- tests/ui/proc-macro/meta-macro-hygiene.stdout | 2 -- .../proc-macro/nonterminal-token-hygiene.stdout | 2 -- tests/ui/proc-macro/quote/debug.stdout | 2 -- .../ast-pretty-check.stdout | 2 -- tests/ui/stats/input-stats.stderr | 8 ++++---- tests/ui/type-alias-impl-trait/issue-60662.stdout | 2 -- tests/ui/unpretty/bad-literal.stdout | 2 -- tests/ui/unpretty/debug-fmt-hir.stdout | 2 -- tests/ui/unpretty/deprecated-attr.stdout | 2 -- tests/ui/unpretty/diagnostic-attr.stdout | 2 -- tests/ui/unpretty/exhaustive-asm.expanded.stdout | 1 - tests/ui/unpretty/exhaustive-asm.hir.stdout | 1 - tests/ui/unpretty/exhaustive.expanded.stdout | 2 -- tests/ui/unpretty/exhaustive.hir.stdout | 1 - tests/ui/unpretty/flattened-format-args.stdout | 2 -- tests/ui/unpretty/interpolation-expanded.stdout | 4 +--- tests/ui/unpretty/let-else-hir.stdout | 2 -- tests/ui/unpretty/self-hir.stdout | 2 -- tests/ui/unpretty/unpretty-expr-fn-arg.stdout | 2 -- 36 files changed, 38 insertions(+), 79 deletions(-) diff --git a/tests/ui/asm/unpretty-expanded.stdout b/tests/ui/asm/unpretty-expanded.stdout index c159270e96f29..ce636c150c1cc 100644 --- a/tests/ui/asm/unpretty-expanded.stdout +++ b/tests/ui/asm/unpretty-expanded.stdout @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout index 9af994c50193e..c53491a6747c6 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout @@ -1,6 +1,4 @@ #![feature(prelude_import)] -#[prelude_import] -use std::prelude::rust_2021::*; extern crate std; #[prelude_import] use std::prelude::rust_2021::*; diff --git a/tests/ui/codemap_tests/unicode.expanded.stdout b/tests/ui/codemap_tests/unicode.expanded.stdout index 10b2eea138e53..4a29277fe3bff 100644 --- a/tests/ui/codemap_tests/unicode.expanded.stdout +++ b/tests/ui/codemap_tests/unicode.expanded.stdout @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/const-generics/defaults/pretty-printing-ast.stdout b/tests/ui/const-generics/defaults/pretty-printing-ast.stdout index bf64725b728b9..efd703b24b435 100644 --- a/tests/ui/const-generics/defaults/pretty-printing-ast.stdout +++ b/tests/ui/const-generics/defaults/pretty-printing-ast.stdout @@ -6,8 +6,6 @@ //@ edition: 2015 #![crate_type = "lib"] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/deriving/built-in-proc-macro-scope.stdout b/tests/ui/deriving/built-in-proc-macro-scope.stdout index 44aa4ba3e79db..e2a9119af3d61 100644 --- a/tests/ui/deriving/built-in-proc-macro-scope.stdout +++ b/tests/ui/deriving/built-in-proc-macro-scope.stdout @@ -6,8 +6,6 @@ //@ edition:2015 #![feature(derive_coerce_pointee)] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index 92358d39a8d1e..ff65009edbb55 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -17,8 +17,6 @@ #![crate_type = "lib"] #![allow(dead_code)] #![allow(deprecated)] -#[prelude_import] -use std::prelude::rust_2021::*; extern crate std; #[prelude_import] use std::prelude::rust_2021::*; diff --git a/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout index ca0979263fbf0..ace45c4d760f6 100644 --- a/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout +++ b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout @@ -4,8 +4,6 @@ //@ compile-flags: -Zunpretty=expanded //@ edition: 2015 #![feature(derive_coerce_pointee)] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/deriving/proc-macro-attribute-mixing.stdout b/tests/ui/deriving/proc-macro-attribute-mixing.stdout index 647a34ecca1db..e82f1780d0959 100644 --- a/tests/ui/deriving/proc-macro-attribute-mixing.stdout +++ b/tests/ui/deriving/proc-macro-attribute-mixing.stdout @@ -12,8 +12,6 @@ //@ edition: 2015 #![feature(derive_coerce_pointee)] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/feature-gates/feature-gate-format_args_nl.stderr b/tests/ui/feature-gates/feature-gate-format_args_nl.stderr index c7e8f8c686f90..1265bd447f40e 100644 --- a/tests/ui/feature-gates/feature-gate-format_args_nl.stderr +++ b/tests/ui/feature-gates/feature-gate-format_args_nl.stderr @@ -1,5 +1,5 @@ error[E0658]: use of unstable library feature `format_args_nl`: `format_args_nl` is only for internal language use and is subject to change - --> $DIR/feature-gate-format_args_nl.rs:2:5 + --> $DIR/feature-gate-format_args_nl.rs:4:5 | LL | format_args_nl!(""); | ^^^^^^^^^^^^^^ @@ -7,6 +7,15 @@ LL | format_args_nl!(""); = help: add `#![feature(format_args_nl)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 1 previous error +error[E0658]: use of unstable library feature `format_args_nl`: `format_args_nl` is only for internal language use and is subject to change + --> $DIR/feature-gate-format_args_nl.rs:1:5 + | +LL | use std::format_args_nl; + | ^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(format_args_nl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/imports/glob-shadowing.stderr b/tests/ui/imports/glob-shadowing.stderr index 0ce8d4f54f8d5..025147d08f014 100644 --- a/tests/ui/imports/glob-shadowing.stderr +++ b/tests/ui/imports/glob-shadowing.stderr @@ -5,14 +5,15 @@ LL | let x = env!("PATH"); | ^^^ 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: `env` could refer to a macro from prelude -note: `env` could also refer to the macro imported here +note: `env` could refer to the macro imported here --> $DIR/glob-shadowing.rs:9:9 | LL | use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `env` to disambiguate = help: or use `self::env` to refer to this macro unambiguously +note: `env` could also refer to a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL error[E0659]: `env` is ambiguous --> $DIR/glob-shadowing.rs:19:21 @@ -21,13 +22,14 @@ LL | let x = env!("PATH"); | ^^^ 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: `env` could refer to a macro from prelude -note: `env` could also refer to the macro imported here +note: `env` could refer to the macro imported here --> $DIR/glob-shadowing.rs:17:13 | LL | use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `env` to disambiguate +note: `env` could also refer to a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL error[E0659]: `fenv` is ambiguous --> $DIR/glob-shadowing.rs:29:21 diff --git a/tests/ui/imports/local-modularized-tricky-fail-1.stderr b/tests/ui/imports/local-modularized-tricky-fail-1.stderr index 52a01e8bcdfe3..5e87531a05333 100644 --- a/tests/ui/imports/local-modularized-tricky-fail-1.stderr +++ b/tests/ui/imports/local-modularized-tricky-fail-1.stderr @@ -30,8 +30,7 @@ LL | panic!(); | ^^^^^ ambiguous name | = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution - = note: `panic` could refer to a macro from prelude -note: `panic` could also refer to the macro defined here +note: `panic` could refer to the macro defined here --> $DIR/local-modularized-tricky-fail-1.rs:12:5 | LL | / macro_rules! panic { @@ -42,6 +41,8 @@ LL | | } LL | define_panic!(); | --------------- in this macro invocation = help: use `crate::panic` to refer to this macro unambiguously +note: `panic` could also refer to a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL = note: this error originates in the macro `define_panic` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `include` is ambiguous @@ -51,8 +52,7 @@ LL | include!(); | ^^^^^^^ ambiguous name | = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution - = note: `include` could refer to a macro from prelude -note: `include` could also refer to the macro defined here +note: `include` could refer to the macro defined here --> $DIR/local-modularized-tricky-fail-1.rs:18:5 | LL | / macro_rules! include { @@ -63,6 +63,8 @@ LL | | } LL | define_include!(); | ----------------- in this macro invocation = help: use `crate::include` to refer to this macro unambiguously +note: `include` could also refer to a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL = note: this error originates in the macro `define_include` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/tests/ui/imports/shadow_builtin_macros.stderr b/tests/ui/imports/shadow_builtin_macros.stderr index c828b1193d81e..7799fb230d434 100644 --- a/tests/ui/imports/shadow_builtin_macros.stderr +++ b/tests/ui/imports/shadow_builtin_macros.stderr @@ -5,14 +5,15 @@ LL | fn f() { panic!(); } | ^^^^^ 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 a macro from prelude -note: `panic` could also refer to the macro imported here +note: `panic` could refer to the macro imported here --> $DIR/shadow_builtin_macros.rs:14:9 | LL | use crate::foo::*; | ^^^^^^^^^^^^^ = 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 a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL error[E0659]: `panic` is ambiguous --> $DIR/shadow_builtin_macros.rs:33:5 @@ -21,8 +22,7 @@ LL | panic!(); | ^^^^^ ambiguous name | = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution - = note: `panic` could refer to a macro from prelude -note: `panic` could also refer to the macro defined here +note: `panic` could refer to the macro defined here --> $DIR/shadow_builtin_macros.rs:30:9 | LL | macro_rules! panic { () => {} } @@ -30,6 +30,8 @@ LL | macro_rules! panic { () => {} } LL | } } LL | m!(); | ---- in this macro invocation +note: `panic` could also refer to a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `n` is ambiguous @@ -59,13 +61,14 @@ LL | fn f() { panic!(); } | ^^^^^ ambiguous name | = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution - = note: `panic` could refer to a macro from prelude -note: `panic` could also refer to the macro imported here +note: `panic` could refer to the macro imported here --> $DIR/shadow_builtin_macros.rs:19:26 | LL | ::two_macros::m!(use crate::foo::panic;); | ^^^^^^^^^^^^^^^^^ = help: use `self::panic` to refer to this macro unambiguously +note: `panic` could also refer to a macro from prelude + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL error: aborting due to 4 previous errors diff --git a/tests/ui/lint/dead-code/with-core-crate.stderr b/tests/ui/lint/dead-code/with-core-crate.stderr index f466a616580c5..9db26c956298e 100644 --- a/tests/ui/lint/dead-code/with-core-crate.stderr +++ b/tests/ui/lint/dead-code/with-core-crate.stderr @@ -1,5 +1,5 @@ error: function `foo` is never used - --> $DIR/with-core-crate.rs:7:4 + --> $DIR/with-core-crate.rs:6:4 | LL | fn foo() { | ^^^ diff --git a/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout b/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout index fbc5abfb20c65..0fcfc936a59bc 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout +++ b/tests/ui/lint/rfc-2383-lint-reason/no_ice_for_partial_compiler_runs.stdout @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout index 98200ada95728..6e41432ad7df1 100644 --- a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ edition: 2015 diff --git a/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout b/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout index 0b5d9defa765f..d47f733d40edb 100644 --- a/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout +++ b/tests/ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout @@ -5,8 +5,6 @@ //@ edition: 2015 #![feature(core_intrinsics, generic_assert)] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/match/issue-82392.stdout b/tests/ui/match/issue-82392.stdout index 284ab0463d775..d44ffbe216716 100644 --- a/tests/ui/match/issue-82392.stdout +++ b/tests/ui/match/issue-82392.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; // https://github.com/rust-lang/rust/issues/82329 //@ compile-flags: -Zunpretty=hir,typed //@ check-pass diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 3acc22c705e64..b5db9922b31a8 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -16,8 +16,6 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro // in the stdout #![no_std /* 0#0 */] -#[prelude_import /* 0#1 */] -use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; extern crate core /* 0#1 */; #[prelude_import /* 0#1 */] use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index 6455386873c87..e45abab03b4c4 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -36,8 +36,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ #![feature /* 0#0 */(decl_macro)] #![no_std /* 0#0 */] -#[prelude_import /* 0#1 */] -use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; extern crate core /* 0#2 */; #[prelude_import /* 0#1 */] use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; diff --git a/tests/ui/proc-macro/quote/debug.stdout b/tests/ui/proc-macro/quote/debug.stdout index 9a9f4b0401f12..896c809fedaba 100644 --- a/tests/ui/proc-macro/quote/debug.stdout +++ b/tests/ui/proc-macro/quote/debug.stdout @@ -12,8 +12,6 @@ #![feature(proc_macro_quote)] #![crate_type = "proc-macro"] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout index 9e6b56142b630..9a34d6c1af7ac 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-pretty-check.stdout @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index 4a73a4747ad0c..eec3e4edd5ed4 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -15,7 +15,7 @@ ast-stats - Ptr 64 (NN.N%) 1 ast-stats - Ref 64 (NN.N%) 1 ast-stats - ImplicitSelf 128 (NN.N%) 2 ast-stats - Path 640 (NN.N%) 10 -ast-stats PathSegment 888 (NN.N%) 37 24 +ast-stats PathSegment 864 (NN.N%) 36 24 ast-stats Expr 648 (NN.N%) 9 72 ast-stats - InlineAsm 72 (NN.N%) 1 ast-stats - Match 72 (NN.N%) 1 @@ -41,9 +41,9 @@ ast-stats - Let 32 (NN.N%) 1 ast-stats - Semi 32 (NN.N%) 1 ast-stats - Expr 96 (NN.N%) 3 ast-stats Param 160 (NN.N%) 4 40 -ast-stats Attribute 160 (NN.N%) 5 32 +ast-stats Attribute 128 (NN.N%) 4 32 ast-stats - DocComment 32 (NN.N%) 1 -ast-stats - Normal 128 (NN.N%) 4 +ast-stats - Normal 96 (NN.N%) 3 ast-stats InlineAsm 120 (NN.N%) 1 120 ast-stats FnDecl 120 (NN.N%) 5 24 ast-stats Local 96 (NN.N%) 1 96 @@ -93,7 +93,7 @@ hir-stats GenericParam 400 (NN.N%) 5 80 hir-stats Block 288 (NN.N%) 6 48 hir-stats GenericBound 256 (NN.N%) 4 64 hir-stats - Trait 256 (NN.N%) 4 -hir-stats Attribute 200 (NN.N%) 5 40 +hir-stats Attribute 160 (NN.N%) 4 40 hir-stats Variant 144 (NN.N%) 2 72 hir-stats GenericArgs 144 (NN.N%) 3 48 hir-stats FieldDef 128 (NN.N%) 2 64 diff --git a/tests/ui/type-alias-impl-trait/issue-60662.stdout b/tests/ui/type-alias-impl-trait/issue-60662.stdout index 93d2e1d6df976..d1f337819f8b0 100644 --- a/tests/ui/type-alias-impl-trait/issue-60662.stdout +++ b/tests/ui/type-alias-impl-trait/issue-60662.stdout @@ -3,11 +3,9 @@ //@ edition: 2015 #![feature(type_alias_impl_trait)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; trait Animal { } diff --git a/tests/ui/unpretty/bad-literal.stdout b/tests/ui/unpretty/bad-literal.stdout index 47c52adcb58fa..267d59a868e41 100644 --- a/tests/ui/unpretty/bad-literal.stdout +++ b/tests/ui/unpretty/bad-literal.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-fail //@ edition: 2015 diff --git a/tests/ui/unpretty/debug-fmt-hir.stdout b/tests/ui/unpretty/debug-fmt-hir.stdout index 5256169539e59..342dc144909ce 100644 --- a/tests/ui/unpretty/debug-fmt-hir.stdout +++ b/tests/ui/unpretty/debug-fmt-hir.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/deprecated-attr.stdout b/tests/ui/unpretty/deprecated-attr.stdout index 43aa96df8c574..0b0f17d556665 100644 --- a/tests/ui/unpretty/deprecated-attr.stdout +++ b/tests/ui/unpretty/deprecated-attr.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/diagnostic-attr.stdout b/tests/ui/unpretty/diagnostic-attr.stdout index be502ba05dd5a..80cd11753493a 100644 --- a/tests/ui/unpretty/diagnostic-attr.stdout +++ b/tests/ui/unpretty/diagnostic-attr.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/exhaustive-asm.expanded.stdout b/tests/ui/unpretty/exhaustive-asm.expanded.stdout index 9a58e4c2877b1..9b3c60b03ba77 100644 --- a/tests/ui/unpretty/exhaustive-asm.expanded.stdout +++ b/tests/ui/unpretty/exhaustive-asm.expanded.stdout @@ -1,5 +1,4 @@ #![feature(prelude_import)] -#[macro_use] extern crate std; #[prelude_import] use std::prelude::rust_2024::*; diff --git a/tests/ui/unpretty/exhaustive-asm.hir.stdout b/tests/ui/unpretty/exhaustive-asm.hir.stdout index b33b38c2caba4..ed98191e1dd56 100644 --- a/tests/ui/unpretty/exhaustive-asm.hir.stdout +++ b/tests/ui/unpretty/exhaustive-asm.hir.stdout @@ -1,4 +1,3 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use std::prelude::rust_2024::*; diff --git a/tests/ui/unpretty/exhaustive.expanded.stdout b/tests/ui/unpretty/exhaustive.expanded.stdout index e86cff64e3323..8952a2a6fc4b6 100644 --- a/tests/ui/unpretty/exhaustive.expanded.stdout +++ b/tests/ui/unpretty/exhaustive.expanded.stdout @@ -30,8 +30,6 @@ #![feature(try_blocks)] #![feature(yeet_expr)] #![allow(incomplete_features)] -#[prelude_import] -use std::prelude::rust_2024::*; extern crate std; #[prelude_import] use std::prelude::rust_2024::*; diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 27cba6560300a..b769f6f402e4a 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -29,7 +29,6 @@ #![feature(try_blocks)] #![feature(yeet_expr)] #![allow(incomplete_features)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use std::prelude::rust_2024::*; diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index c595f8218c479..7f1d6b59c9d38 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir -Zflatten-format-args=yes //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/interpolation-expanded.stdout b/tests/ui/unpretty/interpolation-expanded.stdout index e73b7d44c583e..d385a021ed57a 100644 --- a/tests/ui/unpretty/interpolation-expanded.stdout +++ b/tests/ui/unpretty/interpolation-expanded.stdout @@ -10,8 +10,6 @@ // synthesizing parentheses indiscriminately; only where necessary. #![feature(if_let_guard)] -#[prelude_import] -use ::std::prelude::rust_2024::*; extern crate std; #[prelude_import] use std::prelude::rust_2024::*; @@ -62,7 +60,7 @@ fn local() { macro_rules! let_expr_else_return { ($pat:pat, $expr:expr) => { let $pat = $expr else { return; }; }; } - let + let no_paren = void() else { return; }; } diff --git a/tests/ui/unpretty/let-else-hir.stdout b/tests/ui/unpretty/let-else-hir.stdout index b091fbe746c21..cc19f392c3a43 100644 --- a/tests/ui/unpretty/let-else-hir.stdout +++ b/tests/ui/unpretty/let-else-hir.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/self-hir.stdout b/tests/ui/unpretty/self-hir.stdout index c0656416afb06..c973e143275cd 100644 --- a/tests/ui/unpretty/self-hir.stdout +++ b/tests/ui/unpretty/self-hir.stdout @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass //@ edition: 2015 diff --git a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout index fa543b85fb517..41d62d11aaa61 100644 --- a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout +++ b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout @@ -8,11 +8,9 @@ //@ compile-flags: -Zunpretty=hir,typed //@ edition: 2015 #![allow(dead_code)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; fn main() ({ } as ()) From 73ede2b6d9bc19657d97fb4a1d840fda474b27bf Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Fri, 15 Aug 2025 16:38:41 +0200 Subject: [PATCH 17/24] Fix alloctests again --- library/alloctests/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index e7492b005bf8e..59642619b623e 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -68,10 +68,10 @@ extern crate alloc as realalloc; // This is needed to provide macros to the directly imported alloc modules below. +extern crate std; #[prelude_import] #[allow(unused_imports)] use std::prelude::rust_2024::*; -extern crate std; #[cfg(test)] extern crate test; From 845a56d6630d97b84e30032f7fe9d89d83fd5663 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Fri, 15 Aug 2025 19:07:08 +0200 Subject: [PATCH 18/24] Appease clippy --- library/std/src/prelude/v1.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 27bf745f640a5..86fe3c7ab840d 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -66,6 +66,9 @@ mod ambiguous_macro_only_std { mod vec {} #[allow(hidden_glob_reexports)] mod panic {} + // Building std without the allow exported_private_dependencies will create warnings, but then + // clippy claims its a useless_attribute. So silence both. + #[allow(clippy::useless_attribute)] #[allow(exported_private_dependencies)] #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] pub use crate::*; From ac0c5be1de90f58623fd7f72cce31bcc8387ece4 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Fri, 15 Aug 2025 19:25:52 +0200 Subject: [PATCH 19/24] Export new hash_map macro --- library/std/src/prelude/v1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 86fe3c7ab840d..a641278f646f9 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -56,7 +56,7 @@ pub use core::prelude::v1::{ #[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 + dbg, eprint, eprintln, format, is_x86_feature_detected, print, println, thread_local, hash_map }; // These macros needs special handling, so that we don't export it *and* the modules of the same From 38c53c76b7ba57a060a54fe499ec47907c5db481 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Sat, 16 Aug 2025 18:48:07 +0200 Subject: [PATCH 20/24] Fix deriving-all-codegen UI test An incorrect merge conflict resolution had deleted a relevant new line. --- tests/ui/deriving/deriving-all-codegen.stdout | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index ff65009edbb55..e0b274f3a33d0 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -17,6 +17,7 @@ #![crate_type = "lib"] #![allow(dead_code)] #![allow(deprecated)] +#![feature(derive_from)] extern crate std; #[prelude_import] use std::prelude::rust_2021::*; From 2450cd28bcf58ca179683fd16683735b975c47d2 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Sun, 17 Aug 2025 11:15:47 +0200 Subject: [PATCH 21/24] Bless pretty test output changes --- tests/pretty/asm.pp | 2 -- tests/pretty/cast-lt.pp | 2 -- tests/pretty/dollar-crate.pp | 2 -- tests/pretty/expanded-and-path-remap-80832.pp | 2 -- tests/pretty/format-args-str-escape.pp | 2 -- tests/pretty/hir-delegation.pp | 2 -- tests/pretty/hir-fn-params.pp | 2 -- tests/pretty/hir-fn-variadic.pp | 2 -- tests/pretty/hir-if-else.pp | 2 -- tests/pretty/hir-lifetimes.pp | 2 -- tests/pretty/hir-pretty-attr.pp | 2 -- tests/pretty/hir-pretty-loop.pp | 2 -- tests/pretty/hir-struct-expr.pp | 2 -- tests/pretty/if-else.pp | 2 -- tests/pretty/issue-12590-c.pp | 2 -- tests/pretty/issue-4264.pp | 2 -- tests/pretty/issue-85089.pp | 2 -- tests/pretty/never-pattern.pp | 2 -- tests/pretty/pin-ergonomics-hir.pp | 2 -- tests/pretty/postfix-match/precedence.pp | 2 -- tests/pretty/shebang-at-top.pp | 2 -- tests/pretty/tests-are-sorted.pp | 2 -- 22 files changed, 44 deletions(-) diff --git a/tests/pretty/asm.pp b/tests/pretty/asm.pp index 2ec58a449e124..f1f020a68fb64 100644 --- a/tests/pretty/asm.pp +++ b/tests/pretty/asm.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/cast-lt.pp b/tests/pretty/cast-lt.pp index ce6d440000cd8..deca38fc09627 100644 --- a/tests/pretty/cast-lt.pp +++ b/tests/pretty/cast-lt.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/dollar-crate.pp b/tests/pretty/dollar-crate.pp index b6aad86cf704d..f7f6e5c3d4939 100644 --- a/tests/pretty/dollar-crate.pp +++ b/tests/pretty/dollar-crate.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/expanded-and-path-remap-80832.pp b/tests/pretty/expanded-and-path-remap-80832.pp index f028e446864c3..d434633b7c4bd 100644 --- a/tests/pretty/expanded-and-path-remap-80832.pp +++ b/tests/pretty/expanded-and-path-remap-80832.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/format-args-str-escape.pp b/tests/pretty/format-args-str-escape.pp index bb4872edff6e3..bf944f445e1c1 100644 --- a/tests/pretty/format-args-str-escape.pp +++ b/tests/pretty/format-args-str-escape.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/hir-delegation.pp b/tests/pretty/hir-delegation.pp index cc2c9fcb3dc96..5a27bf34ebf7b 100644 --- a/tests/pretty/hir-delegation.pp +++ b/tests/pretty/hir-delegation.pp @@ -4,11 +4,9 @@ #![allow(incomplete_features)] #![feature(fn_delegation)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; fn b(e: C) { } diff --git a/tests/pretty/hir-fn-params.pp b/tests/pretty/hir-fn-params.pp index 67106f0de716b..52310d5024cd6 100644 --- a/tests/pretty/hir-fn-params.pp +++ b/tests/pretty/hir-fn-params.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-fn-params.pp diff --git a/tests/pretty/hir-fn-variadic.pp b/tests/pretty/hir-fn-variadic.pp index 473f3f08cc480..d40b3be27903a 100644 --- a/tests/pretty/hir-fn-variadic.pp +++ b/tests/pretty/hir-fn-variadic.pp @@ -3,11 +3,9 @@ //@ pp-exact:hir-fn-variadic.pp #![feature(c_variadic)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; extern "C" { unsafe fn foo(x: i32, va1: ...); diff --git a/tests/pretty/hir-if-else.pp b/tests/pretty/hir-if-else.pp index 324fa295849c4..d3721e1758157 100644 --- a/tests/pretty/hir-if-else.pp +++ b/tests/pretty/hir-if-else.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-if-else.pp diff --git a/tests/pretty/hir-lifetimes.pp b/tests/pretty/hir-lifetimes.pp index 1f29bf93d2dab..51598333b125e 100644 --- a/tests/pretty/hir-lifetimes.pp +++ b/tests/pretty/hir-lifetimes.pp @@ -5,11 +5,9 @@ // This tests the pretty-printing of lifetimes in lots of ways. #![allow(unused)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; struct Foo<'a> { x: &'a u32, diff --git a/tests/pretty/hir-pretty-attr.pp b/tests/pretty/hir-pretty-attr.pp index cdfebb2b1b746..a9d8b5e7e5770 100644 --- a/tests/pretty/hir-pretty-attr.pp +++ b/tests/pretty/hir-pretty-attr.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-pretty-attr.pp diff --git a/tests/pretty/hir-pretty-loop.pp b/tests/pretty/hir-pretty-loop.pp index 659ca6aa72bd6..e6614ce318cce 100644 --- a/tests/pretty/hir-pretty-loop.pp +++ b/tests/pretty/hir-pretty-loop.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-pretty-loop.pp diff --git a/tests/pretty/hir-struct-expr.pp b/tests/pretty/hir-struct-expr.pp index edc7e020f84d7..198d7ad6a9b6b 100644 --- a/tests/pretty/hir-struct-expr.pp +++ b/tests/pretty/hir-struct-expr.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ pretty-compare-only //@ pretty-mode:hir //@ pp-exact:hir-struct-expr.pp diff --git a/tests/pretty/if-else.pp b/tests/pretty/if-else.pp index 49c5159e0e9cd..6ca71a3a3d347 100644 --- a/tests/pretty/if-else.pp +++ b/tests/pretty/if-else.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/issue-12590-c.pp b/tests/pretty/issue-12590-c.pp index 412031d9031b5..b79b73337adbd 100644 --- a/tests/pretty/issue-12590-c.pp +++ b/tests/pretty/issue-12590-c.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/issue-4264.pp b/tests/pretty/issue-4264.pp index 74d1360fb9eb8..583358f6f53c9 100644 --- a/tests/pretty/issue-4264.pp +++ b/tests/pretty/issue-4264.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; //@ pretty-compare-only //@ pretty-mode:hir,typed //@ pp-exact:issue-4264.pp diff --git a/tests/pretty/issue-85089.pp b/tests/pretty/issue-85089.pp index bfd79f7392417..919573220fddd 100644 --- a/tests/pretty/issue-85089.pp +++ b/tests/pretty/issue-85089.pp @@ -1,8 +1,6 @@ -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; // Test to print lifetimes on HIR pretty-printing. //@ pretty-compare-only diff --git a/tests/pretty/never-pattern.pp b/tests/pretty/never-pattern.pp index 6ba5fa3f3a338..bb95a1ed442a4 100644 --- a/tests/pretty/never-pattern.pp +++ b/tests/pretty/never-pattern.pp @@ -7,8 +7,6 @@ #![allow(incomplete_features)] #![feature(never_patterns)] #![feature(never_type)] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/pin-ergonomics-hir.pp b/tests/pretty/pin-ergonomics-hir.pp index 1cb7f94ad649e..f00536de571c9 100644 --- a/tests/pretty/pin-ergonomics-hir.pp +++ b/tests/pretty/pin-ergonomics-hir.pp @@ -4,11 +4,9 @@ #![feature(pin_ergonomics)] #![allow(dead_code, incomplete_features)] -#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -extern crate std; use std::pin::Pin; diff --git a/tests/pretty/postfix-match/precedence.pp b/tests/pretty/postfix-match/precedence.pp index 36972df44d725..56ee1f1061af2 100644 --- a/tests/pretty/postfix-match/precedence.pp +++ b/tests/pretty/postfix-match/precedence.pp @@ -1,8 +1,6 @@ #![feature(prelude_import)] #![no_std] #![feature(postfix_match)] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/shebang-at-top.pp b/tests/pretty/shebang-at-top.pp index c27ac52d0960d..0c19c0c44e458 100644 --- a/tests/pretty/shebang-at-top.pp +++ b/tests/pretty/shebang-at-top.pp @@ -1,8 +1,6 @@ #!/usr/bin/env rust #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index b3a4edd8b7950..43f9838e68ce9 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -1,7 +1,5 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use ::std::prelude::rust_2015::*; extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; From 7031546ef694106f0e29a50e332293afbed2cf7d Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Thu, 18 Sep 2025 15:13:41 +0200 Subject: [PATCH 22/24] Bless input-stats UI test --- tests/ui/stats/input-stats.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index eec3e4edd5ed4..99a14085615fd 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -57,7 +57,7 @@ ast-stats GenericArgs 40 (NN.N%) 1 40 ast-stats - AngleBracketed 40 (NN.N%) 1 ast-stats Crate 40 (NN.N%) 1 40 ast-stats ---------------------------------------------------------------- -ast-stats Total 7_528 129 +ast-stats Total 7_472 127 ast-stats ================================================================ hir-stats ================================================================ hir-stats HIR STATS: input_stats @@ -119,5 +119,5 @@ hir-stats TraitItemId 8 (NN.N%) 2 4 hir-stats ImplItemId 8 (NN.N%) 2 4 hir-stats ForeignItemId 4 (NN.N%) 1 4 hir-stats ---------------------------------------------------------------- -hir-stats Total 8_624 173 +hir-stats Total 8_584 172 hir-stats ================================================================ From af7ef8938a5436c316e1ae0d0a438bab0dcfb2ec Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Thu, 18 Sep 2025 15:40:31 +0200 Subject: [PATCH 23/24] Adjust println-type test to include prelude items While this is undesired, blocking explicit macro export and assert_matches for this bug that already exists in a smaller fashion was deemed not worth it. See https://github.com/rust-lang/rust/issues/145577 and https://github.com/rust-lang/rust/pull/139493#issuecomment-3288311495 --- tests/rustdoc-js-std/println-typo.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/rustdoc-js-std/println-typo.js b/tests/rustdoc-js-std/println-typo.js index a4dd90a44d5ba..b91e7883b995f 100644 --- a/tests/rustdoc-js-std/println-typo.js +++ b/tests/rustdoc-js-std/println-typo.js @@ -6,7 +6,10 @@ const EXPECTED = { 'query': 'prinltn', 'others': [ { 'path': 'std', 'name': 'println' }, + { 'path': 'std::prelude::v1', 'name': 'println' }, { 'path': 'std', 'name': 'print' }, + { 'path': 'std::prelude::v1', 'name': 'print' }, { 'path': 'std', 'name': 'eprintln' }, + { 'path': 'std::prelude::v1', 'name': 'eprintln' }, ], }; From bdc4c56ab47eb0a8fa819442d64962cfb7e11a76 Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Sat, 4 Oct 2025 10:08:24 +0200 Subject: [PATCH 24/24] Add ambiguous_panic_imports lint This turns the ambiguous panic import error into a warning to avoid breaking large parts of the Rust crate ecosystem. --- compiler/rustc_lint/src/early/diagnostics.rs | 4 +- compiler/rustc_lint/src/lints.rs | 4 +- compiler/rustc_lint_defs/src/builtin.rs | 38 +++++++++++++++ compiler/rustc_lint_defs/src/lib.rs | 2 +- compiler/rustc_resolve/src/diagnostics.rs | 20 +++++--- compiler/rustc_resolve/src/ident.rs | 43 ++++++++++++----- compiler/rustc_resolve/src/imports.rs | 7 +-- compiler/rustc_resolve/src/lib.rs | 10 +++- tests/ui/imports/ambiguous-panic.rs | 13 +++++ tests/ui/imports/ambiguous-panic.stderr | 51 ++++++++++++++++++++ 10 files changed, 164 insertions(+), 28 deletions(-) create mode 100644 tests/ui/imports/ambiguous-panic.rs create mode 100644 tests/ui/imports/ambiguous-panic.stderr diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 9029ee0447110..139f9513f6ef5 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -257,8 +257,8 @@ pub fn decorate_builtin_lint( lints::ExternCrateNotIdiomatic { span: suggestion_span, code }.decorate_lint(diag); } - BuiltinLintDiag::AmbiguousGlobImports { diag: ambiguity } => { - lints::AmbiguousGlobImports { ambiguity }.decorate_lint(diag); + BuiltinLintDiag::AmbiguousImports { diag: ambiguity } => { + lints::AmbiguousImports { ambiguity }.decorate_lint(diag); } BuiltinLintDiag::AmbiguousGlobReexports { name, diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index b7312484de5cd..2fc0b095499bd 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2863,11 +2863,11 @@ pub(crate) struct ExternCrateNotIdiomatic { } // FIXME: make this translatable -pub(crate) struct AmbiguousGlobImports { +pub(crate) struct AmbiguousImports { pub ambiguity: AmbiguityErrorDiag, } -impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for AmbiguousGlobImports { +impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for AmbiguousImports { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) { diag.primary_message(self.ambiguity.msg.clone()); rustc_errors::report_ambiguity_error(diag, self.ambiguity); diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 939f3d088b12f..a7cdbf2c1c125 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -21,6 +21,7 @@ declare_lint_pass! { AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_GLOB_IMPORTS, AMBIGUOUS_GLOB_REEXPORTS, + AMBIGUOUS_PANIC_IMPORTS, ARITHMETIC_OVERFLOW, ASM_SUB_REGISTER, BAD_ASM_STYLE, @@ -4438,6 +4439,43 @@ declare_lint! { }; } +declare_lint! { + /// The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but + /// previously didn't do that due to `#[macro_use]` prelude macro import. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(ambiguous_panic_imports)] + /// #![no_std] + /// + /// extern crate std; + /// use std::prelude::v1::*; + /// + /// fn xx() { + /// panic!(); // resolves to core::panic + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Future versions of Rust will no longer accept the ambiguous resolution. + /// + /// This is a [future-incompatible] lint to transition this to a hard error in the future. + /// + /// [future-incompatible]: ../index.md#future-incompatible-lints + pub AMBIGUOUS_PANIC_IMPORTS, + Warn, + "detects ambiguous core and std panic imports", + @future_incompatible = FutureIncompatibleInfo { + reason: FutureIncompatibilityReason::FutureReleaseError, + reference: "issue #147319 ", + report_in_deps: true, + }; +} + declare_lint! { /// The `refining_impl_trait_reachable` lint detects `impl Trait` return /// types in method signatures that are refined by a publically reachable diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 40a818a3c9dc7..5e2d5bf94ae1d 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -682,7 +682,7 @@ pub enum BuiltinLintDiag { vis_span: Span, ident_span: Span, }, - AmbiguousGlobImports { + AmbiguousImports { diag: AmbiguityErrorDiag, }, AmbiguousGlobReexports { diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 236ab1f09d35f..27e38e5e1f4b1 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -21,7 +21,7 @@ use rustc_middle::bug; use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_session::lint::builtin::{ - ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, AMBIGUOUS_GLOB_IMPORTS, + ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, AMBIGUOUS_GLOB_IMPORTS, AMBIGUOUS_PANIC_IMPORTS, MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS, }; use rustc_session::lint::{AmbiguityErrorDiag, BuiltinLintDiag}; @@ -42,9 +42,9 @@ use crate::errors::{ use crate::imports::{Import, ImportKind}; use crate::late::{PatternSource, Rib}; use crate::{ - AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingError, BindingKey, Finalize, - ForwardGenericParamBanReason, HasGenericParams, LexicalScopeBinding, MacroRulesScope, Module, - ModuleKind, ModuleOrUniformRoot, NameBinding, NameBindingKind, ParentScope, PathResult, + AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, AmbiguityWarning, BindingError, BindingKey, + Finalize, ForwardGenericParamBanReason, HasGenericParams, LexicalScopeBinding, MacroRulesScope, + Module, ModuleKind, ModuleOrUniformRoot, NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError, ResolutionError, Resolver, Scope, ScopeSet, Segment, UseError, Used, VisResolutionError, errors as errs, path_names_to_string, }; @@ -144,15 +144,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { for ambiguity_error in &self.ambiguity_errors { let diag = self.ambiguity_diagnostics(ambiguity_error); - if ambiguity_error.warning { + if let Some(ambiguity_warning) = ambiguity_error.warning { let NameBindingKind::Import { import, .. } = ambiguity_error.b1.0.kind else { unreachable!() }; + + let lint = match ambiguity_warning { + AmbiguityWarning::GlobImport => AMBIGUOUS_GLOB_IMPORTS, + AmbiguityWarning::PanicImport => AMBIGUOUS_PANIC_IMPORTS, + }; + self.lint_buffer.buffer_lint( - AMBIGUOUS_GLOB_IMPORTS, + lint, import.root_id, ambiguity_error.ident.span, - BuiltinLintDiag::AmbiguousGlobImports { diag }, + BuiltinLintDiag::AmbiguousImports { diag }, ); } else { let mut err = struct_span_code_err!(self.dcx(), diag.span, E0659, "{}", diag.msg); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 4415300777f98..8c149b6250caf 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -15,10 +15,10 @@ use crate::imports::{Import, NameResolution}; use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind}; use crate::macros::{MacroRulesScope, sub_namespace_match}; use crate::{ - AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingKey, CmResolver, Determinacy, - Finalize, ImportKind, LexicalScopeBinding, Module, ModuleKind, ModuleOrUniformRoot, - NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError, Res, ResolutionError, - Resolver, Scope, ScopeSet, Segment, Stage, Used, Weak, errors, + AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, AmbiguityWarning, BindingKey, CmResolver, + Determinacy, Finalize, ImportKind, LexicalScopeBinding, Module, ModuleKind, + ModuleOrUniformRoot, NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError, Res, + ResolutionError, Resolver, Scope, ScopeSet, Segment, Stage, Used, Weak, errors, }; #[derive(Copy, Clone)] @@ -697,13 +697,34 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // Skip ambiguity errors for extern flag bindings "overridden" // by extern item bindings. // FIXME: Remove with lang team approval. - let issue_145575_hack = Some(binding) - == extern_prelude_flag_binding - && extern_prelude_item_binding.is_some() - && extern_prelude_item_binding != Some(innermost_binding); + let is_issue_145575_hack = || { + Some(binding) == extern_prelude_flag_binding + && extern_prelude_item_binding.is_some() + && extern_prelude_item_binding != Some(innermost_binding) + }; + if let Some(kind) = ambiguity_error_kind - && !issue_145575_hack + && !is_issue_145575_hack() { + // Turn ambiguity errors for core vs std panic into warnings. + // FIXME: Remove with lang team approval. + let is_issue_147319_hack = matches!( + (binding.res(), innermost_binding.res()), + ( + Res::Def(DefKind::Macro(_), def_id_core), + Res::Def(DefKind::Macro(_), def_id_std) + ) if this.tcx.def_path_debug_str(def_id_core) + == "core[234c]::macros::panic" + && this.tcx.def_path_debug_str(def_id_std) + == "std[d474]::macros::panic" + ); + + let warning = if is_issue_147319_hack { + Some(AmbiguityWarning::PanicImport) + } else { + None + }; + let misc = |f: Flags| { if f.contains(Flags::MISC_SUGGEST_CRATE) { AmbiguityErrorMisc::SuggestCrate @@ -720,7 +741,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ident: orig_ident, b1: innermost_binding, b2: binding, - warning: false, + warning, misc1: misc(innermost_flags), misc2: misc(flags), }); @@ -1064,7 +1085,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ident, b1: binding, b2: shadowed_glob, - warning: false, + warning: None, misc1: AmbiguityErrorMisc::None, misc2: AmbiguityErrorMisc::None, }); diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index ce90a1bcd313d..211ef869261e2 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -957,8 +957,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ImportKind::Single { bindings, .. } => bindings[TypeNS].get().binding(), _ => None, }; - let ambiguity_errors_len = - |errors: &Vec>| errors.iter().filter(|error| !error.warning).count(); + let ambiguity_errors_len = |errors: &Vec>| { + errors.iter().filter(|error| error.warning.is_none()).count() + }; let prev_ambiguity_errors_len = ambiguity_errors_len(&self.ambiguity_errors); let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span); @@ -1173,7 +1174,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }); let res = binding.res(); let has_ambiguity_error = - this.ambiguity_errors.iter().any(|error| !error.warning); + this.ambiguity_errors.iter().any(|error| error.warning.is_none()); if res == Res::Err || has_ambiguity_error { this.dcx() .span_delayed_bug(import.span, "some error happened for an import"); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index b44b1c966a431..d2a4ca807ef46 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -903,6 +903,12 @@ enum AmbiguityErrorMisc { None, } +#[derive(Clone, Copy, PartialEq)] +enum AmbiguityWarning { + GlobImport, + PanicImport, +} + struct AmbiguityError<'ra> { kind: AmbiguityKind, ident: Ident, @@ -910,7 +916,7 @@ struct AmbiguityError<'ra> { b2: NameBinding<'ra>, misc1: AmbiguityErrorMisc, misc2: AmbiguityErrorMisc, - warning: bool, + warning: Option, } impl<'ra> NameBindingData<'ra> { @@ -2046,7 +2052,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { b2, misc1: AmbiguityErrorMisc::None, misc2: AmbiguityErrorMisc::None, - warning: warn_ambiguity, + warning: if warn_ambiguity { Some(AmbiguityWarning::GlobImport) } else { None }, }; if !self.matches_previous_ambiguity_error(&ambiguity_error) { // avoid duplicated span information to be emit out diff --git a/tests/ui/imports/ambiguous-panic.rs b/tests/ui/imports/ambiguous-panic.rs new file mode 100644 index 0000000000000..654b6e2f9af8b --- /dev/null +++ b/tests/ui/imports/ambiguous-panic.rs @@ -0,0 +1,13 @@ +#![deny(ambiguous_panic_imports)] +#![crate_type = "lib"] +#![no_std] + +extern crate std; +use std::prelude::v1::*; + +#[allow(unused)] +fn xx() { + panic!(); + //~^ ERROR `panic` is ambiguous + //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +} diff --git a/tests/ui/imports/ambiguous-panic.stderr b/tests/ui/imports/ambiguous-panic.stderr new file mode 100644 index 0000000000000..4b4ef29f2f049 --- /dev/null +++ b/tests/ui/imports/ambiguous-panic.stderr @@ -0,0 +1,51 @@ +error: `panic` is ambiguous + --> $DIR/ambiguous-panic.rs:10:5 + | +LL | panic!(); + | ^^^^^ ambiguous name + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #147319 + = 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 + --> $DIR/ambiguous-panic.rs:6:5 + | +LL | use std::prelude::v1::*; + | ^^^^^^^^^^^^^^^^^^^ + = help: consider adding an explicit import of `panic` to disambiguate + = help: or use `crate::panic` to refer to this macro unambiguously +note: `panic` could also refer to a macro from prelude + --> $SRC_DIR/core/src/prelude/mod.rs:LL:COL +note: the lint level is defined here + --> $DIR/ambiguous-panic.rs:1:9 + | +LL | #![deny(ambiguous_panic_imports)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +Future incompatibility report: Future breakage diagnostic: +error: `panic` is ambiguous + --> $DIR/ambiguous-panic.rs:10:5 + | +LL | panic!(); + | ^^^^^ ambiguous name + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #147319 + = 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 + --> $DIR/ambiguous-panic.rs:6:5 + | +LL | use std::prelude::v1::*; + | ^^^^^^^^^^^^^^^^^^^ + = help: consider adding an explicit import of `panic` to disambiguate + = help: or use `crate::panic` to refer to this macro unambiguously +note: `panic` could also refer to a macro from prelude + --> $SRC_DIR/core/src/prelude/mod.rs:LL:COL +note: the lint level is defined here + --> $DIR/ambiguous-panic.rs:1:9 + | +LL | #![deny(ambiguous_panic_imports)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +