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#137444 - compiler-errors:drop-lint, r=oli-obk Improve behavior of `IF_LET_RESCOPE` around temporaries and place expressions Heavily reworks the `IF_LET_RESCOPE` to be more sensitive around 1. temporaries that get consumed/terminated and therefore should not trigger the lint, and 2. borrows of place expressions, which are not temporary values. Fixes rust-lang#137411
- Loading branch information
Showing
5 changed files
with
146 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//@ edition: 2021 | ||
//@ check-pass | ||
|
||
#![deny(if_let_rescope)] | ||
|
||
struct Drop; | ||
impl std::ops::Drop for Drop { | ||
fn drop(&mut self) { | ||
println!("drop") | ||
} | ||
} | ||
|
||
impl Drop { | ||
fn as_ref(&self) -> Option<i32> { | ||
Some(1) | ||
} | ||
} | ||
|
||
fn consume(_: impl Sized) -> Option<i32> { Some(1) } | ||
|
||
fn main() { | ||
let drop = Drop; | ||
|
||
// Make sure we don't drop if we don't actually make a temporary. | ||
if let None = drop.as_ref() {} else {} | ||
|
||
// Make sure we don't lint if we consume the droppy value. | ||
if let None = consume(Drop) {} else {} | ||
|
||
// Make sure we don't lint on field exprs of place exprs. | ||
let tup_place = (Drop, ()); | ||
if let None = consume(tup_place.1) {} else {} | ||
} |
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