Files
rust/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.rs
dianne 64c8d5d7f5 move existing tests away from using boxes
Since deref patterns on boxes will be lowered differently, I'll be
making a separate test file for them. This makes sure we're still
testing the generic `Deref(Mut)::deref(_mut)`-based lowering.
2025-04-24 14:25:27 -07:00

43 lines
904 B
Rust

#![feature(deref_patterns)]
#![allow(incomplete_features)]
use std::rc::Rc;
struct Struct;
fn cant_move_out_vec(b: Vec<Struct>) -> Struct {
match b {
//~^ ERROR: cannot move out of type `[Struct]`, a non-copy slice
deref!([x]) => x,
_ => panic!(),
}
}
fn cant_move_out_rc(rc: Rc<Struct>) -> Struct {
match rc {
//~^ ERROR: cannot move out of a shared reference
deref!(x) => x,
_ => unreachable!(),
}
}
fn cant_move_out_vec_implicit(b: Vec<Struct>) -> Struct {
match b {
//~^ ERROR: cannot move out of type `[Struct]`, a non-copy slice
[x] => x,
_ => panic!(),
}
}
struct Container(Struct);
fn cant_move_out_rc_implicit(rc: Rc<Container>) -> Struct {
match rc {
//~^ ERROR: cannot move out of a shared reference
Container(x) => x,
_ => unreachable!(),
}
}
fn main() {}