2907: fixed inline_local_variable bug #2900 r=matklad a=TomasKralCZ

This also affects issues like #2666.

Co-authored-by: Tomáš <tomas@kral.hk>
This commit is contained in:
bors[bot] 2020-01-26 11:23:22 +00:00 committed by GitHub
commit 13743d1073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,6 +47,9 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<
};
let analyzer = ctx.source_analyzer(bind_pat.syntax(), None);
let refs = analyzer.find_all_refs(&bind_pat);
if refs.is_empty() {
return None;
};
let mut wrap_in_parens = vec![true; refs.len()];
@ -645,4 +648,16 @@ fn foo() {
}",
);
}
#[test]
fn test_not_applicable_if_variable_unused() {
check_assist_not_applicable(
inline_local_variable,
"
fn foo() {
let <|>a = 0;
}
",
)
}
}