Skip to content

Commit 4f260f0

Browse files
Auto merge of #148577 - WaffleLapkin:unmustuse_in_always_ok, r=<try>
[DO NOT MERGE] crater proposed changes in unused must use lint
2 parents 642c19b + 310b963 commit 4f260f0

File tree

23 files changed

+466
-338
lines changed

23 files changed

+466
-338
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 412 additions & 314 deletions
Large diffs are not rendered by default.

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#![warn(rustdoc::unescaped_backticks)]
8383
#![deny(ffi_unwind_calls)]
8484
#![warn(unreachable_pub)]
85+
#![expect(unmustuse_in_always_ok)]
8586
//
8687
// Library features:
8788
// tidy-alphabetical-start

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
#![allow(internal_features)]
9090
#![deny(ffi_unwind_calls)]
9191
#![warn(unreachable_pub)]
92+
#![expect(unmustuse_in_always_ok)]
9293
// Do not check link redundancy on bootstrapping phase
9394
#![allow(rustdoc::redundant_explicit_links)]
9495
#![warn(rustdoc::unescaped_backticks)]

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
#![deny(unsafe_op_in_unsafe_fn)]
250250
#![allow(rustdoc::redundant_explicit_links)]
251251
#![warn(rustdoc::unescaped_backticks)]
252+
#![expect(unmustuse_in_always_ok)]
252253
// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
253254
#![deny(ffi_unwind_calls)]
254255
// std may use features in a platform-specific way

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,10 @@ impl Builder<'_> {
11691169
// Lints just for `compiler/` crates.
11701170
if mode == Mode::Rustc {
11711171
lint_flags.push("-Wrustc::internal");
1172+
if compiler.stage > 0 {
1173+
lint_flags.push("-Aunmustuse_in_always_ok");
1174+
lint_flags.push("-Amustuse_in_always_ok");
1175+
}
11721176
lint_flags.push("-Drustc::symbol_intern_string_literal");
11731177
// FIXME(edition_2024): Change this to `-Wrust_2024_idioms` when all
11741178
// of the individual lints are satisfied.

tests/ui/binding/empty-types-in-patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#![allow(unreachable_patterns)]
77
#![allow(unreachable_code)]
8-
#![allow(unused_variables)]
8+
#![expect(unused_variables, unmustuse_in_always_ok)]
99

1010
#[allow(dead_code)]
1111
fn foo(z: !) {

tests/ui/lint/unused/must_use-result-unit-uninhabited.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
#![deny(unused_must_use)]
55
#![feature(never_type)]
6-
6+
#![expect(unmustuse_in_always_ok, mustuse_in_always_ok)]
77
use core::ops::{ControlFlow, ControlFlow::Continue};
88
use dep::{MyUninhabited, MyUninhabitedNonexhaustive};
99

10+
#[must_use]
11+
struct MustUse;
12+
13+
struct Struct;
14+
1015
fn result_unit_unit() -> Result<(), ()> {
1116
Ok(())
1217
}
@@ -19,6 +24,14 @@ fn result_unit_never() -> Result<(), !> {
1924
Ok(())
2025
}
2126

27+
fn result_struct_never() -> Result<Struct, !> {
28+
Ok(Struct)
29+
}
30+
31+
fn result_must_use_never() -> Result<MustUse, !> {
32+
Ok(MustUse)
33+
}
34+
2235
fn result_unit_myuninhabited() -> Result<(), MyUninhabited> {
2336
Ok(())
2437
}
@@ -80,6 +93,8 @@ fn main() {
8093
result_unit_unit(); //~ ERROR: unused `Result` that must be used
8194
result_unit_infallible();
8295
result_unit_never();
96+
result_must_use_never(); //~ ERROR: unused `MustUse` in a `Result` with an uninhabited error that must be used
97+
result_struct_never();
8398
result_unit_myuninhabited();
8499
result_unit_myuninhabited_nonexhaustive(); //~ ERROR: unused `Result` that must be used
85100
result_unit_assoctype(S1);

tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unused `Result` that must be used
2-
--> $DIR/must_use-result-unit-uninhabited.rs:80:5
2+
--> $DIR/must_use-result-unit-uninhabited.rs:93:5
33
|
44
LL | result_unit_unit();
55
| ^^^^^^^^^^^^^^^^^^
@@ -15,8 +15,14 @@ help: use `let _ = ...` to ignore the resulting value
1515
LL | let _ = result_unit_unit();
1616
| +++++++
1717

18+
error: unused `MustUse` in a `Result` with an uninhabited error that must be used
19+
--> $DIR/must_use-result-unit-uninhabited.rs:96:5
20+
|
21+
LL | result_must_use_never();
22+
| ^^^^^^^^^^^^^^^^^^^^^^^
23+
1824
error: unused `Result` that must be used
19-
--> $DIR/must_use-result-unit-uninhabited.rs:84:5
25+
--> $DIR/must_use-result-unit-uninhabited.rs:99:5
2026
|
2127
LL | result_unit_myuninhabited_nonexhaustive();
2228
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -28,7 +34,7 @@ LL | let _ = result_unit_myuninhabited_nonexhaustive();
2834
| +++++++
2935

3036
error: unused `Result` that must be used
31-
--> $DIR/must_use-result-unit-uninhabited.rs:86:5
37+
--> $DIR/must_use-result-unit-uninhabited.rs:101:5
3238
|
3339
LL | result_unit_assoctype(S2);
3440
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +46,7 @@ LL | let _ = result_unit_assoctype(S2);
4046
| +++++++
4147

4248
error: unused `Result` that must be used
43-
--> $DIR/must_use-result-unit-uninhabited.rs:88:5
49+
--> $DIR/must_use-result-unit-uninhabited.rs:103:5
4450
|
4551
LL | S2.method_use_assoc_type();
4652
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -52,7 +58,7 @@ LL | let _ = S2.method_use_assoc_type();
5258
| +++++++
5359

5460
error: unused `ControlFlow` that must be used
55-
--> $DIR/must_use-result-unit-uninhabited.rs:90:5
61+
--> $DIR/must_use-result-unit-uninhabited.rs:105:5
5662
|
5763
LL | controlflow_unit();
5864
| ^^^^^^^^^^^^^^^^^^
@@ -63,7 +69,7 @@ LL | let _ = controlflow_unit();
6369
| +++++++
6470

6571
error: unused `Result` that must be used
66-
--> $DIR/must_use-result-unit-uninhabited.rs:99:9
72+
--> $DIR/must_use-result-unit-uninhabited.rs:114:9
6773
|
6874
LL | self.generate();
6975
| ^^^^^^^^^^^^^^^
@@ -74,5 +80,5 @@ help: use `let _ = ...` to ignore the resulting value
7480
LL | let _ = self.generate();
7581
| +++++++
7682

77-
error: aborting due to 6 previous errors
83+
error: aborting due to 7 previous errors
7884

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ edition: 2015
22
//@ check-pass
33
#![warn(redundant_imports)]
4-
4+
#![expect(unmustuse_in_always_ok)]
55

66
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
77
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ check-pass
22
//@ edition:2021
33
#![warn(redundant_imports)]
4-
4+
#![expect(unmustuse_in_always_ok)]
55
use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
66
use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly
77

0 commit comments

Comments
 (0)