2025-03-09 05:30:48 +00:00
|
|
|
//@ run-pass
|
|
|
|
//! Test that implicit deref patterns interact as expected with `Cow` constructor patterns.
|
|
|
|
#![feature(deref_patterns)]
|
|
|
|
#![allow(incomplete_features)]
|
|
|
|
|
|
|
|
use std::borrow::Cow;
|
2025-03-17 01:21:00 +00:00
|
|
|
use std::rc::Rc;
|
2025-03-09 05:30:48 +00:00
|
|
|
|
|
|
|
fn main() {
|
2025-04-16 18:13:42 +00:00
|
|
|
let cow: Cow<'static, [u8]> = Cow::Borrowed(&[1, 2, 3]);
|
2025-03-09 05:30:48 +00:00
|
|
|
|
|
|
|
match cow {
|
|
|
|
[..] => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
match cow {
|
|
|
|
Cow::Borrowed(_) => {}
|
|
|
|
Cow::Owned(_) => unreachable!(),
|
|
|
|
}
|
|
|
|
|
2025-03-17 01:21:00 +00:00
|
|
|
match Rc::new(&cow) {
|
2025-03-09 05:30:48 +00:00
|
|
|
Cow::Borrowed { 0: _ } => {}
|
|
|
|
Cow::Owned { 0: _ } => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
let cow_of_cow: Cow<'_, Cow<'static, [u8]>> = Cow::Owned(cow);
|
|
|
|
|
|
|
|
match cow_of_cow {
|
|
|
|
[..] => {}
|
|
|
|
}
|
|
|
|
|
2025-04-16 18:13:42 +00:00
|
|
|
// This matches on the outer `Cow` (the owned one).
|
2025-03-09 05:30:48 +00:00
|
|
|
match cow_of_cow {
|
|
|
|
Cow::Borrowed(_) => unreachable!(),
|
|
|
|
Cow::Owned(_) => {}
|
|
|
|
}
|
|
|
|
|
2025-03-17 01:21:00 +00:00
|
|
|
match Rc::new(&cow_of_cow) {
|
2025-03-09 05:30:48 +00:00
|
|
|
Cow::Borrowed { 0: _ } => unreachable!(),
|
|
|
|
Cow::Owned { 0: _ } => {}
|
|
|
|
}
|
|
|
|
}
|