

Suggest use .. to fill in the rest of the fields of Struct by chenyukang · Pull...
source link: https://github.com/rust-lang/rust/pull/103012
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

self.bump(); |
||
match self.parse_expr() { |
||
Ok(_p) => { |
||
self.sess.emit_err(MissingDotDot { token_span: span, sugg_span: span }); |
Looking better!
Can you actually set the base expression like above? Something like base = ast::StructRest::Base(e)
. Basically emulate the code above. That should suppress the "missing fields x
and y
in initializer of V3
" error below.
Also, can handle the case of ... }
like above?
Contributor
Author
chenyukang
Oct 14, 2022
oo, I left the "missing fields x and y in initializer of V3" intentionally, I thought it may helpful for let developer know which fields are missing.
And for the case of ...}
, we need to suggest something like ..{expr}
? So I left it as before also.
I thought it may helpful for let developer know which fields are missing.
This is extra noise if the developer wrote ...
instead of ..
, which is what your PR is trying to fix, right?
And for the case of
...}
, we need to suggest something like..{expr}
?
Not in the case of a pattern, which is the same place that .. }
is valid.
Basically, we should treat ...
typo as closely to ..
as possible, especially if we're "recovering" parsing here.
It may actually be easier to merge this check with the ..
logic above, since we're basically just duplicating that.
Contributor
Author
chenyukang
Oct 14, 2022
Ok, I will make a update.
Contributor
Author
chenyukang
Oct 14, 2022
For the case of let V3 { z: val, ...} = v
, we already have a check to report:
error: expected field pattern, found `...`
--> /home/cat/code/rust/src/test/ui/parser/issue-102806.rs:23:22
|
23 | let V3 { z: val, ... } = v;
| ^^^ help: to omit remaining fields, use one fewer `.`: `..`
Will keep same as before.
Contributor
Author
chenyukang
Oct 14, 2022
It may actually be easier to merge this check with the
..
logic above, since we're basically just duplicating that.
Tried to merge the two checks, but I found split them seems more easy to read.
That's ok, I don't think it's necessary
</div
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK