Skip to content

Commit 98d72cf

Browse files
Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obk
Extend `unused_must_use` to cover block exprs Given code like ```rust #[must_use] fn foo() -> i32 { 42 } fn warns() { { foo(); } } fn does_not_warn() { { foo() }; } fn main() { warns(); does_not_warn(); } ``` ### Before This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: 1 warning emitted ``` ### After This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: unused return value of `foo` that must be used --> test.rs:14:9 | 14 | foo() | ^^^^^ | help: use `let _ = ...` to ignore the resulting value | 14 | let _ = foo(); | +++++++ + warning: 2 warnings emitted ``` Fixes #104253.
2 parents f6accf8 + 8ef507a commit 98d72cf

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

core/src/primitive_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod prim_never {}
308308
///
309309
/// ```no_run
310310
/// // Undefined behaviour
311-
/// unsafe { char::from_u32_unchecked(0x110000) };
311+
/// let _ = unsafe { char::from_u32_unchecked(0x110000) };
312312
/// ```
313313
///
314314
/// USVs are also the exact set of values that may be encoded in UTF-8. Because

core/tests/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ fn nonnull_tagged_pointer_with_provenance() {
10011001
assert_eq!(p.tag(), 3);
10021002
assert_eq!(unsafe { *p.pointer().as_ptr() }, 10);
10031003

1004-
unsafe { Box::from_raw(p.pointer().as_ptr()) };
1004+
unsafe { drop(Box::from_raw(p.pointer().as_ptr())) };
10051005

10061006
/// A non-null pointer type which carries several bits of metadata and maintains provenance.
10071007
#[repr(transparent)]

std/src/primitive_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod prim_never {}
308308
///
309309
/// ```no_run
310310
/// // Undefined behaviour
311-
/// unsafe { char::from_u32_unchecked(0x110000) };
311+
/// let _ = unsafe { char::from_u32_unchecked(0x110000) };
312312
/// ```
313313
///
314314
/// USVs are also the exact set of values that may be encoded in UTF-8. Because

0 commit comments

Comments
 (0)