9141: fix: Don't inline mutable locals in 'inline_local_variable' r=Veykril a=Veykril

Fixes #9139

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-06-04 18:44:22 +00:00 committed by GitHub
commit d647568db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,6 +182,10 @@ fn inline_usage(ctx: &AssistContext) -> Option<InlineData> {
PathResolution::Local(local) => local,
_ => return None,
};
if local.is_mut(ctx.sema.db) {
cov_mark::hit!(test_not_inline_mut_variable_use);
return None;
}
let bind_pat = match local.source(ctx.db()).value {
Either::Left(ident) => ident,
@ -426,6 +430,19 @@ fn foo() {
);
}
#[test]
fn test_not_inline_mut_variable_use() {
cov_mark::check!(test_not_inline_mut_variable_use);
check_assist_not_applicable(
inline_local_variable,
r"
fn foo() {
let mut a = 1 + 1;
a$0 + 1;
}",
);
}
#[test]
fn test_call_expr() {
check_assist(