Skip to content

Commit 3174216

Browse files
author
lukas
committed
Mark some macros with must_use hint
1 parent 99b7134 commit 3174216

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

library/core/src/macros/mod.rs

+32-14
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,12 @@ pub(crate) mod builtin {
10101010
#[rustc_builtin_macro]
10111011
#[macro_export]
10121012
macro_rules! format_args {
1013-
($fmt:expr) => {{ /* compiler built-in */ }};
1014-
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
1013+
($fmt:expr) => {
1014+
$crate::hint::must_use({ /* compiler built-in */ })
1015+
};
1016+
($fmt:expr, $($args:tt)*) => {
1017+
$crate::hint::must_use({ /* compiler built-in */ })
1018+
};
10151019
}
10161020

10171021
/// Same as [`format_args`], but can be used in some const contexts.
@@ -1081,8 +1085,12 @@ pub(crate) mod builtin {
10811085
#[macro_export]
10821086
#[rustc_diagnostic_item = "env_macro"] // useful for external lints
10831087
macro_rules! env {
1084-
($name:expr $(,)?) => {{ /* compiler built-in */ }};
1085-
($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }};
1088+
($name:expr $(,)?) => {
1089+
$crate::hint::must_use({ /* compiler built-in */ })
1090+
};
1091+
($name:expr, $error_msg:expr $(,)?) => {
1092+
$crate::hint::must_use({ /* compiler built-in */ })
1093+
};
10861094
}
10871095

10881096
/// Optionally inspects an environment variable at compile time.
@@ -1112,7 +1120,9 @@ pub(crate) mod builtin {
11121120
#[macro_export]
11131121
#[rustc_diagnostic_item = "option_env_macro"] // useful for external lints
11141122
macro_rules! option_env {
1115-
($name:expr $(,)?) => {{ /* compiler built-in */ }};
1123+
($name:expr $(,)?) => {
1124+
$crate::hint::must_use({ /* compiler built-in */ })
1125+
};
11161126
}
11171127

11181128
/// Concatenates identifiers into one identifier.
@@ -1174,7 +1184,9 @@ pub(crate) mod builtin {
11741184
#[rustc_builtin_macro]
11751185
#[macro_export]
11761186
macro_rules! concat_bytes {
1177-
($($e:literal),+ $(,)?) => {{ /* compiler built-in */ }};
1187+
($($e:literal),+ $(,)?) => {
1188+
$crate::hint::must_use({ /* compiler built-in */ })
1189+
};
11781190
}
11791191

11801192
/// Concatenates literals into a static string slice.
@@ -1196,7 +1208,9 @@ pub(crate) mod builtin {
11961208
#[rustc_builtin_macro]
11971209
#[macro_export]
11981210
macro_rules! concat {
1199-
($($e:expr),* $(,)?) => {{ /* compiler built-in */ }};
1211+
($($e:expr),* $(,)?) => {
1212+
$crate::hint::must_use({ /* compiler built-in */ })
1213+
};
12001214
}
12011215

12021216
/// Expands to the line number on which it was invoked.
@@ -1222,7 +1236,7 @@ pub(crate) mod builtin {
12221236
#[macro_export]
12231237
macro_rules! line {
12241238
() => {
1225-
/* compiler built-in */
1239+
$crate::hint::must_use({ /* compiler built-in */ })
12261240
};
12271241
}
12281242

@@ -1261,7 +1275,7 @@ pub(crate) mod builtin {
12611275
#[macro_export]
12621276
macro_rules! column {
12631277
() => {
1264-
/* compiler built-in */
1278+
$crate::hint::must_use(/* compiler built-in */)
12651279
};
12661280
}
12671281

@@ -1286,7 +1300,7 @@ pub(crate) mod builtin {
12861300
#[macro_export]
12871301
macro_rules! file {
12881302
() => {
1289-
/* compiler built-in */
1303+
$crate::hint::must_use(/* compiler built-in */)
12901304
};
12911305
}
12921306

@@ -1310,7 +1324,7 @@ pub(crate) mod builtin {
13101324
#[macro_export]
13111325
macro_rules! stringify {
13121326
($($t:tt)*) => {
1313-
/* compiler built-in */
1327+
$crate::hint::must_use(/* compiler built-in */)
13141328
};
13151329
}
13161330

@@ -1351,7 +1365,9 @@ pub(crate) mod builtin {
13511365
#[macro_export]
13521366
#[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")]
13531367
macro_rules! include_str {
1354-
($file:expr $(,)?) => {{ /* compiler built-in */ }};
1368+
($file:expr $(,)?) => {
1369+
$crate::hint::must_use({ /* compiler built-in */ })
1370+
};
13551371
}
13561372

13571373
/// Includes a file as a reference to a byte array.
@@ -1391,7 +1407,9 @@ pub(crate) mod builtin {
13911407
#[macro_export]
13921408
#[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")]
13931409
macro_rules! include_bytes {
1394-
($file:expr $(,)?) => {{ /* compiler built-in */ }};
1410+
($file:expr $(,)?) => {
1411+
$crate::hint::must_use({ /* compiler built-in */ })
1412+
};
13951413
}
13961414

13971415
/// Expands to a string that represents the current module path.
@@ -1449,7 +1467,7 @@ pub(crate) mod builtin {
14491467
#[macro_export]
14501468
macro_rules! cfg {
14511469
($($cfg:tt)*) => {
1452-
/* compiler built-in */
1470+
$crate::hint::must_use(/* compiler built-in */)
14531471
};
14541472
}
14551473

library/core/tests/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn assert_ne_trailing_comma() {
3939
#[rustfmt::skip]
4040
#[test]
4141
fn matches_leading_pipe() {
42-
matches!(1, | 1 | 2 | 3);
42+
let _ = matches!(1, | 1 | 2 | 3);
4343
}
4444

4545
#[test]

tests/ui/box/unit/unique-create.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pub fn main() {
77
}
88

99
fn vec() {
10-
vec![0];
10+
let _ = vec![0];
1111
}

tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn test_drop_list() {
195195
let dropped_fields = Rc::new(RefCell::new(Vec::new()));
196196
let cloned = AssertUnwindSafe(dropped_fields.clone());
197197
panic::catch_unwind(|| {
198-
vec![
198+
let _ = vec![
199199
PushOnDrop::new(2, cloned.clone()),
200200
PushOnDrop::new(1, cloned.clone()),
201201
panic!("this panic is caught :D")

tests/ui/rust-2018/remove-extern-crate.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
with_visibility::foo();
2929
remove_extern_crate::foo!();
3030
bar!();
31-
alloc::vec![5];
31+
let _ = alloc::vec![5];
3232
}
3333

3434
mod another {

tests/ui/rust-2018/remove-extern-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
with_visibility::foo();
2929
remove_extern_crate::foo!();
3030
bar!();
31-
alloc::vec![5];
31+
let _ = alloc::vec![5];
3232
}
3333

3434
mod another {

0 commit comments

Comments
 (0)