Hygienize use of built-in macros in the standard library
This commit is contained in:
parent
f7af19c279
commit
a9ecfd7295
4 changed files with 24 additions and 24 deletions
|
@ -98,5 +98,5 @@ macro_rules! vec {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! format {
|
macro_rules! format {
|
||||||
($($arg:tt)*) => ($crate::fmt::format(format_args!($($arg)*)))
|
($($arg:tt)*) => ($crate::fmt::format(::core::format_args!($($arg)*)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ macro_rules! panic {
|
||||||
$crate::panic!("explicit panic")
|
$crate::panic!("explicit panic")
|
||||||
);
|
);
|
||||||
($msg:expr) => ({
|
($msg:expr) => ({
|
||||||
$crate::panicking::panic(&($msg, file!(), line!(), __rust_unstable_column!()))
|
$crate::panicking::panic(&($msg, $crate::file!(), $crate::line!(), $crate::column!()))
|
||||||
});
|
});
|
||||||
($msg:expr,) => (
|
($msg:expr,) => (
|
||||||
$crate::panic!($msg)
|
$crate::panic!($msg)
|
||||||
);
|
);
|
||||||
($fmt:expr, $($arg:tt)+) => ({
|
($fmt:expr, $($arg:tt)+) => ({
|
||||||
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)+),
|
$crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+),
|
||||||
&(file!(), line!(), __rust_unstable_column!()))
|
&($crate::file!(), $crate::line!(), $crate::column!()))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ macro_rules! assert_eq {
|
||||||
panic!(r#"assertion failed: `(left == right)`
|
panic!(r#"assertion failed: `(left == right)`
|
||||||
left: `{:?}`,
|
left: `{:?}`,
|
||||||
right: `{:?}`: {}"#, &*left_val, &*right_val,
|
right: `{:?}`: {}"#, &*left_val, &*right_val,
|
||||||
format_args!($($arg)+))
|
$crate::format_args!($($arg)+))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ macro_rules! assert_ne {
|
||||||
panic!(r#"assertion failed: `(left != right)`
|
panic!(r#"assertion failed: `(left != right)`
|
||||||
left: `{:?}`,
|
left: `{:?}`,
|
||||||
right: `{:?}`: {}"#, &*left_val, &*right_val,
|
right: `{:?}`: {}"#, &*left_val, &*right_val,
|
||||||
format_args!($($arg)+))
|
$crate::format_args!($($arg)+))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ macro_rules! assert_ne {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! debug_assert {
|
macro_rules! debug_assert {
|
||||||
($($arg:tt)*) => (if cfg!(debug_assertions) { assert!($($arg)*); })
|
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert!($($arg)*); })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts that two expressions are equal to each other.
|
/// Asserts that two expressions are equal to each other.
|
||||||
|
@ -208,7 +208,7 @@ macro_rules! debug_assert {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! debug_assert_eq {
|
macro_rules! debug_assert_eq {
|
||||||
($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
|
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts that two expressions are not equal to each other.
|
/// Asserts that two expressions are not equal to each other.
|
||||||
|
@ -235,7 +235,7 @@ macro_rules! debug_assert_eq {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "assert_ne", since = "1.13.0")]
|
#[stable(feature = "assert_ne", since = "1.13.0")]
|
||||||
macro_rules! debug_assert_ne {
|
macro_rules! debug_assert_ne {
|
||||||
($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
|
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unwraps a result or propagates its error.
|
/// Unwraps a result or propagates its error.
|
||||||
|
@ -386,7 +386,7 @@ macro_rules! r#try {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! write {
|
macro_rules! write {
|
||||||
($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
|
($dst:expr, $($arg:tt)*) => ($dst.write_fmt($crate::format_args!($($arg)*)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write formatted data into a buffer, with a newline appended.
|
/// Write formatted data into a buffer, with a newline appended.
|
||||||
|
@ -446,7 +446,7 @@ macro_rules! writeln {
|
||||||
$crate::writeln!($dst)
|
$crate::writeln!($dst)
|
||||||
);
|
);
|
||||||
($dst:expr, $($arg:tt)*) => (
|
($dst:expr, $($arg:tt)*) => (
|
||||||
$dst.write_fmt(format_args_nl!($($arg)*))
|
$dst.write_fmt($crate::format_args_nl!($($arg)*))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,7 +515,7 @@ macro_rules! unreachable {
|
||||||
$crate::unreachable!($msg)
|
$crate::unreachable!($msg)
|
||||||
});
|
});
|
||||||
($fmt:expr, $($arg:tt)*) => ({
|
($fmt:expr, $($arg:tt)*) => ({
|
||||||
panic!(concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
|
panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +573,7 @@ macro_rules! unreachable {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! unimplemented {
|
macro_rules! unimplemented {
|
||||||
() => (panic!("not yet implemented"));
|
() => (panic!("not yet implemented"));
|
||||||
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
|
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates unfinished code.
|
/// Indicates unfinished code.
|
||||||
|
@ -632,7 +632,7 @@ macro_rules! unimplemented {
|
||||||
#[unstable(feature = "todo_macro", issue = "59277")]
|
#[unstable(feature = "todo_macro", issue = "59277")]
|
||||||
macro_rules! todo {
|
macro_rules! todo {
|
||||||
() => (panic!("not yet implemented"));
|
() => (panic!("not yet implemented"));
|
||||||
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
|
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Definitions of built-in macros.
|
/// Definitions of built-in macros.
|
||||||
|
|
|
@ -59,14 +59,14 @@ macro_rules! panic {
|
||||||
$crate::panic!("explicit panic")
|
$crate::panic!("explicit panic")
|
||||||
});
|
});
|
||||||
($msg:expr) => ({
|
($msg:expr) => ({
|
||||||
$crate::rt::begin_panic($msg, &(file!(), line!(), __rust_unstable_column!()))
|
$crate::rt::begin_panic($msg, &($crate::file!(), $crate::line!(), $crate::column!()))
|
||||||
});
|
});
|
||||||
($msg:expr,) => ({
|
($msg:expr,) => ({
|
||||||
$crate::panic!($msg)
|
$crate::panic!($msg)
|
||||||
});
|
});
|
||||||
($fmt:expr, $($arg:tt)+) => ({
|
($fmt:expr, $($arg:tt)+) => ({
|
||||||
$crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+),
|
$crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+),
|
||||||
&(file!(), line!(), __rust_unstable_column!()))
|
&($crate::file!(), $crate::line!(), $crate::column!()))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ macro_rules! panic {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[allow_internal_unstable(print_internals)]
|
#[allow_internal_unstable(print_internals)]
|
||||||
macro_rules! print {
|
macro_rules! print {
|
||||||
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
|
($($arg:tt)*) => ($crate::io::_print($crate::format_args!($($arg)*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints to the standard output, with a newline.
|
/// Prints to the standard output, with a newline.
|
||||||
|
@ -147,7 +147,7 @@ macro_rules! print {
|
||||||
macro_rules! println {
|
macro_rules! println {
|
||||||
() => ($crate::print!("\n"));
|
() => ($crate::print!("\n"));
|
||||||
($($arg:tt)*) => ({
|
($($arg:tt)*) => ({
|
||||||
$crate::io::_print(format_args_nl!($($arg)*));
|
$crate::io::_print($crate::format_args_nl!($($arg)*));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ macro_rules! println {
|
||||||
#[stable(feature = "eprint", since = "1.19.0")]
|
#[stable(feature = "eprint", since = "1.19.0")]
|
||||||
#[allow_internal_unstable(print_internals)]
|
#[allow_internal_unstable(print_internals)]
|
||||||
macro_rules! eprint {
|
macro_rules! eprint {
|
||||||
($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*)));
|
($($arg:tt)*) => ($crate::io::_eprint($crate::format_args!($($arg)*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints to the standard error, with a newline.
|
/// Prints to the standard error, with a newline.
|
||||||
|
@ -206,7 +206,7 @@ macro_rules! eprint {
|
||||||
macro_rules! eprintln {
|
macro_rules! eprintln {
|
||||||
() => ($crate::eprint!("\n"));
|
() => ($crate::eprint!("\n"));
|
||||||
($($arg:tt)*) => ({
|
($($arg:tt)*) => ({
|
||||||
$crate::io::_eprint(format_args_nl!($($arg)*));
|
$crate::io::_eprint($crate::format_args_nl!($($arg)*));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ macro_rules! eprintln {
|
||||||
#[stable(feature = "dbg_macro", since = "1.32.0")]
|
#[stable(feature = "dbg_macro", since = "1.32.0")]
|
||||||
macro_rules! dbg {
|
macro_rules! dbg {
|
||||||
() => {
|
() => {
|
||||||
$crate::eprintln!("[{}:{}]", file!(), line!());
|
$crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!());
|
||||||
};
|
};
|
||||||
($val:expr) => {
|
($val:expr) => {
|
||||||
// Use of `match` here is intentional because it affects the lifetimes
|
// Use of `match` here is intentional because it affects the lifetimes
|
||||||
|
@ -345,7 +345,7 @@ macro_rules! dbg {
|
||||||
match $val {
|
match $val {
|
||||||
tmp => {
|
tmp => {
|
||||||
$crate::eprintln!("[{}:{}] {} = {:#?}",
|
$crate::eprintln!("[{}:{}] {} = {:#?}",
|
||||||
file!(), line!(), stringify!($val), &tmp);
|
$crate::file!(), $crate::line!(), $crate::stringify!($val), &tmp);
|
||||||
tmp
|
tmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ LL | println!("Hello, World!");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: expanding `println! { "Hello, World!" }`
|
= note: expanding `println! { "Hello, World!" }`
|
||||||
= note: to `{ $crate :: io :: _print (format_args_nl ! ("Hello, World!")) ; }`
|
= note: to `{ $crate :: io :: _print ($crate :: format_args_nl ! ("Hello, World!")) ; }`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue