-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 2 variable binding issues in let_underscore
- Loading branch information
1 parent
f688dd6
commit 515bd25
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>>, | ||
} |
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() {} |
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 | ||
|