Skip to content

Commit cd21715

Browse files
authored
Rollup merge of #63613 - petrochenkov:stdhyg, r=alexcrichton
Hygienize use of built-in macros in the standard library Same as #61629, but for built-in macros. Closes #48781 r? @alexcrichton
2 parents b731131 + 263e3c5 commit cd21715

File tree

11 files changed

+26
-54
lines changed

11 files changed

+26
-54
lines changed

src/liballoc/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ macro_rules! vec {
9898
#[macro_export]
9999
#[stable(feature = "rust1", since = "1.0.0")]
100100
macro_rules! format {
101-
($($arg:tt)*) => ($crate::fmt::format(format_args!($($arg)*)))
101+
($($arg:tt)*) => ($crate::fmt::format(::core::format_args!($($arg)*)))
102102
}

src/libcore/macros.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
///
33
/// For details, see `std::macros`.
44
#[macro_export]
5-
#[allow_internal_unstable(core_panic, __rust_unstable_column)]
5+
#[allow_internal_unstable(core_panic)]
66
#[stable(feature = "core", since = "1.6.0")]
77
macro_rules! panic {
88
() => (
99
$crate::panic!("explicit panic")
1010
);
1111
($msg:expr) => ({
12-
$crate::panicking::panic(&($msg, file!(), line!(), __rust_unstable_column!()))
12+
$crate::panicking::panic(&($msg, $crate::file!(), $crate::line!(), $crate::column!()))
1313
});
1414
($msg:expr,) => (
1515
$crate::panic!($msg)
1616
);
1717
($fmt:expr, $($arg:tt)+) => ({
18-
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)+),
19-
&(file!(), line!(), __rust_unstable_column!()))
18+
$crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+),
19+
&($crate::file!(), $crate::line!(), $crate::column!()))
2020
});
2121
}
2222

@@ -70,7 +70,7 @@ macro_rules! assert_eq {
7070
panic!(r#"assertion failed: `(left == right)`
7171
left: `{:?}`,
7272
right: `{:?}`: {}"#, &*left_val, &*right_val,
73-
format_args!($($arg)+))
73+
$crate::format_args!($($arg)+))
7474
}
7575
}
7676
}
@@ -127,7 +127,7 @@ macro_rules! assert_ne {
127127
panic!(r#"assertion failed: `(left != right)`
128128
left: `{:?}`,
129129
right: `{:?}`: {}"#, &*left_val, &*right_val,
130-
format_args!($($arg)+))
130+
$crate::format_args!($($arg)+))
131131
}
132132
}
133133
}
@@ -181,7 +181,7 @@ macro_rules! assert_ne {
181181
#[macro_export]
182182
#[stable(feature = "rust1", since = "1.0.0")]
183183
macro_rules! debug_assert {
184-
($($arg:tt)*) => (if cfg!(debug_assertions) { assert!($($arg)*); })
184+
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert!($($arg)*); })
185185
}
186186

187187
/// Asserts that two expressions are equal to each other.
@@ -208,7 +208,7 @@ macro_rules! debug_assert {
208208
#[macro_export]
209209
#[stable(feature = "rust1", since = "1.0.0")]
210210
macro_rules! debug_assert_eq {
211-
($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
211+
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
212212
}
213213

214214
/// Asserts that two expressions are not equal to each other.
@@ -235,7 +235,7 @@ macro_rules! debug_assert_eq {
235235
#[macro_export]
236236
#[stable(feature = "assert_ne", since = "1.13.0")]
237237
macro_rules! debug_assert_ne {
238-
($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
238+
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
239239
}
240240

241241
/// Unwraps a result or propagates its error.
@@ -386,7 +386,7 @@ macro_rules! r#try {
386386
#[macro_export]
387387
#[stable(feature = "rust1", since = "1.0.0")]
388388
macro_rules! write {
389-
($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
389+
($dst:expr, $($arg:tt)*) => ($dst.write_fmt($crate::format_args!($($arg)*)))
390390
}
391391

392392
/// Write formatted data into a buffer, with a newline appended.
@@ -446,7 +446,7 @@ macro_rules! writeln {
446446
$crate::writeln!($dst)
447447
);
448448
($dst:expr, $($arg:tt)*) => (
449-
$dst.write_fmt(format_args_nl!($($arg)*))
449+
$dst.write_fmt($crate::format_args_nl!($($arg)*))
450450
);
451451
}
452452

@@ -515,7 +515,7 @@ macro_rules! unreachable {
515515
$crate::unreachable!($msg)
516516
});
517517
($fmt:expr, $($arg:tt)*) => ({
518-
panic!(concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
518+
panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
519519
});
520520
}
521521

@@ -573,7 +573,7 @@ macro_rules! unreachable {
573573
#[stable(feature = "rust1", since = "1.0.0")]
574574
macro_rules! unimplemented {
575575
() => (panic!("not yet implemented"));
576-
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
576+
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
577577
}
578578

579579
/// Indicates unfinished code.
@@ -632,7 +632,7 @@ macro_rules! unimplemented {
632632
#[unstable(feature = "todo_macro", issue = "59277")]
633633
macro_rules! todo {
634634
() => (panic!("not yet implemented"));
635-
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
635+
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
636636
}
637637

638638
/// Definitions of built-in macros.
@@ -927,13 +927,6 @@ pub(crate) mod builtin {
927927
#[macro_export]
928928
macro_rules! column { () => { /* compiler built-in */ } }
929929

930-
/// Same as `column`, but less likely to be shadowed.
931-
#[unstable(feature = "__rust_unstable_column", issue = "0",
932-
reason = "internal implementation detail of the `panic` macro")]
933-
#[rustc_builtin_macro]
934-
#[macro_export]
935-
macro_rules! __rust_unstable_column { () => { /* compiler built-in */ } }
936-
937930
/// Expands to the file name in which it was invoked.
938931
///
939932
/// With [`line!`] and [`column!`], these macros provide debugging information for

src/libcore/prelude/v1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub use crate::hash::macros::Hash;
5656
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
5757
#[doc(no_inline)]
5858
pub use crate::{
59-
__rust_unstable_column,
6059
asm,
6160
assert,
6261
cfg,

src/libstd/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@
228228
// std is implemented with unstable features, many of which are internal
229229
// compiler details that will never be stable
230230
// NB: the following list is sorted to minimize merge conflicts.
231-
#![feature(__rust_unstable_column)]
232231
#![feature(alloc_error_handler)]
233232
#![feature(alloc_layout_extra)]
234233
#![feature(allocator_api)]
@@ -551,7 +550,6 @@ pub use core::{
551550
option_env,
552551
stringify,
553552
// Unstable
554-
__rust_unstable_column,
555553
asm,
556554
concat_idents,
557555
format_args_nl,

src/libstd/macros.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@
5353
/// ```
5454
#[macro_export]
5555
#[stable(feature = "rust1", since = "1.0.0")]
56-
#[allow_internal_unstable(__rust_unstable_column, libstd_sys_internals)]
56+
#[allow_internal_unstable(libstd_sys_internals)]
5757
macro_rules! panic {
5858
() => ({
5959
$crate::panic!("explicit panic")
6060
});
6161
($msg:expr) => ({
62-
$crate::rt::begin_panic($msg, &(file!(), line!(), __rust_unstable_column!()))
62+
$crate::rt::begin_panic($msg, &($crate::file!(), $crate::line!(), $crate::column!()))
6363
});
6464
($msg:expr,) => ({
6565
$crate::panic!($msg)
6666
});
6767
($fmt:expr, $($arg:tt)+) => ({
68-
$crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+),
69-
&(file!(), line!(), __rust_unstable_column!()))
68+
$crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+),
69+
&($crate::file!(), $crate::line!(), $crate::column!()))
7070
});
7171
}
7272

@@ -113,7 +113,7 @@ macro_rules! panic {
113113
#[stable(feature = "rust1", since = "1.0.0")]
114114
#[allow_internal_unstable(print_internals)]
115115
macro_rules! print {
116-
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
116+
($($arg:tt)*) => ($crate::io::_print($crate::format_args!($($arg)*)));
117117
}
118118

119119
/// Prints to the standard output, with a newline.
@@ -147,7 +147,7 @@ macro_rules! print {
147147
macro_rules! println {
148148
() => ($crate::print!("\n"));
149149
($($arg:tt)*) => ({
150-
$crate::io::_print(format_args_nl!($($arg)*));
150+
$crate::io::_print($crate::format_args_nl!($($arg)*));
151151
})
152152
}
153153

@@ -176,7 +176,7 @@ macro_rules! println {
176176
#[stable(feature = "eprint", since = "1.19.0")]
177177
#[allow_internal_unstable(print_internals)]
178178
macro_rules! eprint {
179-
($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*)));
179+
($($arg:tt)*) => ($crate::io::_eprint($crate::format_args!($($arg)*)));
180180
}
181181

182182
/// Prints to the standard error, with a newline.
@@ -206,7 +206,7 @@ macro_rules! eprint {
206206
macro_rules! eprintln {
207207
() => ($crate::eprint!("\n"));
208208
($($arg:tt)*) => ({
209-
$crate::io::_eprint(format_args_nl!($($arg)*));
209+
$crate::io::_eprint($crate::format_args_nl!($($arg)*));
210210
})
211211
}
212212

@@ -337,15 +337,15 @@ macro_rules! eprintln {
337337
#[stable(feature = "dbg_macro", since = "1.32.0")]
338338
macro_rules! dbg {
339339
() => {
340-
$crate::eprintln!("[{}:{}]", file!(), line!());
340+
$crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!());
341341
};
342342
($val:expr) => {
343343
// Use of `match` here is intentional because it affects the lifetimes
344344
// of temporaries - https://stackoverflow.com/a/48732525/1063961
345345
match $val {
346346
tmp => {
347347
$crate::eprintln!("[{}:{}] {} = {:#?}",
348-
file!(), line!(), stringify!($val), &tmp);
348+
$crate::file!(), $crate::line!(), $crate::stringify!($val), &tmp);
349349
tmp
350350
}
351351
}

src/libstd/prelude/v1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub use crate::result::Result::{self, Ok, Err};
4040
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
4141
#[doc(no_inline)]
4242
pub use core::prelude::v1::{
43-
__rust_unstable_column,
4443
asm,
4544
assert,
4645
cfg,

src/libsyntax_ext/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, e
5757
}
5858

5959
register_bang! {
60-
__rust_unstable_column: source_util::expand_column,
6160
asm: asm::expand_asm,
6261
assert: assert::expand_assert,
6362
cfg: cfg::expand_cfg,

src/libsyntax_pos/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,6 @@ symbols! {
609609
rust_eh_personality,
610610
rust_eh_unwind_resume,
611611
rust_oom,
612-
__rust_unstable_column,
613612
rvalue_static_promotion,
614613
sanitizer_runtime,
615614
_Self,

src/test/ui/macros/trace-macro.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ LL | println!("Hello, World!");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: expanding `println! { "Hello, World!" }`
8-
= note: to `{ $crate :: io :: _print (format_args_nl ! ("Hello, World!")) ; }`
8+
= note: to `{ $crate :: io :: _print ($crate :: format_args_nl ! ("Hello, World!")) ; }`
99

src/test/ui/rust-unstable-column-gated.rs

-4
This file was deleted.

src/test/ui/rust-unstable-column-gated.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)