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.
Auto merge of rust-lang#129466 - dingxiangfei2009:let-chain-lint-crat…
…er-run, r=<try> [CRATER RUN DO NOT MERGE] Let chain lint crater run Tracked by rust-lang#124085 Related to rust-lang#107251 cc `@jieyouxu` for review context cc `@traviscross` for edition tracking There is one unresolved issue that `cargo fix --edition` does not emit `if-let-rescope` lint. Details in rust-lang/cargo#14447. Note that this patch is assuming that the feature gate `if_let_rescope` is always on just for this crater run.
- Loading branch information
Showing
8 changed files
with
83 additions
and
6 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
Submodule cargo
updated
7 files
+282 −221 | Cargo.lock | |
+52 −6 | src/bin/cargo/commands/check.rs | |
+45 −138 | src/cargo/core/compiler/fingerprint/mod.rs | |
+2 −4 | src/cargo/ops/vendor.rs | |
+9 −9 | src/cargo/util/toml/mod.rs | |
+0 −4 | tests/testsuite/shell_completions.rs | |
+0 −61 | tests/testsuite/vendor.rs |
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,26 @@ | ||
//@ edition:2024 | ||
//@ compile-flags: -Z validate-mir -Zunstable-options | ||
//@ run-rustfix | ||
|
||
#![deny(if_let_rescope)] | ||
#![feature(if_let_rescope)] | ||
|
||
struct Droppy; | ||
impl Drop for Droppy { | ||
fn drop(&mut self) { | ||
println!("dropped"); | ||
} | ||
} | ||
impl Droppy { | ||
fn get_ref(&self) -> Option<&u8> { | ||
None | ||
} | ||
} | ||
|
||
fn do_something<T>(_: &T) {} | ||
|
||
fn main() { | ||
let binding = Droppy; | ||
do_something(match binding.get_ref() { Some(value) => { value } _ => { &0 }}); | ||
//~^ ERROR: temporary value dropped while borrowed | ||
} |
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,25 @@ | ||
//@ edition:2024 | ||
//@ compile-flags: -Z validate-mir -Zunstable-options | ||
//@ run-rustfix | ||
|
||
#![deny(if_let_rescope)] | ||
#![feature(if_let_rescope)] | ||
|
||
struct Droppy; | ||
impl Drop for Droppy { | ||
fn drop(&mut self) { | ||
println!("dropped"); | ||
} | ||
} | ||
impl Droppy { | ||
fn get_ref(&self) -> Option<&u8> { | ||
None | ||
} | ||
} | ||
|
||
fn do_something<T>(_: &T) {} | ||
|
||
fn main() { | ||
do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 }); | ||
//~^ ERROR: temporary value dropped while borrowed | ||
} |
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,26 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/if-let-rescope-suggestions.rs:23:39 | ||
| | ||
LL | do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 }); | ||
| ^^^^^^ - temporary value is freed at the end of this statement | ||
| | | ||
| creates a temporary value which is freed while still in use | ||
| | ||
note: lifetime for temporaries generated in `if let`s have been shorted in Edition 2024 | ||
--> $DIR/if-let-rescope-suggestions.rs:23:65 | ||
| | ||
LL | do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 }); | ||
| ^ | ||
help: consider using a `let` binding to create a longer lived value | ||
| | ||
LL ~ let binding = Droppy; | ||
LL ~ do_something(if let Some(value) = binding.get_ref() { value } else { &0 }); | ||
| | ||
help: consider rewriting the `if` into `match` which preserves the extended lifetime | ||
| | ||
LL | do_something(match Droppy.get_ref() { Some(value) => { value } _ => { &0 }}); | ||
| ~~~~~ ++++++++++++++++ ~~~~ + | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0716`. |