forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#119704 - chenyukang:yukang-fix-let_underscore, r=Nilstrieb Fix two variable binding issues in lint let_underscore Fixes rust-lang#119696 Fixes rust-lang#119697
- Loading branch information
Showing
7 changed files
with
110 additions
and
2 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
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,21 @@ | ||
// edition: 2021 | ||
|
||
#![deny(let_underscore_drop)] | ||
fn main() { | ||
let _ = foo(); //~ ERROR non-binding let on a type that implements `Drop` | ||
} | ||
|
||
async fn from_config(_: Config) {} | ||
|
||
async fn foo() { | ||
from_config(Config { | ||
nickname: None, | ||
..Default::default() | ||
}) | ||
.await; | ||
} | ||
|
||
#[derive(Default)] | ||
struct Config { | ||
nickname: Option<Box<u8>>, | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/ui/lint/let_underscore/issue-119696-err-on-fn.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,22 @@ | ||
error: non-binding let on a type that implements `Drop` | ||
--> $DIR/issue-119696-err-on-fn.rs:5:5 | ||
| | ||
LL | let _ = foo(); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-119696-err-on-fn.rs:3:9 | ||
| | ||
LL | #![deny(let_underscore_drop)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
help: consider binding to an unused variable to avoid immediately dropping the value | ||
| | ||
LL | let _unused = foo(); | ||
| ~~~~~~~ | ||
help: consider immediately dropping the value | ||
| | ||
LL | drop(foo()); | ||
| ~~~~~ + | ||
|
||
error: aborting due to 1 previous error | ||
|
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,21 @@ | ||
#![deny(let_underscore_drop)] | ||
#![feature(type_alias_impl_trait)] | ||
|
||
pub struct Foo { | ||
/// This type must have nontrivial drop glue | ||
field: String, | ||
} | ||
|
||
pub type Tait = impl Sized; | ||
|
||
pub fn ice_cold(beverage: Tait) { | ||
// Must destructure at least one field of `Foo` | ||
let Foo { field } = beverage; | ||
// boom | ||
_ = field; //~ ERROR non-binding let on a type that implements `Drop` | ||
|
||
let _ = field; //~ ERROR non-binding let on a type that implements `Drop` | ||
} | ||
|
||
|
||
pub fn main() {} |
37 changes: 37 additions & 0 deletions
37
tests/ui/lint/let_underscore/issue-119697-extra-let.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,37 @@ | ||
error: non-binding let on a type that implements `Drop` | ||
--> $DIR/issue-119697-extra-let.rs:15:5 | ||
| | ||
LL | _ = field; | ||
| ^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-119697-extra-let.rs:1:9 | ||
| | ||
LL | #![deny(let_underscore_drop)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
help: consider binding to an unused variable to avoid immediately dropping the value | ||
| | ||
LL | let _unused = field; | ||
| ~~~~~~~~~~~ | ||
help: consider immediately dropping the value | ||
| | ||
LL | drop(field); | ||
| ~~~~~ + | ||
|
||
error: non-binding let on a type that implements `Drop` | ||
--> $DIR/issue-119697-extra-let.rs:17:5 | ||
| | ||
LL | let _ = field; | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
help: consider binding to an unused variable to avoid immediately dropping the value | ||
| | ||
LL | let _unused = field; | ||
| ~~~~~~~ | ||
help: consider immediately dropping the value | ||
| | ||
LL | drop(field); | ||
| ~~~~~ + | ||
|
||
error: aborting due to 2 previous errors | ||
|