-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible false-negative with tail-expr-drop-order
#132861
Comments
fltk@1.4.35 exhibits similar behavior. This function: pub fn event_dx() -> MouseWheel {
match 0.cmp(unsafe { &fl::Fl_event_dx() }) {
cmp::Ordering::Greater => MouseWheel::Right,
cmp::Ordering::Equal => MouseWheel::None,
cmp::Ordering::Less => MouseWheel::Left,
}
} does not generate any warnings. However, after migrating there is an error:
|
I agree the explanation is rather weak without a focus on the edition change. Technically I am looking into improving the diagnostic here. @rustbot claim |
Another example is gix@0.67.0: pub fn is_active(&self) -> Result<bool, is_active::Error> {
let (mut platform, mut attributes) = self.state.active_state_mut()?;
let is_active = platform.is_active(&self.state.repo.config.resolved, self.name.as_ref(), {
&mut |relative_path, case, is_dir, out| {
attributes
.set_case(case)
.at_entry(relative_path, Some(is_dir_to_mode(is_dir)), &self.state.repo.objects)
.map_or(false, |platform| platform.matching_attributes(out))
}
})?;
Ok(is_active)
} doesn't generate warnings, but fails in 2024:
|
This example from the RFC is another example: #![warn(rust_2024_compatibility)]
fn main() {
let zero = { String::new().as_str() }.len();
} |
@dingxiangfei2009 One thing I wanted to mention is that the use of MIR (here) for generating the lint is incompatible with the way For example: #![deny(tail_expr_drop_order)]
struct PrintOnDrop(&'static str);
impl Drop for PrintOnDrop {
fn drop(&mut self) {
println!("{}", self.0);
}
}
impl PrintOnDrop {
fn get(&self) -> Option<u8> {
None
}
}
fn foo() -> Option<u8> {
let x = PrintOnDrop("x");
PrintOnDrop("temp").get()
} This does not fire the lint with |
The reason why this lint doesn't fire is because the current logic explicitly ignores things with "insignificant dtors". That is, This is because originally this lint was intended to lint in cases where we were shortening the lifetime of temporaries such as mutex guards, which would silently fail and possibly cause things like races or UB. We probably should think if there's a way to detect when we're leaking references to things even if they have insignificant dtors, since that results in the class of borrowck errors you see in that example. That will likely require a significant reworking of the lint reporting code, though :/ |
I still have a draft to detect the false positive cases, in other words to detect the potential borrowck error in the new edition. Let me get it posted in a few hours. |
Also for the record, #134493 should fix the |
…<try> Always run `tail_expr_drop_order` lint in promoted MIR query Rather than running the lint at the beginning of `mir_drops_elaborated_and_const_checked`, run it at the end of `mir_promoted`. This should ensure that the lint gets picked up when running `cargo fix`, which runs with `--emit metadata` and therefore doesn't actually query `mir_drops_elaborated_and_const_checked`. We could probably push this down into `mir_built` too? but I don't really see a good reason to do so. rust-lang#132861 (comment) cc `@ehuss`
…<try> Always run `tail_expr_drop_order` lint in promoted MIR query Rather than running the lint at the beginning of `mir_drops_elaborated_and_const_checked`, run it at the end of `mir_promoted`. This should ensure that the lint gets picked up when running `cargo fix`, which runs with `--emit metadata` and therefore doesn't actually query `mir_drops_elaborated_and_const_checked`. We could probably push this down into `mir_built` too? but I don't really see a good reason to do so. rust-lang#132861 (comment) cc `@ehuss`
…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.
…oli-obk Always run `tail_expr_drop_order` lint in promoted MIR query Rather than running the lint at the beginning of `mir_drops_elaborated_and_const_checked`, run it at the end of `mir_promoted`. This should ensure that the lint gets picked up when running `cargo fix`, which runs with `--emit metadata` and therefore doesn't actually query `mir_drops_elaborated_and_const_checked`. We could probably push this down into `mir_built` too? but I don't really see a good reason to do so. rust-lang#132861 (comment) cc `@ehuss`
…oli-obk Always run `tail_expr_drop_order` lint in promoted MIR query Rather than running the lint at the beginning of `mir_drops_elaborated_and_const_checked`, run it at the end of `mir_promoted`. This should ensure that the lint gets picked up when running `cargo fix`, which runs with `--emit metadata` and therefore doesn't actually query `mir_drops_elaborated_and_const_checked`. We could probably push this down into `mir_built` too? but I don't really see a good reason to do so. rust-lang#132861 (comment) cc `@ehuss`
…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.
…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.
…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.
There may be a false-negative with
tail-expr-drop-order
. Reproduction:curl -L https://crates.io/api/v1/crates/faer-core/0.17.1/download | tar -xz
faer-core-0.17.1
git init . && sed -i '1i cargo-features = ["edition2024"]' Cargo.toml && git add . && git commit -m test
cargo fix --edition
On current nightly (2024-11-09), this generates a large number of warnings about tail-expr-drop-order. However, none of them are in the offending function
swap_cols
. Additionally, after #131326, there are no warnings at all.After switching to 2024, this yields an error:
Unfortunately that crate is a maze of types and generics, so it is a bit difficult to minimize.
I'm just assuming this is a tail expression drop change due to the shape of the error.
It does not seem related to the macro, since manually expanding it also does not change anything.
I would expect tail-expr-drop-order to at least warn something here.
cc @dingxiangfei2009
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: