about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-12-30 11:30:32 +0000
committerGitHub <noreply@github.com>2024-12-30 11:30:32 +0000
commit56e05dc2bc9c0460e4797de99aab5b11283b535b (patch)
tree48c99e726d8fbf996d991cd70124dc5c13b87b78 /src/tools/rust-analyzer
parent39ba498c8c17c8c717a1774dc02c98fff0ee0167 (diff)
parent6fa3b3f85b5418a340a947a0f03b6a3177187782 (diff)
downloadrust-56e05dc2bc9c0460e4797de99aab5b11283b535b.tar.gz
rust-56e05dc2bc9c0460e4797de99aab5b11283b535b.zip
Merge pull request #18794 from 1hakusai1/fix_fill_match_arm_in_tokio_main
Fix bug of "fill match arm" action in tokio::main macro
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs
index 236d33878ed..b022baf4cb5 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs
@@ -261,7 +261,9 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
             }
 
             if let Some(cap) = ctx.config.snippet_cap {
-                if let Some(it) = first_new_arm.and_then(|arm| arm.syntax().descendants().find_map(ast::WildcardPat::cast)) {
+                if let Some(it) = first_new_arm
+                    .and_then(|arm| arm.syntax().descendants().find_map(ast::WildcardPat::cast))
+                {
                     edit.add_placeholder_snippet(cap, it);
                 }
 
@@ -287,14 +289,10 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
                         syntax::SyntaxElement::from(edit.make_syntax_mut(it))
                     }
                     syntax::SyntaxElement::Token(it) => {
-                        // Don't have a way to make tokens mut, so instead make the parent mut
-                        // and find the token again
-                        let parent =
-                            edit.make_syntax_mut(it.parent().expect("Token must have a parent."));
-                        let mut_token =
-                            parent.covering_element(it.text_range()).into_token().expect("Covering element cannot be found. Range may be beyond the current node's range");
-
-                        syntax::SyntaxElement::from(mut_token)
+                        // If a token is found, it is '{' or '}'
+                        // The parent is `{ ... }`
+                        let parent = it.parent().expect("Token must have a parent.");
+                        syntax::SyntaxElement::from(edit.make_syntax_mut(parent))
                     }
                 }
             };