Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark some macros with must_use hint #127509

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't do anything, same for all other builtin macros. you'd need to modify the compiler

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid this undergoing is way above my capabilities

};
($fmt:expr, $($args:tt)*) => {
$crate::hint::must_use({ /* compiler built-in */ })
};
}

/// Same as [`format_args`], but can be used in some const contexts.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -1222,7 +1236,7 @@ pub(crate) mod builtin {
#[macro_export]
macro_rules! line {
() => {
/* compiler built-in */
$crate::hint::must_use({ /* compiler built-in */ })
};
}

Expand Down Expand Up @@ -1261,7 +1275,7 @@ pub(crate) mod builtin {
#[macro_export]
macro_rules! column {
() => {
/* compiler built-in */
$crate::hint::must_use(/* compiler built-in */)
};
}

Expand All @@ -1286,7 +1300,7 @@ pub(crate) mod builtin {
#[macro_export]
macro_rules! file {
() => {
/* compiler built-in */
$crate::hint::must_use(/* compiler built-in */)
};
}

Expand All @@ -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 */)
};
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 */)
};
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/box/unit/unique-create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub fn main() {
}

fn vec() {
vec![0];
let _ = vec![0];
}
2 changes: 1 addition & 1 deletion tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/rust-2018/remove-extern-crate.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() {
with_visibility::foo();
remove_extern_crate::foo!();
bar!();
alloc::vec![5];
let _ = alloc::vec![5];
}

mod another {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/rust-2018/remove-extern-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() {
with_visibility::foo();
remove_extern_crate::foo!();
bar!();
alloc::vec![5];
let _ = alloc::vec![5];
}

mod another {
Expand Down
Loading