Let chains should still drop temporaries

by the end of the condition's execution
This commit is contained in:
Nathan Whitaker 2022-10-12 15:29:08 -07:00
parent 0938e1680d
commit ad8b242724
2 changed files with 97 additions and 11 deletions

View file

@ -1,4 +1,5 @@
// run-pass
#![feature(let_chains)]
use std::cell::RefCell;
use std::convert::TryInto;
@ -116,6 +117,58 @@ impl DropOrderCollector {
}
}
fn let_chain(&self) {
// take the "then" branch
if self.option_loud_drop(2).is_some() // 2
&& self.option_loud_drop(1).is_some() // 1
&& let Some(_d) = self.option_loud_drop(4) { // 4
self.print(3); // 3
}
// take the "else" branch
if self.option_loud_drop(6).is_some() // 2
&& self.option_loud_drop(5).is_some() // 1
&& let None = self.option_loud_drop(7) { // 3
unreachable!();
} else {
self.print(8); // 4
}
// let exprs interspersed
if self.option_loud_drop(9).is_some() // 1
&& let Some(_d) = self.option_loud_drop(13) // 5
&& self.option_loud_drop(10).is_some() // 2
&& let Some(_e) = self.option_loud_drop(12) { // 4
self.print(11); // 3
}
// let exprs first
if let Some(_d) = self.option_loud_drop(18) // 5
&& let Some(_e) = self.option_loud_drop(17) // 4
&& self.option_loud_drop(14).is_some() // 1
&& self.option_loud_drop(15).is_some() { // 2
self.print(16); // 3
}
// let exprs last
if self.option_loud_drop(20).is_some() // 2
&& self.option_loud_drop(19).is_some() // 1
&& let Some(_d) = self.option_loud_drop(23) // 5
&& let Some(_e) = self.option_loud_drop(22) { // 4
self.print(21); // 3
}
}
fn while_(&self) {
let mut v = self.option_loud_drop(4);
while let Some(_d) = v
&& self.option_loud_drop(1).is_some()
&& self.option_loud_drop(2).is_some() {
self.print(3);
v = None;
}
}
fn assert_sorted(self) {
assert!(
self.0
@ -142,4 +195,14 @@ fn main() {
let collector = DropOrderCollector::default();
collector.match_();
collector.assert_sorted();
println!("-- let chain --");
let collector = DropOrderCollector::default();
collector.let_chain();
collector.assert_sorted();
println!("-- while --");
let collector = DropOrderCollector::default();
collector.while_();
collector.assert_sorted();
}