2023-01-24 02:06:35 -06:00
|
|
|
//@ edition: 2024
|
|
|
|
//@ compile-flags: -Z validate-mir -Zunstable-options
|
|
|
|
|
|
|
|
#![deny(if_let_rescope)]
|
|
|
|
|
|
|
|
struct Droppy;
|
|
|
|
impl Drop for Droppy {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("dropped");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Droppy {
|
|
|
|
fn get_ref(&self) -> Option<&u8> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_something<T>(_: &T) {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 });
|
|
|
|
//~^ ERROR: temporary value dropped while borrowed
|
2024-09-10 15:07:13 -05:00
|
|
|
do_something(if let Some(value) = Droppy.get_ref() {
|
|
|
|
//~^ ERROR: temporary value dropped while borrowed
|
|
|
|
value
|
|
|
|
} else if let Some(value) = Droppy.get_ref() {
|
|
|
|
//~^ ERROR: temporary value dropped while borrowed
|
|
|
|
value
|
|
|
|
} else {
|
|
|
|
&0
|
|
|
|
});
|
2023-01-24 02:06:35 -06:00
|
|
|
}
|