aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yaml5
-rw-r--r--.github/workflows/metrics.yaml32
-rw-r--r--Cargo.lock171
-rw-r--r--README.md14
-rw-r--r--crates/flycheck/Cargo.toml2
-rw-r--r--crates/flycheck/src/lib.rs13
-rw-r--r--crates/ra_assists/src/ast_transform.rs14
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs16
-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.rs6
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs10
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs4
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs2
-rw-r--r--crates/ra_assists/src/handlers/extract_variable.rs2
-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.rs6
-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/introduce_named_lifetime.rs24
-rw-r--r--crates/ra_assists/src/handlers/merge_imports.rs2
-rw-r--r--crates/ra_assists/src/handlers/move_bounds.rs14
-rw-r--r--crates/ra_assists/src/handlers/remove_dbg.rs94
-rw-r--r--crates/ra_assists/src/handlers/reorder_fields.rs6
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs4
-rw-r--r--crates/ra_assists/src/utils.rs13
-rw-r--r--crates/ra_assists/src/utils/insert_use.rs10
-rw-r--r--crates/ra_hir/src/code_model.rs4
-rw-r--r--crates/ra_hir/src/diagnostics.rs4
-rw-r--r--crates/ra_hir/src/has_source.rs42
-rw-r--r--crates/ra_hir/src/semantics.rs57
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs71
-rw-r--r--crates/ra_hir/src/source_analyzer.rs18
-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.rs48
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs2
-rw-r--r--crates/ra_hir_def/src/generics.rs14
-rw-r--r--crates/ra_hir_def/src/item_tree.rs52
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs171
-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.rs2
-rw-r--r--crates/ra_hir_def/src/path/lower.rs10
-rw-r--r--crates/ra_hir_def/src/path/lower/lower_use.rs2
-rw-r--r--crates/ra_hir_def/src/type_ref.rs47
-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.rs2
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs60
-rw-r--r--crates/ra_hir_expand/src/lib.rs6
-rw-r--r--crates/ra_hir_ty/Cargo.toml8
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs19
-rw-r--r--crates/ra_hir_ty/src/diagnostics/expr.rs4
-rw-r--r--crates/ra_hir_ty/src/tests.rs2
-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.rs290
-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.rs20
-rw-r--r--crates/ra_ide/src/completion/patterns.rs16
-rw-r--r--crates/ra_ide/src/diagnostics.rs178
-rw-r--r--crates/ra_ide/src/display.rs12
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs40
-rw-r--r--crates/ra_ide/src/display/short_label.rs34
-rw-r--r--crates/ra_ide/src/extend_selection.rs8
-rw-r--r--crates/ra_ide/src/file_structure.rs76
-rw-r--r--crates/ra_ide/src/folding_ranges.rs24
-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.rs8
-rw-r--r--crates/ra_ide/src/lib.rs12
-rw-r--r--crates/ra_ide/src/references.rs34
-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.rs39
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs24
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs10
-rw-r--r--crates/ra_ide/src/syntax_tree.rs14
-rw-r--r--crates/ra_ide/test_data/rainbow_highlighting.html12
-rw-r--r--crates/ra_ide_db/src/defs.rs59
-rw-r--r--crates/ra_ide_db/src/search.rs6
-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.rs18
-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/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/type_params.rs2
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs50
-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.rs39
-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/Cargo.toml3
-rw-r--r--crates/ra_ssr/src/lib.rs226
-rw-r--r--crates/ra_ssr/src/matching.rs207
-rw-r--r--crates/ra_ssr/src/nester.rs98
-rw-r--r--crates/ra_ssr/src/parsing.rs142
-rw-r--r--crates/ra_ssr/src/replacing.rs200
-rw-r--r--crates/ra_ssr/src/resolving.rs228
-rw-r--r--crates/ra_ssr/src/search.rs273
-rw-r--r--crates/ra_ssr/src/tests.rs634
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/ast.rs18
-rw-r--r--crates/ra_syntax/src/ast/edit.rs39
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs13
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs3966
-rw-r--r--crates/ra_syntax/src/ast/make.rs16
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs103
-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.rs8
-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.rast2
-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.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0013_invalid_type.rast8
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/err/0019_let_recover.rast2
-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.rast2
-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.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/err/0025_nope.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/err/0026_imp_recovery.rast10
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0031_block_inner_attrs.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0032_match_arms_inner_attrs.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0033_match_arms_outer_attrs.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0034_bad_box_pattern.rast2
-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.rast2
-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.rast28
-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/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.rast2
-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.rast2
-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.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0004_value_parameters_no_patterns.rast2
-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.rast14
-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.rast2
-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.rast4
-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.rast8
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0024_slice_pat.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0027_ref_pat.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0028_impl_trait_type.rast2
-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.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0031_while_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0032_fn_pointer_type.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0033_reference_type;.rast6
-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.rast2
-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.rast2
-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.rast4
-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.rast4
-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.rast2
-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.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rast8
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0071_match_expr.rast6
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0075_block.rast8
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rast2
-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.rast2
-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.rast2
-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.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0096_no_semi_after_block.rast2
-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.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0100_for_expr.rast2
-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.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0106_lambda_expr.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0107_method_call_expr.rast2
-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.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0112_bind_pat.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0120_match_arms_inner_attribute.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0121_match_arms_outer_attributes.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0123_param_list_vararg.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_try_block_expr.rast2
-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.rast2
-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.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rast8
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0144_dot_dot_pat.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_impl_type_params.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rast12
-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.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0155_closure_params.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_fn_def_param.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_or_pattern.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rast2
-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.rast2
-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.rast2
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0029_range_forms.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_string_suffixes.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_traits.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0031_extern.rast24
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0032_where_for.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0033_label_break.rast2
-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.rast50
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0042_ufcs_call_list.rast12
-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.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0045_block_inner_attrs.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0047_minus_in_inner_pattern.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0048_compound_assignment.rast2
-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.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0051_parameter_attrs.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0054_qual_path_in_type_arg.rast6
-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.rast4
-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.rast2
-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.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_variadic_fun.rast6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0064_impl_fn_params.rast12
-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.rast38
-rw-r--r--crates/rust-analyzer/Cargo.toml6
-rw-r--r--crates/rust-analyzer/src/bin/args.rs33
-rw-r--r--crates/rust-analyzer/src/bin/main.rs32
-rw-r--r--crates/rust-analyzer/src/cli.rs11
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs135
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs465
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs2
-rw-r--r--crates/rust-analyzer/src/cli/ssr.rs49
-rw-r--r--crates/rust-analyzer/src/config.rs9
-rw-r--r--crates/rust-analyzer/src/document.rs16
-rw-r--r--crates/rust-analyzer/src/global_state.rs7
-rw-r--r--crates/rust-analyzer/src/handlers.rs37
-rw-r--r--crates/rust-analyzer/src/lib.rs3
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs8
-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/to_proto.rs20
-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
-rw-r--r--crates/vfs/src/file_set.rs71
-rw-r--r--docs/dev/README.md10
-rw-r--r--docs/dev/lsp-extensions.md7
-rw-r--r--docs/dev/syntax.md4
-rw-r--r--docs/user/manual.adoc2
-rw-r--r--editors/code/package.json23
-rw-r--r--editors/code/src/commands.ts15
-rw-r--r--editors/code/src/lsp_ext.ts3
-rw-r--r--xtask/Cargo.toml9
-rw-r--r--xtask/src/ast_src.rs2080
-rw-r--r--xtask/src/codegen/gen_syntax.rs296
-rw-r--r--xtask/src/codegen/rust.ungram544
-rw-r--r--xtask/src/dist.rs27
-rw-r--r--xtask/src/lib.rs1
-rw-r--r--xtask/src/main.rs13
-rw-r--r--xtask/src/metrics.rs279
-rw-r--r--xtask/src/not_bash.rs3
-rw-r--r--xtask/tests/tidy.rs1
459 files changed, 7551 insertions, 7804 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 20663196d..2acd44012 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -61,9 +61,6 @@ jobs:
61 override: true 61 override: true
62 components: rustfmt, rust-src 62 components: rustfmt, rust-src
63 63
64 - if: matrix.os == 'ubuntu-latest'
65 run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
66
67 - name: Cache cargo directories 64 - name: Cache cargo directories
68 uses: actions/cache@v2 65 uses: actions/cache@v2
69 with: 66 with:
@@ -108,8 +105,6 @@ jobs:
108 override: true 105 override: true
109 target: 'powerpc-unknown-linux-gnu' 106 target: 'powerpc-unknown-linux-gnu'
110 107
111 - run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
112
113 - name: Cache cargo directories 108 - name: Cache cargo directories
114 uses: actions/cache@v2 109 uses: actions/cache@v2
115 with: 110 with:
diff --git a/.github/workflows/metrics.yaml b/.github/workflows/metrics.yaml
new file mode 100644
index 000000000..ea780e875
--- /dev/null
+++ b/.github/workflows/metrics.yaml
@@ -0,0 +1,32 @@
1name: metrics
2on:
3 push:
4 branches:
5 - master
6
7env:
8 CARGO_INCREMENTAL: 0
9 CARGO_NET_RETRY: 10
10 RUSTFLAGS: -D warnings
11 RUSTUP_MAX_RETRIES: 10
12
13jobs:
14 metrics:
15 runs-on: ubuntu-latest
16
17 steps:
18 - name: Checkout repository
19 uses: actions/checkout@v2
20
21 - name: Install Rust toolchain
22 uses: actions-rs/toolchain@v1
23 with:
24 toolchain: stable
25 profile: minimal
26 override: true
27 components: rust-src
28
29 - name: Collect metrics
30 run: cargo xtask metrics
31 env:
32 METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
diff --git a/Cargo.lock b/Cargo.lock
index 0a35eb793..234c31406 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -35,9 +35,9 @@ dependencies = [
35 35
36[[package]] 36[[package]]
37name = "anyhow" 37name = "anyhow"
38version = "1.0.31" 38version = "1.0.32"
39source = "registry+https://github.com/rust-lang/crates.io-index" 39source = "registry+https://github.com/rust-lang/crates.io-index"
40checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" 40checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
41 41
42[[package]] 42[[package]]
43name = "anymap" 43name = "anymap"
@@ -102,13 +102,12 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
102 102
103[[package]] 103[[package]]
104name = "cargo_metadata" 104name = "cargo_metadata"
105version = "0.10.1" 105version = "0.11.1"
106source = "registry+https://github.com/rust-lang/crates.io-index" 106source = "registry+https://github.com/rust-lang/crates.io-index"
107checksum = "052dbdd9db69a339d5fa9ac87bfe2e1319f709119f0345988a597af82bb1011c" 107checksum = "89fec17b16f1ac67908af82e47d0a90a7afd0e1827b181cd77504323d3263d35"
108dependencies = [ 108dependencies = [
109 "semver", 109 "semver",
110 "serde", 110 "serde",
111 "serde_derive",
112 "serde_json", 111 "serde_json",
113] 112]
114 113
@@ -126,9 +125,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
126 125
127[[package]] 126[[package]]
128name = "chalk-derive" 127name = "chalk-derive"
129version = "0.18.0" 128version = "0.19.0"
130source = "registry+https://github.com/rust-lang/crates.io-index" 129source = "registry+https://github.com/rust-lang/crates.io-index"
131checksum = "eea3a22f0c30b2504ac4ab58934dac0d00b92a4d7788df32795cabca24c3f929" 130checksum = "654c611946ba2629c5028cb7708687af975faf2c29d731824cb294c873df4697"
132dependencies = [ 131dependencies = [
133 "proc-macro2", 132 "proc-macro2",
134 "quote", 133 "quote",
@@ -138,9 +137,9 @@ dependencies = [
138 137
139[[package]] 138[[package]]
140name = "chalk-ir" 139name = "chalk-ir"
141version = "0.18.0" 140version = "0.19.0"
142source = "registry+https://github.com/rust-lang/crates.io-index" 141source = "registry+https://github.com/rust-lang/crates.io-index"
143checksum = "fb617b643e145e3b151502799e91a9625dd5daf1cf05dc2cb821bc75ae0c9cbd" 142checksum = "0a5341fbc654ca886b73b804a36aebf0e621057ccc1a68e9815b5b39b3ac9ae8"
144dependencies = [ 143dependencies = [
145 "chalk-derive", 144 "chalk-derive",
146 "lazy_static", 145 "lazy_static",
@@ -148,9 +147,9 @@ dependencies = [
148 147
149[[package]] 148[[package]]
150name = "chalk-recursive" 149name = "chalk-recursive"
151version = "0.18.0" 150version = "0.19.0"
152source = "registry+https://github.com/rust-lang/crates.io-index" 151source = "registry+https://github.com/rust-lang/crates.io-index"
153checksum = "d280565c8eefbf9b2bc615df49c7dfd971faad37774bf65734e626fd23864bd6" 152checksum = "4484807b155b5a411e6135d330295f9ba5042e2920b8712c6574ca6ea91e9ee5"
154dependencies = [ 153dependencies = [
155 "chalk-derive", 154 "chalk-derive",
156 "chalk-ir", 155 "chalk-ir",
@@ -161,9 +160,9 @@ dependencies = [
161 160
162[[package]] 161[[package]]
163name = "chalk-solve" 162name = "chalk-solve"
164version = "0.18.0" 163version = "0.19.0"
165source = "registry+https://github.com/rust-lang/crates.io-index" 164source = "registry+https://github.com/rust-lang/crates.io-index"
166checksum = "be906fbca3f3077dce0e76d9864771d0f450c946af0d86b569fb9504148a065a" 165checksum = "281f82facd2538997fbe52132b1941ed213d266748215c31d15f62a8664429ad"
167dependencies = [ 166dependencies = [
168 "chalk-derive", 167 "chalk-derive",
169 "chalk-ir", 168 "chalk-ir",
@@ -319,9 +318,9 @@ dependencies = [
319 318
320[[package]] 319[[package]]
321name = "filetime" 320name = "filetime"
322version = "0.2.10" 321version = "0.2.11"
323source = "registry+https://github.com/rust-lang/crates.io-index" 322source = "registry+https://github.com/rust-lang/crates.io-index"
324checksum = "affc17579b132fc2461adf7c575cc6e8b134ebca52c51f5411388965227dc695" 323checksum = "e500da2fab70bdc43f8f0e0b350a227f31c72311c56aba48f01d5cd62bb0345b"
325dependencies = [ 324dependencies = [
326 "cfg-if", 325 "cfg-if",
327 "libc", 326 "libc",
@@ -401,17 +400,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
401checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 400checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
402 401
403[[package]] 402[[package]]
404name = "getrandom"
405version = "0.1.14"
406source = "registry+https://github.com/rust-lang/crates.io-index"
407checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
408dependencies = [
409 "cfg-if",
410 "libc",
411 "wasi",
412]
413
414[[package]]
415name = "gimli" 403name = "gimli"
416version = "0.22.0" 404version = "0.22.0"
417source = "registry+https://github.com/rust-lang/crates.io-index" 405source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -565,9 +553,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
565 553
566[[package]] 554[[package]]
567name = "libc" 555name = "libc"
568version = "0.2.73" 556version = "0.2.74"
569source = "registry+https://github.com/rust-lang/crates.io-index" 557source = "registry+https://github.com/rust-lang/crates.io-index"
570checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" 558checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
571 559
572[[package]] 560[[package]]
573name = "libloading" 561name = "libloading"
@@ -619,9 +607,9 @@ dependencies = [
619 607
620[[package]] 608[[package]]
621name = "lsp-types" 609name = "lsp-types"
622version = "0.78.0" 610version = "0.79.0"
623source = "registry+https://github.com/rust-lang/crates.io-index" 611source = "registry+https://github.com/rust-lang/crates.io-index"
624checksum = "d2e6cf68e3492cfa2035f0382c1da1b6ab045db0320feca505b86b4f13d66c27" 612checksum = "7f1f86677fdbe8df5f88b99131b1424e50aad27bbe3e5900d221bc414bd72e9b"
625dependencies = [ 613dependencies = [
626 "base64", 614 "base64",
627 "bitflags", 615 "bitflags",
@@ -811,6 +799,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
811checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" 799checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
812 800
813[[package]] 801[[package]]
802name = "oorandom"
803version = "11.1.2"
804source = "registry+https://github.com/rust-lang/crates.io-index"
805checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c"
806
807[[package]]
814name = "parking_lot" 808name = "parking_lot"
815version = "0.11.0" 809version = "0.11.0"
816source = "registry+https://github.com/rust-lang/crates.io-index" 810source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -847,6 +841,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
847checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 841checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
848 842
849[[package]] 843[[package]]
844name = "perf-event"
845version = "0.4.4"
846source = "registry+https://github.com/rust-lang/crates.io-index"
847checksum = "76c42ba5d85a2f4472b99f475fb60cf336d9b4c85b1ea8bb300fef2e3c7c8f89"
848dependencies = [
849 "libc",
850 "perf-event-open-sys",
851]
852
853[[package]]
854name = "perf-event-open-sys"
855version = "0.3.1"
856source = "registry+https://github.com/rust-lang/crates.io-index"
857checksum = "95db63e37862bc1b842135d2234ef9418f222cc660c6752f45e7cf9ddfb97f96"
858dependencies = [
859 "libc",
860]
861
862[[package]]
850name = "petgraph" 863name = "petgraph"
851version = "0.5.1" 864version = "0.5.1"
852source = "registry+https://github.com/rust-lang/crates.io-index" 865source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -869,12 +882,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
869checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" 882checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
870 883
871[[package]] 884[[package]]
872name = "ppv-lite86"
873version = "0.2.8"
874source = "registry+https://github.com/rust-lang/crates.io-index"
875checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
876
877[[package]]
878name = "proc-macro2" 885name = "proc-macro2"
879version = "1.0.19" 886version = "1.0.19"
880source = "registry+https://github.com/rust-lang/crates.io-index" 887source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1046,6 +1053,7 @@ dependencies = [
1046 "indexmap", 1053 "indexmap",
1047 "itertools", 1054 "itertools",
1048 "log", 1055 "log",
1056 "oorandom",
1049 "ra_assists", 1057 "ra_assists",
1050 "ra_cfg", 1058 "ra_cfg",
1051 "ra_db", 1059 "ra_db",
@@ -1056,7 +1064,6 @@ dependencies = [
1056 "ra_ssr", 1064 "ra_ssr",
1057 "ra_syntax", 1065 "ra_syntax",
1058 "ra_text_edit", 1066 "ra_text_edit",
1059 "rand",
1060 "rustc-hash", 1067 "rustc-hash",
1061 "stdx", 1068 "stdx",
1062 "test_utils", 1069 "test_utils",
@@ -1138,6 +1145,7 @@ dependencies = [
1138 "cfg-if", 1145 "cfg-if",
1139 "libc", 1146 "libc",
1140 "once_cell", 1147 "once_cell",
1148 "perf-event",
1141 "ra_arena", 1149 "ra_arena",
1142] 1150]
1143 1151
@@ -1164,6 +1172,7 @@ dependencies = [
1164name = "ra_ssr" 1172name = "ra_ssr"
1165version = "0.1.0" 1173version = "0.1.0"
1166dependencies = [ 1174dependencies = [
1175 "expect",
1167 "ra_db", 1176 "ra_db",
1168 "ra_hir", 1177 "ra_hir",
1169 "ra_ide_db", 1178 "ra_ide_db",
@@ -1217,57 +1226,6 @@ dependencies = [
1217] 1226]
1218 1227
1219[[package]] 1228[[package]]
1220name = "rand"
1221version = "0.7.3"
1222source = "registry+https://github.com/rust-lang/crates.io-index"
1223checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
1224dependencies = [
1225 "getrandom",
1226 "libc",
1227 "rand_chacha",
1228 "rand_core",
1229 "rand_hc",
1230 "rand_pcg",
1231]
1232
1233[[package]]
1234name = "rand_chacha"
1235version = "0.2.2"
1236source = "registry+https://github.com/rust-lang/crates.io-index"
1237checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
1238dependencies = [
1239 "ppv-lite86",
1240 "rand_core",
1241]
1242
1243[[package]]
1244name = "rand_core"
1245version = "0.5.1"
1246source = "registry+https://github.com/rust-lang/crates.io-index"
1247checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
1248dependencies = [
1249 "getrandom",
1250]
1251
1252[[package]]
1253name = "rand_hc"
1254version = "0.2.0"
1255source = "registry+https://github.com/rust-lang/crates.io-index"
1256checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1257dependencies = [
1258 "rand_core",
1259]
1260
1261[[package]]
1262name = "rand_pcg"
1263version = "0.2.1"
1264source = "registry+https://github.com/rust-lang/crates.io-index"
1265checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
1266dependencies = [
1267 "rand_core",
1268]
1269
1270[[package]]
1271name = "rayon" 1229name = "rayon"
1272version = "1.3.1" 1230version = "1.3.1"
1273source = "registry+https://github.com/rust-lang/crates.io-index" 1231source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1353,6 +1311,7 @@ dependencies = [
1353 "lsp-server", 1311 "lsp-server",
1354 "lsp-types", 1312 "lsp-types",
1355 "mimalloc", 1313 "mimalloc",
1314 "oorandom",
1356 "parking_lot", 1315 "parking_lot",
1357 "pico-args", 1316 "pico-args",
1358 "ra_cfg", 1317 "ra_cfg",
@@ -1371,7 +1330,6 @@ dependencies = [
1371 "ra_text_edit", 1330 "ra_text_edit",
1372 "ra_toolchain", 1331 "ra_toolchain",
1373 "ra_tt", 1332 "ra_tt",
1374 "rand",
1375 "rayon", 1333 "rayon",
1376 "rustc-hash", 1334 "rustc-hash",
1377 "serde", 1335 "serde",
@@ -1386,9 +1344,9 @@ dependencies = [
1386 1344
1387[[package]] 1345[[package]]
1388name = "rustc-ap-rustc_lexer" 1346name = "rustc-ap-rustc_lexer"
1389version = "669.0.0" 1347version = "671.0.0"
1390source = "registry+https://github.com/rust-lang/crates.io-index" 1348source = "registry+https://github.com/rust-lang/crates.io-index"
1391checksum = "456af5f09c006cf6c22c1a433ee0232c4bb74bdc6c647a010166a47c94ed2a63" 1349checksum = "22e1221f3bfa2943c942cf8da319ab2346887f8757778c29c7f1822cd27b521f"
1392dependencies = [ 1350dependencies = [
1393 "unicode-xid", 1351 "unicode-xid",
1394] 1352]
@@ -1413,16 +1371,16 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
1413 1371
1414[[package]] 1372[[package]]
1415name = "salsa" 1373name = "salsa"
1416version = "0.15.0" 1374version = "0.15.1"
1417source = "registry+https://github.com/rust-lang/crates.io-index" 1375source = "registry+https://github.com/rust-lang/crates.io-index"
1418checksum = "885b4b99dde959decc84e85dd943bd140b4aabd62db2f8206ef5270f77ec20b9" 1376checksum = "d4cdc109fcc9e9450c7ef47fb7474e99bffd51799da03ed0a6c7f0e2cb3848a6"
1419dependencies = [ 1377dependencies = [
1420 "crossbeam-utils", 1378 "crossbeam-utils",
1421 "indexmap", 1379 "indexmap",
1422 "lock_api", 1380 "lock_api",
1423 "log", 1381 "log",
1382 "oorandom",
1424 "parking_lot", 1383 "parking_lot",
1425 "rand",
1426 "rustc-hash", 1384 "rustc-hash",
1427 "salsa-macros", 1385 "salsa-macros",
1428 "smallvec", 1386 "smallvec",
@@ -1519,9 +1477,9 @@ dependencies = [
1519 1477
1520[[package]] 1478[[package]]
1521name = "serde_json" 1479name = "serde_json"
1522version = "1.0.56" 1480version = "1.0.57"
1523source = "registry+https://github.com/rust-lang/crates.io-index" 1481source = "registry+https://github.com/rust-lang/crates.io-index"
1524checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" 1482checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
1525dependencies = [ 1483dependencies = [
1526 "itoa", 1484 "itoa",
1527 "ryu", 1485 "ryu",
@@ -1575,9 +1533,9 @@ version = "0.1.0"
1575 1533
1576[[package]] 1534[[package]]
1577name = "syn" 1535name = "syn"
1578version = "1.0.35" 1536version = "1.0.36"
1579source = "registry+https://github.com/rust-lang/crates.io-index" 1537source = "registry+https://github.com/rust-lang/crates.io-index"
1580checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" 1538checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250"
1581dependencies = [ 1539dependencies = [
1582 "proc-macro2", 1540 "proc-macro2",
1583 "quote", 1541 "quote",
@@ -1716,9 +1674,9 @@ dependencies = [
1716 1674
1717[[package]] 1675[[package]]
1718name = "tracing-subscriber" 1676name = "tracing-subscriber"
1719version = "0.2.8" 1677version = "0.2.9"
1720source = "registry+https://github.com/rust-lang/crates.io-index" 1678source = "registry+https://github.com/rust-lang/crates.io-index"
1721checksum = "cafe899b943f5433c6cab468d75a17ea92948fe9fe60b00f41e13d5e0d4fd054" 1679checksum = "e4f5dd7095c2481b7b3cbed71c8de53085fb3542bc3c2b4c73cba43e8f11c7ba"
1722dependencies = [ 1680dependencies = [
1723 "ansi_term", 1681 "ansi_term",
1724 "chrono", 1682 "chrono",
@@ -1749,6 +1707,12 @@ dependencies = [
1749] 1707]
1750 1708
1751[[package]] 1709[[package]]
1710name = "ungrammar"
1711version = "0.1.0"
1712source = "registry+https://github.com/rust-lang/crates.io-index"
1713checksum = "0ee12e4891ab3acc2d95d5023022ace22020247bb8a8d1ece875a443f7dab37d"
1714
1715[[package]]
1752name = "unicode-bidi" 1716name = "unicode-bidi"
1753version = "0.3.4" 1717version = "0.3.4"
1754source = "registry+https://github.com/rust-lang/crates.io-index" 1718source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1825,12 +1789,6 @@ dependencies = [
1825] 1789]
1826 1790
1827[[package]] 1791[[package]]
1828name = "wasi"
1829version = "0.9.0+wasi-snapshot-preview1"
1830source = "registry+https://github.com/rust-lang/crates.io-index"
1831checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1832
1833[[package]]
1834name = "winapi" 1792name = "winapi"
1835version = "0.2.8" 1793version = "0.2.8"
1836source = "registry+https://github.com/rust-lang/crates.io-index" 1794source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1892,5 +1850,6 @@ dependencies = [
1892 "pico-args", 1850 "pico-args",
1893 "proc-macro2", 1851 "proc-macro2",
1894 "quote", 1852 "quote",
1853 "ungrammar",
1895 "walkdir", 1854 "walkdir",
1896] 1855]
diff --git a/README.md b/README.md
index 7ba705e73..16c980400 100644
--- a/README.md
+++ b/README.md
@@ -2,11 +2,8 @@
2 <img src="https://user-images.githubusercontent.com/1711539/72443316-5a79f280-37ae-11ea-858f-035209ece2dd.png" alt="rust-analyzer logo"> 2 <img src="https://user-images.githubusercontent.com/1711539/72443316-5a79f280-37ae-11ea-858f-035209ece2dd.png" alt="rust-analyzer logo">
3</p> 3</p>
4 4
5rust-analyzer is an **experimental** modular compiler frontend for the Rust 5rust-analyzer is an **experimental** modular compiler frontend for the Rust language.
6language. It is a part of a larger rls-2.0 effort to create excellent IDE 6It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust.
7support for Rust. If you want to get involved, check the rls-2.0 working group:
8
9https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0
10 7
11Work on rust-analyzer is sponsored by 8Work on rust-analyzer is sponsored by
12 9
@@ -25,8 +22,8 @@ If you want to **contribute** to rust-analyzer or are just curious about how
25things work under the hood, check the [./docs/dev](./docs/dev) folder. 22things work under the hood, check the [./docs/dev](./docs/dev) folder.
26 23
27If you want to **use** rust-analyzer's language server with your editor of 24If you want to **use** rust-analyzer's language server with your editor of
28choice, check [the manual](https://rust-analyzer.github.io/manual.html) folder. It also contains some tips & tricks to help 25choice, check [the manual](https://rust-analyzer.github.io/manual.html) folder.
29you be more productive when using rust-analyzer. 26It also contains some tips & tricks to help you be more productive when using rust-analyzer.
30 27
31## Communication 28## Communication
32 29
@@ -40,8 +37,9 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frls-2.2E0
40 37
41## Quick Links 38## Quick Links
42 39
43* API docs: https://rust-analyzer.github.io/rust-analyzer/ra_ide/
44* Website: https://rust-analyzer.github.io/ 40* Website: https://rust-analyzer.github.io/
41* Metrics: https://rust-analyzer.github.io/metrics/
42* API docs: https://rust-analyzer.github.io/rust-analyzer/ra_ide/
45 43
46## License 44## License
47 45
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/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 01adb834c..3265bd406 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();
@@ -80,17 +80,17 @@ impl<'a> SubstituteTypeParams<'a> {
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.target_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 type_arg_list = path_type.path()?.segment()?.type_arg_list()?;
90 let mut result = Vec::new(); 90 let mut result = Vec::new();
91 for type_arg in type_arg_list.type_args() { 91 for type_arg in type_arg_list.type_args() {
92 let type_arg: ast::TypeArg = type_arg; 92 let type_arg: ast::TypeArg = type_arg;
93 result.push(type_arg.type_ref()?); 93 result.push(type_arg.ty()?);
94 } 94 }
95 Some(result) 95 Some(result)
96 } 96 }
@@ -99,9 +99,9 @@ impl<'a> SubstituteTypeParams<'a> {
99 &self, 99 &self,
100 node: &ra_syntax::SyntaxNode, 100 node: &ra_syntax::SyntaxNode,
101 ) -> Option<ra_syntax::SyntaxNode> { 101 ) -> Option<ra_syntax::SyntaxNode> {
102 let type_ref = ast::TypeRef::cast(node.clone())?; 102 let type_ref = ast::Type::cast(node.clone())?;
103 let path = match &type_ref { 103 let path = match &type_ref {
104 ast::TypeRef::PathType(path_type) => path_type.path()?, 104 ast::Type::PathType(path_type) => path_type.path()?,
105 _ => return None, 105 _ => return None,
106 }; 106 };
107 // FIXME: use `hir::Path::from_src` instead. 107 // FIXME: use `hir::Path::from_src` instead.
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..e69f0a89b 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,11 +22,11 @@ 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::BindPat(bind_pat) => bind_pat,
31 _ => return None, 31 _ => return None,
32 }; 32 };
@@ -34,8 +34,8 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
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,7 +44,7 @@ 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::PlaceholderType::cast).is_none() {
50 return None; 50 return None;
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..167e162d8 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 {
@@ -240,7 +240,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
240 Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 240 Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
241 Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 241 Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
242 Expr::Label(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 242 Expr::Label(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
243 Expr::RecordLit(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 243 Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
244 Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 244 Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
245 Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 245 Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
246 Expr::AwaitExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), 246 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..3650289fd 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
@@ -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
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..b925a2884 100644
--- a/crates/ra_assists/src/handlers/extract_variable.rs
+++ b/crates/ra_assists/src/handlers/extract_variable.rs
@@ -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 };
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..56510861d 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,
@@ -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/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
index 967593031..4537c73a1 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::ReferenceType(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/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/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..120250e79 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,7 +56,7 @@ 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_FIELD_PAT, BIND_PAT],
61 _ => vec![], 61 _ => vec![],
62 } 62 }
@@ -65,7 +65,7 @@ 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::RecordFieldPat(field) => field.field_name().map(|it| it.to_string()),
70 _ => None, 70 _ => None,
71 } 71 }
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..53496ede1 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
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
index 02de902d6..bb16ebd4e 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,7 +109,7 @@ 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 = impl_def
114 .target_trait() 115 .target_trait()
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs
index 8c4f33e59..617afe2e9 100644
--- a/crates/ra_assists/src/utils/insert_use.rs
+++ b/crates/ra_assists/src/utils/insert_use.rs
@@ -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,7 @@ 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_map(|it| it.use_tree()) 381 .filter_map(|it| it.use_tree())
382 .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target)) 382 .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
383 .fold(None, |best, a| match best { 383 .fold(None, |best, a| match best {
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 859bdfb3b..36c0bdc9e 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 {
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs
index 11a0ecb8b..266b513dc 100644
--- a/crates/ra_hir/src/diagnostics.rs
+++ b/crates/ra_hir/src/diagnostics.rs
@@ -1,6 +1,8 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2pub use hir_def::diagnostics::UnresolvedModule; 2pub use hir_def::diagnostics::UnresolvedModule;
3pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; 3pub use hir_expand::diagnostics::{
4 AstDiagnostic, Diagnostic, DiagnosticSink, DiagnosticSinkBuilder,
5};
4pub use hir_ty::diagnostics::{ 6pub use hir_ty::diagnostics::{
5 MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField, 7 MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField,
6}; 8};
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs
index 76c32fc17..1c691d961 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 f5283ab22..6f3b3dc9a 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -89,6 +89,7 @@ pub struct Semantics<'db, DB> {
89pub struct SemanticsImpl<'db> { 89pub struct SemanticsImpl<'db> {
90 pub db: &'db dyn HirDatabase, 90 pub db: &'db dyn HirDatabase,
91 s2d_cache: RefCell<SourceToDefCache>, 91 s2d_cache: RefCell<SourceToDefCache>,
92 expansion_info_cache: RefCell<FxHashMap<HirFileId, Option<ExpansionInfo>>>,
92 cache: RefCell<FxHashMap<SyntaxNode, HirFileId>>, 93 cache: RefCell<FxHashMap<SyntaxNode, HirFileId>>,
93} 94}
94 95
@@ -208,7 +209,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
208 self.imp.resolve_field(field) 209 self.imp.resolve_field(field)
209 } 210 }
210 211
211 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>)> {
212 self.imp.resolve_record_field(field) 216 self.imp.resolve_record_field(field)
213 } 217 }
214 218
@@ -224,7 +228,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
224 self.imp.resolve_path(path) 228 self.imp.resolve_path(path)
225 } 229 }
226 230
227 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantDef> { 231 pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantDef> {
228 self.imp.resolve_variant(record_lit).map(VariantDef::from) 232 self.imp.resolve_variant(record_lit).map(VariantDef::from)
229 } 233 }
230 234
@@ -239,7 +243,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
239 // FIXME: use this instead? 243 // FIXME: use this instead?
240 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; 244 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
241 245
242 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)> {
243 self.imp.record_literal_missing_fields(literal) 247 self.imp.record_literal_missing_fields(literal)
244 } 248 }
245 249
@@ -275,7 +279,12 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
275 279
276impl<'db> SemanticsImpl<'db> { 280impl<'db> SemanticsImpl<'db> {
277 fn new(db: &'db dyn HirDatabase) -> Self { 281 fn new(db: &'db dyn HirDatabase) -> Self {
278 Self { db, s2d_cache: Default::default(), cache: Default::default() } 282 SemanticsImpl {
283 db,
284 s2d_cache: Default::default(),
285 cache: Default::default(),
286 expansion_info_cache: Default::default(),
287 }
279 } 288 }
280 289
281 fn parse(&self, file_id: FileId) -> ast::SourceFile { 290 fn parse(&self, file_id: FileId) -> ast::SourceFile {
@@ -315,18 +324,26 @@ impl<'db> SemanticsImpl<'db> {
315 } 324 }
316 325
317 fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken { 326 fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
327 let _p = profile("descend_into_macros");
318 let parent = token.parent(); 328 let parent = token.parent();
319 let parent = self.find_file(parent); 329 let parent = self.find_file(parent);
320 let sa = self.analyze2(parent.as_ref(), None); 330 let sa = self.analyze2(parent.as_ref(), None);
321 331
322 let token = successors(Some(parent.with_value(token)), |token| { 332 let token = successors(Some(parent.with_value(token)), |token| {
333 self.db.check_canceled();
323 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; 334 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
324 let tt = macro_call.token_tree()?; 335 let tt = macro_call.token_tree()?;
325 if !tt.syntax().text_range().contains_range(token.value.text_range()) { 336 if !tt.syntax().text_range().contains_range(token.value.text_range()) {
326 return None; 337 return None;
327 } 338 }
328 let file_id = sa.expand(self.db, token.with_value(&macro_call))?; 339 let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
329 let token = file_id.expansion_info(self.db.upcast())?.map_token_down(token.as_ref())?; 340 let token = self
341 .expansion_info_cache
342 .borrow_mut()
343 .entry(file_id)
344 .or_insert_with(|| file_id.expansion_info(self.db.upcast()))
345 .as_ref()?
346 .map_token_down(token.as_ref())?;
330 347
331 self.cache(find_root(&token.value.parent()), token.file_id); 348 self.cache(find_root(&token.value.parent()), token.file_id);
332 349
@@ -408,7 +425,7 @@ impl<'db> SemanticsImpl<'db> {
408 self.analyze(field.syntax()).resolve_field(self.db, field) 425 self.analyze(field.syntax()).resolve_field(self.db, field)
409 } 426 }
410 427
411 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>)> {
412 self.analyze(field.syntax()).resolve_record_field(self.db, field) 429 self.analyze(field.syntax()).resolve_record_field(self.db, field)
413 } 430 }
414 431
@@ -426,7 +443,7 @@ impl<'db> SemanticsImpl<'db> {
426 self.analyze(path.syntax()).resolve_path(self.db, path) 443 self.analyze(path.syntax()).resolve_path(self.db, path)
427 } 444 }
428 445
429 fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> { 446 fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {
430 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit) 447 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit)
431 } 448 }
432 449
@@ -439,7 +456,7 @@ impl<'db> SemanticsImpl<'db> {
439 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)
440 } 457 }
441 458
442 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)> {
443 self.analyze(literal.syntax()) 460 self.analyze(literal.syntax())
444 .record_literal_missing_fields(self.db, literal) 461 .record_literal_missing_fields(self.db, literal)
445 .unwrap_or_default() 462 .unwrap_or_default()
@@ -563,18 +580,18 @@ macro_rules! to_def_impls {
563 580
564to_def_impls![ 581to_def_impls![
565 (crate::Module, ast::Module, module_to_def), 582 (crate::Module, ast::Module, module_to_def),
566 (crate::Struct, ast::StructDef, struct_to_def), 583 (crate::Struct, ast::Struct, struct_to_def),
567 (crate::Enum, ast::EnumDef, enum_to_def), 584 (crate::Enum, ast::Enum, enum_to_def),
568 (crate::Union, ast::UnionDef, union_to_def), 585 (crate::Union, ast::Union, union_to_def),
569 (crate::Trait, ast::TraitDef, trait_to_def), 586 (crate::Trait, ast::Trait, trait_to_def),
570 (crate::ImplDef, ast::ImplDef, impl_to_def), 587 (crate::ImplDef, ast::Impl, impl_to_def),
571 (crate::TypeAlias, ast::TypeAliasDef, type_alias_to_def), 588 (crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
572 (crate::Const, ast::ConstDef, const_to_def), 589 (crate::Const, ast::Const, const_to_def),
573 (crate::Static, ast::StaticDef, static_to_def), 590 (crate::Static, ast::Static, static_to_def),
574 (crate::Function, ast::FnDef, fn_to_def), 591 (crate::Function, ast::Fn, fn_to_def),
575 (crate::Field, ast::RecordFieldDef, record_field_to_def), 592 (crate::Field, ast::RecordField, record_field_to_def),
576 (crate::Field, ast::TupleFieldDef, tuple_field_to_def), 593 (crate::Field, ast::TupleField, tuple_field_to_def),
577 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), 594 (crate::EnumVariant, ast::Variant, enum_variant_to_def),
578 (crate::TypeParam, ast::TypeParam, type_param_to_def), 595 (crate::TypeParam, ast::TypeParam, type_param_to_def),
579 (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
580 (crate::Local, ast::BindPat, bind_pat_to_def), 597 (crate::Local, ast::BindPat, bind_pat_to_def),
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 42e5a1bdb..d1994e2e7 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -65,53 +65,44 @@ 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,
@@ -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..f2e630ef1 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)?;
@@ -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..827ced4ad 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -11,7 +11,7 @@ use ra_arena::Arena;
11use ra_syntax::{ 11use ra_syntax::{
12 ast::{ 12 ast::{
13 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, 13 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner,
14 SlicePatComponents, TypeAscriptionOwner, 14 SlicePatComponents,
15 }, 15 },
16 AstNode, AstPtr, 16 AstNode, AstPtr,
17}; 17};
@@ -379,10 +379,10 @@ impl ExprCollector<'_> {
379 let expr = e.expr().map(|e| self.collect_expr(e)); 379 let expr = e.expr().map(|e| self.collect_expr(e));
380 self.alloc_expr(Expr::Return { expr }, syntax_ptr) 380 self.alloc_expr(Expr::Return { expr }, syntax_ptr)
381 } 381 }
382 ast::Expr::RecordLit(e) => { 382 ast::Expr::RecordExpr(e) => {
383 let path = e.path().and_then(|path| self.expander.parse_path(path)); 383 let path = e.path().and_then(|path| self.expander.parse_path(path));
384 let mut field_ptrs = Vec::new(); 384 let mut field_ptrs = Vec::new();
385 let record_lit = if let Some(nfl) = e.record_field_list() { 385 let record_lit = if let Some(nfl) = e.record_expr_field_list() {
386 let fields = nfl 386 let fields = nfl
387 .fields() 387 .fields()
388 .inspect(|field| field_ptrs.push(AstPtr::new(field))) 388 .inspect(|field| field_ptrs.push(AstPtr::new(field)))
@@ -432,7 +432,7 @@ impl ExprCollector<'_> {
432 } 432 }
433 ast::Expr::CastExpr(e) => { 433 ast::Expr::CastExpr(e) => {
434 let expr = self.collect_expr_opt(e.expr()); 434 let expr = self.collect_expr_opt(e.expr());
435 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref()); 435 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
436 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) 436 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
437 } 437 }
438 ast::Expr::RefExpr(e) => { 438 ast::Expr::RefExpr(e) => {
@@ -466,16 +466,13 @@ impl ExprCollector<'_> {
466 if let Some(pl) = e.param_list() { 466 if let Some(pl) = e.param_list() {
467 for param in pl.params() { 467 for param in pl.params() {
468 let pat = self.collect_pat_opt(param.pat()); 468 let pat = self.collect_pat_opt(param.pat());
469 let type_ref = 469 let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
470 param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
471 args.push(pat); 470 args.push(pat);
472 arg_types.push(type_ref); 471 arg_types.push(type_ref);
473 } 472 }
474 } 473 }
475 let ret_type = e 474 let ret_type =
476 .ret_type() 475 e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&self.ctx(), it));
477 .and_then(|r| r.type_ref())
478 .map(|it| TypeRef::from_ast(&self.ctx(), it));
479 let body = self.collect_expr_opt(e.body()); 476 let body = self.collect_expr_opt(e.body());
480 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) 477 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
481 } 478 }
@@ -607,8 +604,7 @@ impl ExprCollector<'_> {
607 .map(|s| match s { 604 .map(|s| match s {
608 ast::Stmt::LetStmt(stmt) => { 605 ast::Stmt::LetStmt(stmt) => {
609 let pat = self.collect_pat_opt(stmt.pat()); 606 let pat = self.collect_pat_opt(stmt.pat());
610 let type_ref = 607 let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
611 stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
612 let initializer = stmt.initializer().map(|e| self.collect_expr(e)); 608 let initializer = stmt.initializer().map(|e| self.collect_expr(e));
613 Statement::Let { pat, type_ref, initializer } 609 Statement::Let { pat, type_ref, initializer }
614 } 610 }
@@ -627,53 +623,53 @@ impl ExprCollector<'_> {
627 .items() 623 .items()
628 .filter_map(|item| { 624 .filter_map(|item| {
629 let (def, name): (ModuleDefId, Option<ast::Name>) = match item { 625 let (def, name): (ModuleDefId, Option<ast::Name>) = match item {
630 ast::ModuleItem::FnDef(def) => { 626 ast::Item::Fn(def) => {
631 let id = self.find_inner_item(&def)?; 627 let id = self.find_inner_item(&def)?;
632 ( 628 (
633 FunctionLoc { container: container.into(), id }.intern(self.db).into(), 629 FunctionLoc { container: container.into(), id }.intern(self.db).into(),
634 def.name(), 630 def.name(),
635 ) 631 )
636 } 632 }
637 ast::ModuleItem::TypeAliasDef(def) => { 633 ast::Item::TypeAlias(def) => {
638 let id = self.find_inner_item(&def)?; 634 let id = self.find_inner_item(&def)?;
639 ( 635 (
640 TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), 636 TypeAliasLoc { container: container.into(), id }.intern(self.db).into(),
641 def.name(), 637 def.name(),
642 ) 638 )
643 } 639 }
644 ast::ModuleItem::ConstDef(def) => { 640 ast::Item::Const(def) => {
645 let id = self.find_inner_item(&def)?; 641 let id = self.find_inner_item(&def)?;
646 ( 642 (
647 ConstLoc { container: container.into(), id }.intern(self.db).into(), 643 ConstLoc { container: container.into(), id }.intern(self.db).into(),
648 def.name(), 644 def.name(),
649 ) 645 )
650 } 646 }
651 ast::ModuleItem::StaticDef(def) => { 647 ast::Item::Static(def) => {
652 let id = self.find_inner_item(&def)?; 648 let id = self.find_inner_item(&def)?;
653 (StaticLoc { container, id }.intern(self.db).into(), def.name()) 649 (StaticLoc { container, id }.intern(self.db).into(), def.name())
654 } 650 }
655 ast::ModuleItem::StructDef(def) => { 651 ast::Item::Struct(def) => {
656 let id = self.find_inner_item(&def)?; 652 let id = self.find_inner_item(&def)?;
657 (StructLoc { container, id }.intern(self.db).into(), def.name()) 653 (StructLoc { container, id }.intern(self.db).into(), def.name())
658 } 654 }
659 ast::ModuleItem::EnumDef(def) => { 655 ast::Item::Enum(def) => {
660 let id = self.find_inner_item(&def)?; 656 let id = self.find_inner_item(&def)?;
661 (EnumLoc { container, id }.intern(self.db).into(), def.name()) 657 (EnumLoc { container, id }.intern(self.db).into(), def.name())
662 } 658 }
663 ast::ModuleItem::UnionDef(def) => { 659 ast::Item::Union(def) => {
664 let id = self.find_inner_item(&def)?; 660 let id = self.find_inner_item(&def)?;
665 (UnionLoc { container, id }.intern(self.db).into(), def.name()) 661 (UnionLoc { container, id }.intern(self.db).into(), def.name())
666 } 662 }
667 ast::ModuleItem::TraitDef(def) => { 663 ast::Item::Trait(def) => {
668 let id = self.find_inner_item(&def)?; 664 let id = self.find_inner_item(&def)?;
669 (TraitLoc { container, id }.intern(self.db).into(), def.name()) 665 (TraitLoc { container, id }.intern(self.db).into(), def.name())
670 } 666 }
671 ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks 667 ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672 ast::ModuleItem::ImplDef(_) 668 ast::Item::Impl(_)
673 | ast::ModuleItem::UseItem(_) 669 | ast::Item::Use(_)
674 | ast::ModuleItem::ExternCrateItem(_) 670 | ast::Item::ExternCrate(_)
675 | ast::ModuleItem::Module(_) 671 | ast::Item::Module(_)
676 | ast::ModuleItem::MacroCall(_) => return None, 672 | ast::Item::MacroCall(_) => return None,
677 }; 673 };
678 674
679 Some((def, name)) 675 Some((def, name))
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index a885ec96d..dcb00a1d9 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -162,7 +162,7 @@ impl ChildBySource for EnumId {
162 let arena_map = arena_map.as_ref(); 162 let arena_map = arena_map.as_ref();
163 for (local_id, source) in arena_map.value.iter() { 163 for (local_id, source) in arena_map.value.iter() {
164 let id = EnumVariantId { parent: *self, local_id }; 164 let id = EnumVariantId { parent: *self, local_id };
165 res[keys::ENUM_VARIANT].insert(arena_map.with_value(source.clone()), id) 165 res[keys::VARIANT].insert(arena_map.with_value(source.clone()), id)
166 } 166 }
167 167
168 res 168 res
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 6a0f493a7..be0b45af3 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -12,7 +12,7 @@ use hir_expand::{
12use ra_arena::{map::ArenaMap, Arena}; 12use ra_arena::{map::ArenaMap, Arena};
13use ra_db::FileId; 13use ra_db::FileId;
14use ra_prof::profile; 14use ra_prof::profile;
15use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 15use ra_syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner};
16 16
17use crate::{ 17use crate::{
18 body::LowerCtx, 18 body::LowerCtx,
@@ -66,7 +66,7 @@ pub enum WherePredicateTarget {
66 TypeParam(LocalTypeParamId), 66 TypeParam(LocalTypeParamId),
67} 67}
68 68
69type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>; 69type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>;
70 70
71impl GenericParams { 71impl GenericParams {
72 pub(crate) fn generic_params_query( 72 pub(crate) fn generic_params_query(
@@ -205,9 +205,9 @@ impl GenericParams {
205 &mut self, 205 &mut self,
206 lower_ctx: &LowerCtx, 206 lower_ctx: &LowerCtx,
207 sm: &mut SourceMap, 207 sm: &mut SourceMap,
208 node: &dyn TypeParamsOwner, 208 node: &dyn GenericParamsOwner,
209 ) { 209 ) {
210 if let Some(params) = node.type_param_list() { 210 if let Some(params) = node.generic_param_list() {
211 self.fill_params(lower_ctx, sm, params) 211 self.fill_params(lower_ctx, sm, params)
212 } 212 }
213 if let Some(where_clause) = node.where_clause() { 213 if let Some(where_clause) = node.where_clause() {
@@ -232,7 +232,7 @@ impl GenericParams {
232 &mut self, 232 &mut self,
233 lower_ctx: &LowerCtx, 233 lower_ctx: &LowerCtx,
234 sm: &mut SourceMap, 234 sm: &mut SourceMap,
235 params: ast::TypeParamList, 235 params: ast::GenericParamList,
236 ) { 236 ) {
237 for type_param in params.type_params() { 237 for type_param in params.type_params() {
238 let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); 238 let name = type_param.name().map_or_else(Name::missing, |it| it.as_name());
@@ -253,7 +253,7 @@ impl GenericParams {
253 253
254 fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) { 254 fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) {
255 for pred in where_clause.predicates() { 255 for pred in where_clause.predicates() {
256 let type_ref = match pred.type_ref() { 256 let type_ref = match pred.ty() {
257 Some(type_ref) => type_ref, 257 Some(type_ref) => type_ref,
258 None => continue, 258 None => continue,
259 }; 259 };
@@ -317,7 +317,7 @@ impl GenericParams {
317 317
318impl HasChildSource for GenericDefId { 318impl HasChildSource for GenericDefId {
319 type ChildId = LocalTypeParamId; 319 type ChildId = LocalTypeParamId;
320 type Value = Either<ast::TraitDef, ast::TypeParam>; 320 type Value = Either<ast::Trait, ast::TypeParam>;
321 fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> { 321 fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> {
322 let (_, sm) = GenericParams::new(db, *self); 322 let (_, sm) = GenericParams::new(db, *self);
323 sm 323 sm
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs
index da79d8ffd..a67e75dac 100644
--- a/crates/ra_hir_def/src/item_tree.rs
+++ b/crates/ra_hir_def/src/item_tree.rs
@@ -13,7 +13,7 @@ use std::{
13 sync::Arc, 13 sync::Arc,
14}; 14};
15 15
16use ast::{AstNode, AttrsOwner, NameOwner, StructKind, TypeAscriptionOwner}; 16use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
17use either::Either;