-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
unused_must_use
is silenced when returning a #[must_use]
value from an unsafe block and not using it
#93925
Comments
#[must_use]
on a foreign fn does nothing#[must_use]
is silenced when returning from an unsafe block
Note that adding a semicolon after the expressions within the unsafe blocks will cause - unsafe { foreign_foo() };
+ unsafe { foreign_foo(); };
This is documented in the Rust Reference, but this case may still be an issue since one might not think of |
#[must_use]
is silenced when returning from an unsafe block#[must_use]
is silenced when returning a #[must_use]
value from an unsafe block and not using it
#[must_use]
is silenced when returning a #[must_use]
value from an unsafe block and not using itunused_must_use
is silenced when returning a #[must_use]
value from an unsafe block and not using it
minimal version with no extern or intrinsics: #[must_use]
unsafe fn foo() -> i64 {
4
}
fn main() {
unsafe { foo() };
} |
Oh the #[must_use]
fn foo() -> i64 {
4
}
fn main() {
{ foo() };
} |
Note that
At the time I opened this issue, I thought that applying this lint to let x = unsafe { get_x_unchecked() }; However, this lint only trips for unsafe fn x() -> i32 {
4
}
fn main() {
unsafe {
x()
}
// avoid interpreting the unsafe block as `main`'s return expression
()
}
Empirically, most |
Found while working on a fix for #93906.
I tried this code (playground):
I expected to see this happen:
Both lines in
main
should tripunused_must_use
. Note thatcore::intrinsics::arith_offset
is marked as#[must_use]
:rust/library/core/src/intrinsics.rs
Lines 1187 to 1189 in e789f3a
Instead, this happened:
nothing
Meta
rustc version:
1.60.0-nightly (2022-02-10 e646f3d2a95419523107)
@rustbot modify labels +A-ffi
The text was updated successfully, but these errors were encountered: