Repository: rust-lang/rust-analyzer
Pull request #13530 (2022-11-02 12:50:33)

minor: Bump ovsx
CC https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues/1330#note_1033611

lnicola: @bors r+
bors: :pushpin: Commit 2c31028447038b69323eaf30c5beaf0170049150 has been approved by `lnicola`

It is now in the [queue](https://bors.rust-lang.org/homu/queue/rust-analyzer) for this repository.

<!-- @bors r=lnicola 2c31028447038b69323eaf30c5beaf0170049150 -->
<!-- homu: {"type":"Approved","sha":"2c31028447038b69323eaf30c5beaf0170049150","approver":"lnicola","queue":"https://bors.rust-lang.org/homu/queue/rust-analyzer"} -->

Patch:
diff --git a/crates/ide-assists/src/assist_config.rs b/crates/ide-assists/src/assist_config.rs
index b273ebc85a..60d1588a44 100644
--- a/crates/ide-assists/src/assist_config.rs
+++ b/crates/ide-assists/src/assist_config.rs
@@ -14,5 +14,4 @@ pub struct AssistConfig {
     pub allowed: Option<Vec<AssistKind>>,
     pub insert_use: InsertUseConfig,
     pub prefer_no_std: bool,
-    pub assist_emit_must_use: bool,
 }
diff --git a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs
index b97be34c5f..cb75619ced 100644
--- a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs
+++ b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs
@@ -129,15 +129,32 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
                 }
                 Some((path, bound_ident)) => {
                     // If-let.
-                    let pat = make::tuple_struct_pat(path, once(bound_ident));
-                    let let_else_stmt = make::let_else_stmt(
-                        pat.into(),
-                        None,
-                        cond_expr,
-                        ast::make::tail_only_block_expr(early_expression),
-                    );
-                    let let_else_stmt = let_else_stmt.indent(if_indent_level);
-                    let_else_stmt.syntax().clone_for_update()
+                    let match_expr = {
+                        let happy_arm = {
+                            let pat = make::tuple_struct_pat(
+                                path,
+                                once(make::ext::simple_ident_pat(make::name("it")).into()),
+                            );
+                            let expr = {
+                                let path = make::ext::ident_path("it");
+                                make::expr_path(path)
+                            };
+                            make::match_arm(once(pat.into()), None, expr)
+                        };
+
+                        let sad_arm = make::match_arm(
+                            // FIXME: would be cool to use `None` or `Err(_)` if appropriate
+                            once(make::wildcard_pat().into()),
+                            None,
+                            early_expression,
+                        );
+
+                        make::expr_match(cond_expr, make::match_arm_list(vec![happy_arm, sad_arm]))
+                    };
+
+                    let let_stmt = make::let_stmt(bound_ident, None, Some(match_expr));
+                    let let_stmt = let_stmt.indent(if_indent_level);
+                    let_stmt.syntax().clone_for_update()
                 }
             };
 
