-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Show record field names in Enum completion #3169
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
bors
merged 4 commits into
rust-lang:master
from
adamrk:show-record-field-names-in-enum-completion
Feb 17, 2020
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
04aff74
show names for record fields in enum completion
adamrk 68d3743
replace uses of VariantData::is_unit with VariantData::kind
adamrk e88eb89
add space before/after wrapping braces
adamrk 0e260aa
use 'if let' instead of match on kind in lower.rs
adamrk 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ use std::iter; | |
use std::sync::Arc; | ||
|
||
use hir_def::{ | ||
adt::StructKind, | ||
builtin_type::BuiltinType, | ||
generics::{TypeParamProvenance, WherePredicate, WherePredicateTarget}, | ||
path::{GenericArg, Path, PathSegment, PathSegments}, | ||
|
@@ -805,8 +806,9 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn | |
/// Build the type of a tuple struct constructor. | ||
fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> { | ||
let struct_data = db.struct_data(def.into()); | ||
if struct_data.variant_data.is_unit() { | ||
return type_for_adt(db, def.into()); // Unit struct | ||
match struct_data.variant_data.kind() { | ||
StructKind::Unit => return type_for_adt(db, def.into()), | ||
StructKind::Tuple | StructKind::Record => (), | ||
} | ||
let generics = generics(db, def.into()); | ||
let substs = Substs::bound_vars(&generics); | ||
|
@@ -830,8 +832,9 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId | |
fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> Binders<Ty> { | ||
let enum_data = db.enum_data(def.parent); | ||
let var_data = &enum_data.variants[def.local_id].variant_data; | ||
if var_data.is_unit() { | ||
return type_for_adt(db, def.parent.into()); // Unit variant | ||
match var_data.kind() { | ||
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. as could this 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. done |
||
StructKind::Unit => return type_for_adt(db, def.parent.into()), | ||
StructKind::Record | StructKind::Tuple => (), | ||
} | ||
let generics = generics(db, def.parent.into()); | ||
let substs = Substs::bound_vars(&generics); | ||
|
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
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.
this could be an
if let
orif ... == StructKind::Unit
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.
Just changed it. Out of curiosity - what makes
if let
preferable? Just that it's more concise? I would think it a lot of situationsmatch
without a default is better because you'll get a compiler error if a new variant is added which forces you to explicitly decide how to handle the new variant. Of course, that doesn't really apply here becauseStructKind
isn't likely to change.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.
I think in this case, as you said,
StructKind
isn't likely to change, and we just want to handle the unit case as a special case here.