diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index d0c5c3b8c0..83527d9040 100644 --- a/crates/ra_assists/src/assists/inline_local_variable.rs +++ b/crates/ra_assists/src/assists/inline_local_variable.rs @@ -47,6 +47,9 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> 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; +} + ", + ) + } }