@@ -221,7 +238,10 @@ fn main(n: Option<String>) {
             r#"
 fn main(n: Option<String>) {
     bar();
-    let Some(n) = n else { return };
+    let n = match n {
+        Some(it) => it,
+        _ => return,
+    };
     foo(n);
 
     // comment
@@ -244,7 +264,10 @@ fn main() {
 "#,
             r#"
 fn main() {
-    let Ok(x) = Err(92) else { return };
+    let x = match Err(92) {
+        Ok(it) => it,
+        _ => return,
+    };
     foo(x);
 }
 "#,
@@ -269,7 +292,10 @@ fn main(n: Option<String>) {
             r#"
 fn main(n: Option<String>) {
     bar();
-    let Some(n) = n else { return };
+    let n = match n {
+        Some(it) => it,
+        _ => return,
+    };
     foo(n);
 
     // comment
@@ -297,7 +323,10 @@ fn main(n: Option<String>) {
             r#"
 fn main(n: Option<String>) {
     bar();
-    let Some(mut n) = n else { return };
+    let mut n = match n {
+        Some(it) => it,
+        _ => return,
+    };
     foo(n);
 
     // comment
@@ -325,7 +354,10 @@ fn main(n: Option<&str>) {
             r#"
 fn main(n: Option<&str>) {
     bar();
-    let Some(ref n) = n else { return };
+    let ref n = match n {
+        Some(it) => it,
+        _ => return,
+    };
     foo(n);
 
     // comment
@@ -380,7 +412,10 @@ fn main() {
             r#"
 fn main() {
     while true {
-        let Some(n) = n else { continue };
+        let n = match n {
+            Some(it) => it,
+            _ => continue,
+        };
         foo(n);
         bar();
     }
@@ -434,7 +469,10 @@ fn main() {
             r#"
 fn main() {
     loop {
-        let Some(n) = n else { continue };
+        let n = match n {
+            Some(it) => it,
+            _ => continue,
+        };
         foo(n);
         bar();
     }
diff --git a/crates/ide-assists/src/handlers/generate_enum_projection_method.rs b/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
index c9aa41c845..bdd3cf4f06 100644
--- a/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
+++ b/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
@@ -124,7 +124,6 @@ fn generate_enum_projection_method(
         happy_case,
         sad_case,
     } = props;
-
     let variant = ctx.find_node_at_offset::<ast::Variant>()?;
     let variant_name = variant.name()?;
     let parent_enum = ast::Adt::Enum(variant.parent_enum());
@@ -145,7 +144,7 @@ fn generate_enum_projection_method(
         ast::StructKind::Unit => return None,
     };
 
-    let fn_name = format!("{fn_name_prefix}_{}", &to_lower_snake_case(&variant_name.text()));
+    let fn_name = format!("{}_{}", fn_name_prefix, &to_lower_snake_case(&variant_name.text()));
 
     // Return early if we've found an existing new fn
     let impl_def = find_struct_impl(ctx, &parent_enum, &[fn_name.clone()])?;
@@ -157,25 +156,15 @@ fn generate_enum_projection_method(
         assist_description,
         target,
         |builder| {
-            let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v));
-
-            let field_type_syntax = field_type.syntax();
-
-            let must_use = if ctx.config.assist_emit_must_use {
-                "#[must_use]\n    "
-            } else {
-                ""
-            };
-
+            let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{v} "));
             let method = format!(
-                "    {must_use}{vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
+                "    {vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type}{return_suffix} {{
         if let Self::{variant_name}{pattern_suffix} = self {{
             {happy_case}({bound_name})
         }} else {{
             {sad_case}
         }}
-    }}"
-            );
+    }}");
 
             add_method_to_adt(builder, &parent_enum, impl_def, &method);
         },
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 4072ae585d..1ed8f2bb5f 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -56,9 +56,6 @@ mod patch_old_style;
 // parsing the old name.
 config_data! {
     struct ConfigData {
-        /// Whether to insert #[must_use] when generating `as_` methods
-        /// for enum variants.
-        assist_emitMustUse: bool               = "false",
         /// Placeholder expression to use for missing expressions in assists.
         assist_expressionFillDefault: ExprFillDefaultDef              = "\"todo\"",
 
@@ -1279,7 +1276,6 @@ impl Config {
             allowed: None,
             insert_use: self.insert_use_config(),
             prefer_no_std: self.data.imports_prefer_no_std,
-            assist_emit_must_use: self.data.assist_emitMustUse,
         }
     }
 
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 8c26009add..4057a75e7c 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -334,10 +334,6 @@ pub fn block_expr(
     ast_from_text(&format!("fn f() {buf}"))
 }
 
-pub fn tail_only_block_expr(tail_expr: ast::Expr) -> ast::BlockExpr {
-    ast_from_text(&format!("fn f() {{ {tail_expr} }}"))
-}
-
 /// Ideally this function wouldn't exist since it involves manual indenting.
 /// It differs from `make::block_expr` by also supporting comments.
 ///
@@ -660,22 +656,6 @@ pub fn let_stmt(
     };
     ast_from_text(&format!("fn f() {{ {text} }}"))
 }
-
-pub fn let_else_stmt(
-    pattern: ast::Pat,
-    ty: Option<ast::Type>,
-    expr: ast::Expr,
-    diverging: ast::BlockExpr,
-) -> ast::LetStmt {
-    let mut text = String::new();
-    format_to!(text, "let {pattern}");
-    if let Some(ty) = ty {
-        format_to!(text, ": {ty}");
-    }
-    format_to!(text, " = {expr} else {diverging};");
-    ast_from_text(&format!("fn f() {{ {text} }}"))
-}
-
 pub fn expr_stmt(expr: ast::Expr) -> ast::ExprStmt {
     let semi = if expr.is_block_like() { "" } else { ";" };
     ast_from_text(&format!("fn f() {{ {expr}{semi} (); }}"))
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 36794efe42..502833de72 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -1,9 +1,3 @@
-[[rust-analyzer.assist.emitMustUse]]rust-analyzer.assist.emitMustUse (default: `false`)::
-+
---
-Whether to insert #[must_use] when generating `as_` methods
-for enum variants.
---
 [[rust-analyzer.assist.expressionFillDefault]]rust-analyzer.assist.expressionFillDefault (default: `"todo"`)::
 +
 --
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json
index a72865d4fe..0b25564e28 100644
--- a/editors/code/package-lock.json
+++ b/editors/code/package-lock.json
@@ -23,7 +23,7 @@
                 "esbuild": "^0.14.48",
                 "eslint": "^8.19.0",
                 "eslint-config-prettier": "^8.5.0",
-                "ovsx": "^0.5.1",
+                "ovsx": "^0.5.2",
                 "prettier": "^2.7.1",
                 "tslib": "^2.4.0",
                 "typescript": "^4.7.4",
@@ -2874,9 +2874,9 @@
             }
         },
         "node_modules/ovsx": {
-            "version": "0.5.1",
-            "resolved": "https://registry.npmjs.org/ovsx/-/ovsx-0.5.1.tgz",
-            "integrity": "sha512-3OWq0l7DuVHi2bd2aQe5+QVQlFIqvrcw3/2vGXL404L6Tr+R4QHtzfnYYghv8CCa85xJHjU0RhcaC7pyXkAUbg==",
+            "version": "0.5.2",
+            "resolved": "https://registry.npmjs.org/ovsx/-/ovsx-0.5.2.tgz",
+            "integrity": "sha512-UbLultRCk46WddeA0Cly4hoRhzBJUiLgbIEViXlgOvV54LbsppClDkMLoCevUUBHoiNdMX2NuiSgURAEXgCZdw==",
             "dev": true,
             "dependencies": {
                 "commander": "^6.1.0",
@@ -5958,9 +5958,9 @@
             }
         },
         "ovsx": {
-            "version": "0.5.1",
-            "resolved": "https://registry.npmjs.org/ovsx/-/ovsx-0.5.1.tgz",
-            "integrity": "sha512-3OWq0l7DuVHi2bd2aQe5+QVQlFIqvrcw3/2vGXL404L6Tr+R4QHtzfnYYghv8CCa85xJHjU0RhcaC7pyXkAUbg==",
+            "version": "0.5.2",
+            "resolved": "https://registry.npmjs.org/ovsx/-/ovsx-0.5.2.tgz",
+            "integrity": "sha512-UbLultRCk46WddeA0Cly4hoRhzBJUiLgbIEViXlgOvV54LbsppClDkMLoCevUUBHoiNdMX2NuiSgURAEXgCZdw==",
             "dev": true,
             "requires": {
                 "commander": "^6.1.0",
diff --git a/editors/code/package.json b/editors/code/package.json
index 0ff6652745..0a2b7d8cfe 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -49,7 +49,7 @@
         "esbuild": "^0.14.48",
         "eslint": "^8.19.0",
         "eslint-config-prettier": "^8.5.0",
-        "ovsx": "^0.5.1",
+        "ovsx": "^0.5.2",
         "prettier": "^2.7.1",
         "tslib": "^2.4.0",
         "typescript": "^4.7.4",
@@ -397,11 +397,6 @@
                     "type": "boolean"
                 },
                 "$generated-start": {},
-                "rust-analyzer.assist.emitMustUse": {
-                    "markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",
-                    "default": false,
-                    "type": "boolean"
-                },
                 "rust-analyzer.assist.expressionFillDefault": {
                     "markdownDescription": "Placeholder expression to use for missing expressions in assists.",
                     "default": "todo",


Test patch:
diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs
index 92ced27c78..f7f2417d07 100644
--- a/crates/ide-assists/src/tests.rs
+++ b/crates/ide-assists/src/tests.rs
@@ -30,7 +30,6 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
         skip_glob_imports: true,
     },
     prefer_no_std: false,
-    assist_emit_must_use: false,
 };
 
 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {