forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#134523 - dingxiangfei2009:issue-130836-attemp…
…t-2, r=<try> Run borrowck tests on BIDs and emit tail-expr-drop-order lints for violations Fix rust-lang#132861 r? `@nikomatsakis` cc `@compiler-errors` This patch enlarges the scope where the `tail-expr-drop-order` lint applies, so that all locals involved in tail expressions are inspected. This is necessary to run borrow-checking to capture the cases where it used to compile under Edition 2021 but is not going to pass borrow-checking from Edition 2024 onwards. The way it works is to inspect each BID against the set of borrows that are still live. If the local involved in BID has a borrow index which happens to be live as well at the location of this BID statement, in the future this will be a borrow-checking violation. The lint will fire in this case.
- Loading branch information
Showing
6 changed files
with
155 additions
and
19 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
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 @@ | ||
// Edition 2024 lint for change in drop order at tail expression | ||
// This lint is to capture potential borrow-checking errors | ||
// due to implementation of RFC 3606 <https://github.com/rust-lang/rfcs/pull/3606> | ||
//@ edition: 2021 | ||
|
||
#![deny(tail_expr_drop_order)] //~ NOTE: the lint level is defined here | ||
|
||
fn should_lint_with_potential_borrowck_err() { | ||
let _ = { String::new().as_str() }.len(); | ||
//~^ ERROR: a temporary value will be dropped here | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: consider using a `let` binding | ||
//~| NOTE: for more information, see | ||
} | ||
|
||
fn should_lint_with_unsafe_block() { | ||
fn f(_: usize) {} | ||
f(unsafe { String::new().as_str() }.len()); | ||
//~^ ERROR: a temporary value will be dropped here | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: consider using a `let` binding | ||
//~| NOTE: for more information, see | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn should_lint_with_big_block() { | ||
fn f<T>(_: T) {} | ||
f({ | ||
&mut || 0 | ||
//~^ ERROR: a temporary value will be dropped here | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: consider using a `let` binding | ||
//~| NOTE: for more information, see | ||
}) | ||
} | ||
|
||
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,40 @@ | ||
error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error | ||
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:9:36 | ||
| | ||
LL | let _ = { String::new().as_str() }.len(); | ||
| ------------- ^ | ||
| | | ||
| consider using a `let` binding to create a longer lived value; or replacing the `{ .. }` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe { .. }` | ||
| | ||
= warning: this changes meaning in Rust 2024 | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> | ||
note: the lint level is defined here | ||
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:6:9 | ||
| | ||
LL | #![deny(tail_expr_drop_order)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error | ||
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:18:37 | ||
| | ||
LL | f(unsafe { String::new().as_str() }.len()); | ||
| ------------- ^ | ||
| | | ||
| consider using a `let` binding to create a longer lived value; or replacing the `{ .. }` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe { .. }` | ||
| | ||
= warning: this changes meaning in Rust 2024 | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> | ||
|
||
error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error | ||
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:29:17 | ||
| | ||
LL | &mut || 0 | ||
| --------^ | ||
| | | ||
| consider using a `let` binding to create a longer lived value; or replacing the `{ .. }` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe { .. }` | ||
| | ||
= warning: this changes meaning in Rust 2024 | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> | ||
|
||
error: aborting due to 3 previous errors | ||
|