New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Fix pattern type mismatches for bindings, enable pattern type mismatch diagnostics again #14732
Conversation
8e3dc0d
to
36c9d5c
Compare
/// It also includes the changes that binding mode makes in the type. For example in | ||
/// `let ref x @ Some(_) = None` the result of `type_of_pat` is `Option<T>` but the result | ||
/// of this function is `&mut Option<T>` | ||
pub fn type_of_binding_in_pat(&self, pat: &ast::IdentPat) -> Option<Type> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting thing to keep in mind that effectively pattern and binding are not always equal in a sense
@@ -148,7 +148,6 @@ struct Struct { | |||
field: &'static str, | |||
} | |||
fn foo(s @ Struct { field, .. }: &Struct) {} | |||
//^^^^^^^^^^^^^^^^^^^^^^^^ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong to me? s is being bound by reference so the ref
mode should still be here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think s
here is binding by moving the reference itself, not binding by ref the thing inside of reference. This example makes the difference clear:
let t @ T = &&&T; // type is `&&&T`, binding mode is `move`
let (t @ T,) = &&&(T,); // type is `&T`, binding mode is `ref`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, turns out I completely misunderstood how binding modes worked for @ bindings! I think you are right here (at least judging from testing with ==
to avoid coercions from messing things up).
That also explains the pattern type mismatches now. Thanks for clarifying
@bors r+ |
Also, what do tuples have to do with this PR, isn't this fixing incorrect type inference for bindings? |
☀️ Test successful - checks-actions |
The main change in this PR is that |
Reduces pattern type mismatches on self to 4