rust-analyzer/crates/ide-assists/src/handlers
bors 3b1b58c225 Auto merge of #15662 - rmehri01:fix_panic_with_return_in_match, r=Veykril
fix: panic with wrapping/unwrapping result return type assists

With the `wrap_return_type_in_result` assist, the following code results in a panic (note the lack of a semicolon):

```rust
fn foo(num: i32) -> $0i32 {
    return num
}

=>

thread 'handlers::wrap_return_type_in_result::tests::wrap_return_in_tail_position' panicked at crates/syntax/src/ted.rs:137:41:
called `Option::unwrap()` on a `None` value
```

I think this is because it first walks the body expression to change any `return` expressions and then walks all tail expressions, resulting in the `return num` being changed twice since it is both a `return` and in tail position. This can also happen when a `match` is in tail position and `return` is used in a branch for example. Not really sure how big of an issue this is in practice though since this seems to be the only case that is impacted and can be reduced to just `num` instead of `return num`.

This also occurs with the `unwrap_result_return_type` assist but panics with the following instead:

```
thread 'handlers::unwrap_result_return_type::tests::wrap_return_in_tail_position' panicked at /rustc/3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e/library/alloc/src/string.rs:1766:29:
assertion failed: self.is_char_boundary(n)
```
2023-09-26 14:18:33 +00:00
..
add_braces.rs fixes 2023-01-21 23:42:11 +05:30
add_explicit_type.rs Add flag to disallow opaque types for DisplayTarget::SourceCode 2023-04-12 19:03:48 +09:00
add_label_to_loop.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
add_lifetime_to_type.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
add_missing_impl_members.rs the "add missing members" assists: supported bracketed default const values 2023-08-08 21:57:55 +04:00
add_missing_match_arms.rs Add a test case to add_missing_match_arms 2023-09-22 13:51:19 +02:00
add_return_type.rs fix some typos 2023-05-01 14:53:25 +08:00
add_turbo_fish.rs Add ExternCrateDecl to HIR 2023-08-02 11:52:55 +02:00
apply_demorgan.rs Rewrite DeMorgan v2 2023-08-08 15:54:58 +02:00
auto_import.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
bind_unused_param.rs Better trait implementation support 2023-08-29 22:56:31 +07:00
bool_to_enum.rs Use parent + and_then instead of ancestors 2023-09-22 08:53:24 +02:00
change_visibility.rs limit change_visibility assist to applicable items 2023-07-22 17:16:51 +03:00
convert_bool_then.rs Parse builtin# syntax 2023-09-05 10:36:35 +02:00
convert_comment_block.rs v4 2023-09-22 13:32:20 +02:00
convert_integer_literal.rs Migrate assists to format args captures, part 1 2022-10-10 15:56:21 -04:00
convert_into_to_from.rs Migrate assists to format args captures, part 1 2022-10-10 15:56:21 -04:00
convert_iter_for_each_to_for.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
convert_let_else_to_match.rs Simplify 2023-03-28 16:32:26 +02:00
convert_match_to_let_else.rs Simplify 2023-03-28 16:32:26 +02:00
convert_named_struct_to_tuple_struct.rs Deunwrap convert_named_struct_to_tuple_struct 2023-08-09 16:40:23 +02:00
convert_nested_function_to_closure.rs Address another round of review comments 2023-04-05 18:48:21 +02:00
convert_to_guarded_return.rs minor : Deunwrap convert_to_guarded_return 2023-08-09 17:17:43 +02:00
convert_tuple_struct_to_named_struct.rs Add render configs for memory layout hovers 2023-05-30 18:36:06 +02:00
convert_two_arm_bool_match_to_matches_macro.rs Allow match to matches assist to trigger on non-literal bool arms 2023-08-01 12:10:38 +02:00
convert_while_to_loop.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
destructure_tuple_binding.rs Updated search to expose some more functions and to make search take the search scope by reference. 2023-07-09 17:30:21 -04:00
desugar_doc_comment.rs v4 2023-09-22 13:32:20 +02:00
expand_glob_import.rs Updated search to expose some more functions and to make search take the search scope by reference. 2023-07-09 17:30:21 -04:00
extract_expressions_from_format_string.rs Don't allocate the format_args template string as an expression 2023-09-06 19:18:12 +02:00
extract_function.rs v3 2023-09-10 23:00:19 +02:00
extract_module.rs Updated search to expose some more functions and to make search take the search scope by reference. 2023-07-09 17:30:21 -04:00
extract_struct_from_enum_variant.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
extract_type_alias.rs Use ConstArg instead of Expr for AstId of InTypeConstId 2023-06-11 00:39:28 +03:30
extract_variable.rs fix: Fix receiver adjustments for extract_variable assist 2023-04-11 14:01:23 +02:00
fix_visibility.rs fix the rest of the nits 2023-07-11 17:32:12 -04:00
flip_binexpr.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
flip_comma.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
flip_trait_bound.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
generate_constant.rs Add flag to disallow opaque types for DisplayTarget::SourceCode 2023-04-12 19:03:48 +09:00
generate_default_from_enum_variant.rs Migrate assists to format args captures, part 2 2022-10-12 02:23:35 -04:00
generate_default_from_new.rs Don't provide generate_default_from_new when impl self ty is missing 2023-08-07 03:23:41 +09:00
generate_delegate_methods.rs Deunwrap generate_delegate_methods 2023-08-09 23:42:52 +02:00
generate_delegate_trait.rs Remove unwraps from Generate delegate trait 2023-08-05 19:23:56 +03:00
generate_deref.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
generate_derive.rs v2 2023-08-16 00:22:08 +02:00
generate_documentation_template.rs Spelling 2023-04-19 09:45:55 -04:00
generate_enum_is_method.rs feat: add multiple getters mode in generate_getter 2022-10-20 16:47:23 +05:30
generate_enum_projection_method.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
generate_enum_variant.rs Add flag to disallow opaque types for DisplayTarget::SourceCode 2023-04-12 19:03:48 +09:00
generate_from_impl_for_enum.rs refactor: use generate_trait_impl_text_intransitive for From-like traits 2022-12-17 22:59:30 +08:00
generate_function.rs remove other unwraps 2023-09-25 11:48:23 +00:00
generate_getter_or_setter.rs Unify getter and setter assists 2023-07-06 12:27:45 +02:00
generate_impl.rs refactor: use generate_trait_impl_text_intransitive for From-like traits 2022-12-17 22:59:30 +08:00
generate_is_empty_from_len.rs Simplify 2023-02-27 15:51:45 +01:00
generate_new.rs Spelling 2023-04-19 09:45:55 -04:00
generate_trait_from_impl.rs Minor changes 2023-07-05 16:45:54 +02:00
inline_call.rs Auto merge of #15432 - alibektas:deunwrap/inline_call, r=Veykril 2023-09-22 07:03:02 +00:00
inline_const_as_literal.rs fix: use render_eval instead of inlined expr 2023-06-06 12:08:11 +02:00
inline_local_variable.rs fix parens when inlining closure local variables 2023-09-21 21:31:15 -07:00
inline_macro.rs Turn unresolved proc macro expansions into missing expressions 2023-08-05 20:00:37 +02:00
inline_type_alias.rs remove needless borrows 2023-01-02 14:52:32 +00:00
into_to_qualified_from.rs Add assist into_to_qualified_from 2023-09-07 23:43:46 +02:00
introduce_named_generic.rs fix: Move cursor before generated generic 2023-03-26 18:10:41 -04:00
introduce_named_lifetime.rs Spelling 2023-04-19 09:45:55 -04:00
invert_if.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
merge_imports.rs a number of code simplifications 2023-01-10 18:48:51 +00:00
merge_match_arms.rs Fix pattern type mismatch in tuples 2023-05-04 16:03:36 +03:30
move_bounds.rs Fmt 2022-09-02 21:18:36 +00:00
move_const_to_impl.rs Updated search to expose some more functions and to make search take the search scope by reference. 2023-07-09 17:30:21 -04:00
move_from_mod_rs.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
move_guard.rs Migrate assists to format args captures, part 3 2022-10-12 02:28:41 -04:00
move_module_to_file.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
move_to_mod_rs.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
number_representation.rs Migrate assists to format args captures, part 3 2022-10-12 02:28:41 -04:00
promote_local_to_const.rs fix: field shorthand overwritten in promote local to const assist 2023-09-11 10:59:23 -07:00
pull_assignment_up.rs Use anonymous lifetime where possible 2023-06-29 23:27:28 +09:00
qualify_method_call.rs Spelling 2023-04-19 09:45:55 -04:00
qualify_path.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
raw_string.rs update assist to include more literals 2023-06-06 00:34:00 +02:00
remove_dbg.rs Parse builtin# syntax 2023-09-05 10:36:35 +02:00
remove_mut.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
remove_parentheses.rs Spelling 2023-04-19 09:45:55 -04:00
remove_unused_imports.rs Deunwrap remove_unused_imports 2023-08-10 01:22:26 +02:00
remove_unused_param.rs Rollback changes in remove_unused_param.rs 2023-08-29 23:06:12 +07:00
reorder_fields.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
reorder_impl_items.rs internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
replace_arith_op.rs Fix replace_arith label 2023-01-17 16:31:34 +02:00
replace_derive_with_manual_impl.rs HiddenDocAttr becomes DocHiddenAttr 2023-07-07 14:15:15 +02:00
replace_if_let_with_match.rs Adjust replace_match_with_if_let applicability range 2023-03-05 16:52:07 +01:00
replace_let_with_if_let.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
replace_method_eager_lazy.rs feature: Make replace_or_with_or_else assists more generally applicable 2023-03-06 22:17:30 +01:00
replace_named_generic_with_impl.rs Updated search to expose some more functions and to make search take the search scope by reference. 2023-07-09 17:30:21 -04:00
replace_qualified_name_with_use.rs Restructure find_path into a separate functions for modules and non-module items 2022-09-13 15:15:27 +02:00
replace_string_with_char.rs Spelling 2023-04-19 09:45:55 -04:00
replace_try_expr_with_match.rs desugar ? operator 2023-03-17 13:08:35 +03:30
replace_turbofish_with_explicit_type.rs Add flag to disallow opaque types for DisplayTarget::SourceCode 2023-04-12 19:03:48 +09:00
sort_items.rs Restrict "sort items" assist inside Impl & Trait 2023-04-17 12:36:32 +02:00
split_import.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
toggle_ignore.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
unmerge_match_arm.rs a number of code simplifications 2023-01-10 18:48:51 +00:00
unmerge_use.rs Give unmerge_use a label explaining what it will affect. 2023-09-16 13:29:03 -07:00
unnecessary_async.rs remove needless borrows 2023-01-02 14:52:32 +00:00
unqualify_method_call.rs Rename assist: convert_ufcs_to_method => unqualify_method_call 2023-01-09 14:23:30 +00:00
unwrap_block.rs Simplify 2023-03-28 16:32:26 +02:00
unwrap_result_return_type.rs fix panic with wrapping/unwrapping result return type assists 2023-09-24 16:00:55 -07:00
unwrap_tuple.rs Migrate assists to format args captures, part 3 2022-10-12 02:28:41 -04:00
wrap_return_type_in_result.rs fix panic with wrapping/unwrapping result return type assists 2023-09-24 16:00:55 -07:00