-
Notifications
You must be signed in to change notification settings - Fork 13.4k
check_match: Dereference ref x
before comparing it and some other type
#23313
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
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
I'm really not sure if this is the right way to fix the issue, so I beg for forgiveness in advance. |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Related issue: #23009 |
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.
Please add a comment to tests saying what is being tested - why it should fail, why it shouldn't ICE. This is helpful for future contributors who break your test and need to know if it is important.
Afraid I don't know this code well enough to review, sorry. Perhaps r? @pnkfelix |
@@ -864,7 +864,10 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], | |||
} else { | |||
None | |||
}, | |||
_ => Some(repeat(DUMMY_WILD_PAT).take(arity).collect()) | |||
_ => match *constructor { | |||
ConstantValue(..) => Some(vec![]), |
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.
so I'm not totally familiar with this code; I'm looking at what you've added here, and I do not immediately see why it suffices to add a special case for ConstantValue(..)
but not need one for e.g. ConstantRange
. Can you enlighten me?
(i'm going to be out until wedneday; handing off to @nikomatsakis to find a reviewer to replace me.) |
I'll take this. @barosl Thanks for tackling this. I don't think your fix is the appropriate one here. If you notice, the example will compile fine if you drop the It looks like we're getting bitten by our old problem of The place to hunt for a solution will be around https://github.com/rust-lang/rust/blob/ee7696383f3423cdd17373ff9e75c01acd8e3417/src/librustc/middle/check_match.rs#L649-658. let left_ty = if real_pat.id == DUMMY_NODE_ID {
ty::mk_nil(cx.tcx)
} else {
ty::pat_ty(cx.tcx, &*real_pat)
}; One way or another, we will need this to be the type of the value being destructured, free from the idiosyncracies of |
Also, could you add the following assertion: assert!(rows.iter().all(|row| row.len() == v.len())); above this line: rust/src/librustc/middle/check_match.rs Line 649 in ee76963
|
b66f35d
to
bcb4974
Compare
If we sanitize let left_ty = match (&real_pat.node, &left_ty.sty) {
(&ast::PatIdent(..), &ty::ty_rptr(_, ty::mt { ty, .. })) => match ty.sty {
ty_int(..) | ty_uint(..) | ty_bool | ty_char | ty_float(..) => ty,
_ => left_ty,
},
_ => left_ty,
}; But I find this ugly, as it hard-codes the list of the non-structural types. It also has a nested How about modifying |
@barosl I don't think we need the nested match at all. Any time you see the pattern left_ty = match left_ty {
ast::PatIdent(ByRef, _, _) => ty::deref(left_ty, true).unwrap().ty,
_ => left_ty
}; |
Sorry, I realise I'd misled you by talking about non-structural and structural types. My only point was that non-structural types should always have arity of 0 but that for |
Oh, I see! So the arity itself wasn't wrong. It seems that you coded the most part, though 😄. I'll update my pull request based on your comment, and run tests locally. |
bcb4974
to
a11c4bf
Compare
The arity of `ref x` is always 1, so it needs to be dereferenced before being compared with some other type whose arity is not 1. Fixes rust-lang#23009.
a11c4bf
to
edbc0e5
Compare
@jakub- Ok, I've done it. The tests pass locally. Also, I changed the code to pass |
ref x
before comparing it and some other type
@barosl: Sure, that's fine. :) Thanks! |
The arity of `ref x` is always 1, so it needs to be dereferenced before being compared with some other type whose arity is not 1. Fixes #23009.
The arity of
ref x
is always 1, so it needs to be dereferenced before being compared with some other type whose arity is not 1.Fixes #23009.