-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Field pattern shorthand can be interpreted as an item reference #42876
Comments
Nominating for @rust-lang/lang. I don't think changing things here at this point is going to be easy (feature is stable) but perhaps we could do a warning cycle if we wanted to not allow this. |
I don't think this is a bug, just the shorthand desugaring and "existing entity vs fresh binding" disambiguation working orthogonally and as expected. (I.e. a perfect behavior for a corner case with near-zero practical impact.)
The wording for the "local-global shadowing" error is misleading, it's actually a "can't disambiguate between existing entity and fresh binding" error, not shadowing error (and it's reported more often than strictly necessary, I was planning to fix it, but still never got to this). If we can force |
I don't see what this has to do with the shorthand? If the pattern is |
Is there no warning on the field name of |
I'm of the opinion that (a) hence I'd prefer to have a lint targeting this case specifically. |
+1 for having this a lint |
Triage: not aware of any movement on this issue. |
When encountering an Item in a pat context, point at the item def ``` error[E0308]: mismatched types --> $DIR/const-in-struct-pat.rs:8:17 | LL | struct foo; | ----------- `foo` defined here ... LL | let Thing { foo } = t; | ^^^ expected struct `std::string::String`, found struct `foo` | = note: `foo` is interpreted as a unit struct, not a new binding help: you can bind the struct field to a different name | LL | let Thing { foo: other_foo } = t; | ^^^^^^^^^^^^^^ ``` ``` error[E0308]: mismatched types --> $DIR/const.rs:14:9 | LL | const FOO: Foo = Foo{bar: 5}; | ----------------------------- constant defined here ... LL | FOO => {}, | ^^^ | | | expected `&Foo`, found struct `Foo` | `FOO` is interpreted as a constant, not a new binding | help: use different name to introduce a new binding: `other_foo` ``` Fix rust-lang#55631, fix rust-lang#48062, cc rust-lang#42876.
When encountering an Item in a pat context, point at the item def ``` error[E0308]: mismatched types --> $DIR/const-in-struct-pat.rs:8:17 | LL | struct foo; | ----------- `foo` defined here ... LL | let Thing { foo } = t; | ^^^ expected struct `std::string::String`, found struct `foo` | = note: `foo` is interpreted as a unit struct, not a new binding help: you can bind the struct field to a different name | LL | let Thing { foo: other_foo } = t; | ^^^^^^^^^^^^^^ ``` ``` error[E0308]: mismatched types --> $DIR/const.rs:14:9 | LL | const FOO: Foo = Foo{bar: 5}; | ----------------------------- constant defined here ... LL | FOO => {}, | ^^^ | | | expected `&Foo`, found struct `Foo` | `FOO` is interpreted as a constant, not a new binding | help: use different name to introduce a new binding: `other_foo` ``` Fix rust-lang#55631, fix rust-lang#48062, cc rust-lang#42876.
B { X }
is a shorthand forB { X: X }
andX
here can be intepreted as an item reference, rather than a binding. I don't know if this is actually a bug or not. Possible fixes are:X
be interpreted as a binding and let it fail to compile (due to local-global shadowing).Bar!
is printed.rustc 1.20.0-nightly (ab5bec255 2017-06-22)
The text was updated successfully, but these errors were encountered: