-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow qualified paths in struct construction (both expressions and patterns) #80080
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
Merged
+374
−187
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/doc/unstable-book/src/language-features/more-qualified-paths.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# `more_qualified_paths` | ||
|
||
The `more_qualified_paths` feature can be used in order to enable the | ||
use of qualified paths in patterns. | ||
|
||
## Example | ||
|
||
```rust | ||
#![feature(more_qualified_paths)] | ||
|
||
fn main() { | ||
// destructure through a qualified path | ||
let <Foo as A>::Assoc { br } = StructStruct { br: 2 }; | ||
} | ||
|
||
struct StructStruct { | ||
br: i8, | ||
} | ||
|
||
struct Foo; | ||
|
||
trait A { | ||
type Assoc; | ||
} | ||
|
||
impl A for Foo { | ||
type Assoc = StructStruct; | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/ui/associated-types/associated-type-destructuring-assignment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// check-pass | ||
|
||
#![feature(destructuring_assignment)] | ||
#![feature(more_qualified_paths)] | ||
|
||
enum E { V() } | ||
|
||
fn main() { | ||
<E>::V() = E::V(); // OK, destructuring assignment | ||
<E>::V {} = E::V(); // OK, destructuring assignment | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
#[cfg(FALSE)] | ||
<() as module>::mac!(); //~ ERROR macros cannot use qualified paths | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: macros cannot use qualified paths | ||
--> $DIR/associated-type-macro.rs:3:5 | ||
| | ||
LL | <() as module>::mac!(); | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
24 changes: 24 additions & 0 deletions
24
src/test/ui/associated-types/associated-type-struct-construction.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Make sure that users can construct structs through associated types | ||
// in both expressions and patterns | ||
|
||
#![feature(more_qualified_paths)] | ||
|
||
// check-pass | ||
fn main() { | ||
let <Foo as A>::Assoc { br } = <Foo as A>::Assoc { br: 2 }; | ||
assert!(br == 2); | ||
} | ||
|
||
struct StructStruct { | ||
br: i8, | ||
} | ||
|
||
struct Foo; | ||
|
||
trait A { | ||
type Assoc; | ||
} | ||
|
||
impl A for Foo { | ||
type Assoc = StructStruct; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/associated-types/associated-type-tuple-struct-construction.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Users cannot yet construct structs through associated types | ||
// in both expressions and patterns | ||
|
||
#![feature(more_qualified_paths)] | ||
|
||
fn main() { | ||
let <Foo as A>::Assoc(n) = <Foo as A>::Assoc(2); | ||
//~^ ERROR expected method or associated constant, found associated type | ||
//~| ERROR expected method or associated constant, found associated type | ||
assert!(n == 2); | ||
} | ||
|
||
struct TupleStruct(i8); | ||
|
||
struct Foo; | ||
|
||
|
||
trait A { | ||
type Assoc; | ||
} | ||
|
||
impl A for Foo { | ||
type Assoc = TupleStruct; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/associated-types/associated-type-tuple-struct-construction.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0575]: expected method or associated constant, found associated type `A::Assoc` | ||
--> $DIR/associated-type-tuple-struct-construction.rs:7:32 | ||
| | ||
LL | let <Foo as A>::Assoc(n) = <Foo as A>::Assoc(2); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: can't use a type alias as a constructor | ||
|
||
error[E0575]: expected method or associated constant, found associated type `A::Assoc` | ||
--> $DIR/associated-type-tuple-struct-construction.rs:7:9 | ||
| | ||
LL | let <Foo as A>::Assoc(n) = <Foo as A>::Assoc(2); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: can't use a type alias as a constructor | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0575`. |
27 changes: 27 additions & 0 deletions
27
src/test/ui/feature-gates/feature-gate-more-qualified-paths.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
fn main() { | ||
// destructure through a qualified path | ||
let <Foo as A>::Assoc { br } = StructStruct { br: 2 }; | ||
//~^ ERROR usage of qualified paths in this context is experimental | ||
let _ = <Foo as A>::Assoc { br: 2 }; | ||
//~^ ERROR usage of qualified paths in this context is experimental | ||
let <E>::V(..) = E::V(0); | ||
//~^ ERROR usage of qualified paths in this context is experimental | ||
} | ||
|
||
struct StructStruct { | ||
br: i8, | ||
} | ||
|
||
struct Foo; | ||
|
||
trait A { | ||
type Assoc; | ||
} | ||
|
||
impl A for Foo { | ||
type Assoc = StructStruct; | ||
} | ||
|
||
enum E { | ||
V(u8) | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/feature-gates/feature-gate-more-qualified-paths.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0658]: usage of qualified paths in this context is experimental | ||
--> $DIR/feature-gate-more-qualified-paths.rs:3:9 | ||
| | ||
LL | let <Foo as A>::Assoc { br } = StructStruct { br: 2 }; | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #80080 <https://github.com/rust-lang/rust/issues/80080> for more information | ||
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable | ||
|
||
error[E0658]: usage of qualified paths in this context is experimental | ||
--> $DIR/feature-gate-more-qualified-paths.rs:5:13 | ||
| | ||
LL | let _ = <Foo as A>::Assoc { br: 2 }; | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #80080 <https://github.com/rust-lang/rust/issues/80080> for more information | ||
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable | ||
|
||
error[E0658]: usage of qualified paths in this context is experimental | ||
--> $DIR/feature-gate-more-qualified-paths.rs:7:9 | ||
| | ||
LL | let <E>::V(..) = E::V(0); | ||
| ^^^^^^ | ||
| | ||
= note: see issue #80080 <https://github.com/rust-lang/rust/issues/80080> for more information | ||
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/test/ui/parser/brace-after-qualified-path-in-match.stderr
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/test/ui/parser/paren-after-qualified-path-in-match.stderr
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.