aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/flycheck/Cargo.toml2
-rw-r--r--crates/flycheck/src/lib.rs13
-rw-r--r--crates/ra_assists/src/assist_context.rs4
-rw-r--r--crates/ra_assists/src/ast_transform.rs34
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs20
-rw-r--r--crates/ra_assists/src/handlers/add_missing_impl_members.rs29
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs2
-rw-r--r--crates/ra_assists/src/handlers/change_return_type_to_result.rs9
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs10
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs14
-rw-r--r--crates/ra_assists/src/handlers/expand_glob_import.rs391
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs2
-rw-r--r--crates/ra_assists/src/handlers/extract_variable.rs6
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs29
-rw-r--r--crates/ra_assists/src/handlers/fix_visibility.rs2
-rw-r--r--crates/ra_assists/src/handlers/generate_derive.rs4
-rw-r--r--crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs8
-rw-r--r--crates/ra_assists/src/handlers/generate_function.rs8
-rw-r--r--crates/ra_assists/src/handlers/generate_impl.rs6
-rw-r--r--crates/ra_assists/src/handlers/generate_new.rs24
-rw-r--r--crates/ra_assists/src/handlers/inline_local_variable.rs2
-rw-r--r--crates/ra_assists/src/handlers/introduce_named_lifetime.rs24
-rw-r--r--crates/ra_assists/src/handlers/merge_imports.rs2
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs2
-rw-r--r--crates/ra_assists/src/handlers/move_bounds.rs14
-rw-r--r--crates/ra_assists/src/handlers/raw_string.rs2
-rw-r--r--crates/ra_assists/src/handlers/remove_dbg.rs94
-rw-r--r--crates/ra_assists/src/handlers/reorder_fields.rs10
-rw-r--r--crates/ra_assists/src/handlers/replace_if_let_with_match.rs2
-rw-r--r--crates/ra_assists/src/handlers/replace_let_with_if_let.rs7
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs46
-rw-r--r--crates/ra_assists/src/handlers/replace_unwrap_with_match.rs4
-rw-r--r--crates/ra_assists/src/lib.rs2
-rw-r--r--crates/ra_assists/src/tests/generated.rs27
-rw-r--r--crates/ra_assists/src/utils.rs24
-rw-r--r--crates/ra_assists/src/utils/insert_use.rs13
-rw-r--r--crates/ra_db/Cargo.toml2
-rw-r--r--crates/ra_hir/src/code_model.rs6
-rw-r--r--crates/ra_hir/src/db.rs9
-rw-r--r--crates/ra_hir/src/has_source.rs42
-rw-r--r--crates/ra_hir/src/semantics.rs49
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs73
-rw-r--r--crates/ra_hir/src/source_analyzer.rs22
-rw-r--r--crates/ra_hir_def/src/adt.rs18
-rw-r--r--crates/ra_hir_def/src/attr.rs19
-rw-r--r--crates/ra_hir_def/src/body.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs163
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs2
-rw-r--r--crates/ra_hir_def/src/generics.rs16
-rw-r--r--crates/ra_hir_def/src/item_tree.rs52
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs175
-rw-r--r--crates/ra_hir_def/src/item_tree/tests.rs62
-rw-r--r--crates/ra_hir_def/src/keys.rs26
-rw-r--r--crates/ra_hir_def/src/lib.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs4
-rw-r--r--crates/ra_hir_def/src/path.rs4
-rw-r--r--crates/ra_hir_def/src/path/lower.rs52
-rw-r--r--crates/ra_hir_def/src/path/lower/lower_use.rs2
-rw-r--r--crates/ra_hir_def/src/type_ref.rs48
-rw-r--r--crates/ra_hir_expand/src/ast_id_map.rs2
-rw-r--r--crates/ra_hir_expand/src/builtin_derive.rs10
-rw-r--r--crates/ra_hir_expand/src/db.rs4
-rw-r--r--crates/ra_hir_expand/src/lib.rs6
-rw-r--r--crates/ra_hir_expand/src/proc_macro.rs2
-rw-r--r--crates/ra_hir_ty/Cargo.toml6
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs14
-rw-r--r--crates/ra_hir_ty/src/diagnostics/expr.rs6
-rw-r--r--crates/ra_hir_ty/src/diagnostics/unsafe_check.rs38
-rw-r--r--crates/ra_hir_ty/src/infer.rs11
-rw-r--r--crates/ra_hir_ty/src/lower.rs5
-rw-r--r--crates/ra_hir_ty/src/tests.rs2
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs38
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs19
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs22
-rw-r--r--crates/ra_ide/Cargo.toml2
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs54
-rw-r--r--crates/ra_ide/src/completion/complete_attribute.rs12
-rw-r--r--crates/ra_ide/src/completion/complete_fn_param.rs40
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs38
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs25
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs30
-rw-r--r--crates/ra_ide/src/completion/patterns.rs18
-rw-r--r--crates/ra_ide/src/completion/unstable_feature_descriptor.rs2
-rw-r--r--crates/ra_ide/src/diagnostics.rs32
-rw-r--r--crates/ra_ide/src/display.rs12
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs46
-rw-r--r--crates/ra_ide/src/display/short_label.rs34
-rw-r--r--crates/ra_ide/src/extend_selection.rs12
-rw-r--r--crates/ra_ide/src/file_structure.rs80
-rw-r--r--crates/ra_ide/src/folding_ranges.rs31
-rw-r--r--crates/ra_ide/src/goto_implementation.rs14
-rw-r--r--crates/ra_ide/src/hover.rs68
-rw-r--r--crates/ra_ide/src/inlay_hints.rs22
-rw-r--r--crates/ra_ide/src/lib.rs3
-rw-r--r--crates/ra_ide/src/references.rs48
-rw-r--r--crates/ra_ide/src/references/rename.rs18
-rw-r--r--crates/ra_ide/src/runnables.rs200
-rw-r--r--crates/ra_ide/src/ssr.rs10
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs97
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs10
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs21
-rw-r--r--crates/ra_ide/src/syntax_tree.rs14
-rw-r--r--crates/ra_ide/test_data/highlight_unsafe.html18
-rw-r--r--crates/ra_ide/test_data/highlighting.html9
-rw-r--r--crates/ra_ide/test_data/rainbow_highlighting.html12
-rw-r--r--crates/ra_ide_db/src/change.rs24
-rw-r--r--crates/ra_ide_db/src/defs.rs57
-rw-r--r--crates/ra_ide_db/src/search.rs2
-rw-r--r--crates/ra_ide_db/src/symbol_index.rs16
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs2
-rw-r--r--crates/ra_mbe/src/tests.rs22
-rw-r--r--crates/ra_parser/src/grammar.rs20
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs6
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs2
-rw-r--r--crates/ra_parser/src/grammar/items.rs18
-rw-r--r--crates/ra_parser/src/grammar/items/adt.rs18
-rw-r--r--crates/ra_parser/src/grammar/items/consts.rs4
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs4
-rw-r--r--crates/ra_parser/src/grammar/items/use_item.rs2
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs12
-rw-r--r--crates/ra_parser/src/grammar/type_args.rs4
-rw-r--r--crates/ra_parser/src/grammar/type_params.rs2
-rw-r--r--crates/ra_parser/src/grammar/types.rs8
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs72
-rw-r--r--crates/ra_proc_macro_srv/Cargo.toml2
-rw-r--r--crates/ra_prof/Cargo.toml3
-rw-r--r--crates/ra_prof/src/lib.rs2
-rw-r--r--crates/ra_prof/src/memory_usage.rs37
-rw-r--r--crates/ra_prof/src/stop_watch.rs86
-rw-r--r--crates/ra_project_model/Cargo.toml2
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs29
-rw-r--r--crates/ra_project_model/src/cfg_flag.rs4
-rw-r--r--crates/ra_project_model/src/sysroot.rs90
-rw-r--r--crates/ra_ssr/src/lib.rs6
-rw-r--r--crates/ra_ssr/src/matching.rs12
-rw-r--r--crates/ra_ssr/src/parsing.rs31
-rw-r--r--crates/ra_ssr/src/replacing.rs106
-rw-r--r--crates/ra_ssr/src/resolving.rs35
-rw-r--r--crates/ra_ssr/src/search.rs98
-rw-r--r--crates/ra_ssr/src/tests.rs195
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/ast.rs20
-rw-r--r--crates/ra_syntax/src/ast/edit.rs51
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs13
-rw-r--r--crates/ra_syntax/src/ast/generated.rs41
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs4754
-rw-r--r--crates/ra_syntax/src/ast/make.rs28
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs141
-rw-r--r--crates/ra_syntax/src/ast/traits.rs12
-rw-r--r--crates/ra_syntax/src/lib.rs10
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs4
-rw-r--r--crates/ra_syntax/src/ptr.rs2
-rw-r--r--crates/ra_syntax/src/tests.rs4
-rw-r--r--crates/ra_syntax/src/validation.rs10
-rw-r--r--crates/ra_syntax/src/validation/block.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0000_struct_field_missing_comma.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0001_item_recovery_in_file.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0003_C++_semicolon.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0006_named_field_recovery.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0009_broken_struct_type_parameter.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0011_extern_struct.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0012_broken_lambda.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/err/0013_invalid_type.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0015_curly_in_params.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/err/0019_let_recover.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0020_fn_recover.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0021_incomplete_param.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0022_bad_exprs.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/err/0023_mismatched_paren.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast30
-rw-r--r--crates/ra_syntax/test_data/parser/err/0025_nope.rast50
-rw-r--r--crates/ra_syntax/test_data/parser/err/0026_imp_recovery.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/err/0027_incomplere_where_for.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0029_field_completion.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0031_block_inner_attrs.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0032_match_arms_inner_attrs.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/err/0033_match_arms_outer_attrs.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0034_bad_box_pattern.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0035_use_recover.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/err/0036_partial_use.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0039_lambda_recovery.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0041_illegal_super_keyword_location.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0042_illegal_self_keyword_location.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_default_const.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0044_unexpected_for_type.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/item/ok/0000_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/ok/0000_enum.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/type/ok/0000_result.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/fuzz-failures/0000.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0001_array_type_missing_semi.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0002_misplaced_label_err.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0003_pointer_type_no_mutability.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0004_impl_type.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0005_fn_pointer_type_missing_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0006_unsafe_block_in_mod.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0007_async_without_semicolon.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0008_pub_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_bad_tuple_index_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_record_literal_before_ellipsis_recovery.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0003_where_pred_for.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0004_value_parameters_no_patterns.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0005_function_type_params.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0006_self_param.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0007_type_param_bounds.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0008_path_part.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0009_loop_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0011_field_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0012_type_item_where_clause.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0013_pointer_type_mut.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0014_never_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0015_continue_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0017_array_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0018_arb_self_types.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0020_use_star.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0022_crate_visibility.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0023_placeholder_type.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0024_slice_pat.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0025_slice_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0026_tuple_pat_fields.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0027_ref_pat.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0028_impl_trait_type.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0029_cast_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0030_cond.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0031_while_expr.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0032_fn_pointer_type.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0033_reference_type;.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0034_break_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0037_qual_paths.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0038_full_range_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0040_crate_keyword_vis.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0041_trait_item.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0042_call_expr.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0043_use_alias.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0044_block_items.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0045_param_list_opt_patterns.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0046_singleton_tuple_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0048_path_type_with_bounds.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0050_fn_decl.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0051_unit_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0052_path_type.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0053_path_expr.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0055_literal_pattern.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0056_where_clause.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0058_range_pat.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0059_match_arms_commas.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0060_extern_crate.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_record_lit.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0062_mod_contents.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0064_if_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0065_dyn_trait_type.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0067_crate_path.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0070_stmt_bin_expr_ambiguity.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0071_match_expr.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0072_return_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0073_type_item_type_params.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0074_stmt_postfix_expr_ambiguity.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0075_block.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0076_function_where_clause.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0077_try_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0078_type_item.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0079_impl_def.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0080_postfix_range.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0083_struct_items.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0084_paren_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0085_expr_literals.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0086_function_ret_type.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0088_break_ambiguity.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0090_type_param_default.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0092_fn_pointer_type_with_ret.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0093_index_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0095_placeholder_pat.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0096_no_semi_after_block.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0099_param_list.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0100_for_expr.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0102_record_field_pat_list.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0103_array_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0104_path_fn_trait_args.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0106_lambda_expr.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0107_method_call_expr.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0108_tuple_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0109_label.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0110_use_path.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0111_tuple_pat.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0112_bind_pat.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0113_nocontentexpr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0117_macro_call_type.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_match_guard.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0120_match_arms_inner_attribute.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0121_match_arms_outer_attributes.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0123_param_list_vararg.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_crate_keyword_path.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_record_literal_field_with_attr.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0126_attr_on_expr_stmt.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0127_attr_on_last_expr_in_block.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_let_stmt.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_try_block_expr.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0131_existential_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_box_expr.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0134_nocontentexpr_after_item.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0137_await_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_associated_type_bounds.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0139_param_outer_arg.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0144_dot_dot_pat.rast94
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_impl_type_params.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_arg_with_attr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0154_fn_pointer_param_ident_path.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0155_closure_params.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_fn_def_param.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_or_pattern.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_lambda_ret_block.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0161_labeled_block.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0162_unsafe_block.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0001_struct_item.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0002_struct_item_field.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0005_fn_item.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0007_extern_crate.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0008_mod_item.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0009_use_item.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0010_use_path_segments.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0011_outer_attribute.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0012_visibility.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0013_use_path_self_super.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0014_use_tree.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0015_use_tree.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0016_struct_flavors.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0017_attr_trailing_comma.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0018_struct_type_params.rast68
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0019_enums.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0020_type_param_bounds.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0023_static_items.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0024_const_item.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0025_extern_fn_in_block.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0026_const_fn_in_block.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0027_unsafe_fn_in_block.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0028_operator_binding_power.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0029_range_forms.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_string_suffixes.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_traits.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0031_extern.rast150
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0032_where_for.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0033_label_break.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0034_crate_path_in_call.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0036_fully_qualified.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0038_where_pred_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0039_raw_fn_item.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0040_raw_struct_item_field.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0041_raw_keywords.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0042_ufcs_call_list.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0043_complex_assignment.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0044_let_attrs.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0045_block_inner_attrs.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0047_minus_in_inner_pattern.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0048_compound_assignment.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0049_async_block.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0050_async_block_as_argument.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0051_parameter_attrs.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0054_qual_path_in_type_arg.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0055_dot_dot_dot.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0056_neq_in_type.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0057_loop_in_call.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0059_loops_in_parens.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0060_as_range.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0062_macro_2.0.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_variadic_fun.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0064_impl_fn_params.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_plus_after_fn_trait_bound.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_const.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0067_where_for_pred.rast60
-rw-r--r--crates/rust-analyzer/Cargo.toml6
-rw-r--r--crates/rust-analyzer/src/bin/args.rs65
-rw-r--r--crates/rust-analyzer/src/bin/main.rs51
-rw-r--r--crates/rust-analyzer/src/caps.rs4
-rw-r--r--crates/rust-analyzer/src/cli.rs4
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs135
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs474
-rw-r--r--crates/rust-analyzer/src/config.rs5
-rw-r--r--crates/rust-analyzer/src/document.rs6
-rw-r--r--crates/rust-analyzer/src/global_state.rs8
-rw-r--r--crates/rust-analyzer/src/handlers.rs78
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs3
-rw-r--r--crates/rust-analyzer/src/lsp_utils.rs40
-rw-r--r--crates/rust-analyzer/src/main_loop.rs21
-rw-r--r--crates/rust-analyzer/src/semantic_tokens.rs139
-rw-r--r--crates/rust-analyzer/src/to_proto.rs39
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs8
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs3
-rw-r--r--crates/stdx/src/lib.rs15
-rw-r--r--crates/test_utils/src/fixture.rs8
462 files changed, 6459 insertions, 6421 deletions
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml
index bea485694..ff8a1e568 100644
--- a/crates/flycheck/Cargo.toml
+++ b/crates/flycheck/Cargo.toml
@@ -11,7 +11,7 @@ doctest = false
11[dependencies] 11[dependencies]
12crossbeam-channel = "0.4.0" 12crossbeam-channel = "0.4.0"
13log = "0.4.8" 13log = "0.4.8"
14cargo_metadata = "0.10.0" 14cargo_metadata = "0.11.1"
15serde_json = "1.0.48" 15serde_json = "1.0.48"
16jod-thread = "0.1.1" 16jod-thread = "0.1.1"
17ra_toolchain = { path = "../ra_toolchain" } 17ra_toolchain = { path = "../ra_toolchain" }
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index ad376ad18..7c38f5ef9 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -24,6 +24,7 @@ pub enum FlycheckConfig {
24 command: String, 24 command: String,
25 target_triple: Option<String>, 25 target_triple: Option<String>,
26 all_targets: bool, 26 all_targets: bool,
27 no_default_features: bool,
27 all_features: bool, 28 all_features: bool,
28 features: Vec<String>, 29 features: Vec<String>,
29 extra_args: Vec<String>, 30 extra_args: Vec<String>,
@@ -180,6 +181,7 @@ impl FlycheckActor {
180 FlycheckConfig::CargoCommand { 181 FlycheckConfig::CargoCommand {
181 command, 182 command,
182 target_triple, 183 target_triple,
184 no_default_features,
183 all_targets, 185 all_targets,
184 all_features, 186 all_features,
185 extra_args, 187 extra_args,
@@ -198,9 +200,14 @@ impl FlycheckActor {
198 } 200 }
199 if *all_features { 201 if *all_features {
200 cmd.arg("--all-features"); 202 cmd.arg("--all-features");
201 } else if !features.is_empty() { 203 } else {
202 cmd.arg("--features"); 204 if *no_default_features {
203 cmd.arg(features.join(" ")); 205 cmd.arg("--no-default-features");
206 }
207 if !features.is_empty() {
208 cmd.arg("--features");
209 cmd.arg(features.join(" "));
210 }
204 } 211 }
205 cmd.args(extra_args); 212 cmd.args(extra_args);
206 cmd 213 cmd
diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs
index 3407df856..afd3fd4b9 100644
--- a/crates/ra_assists/src/assist_context.rs
+++ b/crates/ra_assists/src/assist_context.rs
@@ -73,6 +73,10 @@ impl<'a> AssistContext<'a> {
73 self.sema.db 73 self.sema.db
74 } 74 }
75 75
76 pub(crate) fn source_file(&self) -> &SourceFile {
77 &self.source_file
78 }
79
76 // NB, this ignores active selection. 80 // NB, this ignores active selection.
77 pub(crate) fn offset(&self) -> TextSize { 81 pub(crate) fn offset(&self) -> TextSize {
78 self.frange.range.start() 82 self.frange.range.start()
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 01adb834c..15ec75c95 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -32,7 +32,7 @@ impl<'a> AstTransform<'a> for NullTransformer {
32 32
33pub struct SubstituteTypeParams<'a> { 33pub struct SubstituteTypeParams<'a> {
34 source_scope: &'a SemanticsScope<'a>, 34 source_scope: &'a SemanticsScope<'a>,
35 substs: FxHashMap<hir::TypeParam, ast::TypeRef>, 35 substs: FxHashMap<hir::TypeParam, ast::Type>,
36 previous: Box<dyn AstTransform<'a> + 'a>, 36 previous: Box<dyn AstTransform<'a> + 'a>,
37} 37}
38 38
@@ -41,7 +41,7 @@ impl<'a> SubstituteTypeParams<'a> {
41 source_scope: &'a SemanticsScope<'a>, 41 source_scope: &'a SemanticsScope<'a>,
42 // FIXME: there's implicit invariant that `trait_` and `source_scope` match... 42 // FIXME: there's implicit invariant that `trait_` and `source_scope` match...
43 trait_: hir::Trait, 43 trait_: hir::Trait,
44 impl_def: ast::ImplDef, 44 impl_def: ast::Impl,
45 ) -> SubstituteTypeParams<'a> { 45 ) -> SubstituteTypeParams<'a> {
46 let substs = get_syntactic_substs(impl_def).unwrap_or_default(); 46 let substs = get_syntactic_substs(impl_def).unwrap_or_default();
47 let generic_def: hir::GenericDef = trait_.into(); 47 let generic_def: hir::GenericDef = trait_.into();
@@ -63,7 +63,7 @@ impl<'a> SubstituteTypeParams<'a> {
63 let default = k.default(source_scope.db)?; 63 let default = k.default(source_scope.db)?;
64 Some(( 64 Some((
65 k, 65 k,
66 ast::make::type_ref( 66 ast::make::ty(
67 &default 67 &default
68 .display_source_code(source_scope.db, source_scope.module()?.into()) 68 .display_source_code(source_scope.db, source_scope.module()?.into())
69 .ok()?, 69 .ok()?,
@@ -79,19 +79,25 @@ impl<'a> SubstituteTypeParams<'a> {
79 }; 79 };
80 80
81 // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the 81 // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the
82 // trait ref, and then go from the types in the substs back to the syntax) 82 // trait ref, and then go from the types in the substs back to the syntax).
83 fn get_syntactic_substs(impl_def: ast::ImplDef) -> Option<Vec<ast::TypeRef>> { 83 fn get_syntactic_substs(impl_def: ast::Impl) -> Option<Vec<ast::Type>> {
84 let target_trait = impl_def.target_trait()?; 84 let target_trait = impl_def.trait_()?;
85 let path_type = match target_trait { 85 let path_type = match target_trait {
86 ast::TypeRef::PathType(path) => path, 86 ast::Type::PathType(path) => path,
87 _ => return None, 87 _ => return None,
88 }; 88 };
89 let type_arg_list = path_type.path()?.segment()?.type_arg_list()?; 89 let generic_arg_list = path_type.path()?.segment()?.generic_arg_list()?;
90
90 let mut result = Vec::new(); 91 let mut result = Vec::new();
91 for type_arg in type_arg_list.type_args() { 92 for generic_arg in generic_arg_list.generic_args() {
92 let type_arg: ast::TypeArg = type_arg; 93 match generic_arg {
93 result.push(type_arg.type_ref()?); 94 ast::GenericArg::TypeArg(type_arg) => result.push(type_arg.ty()?),
95 ast::GenericArg::AssocTypeArg(_)
96 | ast::GenericArg::LifetimeArg(_)
97 | ast::GenericArg::ConstArg(_) => (),
98 }
94 } 99 }
100
95 Some(result) 101 Some(result)
96 } 102 }
97 } 103 }
@@ -99,9 +105,9 @@ impl<'a> SubstituteTypeParams<'a> {
99 &self, 105 &self,
100 node: &ra_syntax::SyntaxNode, 106 node: &ra_syntax::SyntaxNode,
101 ) -> Option<ra_syntax::SyntaxNode> { 107 ) -> Option<ra_syntax::SyntaxNode> {
102 let type_ref = ast::TypeRef::cast(node.clone())?; 108 let type_ref = ast::Type::cast(node.clone())?;
103 let path = match &type_ref { 109 let path = match &type_ref {
104 ast::TypeRef::PathType(path_type) => path_type.path()?, 110 ast::Type::PathType(path_type) => path_type.path()?,
105 _ => return None, 111 _ => return None,
106 }; 112 };
107 // FIXME: use `hir::Path::from_src` instead. 113 // FIXME: use `hir::Path::from_src` instead.
@@ -157,7 +163,7 @@ impl<'a> QualifyPaths<'a> {
157 163
158 let type_args = p 164 let type_args = p
159 .segment() 165 .segment()
160 .and_then(|s| s.type_arg_list()) 166 .and_then(|s| s.generic_arg_list())
161 .map(|arg_list| apply(self, arg_list)); 167 .map(|arg_list| apply(self, arg_list));
162 if let Some(type_args) = type_args { 168 if let Some(type_args) = type_args {
163 let last_segment = path.segment().unwrap(); 169 let last_segment = path.segment().unwrap();
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index acb07e36a..b67438b6b 100644
--- a/crates/ra_assists/src/handlers/add_custom_impl.rs
+++ b/crates/ra_assists/src/handlers/add_custom_impl.rs
@@ -29,8 +29,8 @@ use crate::{
29// } 29// }
30// ``` 30// ```
31pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 31pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
32 let input = ctx.find_node_at_offset::<ast::AttrInput>()?; 32 let attr = ctx.find_node_at_offset::<ast::Attr>()?;
33 let attr = input.syntax().parent().and_then(ast::Attr::cast)?; 33 let input = attr.token_tree()?;
34 34
35 let attr_name = attr 35 let attr_name = attr
36 .syntax() 36 .syntax()
diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs
index 39a5321d1..135a2ac9c 100644
--- a/crates/ra_assists/src/handlers/add_explicit_type.rs
+++ b/crates/ra_assists/src/handlers/add_explicit_type.rs
@@ -1,6 +1,6 @@
1use hir::HirDisplay; 1use hir::HirDisplay;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner}, 3 ast::{self, AstNode, LetStmt, NameOwner},
4 TextRange, 4 TextRange,
5}; 5};
6 6
@@ -22,20 +22,20 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
22// } 22// }
23// ``` 23// ```
24pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 24pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
25 let stmt = ctx.find_node_at_offset::<LetStmt>()?; 25 let let_stmt = ctx.find_node_at_offset::<LetStmt>()?;
26 let module = ctx.sema.scope(stmt.syntax()).module()?; 26 let module = ctx.sema.scope(let_stmt.syntax()).module()?;
27 let expr = stmt.initializer()?; 27 let expr = let_stmt.initializer()?;
28 // Must be a binding 28 // Must be a binding
29 let pat = match stmt.pat()? { 29 let pat = match let_stmt.pat()? {
30 ast::Pat::BindPat(bind_pat) => bind_pat, 30 ast::Pat::IdentPat(bind_pat) => bind_pat,
31 _ => return None, 31 _ => return None,
32 }; 32 };
33 let pat_range = pat.syntax().text_range(); 33 let pat_range = pat.syntax().text_range();
34 // The binding must have a name 34 // The binding must have a name
35 let name = pat.name()?; 35 let name = pat.name()?;
36 let name_range = name.syntax().text_range(); 36 let name_range = name.syntax().text_range();
37 let stmt_range = stmt.syntax().text_range(); 37 let stmt_range = let_stmt.syntax().text_range();
38 let eq_range = stmt.eq_token()?.text_range(); 38 let eq_range = let_stmt.eq_token()?.text_range();
39 // Assist should only be applicable if cursor is between 'let' and '=' 39 // Assist should only be applicable if cursor is between 'let' and '='
40 let let_range = TextRange::new(stmt_range.start(), eq_range.start()); 40 let let_range = TextRange::new(stmt_range.start(), eq_range.start());
41 let cursor_in_range = let_range.contains_range(ctx.frange.range); 41 let cursor_in_range = let_range.contains_range(ctx.frange.range);
@@ -44,9 +44,9 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
44 } 44 }
45 // Assist not applicable if the type has already been specified 45 // Assist not applicable if the type has already been specified
46 // and it has no placeholders 46 // and it has no placeholders
47 let ascribed_ty = stmt.ascribed_type(); 47 let ascribed_ty = let_stmt.ty();
48 if let Some(ty) = &ascribed_ty { 48 if let Some(ty) = &ascribed_ty {
49 if ty.syntax().descendants().find_map(ast::PlaceholderType::cast).is_none() { 49 if ty.syntax().descendants().find_map(ast::InferType::cast).is_none() {
50 return None; 50 return None;
51 } 51 }
52 } 52 }
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 f185e61e5..95a750aee 100644
--- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
@@ -111,16 +111,17 @@ fn add_missing_impl_members_inner(
111 label: &'static str, 111 label: &'static str,
112) -> Option<()> { 112) -> Option<()> {
113 let _p = ra_prof::profile("add_missing_impl_members_inner"); 113 let _p = ra_prof::profile("add_missing_impl_members_inner");
114 let impl_def = ctx.find_node_at_offset::<ast::ImplDef>()?; 114 let impl_def = ctx.find_node_at_offset::<ast::Impl>()?;
115 let impl_item_list = impl_def.item_list()?; 115 let impl_item_list = impl_def.assoc_item_list()?;
116 116
117 let trait_ = resolve_target_trait(&ctx.sema, &impl_def)?; 117 let trait_ = resolve_target_trait(&ctx.sema, &impl_def)?;
118 118
119 let def_name = |item: &ast::AssocItem| -> Option<SmolStr> { 119 let def_name = |item: &ast::AssocItem| -> Option<SmolStr> {
120 match item { 120 match item {
121 ast::AssocItem::FnDef(def) => def.name(), 121 ast::AssocItem::Fn(def) => def.name(),
122 ast::AssocItem::TypeAliasDef(def) => def.name(), 122 ast::AssocItem::TypeAlias(def) => def.name(),
123 ast::AssocItem::ConstDef(def) => def.name(), 123 ast::AssocItem::Const(def) => def.name(),
124 ast::AssocItem::MacroCall(_) => None,
124 } 125 }
125 .map(|it| it.text().clone()) 126 .map(|it| it.text().clone())
126 }; 127 };
@@ -128,13 +129,13 @@ fn add_missing_impl_members_inner(
128 let missing_items = get_missing_assoc_items(&ctx.sema, &impl_def) 129 let missing_items = get_missing_assoc_items(&ctx.sema, &impl_def)
129 .iter() 130 .iter()
130 .map(|i| match i { 131 .map(|i| match i {
131 hir::AssocItem::Function(i) => ast::AssocItem::FnDef(i.source(ctx.db()).value), 132 hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(ctx.db()).value),
132 hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAliasDef(i.source(ctx.db()).value), 133 hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(ctx.db()).value),
133 hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db()).value), 134 hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(ctx.db()).value),
134 }) 135 })
135 .filter(|t| def_name(&t).is_some()) 136 .filter(|t| def_name(&t).is_some())
136 .filter(|t| match t { 137 .filter(|t| match t {
137 ast::AssocItem::FnDef(def) => match mode { 138 ast::AssocItem::Fn(def) => match mode {
138 AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), 139 AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(),
139 AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), 140 AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(),
140 }, 141 },
@@ -157,10 +158,8 @@ fn add_missing_impl_members_inner(
157 .into_iter() 158 .into_iter()
158 .map(|it| ast_transform::apply(&*ast_transform, it)) 159 .map(|it| ast_transform::apply(&*ast_transform, it))
159 .map(|it| match it { 160 .map(|it| match it {
160 ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), 161 ast::AssocItem::Fn(def) => ast::AssocItem::Fn(add_body(def)),
161 ast::AssocItem::TypeAliasDef(def) => { 162 ast::AssocItem::TypeAlias(def) => ast::AssocItem::TypeAlias(def.remove_bounds()),
162 ast::AssocItem::TypeAliasDef(def.remove_bounds())
163 }
164 _ => it, 163 _ => it,
165 }) 164 })
166 .map(|it| edit::remove_attrs_and_docs(&it)); 165 .map(|it| edit::remove_attrs_and_docs(&it));
@@ -173,7 +172,7 @@ fn add_missing_impl_members_inner(
173 Some(cap) => { 172 Some(cap) => {
174 let mut cursor = Cursor::Before(first_new_item.syntax()); 173 let mut cursor = Cursor::Before(first_new_item.syntax());
175 let placeholder; 174 let placeholder;
176 if let ast::AssocItem::FnDef(func) = &first_new_item { 175 if let ast::AssocItem::Fn(func) = &first_new_item {
177 if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) { 176 if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) {
178 if m.syntax().text() == "todo!()" { 177 if m.syntax().text() == "todo!()" {
179 placeholder = m; 178 placeholder = m;
@@ -191,7 +190,7 @@ fn add_missing_impl_members_inner(
191 }) 190 })
192} 191}
193 192
194fn add_body(fn_def: ast::FnDef) -> ast::FnDef { 193fn add_body(fn_def: ast::Fn) -> ast::Fn {
195 if fn_def.body().is_some() { 194 if fn_def.body().is_some() {
196 return fn_def; 195 return fn_def;
197 } 196 }
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs
index 947be3b9b..01e7b7a44 100644
--- a/crates/ra_assists/src/handlers/auto_import.rs
+++ b/crates/ra_assists/src/handlers/auto_import.rs
@@ -92,7 +92,7 @@ impl AutoImportAssets {
92 92
93 fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option<Self> { 93 fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option<Self> {
94 let syntax_under_caret = path_under_caret.syntax().to_owned(); 94 let syntax_under_caret = path_under_caret.syntax().to_owned();
95 if syntax_under_caret.ancestors().find_map(ast::UseItem::cast).is_some() { 95 if syntax_under_caret.ancestors().find_map(ast::Use::cast).is_some() {
96 return None; 96 return None;
97 } 97 }
98 98
diff --git a/crates/ra_assists/src/handlers/change_return_type_to_result.rs b/crates/ra_assists/src/handlers/change_return_type_to_result.rs
index def00f7d8..b83c94404 100644
--- a/crates/ra_assists/src/handlers/change_return_type_to_result.rs
+++ b/crates/ra_assists/src/handlers/change_return_type_to_result.rs
@@ -20,9 +20,9 @@ use test_utils::mark;
20pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 20pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
21 let ret_type = ctx.find_node_at_offset::<ast::RetType>()?; 21 let ret_type = ctx.find_node_at_offset::<ast::RetType>()?;
22 // FIXME: extend to lambdas as well 22 // FIXME: extend to lambdas as well
23 let fn_def = ret_type.syntax().parent().and_then(ast::FnDef::cast)?; 23 let fn_def = ret_type.syntax().parent().and_then(ast::Fn::cast)?;
24 24
25 let type_ref = &ret_type.type_ref()?; 25 let type_ref = &ret_type.ty()?;
26 let ret_type_str = type_ref.syntax().text().to_string(); 26 let ret_type_str = type_ref.syntax().text().to_string();
27 let first_part_ret_type = ret_type_str.splitn(2, '<').next(); 27 let first_part_ret_type = ret_type_str.splitn(2, '<').next();
28 if let Some(ret_type_first_part) = first_part_ret_type { 28 if let Some(ret_type_first_part) = first_part_ret_type {
@@ -74,6 +74,7 @@ impl TailReturnCollector {
74 let expr = match &stmt { 74 let expr = match &stmt {
75 ast::Stmt::ExprStmt(stmt) => stmt.expr(), 75 ast::Stmt::ExprStmt(stmt) => stmt.expr(),
76 ast::Stmt::LetStmt(stmt) => stmt.initializer(), 76 ast::Stmt::LetStmt(stmt) => stmt.initializer(),
77 ast::Stmt::Item(_) => continue,
77 }; 78 };
78 if let Some(expr) = &expr { 79 if let Some(expr) = &expr {
79 self.handle_exprs(expr, collect_break); 80 self.handle_exprs(expr, collect_break);
@@ -94,6 +95,7 @@ impl TailReturnCollector {
94 let expr_stmt = match &expr_stmt { 95 let expr_stmt = match &expr_stmt {
95 ast::Stmt::ExprStmt(stmt) => stmt.expr(), 96 ast::Stmt::ExprStmt(stmt) => stmt.expr(),
96 ast::Stmt::LetStmt(stmt) => stmt.initializer(), 97 ast::Stmt::LetStmt(stmt) => stmt.initializer(),
98 ast::Stmt::Item(_) => None,
97 }; 99 };
98 if let Some(expr) = &expr_stmt { 100 if let Some(expr) = &expr_stmt {
99 self.handle_exprs(expr, collect_break); 101 self.handle_exprs(expr, collect_break);
@@ -239,8 +241,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
239 Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 241 Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
240 Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 242 Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
241 Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 243 Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
242 Expr::Label(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 244 Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
243 Expr::RecordLit(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
244 Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 245 Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
245 Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 246 Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
246 Expr::AwaitExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 247 Expr::AwaitExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index 4343b423c..724daa93f 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -1,9 +1,7 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, NameOwner, VisibilityOwner}, 2 ast::{self, NameOwner, VisibilityOwner},
3 AstNode, 3 AstNode,
4 SyntaxKind::{ 4 SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},
5 CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STATIC_DEF, STRUCT_DEF, TRAIT_DEF, VISIBILITY,
6 },
7 T, 5 T,
8}; 6};
9use test_utils::mark; 7use test_utils::mark;
@@ -38,7 +36,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
38 36
39 let (offset, target) = if let Some(keyword) = item_keyword { 37 let (offset, target) = if let Some(keyword) = item_keyword {
40 let parent = keyword.parent(); 38 let parent = keyword.parent();
41 let def_kws = vec![CONST_DEF, STATIC_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; 39 let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT];
42 // Parent is not a definition, can't add visibility 40 // Parent is not a definition, can't add visibility
43 if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { 41 if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
44 return None; 42 return None;
@@ -49,7 +47,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
49 } 47 }
50 (vis_offset(&parent), keyword.text_range()) 48 (vis_offset(&parent), keyword.text_range())
51 } else if let Some(field_name) = ctx.find_node_at_offset::<ast::Name>() { 49 } else if let Some(field_name) = ctx.find_node_at_offset::<ast::Name>() {
52 let field = field_name.syntax().ancestors().find_map(ast::RecordFieldDef::cast)?; 50 let field = field_name.syntax().ancestors().find_map(ast::RecordField::cast)?;
53 if field.name()? != field_name { 51 if field.name()? != field_name {
54 mark::hit!(change_visibility_field_false_positive); 52 mark::hit!(change_visibility_field_false_positive);
55 return None; 53 return None;
@@ -58,7 +56,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
58 return None; 56 return None;
59 } 57 }
60 (vis_offset(field.syntax()), field_name.syntax().text_range()) 58 (vis_offset(field.syntax()), field_name.syntax().text_range())
61 } else if let Some(field) = ctx.find_node_at_offset::<ast::TupleFieldDef>() { 59 } else if let Some(field) = ctx.find_node_at_offset::<ast::TupleField>() {
62 if field.visibility().is_some() { 60 if field.visibility().is_some() {
63 return None; 61 return None;
64 } 62 }
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs
index 330459f3c..6816a2709 100644
--- a/crates/ra_assists/src/handlers/early_return.rs
+++ b/crates/ra_assists/src/handlers/early_return.rs
@@ -8,7 +8,7 @@ use ra_syntax::{
8 make, 8 make,
9 }, 9 },
10 AstNode, 10 AstNode,
11 SyntaxKind::{FN_DEF, LOOP_EXPR, L_CURLY, R_CURLY, WHILE_EXPR, WHITESPACE}, 11 SyntaxKind::{FN, LOOP_EXPR, L_CURLY, R_CURLY, WHILE_EXPR, WHITESPACE},
12 SyntaxNode, 12 SyntaxNode,
13}; 13};
14 14
@@ -51,11 +51,11 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
51 // Check if there is an IfLet that we can handle. 51 // Check if there is an IfLet that we can handle.
52 let if_let_pat = match cond.pat() { 52 let if_let_pat = match cond.pat() {
53 None => None, // No IfLet, supported. 53 None => None, // No IfLet, supported.
54 Some(ast::Pat::TupleStructPat(pat)) if pat.args().count() == 1 => { 54 Some(ast::Pat::TupleStructPat(pat)) if pat.fields().count() == 1 => {
55 let path = pat.path()?; 55 let path = pat.path()?;
56 match path.qualifier() { 56 match path.qualifier() {
57 None => { 57 None => {
58 let bound_ident = pat.args().next().unwrap(); 58 let bound_ident = pat.fields().next().unwrap();
59 Some((path, bound_ident)) 59 Some((path, bound_ident))
60 } 60 }
61 Some(_) => return None, 61 Some(_) => return None,
@@ -88,7 +88,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
88 88
89 let early_expression: ast::Expr = match parent_container.kind() { 89 let early_expression: ast::Expr = match parent_container.kind() {
90 WHILE_EXPR | LOOP_EXPR => make::expr_continue(), 90 WHILE_EXPR | LOOP_EXPR => make::expr_continue(),
91 FN_DEF => make::expr_return(), 91 FN => make::expr_return(),
92 _ => return None, 92 _ => return None,
93 }; 93 };
94 94
@@ -123,7 +123,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
123 let happy_arm = { 123 let happy_arm = {
124 let pat = make::tuple_struct_pat( 124 let pat = make::tuple_struct_pat(
125 path, 125 path,
126 once(make::bind_pat(make::name("it")).into()), 126 once(make::ident_pat(make::name("it")).into()),
127 ); 127 );
128 let expr = { 128 let expr = {
129 let name_ref = make::name_ref("it"); 129 let name_ref = make::name_ref("it");
@@ -136,7 +136,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
136 136
137 let sad_arm = make::match_arm( 137 let sad_arm = make::match_arm(
138 // FIXME: would be cool to use `None` or `Err(_)` if appropriate 138 // FIXME: would be cool to use `None` or `Err(_)` if appropriate
139 once(make::placeholder_pat().into()), 139 once(make::wildcard_pat().into()),
140 early_expression, 140 early_expression,
141 ); 141 );
142 142
@@ -144,7 +144,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
144 }; 144 };
145 145
146 let let_stmt = make::let_stmt( 146 let let_stmt = make::let_stmt(
147 make::bind_pat(make::name(&bound_ident.syntax().to_string())).into(), 147 make::ident_pat(make::name(&bound_ident.syntax().to_string())).into(),
148 Some(match_expr), 148 Some(match_expr),
149 ); 149 );
150 let let_stmt = let_stmt.indent(if_indent_level); 150 let let_stmt = let_stmt.indent(if_indent_level);
diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs
new file mode 100644
index 000000000..eb216a81a
--- /dev/null
+++ b/crates/ra_assists/src/handlers/expand_glob_import.rs
@@ -0,0 +1,391 @@
1use hir::{AssocItem, MacroDef, ModuleDef, Name, PathResolution, ScopeDef, SemanticsScope};
2use ra_ide_db::{
3 defs::{classify_name_ref, Definition, NameRefClass},
4 RootDatabase,
5};
6use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxNode, SyntaxToken, T};
7
8use crate::{
9 assist_context::{AssistBuilder, AssistContext, Assists},
10 AssistId, AssistKind,
11};
12
13use either::Either;
14
15// Assist: expand_glob_import
16//
17// Expands glob imports.
18//
19// ```
20// mod foo {
21// pub struct Bar;
22// pub struct Baz;
23// }
24//
25// use foo::*<|>;
26//
27// fn qux(bar: Bar, baz: Baz) {}
28// ```
29// ->
30// ```
31// mod foo {
32// pub struct Bar;
33// pub struct Baz;
34// }
35//
36// use foo::{Baz, Bar};
37//
38// fn qux(bar: Bar, baz: Baz) {}
39// ```
40pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
41 let star = ctx.find_token_at_offset(T![*])?;
42 let mod_path = find_mod_path(&star)?;
43
44 let source_file = ctx.source_file();
45 let scope = ctx.sema.scope_at_offset(source_file.syntax(), ctx.offset());
46
47 let defs_in_mod = find_defs_in_mod(ctx, scope, &mod_path)?;
48 let name_refs_in_source_file =
49 source_file.syntax().descendants().filter_map(ast::NameRef::cast).collect();
50 let used_names = find_used_names(ctx, defs_in_mod, name_refs_in_source_file);
51
52 let parent = star.parent().parent()?;
53 acc.add(
54 AssistId("expand_glob_import", AssistKind::RefactorRewrite),
55 "Expand glob import",
56 parent.text_range(),
57 |builder| {
58 replace_ast(builder, &parent, mod_path, used_names);
59 },
60 )
61}
62
63fn find_mod_path(star: &SyntaxToken) -> Option<ast::Path> {
64 star.ancestors().find_map(|n| ast::UseTree::cast(n).and_then(|u| u.path()))
65}
66
67#[derive(PartialEq)]
68enum Def {
69 ModuleDef(ModuleDef),
70 MacroDef(MacroDef),
71}
72
73impl Def {
74 fn name(&self, db: &RootDatabase) -> Option<Name> {
75 match self {
76 Def::ModuleDef(def) => def.name(db),
77 Def::MacroDef(def) => def.name(db),
78 }
79 }
80}
81
82fn find_defs_in_mod(
83 ctx: &AssistContext,
84 from: SemanticsScope<'_>,
85 path: &ast::Path,
86) -> Option<Vec<Def>> {
87 let hir_path = ctx.sema.lower_path(&path)?;
88 let module = if let Some(PathResolution::Def(ModuleDef::Module(module))) =
89 from.resolve_hir_path_qualifier(&hir_path)
90 {
91 module
92 } else {
93 return None;
94 };
95
96 let module_scope = module.scope(ctx.db(), from.module());
97
98 let mut defs = vec![];
99 for (_, def) in module_scope {
100 match def {
101 ScopeDef::ModuleDef(def) => defs.push(Def::ModuleDef(def)),
102 ScopeDef::MacroDef(def) => defs.push(Def::MacroDef(def)),
103 _ => continue,
104 }
105 }
106
107 Some(defs)
108}
109
110fn find_used_names(
111 ctx: &AssistContext,
112 defs_in_mod: Vec<Def>,
113 name_refs_in_source_file: Vec<ast::NameRef>,
114) -> Vec<Name> {
115 let defs_in_source_file = name_refs_in_source_file
116 .iter()
117 .filter_map(|r| classify_name_ref(&ctx.sema, r))
118 .filter_map(|rc| match rc {
119 NameRefClass::Definition(Definition::ModuleDef(def)) => Some(Def::ModuleDef(def)),
120 NameRefClass::Definition(Definition::Macro(def)) => Some(Def::MacroDef(def)),
121 _ => None,
122 })
123 .collect::<Vec<Def>>();
124
125 defs_in_mod
126 .iter()
127 .filter(|def| {
128 if let Def::ModuleDef(ModuleDef::Trait(tr)) = def {
129 for item in tr.items(ctx.db()) {
130 if let AssocItem::Function(f) = item {
131 if defs_in_source_file.contains(&Def::ModuleDef(ModuleDef::Function(f))) {
132 return true;
133 }
134 }
135 }
136 }
137
138 defs_in_source_file.contains(def)
139 })
140 .filter_map(|d| d.name(ctx.db()))
141 .collect()
142}
143
144fn replace_ast(
145 builder: &mut AssistBuilder,
146 node: &SyntaxNode,
147 path: ast::Path,
148 used_names: Vec<Name>,
149) {
150 let replacement: Either<ast::UseTree, ast::UseTreeList> = match used_names.as_slice() {
151 [name] => Either::Left(ast::make::use_tree(
152 ast::make::path_from_text(&format!("{}::{}", path, name)),
153 None,
154 None,
155 false,
156 )),
157 names => Either::Right(ast::make::use_tree_list(names.iter().map(|n| {
158 ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false)
159 }))),
160 };
161
162 let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| {
163 algo::diff(node, &replacement.either(|u| u.syntax().clone(), |ut| ut.syntax().clone()))
164 .into_text_edit(builder.text_edit_builder());
165 };
166
167 match_ast! {
168 match node {
169 ast::UseTree(use_tree) => {
170 replace_node(replacement);
171 },
172 ast::UseTreeList(use_tree_list) => {
173 replace_node(replacement);
174 },
175 ast::Use(use_item) => {
176 builder.replace_ast(use_item, ast::make::use_(replacement.left_or_else(|ut| ast::make::use_tree(path, Some(ut), None, false))));
177 },
178 _ => {},
179 }
180 }
181}
182
183#[cfg(test)]
184mod tests {
185 use crate::tests::{check_assist, check_assist_not_applicable};
186
187 use super::*;
188
189 #[test]
190 fn expanding_glob_import() {
191 check_assist(
192 expand_glob_import,
193 r"
194mod foo {
195 pub struct Bar;
196 pub struct Baz;
197 pub struct Qux;
198
199 pub fn f() {}
200}
201
202use foo::*<|>;
203
204fn qux(bar: Bar, baz: Baz) {
205 f();
206}
207",
208 r"
209mod foo {
210 pub struct Bar;
211 pub struct Baz;
212 pub struct Qux;
213
214 pub fn f() {}
215}
216
217use foo::{Baz, Bar, f};
218
219fn qux(bar: Bar, baz: Baz) {
220 f();
221}
222",
223 )
224 }
225
226 #[test]
227 fn expanding_glob_import_with_existing_explicit_names() {
228 check_assist(
229 expand_glob_import,
230 r"
231mod foo {
232 pub struct Bar;
233 pub struct Baz;
234 pub struct Qux;
235
236 pub fn f() {}
237}
238
239use foo::{*<|>, f};
240
241fn qux(bar: Bar, baz: Baz) {
242 f();
243}
244",
245 r"
246mod foo {
247 pub struct Bar;
248 pub struct Baz;
249 pub struct Qux;
250
251 pub fn f() {}
252}
253
254use foo::{Baz, Bar, f};
255
256fn qux(bar: Bar, baz: Baz) {
257 f();
258}
259",
260 )
261 }
262
263 #[test]
264 fn expanding_nested_glob_import() {
265 check_assist(
266 expand_glob_import,
267 r"
268mod foo {
269 mod bar {
270 pub struct Bar;
271 pub struct Baz;
272 pub struct Qux;
273
274 pub fn f() {}
275 }
276
277 mod baz {
278 pub fn g() {}
279 }
280}
281
282use foo::{bar::{*<|>, f}, baz::*};
283
284fn qux(bar: Bar, baz: Baz) {
285 f();
286 g();
287}
288",
289 r"
290mod foo {
291 mod bar {
292 pub struct Bar;
293 pub struct Baz;
294 pub struct Qux;
295
296 pub fn f() {}
297 }
298
299 mod baz {
300 pub fn g() {}
301 }
302}
303
304use foo::{bar::{Baz, Bar, f}, baz::*};
305
306fn qux(bar: Bar, baz: Baz) {
307 f();
308 g();
309}
310",
311 )
312 }
313
314 #[test]
315 fn expanding_glob_import_with_macro_defs() {
316 check_assist(
317 expand_glob_import,
318 r"
319//- /lib.rs crate:foo
320#[macro_export]
321macro_rules! bar {
322 () => ()
323}
324
325pub fn baz() {}
326
327//- /main.rs crate:main deps:foo
328use foo::*<|>;
329
330fn main() {
331 bar!();
332 baz();
333}
334",
335 r"
336use foo::{bar, baz};
337
338fn main() {
339 bar!();
340 baz();
341}
342",
343 )
344 }
345
346 #[test]
347 fn expanding_glob_import_with_trait_method_uses() {
348 check_assist(
349 expand_glob_import,
350 r"
351//- /lib.rs crate:foo
352pub trait Tr {
353 fn method(&self) {}
354}
355impl Tr for () {}
356
357//- /main.rs crate:main deps:foo
358use foo::*<|>;
359
360fn main() {
361 ().method();
362}
363",
364 r"
365use foo::Tr;
366
367fn main() {
368 ().method();
369}
370",
371 )
372 }
373
374 #[test]
375 fn expanding_is_not_applicable_if_cursor_is_not_in_star_token() {
376 check_assist_not_applicable(
377 expand_glob_import,
378 r"
379 mod foo {
380 pub struct Bar;
381 pub struct Baz;
382 pub struct Qux;
383 }
384
385 use foo::Bar<|>;
386
387 fn qux(bar: Bar, baz: Baz) {}
388 ",
389 )
390 }
391}
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
index 2b8e273b3..ccec688ca 100644
--- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -31,7 +31,7 @@ pub(crate) fn extract_struct_from_enum_variant(
31 acc: &mut Assists, 31 acc: &mut Assists,
32 ctx: &AssistContext, 32 ctx: &AssistContext,
33) -> Option<()> { 33) -> Option<()> {
34 let variant = ctx.find_node_at_offset::<ast::EnumVariant>()?; 34 let variant = ctx.find_node_at_offset::<ast::Variant>()?;
35 let field_list = match variant.kind() { 35 let field_list = match variant.kind() {
36 ast::StructKind::Tuple(field_list) => field_list, 36 ast::StructKind::Tuple(field_list) => field_list,
37 _ => return None, 37 _ => return None,
diff --git a/crates/ra_assists/src/handlers/extract_variable.rs b/crates/ra_assists/src/handlers/extract_variable.rs
index 098adf078..cc62db0c4 100644
--- a/crates/ra_assists/src/handlers/extract_variable.rs
+++ b/crates/ra_assists/src/handlers/extract_variable.rs
@@ -1,7 +1,7 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 SyntaxKind::{ 3 SyntaxKind::{
4 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, 4 BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
5 }, 5 },
6 SyntaxNode, 6 SyntaxNode,
7}; 7};
@@ -45,7 +45,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
45 target, 45 target,
46 move |edit| { 46 move |edit| {
47 let field_shorthand = 47 let field_shorthand =
48 match to_extract.syntax().parent().and_then(ast::RecordField::cast) { 48 match to_extract.syntax().parent().and_then(ast::RecordExprField::cast) {
49 Some(field) => field.name_ref(), 49 Some(field) => field.name_ref(),
50 None => None, 50 None => None,
51 }; 51 };
@@ -148,7 +148,7 @@ impl Anchor {
148 } 148 }
149 149
150 if let Some(parent) = node.parent() { 150 if let Some(parent) = node.parent() {
151 if parent.kind() == MATCH_ARM || parent.kind() == LAMBDA_EXPR { 151 if parent.kind() == MATCH_ARM || parent.kind() == CLOSURE_EXPR {
152 return Some(Anchor::WrapInBlock(node)); 152 return Some(Anchor::WrapInBlock(node));
153 } 153 }
154 } 154 }
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 708e1bc6c..6698d1a27 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -43,7 +43,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
43 43
44 let mut arms: Vec<MatchArm> = match_arm_list.arms().collect(); 44 let mut arms: Vec<MatchArm> = match_arm_list.arms().collect();
45 if arms.len() == 1 { 45 if arms.len() == 1 {
46 if let Some(Pat::PlaceholderPat(..)) = arms[0].pat() { 46 if let Some(Pat::WildcardPat(..)) = arms[0].pat() {
47 arms.clear(); 47 arms.clear();
48 } 48 }
49 } 49 }
@@ -116,17 +116,15 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
116 match (first_new_arm, ctx.config.snippet_cap) { 116 match (first_new_arm, ctx.config.snippet_cap) {
117 (Some(first_new_arm), Some(cap)) => { 117 (Some(first_new_arm), Some(cap)) => {
118 let extend_lifetime; 118 let extend_lifetime;
119 let cursor = match first_new_arm 119 let cursor =
120 .syntax() 120 match first_new_arm.syntax().descendants().find_map(ast::WildcardPat::cast)
121 .descendants() 121 {
122 .find_map(ast::PlaceholderPat::cast) 122 Some(it) => {
123 { 123 extend_lifetime = it.syntax().clone();
124 Some(it) => { 124 Cursor::Replace(&extend_lifetime)
125 extend_lifetime = it.syntax().clone(); 125 }
126 Cursor::Replace(&extend_lifetime) 126 None => Cursor::Before(first_new_arm.syntax()),
127 } 127 };
128 None => Cursor::Before(first_new_arm.syntax()),
129 };
130 let snippet = render_snippet(cap, new_arm_list.syntax(), cursor); 128 let snippet = render_snippet(cap, new_arm_list.syntax(), cursor);
131 builder.replace_snippet(cap, old_range, snippet); 129 builder.replace_snippet(cap, old_range, snippet);
132 } 130 }
@@ -152,7 +150,7 @@ fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool {
152 let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text()); 150 let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text());
153 151
154 let pat_head = match pat { 152 let pat_head = match pat {
155 Pat::BindPat(bind_pat) => { 153 Pat::IdentPat(bind_pat) => {
156 if let Some(p) = bind_pat.pat() { 154 if let Some(p) = bind_pat.pat() {
157 first_node_text(&p) 155 first_node_text(&p)
158 } else { 156 } else {
@@ -199,12 +197,11 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O
199 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though 197 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
200 let pat: ast::Pat = match var.source(db).value.kind() { 198 let pat: ast::Pat = match var.source(db).value.kind() {
201 ast::StructKind::Tuple(field_list) => { 199 ast::StructKind::Tuple(field_list) => {
202 let pats = 200 let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count());
203 iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count());
204 make::tuple_struct_pat(path, pats).into() 201 make::tuple_struct_pat(path, pats).into()
205 } 202 }
206 ast::StructKind::Record(field_list) => { 203 ast::StructKind::Record(field_list) => {
207 let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); 204 let pats = field_list.fields().map(|f| make::ident_pat(f.name().unwrap()).into());
208 make::record_pat(path, pats).into() 205 make::record_pat(path, pats).into()
209 } 206 }
210 ast::StructKind::Unit => make::path_pat(path), 207 ast::StructKind::Unit => make::path_pat(path),
diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs
index 1d3ed3c6a..1aefa79cc 100644
--- a/crates/ra_assists/src/handlers/fix_visibility.rs
+++ b/crates/ra_assists/src/handlers/fix_visibility.rs
@@ -82,7 +82,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O
82} 82}
83 83
84fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 84fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
85 let record_field: ast::RecordField = ctx.find_node_at_offset()?; 85 let record_field: ast::RecordExprField = ctx.find_node_at_offset()?;
86 let (record_field_def, _) = ctx.sema.resolve_record_field(&record_field)?; 86 let (record_field_def, _) = ctx.sema.resolve_record_field(&record_field)?;
87 87
88 let current_module = ctx.sema.scope(record_field.syntax()).module()?; 88 let current_module = ctx.sema.scope(record_field.syntax()).module()?;
diff --git a/crates/ra_assists/src/handlers/generate_derive.rs b/crates/ra_assists/src/handlers/generate_derive.rs
index 6ccf39900..90ece9fab 100644
--- a/crates/ra_assists/src/handlers/generate_derive.rs
+++ b/crates/ra_assists/src/handlers/generate_derive.rs
@@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
26// ``` 26// ```
27pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 27pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
28 let cap = ctx.config.snippet_cap?; 28 let cap = ctx.config.snippet_cap?;
29 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 29 let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
30 let node_start = derive_insertion_offset(&nominal)?; 30 let node_start = derive_insertion_offset(&nominal)?;
31 let target = nominal.syntax().text_range(); 31 let target = nominal.syntax().text_range();
32 acc.add( 32 acc.add(
@@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<
58} 58}
59 59
60// Insert `derive` after doc comments. 60// Insert `derive` after doc comments.
61fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> { 61fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> {
62 let non_ws_child = nominal 62 let non_ws_child = nominal
63 .syntax() 63 .syntax()
64 .children_with_tokens() 64 .children_with_tokens()
diff --git a/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs
index a347e3c2e..4c1aef8a2 100644
--- a/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs
+++ b/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs
@@ -22,7 +22,7 @@ use crate::{utils::FamousDefs, AssistContext, AssistId, AssistKind, Assists};
22// } 22// }
23// ``` 23// ```
24pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 24pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
25 let variant = ctx.find_node_at_offset::<ast::EnumVariant>()?; 25 let variant = ctx.find_node_at_offset::<ast::Variant>()?;
26 let variant_name = variant.name()?; 26 let variant_name = variant.name()?;
27 let enum_name = variant.parent_enum().name()?; 27 let enum_name = variant.parent_enum().name()?;
28 let field_list = match variant.kind() { 28 let field_list = match variant.kind() {
@@ -32,9 +32,9 @@ pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext
32 if field_list.fields().count() != 1 { 32 if field_list.fields().count() != 1 {
33 return None; 33 return None;
34 } 34 }
35 let field_type = field_list.fields().next()?.type_ref()?; 35 let field_type = field_list.fields().next()?.ty()?;
36 let path = match field_type { 36 let path = match field_type {
37 ast::TypeRef::PathType(it) => it, 37 ast::Type::PathType(it) => it,
38 _ => return None, 38 _ => return None,
39 }; 39 };
40 40
@@ -69,7 +69,7 @@ impl From<{0}> for {1} {{
69 69
70fn existing_from_impl( 70fn existing_from_impl(
71 sema: &'_ hir::Semantics<'_, RootDatabase>, 71 sema: &'_ hir::Semantics<'_, RootDatabase>,
72 variant: &ast::EnumVariant, 72 variant: &ast::Variant,
73) -> Option<()> { 73) -> Option<()> {
74 let variant = sema.to_def(variant)?; 74 let variant = sema.to_def(variant)?;
75 let enum_ = variant.parent_enum(sema.db); 75 let enum_ = variant.parent_enum(sema.db);
diff --git a/crates/ra_assists/src/handlers/generate_function.rs b/crates/ra_assists/src/handlers/generate_function.rs
index b721b96bb..acc97e648 100644
--- a/crates/ra_assists/src/handlers/generate_function.rs
+++ b/crates/ra_assists/src/handlers/generate_function.rs
@@ -82,7 +82,7 @@ struct FunctionTemplate {
82 insert_offset: TextSize, 82 insert_offset: TextSize,
83 placeholder_expr: ast::MacroCall, 83 placeholder_expr: ast::MacroCall,
84 leading_ws: String, 84 leading_ws: String,
85 fn_def: ast::FnDef, 85 fn_def: ast::Fn,
86 trailing_ws: String, 86 trailing_ws: String,
87 file: FileId, 87 file: FileId,
88} 88}
@@ -104,7 +104,7 @@ impl FunctionTemplate {
104struct FunctionBuilder { 104struct FunctionBuilder {
105 target: GeneratedFunctionTarget, 105 target: GeneratedFunctionTarget,
106 fn_name: ast::Name, 106 fn_name: ast::Name,
107 type_params: Option<ast::TypeParamList>, 107 type_params: Option<ast::GenericParamList>,
108 params: ast::ParamList, 108 params: ast::ParamList,
109 file: FileId, 109 file: FileId,
110 needs_pub: bool, 110 needs_pub: bool,
@@ -142,7 +142,7 @@ impl FunctionBuilder {
142 let fn_body = make::block_expr(vec![], Some(placeholder_expr)); 142 let fn_body = make::block_expr(vec![], Some(placeholder_expr));
143 let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None }; 143 let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None };
144 let mut fn_def = 144 let mut fn_def =
145 make::fn_def(visibility, self.fn_name, self.type_params, self.params, fn_body); 145 make::fn_(visibility, self.fn_name, self.type_params, self.params, fn_body);
146 let leading_ws; 146 let leading_ws;
147 let trailing_ws; 147 let trailing_ws;
148 148
@@ -200,7 +200,7 @@ fn fn_args(
200 ctx: &AssistContext, 200 ctx: &AssistContext,
201 target_module: hir::Module, 201 target_module: hir::Module,
202 call: &ast::CallExpr, 202 call: &ast::CallExpr,
203) -> Option<(Option<ast::TypeParamList>, ast::ParamList)> { 203) -> Option<(Option<ast::GenericParamList>, ast::ParamList)> {
204 let mut arg_names = Vec::new(); 204 let mut arg_names = Vec::new();
205 let mut arg_types = Vec::new(); 205 let mut arg_types = Vec::new();
206 for arg in call.arg_list()?.args() { 206 for arg in call.arg_list()?.args() {
diff --git a/crates/ra_assists/src/handlers/generate_impl.rs b/crates/ra_assists/src/handlers/generate_impl.rs
index cbbac1d7f..d9b87c9c0 100644
--- a/crates/ra_assists/src/handlers/generate_impl.rs
+++ b/crates/ra_assists/src/handlers/generate_impl.rs
@@ -1,4 +1,4 @@
1use ra_syntax::ast::{self, AstNode, NameOwner, TypeParamsOwner}; 1use ra_syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
2use stdx::{format_to, SepBy}; 2use stdx::{format_to, SepBy};
3 3
4use crate::{AssistContext, AssistId, AssistKind, Assists}; 4use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
23// } 23// }
24// ``` 24// ```
25pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 25pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
26 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 26 let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
27 let name = nominal.name()?; 27 let name = nominal.name()?;
28 let target = nominal.syntax().text_range(); 28 let target = nominal.syntax().text_range();
29 acc.add( 29 acc.add(
@@ -31,7 +31,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()
31 format!("Generate impl for `{}`", name), 31 format!("Generate impl for `{}`", name),
32 target, 32 target,
33 |edit| { 33 |edit| {
34 let type_params = nominal.type_param_list(); 34 let type_params = nominal.generic_param_list();
35 let start_offset = nominal.syntax().text_range().end(); 35 let start_offset = nominal.syntax().text_range().end();
36 let mut buf = String::new(); 36 let mut buf = String::new();
37 buf.push_str("\n\nimpl"); 37 buf.push_str("\n\nimpl");
diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs
index e27def1d8..b84aa24b6 100644
--- a/crates/ra_assists/src/handlers/generate_new.rs
+++ b/crates/ra_assists/src/handlers/generate_new.rs
@@ -1,8 +1,6 @@
1use hir::Adt; 1use hir::Adt;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{ 3 ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
4 self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner,
5 },
6 T, 4 T,
7}; 5};
8use stdx::{format_to, SepBy}; 6use stdx::{format_to, SepBy};
@@ -30,7 +28,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
30// 28//
31// ``` 29// ```
32pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 30pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
33 let strukt = ctx.find_node_at_offset::<ast::StructDef>()?; 31 let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
34 32
35 // We want to only apply this to non-union structs with named fields 33 // We want to only apply this to non-union structs with named fields
36 let field_list = match strukt.kind() { 34 let field_list = match strukt.kind() {
@@ -53,9 +51,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
53 51
54 let params = field_list 52 let params = field_list
55 .fields() 53 .fields()
56 .filter_map(|f| { 54 .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax())))
57 Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax()))
58 })
59 .sep_by(", "); 55 .sep_by(", ");
60 let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); 56 let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", ");
61 57
@@ -90,8 +86,8 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
90 86
91// Generates the surrounding `impl Type { <code> }` including type and lifetime 87// Generates the surrounding `impl Type { <code> }` including type and lifetime
92// parameters 88// parameters
93fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String { 89fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String {
94 let type_params = strukt.type_param_list(); 90 let type_params = strukt.generic_param_list();
95 let mut buf = String::with_capacity(code.len()); 91 let mut buf = String::with_capacity(code.len());
96 buf.push_str("\n\nimpl"); 92 buf.push_str("\n\nimpl");
97 if let Some(type_params) = &type_params { 93 if let Some(type_params) = &type_params {
@@ -121,7 +117,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String {
121// 117//
122// FIXME: change the new fn checking to a more semantic approach when that's more 118// FIXME: change the new fn checking to a more semantic approach when that's more
123// viable (e.g. we process proc macros, etc) 119// viable (e.g. we process proc macros, etc)
124fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option<Option<ast::ImplDef>> { 120fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option<Option<ast::Impl>> {
125 let db = ctx.db(); 121 let db = ctx.db();
126 let module = strukt.syntax().ancestors().find(|node| { 122 let module = strukt.syntax().ancestors().find(|node| {
127 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) 123 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
@@ -129,7 +125,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option<Opti
129 125
130 let struct_def = ctx.sema.to_def(strukt)?; 126 let struct_def = ctx.sema.to_def(strukt)?;
131 127
132 let block = module.descendants().filter_map(ast::ImplDef::cast).find_map(|impl_blk| { 128 let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| {
133 let blk = ctx.sema.to_def(&impl_blk)?; 129 let blk = ctx.sema.to_def(&impl_blk)?;
134 130
135 // FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}` 131 // FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}`
@@ -157,10 +153,10 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option<Opti
157 Some(block) 153 Some(block)
158} 154}
159 155
160fn has_new_fn(imp: &ast::ImplDef) -> bool { 156fn has_new_fn(imp: &ast::Impl) -> bool {
161 if let Some(il) = imp.item_list() { 157 if let Some(il) = imp.assoc_item_list() {
162 for item in il.assoc_items() { 158 for item in il.assoc_items() {
163 if let ast::AssocItem::FnDef(f) = item { 159 if let ast::AssocItem::Fn(f) = item {
164 if let Some(name) = f.name() { 160 if let Some(name) = f.name() {
165 if name.text().eq_ignore_ascii_case("new") { 161 if name.text().eq_ignore_ascii_case("new") {
166 return true; 162 return true;
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs
index 2fdfabaf5..3c58020f8 100644
--- a/crates/ra_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ra_assists/src/handlers/inline_local_variable.rs
@@ -29,7 +29,7 @@ use crate::{
29pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 29pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
30 let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?; 30 let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?;
31 let bind_pat = match let_stmt.pat()? { 31 let bind_pat = match let_stmt.pat()? {
32 ast::Pat::BindPat(pat) => pat, 32 ast::Pat::IdentPat(pat) => pat,
33 _ => return None, 33 _ => return None,
34 }; 34 };
35 if bind_pat.mut_token().is_some() { 35 if bind_pat.mut_token().is_some() {
diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
index 967593031..fbaf3c06b 100644
--- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
+++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
@@ -1,5 +1,5 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, 2 ast::{self, GenericParamsOwner, NameOwner},
3 AstNode, SyntaxKind, TextRange, TextSize, 3 AstNode, SyntaxKind, TextRange, TextSize,
4}; 4};
5use rustc_hash::FxHashSet; 5use rustc_hash::FxHashSet;
@@ -38,9 +38,9 @@ pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -
38 let lifetime_token = ctx 38 let lifetime_token = ctx
39 .find_token_at_offset(SyntaxKind::LIFETIME) 39 .find_token_at_offset(SyntaxKind::LIFETIME)
40 .filter(|lifetime| lifetime.text() == "'_")?; 40 .filter(|lifetime| lifetime.text() == "'_")?;
41 if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::FnDef::cast) { 41 if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::Fn::cast) {
42 generate_fn_def_assist(acc, &fn_def, lifetime_token.text_range()) 42 generate_fn_def_assist(acc, &fn_def, lifetime_token.text_range())
43 } else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::ImplDef::cast) { 43 } else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::Impl::cast) {
44 generate_impl_def_assist(acc, &impl_def, lifetime_token.text_range()) 44 generate_impl_def_assist(acc, &impl_def, lifetime_token.text_range())
45 } else { 45 } else {
46 None 46 None
@@ -50,11 +50,11 @@ pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -
50/// Generate the assist for the fn def case 50/// Generate the assist for the fn def case
51fn generate_fn_def_assist( 51fn generate_fn_def_assist(
52 acc: &mut Assists, 52 acc: &mut Assists,
53 fn_def: &ast::FnDef, 53 fn_def: &ast::Fn,
54 lifetime_loc: TextRange, 54 lifetime_loc: TextRange,
55) -> Option<()> { 55) -> Option<()> {
56 let param_list: ast::ParamList = fn_def.param_list()?; 56 let param_list: ast::ParamList = fn_def.param_list()?;
57 let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?; 57 let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.generic_param_list())?;
58 let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end(); 58 let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end();
59 let self_param = 59 let self_param =
60 // use the self if it's a reference and has no explicit lifetime 60 // use the self if it's a reference and has no explicit lifetime
@@ -67,8 +67,8 @@ fn generate_fn_def_assist(
67 // otherwise, if there's a single reference parameter without a named liftime, use that 67 // otherwise, if there's a single reference parameter without a named liftime, use that
68 let fn_params_without_lifetime: Vec<_> = param_list 68 let fn_params_without_lifetime: Vec<_> = param_list
69 .params() 69 .params()
70 .filter_map(|param| match param.ascribed_type() { 70 .filter_map(|param| match param.ty() {
71 Some(ast::TypeRef::ReferenceType(ascribed_type)) 71 Some(ast::Type::RefType(ascribed_type))
72 if ascribed_type.lifetime_token() == None => 72 if ascribed_type.lifetime_token() == None =>
73 { 73 {
74 Some(ascribed_type.amp_token()?.text_range().end()) 74 Some(ascribed_type.amp_token()?.text_range().end())
@@ -93,10 +93,10 @@ fn generate_fn_def_assist(
93/// Generate the assist for the impl def case 93/// Generate the assist for the impl def case
94fn generate_impl_def_assist( 94fn generate_impl_def_assist(
95 acc: &mut Assists, 95 acc: &mut Assists,
96 impl_def: &ast::ImplDef, 96 impl_def: &ast::Impl,
97 lifetime_loc: TextRange, 97 lifetime_loc: TextRange,
98) -> Option<()> { 98) -> Option<()> {
99 let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.type_param_list())?; 99 let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.generic_param_list())?;
100 let end_of_impl_kw = impl_def.impl_token()?.text_range().end(); 100 let end_of_impl_kw = impl_def.impl_token()?.text_range().end();
101 acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| { 101 acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
102 add_lifetime_param(impl_def, builder, end_of_impl_kw, new_lifetime_param); 102 add_lifetime_param(impl_def, builder, end_of_impl_kw, new_lifetime_param);
@@ -107,7 +107,7 @@ fn generate_impl_def_assist(
107/// Given a type parameter list, generate a unique lifetime parameter name 107/// Given a type parameter list, generate a unique lifetime parameter name
108/// which is not in the list 108/// which is not in the list
109fn generate_unique_lifetime_param_name( 109fn generate_unique_lifetime_param_name(
110 existing_type_param_list: &Option<ast::TypeParamList>, 110 existing_type_param_list: &Option<ast::GenericParamList>,
111) -> Option<char> { 111) -> Option<char> {
112 match existing_type_param_list { 112 match existing_type_param_list {
113 Some(type_params) => { 113 Some(type_params) => {
@@ -123,13 +123,13 @@ fn generate_unique_lifetime_param_name(
123 123
124/// Add the lifetime param to `builder`. If there are type parameters in `type_params_owner`, add it to the end. Otherwise 124/// Add the lifetime param to `builder`. If there are type parameters in `type_params_owner`, add it to the end. Otherwise
125/// add new type params brackets with the lifetime parameter at `new_type_params_loc`. 125/// add new type params brackets with the lifetime parameter at `new_type_params_loc`.
126fn add_lifetime_param<TypeParamsOwner: ast::TypeParamsOwner>( 126fn add_lifetime_param<TypeParamsOwner: ast::GenericParamsOwner>(
127 type_params_owner: &TypeParamsOwner, 127 type_params_owner: &TypeParamsOwner,
128 builder: &mut AssistBuilder, 128 builder: &mut AssistBuilder,
129 new_type_params_loc: TextSize, 129 new_type_params_loc: TextSize,
130 new_lifetime_param: char, 130 new_lifetime_param: char,
131) { 131) {
132 match type_params_owner.type_param_list() { 132 match type_params_owner.generic_param_list() {
133 // add the new lifetime parameter to an existing type param list 133 // add the new lifetime parameter to an existing type param list
134 Some(type_params) => { 134 Some(type_params) => {
135 builder.insert( 135 builder.insert(
diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs
index 1beccb61c..c775fe25c 100644
--- a/crates/ra_assists/src/handlers/merge_imports.rs
+++ b/crates/ra_assists/src/handlers/merge_imports.rs
@@ -28,7 +28,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
28 let mut rewriter = SyntaxRewriter::default(); 28 let mut rewriter = SyntaxRewriter::default();
29 let mut offset = ctx.offset(); 29 let mut offset = ctx.offset();
30 30
31 if let Some(use_item) = tree.syntax().parent().and_then(ast::UseItem::cast) { 31 if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
32 let (merged, to_delete) = next_prev() 32 let (merged, to_delete) = next_prev()
33 .filter_map(|dir| neighbor(&use_item, dir)) 33 .filter_map(|dir| neighbor(&use_item, dir))
34 .filter_map(|it| Some((it.clone(), it.use_tree()?))) 34 .filter_map(|it| Some((it.clone(), it.use_tree()?)))
diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs
index 186a1f618..563292282 100644
--- a/crates/ra_assists/src/handlers/merge_match_arms.rs
+++ b/crates/ra_assists/src/handlers/merge_match_arms.rs
@@ -86,7 +86,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
86} 86}
87 87
88fn contains_placeholder(a: &ast::MatchArm) -> bool { 88fn contains_placeholder(a: &ast::MatchArm) -> bool {
89 matches!(a.pat(), Some(ast::Pat::PlaceholderPat(..))) 89 matches!(a.pat(), Some(ast::Pat::WildcardPat(..)))
90} 90}
91 91
92#[cfg(test)] 92#[cfg(test)]
diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs
index ba3dafb99..6d394443e 100644
--- a/crates/ra_assists/src/handlers/move_bounds.rs
+++ b/crates/ra_assists/src/handlers/move_bounds.rs
@@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
23// } 23// }
24// ``` 24// ```
25pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 25pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
26 let type_param_list = ctx.find_node_at_offset::<ast::TypeParamList>()?; 26 let type_param_list = ctx.find_node_at_offset::<ast::GenericParamList>()?;
27 27
28 let mut type_params = type_param_list.type_params(); 28 let mut type_params = type_param_list.type_params();
29 if type_params.all(|p| p.type_bound_list().is_none()) { 29 if type_params.all(|p| p.type_bound_list().is_none()) {
@@ -37,13 +37,13 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
37 37
38 let anchor = match_ast! { 38 let anchor = match_ast! {
39 match parent { 39 match parent {
40 ast::FnDef(it) => it.body()?.syntax().clone().into(), 40 ast::Fn(it) => it.body()?.syntax().clone().into(),
41 ast::TraitDef(it) => it.item_list()?.syntax().clone().into(), 41 ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(),
42 ast::ImplDef(it) => it.item_list()?.syntax().clone().into(), 42 ast::Impl(it) => it.assoc_item_list()?.syntax().clone().into(),
43 ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), 43 ast::Enum(it) => it.variant_list()?.syntax().clone().into(),
44 ast::StructDef(it) => { 44 ast::Struct(it) => {
45 it.syntax().children_with_tokens() 45 it.syntax().children_with_tokens()
46 .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == T![;])? 46 .find(|it| it.kind() == RECORD_FIELD_LIST || it.kind() == T![;])?
47 }, 47 },
48 _ => return None 48 _ => return None
49 } 49 }
diff --git a/crates/ra_assists/src/handlers/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs
index 4e8a0c2db..4c797178f 100644
--- a/crates/ra_assists/src/handlers/raw_string.rs
+++ b/crates/ra_assists/src/handlers/raw_string.rs
@@ -173,7 +173,7 @@ fn test_required_hashes() {
173} 173}
174 174
175#[cfg(test)] 175#[cfg(test)]
176mod test { 176mod tests {
177 use test_utils::mark; 177 use test_utils::mark;
178 178
179 use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; 179 use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
diff --git a/crates/ra_assists/src/handlers/remove_dbg.rs b/crates/ra_assists/src/handlers/remove_dbg.rs
index a616cca57..9430ce1b5 100644
--- a/crates/ra_assists/src/handlers/remove_dbg.rs
+++ b/crates/ra_assists/src/handlers/remove_dbg.rs
@@ -1,6 +1,6 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 TextSize, T, 3 TextRange, TextSize, T,
4}; 4};
5 5
6use crate::{AssistContext, AssistId, AssistKind, Assists}; 6use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -27,19 +27,33 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
27 return None; 27 return None;
28 } 28 }
29 29
30 let macro_range = macro_call.syntax().text_range(); 30 let is_leaf = macro_call.syntax().next_sibling().is_none();
31 31
32 let macro_content = { 32 let macro_end = if macro_call.semicolon_token().is_some() {
33 let macro_args = macro_call.token_tree()?.syntax().clone(); 33 macro_call.syntax().text_range().end() - TextSize::of(';')
34 } else {
35 macro_call.syntax().text_range().end()
36 };
34 37
35 let text = macro_args.text(); 38 // macro_range determines what will be deleted and replaced with macro_content
36 let without_parens = TextSize::of('(')..text.len() - TextSize::of(')'); 39 let macro_range = TextRange::new(macro_call.syntax().text_range().start(), macro_end);
37 text.slice(without_parens).to_string() 40 let paste_instead_of_dbg = {
41 let text = macro_call.token_tree()?.syntax().text();
42
43 // leafiness determines if we should include the parenthesis or not
44 let slice_index: TextRange = if is_leaf {
45 // leaf means - we can extract the contents of the dbg! in text
46 TextRange::new(TextSize::of('('), text.len() - TextSize::of(')'))
47 } else {
48 // not leaf - means we should keep the parens
49 TextRange::up_to(text.len())
50 };
51 text.slice(slice_index).to_string()
38 }; 52 };
39 53
40 let target = macro_call.syntax().text_range(); 54 let target = macro_call.syntax().text_range();
41 acc.add(AssistId("remove_dbg", AssistKind::Refactor), "Remove dbg!()", target, |builder| { 55 acc.add(AssistId("remove_dbg", AssistKind::Refactor), "Remove dbg!()", target, |builder| {
42 builder.replace(macro_range, macro_content); 56 builder.replace(macro_range, paste_instead_of_dbg);
43 }) 57 })
44} 58}
45 59
@@ -99,6 +113,7 @@ fn foo(n: usize) {
99", 113",
100 ); 114 );
101 } 115 }
116
102 #[test] 117 #[test]
103 fn test_remove_dbg_with_brackets_and_braces() { 118 fn test_remove_dbg_with_brackets_and_braces() {
104 check_assist(remove_dbg, "dbg![<|>1 + 1]", "1 + 1"); 119 check_assist(remove_dbg, "dbg![<|>1 + 1]", "1 + 1");
@@ -113,7 +128,7 @@ fn foo(n: usize) {
113 } 128 }
114 129
115 #[test] 130 #[test]
116 fn remove_dbg_target() { 131 fn test_remove_dbg_target() {
117 check_assist_target( 132 check_assist_target(
118 remove_dbg, 133 remove_dbg,
119 " 134 "
@@ -126,4 +141,65 @@ fn foo(n: usize) {
126 "dbg!(n.checked_sub(4))", 141 "dbg!(n.checked_sub(4))",
127 ); 142 );
128 } 143 }
144
145 #[test]
146 fn test_remove_dbg_keep_semicolon() {
147 // https://github.com/rust-analyzer/rust-analyzer/issues/5129#issuecomment-651399779
148 // not quite though
149 // adding a comment at the end of the line makes
150 // the ast::MacroCall to include the semicolon at the end
151 check_assist(
152 remove_dbg,
153 r#"let res = <|>dbg!(1 * 20); // needless comment"#,
154 r#"let res = 1 * 20; // needless comment"#,
155 );
156 }
157
158 #[test]
159 fn test_remove_dbg_keep_expression() {
160 check_assist(
161 remove_dbg,
162 r#"let res = <|>dbg!(a + b).foo();"#,
163 r#"let res = (a + b).foo();"#,
164 );
165 }
166
167 #[test]
168 fn test_remove_dbg_from_inside_fn() {
169 check_assist_target(
170 remove_dbg,
171 r#"
172fn square(x: u32) -> u32 {
173 x * x
174}
175
176fn main() {
177 let x = square(dbg<|>!(5 + 10));
178 println!("{}", x);
179}"#,
180 "dbg!(5 + 10)",
181 );
182
183 check_assist(
184 remove_dbg,
185 r#"
186fn square(x: u32) -> u32 {
187 x * x
188}
189
190fn main() {
191 let x = square(dbg<|>!(5 + 10));
192 println!("{}", x);
193}"#,
194 r#"
195fn square(x: u32) -> u32 {
196 x * x
197}
198
199fn main() {
200 let x = square(5 + 10);
201 println!("{}", x);
202}"#,
203 );
204 }
129} 205}
diff --git a/crates/ra_assists/src/handlers/reorder_fields.rs b/crates/ra_assists/src/handlers/reorder_fields.rs
index 2ac1c56cf..c9b743a06 100644
--- a/crates/ra_assists/src/handlers/reorder_fields.rs
+++ b/crates/ra_assists/src/handlers/reorder_fields.rs
@@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
23// ``` 23// ```
24// 24//
25pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 25pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
26 reorder::<ast::RecordLit>(acc, ctx).or_else(|| reorder::<ast::RecordPat>(acc, ctx)) 26 reorder::<ast::RecordExpr>(acc, ctx).or_else(|| reorder::<ast::RecordPat>(acc, ctx))
27} 27}
28 28
29fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 29fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
@@ -56,8 +56,8 @@ fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
56 56
57fn get_fields_kind(node: &SyntaxNode) -> Vec<SyntaxKind> { 57fn get_fields_kind(node: &SyntaxNode) -> Vec<SyntaxKind> {
58 match node.kind() { 58 match node.kind() {
59 RECORD_LIT => vec![RECORD_FIELD], 59 RECORD_EXPR => vec![RECORD_EXPR_FIELD],
60 RECORD_PAT => vec![RECORD_FIELD_PAT, BIND_PAT], 60 RECORD_PAT => vec![RECORD_PAT_FIELD, IDENT_PAT],
61 _ => vec![], 61 _ => vec![],
62 } 62 }
63} 63}
@@ -65,8 +65,8 @@ fn get_fields_kind(node: &SyntaxNode) -> Vec<SyntaxKind> {
65fn get_field_name(node: &SyntaxNode) -> String { 65fn get_field_name(node: &SyntaxNode) -> String {
66 let res = match_ast! { 66 let res = match_ast! {
67 match node { 67 match node {
68 ast::RecordField(field) => field.field_name().map(|it| it.to_string()), 68 ast::RecordExprField(field) => field.field_name().map(|it| it.to_string()),
69 ast::RecordFieldPat(field) => field.field_name().map(|it| it.to_string()), 69 ast::RecordPatField(field) => field.field_name().map(|it| it.to_string()),
70 _ => None, 70 _ => None,
71 } 71 }
72 }; 72 };
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
index b7e30a7f2..ecafb74a1 100644
--- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
@@ -65,7 +65,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
65 .type_of_pat(&pat) 65 .type_of_pat(&pat)
66 .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty)) 66 .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty))
67 .map(|it| it.sad_pattern()) 67 .map(|it| it.sad_pattern())
68 .unwrap_or_else(|| make::placeholder_pat().into()); 68 .unwrap_or_else(|| make::wildcard_pat().into());
69 let else_expr = unwrap_trivial_block(else_block); 69 let else_expr = unwrap_trivial_block(else_block);
70 make::match_arm(vec![pattern], else_expr) 70 make::match_arm(vec![pattern], else_expr)
71 }; 71 };
diff --git a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs
index a49292c97..e4d436dec 100644
--- a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs
+++ b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs
@@ -50,10 +50,10 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) ->
50 target, 50 target,
51 |edit| { 51 |edit| {
52 let with_placeholder: ast::Pat = match happy_variant { 52 let with_placeholder: ast::Pat = match happy_variant {
53 None => make::placeholder_pat().into(), 53 None => make::wildcard_pat().into(),
54 Some(var_name) => make::tuple_struct_pat( 54 Some(var_name) => make::tuple_struct_pat(
55 make::path_unqualified(make::path_segment(make::name_ref(var_name))), 55 make::path_unqualified(make::path_segment(make::name_ref(var_name))),
56 once(make::placeholder_pat().into()), 56 once(make::wildcard_pat().into()),
57 ) 57 )
58 .into(), 58 .into(),
59 }; 59 };
@@ -62,8 +62,7 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) ->
62 let if_ = make::expr_if(make::condition(init, Some(with_placeholder)), block); 62 let if_ = make::expr_if(make::condition(init, Some(with_placeholder)), block);
63 let stmt = make::expr_stmt(if_); 63 let stmt = make::expr_stmt(if_);
64 64
65 let placeholder = 65 let placeholder = stmt.syntax().descendants().find_map(ast::WildcardPat::cast).unwrap();
66 stmt.syntax().descendants().find_map(ast::PlaceholderPat::cast).unwrap();
67 let stmt = stmt.replace_descendant(placeholder.into(), original_pat); 66 let stmt = stmt.replace_descendant(placeholder.into(), original_pat);
68 67
69 edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt)); 68 edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt));
diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs
index 3d51faa54..da0a860c5 100644
--- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs
@@ -25,7 +25,7 @@ pub(crate) fn replace_qualified_name_with_use(
25) -> Option<()> { 25) -> Option<()> {
26 let path: ast::Path = ctx.find_node_at_offset()?; 26 let path: ast::Path = ctx.find_node_at_offset()?;
27 // We don't want to mess with use statements 27 // We don't want to mess with use statements
28 if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { 28 if path.syntax().ancestors().find_map(ast::Use::cast).is_some() {
29 return None; 29 return None;
30 } 30 }
31 31
@@ -85,7 +85,7 @@ fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path:
85 match child { 85 match child {
86 // Don't modify `use` items, as this can break the `use` item when injecting a new 86 // Don't modify `use` items, as this can break the `use` item when injecting a new
87 // import into the use tree. 87 // import into the use tree.
88 ast::UseItem(_it) => continue, 88 ast::Use(_it) => continue,
89 // Don't descend into submodules, they don't have the same `use` items in scope. 89 // Don't descend into submodules, they don't have the same `use` items in scope.
90 ast::Module(_it) => continue, 90 ast::Module(_it) => continue,
91 91
@@ -643,4 +643,46 @@ fn main() {
643 ", 643 ",
644 ); 644 );
645 } 645 }
646
647 #[test]
648 fn does_not_replace_pub_use() {
649 check_assist(
650 replace_qualified_name_with_use,
651 r"
652pub use std::fmt;
653
654impl std::io<|> for Foo {
655}
656 ",
657 r"
658use std::io;
659
660pub use std::fmt;
661
662impl io for Foo {
663}
664 ",
665 );
666 }
667
668 #[test]
669 fn does_not_replace_pub_crate_use() {
670 check_assist(
671 replace_qualified_name_with_use,
672 r"
673pub(crate) use std::fmt;
674
675impl std::io<|> for Foo {
676}
677 ",
678 r"
679use std::io;
680
681pub(crate) use std::fmt;
682
683impl io for Foo {
684}
685 ",
686 );
687 }
646} 688}
diff --git a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
index e5a4bb23c..d69f2c1b0 100644
--- a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
@@ -52,7 +52,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
52 target, 52 target,
53 |builder| { 53 |builder| {
54 let ok_path = make::path_unqualified(make::path_segment(make::name_ref(happy_variant))); 54 let ok_path = make::path_unqualified(make::path_segment(make::name_ref(happy_variant)));
55 let it = make::bind_pat(make::name("a")).into(); 55 let it = make::ident_pat(make::name("a")).into();
56 let ok_tuple = make::tuple_struct_pat(ok_path, iter::once(it)).into(); 56 let ok_tuple = make::tuple_struct_pat(ok_path, iter::once(it)).into();
57 57
58 let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a"))); 58 let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a")));
@@ -60,7 +60,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
60 60
61 let unreachable_call = make::expr_unreachable(); 61 let unreachable_call = make::expr_unreachable();
62 let err_arm = 62 let err_arm =
63 make::match_arm(iter::once(make::placeholder_pat().into()), unreachable_call); 63 make::match_arm(iter::once(make::wildcard_pat().into()), unreachable_call);
64 64
65 let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]); 65 let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]);
66 let match_expr = make::expr_match(caller.clone(), match_arm_list) 66 let match_expr = make::expr_match(caller.clone(), match_arm_list)
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 465b90415..507646cc8 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -140,6 +140,7 @@ mod handlers {
140 mod change_return_type_to_result; 140 mod change_return_type_to_result;
141 mod change_visibility; 141 mod change_visibility;
142 mod early_return; 142 mod early_return;
143 mod expand_glob_import;
143 mod extract_struct_from_enum_variant; 144 mod extract_struct_from_enum_variant;
144 mod extract_variable; 145 mod extract_variable;
145 mod fill_match_arms; 146 mod fill_match_arms;
@@ -181,6 +182,7 @@ mod handlers {
181 change_return_type_to_result::change_return_type_to_result, 182 change_return_type_to_result::change_return_type_to_result,
182 change_visibility::change_visibility, 183 change_visibility::change_visibility,
183 early_return::convert_to_guarded_return, 184 early_return::convert_to_guarded_return,
185 expand_glob_import::expand_glob_import,
184 extract_struct_from_enum_variant::extract_struct_from_enum_variant, 186 extract_struct_from_enum_variant::extract_struct_from_enum_variant,
185 extract_variable::extract_variable, 187 extract_variable::extract_variable,
186 fill_match_arms::fill_match_arms, 188 fill_match_arms::fill_match_arms,
diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs
index eff7feded..97978e7a2 100644
--- a/crates/ra_assists/src/tests/generated.rs
+++ b/crates/ra_assists/src/tests/generated.rs
@@ -229,6 +229,33 @@ fn main() {
229} 229}
230 230
231#[test] 231#[test]
232fn doctest_expand_glob_import() {
233 check_doc_test(
234 "expand_glob_import",
235 r#####"
236mod foo {
237 pub struct Bar;
238 pub struct Baz;
239}
240
241use foo::*<|>;
242
243fn qux(bar: Bar, baz: Baz) {}
244"#####,
245 r#####"
246mod foo {
247 pub struct Bar;
248 pub struct Baz;
249}
250
251use foo::{Baz, Bar};
252
253fn qux(bar: Bar, baz: Baz) {}
254"#####,
255 )
256}
257
258#[test]
232fn doctest_extract_struct_from_enum_variant() { 259fn doctest_extract_struct_from_enum_variant() {
233 check_doc_test( 260 check_doc_test(
234 "extract_struct_from_enum_variant", 261 "extract_struct_from_enum_variant",
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
index 02de902d6..54d5678d1 100644
--- a/crates/ra_assists/src/utils.rs
+++ b/crates/ra_assists/src/utils.rs
@@ -56,33 +56,34 @@ pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor
56 56
57pub fn get_missing_assoc_items( 57pub fn get_missing_assoc_items(
58 sema: &Semantics<RootDatabase>, 58 sema: &Semantics<RootDatabase>,
59 impl_def: &ast::ImplDef, 59 impl_def: &ast::Impl,
60) -> Vec<hir::AssocItem> { 60) -> Vec<hir::AssocItem> {
61 // Names must be unique between constants and functions. However, type aliases 61 // Names must be unique between constants and functions. However, type aliases
62 // may share the same name as a function or constant. 62 // may share the same name as a function or constant.
63 let mut impl_fns_consts = FxHashSet::default(); 63 let mut impl_fns_consts = FxHashSet::default();
64 let mut impl_type = FxHashSet::default(); 64 let mut impl_type = FxHashSet::default();
65 65
66 if let Some(item_list) = impl_def.item_list() { 66 if let Some(item_list) = impl_def.assoc_item_list() {
67 for item in item_list.assoc_items() { 67 for item in item_list.assoc_items() {
68 match item { 68 match item {
69 ast::AssocItem::FnDef(f) => { 69 ast::AssocItem::Fn(f) => {
70 if let Some(n) = f.name() { 70 if let Some(n) = f.name() {
71 impl_fns_consts.insert(n.syntax().to_string()); 71 impl_fns_consts.insert(n.syntax().to_string());
72 } 72 }
73 } 73 }
74 74
75 ast::AssocItem::TypeAliasDef(t) => { 75 ast::AssocItem::TypeAlias(t) => {
76 if let Some(n) = t.name() { 76 if let Some(n) = t.name() {
77 impl_type.insert(n.syntax().to_string()); 77 impl_type.insert(n.syntax().to_string());
78 } 78 }
79 } 79 }
80 80
81 ast::AssocItem::ConstDef(c) => { 81 ast::AssocItem::Const(c) => {
82 if let Some(n) = c.name() { 82 if let Some(n) = c.name() {
83 impl_fns_consts.insert(n.syntax().to_string()); 83 impl_fns_consts.insert(n.syntax().to_string());
84 } 84 }
85 } 85 }
86 ast::AssocItem::MacroCall(_) => (),
86 } 87 }
87 } 88 }
88 } 89 }
@@ -108,13 +109,10 @@ pub fn get_missing_assoc_items(
108 109
109pub(crate) fn resolve_target_trait( 110pub(crate) fn resolve_target_trait(
110 sema: &Semantics<RootDatabase>, 111 sema: &Semantics<RootDatabase>,
111 impl_def: &ast::ImplDef, 112 impl_def: &ast::Impl,
112) -> Option<hir::Trait> { 113) -> Option<hir::Trait> {
113 let ast_path = impl_def 114 let ast_path =
114 .target_trait() 115 impl_def.trait_().map(|it| it.syntax().clone()).and_then(ast::PathType::cast)?.path()?;
115 .map(|it| it.syntax().clone())
116 .and_then(ast::PathType::cast)?
117 .path()?;
118 116
119 match sema.resolve_path(&ast_path) { 117 match sema.resolve_path(&ast_path) {
120 Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), 118 Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def),
@@ -183,10 +181,10 @@ impl TryEnum {
183 match self { 181 match self {
184 TryEnum::Result => make::tuple_struct_pat( 182 TryEnum::Result => make::tuple_struct_pat(
185 make::path_unqualified(make::path_segment(make::name_ref("Err"))), 183 make::path_unqualified(make::path_segment(make::name_ref("Err"))),
186 iter::once(make::placeholder_pat().into()), 184 iter::once(make::wildcard_pat().into()),
187 ) 185 )
188 .into(), 186 .into(),
189 TryEnum::Option => make::bind_pat(make::name("None")).into(), 187 TryEnum::Option => make::ident_pat(make::name("None")).into(),
190 } 188 }
191 } 189 }
192 190
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs
index 8c4f33e59..32780fceb 100644
--- a/crates/ra_assists/src/utils/insert_use.rs
+++ b/crates/ra_assists/src/utils/insert_use.rs
@@ -4,7 +4,7 @@
4 4
5use hir::{self, ModPath}; 5use hir::{self, ModPath};
6use ra_syntax::{ 6use ra_syntax::{
7 ast::{self, NameOwner}, 7 ast::{self, NameOwner, VisibilityOwner},
8 AstNode, Direction, SmolStr, 8 AstNode, Direction, SmolStr,
9 SyntaxKind::{PATH, PATH_SEGMENT}, 9 SyntaxKind::{PATH, PATH_SEGMENT},
10 SyntaxNode, T, 10 SyntaxNode, T,
@@ -215,7 +215,7 @@ fn walk_use_tree_for_best_action(
215 let prev_len = current_path_segments.len(); 215 let prev_len = current_path_segments.len();
216 216
217 let tree_list = current_use_tree.use_tree_list(); 217 let tree_list = current_use_tree.use_tree_list();
218 let alias = current_use_tree.alias(); 218 let alias = current_use_tree.rename();
219 219
220 let path = match current_use_tree.path() { 220 let path = match current_use_tree.path() {
221 Some(path) => path, 221 Some(path) => path,
@@ -225,7 +225,7 @@ fn walk_use_tree_for_best_action(
225 current_use_tree 225 current_use_tree
226 .syntax() 226 .syntax()
227 .ancestors() 227 .ancestors()
228 .find_map(ast::UseItem::cast) 228 .find_map(ast::Use::cast)
229 .map(|it| it.syntax().clone()), 229 .map(|it| it.syntax().clone()),
230 true, 230 true,
231 ); 231 );
@@ -254,7 +254,7 @@ fn walk_use_tree_for_best_action(
254 current_use_tree 254 current_use_tree
255 .syntax() 255 .syntax()
256 .ancestors() 256 .ancestors()
257 .find_map(ast::UseItem::cast) 257 .find_map(ast::Use::cast)
258 .map(|it| it.syntax().clone()), 258 .map(|it| it.syntax().clone()),
259 true, 259 true,
260 ), 260 ),
@@ -304,7 +304,7 @@ fn walk_use_tree_for_best_action(
304 current_use_tree 304 current_use_tree
305 .syntax() 305 .syntax()
306 .ancestors() 306 .ancestors()
307 .find_map(ast::UseItem::cast) 307 .find_map(ast::Use::cast)
308 .map(|it| it.syntax().clone()), 308 .map(|it| it.syntax().clone()),
309 true, 309 true,
310 ); 310 );
@@ -377,7 +377,8 @@ fn best_action_for_target(
377 let mut storage = Vec::with_capacity(16); // this should be the only allocation 377 let mut storage = Vec::with_capacity(16); // this should be the only allocation
378 let best_action = container 378 let best_action = container
379 .children() 379 .children()
380 .filter_map(ast::UseItem::cast) 380 .filter_map(ast::Use::cast)
381 .filter(|u| u.visibility().is_none())
381 .filter_map(|it| it.use_tree()) 382 .filter_map(|it| it.use_tree())
382 .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target)) 383 .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
383 .fold(None, |best, a| match best { 384 .fold(None, |best, a| match best {
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml
index 5f334d04f..fe73dc015 100644
--- a/crates/ra_db/Cargo.toml
+++ b/crates/ra_db/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
9doctest = false 9doctest = false
10 10
11[dependencies] 11[dependencies]
12salsa = "0.15.0" 12salsa = "0.15.2"
13rustc-hash = "1.1.0" 13rustc-hash = "1.1.0"
14 14
15ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 859bdfb3b..27cdabea0 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -361,8 +361,8 @@ pub struct Field {
361 361
362#[derive(Debug, PartialEq, Eq)] 362#[derive(Debug, PartialEq, Eq)]
363pub enum FieldSource { 363pub enum FieldSource {
364 Named(ast::RecordFieldDef), 364 Named(ast::RecordField),
365 Pos(ast::TupleFieldDef), 365 Pos(ast::TupleField),
366} 366}
367 367
368impl Field { 368impl Field {
@@ -1002,7 +1002,7 @@ impl Local {
1002 Type::new(db, krate, def, ty) 1002 Type::new(db, krate, def, ty)
1003 } 1003 }
1004 1004
1005 pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> { 1005 pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::IdentPat, ast::SelfParam>> {
1006 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 1006 let (_body, source_map) = db.body_with_source_map(self.parent.into());
1007 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... 1007 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
1008 let root = src.file_syntax(db.upcast()); 1008 let root = src.file_syntax(db.upcast());
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index a2b9f3e35..07333c453 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -13,14 +13,7 @@ pub use hir_expand::db::{
13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery, 13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery, 14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery,
15}; 15};
16pub use hir_ty::db::{ 16pub use hir_ty::db::*;
17 AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery,
18 GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase,
19 HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, InferQueryQuery,
20 InherentImplsInCrateQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery,
21 TraitDatumQuery, TraitImplsInCrateQuery, TraitImplsInDepsQuery, TraitSolveQuery, TyQuery,
22 ValueTyQuery,
23};
24 17
25#[test] 18#[test]
26fn hir_database_is_object_safe() { 19fn hir_database_is_object_safe() {
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs
index 4fd675039..db9228d67 100644
--- a/crates/ra_hir/src/has_source.rs
+++ b/crates/ra_hir/src/has_source.rs
@@ -57,56 +57,56 @@ impl HasSource for Field {
57 } 57 }
58} 58}
59impl HasSource for Struct { 59impl HasSource for Struct {
60 type Ast = ast::StructDef; 60 type Ast = ast::Struct;
61 fn source(self, db: &dyn HirDatabase) -> InFile<ast::StructDef> { 61 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Struct> {
62 self.id.lookup(db.upcast()).source(db.upcast()) 62 self.id.lookup(db.upcast()).source(db.upcast())
63 } 63 }
64} 64}
65impl HasSource for Union { 65impl HasSource for Union {
66 type Ast = ast::UnionDef; 66 type Ast = ast::Union;
67 fn source(self, db: &dyn HirDatabase) -> InFile<ast::UnionDef> { 67 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Union> {
68 self.id.lookup(db.upcast()).source(db.upcast()) 68 self.id.lookup(db.upcast()).source(db.upcast())
69 } 69 }
70} 70}
71impl HasSource for Enum { 71impl HasSource for Enum {
72 type Ast = ast::EnumDef; 72 type Ast = ast::Enum;
73 fn source(self, db: &dyn HirDatabase) -> InFile<ast::EnumDef> { 73 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Enum> {
74 self.id.lookup(db.upcast()).source(db.upcast()) 74 self.id.lookup(db.upcast()).source(db.upcast())
75 } 75 }
76} 76}
77impl HasSource for EnumVariant { 77impl HasSource for EnumVariant {
78 type Ast = ast::EnumVariant; 78 type Ast = ast::Variant;
79 fn source(self, db: &dyn HirDatabase) -> InFile<ast::EnumVariant> { 79 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Variant> {
80 self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone()) 80 self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone())
81 } 81 }
82} 82}
83impl HasSource for Function { 83impl HasSource for Function {
84 type Ast = ast::FnDef; 84 type Ast = ast::Fn;
85 fn source(self, db: &dyn HirDatabase) -> InFile<ast::FnDef> { 85 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Fn> {
86 self.id.lookup(db.upcast()).source(db.upcast()) 86 self.id.lookup(db.upcast()).source(db.upcast())
87 } 87 }
88} 88}
89impl HasSource for Const { 89impl HasSource for Const {
90 type Ast = ast::ConstDef; 90 type Ast = ast::Const;
91 fn source(self, db: &dyn HirDatabase) -> InFile<ast::ConstDef> { 91 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Const> {
92 self.id.lookup(db.upcast()).source(db.upcast()) 92 self.id.lookup(db.upcast()).source(db.upcast())
93 } 93 }
94} 94}
95impl HasSource for Static { 95impl HasSource for Static {
96 type Ast = ast::StaticDef; 96 type Ast = ast::Static;
97 fn source(self, db: &dyn HirDatabase) -> InFile<ast::StaticDef> { 97 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Static> {
98 self.id.lookup(db.upcast()).source(db.upcast()) 98 self.id.lookup(db.upcast()).source(db.upcast())
99 } 99 }
100} 100}
101impl HasSource for Trait { 101impl HasSource for Trait {
102 type Ast = ast::TraitDef; 102 type Ast = ast::Trait;
103 fn source(self, db: &dyn HirDatabase) -> InFile<ast::TraitDef> { 103 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
104 self.id.lookup(db.upcast()).source(db.upcast()) 104 self.id.lookup(db.upcast()).source(db.upcast())
105 } 105 }
106} 106}
107impl HasSource for TypeAlias { 107impl HasSource for TypeAlias {
108 type Ast = ast::TypeAliasDef; 108 type Ast = ast::TypeAlias;
109 fn source(self, db: &dyn HirDatabase) -> InFile<ast::TypeAliasDef> { 109 fn source(self, db: &dyn HirDatabase) -> InFile<ast::TypeAlias> {
110 self.id.lookup(db.upcast()).source(db.upcast()) 110 self.id.lookup(db.upcast()).source(db.upcast())
111 } 111 }
112} 112}
@@ -120,14 +120,14 @@ impl HasSource for MacroDef {
120 } 120 }
121} 121}
122impl HasSource for ImplDef { 122impl HasSource for ImplDef {
123 type Ast = ast::ImplDef; 123 type Ast = ast::Impl;
124 fn source(self, db: &dyn HirDatabase) -> InFile<ast::ImplDef> { 124 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Impl> {
125 self.id.lookup(db.upcast()).source(db.upcast()) 125 self.id.lookup(db.upcast()).source(db.upcast())
126 } 126 }
127} 127}
128 128
129impl HasSource for TypeParam { 129impl HasSource for TypeParam {
130 type Ast = Either<ast::TraitDef, ast::TypeParam>; 130 type Ast = Either<ast::Trait, ast::TypeParam>;
131 fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> { 131 fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
132 let child_source = self.id.parent.child_source(db.upcast()); 132 let child_source = self.id.parent.child_source(db.upcast());
133 child_source.map(|it| it[self.id.local_id].clone()) 133 child_source.map(|it| it[self.id.local_id].clone())
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 1436b1afe..307b336f2 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -209,11 +209,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
209 self.imp.resolve_field(field) 209 self.imp.resolve_field(field)
210 } 210 }
211 211
212 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> { 212 pub fn resolve_record_field(
213 &self,
214 field: &ast::RecordExprField,
215 ) -> Option<(Field, Option<Local>)> {
213 self.imp.resolve_record_field(field) 216 self.imp.resolve_record_field(field)
214 } 217 }
215 218
216 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> { 219 pub fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> {
217 self.imp.resolve_record_field_pat(field) 220 self.imp.resolve_record_field_pat(field)
218 } 221 }
219 222
@@ -225,7 +228,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
225 self.imp.resolve_path(path) 228 self.imp.resolve_path(path)
226 } 229 }
227 230
228 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantDef> { 231 pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantDef> {
229 self.imp.resolve_variant(record_lit).map(VariantDef::from) 232 self.imp.resolve_variant(record_lit).map(VariantDef::from)
230 } 233 }
231 234
@@ -233,14 +236,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
233 self.imp.lower_path(path) 236 self.imp.lower_path(path)
234 } 237 }
235 238
236 pub fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> { 239 pub fn resolve_bind_pat_to_const(&self, pat: &ast::IdentPat) -> Option<ModuleDef> {
237 self.imp.resolve_bind_pat_to_const(pat) 240 self.imp.resolve_bind_pat_to_const(pat)
238 } 241 }
239 242
240 // FIXME: use this instead? 243 // FIXME: use this instead?
241 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; 244 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
242 245
243 pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { 246 pub fn record_literal_missing_fields(&self, literal: &ast::RecordExpr) -> Vec<(Field, Type)> {
244 self.imp.record_literal_missing_fields(literal) 247 self.imp.record_literal_missing_fields(literal)
245 } 248 }
246 249
@@ -422,11 +425,11 @@ impl<'db> SemanticsImpl<'db> {
422 self.analyze(field.syntax()).resolve_field(self.db, field) 425 self.analyze(field.syntax()).resolve_field(self.db, field)
423 } 426 }
424 427
425 fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> { 428 fn resolve_record_field(&self, field: &ast::RecordExprField) -> Option<(Field, Option<Local>)> {
426 self.analyze(field.syntax()).resolve_record_field(self.db, field) 429 self.analyze(field.syntax()).resolve_record_field(self.db, field)
427 } 430 }
428 431
429 fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> { 432 fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> {
430 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) 433 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field)
431 } 434 }
432 435
@@ -440,7 +443,7 @@ impl<'db> SemanticsImpl<'db> {
440 self.analyze(path.syntax()).resolve_path(self.db, path) 443 self.analyze(path.syntax()).resolve_path(self.db, path)
441 } 444 }
442 445
443 fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> { 446 fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {
444 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit) 447 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit)
445 } 448 }
446 449
@@ -449,11 +452,11 @@ impl<'db> SemanticsImpl<'db> {
449 Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into())) 452 Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into()))
450 } 453 }
451 454
452 fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> { 455 fn resolve_bind_pat_to_const(&self, pat: &ast::IdentPat) -> Option<ModuleDef> {
453 self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat) 456 self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat)
454 } 457 }
455 458
456 fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { 459 fn record_literal_missing_fields(&self, literal: &ast::RecordExpr) -> Vec<(Field, Type)> {
457 self.analyze(literal.syntax()) 460 self.analyze(literal.syntax())
458 .record_literal_missing_fields(self.db, literal) 461 .record_literal_missing_fields(self.db, literal)
459 .unwrap_or_default() 462 .unwrap_or_default()
@@ -577,21 +580,21 @@ macro_rules! to_def_impls {
577 580
578to_def_impls![ 581to_def_impls![
579 (crate::Module, ast::Module, module_to_def), 582 (crate::Module, ast::Module, module_to_def),
580 (crate::Struct, ast::StructDef, struct_to_def), 583 (crate::Struct, ast::Struct, struct_to_def),
581 (crate::Enum, ast::EnumDef, enum_to_def), 584 (crate::Enum, ast::Enum, enum_to_def),
582 (crate::Union, ast::UnionDef, union_to_def), 585 (crate::Union, ast::Union, union_to_def),
583 (crate::Trait, ast::TraitDef, trait_to_def), 586 (crate::Trait, ast::Trait, trait_to_def),
584 (crate::ImplDef, ast::ImplDef, impl_to_def), 587 (crate::ImplDef, ast::Impl, impl_to_def),
585 (crate::TypeAlias, ast::TypeAliasDef, type_alias_to_def), 588 (crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
586 (crate::Const, ast::ConstDef, const_to_def), 589 (crate::Const, ast::Const, const_to_def),
587 (crate::Static, ast::StaticDef, static_to_def), 590 (crate::Static, ast::Static, static_to_def),
588 (crate::Function, ast::FnDef, fn_to_def), 591 (crate::Function, ast::Fn, fn_to_def),
589 (crate::Field, ast::RecordFieldDef, record_field_to_def), 592 (crate::Field, ast::RecordField, record_field_to_def),
590 (crate::Field, ast::TupleFieldDef, tuple_field_to_def), 593 (crate::Field, ast::TupleField, tuple_field_to_def),
591 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), 594 (crate::EnumVariant, ast::Variant, enum_variant_to_def),
592 (crate::TypeParam, ast::TypeParam, type_param_to_def), 595 (crate::TypeParam, ast::TypeParam, type_param_to_def),
593 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros 596 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros
594 (crate::Local, ast::BindPat, bind_pat_to_def), 597 (crate::Local, ast::IdentPat, bind_pat_to_def),
595]; 598];
596 599
597fn find_root(node: &SyntaxNode) -> SyntaxNode { 600fn find_root(node: &SyntaxNode) -> SyntaxNode {
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 42e5a1bdb..863e8e5ff 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -65,57 +65,48 @@ impl SourceToDefCtx<'_, '_> {
65 Some(ModuleId { krate: parent_module.krate, local_id: child_id }) 65 Some(ModuleId { krate: parent_module.krate, local_id: child_id })
66 } 66 }
67 67
68 pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> { 68 pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
69 self.to_def(src, keys::TRAIT) 69 self.to_def(src, keys::TRAIT)
70 } 70 }
71 pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> { 71 pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> {
72 self.to_def(src, keys::IMPL) 72 self.to_def(src, keys::IMPL)
73 } 73 }
74 pub(super) fn fn_to_def(&mut self, src: InFile<ast::FnDef>) -> Option<FunctionId> { 74 pub(super) fn fn_to_def(&mut self, src: InFile<ast::Fn>) -> Option<FunctionId> {
75 self.to_def(src, keys::FUNCTION) 75 self.to_def(src, keys::FUNCTION)
76 } 76 }
77 pub(super) fn struct_to_def(&mut self, src: InFile<ast::StructDef>) -> Option<StructId> { 77 pub(super) fn struct_to_def(&mut self, src: InFile<ast::Struct>) -> Option<StructId> {
78 self.to_def(src, keys::STRUCT) 78 self.to_def(src, keys::STRUCT)
79 } 79 }
80 pub(super) fn enum_to_def(&mut self, src: InFile<ast::EnumDef>) -> Option<EnumId> { 80 pub(super) fn enum_to_def(&mut self, src: InFile<ast::Enum>) -> Option<EnumId> {
81 self.to_def(src, keys::ENUM) 81 self.to_def(src, keys::ENUM)
82 } 82 }
83 pub(super) fn union_to_def(&mut self, src: InFile<ast::UnionDef>) -> Option<UnionId> { 83 pub(super) fn union_to_def(&mut self, src: InFile<ast::Union>) -> Option<UnionId> {
84 self.to_def(src, keys::UNION) 84 self.to_def(src, keys::UNION)
85 } 85 }
86 pub(super) fn static_to_def(&mut self, src: InFile<ast::StaticDef>) -> Option<StaticId> { 86 pub(super) fn static_to_def(&mut self, src: InFile<ast::Static>) -> Option<StaticId> {
87 self.to_def(src, keys::STATIC) 87 self.to_def(src, keys::STATIC)
88 } 88 }
89 pub(super) fn const_to_def(&mut self, src: InFile<ast::ConstDef>) -> Option<ConstId> { 89 pub(super) fn const_to_def(&mut self, src: InFile<ast::Const>) -> Option<ConstId> {
90 self.to_def(src, keys::CONST) 90 self.to_def(src, keys::CONST)
91 } 91 }
92 pub(super) fn type_alias_to_def( 92 pub(super) fn type_alias_to_def(&mut self, src: InFile<ast::TypeAlias>) -> Option<TypeAliasId> {
93 &mut self,
94 src: InFile<ast::TypeAliasDef>,
95 ) -> Option<TypeAliasId> {
96 self.to_def(src, keys::TYPE_ALIAS) 93 self.to_def(src, keys::TYPE_ALIAS)
97 } 94 }
98 pub(super) fn record_field_to_def( 95 pub(super) fn record_field_to_def(&mut self, src: InFile<ast::RecordField>) -> Option<FieldId> {
99 &mut self,
100 src: InFile<ast::RecordFieldDef>,
101 ) -> Option<FieldId> {
102 self.to_def(src, keys::RECORD_FIELD) 96 self.to_def(src, keys::RECORD_FIELD)
103 } 97 }
104 pub(super) fn tuple_field_to_def( 98 pub(super) fn tuple_field_to_def(&mut self, src: InFile<ast::TupleField>) -> Option<FieldId> {
105 &mut self,
106 src: InFile<ast::TupleFieldDef>,
107 ) -> Option<FieldId> {
108 self.to_def(src, keys::TUPLE_FIELD) 99 self.to_def(src, keys::TUPLE_FIELD)
109 } 100 }
110 pub(super) fn enum_variant_to_def( 101 pub(super) fn enum_variant_to_def(
111 &mut self, 102 &mut self,
112 src: InFile<ast::EnumVariant>, 103 src: InFile<ast::Variant>,
113 ) -> Option<EnumVariantId> { 104 ) -> Option<EnumVariantId> {
114 self.to_def(src, keys::ENUM_VARIANT) 105 self.to_def(src, keys::VARIANT)
115 } 106 }
116 pub(super) fn bind_pat_to_def( 107 pub(super) fn bind_pat_to_def(
117 &mut self, 108 &mut self,
118 src: InFile<ast::BindPat>, 109 src: InFile<ast::IdentPat>,
119 ) -> Option<(DefWithBodyId, PatId)> { 110 ) -> Option<(DefWithBodyId, PatId)> {
120 let container = self.find_pat_container(src.as_ref().map(|it| it.syntax()))?; 111 let container = self.find_pat_container(src.as_ref().map(|it| it.syntax()))?;
121 let (_body, source_map) = self.db.body_with_source_map(container); 112 let (_body, source_map) = self.db.body_with_source_map(container);
@@ -163,39 +154,39 @@ impl SourceToDefCtx<'_, '_> {
163 let def = self.module_to_def(container.with_value(it))?; 154 let def = self.module_to_def(container.with_value(it))?;
164 def.into() 155 def.into()
165 }, 156 },
166 ast::TraitDef(it) => { 157 ast::Trait(it) => {
167 let def = self.trait_to_def(container.with_value(it))?; 158 let def = self.trait_to_def(container.with_value(it))?;
168 def.into() 159 def.into()
169 }, 160 },
170 ast::ImplDef(it) => { 161 ast::Impl(it) => {
171 let def = self.impl_to_def(container.with_value(it))?; 162 let def = self.impl_to_def(container.with_value(it))?;
172 def.into() 163 def.into()
173 }, 164 },
174 ast::FnDef(it) => { 165 ast::Fn(it) => {
175 let def = self.fn_to_def(container.with_value(it))?; 166 let def = self.fn_to_def(container.with_value(it))?;
176 DefWithBodyId::from(def).into() 167 DefWithBodyId::from(def).into()
177 }, 168 },
178 ast::StructDef(it) => { 169 ast::Struct(it) => {
179 let def = self.struct_to_def(container.with_value(it))?; 170 let def = self.struct_to_def(container.with_value(it))?;
180 VariantId::from(def).into() 171 VariantId::from(def).into()
181 }, 172 },
182 ast::EnumDef(it) => { 173 ast::Enum(it) => {
183 let def = self.enum_to_def(container.with_value(it))?; 174 let def = self.enum_to_def(container.with_value(it))?;
184 def.into() 175 def.into()
185 }, 176 },
186 ast::UnionDef(it) => { 177 ast::Union(it) => {
187 let def = self.union_to_def(container.with_value(it))?; 178 let def = self.union_to_def(container.with_value(it))?;
188 VariantId::from(def).into() 179 VariantId::from(def).into()
189 }, 180 },
190 ast::StaticDef(it) => { 181 ast::Static(it) => {
191 let def = self.static_to_def(container.with_value(it))?; 182 let def = self.static_to_def(container.with_value(it))?;
192 DefWithBodyId::from(def).into() 183 DefWithBodyId::from(def).into()
193 }, 184 },
194 ast::ConstDef(it) => { 185 ast::Const(it) => {
195 let def = self.const_to_def(container.with_value(it))?; 186 let def = self.const_to_def(container.with_value(it))?;
196 DefWithBodyId::from(def).into() 187 DefWithBodyId::from(def).into()
197 }, 188 },
198 ast::TypeAliasDef(it) => { 189 ast::TypeAlias(it) => {
199 let def = self.type_alias_to_def(container.with_value(it))?; 190 let def = self.type_alias_to_def(container.with_value(it))?;
200 def.into() 191 def.into()
201 }, 192 },
@@ -213,12 +204,12 @@ impl SourceToDefCtx<'_, '_> {
213 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { 204 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
214 let res: GenericDefId = match_ast! { 205 let res: GenericDefId = match_ast! {
215 match (container.value) { 206 match (container.value) {
216 ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), 207 ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
217 ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(), 208 ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(),
218 ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), 209 ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
219 ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), 210 ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
220 ast::TypeAliasDef(it) => self.type_alias_to_def(container.with_value(it))?.into(), 211 ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(),
221 ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), 212 ast::Impl(it) => self.impl_to_def(container.with_value(it))?.into(),
222 _ => continue, 213 _ => continue,
223 } 214 }
224 }; 215 };
@@ -231,9 +222,9 @@ impl SourceToDefCtx<'_, '_> {
231 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { 222 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
232 let res: DefWithBodyId = match_ast! { 223 let res: DefWithBodyId = match_ast! {
233 match (container.value) { 224 match (container.value) {
234 ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(), 225 ast::Const(it) => self.const_to_def(container.with_value(it))?.into(),
235 ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(), 226 ast::Static(it) => self.static_to_def(container.with_value(it))?.into(),
236 ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), 227 ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
237 _ => continue, 228 _ => continue,
238 } 229 }
239 }; 230 };
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 86a47a9e5..d0cb62ef0 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -159,7 +159,7 @@ impl SourceAnalyzer {
159 pub(crate) fn resolve_record_field( 159 pub(crate) fn resolve_record_field(
160 &self, 160 &self,
161 db: &dyn HirDatabase, 161 db: &dyn HirDatabase,
162 field: &ast::RecordField, 162 field: &ast::RecordExprField,
163 ) -> Option<(Field, Option<Local>)> { 163 ) -> Option<(Field, Option<Local>)> {
164 let expr = field.expr()?; 164 let expr = field.expr()?;
165 let expr_id = self.expr_id(db, &expr)?; 165 let expr_id = self.expr_id(db, &expr)?;
@@ -182,7 +182,7 @@ impl SourceAnalyzer {
182 pub(crate) fn resolve_record_field_pat( 182 pub(crate) fn resolve_record_field_pat(
183 &self, 183 &self,
184 _db: &dyn HirDatabase, 184 _db: &dyn HirDatabase,
185 field: &ast::RecordFieldPat, 185 field: &ast::RecordPatField,
186 ) -> Option<Field> { 186 ) -> Option<Field> {
187 let pat_id = self.pat_id(&field.pat()?)?; 187 let pat_id = self.pat_id(&field.pat()?)?;
188 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; 188 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?;
@@ -202,7 +202,7 @@ impl SourceAnalyzer {
202 pub(crate) fn resolve_bind_pat_to_const( 202 pub(crate) fn resolve_bind_pat_to_const(
203 &self, 203 &self,
204 db: &dyn HirDatabase, 204 db: &dyn HirDatabase,
205 pat: &ast::BindPat, 205 pat: &ast::IdentPat,
206 ) -> Option<ModuleDef> { 206 ) -> Option<ModuleDef> {
207 let pat_id = self.pat_id(&pat.clone().into())?; 207 let pat_id = self.pat_id(&pat.clone().into())?;
208 let body = self.body.as_ref()?; 208 let body = self.body.as_ref()?;
@@ -246,7 +246,7 @@ impl SourceAnalyzer {
246 } 246 }
247 } 247 }
248 248
249 if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordLit::cast) { 249 if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordExpr::cast) {
250 let expr_id = self.expr_id(db, &rec_lit.into())?; 250 let expr_id = self.expr_id(db, &rec_lit.into())?;
251 if let Some(VariantId::EnumVariantId(variant)) = 251 if let Some(VariantId::EnumVariantId(variant)) =
252 self.infer.as_ref()?.variant_resolution_for_expr(expr_id) 252 self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
@@ -284,7 +284,7 @@ impl SourceAnalyzer {
284 pub(crate) fn record_literal_missing_fields( 284 pub(crate) fn record_literal_missing_fields(
285 &self, 285 &self,
286 db: &dyn HirDatabase, 286 db: &dyn HirDatabase,
287 literal: &ast::RecordLit, 287 literal: &ast::RecordExpr,
288 ) -> Option<Vec<(Field, Type)>> { 288 ) -> Option<Vec<(Field, Type)>> {
289 let krate = self.resolver.krate()?; 289 let krate = self.resolver.krate()?;
290 let body = self.body.as_ref()?; 290 let body = self.body.as_ref()?;
@@ -358,7 +358,7 @@ impl SourceAnalyzer {
358 pub(crate) fn resolve_variant( 358 pub(crate) fn resolve_variant(
359 &self, 359 &self,
360 db: &dyn HirDatabase, 360 db: &dyn HirDatabase,
361 record_lit: ast::RecordLit, 361 record_lit: ast::RecordExpr,
362 ) -> Option<VariantId> { 362 ) -> Option<VariantId> {
363 let infer = self.infer.as_ref()?; 363 let infer = self.infer.as_ref()?;
364 let expr_id = self.expr_id(db, &record_lit.into())?; 364 let expr_id = self.expr_id(db, &record_lit.into())?;
@@ -405,8 +405,7 @@ fn scope_for_offset(
405 ) 405 )
406 }) 406 })
407 .map(|(expr_range, scope)| { 407 .map(|(expr_range, scope)| {
408 adjust(db, scopes, source_map, expr_range, offset.file_id, offset.value) 408 adjust(db, scopes, source_map, expr_range, offset).unwrap_or(*scope)
409 .unwrap_or(*scope)
410 }) 409 })
411} 410}
412 411
@@ -417,8 +416,7 @@ fn adjust(
417 scopes: &ExprScopes, 416 scopes: &ExprScopes,
418 source_map: &BodySourceMap, 417 source_map: &BodySourceMap,
419 expr_range: TextRange, 418 expr_range: TextRange,
420 file_id: HirFileId, 419 offset: InFile<TextSize>,
421 offset: TextSize,
422) -> Option<ScopeId> { 420) -> Option<ScopeId> {
423 let child_scopes = scopes 421 let child_scopes = scopes
424 .scope_by_expr() 422 .scope_by_expr()
@@ -426,7 +424,7 @@ fn adjust(
426 .filter_map(|(id, scope)| { 424 .filter_map(|(id, scope)| {
427 let source = source_map.expr_syntax(*id).ok()?; 425 let source = source_map.expr_syntax(*id).ok()?;
428 // FIXME: correctly handle macro expansion 426 // FIXME: correctly handle macro expansion
429 if source.file_id != file_id { 427 if source.file_id != offset.file_id {
430 return None; 428 return None;
431 } 429 }
432 let root = source.file_syntax(db.upcast()); 430 let root = source.file_syntax(db.upcast());
@@ -434,7 +432,7 @@ fn adjust(
434 Some((node.syntax().text_range(), scope)) 432 Some((node.syntax().text_range(), scope))
435 }) 433 })
436 .filter(|&(range, _)| { 434 .filter(|&(range, _)| {
437 range.start() <= offset && expr_range.contains_range(range) && range != expr_range 435 range.start() <= offset.value && expr_range.contains_range(range) && range != expr_range
438 }); 436 });
439 437
440 child_scopes 438 child_scopes
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 4994a2125..6cb56a1cd 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -8,7 +8,7 @@ use hir_expand::{
8 InFile, 8 InFile,
9}; 9};
10use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 11use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
12 12
13use crate::{ 13use crate::{
14 body::{CfgExpander, LowerCtx}, 14 body::{CfgExpander, LowerCtx},
@@ -112,7 +112,7 @@ impl EnumData {
112 112
113impl HasChildSource for EnumId { 113impl HasChildSource for EnumId {
114 type ChildId = LocalEnumVariantId; 114 type ChildId = LocalEnumVariantId;
115 type Value = ast::EnumVariant; 115 type Value = ast::Variant;
116 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 116 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
117 let src = self.lookup(db).source(db); 117 let src = self.lookup(db).source(db);
118 let mut trace = Trace::new_for_map(); 118 let mut trace = Trace::new_for_map();
@@ -123,8 +123,8 @@ impl HasChildSource for EnumId {
123 123
124fn lower_enum( 124fn lower_enum(
125 db: &dyn DefDatabase, 125 db: &dyn DefDatabase,
126 trace: &mut Trace<EnumVariantData, ast::EnumVariant>, 126 trace: &mut Trace<EnumVariantData, ast::Variant>,
127 ast: &InFile<ast::EnumDef>, 127 ast: &InFile<ast::Enum>,
128 module_id: ModuleId, 128 module_id: ModuleId,
129) { 129) {
130 let expander = CfgExpander::new(db, ast.file_id, module_id.krate); 130 let expander = CfgExpander::new(db, ast.file_id, module_id.krate);
@@ -179,7 +179,7 @@ impl VariantData {
179 179
180impl HasChildSource for VariantId { 180impl HasChildSource for VariantId {
181 type ChildId = LocalFieldId; 181 type ChildId = LocalFieldId;
182 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; 182 type Value = Either<ast::TupleField, ast::RecordField>;
183 183
184 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 184 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
185 let (src, module_id) = match self { 185 let (src, module_id) = match self {
@@ -194,7 +194,7 @@ impl HasChildSource for VariantId {
194 } 194 }
195 VariantId::UnionId(it) => ( 195 VariantId::UnionId(it) => (
196 it.lookup(db).source(db).map(|it| { 196 it.lookup(db).source(db).map(|it| {
197 it.record_field_def_list() 197 it.record_field_list()
198 .map(ast::StructKind::Record) 198 .map(ast::StructKind::Record)
199 .unwrap_or(ast::StructKind::Unit) 199 .unwrap_or(ast::StructKind::Unit)
200 }), 200 }),
@@ -218,7 +218,7 @@ pub enum StructKind {
218fn lower_struct( 218fn lower_struct(
219 db: &dyn DefDatabase, 219 db: &dyn DefDatabase,
220 expander: &mut CfgExpander, 220 expander: &mut CfgExpander,
221 trace: &mut Trace<FieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, 221 trace: &mut Trace<FieldData, Either<ast::TupleField, ast::RecordField>>,
222 ast: &InFile<ast::StructKind>, 222 ast: &InFile<ast::StructKind>,
223) -> StructKind { 223) -> StructKind {
224 let ctx = LowerCtx::new(db, ast.file_id); 224 let ctx = LowerCtx::new(db, ast.file_id);
@@ -234,7 +234,7 @@ fn lower_struct(
234 || Either::Left(fd.clone()), 234 || Either::Left(fd.clone()),
235 || FieldData { 235 || FieldData {
236 name: Name::new_tuple_field(i), 236 name: Name::new_tuple_field(i),
237 type_ref: TypeRef::from_ast_opt(&ctx, fd.type_ref()), 237 type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
238 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 238 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
239 }, 239 },
240 ); 240 );
@@ -251,7 +251,7 @@ fn lower_struct(
251 || Either::Right(fd.clone()), 251 || Either::Right(fd.clone()),
252 || FieldData { 252 || FieldData {
253 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 253 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
254 type_ref: TypeRef::from_ast_opt(&ctx, fd.ascribed_type()), 254 type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
255 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 255 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
256 }, 256 },
257 ); 257 );
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 70ccd4305..050832ce0 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -151,18 +151,15 @@ pub enum AttrInput {
151impl Attr { 151impl Attr {
152 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { 152 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> {
153 let path = ModPath::from_src(ast.path()?, hygiene)?; 153 let path = ModPath::from_src(ast.path()?, hygiene)?;
154 let input = match ast.input() { 154 let input = if let Some(lit) = ast.literal() {
155 None => None, 155 // FIXME: escape? raw string?
156 Some(ast::AttrInput::Literal(lit)) => { 156 let value = lit.syntax().first_token()?.text().trim_matches('"').into();
157 // FIXME: escape? raw string? 157 Some(AttrInput::Literal(value))
158 let value = lit.syntax().first_token()?.text().trim_matches('"').into(); 158 } else if let Some(tt) = ast.token_tree() {
159 Some(AttrInput::Literal(value)) 159 Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0))
160 } 160 } else {
161 Some(ast::AttrInput::TokenTree(tt)) => { 161 None
162 Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0))
163 }
164 }; 162 };
165
166 Some(Attr { path, input }) 163 Some(Attr { path, input })
167 } 164 }
168} 165}
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 2fe04db2b..d5f18b920 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -216,7 +216,7 @@ pub struct BodySourceMap {
216 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>, 216 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>,
217 pat_map: FxHashMap<PatSource, PatId>, 217 pat_map: FxHashMap<PatSource, PatId>,
218 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>, 218 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>,
219 field_map: FxHashMap<(ExprId, usize), InFile<AstPtr<ast::RecordField>>>, 219 field_map: FxHashMap<(ExprId, usize), InFile<AstPtr<ast::RecordExprField>>>,
220 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, 220 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
221} 221}
222 222
@@ -314,7 +314,7 @@ impl BodySourceMap {
314 self.pat_map.get(&src).cloned() 314 self.pat_map.get(&src).cloned()
315 } 315 }
316 316
317 pub fn field_syntax(&self, expr: ExprId, field: usize) -> InFile<AstPtr<ast::RecordField>> { 317 pub fn field_syntax(&self, expr: ExprId, field: usize) -> InFile<AstPtr<ast::RecordExprField>> {
318 self.field_map[&(expr, field)].clone() 318 self.field_map[&(expr, field)].clone()
319 } 319 }
320} 320}
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index c6bc85e2f..f5c37edb3 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -1,6 +1,8 @@
1//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` 1//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
2//! representation. 2//! representation.
3 3
4use std::{any::type_name, sync::Arc};
5
4use either::Either; 6use either::Either;
5use hir_expand::{ 7use hir_expand::{
6 hygiene::Hygiene, 8 hygiene::Hygiene,
@@ -10,11 +12,12 @@ use hir_expand::{
10use ra_arena::Arena; 12use ra_arena::Arena;
11use ra_syntax::{ 13use ra_syntax::{
12 ast::{ 14 ast::{
13 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, 15 self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner,
14 SlicePatComponents, TypeAscriptionOwner, 16 SlicePatComponents,
15 }, 17 },
16 AstNode, AstPtr, 18 AstNode, AstPtr,
17}; 19};
20use rustc_hash::FxHashMap;
18use test_utils::mark; 21use test_utils::mark;
19 22
20use crate::{ 23use crate::{
@@ -35,9 +38,6 @@ use crate::{
35}; 38};
36 39
37use super::{ExprSource, PatSource}; 40use super::{ExprSource, PatSource};
38use ast::AstChildren;
39use rustc_hash::FxHashMap;
40use std::{any::type_name, sync::Arc};
41 41
42pub(crate) struct LowerCtx { 42pub(crate) struct LowerCtx {
43 hygiene: Hygiene, 43 hygiene: Hygiene,
@@ -224,9 +224,22 @@ impl ExprCollector<'_> {
224 self.alloc_expr(Expr::Unsafe { body }, syntax_ptr) 224 self.alloc_expr(Expr::Unsafe { body }, syntax_ptr)
225 } 225 }
226 // FIXME: we need to record these effects somewhere... 226 // FIXME: we need to record these effects somewhere...
227 ast::Effect::Async(_) | ast::Effect::Label(_) => { 227 ast::Effect::Label(label) => match e.block_expr() {
228 self.collect_block_opt(e.block_expr()) 228 Some(block) => {
229 } 229 let res = self.collect_block(block);
230 match &mut self.body.exprs[res] {
231 Expr::Block { label: block_label, .. } => {
232 *block_label =