diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 0d4ca4d5f01e4..cf96a8839f293 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1010,8 +1010,12 @@ pub(crate) mod builtin { #[rustc_builtin_macro] #[macro_export] macro_rules! format_args { - ($fmt:expr) => {{ /* compiler built-in */ }}; - ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }}; + ($fmt:expr) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; + ($fmt:expr, $($args:tt)*) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Same as [`format_args`], but can be used in some const contexts. @@ -1081,8 +1085,12 @@ pub(crate) mod builtin { #[macro_export] #[rustc_diagnostic_item = "env_macro"] // useful for external lints macro_rules! env { - ($name:expr $(,)?) => {{ /* compiler built-in */ }}; - ($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }}; + ($name:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; + ($name:expr, $error_msg:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Optionally inspects an environment variable at compile time. @@ -1112,7 +1120,9 @@ pub(crate) mod builtin { #[macro_export] #[rustc_diagnostic_item = "option_env_macro"] // useful for external lints macro_rules! option_env { - ($name:expr $(,)?) => {{ /* compiler built-in */ }}; + ($name:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Concatenates identifiers into one identifier. @@ -1174,7 +1184,9 @@ pub(crate) mod builtin { #[rustc_builtin_macro] #[macro_export] macro_rules! concat_bytes { - ($($e:literal),+ $(,)?) => {{ /* compiler built-in */ }}; + ($($e:literal),+ $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Concatenates literals into a static string slice. @@ -1196,7 +1208,9 @@ pub(crate) mod builtin { #[rustc_builtin_macro] #[macro_export] macro_rules! concat { - ($($e:expr),* $(,)?) => {{ /* compiler built-in */ }}; + ($($e:expr),* $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Expands to the line number on which it was invoked. @@ -1222,7 +1236,7 @@ pub(crate) mod builtin { #[macro_export] macro_rules! line { () => { - /* compiler built-in */ + $crate::hint::must_use({ /* compiler built-in */ }) }; } @@ -1261,7 +1275,7 @@ pub(crate) mod builtin { #[macro_export] macro_rules! column { () => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } @@ -1286,7 +1300,7 @@ pub(crate) mod builtin { #[macro_export] macro_rules! file { () => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } @@ -1310,7 +1324,7 @@ pub(crate) mod builtin { #[macro_export] macro_rules! stringify { ($($t:tt)*) => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } @@ -1351,7 +1365,9 @@ pub(crate) mod builtin { #[macro_export] #[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")] macro_rules! include_str { - ($file:expr $(,)?) => {{ /* compiler built-in */ }}; + ($file:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Includes a file as a reference to a byte array. @@ -1391,7 +1407,9 @@ pub(crate) mod builtin { #[macro_export] #[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")] macro_rules! include_bytes { - ($file:expr $(,)?) => {{ /* compiler built-in */ }}; + ($file:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Expands to a string that represents the current module path. @@ -1449,7 +1467,7 @@ pub(crate) mod builtin { #[macro_export] macro_rules! cfg { ($($cfg:tt)*) => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } diff --git a/library/core/tests/macros.rs b/library/core/tests/macros.rs index 09994fbcbdb78..3357edb7a68d6 100644 --- a/library/core/tests/macros.rs +++ b/library/core/tests/macros.rs @@ -39,7 +39,7 @@ fn assert_ne_trailing_comma() { #[rustfmt::skip] #[test] fn matches_leading_pipe() { - matches!(1, | 1 | 2 | 3); + let _ = matches!(1, | 1 | 2 | 3); } #[test] diff --git a/tests/ui/box/unit/unique-create.rs b/tests/ui/box/unit/unique-create.rs index bf3826156b1d4..a9691f068ab16 100644 --- a/tests/ui/box/unit/unique-create.rs +++ b/tests/ui/box/unit/unique-create.rs @@ -7,5 +7,5 @@ pub fn main() { } fn vec() { - vec![0]; + let _ = vec![0]; } diff --git a/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs b/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs index d5f6628e0dbc1..4495c193bd759 100644 --- a/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs +++ b/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs @@ -195,7 +195,7 @@ fn test_drop_list() { let dropped_fields = Rc::new(RefCell::new(Vec::new())); let cloned = AssertUnwindSafe(dropped_fields.clone()); panic::catch_unwind(|| { - vec![ + let _ = vec![ PushOnDrop::new(2, cloned.clone()), PushOnDrop::new(1, cloned.clone()), panic!("this panic is caught :D") diff --git a/tests/ui/rust-2018/remove-extern-crate.fixed b/tests/ui/rust-2018/remove-extern-crate.fixed index 19b1dc6fb0130..a6aa842238487 100644 --- a/tests/ui/rust-2018/remove-extern-crate.fixed +++ b/tests/ui/rust-2018/remove-extern-crate.fixed @@ -28,7 +28,7 @@ fn main() { with_visibility::foo(); remove_extern_crate::foo!(); bar!(); - alloc::vec![5]; + let _ = alloc::vec![5]; } mod another { diff --git a/tests/ui/rust-2018/remove-extern-crate.rs b/tests/ui/rust-2018/remove-extern-crate.rs index 88ef858da147f..ce194644f7ef5 100644 --- a/tests/ui/rust-2018/remove-extern-crate.rs +++ b/tests/ui/rust-2018/remove-extern-crate.rs @@ -28,7 +28,7 @@ fn main() { with_visibility::foo(); remove_extern_crate::foo!(); bar!(); - alloc::vec![5]; + let _ = alloc::vec![5]; } mod another {