Skip to content

udpdate error message for unsized union field #43901

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
merged 2 commits into from
Aug 18, 2017

Conversation

GuillaumeGomez
Copy link
Member

Fixes #36312.

@rust-highfive
Copy link
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@petrochenkov petrochenkov self-assigned this Aug 16, 2017
@@ -1112,7 +1112,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err.note("structs must have a statically known size to be initialized");
}
ObligationCauseCode::FieldSized => {
err.note("only the last field of a struct may have a dynamically sized type");
err.note("only the last field of a struct or an union may have a dynamically \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"an union" -> "a union"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "last field" part is not relevant for unions, unions may not have unsized fields regardless of position.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message also applies to enums so I think it would be best to have different messages for structs, enums and unions.

@GuillaumeGomez
Copy link
Member Author

Updated. I'm not too sure about the note messages though...

@aidanhs aidanhs added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 16, 2017
match *item {
hir::ItemStruct(_, _) => {
err.note("only the last field of a struct may have a dynamically type \
sized type");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dynamically type sized type" -> "dynamically sized type" here and below

err.note("no field of a union may have a dynamically type sized type");
}
hir::ItemEnum(_, _) => {
err.note("no variant of an enum may have a dynamically type sized type");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"no variant of an enum" -> "no field of an enum variant"

@@ -133,7 +133,7 @@ pub enum ObligationCauseCode<'tcx> {
RepeatVec,

/// Types of fields (other than the last) in a struct must be sized.
FieldSized,
FieldSized(hir::Item_),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use ty::AdtKind here to avoid cloning HIR items.

@GuillaumeGomez
Copy link
Member Author

Updated.

@@ -195,7 +195,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
super::ReturnType(id) => Some(super::ReturnType(id)),
super::SizedReturnType => Some(super::SizedReturnType),
super::RepeatVec => Some(super::RepeatVec),
super::FieldSized => Some(super::FieldSized),
super::FieldSized(ref item) => Some(super::FieldSized(*item)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ref and * are unnecessary.

@petrochenkov
Copy link
Contributor

r=me with the nit fixed

@GuillaumeGomez
Copy link
Member Author

Fixed and squashed the extra commit.

@bors: r=petrochenkov

@bors
Copy link
Collaborator

bors commented Aug 18, 2017

📌 Commit c3c99b9 has been approved by petrochenkov

@bors
Copy link
Collaborator

bors commented Aug 18, 2017

⌛ Testing commit c3c99b9 with merge b8ce1a3...

bors added a commit that referenced this pull request Aug 18, 2017
…nkov

udpdate error message for unsized union field

Fixes #36312.
@bors
Copy link
Collaborator

bors commented Aug 18, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing b8ce1a3 to master...

@bors bors merged commit c3c99b9 into rust-lang:master Aug 18, 2017
@GuillaumeGomez GuillaumeGomez deleted the unsized-union-field branch August 18, 2017 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants