Skip to content

Commit a9ecfd7

Browse files
committed
Hygienize use of built-in macros in the standard library
1 parent f7af19c commit a9ecfd7

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
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

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ macro_rules! panic {
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.

src/libstd/macros.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ macro_rules! panic {
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/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

0 commit comments

Comments
 (0)