-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Accept interpolated patterns in trait method parameters #45775
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
LGTM. r? @nikomatsakis |
So is this also the "make #35203 a hard error" PR (skipping the deny-by-default step)? |
@durka The only patterns transitioning from warning to error are |
The code seems fine, the bigger question is the policy decision about moving to a hard error for at least some patterns. @petrochenkov what kind of crater runs do you have? Maybe we should do a pre-emptive run with this PR? |
From Jun 28, this year: #42894 (comment) #42894 (comment) |
Ah I see. So this is only one of the places that a #35203 warning can be generated and the other one is still a warning. |
Wait, I'm a little confused still, sorry. Is this the behavior I should expect after this PR? macro_rules! m {
($pat: pat, $ty: ty) => {
trait Tr {
fn f($pat: $ty); // changed to have no body so #35203 is triggered
}
}
}
m!(x, u8); // OK
m!(mut x, u8); // warning #35203
m!(&x, &u8); // error
m!((x, y), (u8, u8)): // error |
@durka that is what I expect, from reading the source anyway. |
@durka In particular, this PR makes "complex" patterns like |
OK. I don't think it fully addresses #35203 (comment) then (for me that's a compelling use case), but it matches the previous plan. |
Yes |
Ah, I was misremembering. It's anonymous parameters that I was thinking of. |
Just for completeness, the reason it doesn't address that comment is even though you'll be able to write |
That's future proofing for type ascription in patterns let (x: u8, y) = ...; (and totally separate issue from this PR). |
I know the reasoning, I just wanted to point it out. |
@rfcbot fcp merge OK, well, I'd like to get formal approval on moving to a hard error, even for a limited number of cases. But I think it probably makes sense to go forward here. To summarize the situation:
|
@rfcbot is on vacation
From 20 |
Sigh. No @rfcbot? OK, I will nominate for discussion at today's mtg. |
@petrochenkov have we tried to patch |
Discussed in @rust-lang/compiler meeting and decided to go forward with this PR. |
@bors r+ |
📌 Commit 10c0de3 has been approved by |
⌛ Testing commit 10c0de365d9cc61547ba66f3ea938688757a95f7 with merge d550e9f20fa647e7d1698d44627d77f240f73136... |
💔 Test failed - status-appveyor |
Needs to change the error code.
|
Remove some outdated messages from "no patterns allowed" errors
10c0de3
to
f7b4b88
Compare
@bors r=nikomatsakis |
📌 Commit f7b4b88 has been approved by |
Accept interpolated patterns in trait method parameters Permit this, basically ```rust macro_rules! m { ($pat: pat) => { trait Tr { fn f($pat: u8) {} } } } ``` it previously caused a parsing error during expansion because trait methods accept only very restricted set of patterns during parsing due to ambiguities caused by [anonymous parameters](#41686), and this set didn't include interpolated patterns. Some outdated messages from "no patterns allowed" errors are also removed. Addresses #35203 (comment)
I've sent a PR for |
☀️ Test successful - status-appveyor, status-travis |
Marking for relnotes. This PR moves along the process of making argument patterns in functions without bodies a hard error (see #35203 for details). In particular, we now only support |
Permit this, basically
it previously caused a parsing error during expansion because trait methods accept only very restricted set of patterns during parsing due to ambiguities caused by anonymous parameters, and this set didn't include interpolated patterns.
Some outdated messages from "no patterns allowed" errors are also removed.
Addresses #35203 (comment)