-
Notifications
You must be signed in to change notification settings - Fork 13k
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
match variant with fields unresolved when enum type in scope #14221
Comments
This looks like a serious resolve bug, neither the name |
wow I think this bug is actually much more serious than I had realized. Even doing a pub mod a {
pub enum En { A,
B,
#[cfg(field)] C(int) }
pub fn key(e: En) -> StrBuf {
match e { A => "A",
B => "B",
#[cfg(field)] C(_) => "C",
}.to_strbuf()
}
#[cfg(inner)]
pub mod b {
use a::En;
pub fn key(e: En) -> StrBuf {
match e { A => "A",
B => "B",
#[cfg(field)] C(_) => "C",
}.to_strbuf()
}
}
}
#[cfg(inner)]
fn main() {
println!("Hello World {}", a::b::key(a::A));
}
#[cfg(not(inner))]
fn main() {
println!("Hello World {}", a::key(a::A));
} If you have both
|
@alexcrichton I thought it was by design that when you import an enum type, you were supposed to automatically get its variants without having to import them explicitly? |
I was unaware of such a design! If so, then this seems like just a bug, if not though, we may have some other issues... |
Variants definitely do not auto-import in my experience. |
admittedly, I do not recall where I got the impression that enum import worked this way. (and on a test case i just hacked up, none of the variants get auto-imported into a sibling module. so perhaps this is an artifact of some interaction between the parent and child modules.) But etiher way, we should resolve what the appropriate semantics are here. I have no problem |
This is scary. |
@alexcrichton is right. (I still don't know how I got the impression I had, but then again, clearly someone working on resolve had the same impression I guess...) P-backcompat-lang, 1.0. (And I need to change the test better illustrate that the matches of |
This plugs a leak where resolve was treating enums defined in parent modules as in-scope for all children modules when resolving a pattern identifier. This eliminates the code path in resolve entirely. If this breaks any existing code, then it indicates that the variants need to be explicitly imported into the module. Closes #14221
…Veykril fix: show diagnostic for } token followed by else in let else statement fix rust-lang#14221 My thinking is to check if the `expr` after `=` is block like when parse `let ... lese` , and if so, emit error.
Here is some code (derived from something I actually saw recently in rustc):
Now the bug:
(The workaround is to explicitly import the enum variant with the field. It does not suffice to just do
use a::EnumType
; see comments below.)The text was updated successfully, but these errors were encountered: