Skip to content
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

rustc::ty: Rename struct_variant to non_enum_variant #47258

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

hanna-kruppe
Copy link
Contributor

r? @eddyb

@@ -1694,7 +1694,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
/// Asserts this is a struct and returns the struct's unique
/// variant.
pub fn struct_variant(&self) -> &VariantDef {
assert!(!self.is_enum());
assert!(self.is_struct());
Copy link
Contributor

Choose a reason for hiding this comment

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

Things could change, but IIRC it was called on unions and it was supposed to be called on unions, because unions are represented as an ADT with a single "variant".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case the name is misleading and the doc comment is wrong. I'm now auditing all callers to see whether they might be using this on unions. Depending on results I might change the doc comment and possibly the name.

Copy link
Member

Choose a reason for hiding this comment

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

non_enum_variant is what I'd use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, introduce another method that does the same thing for unions (if union code wants the helper method but there's no code that needs to work on structs and unions).

Copy link
Member

Choose a reason for hiding this comment

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

I'd expect most code using this is common for structs and unions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah there's a bunch. non_enum_variant it is.

@hanna-kruppe hanna-kruppe changed the title rustc::ty: Update an assertion to account for unions rustc::ty: Rename struct_variant to non_enum_variant Jan 7, 2018
@@ -689,7 +689,7 @@ struct AdtField<'tcx> {
}

impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn struct_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
fn non_enum_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this is technically a separate function that was caught up in the mass rename, but the rename fits here as well IMO.

It is also intended for use with unions.
@eddyb
Copy link
Member

eddyb commented Jan 7, 2018

r=me with build fixed

@hanna-kruppe
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Jan 8, 2018

📌 Commit cf3fefe has been approved by eddyb

kennytm added a commit to kennytm/rust that referenced this pull request Jan 8, 2018
rustc::ty: Rename struct_variant to non_enum_variant

r? @eddyb
bors added a commit that referenced this pull request Jan 9, 2018
Rollup of 10 pull requests

- Successful merges: #47210, #47233, #47246, #47254, #47256, #47258, #47259, #47263, #47270, #47272
- Failed merges: #47248
@bors bors merged commit cf3fefe into rust-lang:master Jan 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants