aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs23
-rw-r--r--crates/ra_assists/src/handlers/add_missing_impl_members.rs194
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs16
-rw-r--r--crates/ra_assists/src/handlers/inline_local_variable.rs1
-rw-r--r--crates/ra_assists/src/handlers/introduce_variable.rs2
-rw-r--r--crates/ra_assists/src/handlers/move_guard.rs4
-rw-r--r--crates/ra_assists/src/handlers/unwrap_block.rs348
-rw-r--r--crates/ra_assists/src/lib.rs2
-rw-r--r--crates/ra_fmt/src/lib.rs1
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs2
-rw-r--r--crates/ra_hir_def/src/attr.rs1
-rw-r--r--crates/ra_hir_def/src/body/lower.rs21
-rw-r--r--crates/ra_hir_def/src/expr.rs4
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs29
-rw-r--r--crates/ra_hir_def/src/nameres/tests/macros.rs37
-rw-r--r--crates/ra_hir_def/src/path/lower.rs15
-rw-r--r--crates/ra_hir_expand/src/builtin_derive.rs2
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs4
-rw-r--r--crates/ra_hir_expand/src/db.rs3
-rw-r--r--crates/ra_hir_expand/src/hygiene.rs31
-rw-r--r--crates/ra_hir_expand/src/lib.rs2
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs5
-rw-r--r--crates/ra_hir_ty/src/tests/macros.rs26
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs32
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide/src/folding_ranges.rs2
-rw-r--r--crates/ra_ide/src/join_lines.rs3
-rw-r--r--crates/ra_ide/src/syntax_tree.rs77
-rw-r--r--crates/ra_mbe/src/tests.rs152
-rw-r--r--crates/ra_parser/src/grammar.rs4
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs26
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs74
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
-rw-r--r--crates/ra_parser/src/grammar/type_args.rs2
-rw-r--r--crates/ra_parser/src/lib.rs2
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs2
-rw-r--r--crates/ra_syntax/src/ast.rs4
-rw-r--r--crates/ra_syntax/src/ast/edit.rs2
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs33
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs4
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs81
-rw-r--r--crates/ra_syntax/src/ast/make.rs8
-rw-r--r--crates/ra_syntax/src/lib.rs7
-rw-r--r--crates/ra_syntax/src/validation/block.rs20
-rw-r--r--crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast63
-rw-r--r--crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast61
-rw-r--r--crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast45
-rw-r--r--crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast165
-rw-r--r--crates/ra_syntax/test_data/parser/err/0019_let_recover.rast166
-rw-r--r--crates/ra_syntax/test_data/parser/err/0020_fn_recover.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0021_incomplete_param.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/err/0022_bad_exprs.rast229
-rw-r--r--crates/ra_syntax/test_data/parser/err/0023_mismatched_paren.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast430
-rw-r--r--crates/ra_syntax/test_data/parser/err/0025_nope.rast360
-rw-r--r--crates/ra_syntax/test_data/parser/err/0027_incomplere_where_for.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0029_field_completion.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/err/0031_block_inner_attrs.rast214
-rw-r--r--crates/ra_syntax/test_data/parser/err/0032_match_arms_inner_attrs.rast361
-rw-r--r--crates/ra_syntax/test_data/parser/err/0033_match_arms_outer_attrs.rast103
-rw-r--r--crates/ra_syntax/test_data/parser/err/0034_bad_box_pattern.rast155
-rw-r--r--crates/ra_syntax/test_data/parser/err/0035_use_recover.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/err/0039_lambda_recovery.rast121
-rw-r--r--crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast71
-rw-r--r--crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0002_misplaced_label_err.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0006_unsafe_block_in_mod.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0007_async_without_semicolon.rast37
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0008_pub_expr.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rast92
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_bad_tuple_index_expr.rast77
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_record_literal_before_ellipsis_recovery.rast71
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0003_where_pred_for.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0005_function_type_params.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0006_self_param.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0008_path_part.rast169
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0009_loop_expr.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0011_field_expr.rast95
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0015_continue_expr.rast48
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0018_arb_self_types.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rast65
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0024_slice_pat.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0026_tuple_pat_fields.rast185
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0027_ref_pat.rast75
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0029_cast_expr.rast155
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0030_cond.rast365
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0031_while_expr.rast149
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0034_break_expr.rast84
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0037_qual_paths.rast67
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0038_full_range_expr.rast33
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0040_crate_keyword_vis.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0042_call_expr.rast271
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0044_block_items.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0045_param_list_opt_patterns.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0048_path_type_with_bounds.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0053_path_expr.rast167
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0055_literal_pattern.rast129
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0056_where_clause.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0058_range_pat.rast141
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0059_match_arms_commas.rast94
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_record_lit.rast225
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0062_mod_contents.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0064_if_expr.rast229
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rast279
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0070_stmt_bin_expr_ambiguity.rast79
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0071_match_expr.rast165
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0072_return_expr.rast33
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0074_stmt_postfix_expr_ambiguity.rast98
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0075_block.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0076_function_where_clause.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0077_try_expr.rast27
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0080_postfix_range.rast167
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rast85
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0085_expr_literals.rast247
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0086_function_ret_type.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0088_break_ambiguity.rast112
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0093_index_expr.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0095_placeholder_pat.rast33
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0096_no_semi_after_block.rast229
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0099_param_list.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0100_for_expr.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0102_record_field_pat_list.rast241
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0103_array_expr.rast85
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0106_lambda_expr.rast251
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0107_method_call_expr.rast101
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0108_tuple_expr.rast53
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0109_label.rast108
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0111_tuple_pat.rast155
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0112_bind_pat.rast231
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0113_nocontentexpr.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_match_guard.rast71
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0120_match_arms_inner_attribute.rast137
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0121_match_arms_outer_attributes.rast267
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_crate_keyword_path.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_record_literal_field_with_attr.rast71
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0126_attr_on_expr_stmt.rast172
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0127_attr_on_last_expr_in_block.rast92
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_let_stmt.rast231
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_try_block_expr.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_box_expr.rast155
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0134_nocontentexpr_after_item.rast102
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0137_await_expr.rast115
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_associated_type_bounds.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rast106
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0139_param_outer_arg.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rast197
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0144_dot_dot_pat.rast887
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rast127
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.rast61
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_arg_with_attr.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0155_closure_params.rast115
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_fn_def_param.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_or_pattern.rast199
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rast50
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_lambda_ret_block.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast45
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0161_labeled_block.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0161_labeled_block.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0162_unsafe_block.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0162_unsafe_block.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0005_fn_item.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0008_mod_item.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0011_outer_attribute.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0012_visibility.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0017_attr_trailing_comma.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0025_extern_fn_in_block.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0026_const_fn_in_block.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0027_unsafe_fn_in_block.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0028_operator_binding_power.rast347
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0029_range_forms.rast279
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_string_suffixes.rast103
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0032_where_for.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0033_label_break.rast407
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0034_crate_path_in_call.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast3912
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0036_fully_qualified.rast27
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0038_where_pred_type.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0039_raw_fn_item.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0041_raw_keywords.rast77
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0042_ufcs_call_list.rast97
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0043_complex_assignment.rast133
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0044_let_attrs.rast123
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0045_block_inner_attrs.rast196
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0047_minus_in_inner_pattern.rast495
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0048_compound_assignment.rast373
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0049_async_block.rast47
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0050_async_block_as_argument.rast56
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0051_parameter_attrs.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rast135
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0054_qual_path_in_type_arg.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0055_dot_dot_dot.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0056_neq_in_type.rast106
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0057_loop_in_call.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.rast169
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0059_loops_in_parens.rast174
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0060_as_range.rast87
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rast29
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0062_macro_2.0.rast205
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0064_impl_fn_params.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rast5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_plus_after_fn_trait_bound.rast5
-rw-r--r--crates/rust-analyzer/src/caps.rs2
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs10
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs4
233 files changed, 11268 insertions, 10983 deletions
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index e4fa9ee36..6696cc832 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -180,7 +180,9 @@ trait Trait<T> {
180} 180}
181 181
182impl Trait<u32> for () { 182impl Trait<u32> for () {
183 fn foo(&self) -> u32 { todo!() } 183 fn foo(&self) -> u32 {
184 todo!()
185 }
184 186
185} 187}
186"#####, 188"#####,
@@ -726,3 +728,22 @@ use std::{collections::HashMap};
726"#####, 728"#####,
727 ) 729 )
728} 730}
731
732#[test]
733fn doctest_unwrap_block() {
734 check(
735 "unwrap_block",
736 r#####"
737fn foo() {
738 if true {<|>
739 println!("foo");
740 }
741}
742"#####,
743 r#####"
744fn foo() {
745 println!("foo");
746}
747"#####,
748 )
749}
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
index 2d6d44980..e466c9a86 100644
--- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
@@ -1,6 +1,10 @@
1use hir::HasSource; 1use hir::HasSource;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, edit, make, AstNode, NameOwner}, 3 ast::{
4 self,
5 edit::{self, IndentLevel},
6 make, AstNode, NameOwner,
7 },
4 SmolStr, 8 SmolStr,
5}; 9};
6 10
@@ -40,7 +44,9 @@ enum AddMissingImplMembersMode {
40// } 44// }
41// 45//
42// impl Trait<u32> for () { 46// impl Trait<u32> for () {
43// fn foo(&self) -> u32 { todo!() } 47// fn foo(&self) -> u32 {
48// todo!()
49// }
44// 50//
45// } 51// }
46// ``` 52// ```
@@ -165,7 +171,9 @@ fn add_missing_impl_members_inner(
165 171
166fn add_body(fn_def: ast::FnDef) -> ast::FnDef { 172fn add_body(fn_def: ast::FnDef) -> ast::FnDef {
167 if fn_def.body().is_none() { 173 if fn_def.body().is_none() {
168 fn_def.with_body(make::block_from_expr(make::expr_todo())) 174 let body = make::block_expr(None, Some(make::expr_todo()));
175 let body = IndentLevel(1).increase_indent(body);
176 fn_def.with_body(body)
169 } else { 177 } else {
170 fn_def 178 fn_def
171 } 179 }
@@ -181,7 +189,7 @@ mod tests {
181 fn test_add_missing_impl_members() { 189 fn test_add_missing_impl_members() {
182 check_assist( 190 check_assist(
183 add_missing_impl_members, 191 add_missing_impl_members,
184 " 192 r#"
185trait Foo { 193trait Foo {
186 type Output; 194 type Output;
187 195
@@ -197,8 +205,8 @@ struct S;
197impl Foo for S { 205impl Foo for S {
198 fn bar(&self) {} 206 fn bar(&self) {}
199<|> 207<|>
200}", 208}"#,
201 " 209 r#"
202trait Foo { 210trait Foo {
203 type Output; 211 type Output;
204 212
@@ -215,10 +223,14 @@ impl Foo for S {
215 fn bar(&self) {} 223 fn bar(&self) {}
216 <|>type Output; 224 <|>type Output;
217 const CONST: usize = 42; 225 const CONST: usize = 42;
218 fn foo(&self) { todo!() } 226 fn foo(&self) {
219 fn baz(&self) { todo!() } 227 todo!()
228 }
229 fn baz(&self) {
230 todo!()
231 }
220 232
221}", 233}"#,
222 ); 234 );
223 } 235 }
224 236
@@ -226,7 +238,7 @@ impl Foo for S {
226 fn test_copied_overriden_members() { 238 fn test_copied_overriden_members() {
227 check_assist( 239 check_assist(
228 add_missing_impl_members, 240 add_missing_impl_members,
229 " 241 r#"
230trait Foo { 242trait Foo {
231 fn foo(&self); 243 fn foo(&self);
232 fn bar(&self) -> bool { true } 244 fn bar(&self) -> bool { true }
@@ -238,8 +250,8 @@ struct S;
238impl Foo for S { 250impl Foo for S {
239 fn bar(&self) {} 251 fn bar(&self) {}
240<|> 252<|>
241}", 253}"#,
242 " 254 r#"
243trait Foo { 255trait Foo {
244 fn foo(&self); 256 fn foo(&self);
245 fn bar(&self) -> bool { true } 257 fn bar(&self) -> bool { true }
@@ -250,9 +262,11 @@ struct S;
250 262
251impl Foo for S { 263impl Foo for S {
252 fn bar(&self) {} 264 fn bar(&self) {}
253 <|>fn foo(&self) { todo!() } 265 <|>fn foo(&self) {
266 todo!()
267 }
254 268
255}", 269}"#,
256 ); 270 );
257 } 271 }
258 272
@@ -260,16 +274,18 @@ impl Foo for S {
260 fn test_empty_impl_def() { 274 fn test_empty_impl_def() {
261 check_assist( 275 check_assist(
262 add_missing_impl_members, 276 add_missing_impl_members,
263 " 277 r#"
264trait Foo { fn foo(&self); } 278trait Foo { fn foo(&self); }
265struct S; 279struct S;
266impl Foo for S { <|> }", 280impl Foo for S { <|> }"#,
267 " 281 r#"
268trait Foo { fn foo(&self); } 282trait Foo { fn foo(&self); }
269struct S; 283struct S;
270impl Foo for S { 284impl Foo for S {
271 <|>fn foo(&self) { todo!() } 285 <|>fn foo(&self) {
272}", 286 todo!()
287 }
288}"#,
273 ); 289 );
274 } 290 }
275 291
@@ -277,16 +293,18 @@ impl Foo for S {
277 fn fill_in_type_params_1() { 293 fn fill_in_type_params_1() {
278 check_assist( 294 check_assist(
279 add_missing_impl_members, 295 add_missing_impl_members,
280 " 296 r#"
281trait Foo<T> { fn foo(&self, t: T) -> &T; } 297trait Foo<T> { fn foo(&self, t: T) -> &T; }
282struct S; 298struct S;
283impl Foo<u32> for S { <|> }", 299impl Foo<u32> for S { <|> }"#,
284 " 300 r#"
285trait Foo<T> { fn foo(&self, t: T) -> &T; } 301trait Foo<T> { fn foo(&self, t: T) -> &T; }
286struct S; 302struct S;
287impl Foo<u32> for S { 303impl Foo<u32> for S {
288 <|>fn foo(&self, t: u32) -> &u32 { todo!() } 304 <|>fn foo(&self, t: u32) -> &u32 {
289}", 305 todo!()
306 }
307}"#,
290 ); 308 );
291 } 309 }
292 310
@@ -294,16 +312,18 @@ impl Foo<u32> for S {
294 fn fill_in_type_params_2() { 312 fn fill_in_type_params_2() {
295 check_assist( 313 check_assist(
296 add_missing_impl_members, 314 add_missing_impl_members,
297 " 315 r#"
298trait Foo<T> { fn foo(&self, t: T) -> &T; } 316trait Foo<T> { fn foo(&self, t: T) -> &T; }
299struct S; 317struct S;
300impl<U> Foo<U> for S { <|> }", 318impl<U> Foo<U> for S { <|> }"#,
301 " 319 r#"
302trait Foo<T> { fn foo(&self, t: T) -> &T; } 320trait Foo<T> { fn foo(&self, t: T) -> &T; }
303struct S; 321struct S;
304impl<U> Foo<U> for S { 322impl<U> Foo<U> for S {
305 <|>fn foo(&self, t: U) -> &U { todo!() } 323 <|>fn foo(&self, t: U) -> &U {
306}", 324 todo!()
325 }
326}"#,
307 ); 327 );
308 } 328 }
309 329
@@ -311,16 +331,18 @@ impl<U> Foo<U> for S {
311 fn test_cursor_after_empty_impl_def() { 331 fn test_cursor_after_empty_impl_def() {
312 check_assist( 332 check_assist(
313 add_missing_impl_members, 333 add_missing_impl_members,
314 " 334 r#"
315trait Foo { fn foo(&self); } 335trait Foo { fn foo(&self); }
316struct S; 336struct S;
317impl Foo for S {}<|>", 337impl Foo for S {}<|>"#,
318 " 338 r#"
319trait Foo { fn foo(&self); } 339trait Foo { fn foo(&self); }
320struct S; 340struct S;
321impl Foo for S { 341impl Foo for S {
322 <|>fn foo(&self) { todo!() } 342 <|>fn foo(&self) {
323}", 343 todo!()
344 }
345}"#,
324 ) 346 )
325 } 347 }
326 348
@@ -328,22 +350,24 @@ impl Foo for S {
328 fn test_qualify_path_1() { 350 fn test_qualify_path_1() {
329 check_assist( 351 check_assist(
330 add_missing_impl_members, 352 add_missing_impl_members,
331 " 353 r#"
332mod foo { 354mod foo {
333 pub struct Bar; 355 pub struct Bar;
334 trait Foo { fn foo(&self, bar: Bar); } 356 trait Foo { fn foo(&self, bar: Bar); }
335} 357}
336struct S; 358struct S;
337impl foo::Foo for S { <|> }", 359impl foo::Foo for S { <|> }"#,
338 " 360 r#"
339mod foo { 361mod foo {
340 pub struct Bar; 362 pub struct Bar;
341 trait Foo { fn foo(&self, bar: Bar); } 363 trait Foo { fn foo(&self, bar: Bar); }
342} 364}
343struct S; 365struct S;
344impl foo::Foo for S { 366impl foo::Foo for S {
345 <|>fn foo(&self, bar: foo::Bar) { todo!() } 367 <|>fn foo(&self, bar: foo::Bar) {
346}", 368 todo!()
369 }
370}"#,
347 ); 371 );
348 } 372 }
349 373
@@ -351,22 +375,24 @@ impl foo::Foo for S {
351 fn test_qualify_path_generic() { 375 fn test_qualify_path_generic() {
352 check_assist( 376 check_assist(
353 add_missing_impl_members, 377 add_missing_impl_members,
354 " 378 r#"
355mod foo { 379mod foo {
356 pub struct Bar<T>; 380 pub struct Bar<T>;
357 trait Foo { fn foo(&self, bar: Bar<u32>); } 381 trait Foo { fn foo(&self, bar: Bar<u32>); }
358} 382}
359struct S; 383struct S;
360impl foo::Foo for S { <|> }", 384impl foo::Foo for S { <|> }"#,
361 " 385 r#"
362mod foo { 386mod foo {
363 pub struct Bar<T>; 387 pub struct Bar<T>;
364 trait Foo { fn foo(&self, bar: Bar<u32>); } 388 trait Foo { fn foo(&self, bar: Bar<u32>); }
365} 389}
366struct S; 390struct S;
367impl foo::Foo for S { 391impl foo::Foo for S {
368 <|>fn foo(&self, bar: foo::Bar<u32>) { todo!() } 392 <|>fn foo(&self, bar: foo::Bar<u32>) {
369}", 393 todo!()
394 }
395}"#,
370 ); 396 );
371 } 397 }
372 398
@@ -374,22 +400,24 @@ impl foo::Foo for S {
374 fn test_qualify_path_and_substitute_param() { 400 fn test_qualify_path_and_substitute_param() {
375 check_assist( 401 check_assist(
376 add_missing_impl_members, 402 add_missing_impl_members,
377 " 403 r#"
378mod foo { 404mod foo {
379 pub struct Bar<T>; 405 pub struct Bar<T>;
380 trait Foo<T> { fn foo(&self, bar: Bar<T>); } 406 trait Foo<T> { fn foo(&self, bar: Bar<T>); }
381} 407}
382struct S; 408struct S;
383impl foo::Foo<u32> for S { <|> }", 409impl foo::Foo<u32> for S { <|> }"#,
384 " 410 r#"
385mod foo { 411mod foo {
386 pub struct Bar<T>; 412 pub struct Bar<T>;
387 trait Foo<T> { fn foo(&self, bar: Bar<T>); } 413 trait Foo<T> { fn foo(&self, bar: Bar<T>); }
388} 414}
389struct S; 415struct S;
390impl foo::Foo<u32> for S { 416impl foo::Foo<u32> for S {
391 <|>fn foo(&self, bar: foo::Bar<u32>) { todo!() } 417 <|>fn foo(&self, bar: foo::Bar<u32>) {
392}", 418 todo!()
419 }
420}"#,
393 ); 421 );
394 } 422 }
395 423
@@ -398,15 +426,15 @@ impl foo::Foo<u32> for S {
398 // when substituting params, the substituted param should not be qualified! 426 // when substituting params, the substituted param should not be qualified!
399 check_assist( 427 check_assist(
400 add_missing_impl_members, 428 add_missing_impl_members,
401 " 429 r#"
402mod foo { 430mod foo {
403 trait Foo<T> { fn foo(&self, bar: T); } 431 trait Foo<T> { fn foo(&self, bar: T); }
404 pub struct Param; 432 pub struct Param;
405} 433}
406struct Param; 434struct Param;
407struct S; 435struct S;
408impl foo::Foo<Param> for S { <|> }", 436impl foo::Foo<Param> for S { <|> }"#,
409 " 437 r#"
410mod foo { 438mod foo {
411 trait Foo<T> { fn foo(&self, bar: T); } 439 trait Foo<T> { fn foo(&self, bar: T); }
412 pub struct Param; 440 pub struct Param;
@@ -414,8 +442,10 @@ mod foo {
414struct Param; 442struct Param;
415struct S; 443struct S;
416impl foo::Foo<Param> for S { 444impl foo::Foo<Param> for S {
417 <|>fn foo(&self, bar: Param) { todo!() } 445 <|>fn foo(&self, bar: Param) {
418}", 446 todo!()
447 }
448}"#,
419 ); 449 );
420 } 450 }
421 451
@@ -423,15 +453,15 @@ impl foo::Foo<Param> for S {
423 fn test_qualify_path_associated_item() { 453 fn test_qualify_path_associated_item() {
424 check_assist( 454 check_assist(
425 add_missing_impl_members, 455 add_missing_impl_members,
426 " 456 r#"
427mod foo { 457mod foo {
428 pub struct Bar<T>; 458 pub struct Bar<T>;
429 impl Bar<T> { type Assoc = u32; } 459 impl Bar<T> { type Assoc = u32; }
430 trait Foo { fn foo(&self, bar: Bar<u32>::Assoc); } 460 trait Foo { fn foo(&self, bar: Bar<u32>::Assoc); }
431} 461}
432struct S; 462struct S;
433impl foo::Foo for S { <|> }", 463impl foo::Foo for S { <|> }"#,
434 " 464 r#"
435mod foo { 465mod foo {
436 pub struct Bar<T>; 466 pub struct Bar<T>;
437 impl Bar<T> { type Assoc = u32; } 467 impl Bar<T> { type Assoc = u32; }
@@ -439,8 +469,10 @@ mod foo {
439} 469}
440struct S; 470struct S;
441impl foo::Foo for S { 471impl foo::Foo for S {
442 <|>fn foo(&self, bar: foo::Bar<u32>::Assoc) { todo!() } 472 <|>fn foo(&self, bar: foo::Bar<u32>::Assoc) {
443}", 473 todo!()
474 }
475}"#,
444 ); 476 );
445 } 477 }
446 478
@@ -448,15 +480,15 @@ impl foo::Foo for S {
448 fn test_qualify_path_nested() { 480 fn test_qualify_path_nested() {
449 check_assist( 481 check_assist(
450 add_missing_impl_members, 482 add_missing_impl_members,
451 " 483 r#"
452mod foo { 484mod foo {
453 pub struct Bar<T>; 485 pub struct Bar<T>;
454 pub struct Baz; 486 pub struct Baz;
455 trait Foo { fn foo(&self, bar: Bar<Baz>); } 487 trait Foo { fn foo(&self, bar: Bar<Baz>); }
456} 488}
457struct S; 489struct S;
458impl foo::Foo for S { <|> }", 490impl foo::Foo for S { <|> }"#,
459 " 491 r#"
460mod foo { 492mod foo {
461 pub struct Bar<T>; 493 pub struct Bar<T>;
462 pub struct Baz; 494 pub struct Baz;
@@ -464,8 +496,10 @@ mod foo {
464} 496}
465struct S; 497struct S;
466impl foo::Foo for S { 498impl foo::Foo for S {
467 <|>fn foo(&self, bar: foo::Bar<foo::Baz>) { todo!() } 499 <|>fn foo(&self, bar: foo::Bar<foo::Baz>) {
468}", 500 todo!()
501 }
502}"#,
469 ); 503 );
470 } 504 }
471 505
@@ -473,22 +507,24 @@ impl foo::Foo for S {
473 fn test_qualify_path_fn_trait_notation() { 507 fn test_qualify_path_fn_trait_notation() {
474 check_assist( 508 check_assist(
475 add_missing_impl_members, 509 add_missing_impl_members,
476 " 510 r#"
477mod foo { 511mod foo {
478 pub trait Fn<Args> { type Output; } 512 pub trait Fn<Args> { type Output; }
479 trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); } 513 trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); }
480} 514}
481struct S; 515struct S;
482impl foo::Foo for S { <|> }", 516impl foo::Foo for S { <|> }"#,
483 " 517 r#"
484mod foo { 518mod foo {
485 pub trait Fn<Args> { type Output; } 519 pub trait Fn<Args> { type Output; }
486 trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); } 520 trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); }
487} 521}
488struct S; 522struct S;
489impl foo::Foo for S { 523impl foo::Foo for S {
490 <|>fn foo(&self, bar: dyn Fn(u32) -> i32) { todo!() } 524 <|>fn foo(&self, bar: dyn Fn(u32) -> i32) {
491}", 525 todo!()
526 }
527}"#,
492 ); 528 );
493 } 529 }
494 530
@@ -496,10 +532,10 @@ impl foo::Foo for S {
496 fn test_empty_trait() { 532 fn test_empty_trait() {
497 check_assist_not_applicable( 533 check_assist_not_applicable(
498 add_missing_impl_members, 534 add_missing_impl_members,
499 " 535 r#"
500trait Foo; 536trait Foo;
501struct S; 537struct S;
502impl Foo for S { <|> }", 538impl Foo for S { <|> }"#,
503 ) 539 )
504 } 540 }
505 541
@@ -507,13 +543,13 @@ impl Foo for S { <|> }",
507 fn test_ignore_unnamed_trait_members_and_default_methods() { 543 fn test_ignore_unnamed_trait_members_and_default_methods() {
508 check_assist_not_applicable( 544 check_assist_not_applicable(
509 add_missing_impl_members, 545 add_missing_impl_members,
510 " 546 r#"
511trait Foo { 547trait Foo {
512 fn (arg: u32); 548 fn (arg: u32);
513 fn valid(some: u32) -> bool { false } 549 fn valid(some: u32) -> bool { false }
514} 550}
515struct S; 551struct S;
516impl Foo for S { <|> }", 552impl Foo for S { <|> }"#,
517 ) 553 )
518 } 554 }
519 555
@@ -544,7 +580,9 @@ trait Foo {
544struct S; 580struct S;
545impl Foo for S { 581impl Foo for S {
546 <|>type Output; 582 <|>type Output;
547 fn foo(&self) { todo!() } 583 fn foo(&self) {
584 todo!()
585 }
548}"#, 586}"#,
549 ) 587 )
550 } 588 }
@@ -553,7 +591,7 @@ impl Foo for S {
553 fn test_default_methods() { 591 fn test_default_methods() {
554 check_assist( 592 check_assist(
555 add_missing_default_members, 593 add_missing_default_members,
556 " 594 r#"
557trait Foo { 595trait Foo {
558 type Output; 596 type Output;
559 597
@@ -563,8 +601,8 @@ trait Foo {
563 fn foo(some: u32) -> bool; 601 fn foo(some: u32) -> bool;
564} 602}
565struct S; 603struct S;
566impl Foo for S { <|> }", 604impl Foo for S { <|> }"#,
567 " 605 r#"
568trait Foo { 606trait Foo {
569 type Output; 607 type Output;
570 608
@@ -576,7 +614,7 @@ trait Foo {
576struct S; 614struct S;
577impl Foo for S { 615impl Foo for S {
578 <|>fn valid(some: u32) -> bool { false } 616 <|>fn valid(some: u32) -> bool { false }
579}", 617}"#,
580 ) 618 )
581 } 619 }
582} 620}
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs
index ea6c56f8c..eede2fe91 100644
--- a/crates/ra_assists/src/handlers/early_return.rs
+++ b/crates/ra_assists/src/handlers/early_return.rs
@@ -2,7 +2,7 @@ use std::{iter::once, ops::RangeInclusive};
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 algo::replace_children, 4 algo::replace_children,
5 ast::{self, edit::IndentLevel, make, Block, Pat::TupleStructPat}, 5 ast::{self, edit::IndentLevel, make},
6 AstNode, 6 AstNode,
7 SyntaxKind::{FN_DEF, LOOP_EXPR, L_CURLY, R_CURLY, WHILE_EXPR, WHITESPACE}, 7 SyntaxKind::{FN_DEF, LOOP_EXPR, L_CURLY, R_CURLY, WHILE_EXPR, WHITESPACE},
8 SyntaxNode, 8 SyntaxNode,
@@ -47,7 +47,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
47 // Check if there is an IfLet that we can handle. 47 // Check if there is an IfLet that we can handle.
48 let if_let_pat = match cond.pat() { 48 let if_let_pat = match cond.pat() {
49 None => None, // No IfLet, supported. 49 None => None, // No IfLet, supported.
50 Some(TupleStructPat(pat)) if pat.args().count() == 1 => { 50 Some(ast::Pat::TupleStructPat(pat)) if pat.args().count() == 1 => {
51 let path = pat.path()?; 51 let path = pat.path()?;
52 match path.qualifier() { 52 match path.qualifier() {
53 None => { 53 None => {
@@ -61,9 +61,9 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
61 }; 61 };
62 62
63 let cond_expr = cond.expr()?; 63 let cond_expr = cond.expr()?;
64 let then_block = if_expr.then_branch()?.block()?; 64 let then_block = if_expr.then_branch()?;
65 65
66 let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::Block::cast)?; 66 let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?;
67 67
68 if parent_block.expr()? != if_expr.clone().into() { 68 if parent_block.expr()? != if_expr.clone().into() {
69 return None; 69 return None;
@@ -80,7 +80,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
80 return None; 80 return None;
81 } 81 }
82 82
83 let parent_container = parent_block.syntax().parent()?.parent()?; 83 let parent_container = parent_block.syntax().parent()?;
84 84
85 let early_expression: ast::Expr = match parent_container.kind() { 85 let early_expression: ast::Expr = match parent_container.kind() {
86 WHILE_EXPR | LOOP_EXPR => make::expr_continue(), 86 WHILE_EXPR | LOOP_EXPR => make::expr_continue(),
@@ -144,13 +144,13 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
144 } 144 }
145 }; 145 };
146 edit.target(if_expr.syntax().text_range()); 146 edit.target(if_expr.syntax().text_range());
147 edit.replace_ast(parent_block, ast::Block::cast(new_block).unwrap()); 147 edit.replace_ast(parent_block, ast::BlockExpr::cast(new_block).unwrap());
148 edit.set_cursor(cursor_position); 148 edit.set_cursor(cursor_position);
149 149
150 fn replace( 150 fn replace(
151 new_expr: &SyntaxNode, 151 new_expr: &SyntaxNode,
152 then_block: &Block, 152 then_block: &ast::BlockExpr,
153 parent_block: &Block, 153 parent_block: &ast::BlockExpr,
154 if_expr: &ast::IfExpr, 154 if_expr: &ast::IfExpr,
155 ) -> SyntaxNode { 155 ) -> SyntaxNode {
156 let then_block_items = IndentLevel::from(1).decrease_indent(then_block.clone()); 156 let then_block_items = IndentLevel::from(1).decrease_indent(then_block.clone());
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs
index f5702f6e0..60ec536a7 100644
--- a/crates/ra_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ra_assists/src/handlers/inline_local_variable.rs
@@ -89,6 +89,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
89 | (ast::Expr::ParenExpr(_), _) 89 | (ast::Expr::ParenExpr(_), _)
90 | (ast::Expr::PathExpr(_), _) 90 | (ast::Expr::PathExpr(_), _)
91 | (ast::Expr::BlockExpr(_), _) 91 | (ast::Expr::BlockExpr(_), _)
92 | (ast::Expr::EffectExpr(_), _)
92 | (_, ast::Expr::CallExpr(_)) 93 | (_, ast::Expr::CallExpr(_))
93 | (_, ast::Expr::TupleExpr(_)) 94 | (_, ast::Expr::TupleExpr(_))
94 | (_, ast::Expr::ArrayExpr(_)) 95 | (_, ast::Expr::ArrayExpr(_))
diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs
index eda9ac296..39c656305 100644
--- a/crates/ra_assists/src/handlers/introduce_variable.rs
+++ b/crates/ra_assists/src/handlers/introduce_variable.rs
@@ -111,7 +111,7 @@ fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> {
111/// expression like a lambda or match arm. 111/// expression like a lambda or match arm.
112fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> { 112fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> {
113 expr.syntax().ancestors().find_map(|node| { 113 expr.syntax().ancestors().find_map(|node| {
114 if let Some(expr) = node.parent().and_then(ast::Block::cast).and_then(|it| it.expr()) { 114 if let Some(expr) = node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.expr()) {
115 if expr.syntax() == &node { 115 if expr.syntax() == &node {
116 tested_by!(test_introduce_var_last_expr); 116 tested_by!(test_introduce_var_last_expr);
117 return Some((node, false)); 117 return Some((node, false));
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs
index d5ccdd91c..b084dd9ee 100644
--- a/crates/ra_assists/src/handlers/move_guard.rs
+++ b/crates/ra_assists/src/handlers/move_guard.rs
@@ -113,9 +113,9 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
113 "Move condition to match guard", 113 "Move condition to match guard",
114 |edit| { 114 |edit| {
115 edit.target(if_expr.syntax().text_range()); 115 edit.target(if_expr.syntax().text_range());
116 let then_only_expr = then_block.block().and_then(|it| it.statements().next()).is_none(); 116 let then_only_expr = then_block.statements().next().is_none();
117 117
118 match &then_block.block().and_then(|it| it.expr()) { 118 match &then_block.expr() {
119 Some(then_expr) if then_only_expr => { 119 Some(then_expr) if then_only_expr => {
120 edit.replace(if_expr.syntax().text_range(), then_expr.syntax().text()) 120 edit.replace(if_expr.syntax().text_range(), then_expr.syntax().text())
121 } 121 }
diff --git a/crates/ra_assists/src/handlers/unwrap_block.rs b/crates/ra_assists/src/handlers/unwrap_block.rs
new file mode 100644
index 000000000..58649c47e
--- /dev/null
+++ b/crates/ra_assists/src/handlers/unwrap_block.rs
@@ -0,0 +1,348 @@
1use crate::{Assist, AssistCtx, AssistId};
2
3use ast::{BlockExpr, Expr, ForExpr, IfExpr, LoopBodyOwner, LoopExpr, WhileExpr};
4use ra_fmt::unwrap_trivial_block;
5use ra_syntax::{ast, AstNode, TextRange, T};
6
7// Assist: unwrap_block
8//
9// This assist removes if...else, for, while and loop control statements to just keep the body.
10//
11// ```
12// fn foo() {
13// if true {<|>
14// println!("foo");
15// }
16// }
17// ```
18// ->
19// ```
20// fn foo() {
21// println!("foo");
22// }
23// ```
24pub(crate) fn unwrap_block(ctx: AssistCtx) -> Option<Assist> {
25 let l_curly_token = ctx.find_token_at_offset(T!['{'])?;
26
27 let res = if let Some(if_expr) = l_curly_token.ancestors().find_map(IfExpr::cast) {
28 // if expression
29 let expr_to_unwrap = if_expr.blocks().find_map(|expr| extract_expr(ctx.frange.range, expr));
30 let expr_to_unwrap = expr_to_unwrap?;
31 // Find if we are in a else if block
32 let ancestor = if_expr.syntax().ancestors().skip(1).find_map(ast::IfExpr::cast);
33
34 if let Some(ancestor) = ancestor {
35 Some((ast::Expr::IfExpr(ancestor), expr_to_unwrap))
36 } else {
37 Some((ast::Expr::IfExpr(if_expr), expr_to_unwrap))
38 }
39 } else if let Some(for_expr) = l_curly_token.ancestors().find_map(ForExpr::cast) {
40 // for expression
41 let block_expr = for_expr.loop_body()?;
42 extract_expr(ctx.frange.range, block_expr)
43 .map(|expr_to_unwrap| (ast::Expr::ForExpr(for_expr), expr_to_unwrap))
44 } else if let Some(while_expr) = l_curly_token.ancestors().find_map(WhileExpr::cast) {
45 // while expression
46 let block_expr = while_expr.loop_body()?;
47 extract_expr(ctx.frange.range, block_expr)
48 .map(|expr_to_unwrap| (ast::Expr::WhileExpr(while_expr), expr_to_unwrap))
49 } else if let Some(loop_expr) = l_curly_token.ancestors().find_map(LoopExpr::cast) {
50 // loop expression
51 let block_expr = loop_expr.loop_body()?;
52 extract_expr(ctx.frange.range, block_expr)
53 .map(|expr_to_unwrap| (ast::Expr::LoopExpr(loop_expr), expr_to_unwrap))
54 } else {
55 None
56 };
57
58 let (expr, expr_to_unwrap) = res?;
59 ctx.add_assist(AssistId("unwrap_block"), "Unwrap block", |edit| {
60 edit.set_cursor(expr.syntax().text_range().start());
61 edit.target(expr_to_unwrap.syntax().text_range());
62
63 let pat_start: &[_] = &[' ', '{', '\n'];
64 let expr_to_unwrap = expr_to_unwrap.to_string();
65 let expr_string = expr_to_unwrap.trim_start_matches(pat_start);
66 let mut expr_string_lines: Vec<&str> = expr_string.lines().collect();
67 expr_string_lines.pop(); // Delete last line
68
69 let expr_string = expr_string_lines
70 .into_iter()
71 .map(|line| line.replacen(" ", "", 1)) // Delete indentation
72 .collect::<Vec<String>>()
73 .join("\n");
74
75 edit.replace(expr.syntax().text_range(), expr_string);
76 })
77}
78
79fn extract_expr(cursor_range: TextRange, block: BlockExpr) -> Option<Expr> {
80 let cursor_in_range = block.l_curly_token()?.text_range().contains_range(cursor_range);
81
82 if cursor_in_range {
83 Some(unwrap_trivial_block(block))
84 } else {
85 None
86 }
87}
88
89#[cfg(test)]
90mod tests {
91 use crate::helpers::{check_assist, check_assist_not_applicable};
92
93 use super::*;
94
95 #[test]
96 fn simple_if() {
97 check_assist(
98 unwrap_block,
99 r#"
100 fn main() {
101 bar();
102 if true {<|>
103 foo();
104
105 //comment
106 bar();
107 } else {
108 println!("bar");
109 }
110 }
111 "#,
112 r#"
113 fn main() {
114 bar();
115 <|>foo();
116
117 //comment
118 bar();
119 }
120 "#,
121 );
122 }
123
124 #[test]
125 fn simple_if_else() {
126 check_assist(
127 unwrap_block,
128 r#"
129 fn main() {
130 bar();
131 if true {
132 foo();
133
134 //comment
135 bar();
136 } else {<|>
137 println!("bar");
138 }
139 }
140 "#,
141 r#"
142 fn main() {
143 bar();
144 <|>println!("bar");
145 }
146 "#,
147 );
148 }
149
150 #[test]
151 fn simple_if_else_if() {
152 check_assist(
153 unwrap_block,
154 r#"
155 fn main() {
156 //bar();
157 if true {
158 println!("true");
159
160 //comment
161 //bar();
162 } else if false {<|>
163 println!("bar");
164 } else {
165 println!("foo");
166 }
167 }
168 "#,
169 r#"
170 fn main() {
171 //bar();
172 <|>println!("bar");
173 }
174 "#,
175 );
176 }
177
178 #[test]
179 fn simple_if_bad_cursor_position() {
180 check_assist_not_applicable(
181 unwrap_block,
182 r#"
183 fn main() {
184 bar();<|>
185 if true {
186 foo();
187
188 //comment
189 bar();
190 } else {
191 println!("bar");
192 }
193 }
194 "#,
195 );
196 }
197
198 #[test]
199 fn simple_for() {
200 check_assist(
201 unwrap_block,
202 r#"
203 fn main() {
204 for i in 0..5 {<|>
205 if true {
206 foo();
207
208 //comment
209 bar();
210 } else {
211 println!("bar");
212 }
213 }
214 }
215 "#,
216 r#"
217 fn main() {
218 <|>if true {
219 foo();
220
221 //comment
222 bar();
223 } else {
224 println!("bar");
225 }
226 }
227 "#,
228 );
229 }
230
231 #[test]
232 fn simple_if_in_for() {
233 check_assist(
234 unwrap_block,
235 r#"
236 fn main() {
237 for i in 0..5 {
238 if true {<|>
239 foo();
240
241 //comment
242 bar();
243 } else {
244 println!("bar");
245 }
246 }
247 }
248 "#,
249 r#"
250 fn main() {
251 for i in 0..5 {
252 <|>foo();
253
254 //comment
255 bar();
256 }
257 }
258 "#,
259 );
260 }
261
262 #[test]
263 fn simple_loop() {
264 check_assist(
265 unwrap_block,
266 r#"
267 fn main() {
268 loop {<|>
269 if true {
270 foo();
271
272 //comment
273 bar();
274 } else {
275 println!("bar");
276 }
277 }
278 }
279 "#,
280 r#"
281 fn main() {
282 <|>if true {
283 foo();
284
285 //comment
286 bar();
287 } else {
288 println!("bar");
289 }
290 }
291 "#,
292 );
293 }
294
295 #[test]
296 fn simple_while() {
297 check_assist(
298 unwrap_block,
299 r#"
300 fn main() {
301 while true {<|>
302 if true {
303 foo();
304
305 //comment
306 bar();
307 } else {
308 println!("bar");
309 }
310 }
311 }
312 "#,
313 r#"
314 fn main() {
315 <|>if true {
316 foo();
317
318 //comment
319 bar();
320 } else {
321 println!("bar");
322 }
323 }
324 "#,
325 );
326 }
327
328 #[test]
329 fn simple_if_in_while_bad_cursor_position() {
330 check_assist_not_applicable(
331 unwrap_block,
332 r#"
333 fn main() {
334 while true {
335 if true {
336 foo();<|>
337
338 //comment
339 bar();
340 } else {
341 println!("bar");
342 }
343 }
344 }
345 "#,
346 );
347 }
348}
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 64bd87afb..c5df86600 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -143,6 +143,7 @@ mod handlers {
143 mod split_import; 143 mod split_import;
144 mod add_from_impl_for_enum; 144 mod add_from_impl_for_enum;
145 mod reorder_fields; 145 mod reorder_fields;
146 mod unwrap_block;
146 147
147 pub(crate) fn all() -> &'static [AssistHandler] { 148 pub(crate) fn all() -> &'static [AssistHandler] {
148 &[ 149 &[
@@ -181,6 +182,7 @@ mod handlers {
181 replace_unwrap_with_match::replace_unwrap_with_match, 182 replace_unwrap_with_match::replace_unwrap_with_match,
182 split_import::split_import, 183 split_import::split_import,
183 add_from_impl_for_enum::add_from_impl_for_enum, 184 add_from_impl_for_enum::add_from_impl_for_enum,
185 unwrap_block::unwrap_block,
184 // These are manually sorted for better priorities 186 // These are manually sorted for better priorities
185 add_missing_impl_members::add_missing_impl_members, 187 add_missing_impl_members::add_missing_impl_members,
186 add_missing_impl_members::add_missing_default_members, 188 add_missing_impl_members::add_missing_default_members,
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs
index 1a30b2b3a..f910ded9d 100644
--- a/crates/ra_fmt/src/lib.rs
+++ b/crates/ra_fmt/src/lib.rs
@@ -42,7 +42,6 @@ pub fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
42} 42}
43 43
44pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { 44pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
45 let block = block.block()?;
46 let has_anything_else = |thing: &SyntaxNode| -> bool { 45 let has_anything_else = |thing: &SyntaxNode| -> bool {
47 let mut non_trivial_children = 46 let mut non_trivial_children =
48 block.syntax().children_with_tokens().filter(|it| match it.kind() { 47 block.syntax().children_with_tokens().filter(|it| match it.kind() {
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 6f3b5b2da..8af64fdc1 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -151,7 +151,7 @@ impl SourceToDefCtx<'_, '_> {
151 let krate = self.file_to_def(file_id)?.krate; 151 let krate = self.file_to_def(file_id)?.krate;
152 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); 152 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value);
153 let ast_id = Some(AstId::new(src.file_id, file_ast_id)); 153 let ast_id = Some(AstId::new(src.file_id, file_ast_id));
154 Some(MacroDefId { krate: Some(krate), ast_id, kind }) 154 Some(MacroDefId { krate: Some(krate), ast_id, kind, local_inner: false })
155 } 155 }
156 156
157 pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { 157 pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> {
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 5a86af8ba..576cd0c65 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -140,6 +140,7 @@ impl Attr {
140 } 140 }
141} 141}
142 142
143#[derive(Debug, Clone, Copy)]
143pub struct AttrQuery<'a> { 144pub struct AttrQuery<'a> {
144 attrs: &'a Attrs, 145 attrs: &'a Attrs,
145 key: &'static str, 146 key: &'static str,
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index e9dd65b0a..687216dc3 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -203,6 +203,16 @@ impl ExprCollector<'_> {
203 203
204 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) 204 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
205 } 205 }
206 ast::Expr::EffectExpr(e) => match e.effect() {
207 ast::Effect::Try(_) => {
208 let body = self.collect_block_opt(e.block_expr());
209 self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
210 }
211 // FIXME: we need to record these effects somewhere...
212 ast::Effect::Async(_) | ast::Effect::Label(_) | ast::Effect::Unsafe(_) => {
213 self.collect_block_opt(e.block_expr())
214 }
215 },
206 ast::Expr::BlockExpr(e) => self.collect_block(e), 216 ast::Expr::BlockExpr(e) => self.collect_block(e),
207 ast::Expr::LoopExpr(e) => { 217 ast::Expr::LoopExpr(e) => {
208 let body = self.collect_block_opt(e.loop_body()); 218 let body = self.collect_block_opt(e.loop_body());
@@ -456,6 +466,7 @@ impl ExprCollector<'_> {
456 krate: Some(self.expander.module.krate), 466 krate: Some(self.expander.module.krate),
457 ast_id: Some(self.expander.ast_id(&e)), 467 ast_id: Some(self.expander.ast_id(&e)),
458 kind: MacroDefKind::Declarative, 468 kind: MacroDefKind::Declarative,
469 local_inner: false,
459 }; 470 };
460 self.body.item_scope.define_legacy_macro(name, mac); 471 self.body.item_scope.define_legacy_macro(name, mac);
461 472
@@ -490,12 +501,8 @@ impl ExprCollector<'_> {
490 } 501 }
491 } 502 }
492 503
493 fn collect_block(&mut self, expr: ast::BlockExpr) -> ExprId { 504 fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId {
494 let syntax_node_ptr = AstPtr::new(&expr.clone().into()); 505 let syntax_node_ptr = AstPtr::new(&block.clone().into());
495 let block = match expr.block() {
496 Some(block) => block,
497 None => return self.alloc_expr(Expr::Missing, syntax_node_ptr),
498 };
499 self.collect_block_items(&block); 506 self.collect_block_items(&block);
500 let statements = block 507 let statements = block
501 .statements() 508 .statements()
@@ -513,7 +520,7 @@ impl ExprCollector<'_> {
513 self.alloc_expr(Expr::Block { statements, tail }, syntax_node_ptr) 520 self.alloc_expr(Expr::Block { statements, tail }, syntax_node_ptr)
514 } 521 }
515 522
516 fn collect_block_items(&mut self, block: &ast::Block) { 523 fn collect_block_items(&mut self, block: &ast::BlockExpr) {
517 let container = ContainerId::DefWithBodyId(self.def); 524 let container = ContainerId::DefWithBodyId(self.def);
518 for item in block.items() { 525 for item in block.items() {
519 let (def, name): (ModuleDefId, Option<ast::Name>) = match item { 526 let (def, name): (ModuleDefId, Option<ast::Name>) = match item {
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs
index aad12e123..a0cdad529 100644
--- a/crates/ra_hir_def/src/expr.rs
+++ b/crates/ra_hir_def/src/expr.rs
@@ -101,6 +101,9 @@ pub enum Expr {
101 Try { 101 Try {
102 expr: ExprId, 102 expr: ExprId,
103 }, 103 },
104 TryBlock {
105 body: ExprId,
106 },
104 Cast { 107 Cast {
105 expr: ExprId, 108 expr: ExprId,
106 type_ref: TypeRef, 109 type_ref: TypeRef,
@@ -236,6 +239,7 @@ impl Expr {
236 f(*expr); 239 f(*expr);
237 } 240 }
238 } 241 }
242 Expr::TryBlock { body } => f(*body),
239 Expr::Loop { body } => f(*body), 243 Expr::Loop { body } => f(*body),
240 Expr::While { condition, body } => { 244 Expr::While { condition, body } => {
241 f(*condition); 245 f(*condition);
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 98c74fe25..bf3968bd6 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -204,6 +204,7 @@ impl DefCollector<'_> {
204 ast_id: None, 204 ast_id: None,
205 krate: Some(krate), 205 krate: Some(krate),
206 kind: MacroDefKind::CustomDerive(expander), 206 kind: MacroDefKind::CustomDerive(expander),
207 local_inner: false,
207 }; 208 };
208 209
209 self.define_proc_macro(name.clone(), macro_id); 210 self.define_proc_macro(name.clone(), macro_id);
@@ -941,6 +942,7 @@ impl ModCollector<'_, '_> {
941 ast_id: Some(ast_id.ast_id), 942 ast_id: Some(ast_id.ast_id),
942 krate: Some(self.def_collector.def_map.krate), 943 krate: Some(self.def_collector.def_map.krate),
943 kind: MacroDefKind::Declarative, 944 kind: MacroDefKind::Declarative,
945 local_inner: mac.local_inner,
944 }; 946 };
945 self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); 947 self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export);
946 } 948 }
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 39b011ad7..a71503c76 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -188,6 +188,7 @@ pub(super) struct MacroData {
188 pub(super) path: ModPath, 188 pub(super) path: ModPath,
189 pub(super) name: Option<Name>, 189 pub(super) name: Option<Name>,
190 pub(super) export: bool, 190 pub(super) export: bool,
191 pub(super) local_inner: bool,
191 pub(super) builtin: bool, 192 pub(super) builtin: bool,
192} 193}
193 194
@@ -401,14 +402,32 @@ impl RawItemsCollector {
401 402
402 let name = m.name().map(|it| it.as_name()); 403 let name = m.name().map(|it| it.as_name());
403 let ast_id = self.source_ast_id_map.ast_id(&m); 404 let ast_id = self.source_ast_id_map.ast_id(&m);
404 // FIXME: cfg_attr
405 let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export");
406 405
407 // FIXME: cfg_attr 406 // FIXME: cfg_attr
408 let builtin = 407 let export_attr = attrs.by_key("macro_export");
409 m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "rustc_builtin_macro"); 408
409 let export = export_attr.exists();
410 let local_inner = if export {
411 export_attr.tt_values().map(|it| &it.token_trees).flatten().any(|it| match it {
412 tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => {
413 ident.text.contains("local_inner_macros")
414 }
415 _ => false,
416 })
417 } else {
418 false
419 };
420
421 let builtin = attrs.by_key("rustc_builtin_macro").exists();
410 422
411 let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export, builtin }); 423 let m = self.raw_items.macros.alloc(MacroData {
424 ast_id,
425 path,
426 name,
427 export,
428 local_inner,
429 builtin,
430 });
412 self.push_item(current_module, attrs, RawItemKind::Macro(m)); 431 self.push_item(current_module, attrs, RawItemKind::Macro(m));
413 } 432 }
414 433
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs
index b0befdfbd..9bc0e6287 100644
--- a/crates/ra_hir_def/src/nameres/tests/macros.rs
+++ b/crates/ra_hir_def/src/nameres/tests/macros.rs
@@ -136,6 +136,43 @@ fn macro_rules_export_with_local_inner_macros_are_visible() {
136} 136}
137 137
138#[test] 138#[test]
139fn local_inner_macros_makes_local_macros_usable() {
140 let map = def_map(
141 "
142 //- /main.rs crate:main deps:foo
143 foo::structs!(Foo, Bar);
144 mod bar;
145 //- /bar.rs
146 use crate::*;
147 //- /lib.rs crate:foo
148 #[macro_export(local_inner_macros)]
149 macro_rules! structs {
150 ($($i:ident),*) => {
151 inner!($($i),*);
152 }
153 }
154 #[macro_export]
155 macro_rules! inner {
156 ($($i:ident),*) => {
157 $(struct $i { field: u32 } )*
158 }
159 }
160 ",
161 );
162 assert_snapshot!(map, @r###"
163 â‹®crate
164 â‹®Bar: t v
165 â‹®Foo: t v
166 â‹®bar: t
167 â‹®
168 â‹®crate::bar
169 â‹®Bar: t v
170 â‹®Foo: t v
171 â‹®bar: t
172 "###);
173}
174
175#[test]
139fn unexpanded_macro_should_expand_by_fixedpoint_loop() { 176fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
140 let map = def_map( 177 let map = def_map(
141 " 178 "
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs
index e3d237a0a..6a0c019fd 100644
--- a/crates/ra_hir_def/src/path/lower.rs
+++ b/crates/ra_hir_def/src/path/lower.rs
@@ -116,6 +116,21 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
116 } 116 }
117 segments.reverse(); 117 segments.reverse();
118 generic_args.reverse(); 118 generic_args.reverse();
119
120 // handle local_inner_macros :
121 // Basically, even in rustc it is quite hacky:
122 // https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
123 // We follow what it did anyway :)
124 if segments.len() == 1 && kind == PathKind::Plain {
125 if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
126 if macro_call.is_bang() {
127 if let Some(crate_id) = hygiene.local_inner_macros() {
128 kind = PathKind::DollarCrate(crate_id);
129 }
130 }
131 }
132 }
133
119 let mod_path = ModPath { kind, segments }; 134 let mod_path = ModPath { kind, segments };
120 return Some(Path { type_anchor, mod_path, generic_args }); 135 return Some(Path { type_anchor, mod_path, generic_args });
121 136
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs
index e60f879a3..1dc9cac66 100644
--- a/crates/ra_hir_expand/src/builtin_derive.rs
+++ b/crates/ra_hir_expand/src/builtin_derive.rs
@@ -38,7 +38,7 @@ macro_rules! register_builtin {
38 _ => return None, 38 _ => return None,
39 }; 39 };
40 40
41 Some(MacroDefId { krate: None, ast_id: None, kind: MacroDefKind::BuiltInDerive(kind) }) 41 Some(MacroDefId { krate: None, ast_id: None, kind: MacroDefKind::BuiltInDerive(kind), local_inner: false })
42 } 42 }
43 }; 43 };
44} 44}
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index e0fef613d..d8b3d342c 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -73,11 +73,13 @@ pub fn find_builtin_macro(
73 krate: Some(krate), 73 krate: Some(krate),
74 ast_id: Some(ast_id), 74 ast_id: Some(ast_id),
75 kind: MacroDefKind::BuiltIn(kind), 75 kind: MacroDefKind::BuiltIn(kind),
76 local_inner: false,
76 }), 77 }),
77 Either::Right(kind) => Some(MacroDefId { 78 Either::Right(kind) => Some(MacroDefId {
78 krate: Some(krate), 79 krate: Some(krate),
79 ast_id: Some(ast_id), 80 ast_id: Some(ast_id),
80 kind: MacroDefKind::BuiltInEager(kind), 81 kind: MacroDefKind::BuiltInEager(kind),
82 local_inner: false,
81 }), 83 }),
82 } 84 }
83} 85}
@@ -406,6 +408,7 @@ mod tests {
406 krate: Some(CrateId(0)), 408 krate: Some(CrateId(0)),
407 ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(&macro_calls[0]))), 409 ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(&macro_calls[0]))),
408 kind: MacroDefKind::BuiltIn(expander), 410 kind: MacroDefKind::BuiltIn(expander),
411 local_inner: false,
409 }; 412 };
410 413
411 let loc = MacroCallLoc { 414 let loc = MacroCallLoc {
@@ -425,6 +428,7 @@ mod tests {
425 krate: Some(CrateId(0)), 428 krate: Some(CrateId(0)),
426 ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(&macro_calls[0]))), 429 ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(&macro_calls[0]))),
427 kind: MacroDefKind::BuiltInEager(expander), 430 kind: MacroDefKind::BuiltInEager(expander),
431 local_inner: false,
428 }; 432 };
429 433
430 let args = macro_calls[1].token_tree().unwrap(); 434 let args = macro_calls[1].token_tree().unwrap();
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index 047452306..4c12d0a15 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -330,7 +330,7 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind {
330 FragmentKind::Expr 330 FragmentKind::Expr
331 } 331 }
332 // FIXME: Expand to statements in appropriate positions; HIR lowering needs to handle that 332 // FIXME: Expand to statements in appropriate positions; HIR lowering needs to handle that
333 EXPR_STMT | BLOCK => FragmentKind::Expr, 333 EXPR_STMT | BLOCK_EXPR => FragmentKind::Expr,
334 ARG_LIST => FragmentKind::Expr, 334 ARG_LIST => FragmentKind::Expr,
335 TRY_EXPR => FragmentKind::Expr, 335 TRY_EXPR => FragmentKind::Expr,
336 TUPLE_EXPR => FragmentKind::Expr, 336 TUPLE_EXPR => FragmentKind::Expr,
@@ -342,7 +342,6 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind {
342 CONDITION => FragmentKind::Expr, 342 CONDITION => FragmentKind::Expr,
343 BREAK_EXPR => FragmentKind::Expr, 343 BREAK_EXPR => FragmentKind::Expr,
344 RETURN_EXPR => FragmentKind::Expr, 344 RETURN_EXPR => FragmentKind::Expr,
345 BLOCK_EXPR => FragmentKind::Expr,
346 MATCH_EXPR => FragmentKind::Expr, 345 MATCH_EXPR => FragmentKind::Expr,
347 MATCH_ARM => FragmentKind::Expr, 346 MATCH_ARM => FragmentKind::Expr,
348 MATCH_GUARD => FragmentKind::Expr, 347 MATCH_GUARD => FragmentKind::Expr,
diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs
index 53866bbcb..6b482a60c 100644
--- a/crates/ra_hir_expand/src/hygiene.rs
+++ b/crates/ra_hir_expand/src/hygiene.rs
@@ -16,31 +16,34 @@ use crate::{
16pub struct Hygiene { 16pub struct Hygiene {
17 // This is what `$crate` expands to 17 // This is what `$crate` expands to
18 def_crate: Option<CrateId>, 18 def_crate: Option<CrateId>,
19
20 // Indiciate this is a local inner macro
21 local_inner: bool,
19} 22}
20 23
21impl Hygiene { 24impl Hygiene {
22 pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene { 25 pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene {
23 let def_crate = match file_id.0 { 26 let (def_crate, local_inner) = match file_id.0 {
24 HirFileIdRepr::FileId(_) => None, 27 HirFileIdRepr::FileId(_) => (None, false),
25 HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id { 28 HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id {
26 MacroCallId::LazyMacro(id) => { 29 MacroCallId::LazyMacro(id) => {
27 let loc = db.lookup_intern_macro(id); 30 let loc = db.lookup_intern_macro(id);
28 match loc.def.kind { 31 match loc.def.kind {
29 MacroDefKind::Declarative => loc.def.krate, 32 MacroDefKind::Declarative => (loc.def.krate, loc.def.local_inner),
30 MacroDefKind::BuiltIn(_) => None, 33 MacroDefKind::BuiltIn(_) => (None, false),
31 MacroDefKind::BuiltInDerive(_) => None, 34 MacroDefKind::BuiltInDerive(_) => (None, false),
32 MacroDefKind::BuiltInEager(_) => None, 35 MacroDefKind::BuiltInEager(_) => (None, false),
33 MacroDefKind::CustomDerive(_) => None, 36 MacroDefKind::CustomDerive(_) => (None, false),
34 } 37 }
35 } 38 }
36 MacroCallId::EagerMacro(_id) => None, 39 MacroCallId::EagerMacro(_id) => (None, false),
37 }, 40 },
38 }; 41 };
39 Hygiene { def_crate } 42 Hygiene { def_crate, local_inner }
40 } 43 }
41 44
42 pub fn new_unhygienic() -> Hygiene { 45 pub fn new_unhygienic() -> Hygiene {
43 Hygiene { def_crate: None } 46 Hygiene { def_crate: None, local_inner: false }
44 } 47 }
45 48
46 // FIXME: this should just return name 49 // FIXME: this should just return name
@@ -52,4 +55,12 @@ impl Hygiene {
52 } 55 }
53 Either::Left(name_ref.as_name()) 56 Either::Left(name_ref.as_name())
54 } 57 }
58
59 pub fn local_inner_macros(&self) -> Option<CrateId> {
60 if self.local_inner {
61 self.def_crate
62 } else {
63 None
64 }
65 }
55} 66}
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 754a0f005..f440c073b 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -204,6 +204,8 @@ pub struct MacroDefId {
204 pub krate: Option<CrateId>, 204 pub krate: Option<CrateId>,
205 pub ast_id: Option<AstId<ast::MacroCall>>, 205 pub ast_id: Option<AstId<ast::MacroCall>>,
206 pub kind: MacroDefKind, 206 pub kind: MacroDefKind,
207
208 pub local_inner: bool,
207} 209}
208 210
209impl MacroDefId { 211impl MacroDefId {
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index efc60986b..83f946eee 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -73,6 +73,11 @@ impl<'a> InferenceContext<'a> {
73 self.coerce_merge_branch(&then_ty, &else_ty) 73 self.coerce_merge_branch(&then_ty, &else_ty)
74 } 74 }
75 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), 75 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected),
76 Expr::TryBlock { body } => {
77 let _inner = self.infer_expr(*body, expected);
78 // FIXME should be std::result::Result<{inner}, _>
79 Ty::Unknown
80 }
76 Expr::Loop { body } => { 81 Expr::Loop { body } => {
77 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 82 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
78 // FIXME handle break with value 83 // FIXME handle break with value
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index 1f796876d..29e38a06c 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -428,6 +428,32 @@ fn main() {
428} 428}
429 429
430#[test] 430#[test]
431fn infer_local_inner_macros() {
432 let (db, pos) = TestDB::with_position(
433 r#"
434//- /main.rs crate:main deps:foo
435fn test() {
436 let x = foo::foo!(1);
437 x<|>;
438}
439
440//- /lib.rs crate:foo
441#[macro_export(local_inner_macros)]
442macro_rules! foo {
443 (1) => { bar!() };
444}
445
446#[macro_export]
447macro_rules! bar {
448 () => { 42 }
449}
450
451"#,
452 );
453 assert_eq!("i32", type_at_pos(&db, pos));
454}
455
456#[test]
431fn infer_builtin_macros_line() { 457fn infer_builtin_macros_line() {
432 assert_snapshot!( 458 assert_snapshot!(
433 infer(r#" 459 infer(r#"
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index 56abc65b8..3d3088965 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -1755,3 +1755,35 @@ fn main() {
1755 "### 1755 "###
1756 ); 1756 );
1757} 1757}
1758
1759#[test]
1760fn effects_smoke_test() {
1761 assert_snapshot!(
1762 infer(r#"
1763fn main() {
1764 let x = unsafe { 92 };
1765 let y = async { async { () }.await };
1766 let z = try { () };
1767 let t = 'a: { 92 };
1768}
1769"#),
1770 @r###"
1771 11..131 '{ ...2 }; }': ()
1772 21..22 'x': i32
1773 32..38 '{ 92 }': i32
1774 34..36 '92': i32
1775 48..49 'y': {unknown}
1776 58..80 '{ asyn...wait }': {unknown}
1777 60..78 'async ....await': {unknown}
1778 66..72 '{ () }': ()
1779 68..70 '()': ()
1780 90..91 'z': {unknown}
1781 94..104 'try { () }': {unknown}
1782 98..104 '{ () }': ()
1783 100..102 '()': ()
1784 114..115 't': i32
1785 122..128 '{ 92 }': i32
1786 124..126 '92': i32
1787 "###
1788 )
1789}
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 118fceb2e..c529752d4 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -344,7 +344,7 @@ impl<'a> CompletionContext<'a> {
344 stmt.syntax().text_range() == name_ref.syntax().text_range(), 344 stmt.syntax().text_range() == name_ref.syntax().text_range(),
345 ); 345 );
346 } 346 }
347 if let Some(block) = ast::Block::cast(node) { 347 if let Some(block) = ast::BlockExpr::cast(node) {
348 return Some( 348 return Some(
349 block.expr().map(|e| e.syntax().text_range()) 349 block.expr().map(|e| e.syntax().text_range())
350 == Some(name_ref.syntax().text_range()), 350 == Some(name_ref.syntax().text_range()),
diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs
index 4379005aa..8657377de 100644
--- a/crates/ra_ide/src/folding_ranges.rs
+++ b/crates/ra_ide/src/folding_ranges.rs
@@ -88,7 +88,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
88 | ITEM_LIST 88 | ITEM_LIST
89 | EXTERN_ITEM_LIST 89 | EXTERN_ITEM_LIST
90 | USE_TREE_LIST 90 | USE_TREE_LIST
91 | BLOCK 91 | BLOCK_EXPR
92 | MATCH_ARM_LIST 92 | MATCH_ARM_LIST
93 | ENUM_VARIANT_LIST 93 | ENUM_VARIANT_LIST
94 | TOKEN_TREE => Some(FoldKind::Block), 94 | TOKEN_TREE => Some(FoldKind::Block),
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index d0def7eaa..63fd6b3e4 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -129,8 +129,7 @@ fn has_comma_after(node: &SyntaxNode) -> bool {
129} 129}
130 130
131fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> { 131fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> {
132 let block = ast::Block::cast(token.parent())?; 132 let block_expr = ast::BlockExpr::cast(token.parent())?;
133 let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?;
134 if !block_expr.is_standalone() { 133 if !block_expr.is_standalone() {
135 return None; 134 return None;
136 } 135 }
diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs
index bf97f8c56..86c70ff83 100644
--- a/crates/ra_ide/src/syntax_tree.rs
+++ b/crates/ra_ide/src/syntax_tree.rs
@@ -120,9 +120,8 @@ [email protected]
120 [email protected] ")" 120 [email protected] ")"
121 [email protected] " " 121 [email protected] " "
122 [email protected] 122 [email protected]
123 [email protected] 123 [email protected] "{"
124 [email protected] "{" 124 [email protected] "}"
125 [email protected] "}"
126"# 125"#
127 .trim() 126 .trim()
128 ); 127 );
@@ -153,26 +152,25 @@ [email protected]
153 [email protected] ")" 152 [email protected] ")"
154 [email protected] " " 153 [email protected] " "
155 [email protected] 154 [email protected]
156 [email protected] 155 [email protected] "{"
157 [email protected] "{" 156 [email protected] "\n "
158 [email protected] "\n " 157 [email protected]
159 [email protected] 158 [email protected]
160 [email protected] 159 [email protected]
161 [email protected] 160 [email protected]
162 [email protected] 161 [email protected]
163 [email protected] 162 [email protected] "assert"
164 [email protected] "assert" 163 [email protected] "!"
165 [email protected] "!" 164 [email protected]
166 [email protected] 165 [email protected] "("
167 [email protected] "(" 166 [email protected] "\"\n fn foo() {\n ..."
168 [email protected] "\"\n fn foo() {\n ..." 167 [email protected] ","
169 [email protected] "," 168 [email protected] " "
170 [email protected] " " 169 [email protected] "\"\""
171 [email protected] "\"\"" 170 [email protected] ")"
172 [email protected] ")" 171 [email protected] ";"
173 [email protected] ";" 172 [email protected] "\n"
174 [email protected] "\n" 173 [email protected] "}"
175 [email protected] "}"
176"# 174"#
177 .trim() 175 .trim()
178 ); 176 );
@@ -196,9 +194,8 @@ [email protected]
196 [email protected] ")" 194 [email protected] ")"
197 [email protected] " " 195 [email protected] " "
198 [email protected] 196 [email protected]
199 [email protected] 197 [email protected] "{"
200 [email protected] "{" 198 [email protected] "}"
201 [email protected] "}"
202"# 199"#
203 .trim() 200 .trim()
204 ); 201 );
@@ -265,10 +262,9 @@ [email protected]
265 [email protected] ")" 262 [email protected] ")"
266 [email protected] " " 263 [email protected] " "
267 [email protected] 264 [email protected]
268 [email protected] 265 [email protected] "{"
269 [email protected] "{" 266 [email protected] "\n"
270 [email protected] "\n" 267 [email protected] "}"
271 [email protected] "}"
272"# 268"#
273 .trim() 269 .trim()
274 ); 270 );
@@ -300,10 +296,9 @@ [email protected]
300 [email protected] ")" 296 [email protected] ")"
301 [email protected] " " 297 [email protected] " "
302 [email protected] 298 [email protected]
303 [email protected] 299 [email protected] "{"
304 [email protected] "{" 300 [email protected] "\n"
305 [email protected] "\n" 301 [email protected] "}"
306 [email protected] "}"
307"# 302"#
308 .trim() 303 .trim()
309 ); 304 );
@@ -334,10 +329,9 @@ [email protected]
334 [email protected] ")" 329 [email protected] ")"
335 [email protected] " " 330 [email protected] " "
336 [email protected] 331 [email protected]
337 [email protected] 332 [email protected] "{"
338 [email protected] "{" 333 [email protected] "\n"
339 [email protected] "\n" 334 [email protected] "}"
340 [email protected] "}"
341 [email protected] "\n" 335 [email protected] "\n"
342 [email protected] 336 [email protected]
343 [email protected] "fn" 337 [email protected] "fn"
@@ -349,10 +343,9 @@ [email protected]
349 [email protected] ")" 343 [email protected] ")"
350 [email protected] " " 344 [email protected] " "
351 [email protected] 345 [email protected]
352 [email protected] 346 [email protected] "{"
353 [email protected] "{" 347 [email protected] "\n"
354 [email protected] "\n" 348 [email protected] "}"
355 [email protected] "}"
356"# 349"#
357 .trim() 350 .trim()
358 ); 351 );
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index 0d924ce58..c43003fd6 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -266,21 +266,20 @@ fn test_expr_order() {
266 [email protected] "(" 266 [email protected] "("
267 [email protected] ")" 267 [email protected] ")"
268 [email protected] 268 [email protected]
269 [email protected] 269 [email protected] "{"
270 [email protected] "{" 270 [email protected]
271 [email protected] 271 [email protected]
272 [email protected] 272 [email protected]
273 [email protected] 273 [email protected]
274 [email protected] 274 [email protected] "1"
275 [email protected] "1" 275 [email protected] "+"
276 [email protected] "+" 276 [email protected]
277 [email protected] 277 [email protected] "1"
278 [email protected] "1" 278 [email protected] "*"
279 [email protected] "*" 279 [email protected]
280 [email protected] 280 [email protected] "2"
281 [email protected] "2" 281 [email protected] ";"
282 [email protected] ";" 282 [email protected] "}""#,
283 [email protected] "}""#,
284 ); 283 );
285} 284}
286 285
@@ -1114,68 +1113,67 @@ fn test_vec() {
1114 assert_eq!( 1113 assert_eq!(
1115 format!("{:#?}", tree).trim(), 1114 format!("{:#?}", tree).trim(),
1116 r#"[email protected] 1115 r#"[email protected]
1117 [email protected] 1116 [email protected] "{"
1118 [email protected] "{" 1117 [email protected]
1119 [email protected] 1118 [email protected] "let"
1120 [email protected] "let" 1119 [email protected]
1121 [email protected] 1120 [email protected] "mut"
1122 [email protected] "mut" 1121 [email protected]
1123 [email protected] 1122 [email protected] "v"
1124 [email protected] "v" 1123 [email protected] "="
1125 [email protected] "=" 1124 [email protected]
1126 [email protected] 1125 [email protected]
1127 [email protected] 1126 [email protected]
1128 [email protected] 1127 [email protected]
1129 [email protected] 1128 [email protected]
1130 [email protected] 1129 [email protected]
1131 [email protected] 1130 [email protected] "Vec"
1132 [email protected] "Vec" 1131 [email protected] "::"
1133 [email protected] "::" 1132 [email protected]
1134 [email protected] 1133 [email protected]
1135 [email protected] 1134 [email protected] "new"
1136 [email protected] "new" 1135 [email protected]
1137 [email protected] 1136 [email protected] "("
1138 [email protected] "(" 1137 [email protected] ")"
1139 [email protected] ")" 1138 [email protected] ";"
1140 [email protected] ";" 1139 [email protected]
1141 [email protected] 1140 [email protected]
1142 [email protected] 1141 [email protected]
1143 [email protected] 1142 [email protected]
1144 [email protected] 1143 [email protected]
1145 [email protected] 1144 [email protected]
1146 [email protected] 1145 [email protected] "v"
1147 [email protected] "v" 1146 [email protected] "."
1148 [email protected] "." 1147 [email protected]
1149 [email protected] 1148 [email protected] "push"
1150 [email protected] "push" 1149 [email protected]
1151 [email protected] 1150 [email protected] "("
1152 [email protected] "(" 1151 [email protected]
1153 [email protected] 1152 [email protected] "1u32"
1154 [email protected] "1u32" 1153 [email protected] ")"
1155 [email protected] ")" 1154 [email protected] ";"
1156 [email protected] ";" 1155 [email protected]
1157 [email protected] 1156 [email protected]
1158 [email protected] 1157 [email protected]
1159 [email protected] 1158 [email protected]
1160 [email protected] 1159 [email protected]
1161 [email protected] 1160 [email protected]
1162 [email protected] 1161 [email protected] "v"
1163 [email protected] "v" 1162 [email protected] "."
1164 [email protected] "." 1163 [email protected]
1165 [email protected] 1164 [email protected] "push"
1166 [email protected] "push" 1165 [email protected]
1167 [email protected] 1166 [email protected] "("
1168 [email protected] "(" 1167 [email protected]
1169 [email protected] 1168 [email protected] "2"
1170 [email protected] "2" 1169 [email protected] ")"
1171 [email protected] ")" 1170 [email protected] ";"
1172 [email protected] ";" 1171 [email protected]
1173 [email protected] 1172 [email protected]
1174 [email protected] 1173 [email protected]
1175 [email protected] 1174 [email protected]
1176 [email protected] 1175 [email protected] "v"
1177 [email protected] "v" 1176 [email protected] "}""#
1178 [email protected] "}""#
1179 ); 1177 );
1180} 1178}
1181 1179
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index c2a6e82e9..be0cd5661 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -54,7 +54,7 @@ pub(crate) mod fragments {
54 use super::*; 54 use super::*;
55 55
56 pub(crate) use super::{ 56 pub(crate) use super::{
57 expressions::block, paths::type_path as path, patterns::pattern, types::type_, 57 expressions::block_expr, paths::type_path as path, patterns::pattern, types::type_,
58 }; 58 };
59 59
60 pub(crate) fn expr(p: &mut Parser) { 60 pub(crate) fn expr(p: &mut Parser) {
@@ -143,7 +143,7 @@ pub(crate) fn reparser(
143 parent: Option<SyntaxKind>, 143 parent: Option<SyntaxKind>,
144) -> Option<fn(&mut Parser)> { 144) -> Option<fn(&mut Parser)> {
145 let res = match node { 145 let res = match node {
146 BLOCK => expressions::naked_block, 146 BLOCK_EXPR => expressions::block_expr,
147 RECORD_FIELD_DEF_LIST => items::record_field_def_list, 147 RECORD_FIELD_DEF_LIST => items::record_field_def_list,
148 RECORD_FIELD_LIST => items::record_field_list, 148 RECORD_FIELD_LIST => items::record_field_list,
149 ENUM_VARIANT_LIST => items::enum_variant_list, 149 ENUM_VARIANT_LIST => items::enum_variant_list,
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index cb30b25a8..34f039768 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -2,7 +2,7 @@
2 2
3mod atom; 3mod atom;
4 4
5pub(crate) use self::atom::match_arm_list; 5pub(crate) use self::atom::{block_expr, match_arm_list};
6pub(super) use self::atom::{literal, LITERAL_FIRST}; 6pub(super) use self::atom::{literal, LITERAL_FIRST};
7use super::*; 7use super::*;
8 8
@@ -49,28 +49,6 @@ fn expr_no_struct(p: &mut Parser) {
49 expr_bp(p, r, 1); 49 expr_bp(p, r, 1);
50} 50}
51 51
52// test block
53// fn a() {}
54// fn b() { let _ = 1; }
55// fn c() { 1; 2; }
56// fn d() { 1; 2 }
57pub(crate) fn block(p: &mut Parser) {
58 if !p.at(T!['{']) {
59 p.error("expected a block");
60 return;
61 }
62 atom::block_expr(p, None);
63}
64
65pub(crate) fn naked_block(p: &mut Parser) {
66 assert!(p.at(T!['{']));
67 let m = p.start();
68 p.bump(T!['{']);
69 expr_block_contents(p);
70 p.expect(T!['}']);
71 m.complete(p, BLOCK);
72}
73
74fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool { 52fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool {
75 match kind { 53 match kind {
76 BIN_EXPR | RANGE_EXPR | IF_EXPR => false, 54 BIN_EXPR | RANGE_EXPR | IF_EXPR => false,
@@ -197,7 +175,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
197 } 175 }
198} 176}
199 177
200pub(crate) fn expr_block_contents(p: &mut Parser) { 178pub(super) fn expr_block_contents(p: &mut Parser) {
201 // This is checked by a validator 179 // This is checked by a validator
202 attributes::inner_attributes(p); 180 attributes::inner_attributes(p);
203 181
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 76aa601cb..706a2f796 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -84,7 +84,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
84 T![box] => box_expr(p, None), 84 T![box] => box_expr(p, None),
85 T![for] => for_expr(p, None), 85 T![for] => for_expr(p, None),
86 T![while] => while_expr(p, None), 86 T![while] => while_expr(p, None),
87 T![try] => try_expr(p, None), 87 T![try] => try_block_expr(p, None),
88 LIFETIME if la == T![:] => { 88 LIFETIME if la == T![:] => {
89 let m = p.start(); 89 let m = p.start();
90 label(p); 90 label(p);
@@ -92,7 +92,12 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
92 T![loop] => loop_expr(p, Some(m)), 92 T![loop] => loop_expr(p, Some(m)),
93 T![for] => for_expr(p, Some(m)), 93 T![for] => for_expr(p, Some(m)),
94 T![while] => while_expr(p, Some(m)), 94 T![while] => while_expr(p, Some(m)),
95 T!['{'] => block_expr(p, Some(m)), 95 // test labeled_block
96 // fn f() { 'label: {}; }
97 T!['{'] => {
98 block_expr(p);
99 m.complete(p, EFFECT_EXPR)
100 }
96 _ => { 101 _ => {
97 // test_err misplaced_label_err 102 // test_err misplaced_label_err
98 // fn main() { 103 // fn main() {
@@ -108,13 +113,17 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
108 let m = p.start(); 113 let m = p.start();
109 p.bump(T![async]); 114 p.bump(T![async]);
110 p.eat(T![move]); 115 p.eat(T![move]);
111 block_expr(p, Some(m)) 116 block_expr(p);
117 m.complete(p, EFFECT_EXPR)
112 } 118 }
113 T![match] => match_expr(p), 119 T![match] => match_expr(p),
120 // test unsafe_block
121 // fn f() { unsafe { } }
114 T![unsafe] if la == T!['{'] => { 122 T![unsafe] if la == T!['{'] => {
115 let m = p.start(); 123 let m = p.start();
116 p.bump(T![unsafe]); 124 p.bump(T![unsafe]);
117 block_expr(p, Some(m)) 125 block_expr(p);
126 m.complete(p, EFFECT_EXPR)
118 } 127 }
119 T!['{'] => { 128 T!['{'] => {
120 // test for_range_from 129 // test for_range_from
@@ -123,7 +132,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
123 // break; 132 // break;
124 // } 133 // }
125 // } 134 // }
126 block_expr(p, None) 135 block_expr_unchecked(p)
127 } 136 }
128 T![return] => return_expr(p), 137 T![return] => return_expr(p),
129 T![continue] => continue_expr(p), 138 T![continue] => continue_expr(p),
@@ -134,7 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
134 } 143 }
135 }; 144 };
136 let blocklike = match done.kind() { 145 let blocklike = match done.kind() {
137 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_EXPR => { 146 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | EFFECT_EXPR => {
138 BlockLike::Block 147 BlockLike::Block
139 } 148 }
140 _ => BlockLike::NotBlock, 149 _ => BlockLike::NotBlock,
@@ -231,13 +240,9 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
231 p.eat(T![move]); 240 p.eat(T![move]);
232 params::param_list_closure(p); 241 params::param_list_closure(p);
233 if opt_fn_ret_type(p) { 242 if opt_fn_ret_type(p) {
234 if p.at(T!['{']) { 243 // test lambda_ret_block
235 // test lambda_ret_block 244 // fn main() { || -> i32 { 92 }(); }
236 // fn main() { || -> i32 { 92 }(); } 245 block_expr(p);
237 block_expr(p, None);
238 } else {
239 p.error("expected `{`");
240 }
241 } else { 246 } else {
242 if p.at_ts(EXPR_FIRST) { 247 if p.at_ts(EXPR_FIRST) {
243 expr(p); 248 expr(p);
@@ -261,13 +266,13 @@ fn if_expr(p: &mut Parser) -> CompletedMarker {
261 let m = p.start(); 266 let m = p.start();
262 p.bump(T![if]); 267 p.bump(T![if]);
263 cond(p); 268 cond(p);
264 block(p); 269 block_expr(p);
265 if p.at(T![else]) { 270 if p.at(T![else]) {
266 p.bump(T![else]); 271 p.bump(T![else]);
267 if p.at(T![if]) { 272 if p.at(T![if]) {
268 if_expr(p); 273 if_expr(p);
269 } else { 274 } else {
270 block(p); 275 block_expr(p);
271 } 276 }
272 } 277 }
273 m.complete(p, IF_EXPR) 278 m.complete(p, IF_EXPR)
@@ -295,7 +300,7 @@ fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
295 assert!(p.at(T![loop])); 300 assert!(p.at(T![loop]));
296 let m = m.unwrap_or_else(|| p.start()); 301 let m = m.unwrap_or_else(|| p.start());
297 p.bump(T![loop]); 302 p.bump(T![loop]);
298 block(p); 303 block_expr(p);
299 m.complete(p, LOOP_EXPR) 304 m.complete(p, LOOP_EXPR)
300} 305}
301 306
@@ -310,7 +315,7 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
310 let m = m.unwrap_or_else(|| p.start()); 315 let m = m.unwrap_or_else(|| p.start());
311 p.bump(T![while]); 316 p.bump(T![while]);
312 cond(p); 317 cond(p);
313 block(p); 318 block_expr(p);
314 m.complete(p, WHILE_EXPR) 319 m.complete(p, WHILE_EXPR)
315} 320}
316 321
@@ -325,7 +330,7 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
325 patterns::pattern(p); 330 patterns::pattern(p);
326 p.expect(T![in]); 331 p.expect(T![in]);
327 expr_no_struct(p); 332 expr_no_struct(p);
328 block(p); 333 block_expr(p);
329 m.complete(p, FOR_EXPR) 334 m.complete(p, FOR_EXPR)
330} 335}
331 336
@@ -458,16 +463,25 @@ fn match_guard(p: &mut Parser) -> CompletedMarker {
458 m.complete(p, MATCH_GUARD) 463 m.complete(p, MATCH_GUARD)
459} 464}
460 465
461// test block_expr 466// test block
462// fn foo() { 467// fn a() {}
463// {}; 468// fn b() { let _ = 1; }
464// unsafe {}; 469// fn c() { 1; 2; }
465// 'label: {}; 470// fn d() { 1; 2 }
466// } 471pub(crate) fn block_expr(p: &mut Parser) {
467pub(super) fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 472 if !p.at(T!['{']) {
473 p.error("expected a block");
474 return;
475 }
476 block_expr_unchecked(p);
477}
478
479fn block_expr_unchecked(p: &mut Parser) -> CompletedMarker {
468 assert!(p.at(T!['{'])); 480 assert!(p.at(T!['{']));
469 let m = m.unwrap_or_else(|| p.start()); 481 let m = p.start();
470 naked_block(p); 482 p.bump(T!['{']);
483 expr_block_contents(p);
484 p.expect(T!['}']);
471 m.complete(p, BLOCK_EXPR) 485 m.complete(p, BLOCK_EXPR)
472} 486}
473 487
@@ -532,7 +546,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
532// fn foo() { 546// fn foo() {
533// let _ = try {}; 547// let _ = try {};
534// } 548// }
535fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 549fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
536 assert!(p.at(T![try])); 550 assert!(p.at(T![try]));
537 let m = m.unwrap_or_else(|| p.start()); 551 let m = m.unwrap_or_else(|| p.start());
538 // Special-case `try!` as macro. 552 // Special-case `try!` as macro.
@@ -552,8 +566,8 @@ fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
552 } 566 }
553 567
554 p.bump(T![try]); 568 p.bump(T![try]);
555 block(p); 569 block_expr(p);
556 m.complete(p, TRY_EXPR) 570 m.complete(p, EFFECT_EXPR)
557} 571}
558 572
559// test box_expr 573// test box_expr
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 1503a8730..67a924de5 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -329,7 +329,7 @@ fn fn_def(p: &mut Parser) {
329 if p.at(T![;]) { 329 if p.at(T![;]) {
330 p.bump(T![;]); 330 p.bump(T![;]);
331 } else { 331 } else {
332 expressions::block(p) 332 expressions::block_expr(p)
333 } 333 }
334} 334}
335 335
diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs
index 33d9973e9..2d61f9d80 100644
--- a/crates/ra_parser/src/grammar/type_args.rs
+++ b/crates/ra_parser/src/grammar/type_args.rs
@@ -48,7 +48,7 @@ fn type_arg(p: &mut Parser) {
48 m.complete(p, ASSOC_TYPE_ARG); 48 m.complete(p, ASSOC_TYPE_ARG);
49 } 49 }
50 T!['{'] => { 50 T!['{'] => {
51 expressions::block(p); 51 expressions::block_expr(p);
52 m.complete(p, CONST_ARG); 52 m.complete(p, CONST_ARG);
53 } 53 }
54 k if k.is_literal() => { 54 k if k.is_literal() => {
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs
index 652492c1e..e08ad4dae 100644
--- a/crates/ra_parser/src/lib.rs
+++ b/crates/ra_parser/src/lib.rs
@@ -112,7 +112,7 @@ pub fn parse_fragment(
112 FragmentKind::Type => grammar::fragments::type_, 112 FragmentKind::Type => grammar::fragments::type_,
113 FragmentKind::Pattern => grammar::fragments::pattern, 113 FragmentKind::Pattern => grammar::fragments::pattern,
114 FragmentKind::Item => grammar::fragments::item, 114 FragmentKind::Item => grammar::fragments::item,
115 FragmentKind::Block => grammar::fragments::block, 115 FragmentKind::Block => grammar::fragments::block_expr,
116 FragmentKind::Visibility => grammar::fragments::opt_visibility, 116 FragmentKind::Visibility => grammar::fragments::opt_visibility,
117 FragmentKind::MetaItem => grammar::fragments::meta_item, 117 FragmentKind::MetaItem => grammar::fragments::meta_item,
118 FragmentKind::Statement => grammar::fragments::stmt, 118 FragmentKind::Statement => grammar::fragments::stmt,
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index ab727ed7e..e7404492a 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -191,6 +191,7 @@ pub enum SyntaxKind {
191 RECORD_LIT, 191 RECORD_LIT,
192 RECORD_FIELD_LIST, 192 RECORD_FIELD_LIST,
193 RECORD_FIELD, 193 RECORD_FIELD,
194 EFFECT_EXPR,
194 BOX_EXPR, 195 BOX_EXPR,
195 CALL_EXPR, 196 CALL_EXPR,
196 INDEX_EXPR, 197 INDEX_EXPR,
@@ -203,7 +204,6 @@ pub enum SyntaxKind {
203 PREFIX_EXPR, 204 PREFIX_EXPR,
204 RANGE_EXPR, 205 RANGE_EXPR,
205 BIN_EXPR, 206 BIN_EXPR,
206 BLOCK,
207 EXTERN_BLOCK, 207 EXTERN_BLOCK,
208 EXTERN_ITEM_LIST, 208 EXTERN_ITEM_LIST,
209 ENUM_VARIANT, 209 ENUM_VARIANT,
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 521ca8ab8..1876afe95 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -16,9 +16,7 @@ use crate::{
16}; 16};
17 17
18pub use self::{ 18pub use self::{
19 expr_extensions::{ 19 expr_extensions::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
20 ArrayExprKind, BinOp, BlockModifier, ElseBranch, LiteralKind, PrefixOp, RangeOp,
21 },
22 extensions::{ 20 extensions::{
23 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, 21 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
24 StructKind, TypeBoundKind, VisibilityKind, 22 StructKind, TypeBoundKind, VisibilityKind,
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 26e4576ff..c507dc683 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -28,7 +28,7 @@ impl ast::BinExpr {
28 28
29impl ast::FnDef { 29impl ast::FnDef {
30 #[must_use] 30 #[must_use]
31 pub fn with_body(&self, body: ast::Block) -> ast::FnDef { 31 pub fn with_body(&self, body: ast::BlockExpr) -> ast::FnDef {
32 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); 32 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
33 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { 33 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() {
34 old_body.syntax().clone().into() 34 old_body.syntax().clone().into()
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 352c0d2c5..7771d6759 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -16,7 +16,7 @@ impl ast::Expr {
16 | ast::Expr::WhileExpr(_) 16 | ast::Expr::WhileExpr(_)
17 | ast::Expr::BlockExpr(_) 17 | ast::Expr::BlockExpr(_)
18 | ast::Expr::MatchExpr(_) 18 | ast::Expr::MatchExpr(_)
19 | ast::Expr::TryExpr(_) => true, 19 | ast::Expr::EffectExpr(_) => true,
20 _ => false, 20 _ => false,
21 } 21 }
22 } 22 }
@@ -43,7 +43,7 @@ impl ast::IfExpr {
43 Some(res) 43 Some(res)
44 } 44 }
45 45
46 fn blocks(&self) -> AstChildren<ast::BlockExpr> { 46 pub fn blocks(&self) -> AstChildren<ast::BlockExpr> {
47 support::children(self.syntax()) 47 support::children(self.syntax())
48 } 48 }
49} 49}
@@ -359,22 +359,34 @@ impl ast::Literal {
359 } 359 }
360} 360}
361 361
362pub enum BlockModifier { 362#[derive(Debug, Clone, PartialEq, Eq)]
363pub enum Effect {
363 Async(SyntaxToken), 364 Async(SyntaxToken),
364 Unsafe(SyntaxToken), 365 Unsafe(SyntaxToken),
366 Try(SyntaxToken),
367 // Very much not an effect, but we stuff it into this node anyway
368 Label(ast::Label),
365} 369}
366 370
367impl ast::BlockExpr { 371impl ast::EffectExpr {
368 pub fn modifier(&self) -> Option<BlockModifier> { 372 pub fn effect(&self) -> Effect {
369 if let Some(token) = self.async_token() { 373 if let Some(token) = self.async_token() {
370 return Some(BlockModifier::Async(token)); 374 return Effect::Async(token);
371 } 375 }
372 if let Some(token) = self.unsafe_token() { 376 if let Some(token) = self.unsafe_token() {
373 return Some(BlockModifier::Unsafe(token)); 377 return Effect::Unsafe(token);
378 }
379 if let Some(token) = self.try_token() {
380 return Effect::Try(token);
381 }
382 if let Some(label) = self.label() {
383 return Effect::Label(label);
374 } 384 }
375 None 385 unreachable!("ast::EffectExpr without Effect")
376 } 386 }
387}
377 388
389impl ast::BlockExpr {
378 /// false if the block is an intrinsic part of the syntax and can't be 390 /// false if the block is an intrinsic part of the syntax and can't be
379 /// replaced with arbitrary expression. 391 /// replaced with arbitrary expression.
380 /// 392 ///
@@ -383,15 +395,12 @@ impl ast::BlockExpr {
383 /// const FOO: () = { stand_alone }; 395 /// const FOO: () = { stand_alone };
384 /// ``` 396 /// ```
385 pub fn is_standalone(&self) -> bool { 397 pub fn is_standalone(&self) -> bool {
386 if self.modifier().is_some() {
387 return false;
388 }
389 let parent = match self.syntax().parent() { 398 let parent = match self.syntax().parent() {
390 Some(it) => it, 399 Some(it) => it,
391 None => return true, 400 None => return true,
392 }; 401 };
393 match parent.kind() { 402 match parent.kind() {
394 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR => false, 403 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR => false,
395 _ => true, 404 _ => true,
396 } 405 }
397 } 406 }
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 45e3dd2d3..528c873e0 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -423,6 +423,10 @@ impl ast::MacroCall {
423 None 423 None
424 } 424 }
425 } 425 }
426
427 pub fn is_bang(&self) -> bool {
428 self.is_macro_rules().is_none()
429 }
426} 430}
427 431
428impl ast::LifetimeParam { 432impl ast::LifetimeParam {
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 3f16592b6..5e844d5ae 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -476,6 +476,19 @@ impl LoopExpr {
476} 476}
477 477
478#[derive(Debug, Clone, PartialEq, Eq, Hash)] 478#[derive(Debug, Clone, PartialEq, Eq, Hash)]
479pub struct EffectExpr {
480 pub(crate) syntax: SyntaxNode,
481}
482impl ast::AttrsOwner for EffectExpr {}
483impl EffectExpr {
484 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
485 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
486 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
487 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
488 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
489}
490
491#[derive(Debug, Clone, PartialEq, Eq, Hash)]
479pub struct ForExpr { 492pub struct ForExpr {
480 pub(crate) syntax: SyntaxNode, 493 pub(crate) syntax: SyntaxNode,
481} 494}
@@ -541,11 +554,12 @@ pub struct BlockExpr {
541 pub(crate) syntax: SyntaxNode, 554 pub(crate) syntax: SyntaxNode,
542} 555}
543impl ast::AttrsOwner for BlockExpr {} 556impl ast::AttrsOwner for BlockExpr {}
557impl ast::ModuleItemOwner for BlockExpr {}
544impl BlockExpr { 558impl BlockExpr {
545 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } 559 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
546 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 560 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
547 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } 561 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
548 pub fn block(&self) -> Option<Block> { support::child(&self.syntax) } 562 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
549} 563}
550 564
551#[derive(Debug, Clone, PartialEq, Eq, Hash)] 565#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -617,8 +631,8 @@ pub struct TryExpr {
617} 631}
618impl ast::AttrsOwner for TryExpr {} 632impl ast::AttrsOwner for TryExpr {}
619impl TryExpr { 633impl TryExpr {
620 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
621 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 634 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
635 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
622} 636}
623 637
624#[derive(Debug, Clone, PartialEq, Eq, Hash)] 638#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1112,19 +1126,6 @@ impl Condition {
1112} 1126}
1113 1127
1114#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1128#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1115pub struct Block {
1116 pub(crate) syntax: SyntaxNode,
1117}
1118impl ast::AttrsOwner for Block {}
1119impl ast::ModuleItemOwner for Block {}
1120impl Block {
1121 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1122 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
1123 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1124 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1125}
1126
1127#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1128pub struct ParamList { 1129pub struct ParamList {
1129 pub(crate) syntax: SyntaxNode, 1130 pub(crate) syntax: SyntaxNode,
1130} 1131}
@@ -1467,6 +1468,7 @@ pub enum Expr {
1467 FieldExpr(FieldExpr), 1468 FieldExpr(FieldExpr),
1468 AwaitExpr(AwaitExpr), 1469 AwaitExpr(AwaitExpr),
1469 TryExpr(TryExpr), 1470 TryExpr(TryExpr),
1471 EffectExpr(EffectExpr),
1470 CastExpr(CastExpr), 1472 CastExpr(CastExpr),
1471 RefExpr(RefExpr), 1473 RefExpr(RefExpr),
1472 PrefixExpr(PrefixExpr), 1474 PrefixExpr(PrefixExpr),
@@ -1949,6 +1951,17 @@ impl AstNode for LoopExpr {
1949 } 1951 }
1950 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1952 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1951} 1953}
1954impl AstNode for EffectExpr {
1955 fn can_cast(kind: SyntaxKind) -> bool { kind == EFFECT_EXPR }
1956 fn cast(syntax: SyntaxNode) -> Option<Self> {
1957 if Self::can_cast(syntax.kind()) {
1958 Some(Self { syntax })
1959 } else {
1960 None
1961 }
1962 }
1963 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1964}
1952impl AstNode for ForExpr { 1965impl AstNode for ForExpr {
1953 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } 1966 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR }
1954 fn cast(syntax: SyntaxNode) -> Option<Self> { 1967 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2631,17 +2644,6 @@ impl AstNode for Condition {
2631 } 2644 }
2632 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2645 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2633} 2646}
2634impl AstNode for Block {
2635 fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK }
2636 fn cast(syntax: SyntaxNode) -> Option<Self> {
2637 if Self::can_cast(syntax.kind()) {
2638 Some(Self { syntax })
2639 } else {
2640 None
2641 }
2642 }
2643 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2644}
2645impl AstNode for ParamList { 2647impl AstNode for ParamList {
2646 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } 2648 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
2647 fn cast(syntax: SyntaxNode) -> Option<Self> { 2649 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3290,6 +3292,9 @@ impl From<AwaitExpr> for Expr {
3290impl From<TryExpr> for Expr { 3292impl From<TryExpr> for Expr {
3291 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } 3293 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) }
3292} 3294}
3295impl From<EffectExpr> for Expr {
3296 fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) }
3297}
3293impl From<CastExpr> for Expr { 3298impl From<CastExpr> for Expr {
3294 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } 3299 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) }
3295} 3300}
@@ -3320,8 +3325,10 @@ impl AstNode for Expr {
3320 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR 3325 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
3321 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL 3326 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
3322 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR 3327 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
3323 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | CAST_EXPR | REF_EXPR 3328 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR
3324 | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => true, 3329 | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => {
3330 true
3331 }
3325 _ => false, 3332 _ => false,
3326 } 3333 }
3327 } 3334 }
@@ -3349,6 +3356,7 @@ impl AstNode for Expr {
3349 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), 3356 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
3350 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), 3357 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
3351 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), 3358 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
3359 EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }),
3352 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), 3360 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
3353 REF_EXPR => Expr::RefExpr(RefExpr { syntax }), 3361 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
3354 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), 3362 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
@@ -3385,6 +3393,7 @@ impl AstNode for Expr {
3385 Expr::FieldExpr(it) => &it.syntax, 3393 Expr::FieldExpr(it) => &it.syntax,
3386 Expr::AwaitExpr(it) => &it.syntax, 3394 Expr::AwaitExpr(it) => &it.syntax,
3387 Expr::TryExpr(it) => &it.syntax, 3395 Expr::TryExpr(it) => &it.syntax,
3396 Expr::EffectExpr(it) => &it.syntax,
3388 Expr::CastExpr(it) => &it.syntax, 3397 Expr::CastExpr(it) => &it.syntax,
3389 Expr::RefExpr(it) => &it.syntax, 3398 Expr::RefExpr(it) => &it.syntax,
3390 Expr::PrefixExpr(it) => &it.syntax, 3399 Expr::PrefixExpr(it) => &it.syntax,
@@ -3865,6 +3874,11 @@ impl std::fmt::Display for LoopExpr {
3865 std::fmt::Display::fmt(self.syntax(), f) 3874 std::fmt::Display::fmt(self.syntax(), f)
3866 } 3875 }
3867} 3876}
3877impl std::fmt::Display for EffectExpr {
3878 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3879 std::fmt::Display::fmt(self.syntax(), f)
3880 }
3881}
3868impl std::fmt::Display for ForExpr { 3882impl std::fmt::Display for ForExpr {
3869 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 3883 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3870 std::fmt::Display::fmt(self.syntax(), f) 3884 std::fmt::Display::fmt(self.syntax(), f)
@@ -4175,11 +4189,6 @@ impl std::fmt::Display for Condition {
4175 std::fmt::Display::fmt(self.syntax(), f) 4189 std::fmt::Display::fmt(self.syntax(), f)
4176 } 4190 }
4177} 4191}
4178impl std::fmt::Display for Block {
4179 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4180 std::fmt::Display::fmt(self.syntax(), f)
4181 }
4182}
4183impl std::fmt::Display for ParamList { 4192impl std::fmt::Display for ParamList {
4184 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 4193 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4185 std::fmt::Display::fmt(self.syntax(), f) 4194 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 492088353..7b17fef49 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -82,14 +82,6 @@ pub fn block_expr(
82 ast_from_text(&format!("fn f() {}", buf)) 82 ast_from_text(&format!("fn f() {}", buf))
83} 83}
84 84
85pub fn block_from_expr(e: ast::Expr) -> ast::Block {
86 return from_text(&format!("{{ {} }}", e));
87
88 fn from_text(text: &str) -> ast::Block {
89 ast_from_text(&format!("fn f() {}", text))
90 }
91}
92
93pub fn expr_unit() -> ast::Expr { 85pub fn expr_unit() -> ast::Expr {
94 expr_from_text("()") 86 expr_from_text("()")
95} 87}
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index ceeb2bde9..d0234cada 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -237,8 +237,7 @@ fn api_walkthrough() {
237 237
238 // Let's get the `1 + 1` expression! 238 // Let's get the `1 + 1` expression!
239 let body: ast::BlockExpr = func.body().unwrap(); 239 let body: ast::BlockExpr = func.body().unwrap();
240 let block = body.block().unwrap(); 240 let expr: ast::Expr = body.expr().unwrap();
241 let expr: ast::Expr = block.expr().unwrap();
242 241
243 // Enums are used to group related ast nodes together, and can be used for 242 // Enums are used to group related ast nodes together, and can be used for
244 // matching. However, because there are no public fields, it's possible to 243 // matching. However, because there are no public fields, it's possible to
@@ -274,8 +273,8 @@ fn api_walkthrough() {
274 assert_eq!(text.to_string(), "1 + 1"); 273 assert_eq!(text.to_string(), "1 + 1");
275 274
276 // There's a bunch of traversal methods on `SyntaxNode`: 275 // There's a bunch of traversal methods on `SyntaxNode`:
277 assert_eq!(expr_syntax.parent().as_ref(), Some(block.syntax())); 276 assert_eq!(expr_syntax.parent().as_ref(), Some(body.syntax()));
278 assert_eq!(block.syntax().first_child_or_token().map(|it| it.kind()), Some(T!['{'])); 277 assert_eq!(body.syntax().first_child_or_token().map(|it| it.kind()), Some(T!['{']));
279 assert_eq!( 278 assert_eq!(
280 expr_syntax.next_sibling_or_token().map(|it| it.kind()), 279 expr_syntax.next_sibling_or_token().map(|it| it.kind()),
281 Some(SyntaxKind::WHITESPACE) 280 Some(SyntaxKind::WHITESPACE)
diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs
index 8e962ab5b..2c08f7e6e 100644
--- a/crates/ra_syntax/src/validation/block.rs
+++ b/crates/ra_syntax/src/validation/block.rs
@@ -6,19 +6,17 @@ use crate::{
6 SyntaxKind::*, 6 SyntaxKind::*,
7}; 7};
8 8
9pub(crate) fn validate_block_expr(expr: ast::BlockExpr, errors: &mut Vec<SyntaxError>) { 9pub(crate) fn validate_block_expr(block: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
10 if let Some(parent) = expr.syntax().parent() { 10 if let Some(parent) = block.syntax().parent() {
11 match parent.kind() { 11 match parent.kind() {
12 FN_DEF | EXPR_STMT | BLOCK => return, 12 FN_DEF | EXPR_STMT | BLOCK_EXPR => return,
13 _ => {} 13 _ => {}
14 } 14 }
15 } 15 }
16 if let Some(block) = expr.block() { 16 errors.extend(block.attrs().map(|attr| {
17 errors.extend(block.attrs().map(|attr| { 17 SyntaxError::new(
18 SyntaxError::new( 18 "A block in this position cannot accept inner attributes",
19 "A block in this position cannot accept inner attributes", 19 attr.syntax().text_range(),
20 attr.syntax().text_range(), 20 )
21 ) 21 }))
22 }))
23 }
24} 22}
diff --git a/crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast b/crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast
index 95cc83caa..375ed45e0 100644
--- a/crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast
+++ b/crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast
@@ -28,10 +28,9 @@ [email protected]
28 [email protected] ")" 28 [email protected] ")"
29 [email protected] " " 29 [email protected] " "
30 [email protected] 30 [email protected]
31 [email protected] 31 [email protected] "{"
32 [email protected] "{" 32 [email protected] "\n"
33 [email protected] "\n" 33 [email protected] "}"
34 [email protected] "}"
35 [email protected] "\n\n\n" 34 [email protected] "\n\n\n"
36 [email protected] 35 [email protected]
37 [email protected] "#" 36 [email protected] "#"
diff --git a/crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast b/crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast
index dc3e12091..b72c92c33 100644
--- a/crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast
+++ b/crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast
@@ -21,9 +21,8 @@ [email protected]
21 [email protected] "(" 21 [email protected] "("
22 [email protected] ")" 22 [email protected] ")"
23 [email protected] 23 [email protected]
24 [email protected] 24 [email protected] "{"
25 [email protected] "{" 25 [email protected] "}"
26 [email protected] "}"
27 [email protected] "\n\n" 26 [email protected] "\n\n"
28 [email protected] 27 [email protected]
29 [email protected] "}" 28 [email protected] "}"
diff --git a/crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast b/crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast
index 97539fcf2..33953d8d7 100644
--- a/crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast
+++ b/crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast
@@ -9,10 +9,9 @@ [email protected]
9 [email protected] ")" 9 [email protected] ")"
10 [email protected] " " 10 [email protected] " "
11 [email protected] 11 [email protected]
12 [email protected] 12 [email protected] "{"
13 [email protected] "{" 13 [email protected] "\n"
14 [email protected] "\n" 14 [email protected] "}"
15 [email protected] "}"
16 [email protected] "\n\n" 15 [email protected] "\n\n"
17 [email protected] 16 [email protected]
18 [email protected] 17 [email protected]
@@ -34,30 +33,28 @@ [email protected]
34 [email protected] "true" 33 [email protected] "true"
35 [email protected] " " 34 [email protected] " "
36 [email protected] 35 [email protected]
37 [email protected] 36 [email protected] "{"
38 [email protected] "{" 37 [email protected] "\n "
39 [email protected] "\n " 38 [email protected]
40 [email protected] 39 [email protected] "1"
41 [email protected] "1" 40 [email protected] "\n "
42 [email protected] "\n " 41 [email protected] "}"
43 [email protected] "}"
44 [email protected] " " 42 [email protected] " "
45 [email protected] "else" 43 [email protected] "else"
46 [email protected] " " 44 [email protected] " "
47 [email protected] 45 [email protected]
48 [email protected] 46 [email protected] "{"
49 [email protected] "{" 47 [email protected] "\n "
50 [email protected] "\n " 48 [email protected]
51 [email protected] 49 [email protected]
52 [email protected] 50 [email protected] "2"
53 [email protected] "2" 51 [email protected] " "
54 [email protected] " " 52 [email protected] "+"
55 [email protected] "+" 53 [email protected] " "
56 [email protected] " " 54 [email protected]
57 [email protected] 55 [email protected] "3"
58 [email protected] "3" 56 [email protected] "\n "
59 [email protected] "\n " 57 [email protected] "}"
60 [email protected] "}"
61 [email protected] "\n" 58 [email protected] "\n"
62 [email protected] "}" 59 [email protected] "}"
63 [email protected] "\n\n" 60 [email protected] "\n\n"
@@ -71,10 +68,9 @@ [email protected]
71 [email protected] ")" 68 [email protected] ")"
72 [email protected] " " 69 [email protected] " "
73 [email protected] 70 [email protected]
74 [email protected] 71 [email protected] "{"
75 [email protected] "{" 72 [email protected] "\n"
76 [email protected] "\n" 73 [email protected] "}"
77 [email protected] "}"
78 [email protected] "\n" 74 [email protected] "\n"
79error 17..17: expected BANG 75error 17..17: expected BANG
80error 19..19: expected SEMICOLON 76error 19..19: expected SEMICOLON
diff --git a/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast b/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast
index e10bb8174..3bf57eacc 100644
--- a/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast
+++ b/crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast
@@ -9,37 +9,36 @@ [email protected]
9 [email protected] ")" 9 [email protected] ")"
10 [email protected] " " 10 [email protected] " "
11 [email protected] 11 [email protected]
12 [email protected] 12 [email protected] "{"
13 [email protected] "{" 13 [email protected] "\n "
14 [email protected] "\n " 14 [email protected]
15 [email protected] 15 [email protected]
16 [email protected] 16 [email protected]
17 [email protected] 17 [email protected] "|"
18 [email protected] "|" 18 [email protected] "|"
19 [email protected] "|" 19 [email protected] " "
20 [email protected] " " 20 [email protected]
21 [email protected] 21 [email protected] "->"
22 [email protected] "->" 22 [email protected] " "
23 [email protected] " " 23 [email protected]
24 [email protected] 24 [email protected] "("
25 [email protected] "(" 25 [email protected] ")"
26 [email protected] ")" 26 [email protected] " "
27 [email protected] " " 27 [email protected]
28 [email protected] 28 [email protected]
29 [email protected] 29 [email protected] "unsafe"
30 [email protected] "unsafe" 30 [email protected] " "
31 [email protected] " " 31 [email protected]
32 [email protected] 32 [email protected] "{"
33 [email protected] "{" 33 [email protected] " "
34 [email protected] " " 34 [email protected]
35 [email protected] 35 [email protected] "("
36 [email protected] "(" 36 [email protected] ")"
37 [email protected] ")" 37 [email protected] " "
38 [email protected] " " 38 [email protected] "}"
39 [email protected] "}" 39 [email protected] ";"
40 [email protected] ";" 40 [email protected] "\n"
41 [email protected] "\n" 41 [email protected] "}"
42 [email protected] "}"
43 [email protected] "\n" 42 [email protected] "\n"
44error 24..24: expected `{` 43error 24..24: expected a block
45error 24..24: expected SEMICOLON 44error 24..24: expected SEMICOLON
diff --git a/crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast b/crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast
index 61c361833..9323b7890 100644
--- a/crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast
+++ b/crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast
@@ -25,8 +25,7 @@ [email protected]
25 [email protected] "T" 25 [email protected] "T"
26 [email protected] " " 26 [email protected] " "
27 [email protected] 27 [email protected]
28 [email protected] 28 [email protected] "{"
29 [email protected] "{" 29 [email protected] "}"
30 [email protected] "}"
31 [email protected] "\n" 30 [email protected] "\n"
32error 19..19: expected colon 31error 19..19: expected colon
diff --git a/crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast b/crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast
index 92bb47316..93434f34f 100644
--- a/crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast
+++ b/crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast
@@ -9,36 +9,35 @@ [email protected]
9 [email protected] ")" 9 [email protected] ")"
10 [email protected] " " 10 [email protected] " "
11 [email protected] 11 [email protected]
12 [email protected] 12 [email protected] "{"
13 [email protected] "{" 13 [email protected] "\n "
14 [email protected] "\n " 14 [email protected]
15 [email protected] 15 [email protected]
16 [email protected] 16 [email protected]
17 [email protected] 17 [email protected]
18 [email protected] 18 [email protected]
19 [email protected] 19 [email protected]
20 [email protected] 20 [email protected] "foo"
21 [email protected] "foo" 21 [email protected]
22 [email protected] 22 [email protected] "("
23 [email protected] "(" 23 [email protected] "\n "
24 [email protected] "\n " 24 [email protected]
25 [email protected] 25 [email protected] "1"
26 [email protected] "1" 26 [email protected] ","
27 [email protected] "," 27 [email protected] " "
28 [email protected] " " 28 [email protected]
29 [email protected] 29 [email protected] "2"
30 [email protected] "2" 30 [email protected] "\n "
31 [email protected] "\n " 31 [email protected] ")"
32 [email protected] ")" 32 [email protected] "\n "
33 [email protected] "\n " 33 [email protected]
34 [email protected] 34 [email protected]
35 [email protected] 35 [email protected] "return"
36 [email protected] "return" 36 [email protected] " "
37 [email protected] " " 37 [email protected]
38 [email protected] 38 [email protected] "92"
39 [email protected] "92" 39 [email protected] ";"
40 [email protected] ";" 40 [email protected] "\n"
41 [email protected] "\n" 41 [email protected] "}"
42 [email protected] "}"
43 [email protected] "\n" 42 [email protected] "\n"
44error 38..38: expected SEMICOLON 43error 38..38: expected SEMICOLON
diff --git a/crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast b/crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast
index 7bc718302..628315c78 100644
--- a/crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast
+++ b/crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast
@@ -20,28 +20,27 @@ [email protected]
20 [email protected] ")" 20 [email protected] ")"
21 [email protected] " " 21 [email protected] " "
22 [email protected] 22 [email protected]
23 [email protected] 23 [email protected] "{"
24 [email protected] "{" 24 [email protected] "\n "
25 [email protected] "\n " 25 [email protected]
26 [email protected] 26 [email protected] "let"
27 [email protected] "let" 27 [email protected] " "
28 [email protected] " " 28 [email protected]
29 [email protected] 29 [email protected]
30 [email protected] 30 [email protected] "bar"
31 [email protected] "bar" 31 [email protected] " "
32 [email protected] " " 32 [email protected] "="
33 [email protected] "=" 33 [email protected] " "
34 [email protected] " " 34 [email protected]
35 [email protected] 35 [email protected] "92"
36 [email protected] "92" 36 [email protected] ";"
37 [email protected] ";" 37 [email protected] "\n "
38 [email protected] "\n " 38 [email protected]
39 [email protected] 39 [email protected]
40 [email protected] 40 [email protected] "1"
41 [email protected] "1" 41 [email protected] " "
42 [email protected] " " 42 [email protected] "+"
43 [email protected] "+" 43 [email protected] "\n"
44 [email protected] "\n" 44 [email protected] "}"
45 [email protected] "}"
46 [email protected] "\n" 45 [email protected] "\n"
47error 44..44: expected expression 46error 44..44: expected expression
diff --git a/crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast b/crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast
index 63194f974..31cc4e551 100644
--- a/crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast
+++ b/crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast
@@ -33,89 +33,88 @@ [email protected]
33 [email protected] "ScopeId" 33 [email protected] "ScopeId"
34 [email protected] " " 34 [email protected] " "
35 [email protected] 35 [email protected]
36 [email protected] 36 [email protected] "{"
37 [email protected] "{" 37 [email protected] "\n "
38 [email protected] "\n " 38 [email protected]
39 [email protected] 39 [email protected] "let"
40 [email protected] "let" 40 [email protected] " "
41 [email protected] " " 41 [email protected]
42 [email protected] 42 [email protected]
43 [email protected] 43 [email protected] "res"
44 [email protected] "res" 44 [email protected] " "
45 [email protected] " " 45 [email protected] "="
46 [email protected] "=" 46 [email protected] " "
47 [email protected] " " 47 [email protected]
48 [email protected] 48 [email protected]
49 [email protected] 49 [email protected]
50 [email protected] 50 [email protected]
51 [email protected] 51 [email protected]
52 [email protected] 52 [email protected] "self"
53 [email protected] "self" 53 [email protected] "."
54 [email protected] "." 54 [email protected]
55 [email protected] 55 [email protected] "scopes"
56 [email protected] "scopes" 56 [email protected] "."
57 [email protected] "." 57 [email protected]
58 [email protected] 58 [email protected] "len"
59 [email protected] "len" 59 [email protected]
60 [email protected] 60 [email protected] "("
61 [email protected] "(" 61 [email protected] ")"
62 [email protected] ")" 62 [email protected] ";"
63 [email protected] ";" 63 [email protected] "\n "
64 [email protected] "\n " 64 [email protected]
65 [email protected] 65 [email protected]
66 [email protected] 66 [email protected]
67 [email protected] 67 [email protected]
68 [email protected] 68 [email protected]
69 [email protected] 69 [email protected] "self"
70 [email protected] "self" 70 [email protected] "."
71 [email protected] "." 71 [email protected]
72 [email protected] 72 [email protected] "scopes"
73 [email protected] "scopes" 73 [email protected] "."
74 [email protected] "." 74 [email protected]
75 [email protected] 75 [email protected] "push"
76 [email protected] "push" 76 [email protected]
77 [email protected] 77 [email protected] "("
78 [email protected] "(" 78 [email protected]
79 [email protected] 79 [email protected]
80 [email protected] 80 [email protected]
81 [email protected] 81 [email protected]
82 [email protected] 82 [email protected] "ScopeData"
83 [email protected] "ScopeData" 83 [email protected] " "
84 [email protected] " " 84 [email protected]
85 [email protected] 85 [email protected] "{"
86 [email protected] "{" 86 [email protected] " "
87 [email protected] " " 87 [email protected]
88 [email protected] 88 [email protected]
89 [email protected] 89 [email protected] "parent"
90 [email protected] "parent" 90 [email protected] ":"
91 [email protected] ":" 91 [email protected] " "
92 [email protected] " " 92 [email protected]
93 [email protected] 93 [email protected]
94 [email protected] 94 [email protected]
95 [email protected] 95 [email protected]
96 [email protected] 96 [email protected] "None"
97 [email protected] "None" 97 [email protected] ","
98 [email protected] "," 98 [email protected] " "
99 [email protected] " " 99 [email protected]
100 [email protected] 100 [email protected]
101 [email protected] 101 [email protected] "entries"
102 [email protected] "entries" 102 [email protected] ":"
103 [email protected] ":" 103 [email protected] " "
104 [email protected] " " 104 [email protected]
105 [email protected] 105 [email protected]
106 [email protected] 106 [email protected]
107 [email protected] 107 [email protected]
108 [email protected] 108 [email protected] "vec"
109 [email protected] "vec" 109 [email protected] "!"
110 [email protected] "!" 110 [email protected]
111 [email protected] 111 [email protected] "["
112 [email protected] "[" 112 [email protected] "]"
113 [email protected] "]" 113 [email protected] " "
114 [email protected] " " 114 [email protected] "}"
115 [email protected] "}" 115 [email protected] ")"
116 [email protected] ")" 116 [email protected] "\n "
117 [email protected] "\n " 117 [email protected] "}"
118 [email protected] "}"
119 [email protected] "\n\n " 118 [email protected] "\n\n "
120 [email protected] 119 [email protected]
121 [email protected] "fn" 120 [email protected] "fn"
diff --git a/crates/ra_syntax/test_data/parser/err/0019_let_recover.rast b/crates/ra_syntax/test_data/parser/err/0019_let_recover.rast
index d20bb60f1..4ff27f5c8 100644
--- a/crates/ra_syntax/test_data/parser/err/0019_let_recover.rast
+++ b/crates/ra_syntax/test_data/parser/err/0019_let_recover.rast
@@ -9,91 +9,87 @@ [email protected]
9 [email protected] ")" 9 [email protected] ")"
10 [email protected] " " 10 [email protected] " "
11 [email protected] 11 [email protected]
12 [email protected] 12 [email protected] "{"
13 [email protected] "{" 13 [email protected] "\n "
14 [email protected] "\n " 14 [email protected]
15 [email protected] 15 [email protected] "let"
16 [email protected] "let" 16 [email protected] " "
17 [email protected] " " 17 [email protected]
18 [email protected] 18 [email protected]
19 [email protected] 19 [email protected] "foo"
20 [email protected] "foo" 20 [email protected] " "
21 [email protected] " " 21 [email protected] "="
22 [email protected] "=" 22 [email protected] "\n "
23 [email protected] "\n " 23 [email protected]
24 [email protected] 24 [email protected] "let"
25 [email protected] "let" 25 [email protected] " "
26 [email protected] " " 26 [email protected]
27 [email protected] 27 [email protected]
28 [email protected] 28 [email protected] "bar"
29 [email protected] "bar" 29 [email protected] " "
30 [email protected] " " 30 [email protected] "="
31 [email protected] "=" 31 [email protected] " "
32 [email protected] " " 32 [email protected]
33 [email protected] 33 [email protected] "1"
34 [email protected] "1" 34 [email protected] ";"
35 [email protected] ";" 35 [email protected] "\n "
36 [email protected] "\n " 36 [email protected]
37 [email protected] 37 [email protected] "let"
38 [email protected] "let" 38 [email protected] "\n "
39 [email protected] "\n " 39 [email protected]
40 [email protected] 40 [email protected] "let"
41 [email protected] "let" 41 [email protected] " "
42 [email protected] " " 42 [email protected]
43 [email protected] 43 [email protected]
44 [email protected] 44 [email protected] "baz"
45 [email protected] "baz" 45 [email protected] " "
46 [email protected] " " 46 [email protected] "="
47 [email protected] "=" 47 [email protected] " "
48 [email protected] " " 48 [email protected]
49 [email protected] 49 [email protected] "92"
50 [email protected] "92" 50 [email protected] ";"
51 [email protected] ";" 51 [email protected] "\n "
52 [email protected] "\n " 52 [email protected]
53 [email protected] 53 [email protected] "let"
54 [email protected] "let" 54 [email protected] "\n "
55 [email protected] "\n " 55 [email protected]
56 [email protected] 56 [email protected]
57 [email protected] 57 [email protected] "if"
58 [email protected] "if" 58 [email protected] " "
59 [email protected] " " 59 [email protected]
60 [email protected] 60 [email protected]
61 [email protected] 61 [email protected] "true"
62 [email protected] "true" 62 [email protected] " "
63 [email protected] " " 63 [email protected]
64 [email protected] 64 [email protected] "{"
65 [email protected] 65 [email protected] "}"
66 [email protected] "{" 66 [email protected] "\n "
67 [email protected] "}" 67 [email protected]
68 [email protected] "\n " 68 [email protected] "let"
69 [email protected] 69 [email protected] "\n "
70 [email protected] "let" 70 [email protected]
71 [email protected] "\n " 71 [email protected]
72 [email protected] 72 [email protected] "while"
73 [email protected] 73 [email protected] " "
74 [email protected] "while" 74 [email protected]
75 [email protected] " " 75 [email protected]
76 [email protected] 76 [email protected] "true"
77 [email protected] 77 [email protected] " "
78 [email protected] "true" 78 [email protected]
79 [email protected] " " 79 [email protected] "{"
80 [email protected] 80 [email protected] "}"
81 [email protected] 81 [email protected] "\n "
82 [email protected] "{" 82 [email protected]
83 [email protected] "}" 83 [email protected] "let"
84 [email protected] "\n " 84 [email protected] "\n "
85 [email protected] 85 [email protected]
86 [email protected] "let" 86 [email protected] "loop"
87 [email protected] "\n " 87 [email protected] " "
88 [email protected] 88 [email protected]
89 [email protected] "loop" 89 [email protected] "{"
90 [email protected] " " 90 [email protected] "}"
91 [email protected] 91 [email protected] "\n"
92 [email protected] 92 [email protected] "}"
93 [email protected] "{"
94 [email protected] "}"
95 [email protected] "\n"
96 [email protected] "}"
97 [email protected] "\n" 93 [email protected] "\n"
98error 24..24: expected expression