mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Handle unordered fields in struct patterns
This commit is contained in:
parent
3ffcb2658c
commit
2431ff5987
1 changed files with 12 additions and 2 deletions
|
@ -857,8 +857,18 @@ impl Fields {
|
||||||
self.replace_with_fieldpats(args.iter().copied())
|
self.replace_with_fieldpats(args.iter().copied())
|
||||||
}
|
}
|
||||||
Pat::Record { args, ellipsis, .. } => {
|
Pat::Record { args, ellipsis, .. } => {
|
||||||
// FIXME(iDawer) handle ellipsis.
|
let variant_id =
|
||||||
self.replace_with_fieldpats(args.iter().map(|field_pat| field_pat.pat))
|
cx.infer.variant_resolution_for_pat(pat).unwrap_or_else(|| todo!());
|
||||||
|
let variant_data = variant_id.variant_data(cx.db.upcast());
|
||||||
|
|
||||||
|
let new_pats = args.iter().map(|field_pat| {
|
||||||
|
// TODO: field lookup is inefficient
|
||||||
|
let raw =
|
||||||
|
variant_data.field(&field_pat.name).unwrap_or_else(|| todo!()).into_raw();
|
||||||
|
let idx = u32::from(raw) as usize;
|
||||||
|
(idx, field_pat.pat)
|
||||||
|
});
|
||||||
|
self.replace_fields_indexed(new_pats)
|
||||||
}
|
}
|
||||||
Pat::Slice { .. } => {
|
Pat::Slice { .. } => {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue