You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an open question around what syntax (if any) should be required to cause the deref function to be considered in a pattern. From this Zulip discussion the currently preferred option is 'no syntax'. I.e., we extend the match ergonomics rules to apply in any situation where there is a Deref impl, not just in the &T case (to be more precise, where the scrutinee (or a sub-part) has type &T and there is Deref impl for T, then we can match a pattern (or sub-pattern) with type <T as Deref>::Target.
So, the following examples should type check:
fn proposed(a: Option<String>, b: Rc<Box<&Vec<i32>>>) {
match a {
Some("hello") => {}
_ => {}
}
match b {
[1, 2, 3] => {}
_ => {}
}
}
The text was updated successfully, but these errors were encountered:
Would it be possible to have a kind of "path" based pure de-referencing system, so it wouldn't involve arbitrary code execution?
Eg
structBox<T>{pointer:*constT for deref}// ORstructBox<T>{pointer:*constT for pattern}// OR (this involves no new keywords) & fully backwards compatiblestructBox<T>{pointer:*constTfor match
}// and then...enumFoo{A,B,}let item = Box::new(Foo::A);match a_box {Foo::A => ...,Foo::B => ...}
Can anyone foresee any issues with this kind of syntax?
Previous discussion
There is an open question around what syntax (if any) should be required to cause the deref function to be considered in a pattern. From this Zulip discussion the currently preferred option is 'no syntax'. I.e., we extend the match ergonomics rules to apply in any situation where there is a
Deref
impl, not just in the&T
case (to be more precise, where the scrutinee (or a sub-part) has type&T
and there isDeref
impl forT
, then we can match a pattern (or sub-pattern) with type<T as Deref>::Target
.So, the following examples should type check:
The text was updated successfully, but these errors were encountered: