-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Don't allow opaque ty aliases in ADT fields #86928
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
Closed
b-naber
wants to merge
4
commits into
rust-lang:master
from
b-naber:dont_allow_opaque_ty_alias_in_struct_fields_issue-86732
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c0bd0c6
reject type alias impl traits as field types
b-naber cba8b4c
add test and update existing tests
b-naber 21548b4
add typevisitor for rejecting fields with nested type alias impl types
b-naber fb17ef1
dont check opaque type aliases in fields in type_alias_impl_trait
b-naber 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![feature(min_type_alias_impl_trait)] | ||
|
||
type ImplCopy = impl Copy; | ||
//~^ ERROR could not find defining uses | ||
|
||
enum Wrapper { | ||
//~^ ERROR type alias impl traits are not allowed as field types in enums | ||
First(ImplCopy), | ||
Second | ||
} | ||
|
||
type X = impl Iterator<Item = u64> + Unpin; | ||
//~^ ERROR could not find defining uses | ||
|
||
struct Foo(X); | ||
//~^ ERROR type alias impl traits are not allowed as field types in structs | ||
|
||
impl Foo { | ||
fn new(z: Vec<u64>) -> Self { | ||
Foo(z.into_iter()) | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
|
||
struct Bar {a : X} | ||
//~^ ERROR type alias impl traits are not allowed as field types in structs | ||
|
||
impl Bar { | ||
fn new(z: Vec<u64>) -> Self { | ||
Bar {a: z.into_iter() } | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
|
||
union MyUnion { | ||
//~^ ERROR type alias impl traits are not allowed as field types in unions | ||
a: X, | ||
//~^ ERROR unions may not contain fields that need dropping | ||
} | ||
|
||
|
||
fn main() {} |
102 changes: 102 additions & 0 deletions
102
src/test/ui/impl-trait/reject-opaque_types-in-fields.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,102 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/reject-opaque_types-in-fields.rs:20:13 | ||
| | ||
LL | type X = impl Iterator<Item = u64> + Unpin; | ||
| --------------------------------- the expected opaque type | ||
... | ||
LL | Foo(z.into_iter()) | ||
| ^^^^^^^^^^^^^ expected opaque type, found struct `std::vec::IntoIter` | ||
| | ||
= note: expected opaque type `impl Iterator+Unpin` | ||
found struct `std::vec::IntoIter<u64>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/reject-opaque_types-in-fields.rs:30:13 | ||
| | ||
LL | type X = impl Iterator<Item = u64> + Unpin; | ||
| --------------------------------- the expected opaque type | ||
... | ||
LL | Bar {a: z.into_iter() } | ||
| ^^^^^^^^^^^^^ expected opaque type, found struct `std::vec::IntoIter` | ||
| | ||
= note: expected opaque type `impl Iterator+Unpin` | ||
found struct `std::vec::IntoIter<u64>` | ||
|
||
error: could not find defining uses | ||
--> $DIR/reject-opaque_types-in-fields.rs:3:17 | ||
| | ||
LL | type ImplCopy = impl Copy; | ||
| ^^^^^^^^^ | ||
|
||
error: type alias impl traits are not allowed as field types in enums | ||
--> $DIR/reject-opaque_types-in-fields.rs:6:1 | ||
| | ||
LL | type ImplCopy = impl Copy; | ||
| -------------------------- type alias defined here | ||
... | ||
LL | / enum Wrapper { | ||
LL | | | ||
LL | | First(ImplCopy), | ||
| | -------- this field contains a type alias impl trait | ||
LL | | Second | ||
LL | | } | ||
| |_^ | ||
|
||
error: could not find defining uses | ||
--> $DIR/reject-opaque_types-in-fields.rs:12:10 | ||
| | ||
LL | type X = impl Iterator<Item = u64> + Unpin; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type alias impl traits are not allowed as field types in structs | ||
--> $DIR/reject-opaque_types-in-fields.rs:15:1 | ||
| | ||
LL | type X = impl Iterator<Item = u64> + Unpin; | ||
| ------------------------------------------- type alias defined here | ||
... | ||
LL | struct Foo(X); | ||
| ^^^^^^^^^^^-^^ | ||
| | | ||
| this field contains a type alias impl trait | ||
|
||
error: type alias impl traits are not allowed as field types in structs | ||
--> $DIR/reject-opaque_types-in-fields.rs:25:1 | ||
| | ||
LL | type X = impl Iterator<Item = u64> + Unpin; | ||
| ------------------------------------------- type alias defined here | ||
... | ||
LL | struct Bar {a : X} | ||
| ^^^^^^^^^^^^-----^ | ||
| | | ||
| this field contains a type alias impl trait | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worthwhile to put the name of the type alias in this message, if the alias is part of some larger nested type then identifying it might be helpful. e.g. |
||
|
||
error: type alias impl traits are not allowed as field types in unions | ||
--> $DIR/reject-opaque_types-in-fields.rs:35:1 | ||
| | ||
LL | type X = impl Iterator<Item = u64> + Unpin; | ||
| ------------------------------------------- type alias defined here | ||
... | ||
LL | / union MyUnion { | ||
LL | | | ||
LL | | a: X, | ||
| | ---- this field contains a type alias impl trait | ||
LL | | | ||
LL | | } | ||
| |_^ | ||
|
||
error[E0740]: unions may not contain fields that need dropping | ||
--> $DIR/reject-opaque_types-in-fields.rs:37:3 | ||
| | ||
LL | a: X, | ||
| ^^^^ | ||
| | ||
note: `std::mem::ManuallyDrop` can be used to wrap the type | ||
--> $DIR/reject-opaque_types-in-fields.rs:37:3 | ||
| | ||
LL | a: X, | ||
| ^^^^ | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0740. | ||
For more information about an error, try `rustc --explain E0308`. |
Oops, something went wrong.
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.