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=nikomatsakis 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
17 changed files
with
310 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -992,6 +992,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
kind, | ||
}; | ||
} | ||
|
||
normal_ret | ||
} | ||
|
||
|
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
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,51 @@ | ||
// 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: relative drop order changing | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: this temporary value will be dropped at the end of the block | ||
//~| borrow later used by call | ||
//~| NOTE: for more information, see | ||
} | ||
|
||
fn should_lint_with_unsafe_block() { | ||
fn f(_: usize) {} | ||
f(unsafe { String::new().as_str() }.len()); | ||
//~^ ERROR: relative drop order changing | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: this temporary value will be dropped at the end of the block | ||
//~| borrow later used by call | ||
//~| NOTE: for more information, see | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn should_lint_with_big_block() { | ||
fn f<T>(_: T) {} | ||
f({ | ||
&mut || 0 | ||
//~^ ERROR: relative drop order changing | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: this temporary value will be dropped at the end of the block | ||
//~| borrow later used here | ||
//~| NOTE: for more information, see | ||
}) | ||
} | ||
|
||
fn another_temp_that_is_copy_in_arg() { | ||
fn f() {} | ||
fn g(_: &()) {} | ||
g({ &f() }); | ||
//~^ ERROR: relative drop order changing | ||
//~| WARN: this changes meaning in Rust 2024 | ||
//~| NOTE: this temporary value will be dropped at the end of the block | ||
//~| borrow later used by call | ||
//~| NOTE: for more information, see | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.