From ec6a7f07106e9d90c5d947f726cf9958a31c1d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1?= Date: Sat, 25 Jan 2020 21:07:21 +0100 Subject: fixed inline_local_variable bug --- crates/ra_assists/src/assists/inline_local_variable.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index d0c5c3b8c..83527d904 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; +} + ", + ) + } } -- cgit v1.2.3