-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make closures and generators a must use types
Warn about unused expressions with closure or generator type. This follows existing precedence of must use annotations present on `FnOnce`, `FnMut`, `Fn` traits, which already indirectly apply to closures in some cases, e.g.,: ```rust fn f() -> impl FnOnce() { || {} } fn main() { // an existing warning: unused implementer of `std::ops::FnOnce` that must be used: f(); // a new warning: unused closure that must be used: || {}; } ```
- Loading branch information
Showing
36 changed files
with
355 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/issue-52398.rs:17:5 | ||
| | ||
LL | / move || { | ||
LL | | A.test(yield); | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: unused generator that must be used | ||
--> $DIR/issue-52398.rs:24:5 | ||
| | ||
LL | / static move || { | ||
LL | | yield *y.borrow(); | ||
LL | | return "Done"; | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 2 warnings emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/issue-57084.rs:22:5 | ||
| | ||
LL | / || { | ||
LL | | let _to_pin = with(move || println!("{:p}", data)); | ||
LL | | loop { | ||
LL | | yield | ||
LL | | } | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/match-bindings.rs:12:5 | ||
| | ||
LL | / || { | ||
LL | | loop { | ||
LL | | if let true = true { | ||
LL | | match Enum::A(String::new()) { | ||
... | | ||
LL | | } | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/reborrow-mut-upvar.rs:6:5 | ||
| | ||
LL | / || { | ||
LL | | { | ||
LL | | let _baz = &*bar; | ||
LL | | yield; | ||
... | | ||
LL | | *bar = 2; | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/ui/generator/too-live-local-in-immovable-gen.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/too-live-local-in-immovable-gen.rs:8:9 | ||
| | ||
LL | / static move || { | ||
LL | | // Tests that the generator transformation finds out that `a` is not live | ||
LL | | // during the yield expression. Type checking will also compute liveness | ||
LL | | // and it should also find out that `a` is not live. | ||
... | | ||
LL | | &a; | ||
LL | | }; | ||
| |__________^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/yield-in-args-rev.rs:13:5 | ||
| | ||
LL | / || { | ||
LL | | let b = true; | ||
LL | | foo(yield, &b); | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/yield-in-box.rs:9:5 | ||
| | ||
LL | / || { | ||
LL | | let y = 2u32; | ||
LL | | { | ||
LL | | let _t = box (&x, yield 0, &y); | ||
... | | ||
LL | | } | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/yield-in-initializer.rs:6:5 | ||
| | ||
LL | / static || { | ||
LL | | loop { | ||
LL | | // Test that `opt` is not live across the yield, even when borrowed in a loop | ||
LL | | // See https://github.com/rust-lang/rust/issues/52792 | ||
... | | ||
LL | | } | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
warning: unused generator that must be used | ||
--> $DIR/yield-subtype.rs:11:5 | ||
| | ||
LL | / || { | ||
LL | | yield a; | ||
LL | | yield b; | ||
LL | | }; | ||
| |______^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: generators are lazy and do nothing unless resumed | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: unused closure that must be used | ||
--> $DIR/issue-1460.rs:6:5 | ||
| | ||
LL | {|i: u32| if 1 == i { }}; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: closures are lazy and do nothing unless called | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: unused closure that must be used | ||
--> $DIR/issue-16256.rs:6:5 | ||
| | ||
LL | |c: u8| buf.push(c); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_must_use)]` on by default | ||
= note: closures are lazy and do nothing unless called | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
pub fn mutable_upvar() { | ||
let x = &mut 0; | ||
//~^ ERROR | ||
move || { | ||
let _ = move || { | ||
*x = 1; | ||
}; | ||
} | ||
|
Oops, something went wrong.