-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix false positive in missing_const_for_fn #4981
Conversation
This fixes some additional false positives with functions or methods that return types which implement drop. Since `drop` can't be const-evaluated, these cases can't be made const. Fixes rust-lang#4979
b3dd25d
to
747e3b6
Compare
The issue at hand talked about a second level Drop implementation. So fn take(self) -> NotDrop {
// ^^^^ ^^^^^^^ Doesn't implement Drop
self.field
}
struct NotDrop {
field: CustomDrop,
} can you add a test for this case? |
@flip1995 Hm, if struct CustomDrop {
field: i32,
}
impl Drop for CustomDrop {
fn drop(&mut self) {}
}
struct NotDrop {
field: CustomDrop,
}
impl NotDrop {
// This is allowed to be const because the field values are never used.
fn take(self) -> NotDrop {
self
}
} Is that what you meant? |
Not quiet. We have to go even further beyond: Playground struct CustomDrop;
impl Drop for CustomDrop {
fn drop(&mut self) {}
}
struct NotDrop {
field: CustomDrop,
}
struct SmallTurtle { // Another layer
field: NotDrop,
}
impl SmallTurtle {
fn take(self) -> NotDrop {
self.field
}
} That's the structure of the issue: Struct -> String -> Vec (has drop impl). I guess another test case would be to just have a struct with a |
@flip1995 Yes that doesn't get detected as you expected. Hm. |
You may be able to just use the iterator returned by |
☔ The latest upstream changes (presumably #5040) made this pull request unmergeable. Please resolve the merge conflicts. |
@oli-obk Unfortunately |
I'm currently trying to use |
Going to close this for now and revisit it at a later date 📆 |
This fixes some additional false positives with functions or methods
that return types which implement drop. Since
drop
can't beconst-evaluated, these cases can't be made const.
changelog: Fix false positive in [
missing_const_for_fn
]Fixes #4979