diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2024-01-03 16:32:13 +0000 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2024-01-05 10:56:59 +0000 |
| commit | 1a267e3f40c4c6e32482a7dd98c512f4664a329e (patch) | |
| tree | a435dca89a742799998ceb8661bbead879bcdbc2 /tests | |
| parent | a549711f6e3dc804783652810a40653719dd0af7 (diff) | |
| download | rust-1a267e3f40c4c6e32482a7dd98c512f4664a329e.tar.gz rust-1a267e3f40c4c6e32482a7dd98c512f4664a329e.zip | |
Restore if let guard temporary scoping difference
Match guards with an if let guard or an if let chain guard should have a temporary scope of the whole arm. This is to allow ref bindings to temporaries to borrow check.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/rfcs/rfc-2294-if-let-guard/drop-scope.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/drop-scope.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/drop-scope.rs new file mode 100644 index 00000000000..9e6e23e8882 --- /dev/null +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/drop-scope.rs @@ -0,0 +1,72 @@ +// Ensure that temporaries in if-let guards live for the arm +// regression test for #118593 + +// check-pass + +#![feature(if_let_guard)] +#![feature(let_chains)] + +fn get_temp() -> Option<String> { + None +} + +fn let_guard(num: u8) { + match num { + 1 | 2 if let Some(ref a) = get_temp() => { + let _b = a; + } + _ => {} + } + match num { + 3 | 4 if let Some(ref mut c) = get_temp() => { + let _d = c; + } + _ => {} + } +} + +fn let_let_chain_guard(num: u8) { + match num { + 5 | 6 + if let Some(ref a) = get_temp() + && let Some(ref b) = get_temp() => + { + let _x = a; + let _y = b; + } + _ => {} + } + match num { + 7 | 8 + if let Some(ref mut c) = get_temp() + && let Some(ref mut d) = get_temp() => + { + let _w = c; + let _z = d; + } + _ => {} + } +} + +fn let_cond_chain_guard(num: u8) { + match num { + 9 | 10 + if let Some(ref a) = get_temp() + && true => + { + let _x = a; + } + _ => {} + } + match num { + 11 | 12 + if let Some(ref mut b) = get_temp() + && true => + { + let _w = b; + } + _ => {} + } +} + +fn main() {} |
