diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/let-else/let-else-non-copy.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/let-else/let-else-non-copy.rs')
-rw-r--r-- | tests/ui/let-else/let-else-non-copy.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui/let-else/let-else-non-copy.rs b/tests/ui/let-else/let-else-non-copy.rs new file mode 100644 index 000000000..08c07dd1a --- /dev/null +++ b/tests/ui/let-else/let-else-non-copy.rs @@ -0,0 +1,45 @@ +// run-pass +// +// This is derived from a change to compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs, in +// preparation for adopting let-else within the compiler (thanks @est31): +// +// ``` +// - let place = if let mir::VarDebugInfoContents::Place(p) = var.value { p } else { continue }; +// + let mir::VarDebugInfoContents::Place(place) = var.value else { continue }; +// ``` +// +// The move was due to mir::Place being Copy, but mir::VarDebugInfoContents not being Copy. + + + +#[derive(Copy, Clone)] +struct Copyable; + +enum NonCopy { + Thing(Copyable), + #[allow(unused)] + Other, +} + +struct Wrapper { + field: NonCopy, +} + +fn let_else() { + let vec = vec![Wrapper { field: NonCopy::Thing(Copyable) }]; + for item in &vec { + let NonCopy::Thing(_copyable) = item.field else { continue }; + } +} + +fn if_let() { + let vec = vec![Wrapper { field: NonCopy::Thing(Copyable) }]; + for item in &vec { + let _copyable = if let NonCopy::Thing(copyable) = item.field { copyable } else { continue }; + } +} + +fn main() { + let_else(); + if_let(); +} |