3 // Taken from https://github.com/rust-lang/rust/blob/6cc0a764e082d9c0abcf37a768d5889247ba13e2/compiler/rustc_typeck/src/check/_match.rs#L445-L462
5 // We attempt to `let Bar::Present(_): &mut Bar = foo else { ... }` where foo is meant to
6 // Deref/DerefMut to Bar. You can do this with an irrefutable binding, so it should work with
10 use std::ops::{Deref, DerefMut};
20 fn deref(&self) -> &Bar {
24 impl DerefMut for Foo {
25 fn deref_mut(&mut self) -> &mut Bar {
30 fn bar(&self) -> Option<u32> {
31 let Bar::Present(z): &Bar = self else {
38 fn set_bar_annotated(&mut self, value: u32) {
39 let Bar::Present(z): &mut Bar = self else { // OK
47 let mut foo = Foo(Bar::Present(1));
48 foo.set_bar_annotated(42);
49 assert_eq!(foo.bar(), Some(42));
53 // The original, to show it works for irrefutable let decls
55 use std::ops::{Deref, DerefMut};
60 fn deref(&self) -> &Bar {
64 impl DerefMut for Foo {
65 fn deref_mut(&mut self) -> &mut Bar {
70 let Bar(z): &mut Bar = x; // OK
72 assert_eq!((x.0).0, 42);
75 foo(&mut Foo(Bar(1)));