Consider lvalues of field and index as possibly temporary places
This commit is contained in:
parent
2797936f6d
commit
bad8e98c7d
5 changed files with 46 additions and 1 deletions
|
@ -436,6 +436,14 @@ impl<'tcx> Visitor<'tcx> for FindSignificantDropper<'_, 'tcx> {
|
||||||
self.check_promoted_temp_with_drop(expr)?;
|
self.check_promoted_temp_with_drop(expr)?;
|
||||||
intravisit::walk_expr(self, expr)
|
intravisit::walk_expr(self, expr)
|
||||||
}
|
}
|
||||||
|
// `(Drop, ()).1` introduces a temporary and then moves out of
|
||||||
|
// part of it, therefore we should check it for temporaries.
|
||||||
|
// FIXME: This may have false positives if we move the part
|
||||||
|
// that actually has drop, but oh well.
|
||||||
|
hir::ExprKind::Index(expr, _, _) | hir::ExprKind::Field(expr, _) => {
|
||||||
|
self.check_promoted_temp_with_drop(expr)?;
|
||||||
|
intravisit::walk_expr(self, expr)
|
||||||
|
}
|
||||||
// If always introduces a temporary terminating scope for its cond and arms,
|
// If always introduces a temporary terminating scope for its cond and arms,
|
||||||
// so don't visit them.
|
// so don't visit them.
|
||||||
hir::ExprKind::If(..) => ControlFlow::Continue(()),
|
hir::ExprKind::If(..) => ControlFlow::Continue(()),
|
||||||
|
|
|
@ -26,4 +26,8 @@ fn main() {
|
||||||
|
|
||||||
// Make sure we don't lint if we consume the droppy value.
|
// Make sure we don't lint if we consume the droppy value.
|
||||||
if let None = consume(Drop) {} else {}
|
if let None = consume(Drop) {} else {}
|
||||||
|
|
||||||
|
// Make sure we don't lint on field exprs of place exprs.
|
||||||
|
let tup_place = (Drop, ());
|
||||||
|
if let None = consume(tup_place.1) {} else {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,12 @@ fn main() {
|
||||||
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match Some((droppy(), ()).1) { Some(_value) => {} _ => {}}
|
||||||
|
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
|
||||||
|
//~| WARN: this changes meaning in Rust 2024
|
||||||
|
//~| HELP: the value is now dropped here in Edition 2024
|
||||||
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
||||||
|
|
||||||
// We want to keep the `if let`s below as direct descendents of match arms,
|
// We want to keep the `if let`s below as direct descendents of match arms,
|
||||||
// so the formatting is suppressed.
|
// so the formatting is suppressed.
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
|
@ -94,6 +94,12 @@ fn main() {
|
||||||
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(_value) = Some((droppy(), ()).1) {} else {}
|
||||||
|
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
|
||||||
|
//~| WARN: this changes meaning in Rust 2024
|
||||||
|
//~| HELP: the value is now dropped here in Edition 2024
|
||||||
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
||||||
|
|
||||||
// We want to keep the `if let`s below as direct descendents of match arms,
|
// We want to keep the `if let`s below as direct descendents of match arms,
|
||||||
// so the formatting is suppressed.
|
// so the formatting is suppressed.
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
|
@ -175,5 +175,26 @@ LL - while (if let Some(_value) = droppy().get() { false } else { true }) {
|
||||||
LL + while (match droppy().get() { Some(_value) => { false } _ => { true }}) {
|
LL + while (match droppy().get() { Some(_value) => { false } _ => { true }}) {
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 7 previous errors
|
error: `if let` assigns a shorter lifetime since Edition 2024
|
||||||
|
--> $DIR/lint-if-let-rescope.rs:97:8
|
||||||
|
|
|
||||||
|
LL | if let Some(_value) = Some((droppy(), ()).1) {} else {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^--------------^^^
|
||||||
|
| |
|
||||||
|
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
|
||||||
|
|
|
||||||
|
= warning: this changes meaning in Rust 2024
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
|
||||||
|
help: the value is now dropped here in Edition 2024
|
||||||
|
--> $DIR/lint-if-let-rescope.rs:97:51
|
||||||
|
|
|
||||||
|
LL | if let Some(_value) = Some((droppy(), ()).1) {} else {}
|
||||||
|
| ^
|
||||||
|
help: a `match` with a single arm can preserve the drop order up to Edition 2021
|
||||||
|
|
|
||||||
|
LL - if let Some(_value) = Some((droppy(), ()).1) {} else {}
|
||||||
|
LL + match Some((droppy(), ()).1) { Some(_value) => {} _ => {}}
|
||||||
|
|
|
||||||
|
|
||||||
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue