-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -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 \ |
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.
"an union" -> "a union"
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.
The "last field" part is not relevant for unions, unions may not have unsized fields regardless of position.
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.
This message also applies to enums so I think it would be best to have different messages for structs, enums and unions.
Updated. I'm not too sure about the note messages though... |
match *item { | ||
hir::ItemStruct(_, _) => { | ||
err.note("only the last field of a struct may have a dynamically type \ | ||
sized type"); |
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.
"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"); |
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.
"no variant of an enum" -> "no field of an enum variant"
src/librustc/traits/mod.rs
Outdated
@@ -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_), |
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.
You can use ty::AdtKind
here to avoid cloning HIR items.
210e2b5
to
6abd035
Compare
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)), |
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.
Nit: ref
and *
are unnecessary.
r=me with the nit fixed |
6abd035
to
c3c99b9
Compare
Fixed and squashed the extra commit. @bors: r=petrochenkov |
📌 Commit c3c99b9 has been approved by |
…nkov udpdate error message for unsized union field Fixes #36312.
☀️ Test successful - status-appveyor, status-travis |
Fixes #36312.