mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Show type hints for & patterns
This commit is contained in:
parent
6bd9fb8525
commit
decc4cb084
1 changed files with 15 additions and 16 deletions
|
@ -122,18 +122,11 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> {
|
|||
|
||||
while let Some(maybe_leaf_pat) = pats_to_process.pop_front() {
|
||||
match &maybe_leaf_pat {
|
||||
ast::Pat::BindPat(bind_pat) => {
|
||||
if let Some(pat) = bind_pat.pat() {
|
||||
pats_to_process.push_back(pat);
|
||||
} else {
|
||||
leaf_pats.push(maybe_leaf_pat);
|
||||
}
|
||||
}
|
||||
ast::Pat::TuplePat(tuple_pat) => {
|
||||
for arg_pat in tuple_pat.args() {
|
||||
pats_to_process.push_back(arg_pat);
|
||||
}
|
||||
}
|
||||
ast::Pat::BindPat(bind_pat) => match bind_pat.pat() {
|
||||
Some(pat) => pats_to_process.push_back(pat),
|
||||
_ => leaf_pats.push(maybe_leaf_pat),
|
||||
},
|
||||
ast::Pat::TuplePat(tuple_pat) => pats_to_process.extend(tuple_pat.args()),
|
||||
ast::Pat::RecordPat(record_pat) => {
|
||||
if let Some(pat_list) = record_pat.record_field_pat_list() {
|
||||
pats_to_process.extend(
|
||||
|
@ -151,10 +144,9 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> {
|
|||
}
|
||||
}
|
||||
ast::Pat::TupleStructPat(tuple_struct_pat) => {
|
||||
for arg_pat in tuple_struct_pat.args() {
|
||||
pats_to_process.push_back(arg_pat);
|
||||
}
|
||||
pats_to_process.extend(tuple_struct_pat.args())
|
||||
}
|
||||
ast::Pat::RefPat(ref_pat) => pats_to_process.extend(ref_pat.pat()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -163,9 +155,10 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::mock_analysis::single_file;
|
||||
use insta::assert_debug_snapshot;
|
||||
|
||||
use crate::mock_analysis::single_file;
|
||||
|
||||
#[test]
|
||||
fn let_statement() {
|
||||
let (analysis, file_id) = single_file(
|
||||
|
@ -202,6 +195,7 @@ fn main() {
|
|||
|
||||
let test = (42, 'a');
|
||||
let (a, (b, c, (d, e), f)) = (2, (3, 4, (6.6, 7.7), 5));
|
||||
let &x = &92;
|
||||
}"#,
|
||||
);
|
||||
|
||||
|
@ -257,6 +251,11 @@ fn main() {
|
|||
kind: TypeHint,
|
||||
label: "f64",
|
||||
},
|
||||
InlayHint {
|
||||
range: [627; 628),
|
||||
kind: TypeHint,
|
||||
label: "i32",
|
||||
},
|
||||
]
|
||||
"###
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue