-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Add field representing types #146307
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
Open
BennoLossin
wants to merge
13
commits into
rust-lang:main
Choose a base branch
from
BennoLossin:field-projections
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,281
−27
Open
Add field representing types #146307
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
308dbc8
parse field representing types
BennoLossin c9a0075
lower field representing types to HIR
BennoLossin 4b7a7d6
lower field representing types to MIR
BennoLossin 3f9fe58
add field representing types to rustc_public
BennoLossin eca5b78
add `Field` trait, lang items and `field_offset` intrinsic
BennoLossin 6e29425
add builtin impl of `Field` for field representing types
BennoLossin 617b378
add feature gate test
BennoLossin 9202339
add run-pass tests
BennoLossin 0d02b3a
test incoherent impls
BennoLossin c03d950
deny accessing FRTs of private fields
BennoLossin a1f1b32
deny manual impls of the `Field` trait
BennoLossin ef7132c
deny auto trait and drop impls for FRTs
BennoLossin a32b103
do not impl `Field` for FRTs of `repr(packed)` types
BennoLossin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3755,6 +3755,10 @@ pub enum TyKind<'hir, Unambig = ()> { | |
| Err(rustc_span::ErrorGuaranteed), | ||
| /// Pattern types (`pattern_type!(u32 is 1..)`) | ||
| Pat(&'hir Ty<'hir>, &'hir TyPat<'hir>), | ||
| /// Field representing type (`field_of!(Struct, field)`). | ||
| /// | ||
| /// The optional ident is the variant when an enum is passed `field_of!(Enum, Variant.field)`. | ||
| FieldOf(&'hir Ty<'hir>, Option<Ident>, Ident), | ||
| /// `TyKind::Infer` means the type should be inferred instead of it having been | ||
| /// specified. This can appear anywhere in a type. | ||
| /// | ||
|
|
@@ -5051,8 +5055,8 @@ mod size_asserts { | |
| static_assert_size!(TraitImplHeader<'_>, 48); | ||
| static_assert_size!(TraitItem<'_>, 88); | ||
| static_assert_size!(TraitItemKind<'_>, 48); | ||
| static_assert_size!(Ty<'_>, 48); | ||
| static_assert_size!(TyKind<'_>, 32); | ||
| static_assert_size!(Ty<'_>, 56); | ||
| static_assert_size!(TyKind<'_>, 40); | ||
|
Comment on lines
-5054
to
+5059
Contributor
Author
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. Not sure if this is fine, let me know if there is a better solution. |
||
| // tidy-alphabetical-end | ||
| } | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -261,6 +261,17 @@ pub(super) fn check_item<'tcx>( | |
| .with_span_label(sp, "auto trait") | ||
| .emit()); | ||
| } | ||
| if is_auto && let rustc_hir::TyKind::FieldOf(..) = impl_.self_ty.kind { | ||
| res = res.and(Err(tcx | ||
| .dcx() | ||
| .struct_span_err( | ||
| item.span, | ||
| "impls of auto traits for field representing types not supported", | ||
| ) | ||
| .with_span_label(impl_.self_ty.span, "field representing type") | ||
| .with_span_label(of_trait.trait_ref.path.span, "auto trait") | ||
| .emit())); | ||
| } | ||
|
Comment on lines
+264
to
+274
Contributor
Author
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. This feels pretty hacky, but I copied this from the previous version. |
||
| match header.polarity { | ||
| ty::ImplPolarity::Positive => { | ||
| res = res.and(check_impl(tcx, item, impl_)); | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is okay, but I need this in order for
FieldId(which containsFieldIdxandVariantIdx) to implementserde::Serialize. This is becauseFieldIdis needed inRigidTy, which derivesserde::Serialize.