-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Complete only missing fields in pats #3779
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
Complete only missing fields in pats #3779
Conversation
I think a method on |
On the other hand, going to the |
I had thoughts on making struct ra_hir::Pat {
id: Idx<ra_hir_def::Pat>,
parent: ra_hir_def::DefWithBodyId,
} |
Hm, I see that Next, I have to match the Did I get the idea right? |
@SomeoneToIgnore I may be wrong, but we shouldn't expose |
They are not available in
So apparently I've understood it wrong and need clarification :) |
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.
So apparently I've understood it wrong and need clarification :)
You didn't misunderstand, I just imagined APIs that don't exist yet ;)
Next, I have to match the Pat contents and descend down to the Path::Bind to extract the name and add it to the vec of an existing name.
Not Pat::Bind
, Pat::Record
, which has a list of RecordFieldPat
s :)
It looks doable, but what is the actual benefit compared to the ast approach?
It should be the simplest and cleanest way to do this, if the APIs actually existed ;) For one thing, you wouldn't have to deal with field shorthand.
I think for this specifically, we should have something more high-level impl Semantics {
fn missing_fields(&self, src: RecordLiteral | CallExpr | TupleStructPat | RecordPat) -> Vec<StructField>
} In general, I think we should strive for broad, but shallow API, a-la BindingContext. |
Specific action items for this PR are probably:
|
Hmm to me, 'missing fields' seems like an IDE-level concern and doesn't really fit into my understanding of |
Yeah, it's true that it is primarily for IDEs (although I expect there will be some impl intersection with relevant diagnostics). But in my mind it's not really about IDE vs compiler. Like we only use Semantics from an IDE anyway, and the whole Rather, it's about the level of abstraction. Stuff below semantics works with relative ids, stuff above works with OO-ish code-model, and Semantics is a facade. So, I wouldn't worry about Yeah, I sound like I know what I am talking about, but I actually don't, it's just my gut feeling that it's better to expose sepecific rather than general APIs here. |
And I just wanted to submit a small useful PR 😀 |
To clarify, doing just
is totally fine, I can then look into refactoring things :) |
Just to clarify more: what is the current approach? |
That BindingContext thing requires quite some digging... |
The ast one, or, really, whichever simpler that works in the common case :) |
c64f985
to
f0bae66
Compare
I've fiddled with the code and eventually decided to unite both files into one: whenever I extract the common logic, the rest of it in both files becomes so small and similar, that it feels like the right way. Few nonrelated findings along the way:
|
f0bae66
to
1335608
Compare
Yeah, I do think merging the two makes sense.
Yes please, this have been bugging me for a long time bors r+ |
That is explained by the fact that all closure parameters are .filter_map(|fild_pat| fild_pat.name())
.chain(pat_list.bind_pats().filter_map(|bind_pat| bind_pat.name())) hence the trait checks in |
Build succeeded |
Not all of them, just many 😬 |
Replace set_last_error with set_last_error_and_return Took care of the simple patterns. Other patterns involved setting an error and then using `write_int` or setting metadata and returning -1. Unsure if those are in the scope of this change Looks like this has conflicts with rust-lang#3779, so I can update when how to handle that is decided. Part of rust-lang/miri#3930.
A follow-up for #3694
Same name vs string issue persists here, now I'm able to obtain
ast::Name
, but I see no way to convert it intohir::Name
or vice versa.