mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
handle arbitrary length slices
This commit is contained in:
parent
f353625705
commit
d0e282f6b1
2 changed files with 29 additions and 12 deletions
|
@ -188,10 +188,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
Pat::Slice { prefix, slice, suffix } => {
|
Pat::Slice { prefix, slice, suffix } => {
|
||||||
if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
|
if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
|
||||||
match (prefix.as_slice(), slice, suffix.as_slice()) {
|
match (prefix.as_slice(), slice, suffix.as_slice()) {
|
||||||
([prefix_pat_id], None, []) => {
|
(prefix_pat_ids, None, []) => {
|
||||||
let ty = self.infer_pat(*prefix_pat_id, ¶meters.0[0], default_bm);
|
for pat_id in prefix_pat_ids {
|
||||||
|
self.infer_pat(*pat_id, parameters.as_single(), default_bm);
|
||||||
|
}
|
||||||
|
|
||||||
Ty::apply_one(TypeCtor::Slice, ty)
|
Ty::apply_one(TypeCtor::Slice, parameters.as_single().clone())
|
||||||
},
|
},
|
||||||
_ => Ty::Unknown,
|
_ => Ty::Unknown,
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,28 +143,43 @@ fn infer_pattern_match_slice() {
|
||||||
fn test() {
|
fn test() {
|
||||||
let slice: &[f64] = &[0.0];
|
let slice: &[f64] = &[0.0];
|
||||||
match slice {
|
match slice {
|
||||||
|
&[] => {},
|
||||||
&[a] => {
|
&[a] => {
|
||||||
a;
|
a;
|
||||||
|
},
|
||||||
|
&[b, c] => {
|
||||||
|
b;
|
||||||
|
c;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#),
|
"#),
|
||||||
@r###"
|
@r###"
|
||||||
[11; 129) '{ ... } }': ()
|
[11; 210) '{ ... } }': ()
|
||||||
[21; 26) 'slice': &[f64]
|
[21; 26) 'slice': &[f64]
|
||||||
[37; 43) '&[0.0]': &[f64; _]
|
[37; 43) '&[0.0]': &[f64; _]
|
||||||
[38; 43) '[0.0]': [f64; _]
|
[38; 43) '[0.0]': [f64; _]
|
||||||
[39; 42) '0.0': f64
|
[39; 42) '0.0': f64
|
||||||
[49; 127) 'match ... }': ()
|
[49; 208) 'match ... }': ()
|
||||||
[55; 60) 'slice': &[f64]
|
[55; 60) 'slice': &[f64]
|
||||||
[71; 75) '&[a]': &[f64]
|
[71; 74) '&[]': &[f64]
|
||||||
[72; 75) '[a]': [f64]
|
[72; 74) '[]': [f64]
|
||||||
[73; 74) 'a': f64
|
[78; 80) '{}': ()
|
||||||
[79; 105) '{ ... }': ()
|
[90; 94) '&[a]': &[f64]
|
||||||
[93; 94) 'a': f64
|
[91; 94) '[a]': [f64]
|
||||||
[114; 115) '_': &[f64]
|
[92; 93) 'a': f64
|
||||||
[119; 121) '{}': ()
|
[98; 124) '{ ... }': ()
|
||||||
|
[112; 113) 'a': f64
|
||||||
|
[134; 141) '&[b, c]': &[f64]
|
||||||
|
[135; 141) '[b, c]': [f64]
|
||||||
|
[136; 137) 'b': f64
|
||||||
|
[139; 140) 'c': f64
|
||||||
|
[145; 186) '{ ... }': ()
|
||||||
|
[159; 160) 'b': f64
|
||||||
|
[174; 175) 'c': f64
|
||||||
|
[195; 196) '_': &[f64]
|
||||||
|
[200; 202) '{}': ()
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue