aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs16
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs10
-rw-r--r--crates/ra_assists/src/handlers/add_derive.rs8
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_from_impl_for_enum.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_function.rs242
-rw-r--r--crates/ra_assists/src/handlers/add_impl.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_new.rs8
-rw-r--r--crates/ra_assists/src/handlers/apply_demorgan.rs2
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs4
-rw-r--r--crates/ra_assists/src/handlers/flip_binexpr.rs2
-rw-r--r--crates/ra_assists/src/handlers/inline_local_variable.rs2
-rw-r--r--crates/ra_assists/src/handlers/introduce_variable.rs6
-rw-r--r--crates/ra_assists/src/handlers/invert_if.rs2
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs10
-rw-r--r--crates/ra_assists/src/handlers/move_guard.rs10
-rw-r--r--crates/ra_assists/src/handlers/raw_string.rs4
-rw-r--r--crates/ra_assists/src/handlers/remove_dbg.rs8
-rw-r--r--crates/ra_assists/src/handlers/remove_mut.rs2
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs2
-rw-r--r--crates/ra_assists/src/lib.rs34
-rw-r--r--crates/ra_db/src/lib.rs4
-rw-r--r--crates/ra_hir/src/code_model.rs34
-rw-r--r--crates/ra_hir/src/from_id.rs22
-rw-r--r--crates/ra_hir/src/has_source.rs6
-rw-r--r--crates/ra_hir/src/lib.rs4
-rw-r--r--crates/ra_hir/src/semantics.rs45
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs8
-rw-r--r--crates/ra_hir/src/source_analyzer.rs40
-rw-r--r--crates/ra_hir_def/src/adt.rs22
-rw-r--r--crates/ra_hir_def/src/attr.rs25
-rw-r--r--crates/ra_hir_def/src/body/scope.rs2
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs6
-rw-r--r--crates/ra_hir_def/src/docs.rs2
-rw-r--r--crates/ra_hir_def/src/find_path.rs78
-rw-r--r--crates/ra_hir_def/src/keys.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs10
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs6
-rw-r--r--crates/ra_hir_expand/src/lib.rs4
-rw-r--r--crates/ra_hir_ty/src/db.rs4
-rw-r--r--crates/ra_hir_ty/src/expr.rs14
-rw-r--r--crates/ra_hir_ty/src/infer.rs16
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs8
-rw-r--r--crates/ra_hir_ty/src/infer/pat.rs4
-rw-r--r--crates/ra_hir_ty/src/lower.rs6
-rw-r--r--crates/ra_hir_ty/src/tests.rs4
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs582
-rw-r--r--crates/ra_hir_ty/src/tests/macros.rs202
-rw-r--r--crates/ra_hir_ty/src/tests/method_resolution.rs376
-rw-r--r--crates/ra_hir_ty/src/tests/patterns.rs480
-rw-r--r--crates/ra_hir_ty/src/tests/regression.rs278
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs1360
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs1106
-rw-r--r--crates/ra_ide/src/assists.rs4
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs36
-rw-r--r--crates/ra_ide/src/call_info.rs2
-rw-r--r--crates/ra_ide/src/completion.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_attribute.rs587
-rw-r--r--crates/ra_ide/src/completion/complete_dot.rs112
-rw-r--r--crates/ra_ide/src/completion/complete_fn_param.rs12
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs254
-rw-r--r--crates/ra_ide/src/completion/complete_macro_in_item_position.rs22
-rw-r--r--crates/ra_ide/src/completion/complete_pattern.rs30
-rw-r--r--crates/ra_ide/src/completion/complete_postfix.rs134
-rw-r--r--crates/ra_ide/src/completion/complete_qualified_path.rs198
-rw-r--r--crates/ra_ide/src/completion/complete_record.rs60
-rw-r--r--crates/ra_ide/src/completion/complete_snippet.rs20
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs53
-rw-r--r--crates/ra_ide/src/completion/complete_unqualified_path.rs379
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs16
-rw-r--r--crates/ra_ide/src/completion/completion_item.rs2
-rw-r--r--crates/ra_ide/src/completion/presentation.rs286
-rw-r--r--crates/ra_ide/src/diagnostics.rs10
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs4
-rw-r--r--crates/ra_ide/src/display/structure.rs76
-rw-r--r--crates/ra_ide/src/extend_selection.rs44
-rw-r--r--crates/ra_ide/src/folding_ranges.rs7
-rw-r--r--crates/ra_ide/src/goto_definition.rs90
-rw-r--r--crates/ra_ide/src/goto_type_definition.rs10
-rw-r--r--crates/ra_ide/src/hover.rs6
-rw-r--r--crates/ra_ide/src/impls.rs20
-rw-r--r--crates/ra_ide/src/inlay_hints.rs166
-rw-r--r--crates/ra_ide/src/join_lines.rs40
-rw-r--r--crates/ra_ide/src/lib.rs4
-rw-r--r--crates/ra_ide/src/matching_brace.rs4
-rw-r--r--crates/ra_ide/src/parent_module.rs6
-rw-r--r--crates/ra_ide/src/prime_caches.rs5
-rw-r--r--crates/ra_ide/src/references.rs92
-rw-r--r--crates/ra_ide/src/references/rename.rs25
-rw-r--r--crates/ra_ide/src/runnables.rs18
-rw-r--r--crates/ra_ide/src/snapshots/highlight_strings.html82
-rw-r--r--crates/ra_ide/src/source_change.rs4
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs230
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs14
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs72
-rw-r--r--crates/ra_ide/src/syntax_tree.rs277
-rw-r--r--crates/ra_ide/src/test_utils.rs4
-rw-r--r--crates/ra_ide/src/typing.rs25
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs6
-rw-r--r--crates/ra_ide_db/src/defs.rs22
-rw-r--r--crates/ra_ide_db/src/line_index.rs66
-rw-r--r--crates/ra_ide_db/src/line_index_utils.rs51
-rw-r--r--crates/ra_ide_db/src/search.rs22
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs69
-rw-r--r--crates/ra_mbe/src/tests.rs421
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs5
-rw-r--r--crates/ra_project_model/src/lib.rs12
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/algo.rs12
-rw-r--r--crates/ra_syntax/src/ast/make.rs11
-rw-r--r--crates/ra_syntax/src/ast/tokens.rs372
-rw-r--r--crates/ra_syntax/src/fuzz.rs15
-rw-r--r--crates/ra_syntax/src/lib.rs4
-rw-r--r--crates/ra_syntax/src/parsing/lexer.rs32
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs4
-rw-r--r--crates/ra_syntax/src/parsing/text_token_source.rs8
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs14
-rw-r--r--crates/ra_syntax/src/ptr.rs2
-rw-r--r--crates/ra_syntax/src/syntax_error.rs6
-rw-r--r--crates/ra_syntax/src/syntax_node.rs4
-rw-r--r--crates/ra_syntax/src/tests.rs8
-rw-r--r--crates/ra_syntax/src/validation.rs6
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0001_unclosed_char_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0002_unclosed_char_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0003_unclosed_char_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0004_unclosed_char_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0005_unclosed_char_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0006_unclosed_char_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0007_unclosed_char_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0008_unclosed_char_with_slash_single_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0009_unclosed_byte_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0010_unclosed_byte_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0011_unclosed_byte_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0012_unclosed_byte_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0013_unclosed_byte_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0014_unclosed_byte_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0015_unclosed_byte_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0016_unclosed_byte_with_slash_single_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0017_unclosed_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0018_unclosed_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0019_unclosed_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0020_unclosed_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0021_unclosed_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0022_unclosed_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0023_unclosed_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0024_unclosed_string_with_slash_double_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0025_unclosed_byte_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0026_unclosed_byte_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0027_unclosed_byte_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0028_unclosed_byte_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0029_unclosed_byte_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0030_unclosed_byte_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0031_unclosed_byte_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0032_unclosed_byte_string_with_slash_double_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0033_unclosed_raw_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0034_unclosed_raw_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0035_unclosed_raw_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0036_unclosed_raw_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0037_unclosed_raw_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0038_unclosed_raw_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0039_unclosed_raw_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0040_unclosed_raw_byte_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0041_unclosed_raw_byte_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0042_unclosed_raw_byte_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0043_unclosed_raw_byte_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0044_unclosed_raw_byte_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0045_unclosed_raw_byte_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0046_unclosed_raw_byte_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0047_unstarted_raw_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0048_unstarted_raw_byte_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0049_unstarted_raw_string_with_ascii.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0050_unstarted_raw_byte_string_with_ascii.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0051_unclosed_block_comment_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0052_unclosed_block_comment_with_content.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0053_unclosed_nested_block_comment_entirely.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0054_unclosed_nested_block_comment_partially.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0055_empty_int.txt26
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0056_empty_exponent.txt28
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0057_lifetime_strarts_with_a_number.txt4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0000_struct_field_missing_comma.rast68
-rw-r--r--crates/ra_syntax/test_data/parser/err/0001_item_recovery_in_file.rast36
-rw-r--r--crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/err/0003_C++_semicolon.rast76
-rw-r--r--crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast120
-rw-r--r--crates/ra_syntax/test_data/parser/err/0006_named_field_recovery.rast148
-rw-r--r--crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast66
-rw-r--r--crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast162
-rw-r--r--crates/ra_syntax/test_data/parser/err/0009_broken_struct_type_parameter.rast116
-rw-r--r--crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/err/0011_extern_struct.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/err/0012_broken_lambda.rast636
-rw-r--r--crates/ra_syntax/test_data/parser/err/0013_invalid_type.rast178
-rw-r--r--crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/err/0015_curly_in_params.rast48
-rw-r--r--crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast88
-rw-r--r--crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast94
-rw-r--r--crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast264
-rw-r--r--crates/ra_syntax/test_data/parser/err/0019_let_recover.rast214
-rw-r--r--crates/ra_syntax/test_data/parser/err/0020_fn_recover.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/err/0021_incomplete_param.rast70
-rw-r--r--crates/ra_syntax/test_data/parser/err/0022_bad_exprs.rast366
-rw-r--r--crates/ra_syntax/test_data/parser/err/0023_mismatched_paren.rast88
-rw-r--r--crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast642
-rw-r--r--crates/ra_syntax/test_data/parser/err/0025_nope.rast408
-rw-r--r--crates/ra_syntax/test_data/parser/err/0026_imp_recovery.rast98
-rw-r--r--crates/ra_syntax/test_data/parser/err/0027_incomplere_where_for.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/err/0029_field_completion.rast72
-rw-r--r--crates/ra_syntax/test_data/parser/err/0031_block_inner_attrs.rast250
-rw-r--r--crates/ra_syntax/test_data/parser/err/0032_match_arms_inner_attrs.rast408
-rw-r--r--crates/ra_syntax/test_data/parser/err/0033_match_arms_outer_attrs.rast134
-rw-r--r--crates/ra_syntax/test_data/parser/err/0034_bad_box_pattern.rast192
-rw-r--r--crates/ra_syntax/test_data/parser/err/0035_use_recover.rast108
-rw-r--r--crates/ra_syntax/test_data/parser/err/0036_partial_use.rast102
-rw-r--r--crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast198
-rw-r--r--crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/err/0039_lambda_recovery.rast166
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0001_array_type_missing_semi.rast54
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0002_misplaced_label_err.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0003_pointer_type_no_mutability.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0004_impl_type.rast158
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0005_fn_pointer_type_missing_fn.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0006_unsafe_block_in_mod.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0007_async_without_semicolon.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0008_pub_expr.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rast122
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_bad_tuple_index_expr.rast106
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast82
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast118
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_record_literal_before_ellipsis_recovery.rast98
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast144
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast270
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0003_where_pred_for.rast124
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0004_value_parameters_no_patterns.rast120
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0005_function_type_params.rast76
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0006_self_param.rast242
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0007_type_param_bounds.rast80
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0008_path_part.rast194
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0009_loop_expr.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0010_extern_block.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0011_field_expr.rast120
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0012_type_item_where_clause.rast66
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0013_pointer_type_mut.rast70
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0014_never_type.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0015_continue_expr.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0017_array_type.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0018_arb_self_types.rast148
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0020_use_star.rast118
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast160
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0022_crate_visibility.rast106
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0023_placeholder_type.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0024_slice_pat.rast84
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0025_slice_type.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0026_tuple_pat_fields.rast210
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0027_ref_pat.rast100
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0028_impl_trait_type.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0029_cast_expr.rast180
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0030_cond.rast418
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0031_while_expr.rast178
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0032_fn_pointer_type.rast196
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0033_reference_type;.rast100
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0034_break_expr.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0037_qual_paths.rast158
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0038_full_range_expr.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0040_crate_keyword_vis.rast126
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0041_trait_item.rast250
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0042_call_expr.rast296
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0043_use_alias.rast276
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0044_block_items.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0045_param_list_opt_patterns.rast94
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0046_singleton_tuple_type.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast36
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0048_path_type_with_bounds.rast166
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0050_fn_decl.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0051_unit_type.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0052_path_type.rast140
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0053_path_expr.rast192
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast88
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0055_literal_pattern.rast154
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0056_where_clause.rast222
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0058_range_pat.rast166
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0059_match_arms_commas.rast120
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0060_extern_crate.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_record_lit.rast250
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0062_mod_contents.rast134
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0064_if_expr.rast264
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0065_dyn_trait_type.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rast304
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0067_crate_path.rast30
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast92
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0070_stmt_bin_expr_ambiguity.rast106
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0071_match_expr.rast192
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0072_return_expr.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0073_type_item_type_params.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0074_stmt_postfix_expr_ambiguity.rast126
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0075_block.rast180
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0076_function_where_clause.rast80
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0077_try_expr.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0078_type_item.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0079_impl_def.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0080_postfix_range.rast192
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rast486
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0083_struct_items.rast174
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0084_paren_type.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0085_expr_literals.rast272
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0086_function_ret_type.rast72
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0088_break_ambiguity.rast138
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast36
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0090_type_param_default.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0092_fn_pointer_type_with_ret.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0093_index_expr.rast68
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast30
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0095_placeholder_pat.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0096_no_semi_after_block.rast260
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0099_param_list.rast206
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0100_for_expr.rast72
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0102_record_field_pat_list.rast266
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0103_array_expr.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0104_path_fn_trait_args.rast82
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0105_block_expr.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0106_lambda_expr.rast280
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0107_method_call_expr.rast126
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0108_tuple_expr.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0109_label.rast136
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0110_use_path.rast76
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0111_tuple_pat.rast180
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0112_bind_pat.rast256
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0113_nocontentexpr.rast114
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast128
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast82
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0117_macro_call_type.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast80
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_match_guard.rast96
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0120_match_arms_inner_attribute.rast162
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0121_match_arms_outer_attributes.rast292
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast132
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0123_param_list_vararg.rast100
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_crate_keyword_path.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_record_literal_field_with_attr.rast96
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0126_attr_on_expr_stmt.rast198
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0127_attr_on_last_expr_in_block.rast118
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_let_stmt.rast258
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_try_block_expr.rast66
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0131_existential_type.rast62
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_box_expr.rast180
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast112
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0134_nocontentexpr_after_item.rast128
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0137_await_expr.rast140
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_associated_type_bounds.rast112
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rast132
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0139_param_outer_arg.rast70
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rast84
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rast222
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0144_dot_dot_pat.rast912
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rast152
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_macro_def.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0148_pub_macro_def.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast94
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_impl_type_params.rast76
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rast256
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_arg_with_attr.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0154_fn_pointer_param_ident_path.rast116
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0155_closure_params.rast140
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_fn_def_param.rast88
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_or_pattern.rast224
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rast76
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_lambda_ret_block.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0000_empty.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0001_struct_item.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0002_struct_item_field.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0004_file_shebang.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0005_fn_item.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0006_inner_attributes.rast368
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0007_extern_crate.rast80
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0008_mod_item.rast186
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0009_use_item.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0010_use_path_segments.rast84
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0011_outer_attribute.rast116
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0012_visibility.rast214
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0013_use_path_self_super.rast114
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0014_use_tree.rast190
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0015_use_tree.rast130
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0016_struct_flavors.rast186
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0017_attr_trailing_comma.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0018_struct_type_params.rast514
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0019_enums.rast310
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0020_type_param_bounds.rast536
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast118
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0022_empty_extern_block.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0023_static_items.rast82
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0024_const_item.rast118
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0025_extern_fn_in_block.rast66
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0026_const_fn_in_block.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0027_unsafe_fn_in_block.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0028_operator_binding_power.rast372
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0029_range_forms.rast304
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_string_suffixes.rast128
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_traits.rast122
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0031_extern.rast1946
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0032_where_for.rast182
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0033_label_break.rast440
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0034_crate_path_in_call.rast84
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast4658
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0036_fully_qualified.rast186
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0037_mod.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0038_where_pred_type.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0039_raw_fn_item.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0040_raw_struct_item_field.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0041_raw_keywords.rast100
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0042_ufcs_call_list.rast252
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0043_complex_assignment.rast220
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0044_let_attrs.rast152
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0045_block_inner_attrs.rast362
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0046_extern_inner_attributes.rast56
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0047_minus_in_inner_pattern.rast646
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0048_compound_assignment.rast402
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0049_async_block.rast72
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0050_async_block_as_argument.rast184
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0051_parameter_attrs.rast1038
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rast162
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0053_outer_attribute_on_macro_rules.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0054_qual_path_in_type_arg.rast252
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0055_dot_dot_dot.rast100
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0056_neq_in_type.rast132
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0057_loop_in_call.rast118
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.rast194
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0059_loops_in_parens.rast202
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0060_as_range.rast112
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rast54
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0062_macro_2.0.rast352
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.rast396
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_variadic_fun.rast266
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0064_impl_fn_params.rast332
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_plus_after_fn_trait_bound.rast122
-rw-r--r--crates/ra_text_edit/Cargo.toml3
-rw-r--r--crates/ra_text_edit/src/lib.rs10
-rw-r--r--crates/ra_text_edit/src/text_edit.rs25
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs2
-rw-r--r--crates/rust-analyzer/src/conv.rs19
-rw-r--r--crates/rust-analyzer/src/main_loop.rs18
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs22
-rw-r--r--crates/rust-analyzer/src/req.rs3
-rw-r--r--crates/test_utils/Cargo.toml2
-rw-r--r--crates/test_utils/src/lib.rs26
468 files changed, 28664 insertions, 27092 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index c3e653299..2fe7c3de3 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -5,12 +5,12 @@ use ra_fmt::{leading_indent, reindent};
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_syntax::{ 6use ra_syntax::{
7 algo::{self, find_covering_element, find_node_at_offset}, 7 algo::{self, find_covering_element, find_node_at_offset},
8 AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit, 8 AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
9 TokenAtOffset, 9 TokenAtOffset,
10}; 10};
11use ra_text_edit::TextEditBuilder; 11use ra_text_edit::TextEditBuilder;
12 12
13use crate::{AssistAction, AssistId, AssistLabel, GroupLabel, ResolvedAssist}; 13use crate::{AssistAction, AssistFile, AssistId, AssistLabel, GroupLabel, ResolvedAssist};
14use algo::SyntaxRewriter; 14use algo::SyntaxRewriter;
15 15
16#[derive(Clone, Debug)] 16#[derive(Clone, Debug)]
@@ -178,8 +178,9 @@ impl<'a> AssistGroup<'a> {
178#[derive(Default)] 178#[derive(Default)]
179pub(crate) struct ActionBuilder { 179pub(crate) struct ActionBuilder {
180 edit: TextEditBuilder, 180 edit: TextEditBuilder,
181 cursor_position: Option<TextUnit>, 181 cursor_position: Option<TextSize>,
182 target: Option<TextRange>, 182 target: Option<TextRange>,
183 file: AssistFile,
183} 184}
184 185
185impl ActionBuilder { 186impl ActionBuilder {
@@ -210,12 +211,12 @@ impl ActionBuilder {
210 } 211 }
211 212
212 /// Append specified `text` at the given `offset` 213 /// Append specified `text` at the given `offset`
213 pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into<String>) { 214 pub(crate) fn insert(&mut self, offset: TextSize, text: impl Into<String>) {
214 self.edit.insert(offset, text.into()) 215 self.edit.insert(offset, text.into())
215 } 216 }
216 217
217 /// Specify desired position of the cursor after the assist is applied. 218 /// Specify desired position of the cursor after the assist is applied.
218 pub(crate) fn set_cursor(&mut self, offset: TextUnit) { 219 pub(crate) fn set_cursor(&mut self, offset: TextSize) {
219 self.cursor_position = Some(offset) 220 self.cursor_position = Some(offset)
220 } 221 }
221 222
@@ -241,11 +242,16 @@ impl ActionBuilder {
241 algo::diff(&node, &new).into_text_edit(&mut self.edit) 242 algo::diff(&node, &new).into_text_edit(&mut self.edit)
242 } 243 }
243 244
245 pub(crate) fn set_file(&mut self, assist_file: AssistFile) {
246 self.file = assist_file
247 }
248
244 fn build(self) -> AssistAction { 249 fn build(self) -> AssistAction {
245 AssistAction { 250 AssistAction {
246 edit: self.edit.finish(), 251 edit: self.edit.finish(),
247 cursor_position: self.cursor_position, 252 cursor_position: self.cursor_position,
248 target: self.target, 253 target: self.target,
254 file: self.file,
249 } 255 }
250 } 256 }
251} 257}
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index b39e60870..e4fa9ee36 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -66,7 +66,7 @@ fn doctest_add_function() {
66struct Baz; 66struct Baz;
67fn baz() -> Baz { Baz } 67fn baz() -> Baz { Baz }
68fn foo() { 68fn foo() {
69 bar<|>("", baz()); 69 bar<|>("", baz());
70} 70}
71 71
72"#####, 72"#####,
@@ -74,7 +74,7 @@ fn foo() {
74struct Baz; 74struct Baz;
75fn baz() -> Baz { Baz } 75fn baz() -> Baz { Baz }
76fn foo() { 76fn foo() {
77 bar("", baz()); 77 bar("", baz());
78} 78}
79 79
80fn bar(arg: &str, baz: Baz) { 80fn bar(arg: &str, baz: Baz) {
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index 15f9b216b..4ea26a550 100644
--- a/crates/ra_assists/src/handlers/add_custom_impl.rs
+++ b/crates/ra_assists/src/handlers/add_custom_impl.rs
@@ -2,7 +2,7 @@ use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 Direction, SmolStr, 3 Direction, SmolStr,
4 SyntaxKind::{IDENT, WHITESPACE}, 4 SyntaxKind::{IDENT, WHITESPACE},
5 TextRange, TextUnit, 5 TextRange, TextSize,
6}; 6};
7use stdx::SepBy; 7use stdx::SepBy;
8 8
@@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
60 .collect::<Vec<SmolStr>>(); 60 .collect::<Vec<SmolStr>>();
61 let has_more_derives = !new_attr_input.is_empty(); 61 let has_more_derives = !new_attr_input.is_empty();
62 let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); 62 let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string();
63 let new_attr_input_len = new_attr_input.len();
64 63
65 let mut buf = String::new(); 64 let mut buf = String::new();
66 buf.push_str("\n\nimpl "); 65 buf.push_str("\n\nimpl ");
@@ -70,8 +69,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
70 buf.push_str(" {\n"); 69 buf.push_str(" {\n");
71 70
72 let cursor_delta = if has_more_derives { 71 let cursor_delta = if has_more_derives {
72 let delta = input.syntax().text_range().len() - TextSize::of(&new_attr_input);
73 edit.replace(input.syntax().text_range(), new_attr_input); 73 edit.replace(input.syntax().text_range(), new_attr_input);
74 input.syntax().text_range().len() - TextUnit::from_usize(new_attr_input_len) 74 delta
75 } else { 75 } else {
76 let attr_range = attr.syntax().text_range(); 76 let attr_range = attr.syntax().text_range();
77 edit.delete(attr_range); 77 edit.delete(attr_range);
@@ -81,13 +81,13 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
81 .next_sibling_or_token() 81 .next_sibling_or_token()
82 .filter(|t| t.kind() == WHITESPACE) 82 .filter(|t| t.kind() == WHITESPACE)
83 .map(|t| t.text_range()) 83 .map(|t| t.text_range())
84 .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); 84 .unwrap_or_else(|| TextRange::new(TextSize::from(0), TextSize::from(0)));
85 edit.delete(line_break_range); 85 edit.delete(line_break_range);
86 86
87 attr_range.len() + line_break_range.len() 87 attr_range.len() + line_break_range.len()
88 }; 88 };
89 89
90 edit.set_cursor(start_offset + TextUnit::of_str(&buf) - cursor_delta); 90 edit.set_cursor(start_offset + TextSize::of(&buf) - cursor_delta);
91 buf.push_str("\n}"); 91 buf.push_str("\n}");
92 edit.insert(start_offset, buf); 92 edit.insert(start_offset, buf);
93 }) 93 })
diff --git a/crates/ra_assists/src/handlers/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs
index b0d1a0a80..6254eb7c4 100644
--- a/crates/ra_assists/src/handlers/add_derive.rs
+++ b/crates/ra_assists/src/handlers/add_derive.rs
@@ -1,7 +1,7 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode, AttrsOwner}, 2 ast::{self, AstNode, AttrsOwner},
3 SyntaxKind::{COMMENT, WHITESPACE}, 3 SyntaxKind::{COMMENT, WHITESPACE},
4 TextUnit, 4 TextSize,
5}; 5};
6 6
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{Assist, AssistCtx, AssistId};
@@ -37,9 +37,9 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
37 let offset = match derive_attr { 37 let offset = match derive_attr {
38 None => { 38 None => {
39 edit.insert(node_start, "#[derive()]\n"); 39 edit.insert(node_start, "#[derive()]\n");
40 node_start + TextUnit::of_str("#[derive(") 40 node_start + TextSize::of("#[derive(")
41 } 41 }
42 Some(tt) => tt.syntax().text_range().end() - TextUnit::of_char(')'), 42 Some(tt) => tt.syntax().text_range().end() - TextSize::of(')'),
43 }; 43 };
44 edit.target(nominal.syntax().text_range()); 44 edit.target(nominal.syntax().text_range());
45 edit.set_cursor(offset) 45 edit.set_cursor(offset)
@@ -47,7 +47,7 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
47} 47}
48 48
49// Insert `derive` after doc comments. 49// Insert `derive` after doc comments.
50fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> { 50fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> {
51 let non_ws_child = nominal 51 let non_ws_child = nominal
52 .syntax() 52 .syntax()
53 .children_with_tokens() 53 .children_with_tokens()
diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs
index 6c56d93d8..bc313782b 100644
--- a/crates/ra_assists/src/handlers/add_explicit_type.rs
+++ b/crates/ra_assists/src/handlers/add_explicit_type.rs
@@ -37,8 +37,8 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> {
37 let stmt_range = stmt.syntax().text_range(); 37 let stmt_range = stmt.syntax().text_range();
38 let eq_range = stmt.eq_token()?.text_range(); 38 let eq_range = 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::from_to(stmt_range.start(), eq_range.start()); 40 let let_range = TextRange::new(stmt_range.start(), eq_range.start());
41 let cursor_in_range = ctx.frange.range.is_subrange(&let_range); 41 let cursor_in_range = let_range.contains_range(ctx.frange.range);
42 if !cursor_in_range { 42 if !cursor_in_range {
43 return None; 43 return None;
44 } 44 }
diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
index 0621487e8..03806724a 100644
--- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
+++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
@@ -1,6 +1,6 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode, NameOwner}, 2 ast::{self, AstNode, NameOwner},
3 TextUnit, 3 TextSize,
4}; 4};
5use stdx::format_to; 5use stdx::format_to;
6 6
@@ -65,7 +65,7 @@ impl From<{0}> for {1} {{
65 variant_name 65 variant_name
66 ); 66 );
67 edit.insert(start_offset, buf); 67 edit.insert(start_offset, buf);
68 edit.set_cursor(start_offset + TextUnit::of_str("\n\n")); 68 edit.set_cursor(start_offset + TextSize::of("\n\n"));
69 }, 69 },
70 ) 70 )
71} 71}
diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs
index ad4ab66ed..6c7456579 100644
--- a/crates/ra_assists/src/handlers/add_function.rs
+++ b/crates/ra_assists/src/handlers/add_function.rs
@@ -1,10 +1,10 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 SyntaxKind, SyntaxNode, TextUnit, 3 SyntaxKind, SyntaxNode, TextSize,
4}; 4};
5 5
6use crate::{Assist, AssistCtx, AssistId}; 6use crate::{Assist, AssistCtx, AssistFile, AssistId};
7use ast::{edit::IndentLevel, ArgListOwner, CallExpr, Expr}; 7use ast::{edit::IndentLevel, ArgListOwner, ModuleItemOwner};
8use hir::HirDisplay; 8use hir::HirDisplay;
9use rustc_hash::{FxHashMap, FxHashSet}; 9use rustc_hash::{FxHashMap, FxHashSet};
10 10
@@ -16,7 +16,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
16// struct Baz; 16// struct Baz;
17// fn baz() -> Baz { Baz } 17// fn baz() -> Baz { Baz }
18// fn foo() { 18// fn foo() {
19// bar<|>("", baz()); 19// bar<|>("", baz());
20// } 20// }
21// 21//
22// ``` 22// ```
@@ -25,7 +25,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
25// struct Baz; 25// struct Baz;
26// fn baz() -> Baz { Baz } 26// fn baz() -> Baz { Baz }
27// fn foo() { 27// fn foo() {
28// bar("", baz()); 28// bar("", baz());
29// } 29// }
30// 30//
31// fn bar(arg: &str, baz: Baz) { 31// fn bar(arg: &str, baz: Baz) {
@@ -38,21 +38,30 @@ pub(crate) fn add_function(ctx: AssistCtx) -> Option<Assist> {
38 let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?; 38 let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
39 let path = path_expr.path()?; 39 let path = path_expr.path()?;
40 40
41 if path.qualifier().is_some() {
42 return None;
43 }
44
45 if ctx.sema.resolve_path(&path).is_some() { 41 if ctx.sema.resolve_path(&path).is_some() {
46 // The function call already resolves, no need to add a function 42 // The function call already resolves, no need to add a function
47 return None; 43 return None;
48 } 44 }
49 45
50 let function_builder = FunctionBuilder::from_call(&ctx, &call)?; 46 let target_module = if let Some(qualifier) = path.qualifier() {
47 if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) =
48 ctx.sema.resolve_path(&qualifier)
49 {
50 Some(module.definition_source(ctx.sema.db))
51 } else {
52 return None;
53 }
54 } else {
55 None
56 };
57
58 let function_builder = FunctionBuilder::from_call(&ctx, &call, &path, target_module)?;
51 59
52 ctx.add_assist(AssistId("add_function"), "Add function", |edit| { 60 ctx.add_assist(AssistId("add_function"), "Add function", |edit| {
53 edit.target(call.syntax().text_range()); 61 edit.target(call.syntax().text_range());
54 62
55 if let Some(function_template) = function_builder.render() { 63 if let Some(function_template) = function_builder.render() {
64 edit.set_file(function_template.file);
56 edit.set_cursor(function_template.cursor_offset); 65 edit.set_cursor(function_template.cursor_offset);
57 edit.insert(function_template.insert_offset, function_template.fn_def.to_string()); 66 edit.insert(function_template.insert_offset, function_template.fn_def.to_string());
58 } 67 }
@@ -60,32 +69,70 @@ pub(crate) fn add_function(ctx: AssistCtx) -> Option<Assist> {
60} 69}
61 70
62struct FunctionTemplate { 71struct FunctionTemplate {
63 insert_offset: TextUnit, 72 insert_offset: TextSize,
64 cursor_offset: TextUnit, 73 cursor_offset: TextSize,
65 fn_def: ast::SourceFile, 74 fn_def: ast::SourceFile,
75 file: AssistFile,
66} 76}
67 77
68struct FunctionBuilder { 78struct FunctionBuilder {
69 append_fn_at: SyntaxNode, 79 target: GeneratedFunctionTarget,
70 fn_name: ast::Name, 80 fn_name: ast::Name,
71 type_params: Option<ast::TypeParamList>, 81 type_params: Option<ast::TypeParamList>,
72 params: ast::ParamList, 82 params: ast::ParamList,
83 file: AssistFile,
84 needs_pub: bool,
73} 85}
74 86
75impl FunctionBuilder { 87impl FunctionBuilder {
76 fn from_call(ctx: &AssistCtx, call: &ast::CallExpr) -> Option<Self> { 88 /// Prepares a generated function that matches `call` in `generate_in`
77 let append_fn_at = next_space_for_fn(&call)?; 89 /// (or as close to `call` as possible, if `generate_in` is `None`)
78 let fn_name = fn_name(&call)?; 90 fn from_call(
91 ctx: &AssistCtx,
92 call: &ast::CallExpr,
93 path: &ast::Path,
94 target_module: Option<hir::InFile<hir::ModuleSource>>,
95 ) -> Option<Self> {
96 let needs_pub = target_module.is_some();
97 let mut file = AssistFile::default();
98 let target = if let Some(target_module) = target_module {
99 let (in_file, target) = next_space_for_fn_in_module(ctx.sema.db, target_module)?;
100 file = in_file;
101 target
102 } else {
103 next_space_for_fn_after_call_site(&call)?
104 };
105 let fn_name = fn_name(&path)?;
79 let (type_params, params) = fn_args(ctx, &call)?; 106 let (type_params, params) = fn_args(ctx, &call)?;
80 Some(Self { append_fn_at, fn_name, type_params, params }) 107 Some(Self { target, fn_name, type_params, params, file, needs_pub })
81 } 108 }
109
82 fn render(self) -> Option<FunctionTemplate> { 110 fn render(self) -> Option<FunctionTemplate> {
83 let placeholder_expr = ast::make::expr_todo(); 111 let placeholder_expr = ast::make::expr_todo();
84 let fn_body = ast::make::block_expr(vec![], Some(placeholder_expr)); 112 let fn_body = ast::make::block_expr(vec![], Some(placeholder_expr));
85 let fn_def = ast::make::fn_def(self.fn_name, self.type_params, self.params, fn_body); 113 let mut fn_def = ast::make::fn_def(self.fn_name, self.type_params, self.params, fn_body);
86 let fn_def = ast::make::add_newlines(2, fn_def); 114 if self.needs_pub {
87 let fn_def = IndentLevel::from_node(&self.append_fn_at).increase_indent(fn_def); 115 fn_def = ast::make::add_pub_crate_modifier(fn_def);
88 let insert_offset = self.append_fn_at.text_range().end(); 116 }
117
118 let (fn_def, insert_offset) = match self.target {
119 GeneratedFunctionTarget::BehindItem(it) => {
120 let with_leading_blank_line = ast::make::add_leading_newlines(2, fn_def);
121 let indented = IndentLevel::from_node(&it).increase_indent(with_leading_blank_line);
122 (indented, it.text_range().end())
123 }
124 GeneratedFunctionTarget::InEmptyItemList(it) => {
125 let indent_once = IndentLevel(1);
126 let indent = IndentLevel::from_node(it.syntax());
127
128 let fn_def = ast::make::add_leading_newlines(1, fn_def);
129 let fn_def = indent_once.increase_indent(fn_def);
130 let fn_def = ast::make::add_trailing_newlines(1, fn_def);
131 let fn_def = indent.increase_indent(fn_def);
132 (fn_def, it.syntax().text_range().start() + TextSize::of('{'))
133 }
134 };
135
89 let cursor_offset_from_fn_start = fn_def 136 let cursor_offset_from_fn_start = fn_def
90 .syntax() 137 .syntax()
91 .descendants() 138 .descendants()
@@ -94,19 +141,24 @@ impl FunctionBuilder {
94 .text_range() 141 .text_range()
95 .start(); 142 .start();
96 let cursor_offset = insert_offset + cursor_offset_from_fn_start; 143 let cursor_offset = insert_offset + cursor_offset_from_fn_start;
97 Some(FunctionTemplate { insert_offset, cursor_offset, fn_def }) 144 Some(FunctionTemplate { insert_offset, cursor_offset, fn_def, file: self.file })
98 } 145 }
99} 146}
100 147
101fn fn_name(call: &CallExpr) -> Option<ast::Name> { 148enum GeneratedFunctionTarget {
102 let name = call.expr()?.syntax().to_string(); 149 BehindItem(SyntaxNode),
150 InEmptyItemList(ast::ItemList),
151}
152
153fn fn_name(call: &ast::Path) -> Option<ast::Name> {
154 let name = call.segment()?.syntax().to_string();
103 Some(ast::make::name(&name)) 155 Some(ast::make::name(&name))
104} 156}
105 157
106/// Computes the type variables and arguments required for the generated function 158/// Computes the type variables and arguments required for the generated function
107fn fn_args( 159fn fn_args(
108 ctx: &AssistCtx, 160 ctx: &AssistCtx,
109 call: &CallExpr, 161 call: &ast::CallExpr,
110) -> Option<(Option<ast::TypeParamList>, ast::ParamList)> { 162) -> Option<(Option<ast::TypeParamList>, ast::ParamList)> {
111 let mut arg_names = Vec::new(); 163 let mut arg_names = Vec::new();
112 let mut arg_types = Vec::new(); 164 let mut arg_types = Vec::new();
@@ -158,9 +210,9 @@ fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
158 } 210 }
159} 211}
160 212
161fn fn_arg_name(fn_arg: &Expr) -> Option<String> { 213fn fn_arg_name(fn_arg: &ast::Expr) -> Option<String> {
162 match fn_arg { 214 match fn_arg {
163 Expr::CastExpr(cast_expr) => fn_arg_name(&cast_expr.expr()?), 215 ast::Expr::CastExpr(cast_expr) => fn_arg_name(&cast_expr.expr()?),
164 _ => Some( 216 _ => Some(
165 fn_arg 217 fn_arg
166 .syntax() 218 .syntax()
@@ -172,7 +224,7 @@ fn fn_arg_name(fn_arg: &Expr) -> Option<String> {
172 } 224 }
173} 225}
174 226
175fn fn_arg_type(ctx: &AssistCtx, fn_arg: &Expr) -> Option<String> { 227fn fn_arg_type(ctx: &AssistCtx, fn_arg: &ast::Expr) -> Option<String> {
176 let ty = ctx.sema.type_of_expr(fn_arg)?; 228 let ty = ctx.sema.type_of_expr(fn_arg)?;
177 if ty.is_unknown() { 229 if ty.is_unknown() {
178 return None; 230 return None;
@@ -184,7 +236,7 @@ fn fn_arg_type(ctx: &AssistCtx, fn_arg: &Expr) -> Option<String> {
184/// directly after the current block 236/// directly after the current block
185/// We want to write the generated function directly after 237/// We want to write the generated function directly after
186/// fns, impls or macro calls, but inside mods 238/// fns, impls or macro calls, but inside mods
187fn next_space_for_fn(expr: &CallExpr) -> Option<SyntaxNode> { 239fn next_space_for_fn_after_call_site(expr: &ast::CallExpr) -> Option<GeneratedFunctionTarget> {
188 let mut ancestors = expr.syntax().ancestors().peekable(); 240 let mut ancestors = expr.syntax().ancestors().peekable();
189 let mut last_ancestor: Option<SyntaxNode> = None; 241 let mut last_ancestor: Option<SyntaxNode> = None;
190 while let Some(next_ancestor) = ancestors.next() { 242 while let Some(next_ancestor) = ancestors.next() {
@@ -201,7 +253,32 @@ fn next_space_for_fn(expr: &CallExpr) -> Option<SyntaxNode> {
201 } 253 }
202 last_ancestor = Some(next_ancestor); 254 last_ancestor = Some(next_ancestor);
203 } 255 }
204 last_ancestor 256 last_ancestor.map(GeneratedFunctionTarget::BehindItem)
257}
258
259fn next_space_for_fn_in_module(
260 db: &dyn hir::db::AstDatabase,
261 module: hir::InFile<hir::ModuleSource>,
262) -> Option<(AssistFile, GeneratedFunctionTarget)> {
263 let file = module.file_id.original_file(db);
264 let assist_file = AssistFile::TargetFile(file);
265 let assist_item = match module.value {
266 hir::ModuleSource::SourceFile(it) => {
267 if let Some(last_item) = it.items().last() {
268 GeneratedFunctionTarget::BehindItem(last_item.syntax().clone())
269 } else {
270 GeneratedFunctionTarget::BehindItem(it.syntax().clone())
271 }
272 }
273 hir::ModuleSource::Module(it) => {
274 if let Some(last_item) = it.item_list().and_then(|it| it.items().last()) {
275 GeneratedFunctionTarget::BehindItem(last_item.syntax().clone())
276 } else {
277 GeneratedFunctionTarget::InEmptyItemList(it.item_list()?)
278 }
279 }
280 };
281 Some((assist_file, assist_item))
205} 282}
206 283
207#[cfg(test)] 284#[cfg(test)]
@@ -714,6 +791,111 @@ fn bar(baz_1: Baz, baz_2: Baz, arg_1: &str, arg_2: &str) {
714 } 791 }
715 792
716 #[test] 793 #[test]
794 fn add_function_in_module() {
795 check_assist(
796 add_function,
797 r"
798mod bar {}
799
800fn foo() {
801 bar::my_fn<|>()
802}
803",
804 r"
805mod bar {
806 pub(crate) fn my_fn() {
807 <|>todo!()
808 }
809}
810
811fn foo() {
812 bar::my_fn()
813}
814",
815 )
816 }
817
818 #[test]
819 fn add_function_in_module_containing_other_items() {
820 check_assist(
821 add_function,
822 r"
823mod bar {
824 fn something_else() {}
825}
826
827fn foo() {
828 bar::my_fn<|>()
829}
830",
831 r"
832mod bar {
833 fn something_else() {}
834
835 pub(crate) fn my_fn() {
836 <|>todo!()
837 }
838}
839
840fn foo() {
841 bar::my_fn()
842}
843",
844 )
845 }
846
847 #[test]
848 fn add_function_in_nested_module() {
849 check_assist(
850 add_function,
851 r"
852mod bar {
853 mod baz {}
854}
855
856fn foo() {
857 bar::baz::my_fn<|>()
858}
859",
860 r"
861mod bar {
862 mod baz {
863 pub(crate) fn my_fn() {
864 <|>todo!()
865 }
866 }
867}
868
869fn foo() {
870 bar::baz::my_fn()
871}
872",
873 )
874 }
875
876 #[test]
877 fn add_function_in_another_file() {
878 check_assist(
879 add_function,
880 r"
881//- /main.rs
882mod foo;
883
884fn main() {
885 foo::bar<|>()
886}
887//- /foo.rs
888",
889 r"
890
891
892pub(crate) fn bar() {
893 <|>todo!()
894}",
895 )
896 }
897
898 #[test]
717 fn add_function_not_applicable_if_function_already_exists() { 899 fn add_function_not_applicable_if_function_already_exists() {
718 check_assist_not_applicable( 900 check_assist_not_applicable(
719 add_function, 901 add_function,
diff --git a/crates/ra_assists/src/handlers/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs
index 6622eadb2..d26f8b93d 100644
--- a/crates/ra_assists/src/handlers/add_impl.rs
+++ b/crates/ra_assists/src/handlers/add_impl.rs
@@ -1,6 +1,6 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode, NameOwner, TypeParamsOwner}, 2 ast::{self, AstNode, NameOwner, TypeParamsOwner},
3 TextUnit, 3 TextSize,
4}; 4};
5use stdx::{format_to, SepBy}; 5use stdx::{format_to, SepBy};
6 6
@@ -51,7 +51,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
51 format_to!(buf, "<{}>", generic_params) 51 format_to!(buf, "<{}>", generic_params)
52 } 52 }
53 buf.push_str(" {\n"); 53 buf.push_str(" {\n");
54 edit.set_cursor(start_offset + TextUnit::of_str(&buf)); 54 edit.set_cursor(start_offset + TextSize::of(&buf));
55 buf.push_str("\n}"); 55 buf.push_str("\n}");
56 edit.insert(start_offset, buf); 56 edit.insert(start_offset, buf);
57 }) 57 })
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs
index 240b19fa3..0f9174a29 100644
--- a/crates/ra_assists/src/handlers/add_new.rs
+++ b/crates/ra_assists/src/handlers/add_new.rs
@@ -3,7 +3,7 @@ use ra_syntax::{
3 ast::{ 3 ast::{
4 self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner, 4 self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner,
5 }, 5 },
6 TextUnit, T, 6 TextSize, T,
7}; 7};
8use stdx::{format_to, SepBy}; 8use stdx::{format_to, SepBy};
9 9
@@ -77,16 +77,16 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
77 .text_range() 77 .text_range()
78 .end(); 78 .end();
79 79
80 Some((start, TextUnit::from_usize(1))) 80 Some((start, TextSize::of("\n")))
81 }) 81 })
82 .unwrap_or_else(|| { 82 .unwrap_or_else(|| {
83 buf = generate_impl_text(&strukt, &buf); 83 buf = generate_impl_text(&strukt, &buf);
84 let start = strukt.syntax().text_range().end(); 84 let start = strukt.syntax().text_range().end();
85 85
86 (start, TextUnit::from_usize(3)) 86 (start, TextSize::of("\n}\n"))
87 }); 87 });
88 88
89 edit.set_cursor(start_offset + TextUnit::of_str(&buf) - end_offset); 89 edit.set_cursor(start_offset + TextSize::of(&buf) - end_offset);
90 edit.insert(start_offset, buf); 90 edit.insert(start_offset, buf);
91 }) 91 })
92} 92}
diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs
index 239807e24..260b9e073 100644
--- a/crates/ra_assists/src/handlers/apply_demorgan.rs
+++ b/crates/ra_assists/src/handlers/apply_demorgan.rs
@@ -26,7 +26,7 @@ pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option<Assist> {
26 let op = expr.op_kind()?; 26 let op = expr.op_kind()?;
27 let op_range = expr.op_token()?.text_range(); 27 let op_range = expr.op_token()?.text_range();
28 let opposite_op = opposite_logic_op(op)?; 28 let opposite_op = opposite_logic_op(op)?;
29 let cursor_in_range = ctx.frange.range.is_subrange(&op_range); 29 let cursor_in_range = op_range.contains_range(ctx.frange.range);
30 if !cursor_in_range { 30 if !cursor_in_range {
31 return None; 31 return None;
32 } 32 }
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index cd6d1ee6c..44f6a1dae 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -5,7 +5,7 @@ use ra_syntax::{
5 ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY, 5 ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY,
6 WHITESPACE, 6 WHITESPACE,
7 }, 7 },
8 SyntaxNode, TextUnit, T, 8 SyntaxNode, TextSize, T,
9}; 9};
10 10
11use crate::{Assist, AssistCtx, AssistId}; 11use crate::{Assist, AssistCtx, AssistId};
@@ -67,7 +67,7 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
67 }) 67 })
68} 68}
69 69
70fn vis_offset(node: &SyntaxNode) -> TextUnit { 70fn vis_offset(node: &SyntaxNode) -> TextSize {
71 node.children_with_tokens() 71 node.children_with_tokens()
72 .skip_while(|it| match it.kind() { 72 .skip_while(|it| match it.kind() {
73 WHITESPACE | COMMENT | ATTR => true, 73 WHITESPACE | COMMENT | ATTR => true,
diff --git a/crates/ra_assists/src/handlers/flip_binexpr.rs b/crates/ra_assists/src/handlers/flip_binexpr.rs
index bfcc09e90..8030efb35 100644
--- a/crates/ra_assists/src/handlers/flip_binexpr.rs
+++ b/crates/ra_assists/src/handlers/flip_binexpr.rs
@@ -23,7 +23,7 @@ pub(crate) fn flip_binexpr(ctx: AssistCtx) -> Option<Assist> {
23 let rhs = expr.rhs()?.syntax().clone(); 23 let rhs = expr.rhs()?.syntax().clone();
24 let op_range = expr.op_token()?.text_range(); 24 let op_range = expr.op_token()?.text_range();
25 // The assist should be applied only if the cursor is on the operator 25 // The assist should be applied only if the cursor is on the operator
26 let cursor_in_range = ctx.frange.range.is_subrange(&op_range); 26 let cursor_in_range = op_range.contains_range(ctx.frange.range);
27 if !cursor_in_range { 27 if !cursor_in_range {
28 return None; 28 return None;
29 } 29 }
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs
index c4fb425b0..f5702f6e0 100644
--- a/crates/ra_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ra_assists/src/handlers/inline_local_variable.rs
@@ -52,7 +52,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
52 .next_sibling_or_token() 52 .next_sibling_or_token()
53 .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone())) 53 .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone()))
54 { 54 {
55 TextRange::from_to( 55 TextRange::new(
56 let_stmt.syntax().text_range().start(), 56 let_stmt.syntax().text_range().start(),
57 whitespace.syntax().text_range().end(), 57 whitespace.syntax().text_range().end(),
58 ) 58 )
diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs
index 8c09e6bcd..eda9ac296 100644
--- a/crates/ra_assists/src/handlers/introduce_variable.rs
+++ b/crates/ra_assists/src/handlers/introduce_variable.rs
@@ -4,7 +4,7 @@ use ra_syntax::{
4 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, 4 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
5 WHITESPACE, 5 WHITESPACE,
6 }, 6 },
7 SyntaxNode, TextUnit, 7 SyntaxNode, TextSize,
8}; 8};
9use stdx::format_to; 9use stdx::format_to;
10use test_utils::tested_by; 10use test_utils::tested_by;
@@ -47,10 +47,10 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option<Assist> {
47 47
48 let cursor_offset = if wrap_in_block { 48 let cursor_offset = if wrap_in_block {
49 buf.push_str("{ let var_name = "); 49 buf.push_str("{ let var_name = ");
50 TextUnit::of_str("{ let ") 50 TextSize::of("{ let ")
51 } else { 51 } else {
52 buf.push_str("let var_name = "); 52 buf.push_str("let var_name = ");
53 TextUnit::of_str("let ") 53 TextSize::of("let ")
54 }; 54 };
55 format_to!(buf, "{}", expr.syntax()); 55 format_to!(buf, "{}", expr.syntax());
56 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); 56 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone());
diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs
index 4c5716868..682e08512 100644
--- a/crates/ra_assists/src/handlers/invert_if.rs
+++ b/crates/ra_assists/src/handlers/invert_if.rs
@@ -28,7 +28,7 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> {
28 let if_keyword = ctx.find_token_at_offset(T![if])?; 28 let if_keyword = ctx.find_token_at_offset(T![if])?;
29 let expr = ast::IfExpr::cast(if_keyword.parent())?; 29 let expr = ast::IfExpr::cast(if_keyword.parent())?;
30 let if_range = if_keyword.text_range(); 30 let if_range = if_keyword.text_range();
31 let cursor_in_range = ctx.frange.range.is_subrange(&if_range); 31 let cursor_in_range = if_range.contains_range(ctx.frange.range);
32 if !cursor_in_range { 32 if !cursor_in_range {
33 return None; 33 return None;
34 } 34 }
diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs
index eb967ab92..5a77d3dbc 100644
--- a/crates/ra_assists/src/handlers/merge_match_arms.rs
+++ b/crates/ra_assists/src/handlers/merge_match_arms.rs
@@ -3,7 +3,7 @@ use std::iter::successors;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::neighbor, 4 algo::neighbor,
5 ast::{self, AstNode}, 5 ast::{self, AstNode},
6 Direction, TextUnit, 6 Direction, TextSize,
7}; 7};
8 8
9use crate::{Assist, AssistCtx, AssistId, TextRange}; 9use crate::{Assist, AssistCtx, AssistId, TextRange};
@@ -42,8 +42,8 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option<Assist> {
42 let current_text_range = current_arm.syntax().text_range(); 42 let current_text_range = current_arm.syntax().text_range();
43 43
44 enum CursorPos { 44 enum CursorPos {
45 InExpr(TextUnit), 45 InExpr(TextSize),
46 InPat(TextUnit), 46 InPat(TextSize),
47 } 47 }
48 let cursor_pos = ctx.frange.range.start(); 48 let cursor_pos = ctx.frange.range.start();
49 let cursor_pos = if current_expr.syntax().text_range().contains(cursor_pos) { 49 let cursor_pos = if current_expr.syntax().text_range().contains(cursor_pos) {
@@ -89,10 +89,10 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option<Assist> {
89 89
90 edit.target(current_text_range); 90 edit.target(current_text_range);
91 edit.set_cursor(match cursor_pos { 91 edit.set_cursor(match cursor_pos {
92 CursorPos::InExpr(back_offset) => start + TextUnit::from_usize(arm.len()) - back_offset, 92 CursorPos::InExpr(back_offset) => start + TextSize::of(&arm) - back_offset,
93 CursorPos::InPat(offset) => offset, 93 CursorPos::InPat(offset) => offset,
94 }); 94 });
95 edit.replace(TextRange::from_to(start, end), arm); 95 edit.replace(TextRange::new(start, end), arm);
96 }) 96 })
97} 97}
98 98
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs
index 1cc498638..d5ccdd91c 100644
--- a/crates/ra_assists/src/handlers/move_guard.rs
+++ b/crates/ra_assists/src/handlers/move_guard.rs
@@ -1,7 +1,7 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast, 2 ast,
3 ast::{AstNode, AstToken, IfExpr, MatchArm}, 3 ast::{AstNode, AstToken, IfExpr, MatchArm},
4 TextUnit, 4 TextSize,
5}; 5};
6 6
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{Assist, AssistCtx, AssistId};
@@ -49,16 +49,16 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> {
49 edit.delete(ele); 49 edit.delete(ele);
50 ele.len() 50 ele.len()
51 } else { 51 } else {
52 TextUnit::from(0) 52 TextSize::from(0)
53 } 53 }
54 } 54 }
55 _ => TextUnit::from(0), 55 _ => TextSize::from(0),
56 }; 56 };
57 57
58 edit.delete(guard.syntax().text_range()); 58 edit.delete(guard.syntax().text_range());
59 edit.replace_node_and_indent(arm_expr.syntax(), buf); 59 edit.replace_node_and_indent(arm_expr.syntax(), buf);
60 edit.set_cursor( 60 edit.set_cursor(
61 arm_expr.syntax().text_range().start() + TextUnit::from(3) - offseting_amount, 61 arm_expr.syntax().text_range().start() + TextSize::from(3) - offseting_amount,
62 ); 62 );
63 }) 63 })
64} 64}
@@ -123,7 +123,7 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
123 } 123 }
124 124
125 edit.insert(match_pat.syntax().text_range().end(), buf); 125 edit.insert(match_pat.syntax().text_range().end(), buf);
126 edit.set_cursor(match_pat.syntax().text_range().end() + TextUnit::from(1)); 126 edit.set_cursor(match_pat.syntax().text_range().end() + TextSize::from(1));
127 }, 127 },
128 ) 128 )
129} 129}
diff --git a/crates/ra_assists/src/handlers/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs
index 7e4b83f13..567400b9c 100644
--- a/crates/ra_assists/src/handlers/raw_string.rs
+++ b/crates/ra_assists/src/handlers/raw_string.rs
@@ -2,7 +2,7 @@ use ra_syntax::{
2 ast::{self, HasStringValue}, 2 ast::{self, HasStringValue},
3 AstToken, 3 AstToken,
4 SyntaxKind::{RAW_STRING, STRING}, 4 SyntaxKind::{RAW_STRING, STRING},
5 TextUnit, 5 TextSize,
6}; 6};
7 7
8use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
@@ -81,7 +81,7 @@ pub(crate) fn add_hash(ctx: AssistCtx) -> Option<Assist> {
81 let token = ctx.find_token_at_offset(RAW_STRING)?; 81 let token = ctx.find_token_at_offset(RAW_STRING)?;
82 ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| { 82 ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| {
83 edit.target(token.text_range()); 83 edit.target(token.text_range());
84 edit.insert(token.text_range().start() + TextUnit::of_char('r'), "#"); 84 edit.insert(token.text_range().start() + TextSize::of('r'), "#");
85 edit.insert(token.text_range().end(), "#"); 85 edit.insert(token.text_range().end(), "#");
86 }) 86 })
87} 87}
diff --git a/crates/ra_assists/src/handlers/remove_dbg.rs b/crates/ra_assists/src/handlers/remove_dbg.rs
index 5085649b4..4e5eb4350 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 TextUnit, T, 3 TextSize, T,
4}; 4};
5 5
6use crate::{Assist, AssistCtx, AssistId}; 6use crate::{Assist, AssistCtx, AssistId};
@@ -38,9 +38,9 @@ pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option<Assist> {
38 let offset_start = file_range 38 let offset_start = file_range
39 .start() 39 .start()
40 .checked_sub(macro_range.start()) 40 .checked_sub(macro_range.start())
41 .unwrap_or_else(|| TextUnit::from(0)); 41 .unwrap_or_else(|| TextSize::from(0));
42 42
43 let dbg_size = TextUnit::of_str("dbg!("); 43 let dbg_size = TextSize::of("dbg!(");
44 44
45 if offset_start > dbg_size { 45 if offset_start > dbg_size {
46 file_range.start() - dbg_size 46 file_range.start() - dbg_size
@@ -53,7 +53,7 @@ pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option<Assist> {
53 let macro_args = macro_call.token_tree()?.syntax().clone(); 53 let macro_args = macro_call.token_tree()?.syntax().clone();
54 54
55 let text = macro_args.text(); 55 let text = macro_args.text();
56 let without_parens = TextUnit::of_char('(')..text.len() - TextUnit::of_char(')'); 56 let without_parens = TextSize::of('(')..text.len() - TextSize::of(')');
57 text.slice(without_parens).to_string() 57 text.slice(without_parens).to_string()
58 }; 58 };
59 59
diff --git a/crates/ra_assists/src/handlers/remove_mut.rs b/crates/ra_assists/src/handlers/remove_mut.rs
index 6884830eb..e598023b2 100644
--- a/crates/ra_assists/src/handlers/remove_mut.rs
+++ b/crates/ra_assists/src/handlers/remove_mut.rs
@@ -27,6 +27,6 @@ pub(crate) fn remove_mut(ctx: AssistCtx) -> Option<Assist> {
27 27
28 ctx.add_assist(AssistId("remove_mut"), "Remove `mut` keyword", |edit| { 28 ctx.add_assist(AssistId("remove_mut"), "Remove `mut` keyword", |edit| {
29 edit.set_cursor(delete_from); 29 edit.set_cursor(delete_from);
30 edit.delete(TextRange::from_to(delete_from, delete_to)); 30 edit.delete(TextRange::new(delete_from, delete_to));
31 }) 31 })
32} 32}
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 94f5d6c50..2f02df303 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
@@ -43,7 +43,7 @@ pub(crate) fn replace_qualified_name_with_use(ctx: AssistCtx) -> Option<Assist>
43 if let Some(last) = path.segment() { 43 if let Some(last) = path.segment() {
44 // Here we are assuming the assist will provide a correct use statement 44 // Here we are assuming the assist will provide a correct use statement
45 // so we can delete the path qualifier 45 // so we can delete the path qualifier
46 edit.delete(TextRange::from_to( 46 edit.delete(TextRange::new(
47 path.syntax().text_range().start(), 47 path.syntax().text_range().start(),
48 last.syntax().text_range().start(), 48 last.syntax().text_range().start(),
49 )); 49 ));
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index a00136da1..64bd87afb 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -17,9 +17,9 @@ mod doc_tests;
17pub mod utils; 17pub mod utils;
18pub mod ast_transform; 18pub mod ast_transform;
19 19
20use ra_db::FileRange; 20use ra_db::{FileId, FileRange};
21use ra_ide_db::RootDatabase; 21use ra_ide_db::RootDatabase;
22use ra_syntax::{TextRange, TextUnit}; 22use ra_syntax::{TextRange, TextSize};
23use ra_text_edit::TextEdit; 23use ra_text_edit::TextEdit;
24 24
25pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; 25pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler};
@@ -51,9 +51,10 @@ impl AssistLabel {
51#[derive(Debug, Clone)] 51#[derive(Debug, Clone)]
52pub struct AssistAction { 52pub struct AssistAction {
53 pub edit: TextEdit, 53 pub edit: TextEdit,
54 pub cursor_position: Option<TextUnit>, 54 pub cursor_position: Option<TextSize>,
55 // FIXME: This belongs to `AssistLabel` 55 // FIXME: This belongs to `AssistLabel`
56 pub target: Option<TextRange>, 56 pub target: Option<TextRange>,
57 pub file: AssistFile,
57} 58}
58 59
59#[derive(Debug, Clone)] 60#[derive(Debug, Clone)]
@@ -63,6 +64,18 @@ pub struct ResolvedAssist {
63 pub action: AssistAction, 64 pub action: AssistAction,
64} 65}
65 66
67#[derive(Debug, Clone, Copy)]
68pub enum AssistFile {
69 CurrentFile,
70 TargetFile(FileId),
71}
72
73impl Default for AssistFile {
74 fn default() -> Self {
75 Self::CurrentFile
76 }
77}
78
66/// Return all the assists applicable at the given position. 79/// Return all the assists applicable at the given position.
67/// 80///
68/// Assists are returned in the "unresolved" state, that is only labels are 81/// Assists are returned in the "unresolved" state, that is only labels are
@@ -91,7 +104,7 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssi
91 .flat_map(|it| it.0) 104 .flat_map(|it| it.0)
92 .map(|it| it.into_resolved().unwrap()) 105 .map(|it| it.into_resolved().unwrap())
93 .collect::<Vec<_>>(); 106 .collect::<Vec<_>>();
94 a.sort_by_key(|it| it.action.target.map_or(TextUnit::from(!0u32), |it| it.len())); 107 a.sort_by_key(|it| it.action.target.map_or(TextSize::from(!0u32), |it| it.len()));
95 a 108 a
96} 109}
97 110
@@ -184,7 +197,7 @@ mod helpers {
184 use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; 197 use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
185 use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset}; 198 use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset};
186 199
187 use crate::{AssistCtx, AssistHandler}; 200 use crate::{AssistCtx, AssistFile, AssistHandler};
188 use hir::Semantics; 201 use hir::Semantics;
189 202
190 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 203 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
@@ -246,7 +259,13 @@ mod helpers {
246 (Some(assist), ExpectedResult::After(after)) => { 259 (Some(assist), ExpectedResult::After(after)) => {
247 let action = assist.0[0].action.clone().unwrap(); 260 let action = assist.0[0].action.clone().unwrap();
248 261
249 let mut actual = action.edit.apply(&text_without_caret); 262 let assisted_file_text = if let AssistFile::TargetFile(file_id) = action.file {
263 db.file_text(file_id).as_ref().to_owned()
264 } else {
265 text_without_caret
266 };
267
268 let mut actual = action.edit.apply(&assisted_file_text);
250 match action.cursor_position { 269 match action.cursor_position {
251 None => { 270 None => {
252 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { 271 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {
@@ -289,8 +308,7 @@ mod tests {
289 let before = "struct Foo { <|>bar: u32 }"; 308 let before = "struct Foo { <|>bar: u32 }";
290 let (before_cursor_pos, before) = extract_offset(before); 309 let (before_cursor_pos, before) = extract_offset(before);
291 let (db, file_id) = helpers::with_single_file(&before); 310 let (db, file_id) = helpers::with_single_file(&before);
292 let frange = 311 let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
293 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
294 let assists = resolved_assists(&db, frange); 312 let assists = resolved_assists(&db, frange);
295 let mut assists = assists.iter(); 313 let mut assists = assists.iter();
296 314
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index a06f59c14..fd4280de2 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -6,7 +6,7 @@ pub mod fixture;
6use std::{panic, sync::Arc}; 6use std::{panic, sync::Arc};
7 7
8use ra_prof::profile; 8use ra_prof::profile;
9use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit}; 9use ra_syntax::{ast, Parse, SourceFile, TextRange, TextSize};
10 10
11pub use crate::{ 11pub use crate::{
12 cancellation::Canceled, 12 cancellation::Canceled,
@@ -75,7 +75,7 @@ impl<T: salsa::Database> CheckCanceled for T {
75#[derive(Clone, Copy, Debug)] 75#[derive(Clone, Copy, Debug)]
76pub struct FilePosition { 76pub struct FilePosition {
77 pub file_id: FileId, 77 pub file_id: FileId,
78 pub offset: TextUnit, 78 pub offset: TextSize,
79} 79}
80 80
81#[derive(Clone, Copy, Debug)] 81#[derive(Clone, Copy, Debug)]
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 43f932e20..3f645a1dd 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -13,8 +13,8 @@ use hir_def::{
13 resolver::{HasResolver, Resolver}, 13 resolver::{HasResolver, Resolver},
14 type_ref::{Mutability, TypeRef}, 14 type_ref::{Mutability, TypeRef},
15 AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, 15 AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule,
16 ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, 16 ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, StructId,
17 StructId, TraitId, TypeAliasId, TypeParamId, UnionId, 17 TraitId, TypeAliasId, TypeParamId, UnionId,
18}; 18};
19use hir_expand::{ 19use hir_expand::{
20 diagnostics::DiagnosticSink, 20 diagnostics::DiagnosticSink,
@@ -294,9 +294,9 @@ impl Module {
294} 294}
295 295
296#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 296#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
297pub struct StructField { 297pub struct Field {
298 pub(crate) parent: VariantDef, 298 pub(crate) parent: VariantDef,
299 pub(crate) id: LocalStructFieldId, 299 pub(crate) id: LocalFieldId,
300} 300}
301 301
302#[derive(Debug, PartialEq, Eq)] 302#[derive(Debug, PartialEq, Eq)]
@@ -305,7 +305,7 @@ pub enum FieldSource {
305 Pos(ast::TupleFieldDef), 305 Pos(ast::TupleFieldDef),
306} 306}
307 307
308impl StructField { 308impl Field {
309 pub fn name(&self, db: &dyn HirDatabase) -> Name { 309 pub fn name(&self, db: &dyn HirDatabase) -> Name {
310 self.parent.variant_data(db).fields()[self.id].name.clone() 310 self.parent.variant_data(db).fields()[self.id].name.clone()
311 } 311 }
@@ -331,7 +331,7 @@ impl StructField {
331 } 331 }
332} 332}
333 333
334impl HasVisibility for StructField { 334impl HasVisibility for Field {
335 fn visibility(&self, db: &dyn HirDatabase) -> Visibility { 335 fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
336 let variant_data = self.parent.variant_data(db); 336 let variant_data = self.parent.variant_data(db);
337 let visibility = &variant_data.fields()[self.id].visibility; 337 let visibility = &variant_data.fields()[self.id].visibility;
@@ -358,12 +358,12 @@ impl Struct {
358 db.struct_data(self.id).name.clone() 358 db.struct_data(self.id).name.clone()
359 } 359 }
360 360
361 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 361 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
362 db.struct_data(self.id) 362 db.struct_data(self.id)
363 .variant_data 363 .variant_data
364 .fields() 364 .fields()
365 .iter() 365 .iter()
366 .map(|(id, _)| StructField { parent: self.into(), id }) 366 .map(|(id, _)| Field { parent: self.into(), id })
367 .collect() 367 .collect()
368 } 368 }
369 369
@@ -394,12 +394,12 @@ impl Union {
394 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) 394 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id)
395 } 395 }
396 396
397 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 397 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
398 db.union_data(self.id) 398 db.union_data(self.id)
399 .variant_data 399 .variant_data
400 .fields() 400 .fields()
401 .iter() 401 .iter()
402 .map(|(id, _)| StructField { parent: self.into(), id }) 402 .map(|(id, _)| Field { parent: self.into(), id })
403 .collect() 403 .collect()
404 } 404 }
405 405
@@ -457,11 +457,11 @@ impl EnumVariant {
457 db.enum_data(self.parent.id).variants[self.id].name.clone() 457 db.enum_data(self.parent.id).variants[self.id].name.clone()
458 } 458 }
459 459
460 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 460 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
461 self.variant_data(db) 461 self.variant_data(db)
462 .fields() 462 .fields()
463 .iter() 463 .iter()
464 .map(|(id, _)| StructField { parent: self.into(), id }) 464 .map(|(id, _)| Field { parent: self.into(), id })
465 .collect() 465 .collect()
466 } 466 }
467 467
@@ -527,7 +527,7 @@ pub enum VariantDef {
527impl_froms!(VariantDef: Struct, Union, EnumVariant); 527impl_froms!(VariantDef: Struct, Union, EnumVariant);
528 528
529impl VariantDef { 529impl VariantDef {
530 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 530 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
531 match self { 531 match self {
532 VariantDef::Struct(it) => it.fields(db), 532 VariantDef::Struct(it) => it.fields(db),
533 VariantDef::Union(it) => it.fields(db), 533 VariantDef::Union(it) => it.fields(db),
@@ -1148,7 +1148,7 @@ impl Type {
1148 } 1148 }
1149 } 1149 }
1150 1150
1151 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(StructField, Type)> { 1151 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
1152 if let Ty::Apply(a_ty) = &self.ty.value { 1152 if let Ty::Apply(a_ty) = &self.ty.value {
1153 if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor { 1153 if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor {
1154 let var_def = s.into(); 1154 let var_def = s.into();
@@ -1156,7 +1156,7 @@ impl Type {
1156 .field_types(var_def) 1156 .field_types(var_def)
1157 .iter() 1157 .iter()
1158 .map(|(local_id, ty)| { 1158 .map(|(local_id, ty)| {
1159 let def = StructField { parent: var_def.into(), id: local_id }; 1159 let def = Field { parent: var_def.into(), id: local_id };
1160 let ty = ty.clone().subst(&a_ty.parameters); 1160 let ty = ty.clone().subst(&a_ty.parameters);
1161 (def, self.derived(ty)) 1161 (def, self.derived(ty))
1162 }) 1162 })
@@ -1352,7 +1352,7 @@ impl ScopeDef {
1352#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 1352#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1353pub enum AttrDef { 1353pub enum AttrDef {
1354 Module(Module), 1354 Module(Module),
1355 StructField(StructField), 1355 Field(Field),
1356 Adt(Adt), 1356 Adt(Adt),
1357 Function(Function), 1357 Function(Function),
1358 EnumVariant(EnumVariant), 1358 EnumVariant(EnumVariant),
@@ -1365,7 +1365,7 @@ pub enum AttrDef {
1365 1365
1366impl_froms!( 1366impl_froms!(
1367 AttrDef: Module, 1367 AttrDef: Module,
1368 StructField, 1368 Field,
1369 Adt(Struct, Enum, Union), 1369 Adt(Struct, Enum, Union),
1370 EnumVariant, 1370 EnumVariant,
1371 Static, 1371 Static,
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs
index 62fb52e72..679ae8121 100644
--- a/crates/ra_hir/src/from_id.rs
+++ b/crates/ra_hir/src/from_id.rs
@@ -4,13 +4,13 @@
4//! are splitting the hir. 4//! are splitting the hir.
5 5
6use hir_def::{ 6use hir_def::{
7 expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, 7 expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, FieldId,
8 ModuleDefId, StructFieldId, VariantId, 8 GenericDefId, ModuleDefId, VariantId,
9}; 9};
10 10
11use crate::{ 11use crate::{
12 code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, 12 code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, Field, GenericDef,
13 MacroDef, ModuleDef, StructField, VariantDef, 13 Local, MacroDef, ModuleDef, VariantDef,
14}; 14};
15 15
16macro_rules! from_id { 16macro_rules! from_id {
@@ -184,15 +184,15 @@ impl From<VariantDef> for VariantId {
184 } 184 }
185} 185}
186 186
187impl From<StructField> for StructFieldId { 187impl From<Field> for FieldId {
188 fn from(def: StructField) -> Self { 188 fn from(def: Field) -> Self {
189 StructFieldId { parent: def.parent.into(), local_id: def.id } 189 FieldId { parent: def.parent.into(), local_id: def.id }
190 } 190 }
191} 191}
192 192
193impl From<StructFieldId> for StructField { 193impl From<FieldId> for Field {
194 fn from(def: StructFieldId) -> Self { 194 fn from(def: FieldId) -> Self {
195 StructField { parent: def.parent.into(), id: def.local_id } 195 Field { parent: def.parent.into(), id: def.local_id }
196 } 196 }
197} 197}
198 198
@@ -200,7 +200,7 @@ impl From<AttrDef> for AttrDefId {
200 fn from(def: AttrDef) -> Self { 200 fn from(def: AttrDef) -> Self {
201 match def { 201 match def {
202 AttrDef::Module(it) => AttrDefId::ModuleId(it.id), 202 AttrDef::Module(it) => AttrDefId::ModuleId(it.id),
203 AttrDef::StructField(it) => AttrDefId::StructFieldId(it.into()), 203 AttrDef::Field(it) => AttrDefId::FieldId(it.into()),
204 AttrDef::Adt(it) => AttrDefId::AdtId(it.into()), 204 AttrDef::Adt(it) => AttrDefId::AdtId(it.into()),
205 AttrDef::Function(it) => AttrDefId::FunctionId(it.id), 205 AttrDef::Function(it) => AttrDefId::FunctionId(it.id),
206 AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()), 206 AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()),
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs
index 129764e0a..63b8fd369 100644
--- a/crates/ra_hir/src/has_source.rs
+++ b/crates/ra_hir/src/has_source.rs
@@ -9,8 +9,8 @@ use hir_def::{
9use ra_syntax::ast; 9use ra_syntax::ast;
10 10
11use crate::{ 11use crate::{
12 db::HirDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplDef, MacroDef, Module, 12 db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef,
13 Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, 13 Module, Static, Struct, Trait, TypeAlias, TypeParam, Union,
14}; 14};
15 15
16pub use hir_expand::InFile; 16pub use hir_expand::InFile;
@@ -37,7 +37,7 @@ impl Module {
37 } 37 }
38} 38}
39 39
40impl HasSource for StructField { 40impl HasSource for Field {
41 type Ast = FieldSource; 41 type Ast = FieldSource;
42 fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> { 42 fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> {
43 let var = VariantId::from(self.parent); 43 let var = VariantId::from(self.parent);
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 5af7e5d6d..312ef3814 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -52,9 +52,9 @@ mod has_source;
52pub use crate::{ 52pub use crate::{
53 code_model::{ 53 code_model::{
54 Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, 54 Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency,
55 DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, 55 DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasAttrs,
56 HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, 56 HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct,
57 StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, 57 Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility,
58 }, 58 },
59 has_source::HasSource, 59 has_source::HasSource,
60 semantics::{original_range, PathResolution, Semantics, SemanticsScope}, 60 semantics::{original_range, PathResolution, Semantics, SemanticsScope},
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 5d6edc45c..86bfb416c 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -14,7 +14,7 @@ use ra_db::{FileId, FileRange};
14use ra_prof::profile; 14use ra_prof::profile;
15use ra_syntax::{ 15use ra_syntax::{
16 algo::{find_node_at_offset, skip_trivia_token}, 16 algo::{find_node_at_offset, skip_trivia_token},
17 ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextUnit, 17 ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize,
18}; 18};
19use rustc_hash::{FxHashMap, FxHashSet}; 19use rustc_hash::{FxHashMap, FxHashSet};
20 20
@@ -23,8 +23,8 @@ use crate::{
23 diagnostics::Diagnostic, 23 diagnostics::Diagnostic,
24 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 24 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
25 source_analyzer::{resolve_hir_path, SourceAnalyzer}, 25 source_analyzer::{resolve_hir_path, SourceAnalyzer},
26 AssocItem, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, Name, 26 AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef,
27 Origin, Path, ScopeDef, StructField, Trait, Type, TypeParam, 27 Name, Origin, Path, ScopeDef, Trait, Type, TypeParam,
28}; 28};
29 29
30#[derive(Debug, Clone, PartialEq, Eq)] 30#[derive(Debug, Clone, PartialEq, Eq)]
@@ -95,7 +95,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
95 let token = successors(Some(parent.with_value(token)), |token| { 95 let token = successors(Some(parent.with_value(token)), |token| {
96 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; 96 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
97 let tt = macro_call.token_tree()?; 97 let tt = macro_call.token_tree()?;
98 if !token.value.text_range().is_subrange(&tt.syntax().text_range()) { 98 if !tt.syntax().text_range().contains_range(token.value.text_range()) {
99 return None; 99 return None;
100 } 100 }
101 let file_id = sa.expand(self.db, token.with_value(&macro_call))?; 101 let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
@@ -114,7 +114,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
114 pub fn descend_node_at_offset<N: ast::AstNode>( 114 pub fn descend_node_at_offset<N: ast::AstNode>(
115 &self, 115 &self,
116 node: &SyntaxNode, 116 node: &SyntaxNode,
117 offset: TextUnit, 117 offset: TextSize,
118 ) -> Option<N> { 118 ) -> Option<N> {
119 // Handle macro token cases 119 // Handle macro token cases
120 node.token_at_offset(offset) 120 node.token_at_offset(offset)
@@ -142,7 +142,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
142 pub fn ancestors_at_offset_with_macros( 142 pub fn ancestors_at_offset_with_macros(
143 &self, 143 &self,
144 node: &SyntaxNode, 144 node: &SyntaxNode,
145 offset: TextUnit, 145 offset: TextSize,
146 ) -> impl Iterator<Item = SyntaxNode> + '_ { 146 ) -> impl Iterator<Item = SyntaxNode> + '_ {
147 node.token_at_offset(offset) 147 node.token_at_offset(offset)
148 .map(|token| self.ancestors_with_macros(token.parent())) 148 .map(|token| self.ancestors_with_macros(token.parent()))
@@ -154,7 +154,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
154 pub fn find_node_at_offset_with_macros<N: AstNode>( 154 pub fn find_node_at_offset_with_macros<N: AstNode>(
155 &self, 155 &self,
156 node: &SyntaxNode, 156 node: &SyntaxNode,
157 offset: TextUnit, 157 offset: TextSize,
158 ) -> Option<N> { 158 ) -> Option<N> {
159 self.ancestors_at_offset_with_macros(node, offset).find_map(N::cast) 159 self.ancestors_at_offset_with_macros(node, offset).find_map(N::cast)
160 } 160 }
@@ -164,7 +164,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
164 pub fn find_node_at_offset_with_descend<N: AstNode>( 164 pub fn find_node_at_offset_with_descend<N: AstNode>(
165 &self, 165 &self,
166 node: &SyntaxNode, 166 node: &SyntaxNode,
167 offset: TextUnit, 167 offset: TextSize,
168 ) -> Option<N> { 168 ) -> Option<N> {
169 if let Some(it) = find_node_at_offset(&node, offset) { 169 if let Some(it) = find_node_at_offset(&node, offset) {
170 return Some(it); 170 return Some(it);
@@ -184,18 +184,15 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
184 self.analyze(call.syntax()).resolve_method_call(self.db, call) 184 self.analyze(call.syntax()).resolve_method_call(self.db, call)
185 } 185 }
186 186
187 pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<StructField> { 187 pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<Field> {
188 self.analyze(field.syntax()).resolve_field(self.db, field) 188 self.analyze(field.syntax()).resolve_field(self.db, field)
189 } 189 }
190 190
191 pub fn resolve_record_field( 191 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> {
192 &self,
193 field: &ast::RecordField,
194 ) -> Option<(StructField, Option<Local>)> {
195 self.analyze(field.syntax()).resolve_record_field(self.db, field) 192 self.analyze(field.syntax()).resolve_record_field(self.db, field)
196 } 193 }
197 194
198 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<StructField> { 195 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> {
199 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) 196 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field)
200 } 197 }
201 198
@@ -216,19 +213,13 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
216 // FIXME: use this instead? 213 // FIXME: use this instead?
217 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; 214 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
218 215
219 pub fn record_literal_missing_fields( 216 pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> {
220 &self,
221 literal: &ast::RecordLit,
222 ) -> Vec<(StructField, Type)> {
223 self.analyze(literal.syntax()) 217 self.analyze(literal.syntax())
224 .record_literal_missing_fields(self.db, literal) 218 .record_literal_missing_fields(self.db, literal)
225 .unwrap_or_default() 219 .unwrap_or_default()
226 } 220 }
227 221
228 pub fn record_pattern_missing_fields( 222 pub fn record_pattern_missing_fields(&self, pattern: &ast::RecordPat) -> Vec<(Field, Type)> {
229 &self,
230 pattern: &ast::RecordPat,
231 ) -> Vec<(StructField, Type)> {
232 self.analyze(pattern.syntax()) 223 self.analyze(pattern.syntax())
233 .record_pattern_missing_fields(self.db, pattern) 224 .record_pattern_missing_fields(self.db, pattern)
234 .unwrap_or_default() 225 .unwrap_or_default()
@@ -255,7 +246,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
255 SemanticsScope { db: self.db, resolver } 246 SemanticsScope { db: self.db, resolver }
256 } 247 }
257 248
258 pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextUnit) -> SemanticsScope<'db, DB> { 249 pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db, DB> {
259 let node = self.find_file(node.clone()); 250 let node = self.find_file(node.clone());
260 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; 251 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
261 SemanticsScope { db: self.db, resolver } 252 SemanticsScope { db: self.db, resolver }
@@ -271,7 +262,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
271 self.analyze2(src.as_ref(), None) 262 self.analyze2(src.as_ref(), None)
272 } 263 }
273 264
274 fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextUnit>) -> SourceAnalyzer { 265 fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextSize>) -> SourceAnalyzer {
275 let _p = profile("Semantics::analyze2"); 266 let _p = profile("Semantics::analyze2");
276 267
277 let container = match self.with_ctx(|ctx| ctx.find_container(src)) { 268 let container = match self.with_ctx(|ctx| ctx.find_container(src)) {
@@ -359,8 +350,8 @@ to_def_impls![
359 (crate::Const, ast::ConstDef, const_to_def), 350 (crate::Const, ast::ConstDef, const_to_def),
360 (crate::Static, ast::StaticDef, static_to_def), 351 (crate::Static, ast::StaticDef, static_to_def),
361 (crate::Function, ast::FnDef, fn_to_def), 352 (crate::Function, ast::FnDef, fn_to_def),
362 (crate::StructField, ast::RecordFieldDef, record_field_to_def), 353 (crate::Field, ast::RecordFieldDef, record_field_to_def),
363 (crate::StructField, ast::TupleFieldDef, tuple_field_to_def), 354 (crate::Field, ast::TupleFieldDef, tuple_field_to_def),
364 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), 355 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def),
365 (crate::TypeParam, ast::TypeParam, type_param_to_def), 356 (crate::TypeParam, ast::TypeParam, type_param_to_def),
366 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros 357 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros
@@ -463,7 +454,7 @@ fn original_range_opt(
463 return None; 454 return None;
464 } 455 }
465 456
466 Some(first.with_value(first.value.text_range().extend_to(&last.value.text_range()))) 457 Some(first.with_value(first.value.text_range().cover(last.value.text_range())))
467 })?) 458 })?)
468} 459}
469 460
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 66724919b..6f3b5b2da 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -5,8 +5,8 @@ use hir_def::{
5 dyn_map::DynMap, 5 dyn_map::DynMap,
6 expr::PatId, 6 expr::PatId,
7 keys::{self, Key}, 7 keys::{self, Key},
8 ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, 8 ConstId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId, GenericDefId, ImplId,
9 StaticId, StructFieldId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, 9 ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
10}; 10};
11use hir_expand::{name::AsName, AstId, MacroDefKind}; 11use hir_expand::{name::AsName, AstId, MacroDefKind};
12use ra_db::FileId; 12use ra_db::FileId;
@@ -97,13 +97,13 @@ impl SourceToDefCtx<'_, '_> {
97 pub(super) fn record_field_to_def( 97 pub(super) fn record_field_to_def(
98 &mut self, 98 &mut self,
99 src: InFile<ast::RecordFieldDef>, 99 src: InFile<ast::RecordFieldDef>,
100 ) -> Option<StructFieldId> { 100 ) -> Option<FieldId> {
101 self.to_def(src, keys::RECORD_FIELD) 101 self.to_def(src, keys::RECORD_FIELD)
102 } 102 }
103 pub(super) fn tuple_field_to_def( 103 pub(super) fn tuple_field_to_def(
104 &mut self, 104 &mut self,
105 src: InFile<ast::TupleFieldDef>, 105 src: InFile<ast::TupleFieldDef>,
106 ) -> Option<StructFieldId> { 106 ) -> Option<FieldId> {
107 self.to_def(src, keys::TUPLE_FIELD) 107 self.to_def(src, keys::TUPLE_FIELD)
108 } 108 }
109 pub(super) fn enum_variant_to_def( 109 pub(super) fn enum_variant_to_def(
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 0ed6d0958..74d64c97d 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -14,7 +14,7 @@ use hir_def::{
14 }, 14 },
15 expr::{ExprId, Pat, PatId}, 15 expr::{ExprId, Pat, PatId},
16 resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs}, 16 resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs},
17 AsMacroCall, DefWithBodyId, LocalStructFieldId, StructFieldId, VariantId, 17 AsMacroCall, DefWithBodyId, FieldId, LocalFieldId, VariantId,
18}; 18};
19use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; 19use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
20use hir_ty::{ 20use hir_ty::{
@@ -23,12 +23,12 @@ use hir_ty::{
23}; 23};
24use ra_syntax::{ 24use ra_syntax::{
25 ast::{self, AstNode}, 25 ast::{self, AstNode},
26 SyntaxNode, TextRange, TextUnit, 26 SyntaxNode, TextRange, TextSize,
27}; 27};
28 28
29use crate::{ 29use crate::{
30 db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Function, Local, MacroDef, 30 db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Field, Function, Local,
31 ModPath, ModuleDef, Path, PathKind, Static, Struct, StructField, Trait, Type, TypeAlias, 31 MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias,
32 TypeParam, 32 TypeParam,
33}; 33};
34use ra_db::CrateId; 34use ra_db::CrateId;
@@ -50,7 +50,7 @@ impl SourceAnalyzer {
50 db: &dyn HirDatabase, 50 db: &dyn HirDatabase,
51 def: DefWithBodyId, 51 def: DefWithBodyId,
52 node: InFile<&SyntaxNode>, 52 node: InFile<&SyntaxNode>,
53 offset: Option<TextUnit>, 53 offset: Option<TextSize>,
54 ) -> SourceAnalyzer { 54 ) -> SourceAnalyzer {
55 let (body, source_map) = db.body_with_source_map(def); 55 let (body, source_map) = db.body_with_source_map(def);
56 let scopes = db.expr_scopes(def); 56 let scopes = db.expr_scopes(def);
@@ -140,7 +140,7 @@ impl SourceAnalyzer {
140 &self, 140 &self,
141 db: &dyn HirDatabase, 141 db: &dyn HirDatabase,
142 field: &ast::FieldExpr, 142 field: &ast::FieldExpr,
143 ) -> Option<StructField> { 143 ) -> Option<Field> {
144 let expr_id = self.expr_id(db, &field.clone().into())?; 144 let expr_id = self.expr_id(db, &field.clone().into())?;
145 self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) 145 self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into())
146 } 146 }
@@ -149,7 +149,7 @@ impl SourceAnalyzer {
149 &self, 149 &self,
150 db: &dyn HirDatabase, 150 db: &dyn HirDatabase,
151 field: &ast::RecordField, 151 field: &ast::RecordField,
152 ) -> Option<(StructField, Option<Local>)> { 152 ) -> Option<(Field, Option<Local>)> {
153 let expr = field.expr()?; 153 let expr = field.expr()?;
154 let expr_id = self.expr_id(db, &expr)?; 154 let expr_id = self.expr_id(db, &expr)?;
155 let local = if field.name_ref().is_some() { 155 let local = if field.name_ref().is_some() {
@@ -172,7 +172,7 @@ impl SourceAnalyzer {
172 &self, 172 &self,
173 _db: &dyn HirDatabase, 173 _db: &dyn HirDatabase,
174 field: &ast::RecordFieldPat, 174 field: &ast::RecordFieldPat,
175 ) -> Option<StructField> { 175 ) -> Option<Field> {
176 let pat_id = self.pat_id(&field.pat()?)?; 176 let pat_id = self.pat_id(&field.pat()?)?;
177 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; 177 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?;
178 Some(struct_field.into()) 178 Some(struct_field.into())
@@ -232,7 +232,7 @@ impl SourceAnalyzer {
232 &self, 232 &self,
233 db: &dyn HirDatabase, 233 db: &dyn HirDatabase,
234 literal: &ast::RecordLit, 234 literal: &ast::RecordLit,
235 ) -> Option<Vec<(StructField, Type)>> { 235 ) -> Option<Vec<(Field, Type)>> {
236 let krate = self.resolver.krate()?; 236 let krate = self.resolver.krate()?;
237 let body = self.body.as_ref()?; 237 let body = self.body.as_ref()?;
238 let infer = self.infer.as_ref()?; 238 let infer = self.infer.as_ref()?;
@@ -253,7 +253,7 @@ impl SourceAnalyzer {
253 &self, 253 &self,
254 db: &dyn HirDatabase, 254 db: &dyn HirDatabase,
255 pattern: &ast::RecordPat, 255 pattern: &ast::RecordPat,
256 ) -> Option<Vec<(StructField, Type)>> { 256 ) -> Option<Vec<(Field, Type)>> {
257 let krate = self.resolver.krate()?; 257 let krate = self.resolver.krate()?;
258 let body = self.body.as_ref()?; 258 let body = self.body.as_ref()?;
259 let infer = self.infer.as_ref()?; 259 let infer = self.infer.as_ref()?;
@@ -276,14 +276,14 @@ impl SourceAnalyzer {
276 krate: CrateId, 276 krate: CrateId,
277 substs: &Substs, 277 substs: &Substs,
278 variant: VariantId, 278 variant: VariantId,
279 missing_fields: Vec<LocalStructFieldId>, 279 missing_fields: Vec<LocalFieldId>,
280 ) -> Vec<(StructField, Type)> { 280 ) -> Vec<(Field, Type)> {
281 let field_types = db.field_types(variant); 281 let field_types = db.field_types(variant);
282 282
283 missing_fields 283 missing_fields
284 .into_iter() 284 .into_iter()
285 .map(|local_id| { 285 .map(|local_id| {
286 let field = StructFieldId { parent: variant, local_id }; 286 let field = FieldId { parent: variant, local_id };
287 let ty = field_types[local_id].clone().subst(substs); 287 let ty = field_types[local_id].clone().subst(substs);
288 (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) 288 (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty))
289 }) 289 })
@@ -318,7 +318,7 @@ fn scope_for_offset(
318 db: &dyn HirDatabase, 318 db: &dyn HirDatabase,
319 scopes: &ExprScopes, 319 scopes: &ExprScopes,
320 source_map: &BodySourceMap, 320 source_map: &BodySourceMap,
321 offset: InFile<TextUnit>, 321 offset: InFile<TextSize>,
322) -> Option<ScopeId> { 322) -> Option<ScopeId> {
323 scopes 323 scopes
324 .scope_by_expr() 324 .scope_by_expr()
@@ -354,7 +354,7 @@ fn adjust(
354 source_map: &BodySourceMap, 354 source_map: &BodySourceMap,
355 expr_range: TextRange, 355 expr_range: TextRange,
356 file_id: HirFileId, 356 file_id: HirFileId,
357 offset: TextUnit, 357 offset: TextSize,
358) -> Option<ScopeId> { 358) -> Option<ScopeId> {
359 let child_scopes = scopes 359 let child_scopes = scopes
360 .scope_by_expr() 360 .scope_by_expr()
@@ -369,15 +369,15 @@ fn adjust(
369 let node = source.value.to_node(&root); 369 let node = source.value.to_node(&root);
370 Some((node.syntax().text_range(), scope)) 370 Some((node.syntax().text_range(), scope))
371 }) 371 })
372 .filter(|(range, _)| { 372 .filter(|&(range, _)| {
373 range.start() <= offset && range.is_subrange(&expr_range) && *range != expr_range 373 range.start() <= offset && expr_range.contains_range(range) && range != expr_range
374 }); 374 });
375 375
376 child_scopes 376 child_scopes
377 .max_by(|(r1, _), (r2, _)| { 377 .max_by(|&(r1, _), &(r2, _)| {
378 if r2.is_subrange(&r1) { 378 if r1.contains_range(r2) {
379 std::cmp::Ordering::Greater 379 std::cmp::Ordering::Greater
380 } else if r1.is_subrange(&r2) { 380 } else if r2.contains_range(r1) {
381 std::cmp::Ordering::Less 381 std::cmp::Ordering::Less
382 } else { 382 } else {
383 r1.start().cmp(&r2.start()) 383 r1.start().cmp(&r2.start())
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 7c0d93691..753becc3d 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -14,7 +14,7 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner};
14use crate::{ 14use crate::{
15 body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, 15 body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace,
16 type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, 16 type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId,
17 LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, 17 LocalFieldId, Lookup, ModuleId, StructId, UnionId, VariantId,
18}; 18};
19 19
20/// Note that we use `StructData` for unions as well! 20/// Note that we use `StructData` for unions as well!
@@ -38,14 +38,14 @@ pub struct EnumVariantData {
38 38
39#[derive(Debug, Clone, PartialEq, Eq)] 39#[derive(Debug, Clone, PartialEq, Eq)]
40pub enum VariantData { 40pub enum VariantData {
41 Record(Arena<StructFieldData>), 41 Record(Arena<FieldData>),
42 Tuple(Arena<StructFieldData>), 42 Tuple(Arena<FieldData>),
43 Unit, 43 Unit,
44} 44}
45 45
46/// A single field of an enum variant or struct 46/// A single field of an enum variant or struct
47#[derive(Debug, Clone, PartialEq, Eq)] 47#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct StructFieldData { 48pub struct FieldData {
49 pub name: Name, 49 pub name: Name,
50 pub type_ref: TypeRef, 50 pub type_ref: TypeRef,
51 pub visibility: RawVisibility, 51 pub visibility: RawVisibility,
@@ -133,15 +133,15 @@ impl VariantData {
133 } 133 }
134 } 134 }
135 135
136 pub fn fields(&self) -> &Arena<StructFieldData> { 136 pub fn fields(&self) -> &Arena<FieldData> {
137 const EMPTY: &Arena<StructFieldData> = &Arena::new(); 137 const EMPTY: &Arena<FieldData> = &Arena::new();
138 match &self { 138 match &self {
139 VariantData::Record(fields) | VariantData::Tuple(fields) => fields, 139 VariantData::Record(fields) | VariantData::Tuple(fields) => fields,
140 _ => EMPTY, 140 _ => EMPTY,
141 } 141 }
142 } 142 }
143 143
144 pub fn field(&self, name: &Name) -> Option<LocalStructFieldId> { 144 pub fn field(&self, name: &Name) -> Option<LocalFieldId> {
145 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None }) 145 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None })
146 } 146 }
147 147
@@ -155,7 +155,7 @@ impl VariantData {
155} 155}
156 156
157impl HasChildSource for VariantId { 157impl HasChildSource for VariantId {
158 type ChildId = LocalStructFieldId; 158 type ChildId = LocalFieldId;
159 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; 159 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>;
160 160
161 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 161 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
@@ -195,7 +195,7 @@ pub enum StructKind {
195fn lower_struct( 195fn lower_struct(
196 db: &dyn DefDatabase, 196 db: &dyn DefDatabase,
197 expander: &mut CfgExpander, 197 expander: &mut CfgExpander,
198 trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, 198 trace: &mut Trace<FieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>,
199 ast: &InFile<ast::StructKind>, 199 ast: &InFile<ast::StructKind>,
200) -> StructKind { 200) -> StructKind {
201 match &ast.value { 201 match &ast.value {
@@ -208,7 +208,7 @@ fn lower_struct(
208 208
209 trace.alloc( 209 trace.alloc(
210 || Either::Left(fd.clone()), 210 || Either::Left(fd.clone()),
211 || StructFieldData { 211 || FieldData {
212 name: Name::new_tuple_field(i), 212 name: Name::new_tuple_field(i),
213 type_ref: TypeRef::from_ast_opt(fd.type_ref()), 213 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
214 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 214 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
@@ -226,7 +226,7 @@ fn lower_struct(
226 226
227 trace.alloc( 227 trace.alloc(
228 || Either::Right(fd.clone()), 228 || Either::Right(fd.clone()),
229 || StructFieldData { 229 || FieldData {
230 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 230 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
231 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), 231 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
232 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 232 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 2f2e3e5ba..5a86af8ba 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -13,7 +13,8 @@ use ra_syntax::{
13use tt::Subtree; 13use tt::Subtree;
14 14
15use crate::{ 15use crate::{
16 db::DefDatabase, path::ModPath, src::HasChildSource, src::HasSource, AdtId, AttrDefId, Lookup, 16 db::DefDatabase, nameres::ModuleSource, path::ModPath, src::HasChildSource, src::HasSource,
17 AdtId, AttrDefId, Lookup,
17}; 18};
18 19
19#[derive(Default, Debug, Clone, PartialEq, Eq)] 20#[derive(Default, Debug, Clone, PartialEq, Eq)]
@@ -37,13 +38,21 @@ impl Attrs {
37 match def { 38 match def {
38 AttrDefId::ModuleId(module) => { 39 AttrDefId::ModuleId(module) => {
39 let def_map = db.crate_def_map(module.krate); 40 let def_map = db.crate_def_map(module.krate);
40 let src = match def_map[module.local_id].declaration_source(db) { 41 let mod_data = &def_map[module.local_id];
41 Some(it) => it, 42 match mod_data.declaration_source(db) {
42 None => return Attrs::default(), 43 Some(it) => {
43 }; 44 Attrs::from_attrs_owner(db, it.as_ref().map(|it| it as &dyn AttrsOwner))
44 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) 45 }
46 None => Attrs::from_attrs_owner(
47 db,
48 mod_data.definition_source(db).as_ref().map(|src| match src {
49 ModuleSource::SourceFile(file) => file as &dyn AttrsOwner,
50 ModuleSource::Module(module) => module as &dyn AttrsOwner,
51 }),
52 ),
53 }
45 } 54 }
46 AttrDefId::StructFieldId(it) => { 55 AttrDefId::FieldId(it) => {
47 let src = it.parent.child_source(db); 56 let src = it.parent.child_source(db);
48 match &src.value[it.local_id] { 57 match &src.value[it.local_id] {
49 Either::Left(_tuple) => Attrs::default(), 58 Either::Left(_tuple) => Attrs::default(),
@@ -106,7 +115,9 @@ pub struct Attr {
106 115
107#[derive(Debug, Clone, PartialEq, Eq)] 116#[derive(Debug, Clone, PartialEq, Eq)]
108pub enum AttrInput { 117pub enum AttrInput {
118 /// `#[attr = "string"]`
109 Literal(SmolStr), 119 Literal(SmolStr),
120 /// `#[attr(subtree)]`
110 TokenTree(Subtree), 121 TokenTree(Subtree),
111} 122}
112 123
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index 5b36a7cc1..86f953c80 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -194,7 +194,7 @@ mod tests {
194 let (off, code) = extract_offset(code); 194 let (off, code) = extract_offset(code);
195 let code = { 195 let code = {
196 let mut buf = String::new(); 196 let mut buf = String::new();
197 let off = off.to_usize(); 197 let off: usize = off.into();
198 buf.push_str(&code[..off]); 198 buf.push_str(&code[..off]);
199 buf.push_str("marker"); 199 buf.push_str("marker");
200 buf.push_str(&code[off..]); 200 buf.push_str(&code[off..]);
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index 7009f21d1..a885ec96d 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -12,8 +12,8 @@ use crate::{
12 item_scope::ItemScope, 12 item_scope::ItemScope,
13 keys, 13 keys,
14 src::{HasChildSource, HasSource}, 14 src::{HasChildSource, HasSource},
15 AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, ImplId, Lookup, ModuleDefId, 15 AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, FieldId, ImplId, Lookup, ModuleDefId,
16 ModuleId, StructFieldId, TraitId, VariantId, 16 ModuleId, TraitId, VariantId,
17}; 17};
18 18
19pub trait ChildBySource { 19pub trait ChildBySource {
@@ -140,7 +140,7 @@ impl ChildBySource for VariantId {
140 let arena_map = self.child_source(db); 140 let arena_map = self.child_source(db);
141 let arena_map = arena_map.as_ref(); 141 let arena_map = arena_map.as_ref();
142 for (local_id, source) in arena_map.value.iter() { 142 for (local_id, source) in arena_map.value.iter() {
143 let id = StructFieldId { parent: *self, local_id }; 143 let id = FieldId { parent: *self, local_id };
144 match source { 144 match source {
145 Either::Left(source) => { 145 Either::Left(source) => {
146 res[keys::TUPLE_FIELD].insert(arena_map.with_value(source.clone()), id) 146 res[keys::TUPLE_FIELD].insert(arena_map.with_value(source.clone()), id)
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 0539a77d4..b221ae1ce 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -43,7 +43,7 @@ impl Documentation {
43 let src = def_map[module.local_id].declaration_source(db)?; 43 let src = def_map[module.local_id].declaration_source(db)?;
44 docs_from_ast(&src.value) 44 docs_from_ast(&src.value)
45 } 45 }
46 AttrDefId::StructFieldId(it) => { 46 AttrDefId::FieldId(it) => {
47 let src = it.parent.child_source(db); 47 let src = it.parent.child_source(db);
48 match &src.value[it.local_id] { 48 match &src.value[it.local_id] {
49 Either::Left(_tuple) => None, 49 Either::Left(_tuple) => None,
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 81eff5bfe..70dcb03e6 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -19,7 +19,7 @@ impl ModPath {
19 19
20 // When std library is present, paths starting with `std::` 20 // When std library is present, paths starting with `std::`
21 // should be preferred over paths starting with `core::` and `alloc::` 21 // should be preferred over paths starting with `core::` and `alloc::`
22 fn should_start_with_std(&self) -> bool { 22 fn can_start_with_std(&self) -> bool {
23 self.segments 23 self.segments
24 .first() 24 .first()
25 .filter(|&first_segment| { 25 .filter(|&first_segment| {
@@ -132,6 +132,9 @@ fn find_path_inner(
132 } 132 }
133 133
134 // - otherwise, look for modules containing (reexporting) it and import it from one of those 134 // - otherwise, look for modules containing (reexporting) it and import it from one of those
135 let crate_root = ModuleId { local_id: def_map.root, krate: from.krate };
136 let crate_attrs = db.attrs(crate_root.into());
137 let prefer_no_std = crate_attrs.by_key("no_std").exists();
135 let importable_locations = find_importable_locations(db, item, from); 138 let importable_locations = find_importable_locations(db, item, from);
136 let mut best_path = None; 139 let mut best_path = None;
137 let mut best_path_len = max_len; 140 let mut best_path_len = max_len;
@@ -147,21 +150,32 @@ fn find_path_inner(
147 }; 150 };
148 path.segments.push(name); 151 path.segments.push(name);
149 152
150 let new_path = 153 let new_path = if let Some(best_path) = best_path {
151 if let Some(best_path) = best_path { select_best_path(best_path, path) } else { path }; 154 select_best_path(best_path, path, prefer_no_std)
155 } else {
156 path
157 };
152 best_path_len = new_path.len(); 158 best_path_len = new_path.len();
153 best_path = Some(new_path); 159 best_path = Some(new_path);
154 } 160 }
155 best_path 161 best_path
156} 162}
157 163
158fn select_best_path(old_path: ModPath, new_path: ModPath) -> ModPath { 164fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath {
159 if old_path.starts_with_std() && new_path.should_start_with_std() { 165 if old_path.starts_with_std() && new_path.can_start_with_std() {
160 tested_by!(prefer_std_paths); 166 tested_by!(prefer_std_paths);
161 old_path 167 if prefer_no_std {
162 } else if new_path.starts_with_std() && old_path.should_start_with_std() { 168 new_path
169 } else {
170 old_path
171 }
172 } else if new_path.starts_with_std() && old_path.can_start_with_std() {
163 tested_by!(prefer_std_paths); 173 tested_by!(prefer_std_paths);
164 new_path 174 if prefer_no_std {
175 old_path
176 } else {
177 new_path
178 }
165 } else if new_path.len() < old_path.len() { 179 } else if new_path.len() < old_path.len() {
166 new_path 180 new_path
167 } else { 181 } else {
@@ -513,6 +527,54 @@ mod tests {
513 } 527 }
514 528
515 #[test] 529 #[test]
530 fn prefer_alloc_paths_over_std() {
531 covers!(prefer_std_paths);
532 let code = r#"
533 //- /main.rs crate:main deps:alloc,std
534 #![no_std]
535
536 <|>
537
538 //- /std.rs crate:std deps:alloc
539
540 pub mod sync {
541 pub use alloc::sync::Arc;
542 }
543
544 //- /zzz.rs crate:alloc
545
546 pub mod sync {
547 pub struct Arc;
548 }
549 "#;
550 check_found_path(code, "alloc::sync::Arc");
551 }
552
553 #[test]
554 fn prefer_core_paths_over_std() {
555 covers!(prefer_std_paths);
556 let code = r#"
557 //- /main.rs crate:main deps:core,std
558 #![no_std]
559
560 <|>
561
562 //- /std.rs crate:std deps:core
563
564 pub mod fmt {
565 pub use core::fmt::Error;
566 }
567
568 //- /zzz.rs crate:core
569
570 pub mod fmt {
571 pub struct Error;
572 }
573 "#;
574 check_found_path(code, "core::fmt::Error");
575 }
576
577 #[test]
516 fn prefer_shorter_paths_if_not_alloc() { 578 fn prefer_shorter_paths_if_not_alloc() {
517 let code = r#" 579 let code = r#"
518 //- /main.rs crate:main deps:megaalloc,std 580 //- /main.rs crate:main deps:megaalloc,std
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index 8cd70eb9a..a7349a21d 100644
--- a/crates/ra_hir_def/src/keys.rs
+++ b/crates/ra_hir_def/src/keys.rs
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
8 8
9use crate::{ 9use crate::{
10 dyn_map::{DynMap, Policy}, 10 dyn_map::{DynMap, Policy},
11 ConstId, EnumId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId, 11 ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, StaticId, StructId, TraitId,
12 TypeAliasId, TypeParamId, UnionId, 12 TypeAliasId, TypeParamId, UnionId,
13}; 13};
14 14
@@ -25,8 +25,8 @@ pub const UNION: Key<ast::UnionDef, UnionId> = Key::new();
25pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new(); 25pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new();
26 26
27pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); 27pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
28pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); 28pub const TUPLE_FIELD: Key<ast::TupleFieldDef, FieldId> = Key::new();
29pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); 29pub const RECORD_FIELD: Key<ast::RecordFieldDef, FieldId> = Key::new();
30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); 30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new();
31 31
32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new(); 32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new();
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 2d27bbdf8..518772e8a 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -133,12 +133,12 @@ pub struct EnumVariantId {
133pub type LocalEnumVariantId = Idx<adt::EnumVariantData>; 133pub type LocalEnumVariantId = Idx<adt::EnumVariantData>;
134 134
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
136pub struct StructFieldId { 136pub struct FieldId {
137 pub parent: VariantId, 137 pub parent: VariantId,
138 pub local_id: LocalStructFieldId, 138 pub local_id: LocalFieldId,
139} 139}
140 140
141pub type LocalStructFieldId = Idx<adt::StructFieldData>; 141pub type LocalFieldId = Idx<adt::FieldData>;
142 142
143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
144pub struct ConstId(salsa::InternId); 144pub struct ConstId(salsa::InternId);
@@ -299,7 +299,7 @@ impl From<AssocItemId> for GenericDefId {
299#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 299#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
300pub enum AttrDefId { 300pub enum AttrDefId {
301 ModuleId(ModuleId), 301 ModuleId(ModuleId),
302 StructFieldId(StructFieldId), 302 FieldId(FieldId),
303 AdtId(AdtId), 303 AdtId(AdtId),
304 FunctionId(FunctionId), 304 FunctionId(FunctionId),
305 EnumVariantId(EnumVariantId), 305 EnumVariantId(EnumVariantId),
@@ -313,7 +313,7 @@ pub enum AttrDefId {
313 313
314impl_froms!( 314impl_froms!(
315 AttrDefId: ModuleId, 315 AttrDefId: ModuleId,
316 StructFieldId, 316 FieldId,
317 AdtId(StructId, EnumId, UnionId), 317 AdtId(StructId, EnumId, UnionId),
318 EnumVariantId, 318 EnumVariantId,
319 StaticId, 319 StaticId,
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 3da137f2e..e0fef613d 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -2,7 +2,7 @@
2use crate::db::AstDatabase; 2use crate::db::AstDatabase;
3use crate::{ 3use crate::{
4 ast::{self, AstToken, HasStringValue}, 4 ast::{self, AstToken, HasStringValue},
5 name, AstId, CrateId, MacroDefId, MacroDefKind, TextUnit, 5 name, AstId, CrateId, MacroDefId, MacroDefKind, TextSize,
6}; 6};
7 7
8use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; 8use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId};
@@ -127,7 +127,7 @@ fn stringify_expand(
127 let arg = loc.kind.arg(db).ok_or_else(|| mbe::ExpandError::UnexpectedToken)?; 127 let arg = loc.kind.arg(db).ok_or_else(|| mbe::ExpandError::UnexpectedToken)?;
128 let macro_args = arg; 128 let macro_args = arg;
129 let text = macro_args.text(); 129 let text = macro_args.text();
130 let without_parens = TextUnit::of_char('(')..text.len() - TextUnit::of_char(')'); 130 let without_parens = TextSize::of('(')..text.len() - TextSize::of(')');
131 text.slice(without_parens).to_string() 131 text.slice(without_parens).to_string()
132 }; 132 };
133 133
@@ -358,7 +358,7 @@ fn env_expand(
358 // However, we cannot use an empty string here, because for 358 // However, we cannot use an empty string here, because for
359 // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become 359 // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become
360 // `include!("foo.rs"), which might go to infinite loop 360 // `include!("foo.rs"), which might go to infinite loop
361 let s = get_env_inner(db, arg_id, &key).unwrap_or("__RA_UNIMPLEMENTATED__".to_string()); 361 let s = get_env_inner(db, arg_id, &key).unwrap_or_else(|| "__RA_UNIMPLEMENTATED__".to_string());
362 let expanded = quote! { #s }; 362 let expanded = quote! { #s };
363 363
364 Ok((expanded, FragmentKind::Expr)) 364 Ok((expanded, FragmentKind::Expr))
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 86299459f..754a0f005 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -22,7 +22,7 @@ use ra_db::{impl_intern_key, salsa, CrateId, FileId};
22use ra_syntax::{ 22use ra_syntax::{
23 algo, 23 algo,
24 ast::{self, AstNode}, 24 ast::{self, AstNode},
25 SyntaxNode, SyntaxToken, TextUnit, 25 SyntaxNode, SyntaxToken, TextSize,
26}; 26};
27 27
28use crate::ast_id_map::FileAstId; 28use crate::ast_id_map::FileAstId;
@@ -348,7 +348,7 @@ impl<N: AstNode> AstId<N> {
348/// 348///
349/// * `InFile<SyntaxNode>` -- syntax node in a file 349/// * `InFile<SyntaxNode>` -- syntax node in a file
350/// * `InFile<ast::FnDef>` -- ast node in a file 350/// * `InFile<ast::FnDef>` -- ast node in a file
351/// * `InFile<TextUnit>` -- offset in a file 351/// * `InFile<TextSize>` -- offset in a file
352#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] 352#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
353pub struct InFile<T> { 353pub struct InFile<T> {
354 pub file_id: HirFileId, 354 pub file_id: HirFileId,
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs
index 9e5dfeab3..fdb49560b 100644
--- a/crates/ra_hir_ty/src/db.rs
+++ b/crates/ra_hir_ty/src/db.rs
@@ -3,7 +3,7 @@
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{ 5use hir_def::{
6 db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, TypeParamId, 6 db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalFieldId, TraitId, TypeParamId,
7 VariantId, 7 VariantId,
8}; 8};
9use ra_arena::map::ArenaMap; 9use ra_arena::map::ArenaMap;
@@ -43,7 +43,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
43 fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>; 43 fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
44 44
45 #[salsa::invoke(crate::lower::field_types_query)] 45 #[salsa::invoke(crate::lower::field_types_query)]
46 fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>>; 46 fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>>;
47 47
48 #[salsa::invoke(crate::callable_item_sig)] 48 #[salsa::invoke(crate::callable_item_sig)]
49 fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig; 49 fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig;
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index fd59f4320..f04968e14 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -24,7 +24,7 @@ pub use hir_def::{
24 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, 24 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp,
25 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp, 25 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp,
26 }, 26 },
27 LocalStructFieldId, VariantId, 27 LocalFieldId, VariantId,
28}; 28};
29 29
30pub struct ExprValidator<'a, 'b: 'a> { 30pub struct ExprValidator<'a, 'b: 'a> {
@@ -83,7 +83,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
83 id: ExprId, 83 id: ExprId,
84 db: &dyn HirDatabase, 84 db: &dyn HirDatabase,
85 variant_def: VariantId, 85 variant_def: VariantId,
86 missed_fields: Vec<LocalStructFieldId>, 86 missed_fields: Vec<LocalFieldId>,
87 ) { 87 ) {
88 // XXX: only look at source_map if we do have missing fields 88 // XXX: only look at source_map if we do have missing fields
89 let (_, source_map) = db.body_with_source_map(self.func.into()); 89 let (_, source_map) = db.body_with_source_map(self.func.into());
@@ -112,7 +112,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
112 id: PatId, 112 id: PatId,
113 db: &dyn HirDatabase, 113 db: &dyn HirDatabase,
114 variant_def: VariantId, 114 variant_def: VariantId,
115 missed_fields: Vec<LocalStructFieldId>, 115 missed_fields: Vec<LocalFieldId>,
116 ) { 116 ) {
117 // XXX: only look at source_map if we do have missing fields 117 // XXX: only look at source_map if we do have missing fields
118 let (_, source_map) = db.body_with_source_map(self.func.into()); 118 let (_, source_map) = db.body_with_source_map(self.func.into());
@@ -256,7 +256,7 @@ pub fn record_literal_missing_fields(
256 infer: &InferenceResult, 256 infer: &InferenceResult,
257 id: ExprId, 257 id: ExprId,
258 expr: &Expr, 258 expr: &Expr,
259) -> Option<(VariantId, Vec<LocalStructFieldId>, /*exhaustive*/ bool)> { 259) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
260 let (fields, exhausitve) = match expr { 260 let (fields, exhausitve) = match expr {
261 Expr::RecordLit { path: _, fields, spread } => (fields, spread.is_none()), 261 Expr::RecordLit { path: _, fields, spread } => (fields, spread.is_none()),
262 _ => return None, 262 _ => return None,
@@ -270,7 +270,7 @@ pub fn record_literal_missing_fields(
270 let variant_data = variant_data(db.upcast(), variant_def); 270 let variant_data = variant_data(db.upcast(), variant_def);
271 271
272 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 272 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
273 let missed_fields: Vec<LocalStructFieldId> = variant_data 273 let missed_fields: Vec<LocalFieldId> = variant_data
274 .fields() 274 .fields()
275 .iter() 275 .iter()
276 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) }) 276 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
@@ -286,7 +286,7 @@ pub fn record_pattern_missing_fields(
286 infer: &InferenceResult, 286 infer: &InferenceResult,
287 id: PatId, 287 id: PatId,
288 pat: &Pat, 288 pat: &Pat,
289) -> Option<(VariantId, Vec<LocalStructFieldId>, /*exhaustive*/ bool)> { 289) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
290 let (fields, exhaustive) = match pat { 290 let (fields, exhaustive) = match pat {
291 Pat::Record { path: _, args, ellipsis } => (args, !ellipsis), 291 Pat::Record { path: _, args, ellipsis } => (args, !ellipsis),
292 _ => return None, 292 _ => return None,
@@ -300,7 +300,7 @@ pub fn record_pattern_missing_fields(
300 let variant_data = variant_data(db.upcast(), variant_def); 300 let variant_data = variant_data(db.upcast(), variant_def);
301 301
302 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 302 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
303 let missed_fields: Vec<LocalStructFieldId> = variant_data 303 let missed_fields: Vec<LocalFieldId> = variant_data
304 .fields() 304 .fields()
305 .iter() 305 .iter()
306 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) }) 306 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index dfb6a435f..6a53be621 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -28,7 +28,7 @@ use hir_def::{
28 path::{path, Path}, 28 path::{path, Path},
29 resolver::{HasResolver, Resolver, TypeNs}, 29 resolver::{HasResolver, Resolver, TypeNs},
30 type_ref::{Mutability, TypeRef}, 30 type_ref::{Mutability, TypeRef},
31 AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TraitId, TypeAliasId, VariantId, 31 AdtId, AssocItemId, DefWithBodyId, FieldId, FunctionId, TraitId, TypeAliasId, VariantId,
32}; 32};
33use hir_expand::{diagnostics::DiagnosticSink, name::name}; 33use hir_expand::{diagnostics::DiagnosticSink, name::name};
34use ra_arena::map::ArenaMap; 34use ra_arena::map::ArenaMap;
@@ -124,10 +124,10 @@ pub struct InferenceResult {
124 /// For each method call expr, records the function it resolves to. 124 /// For each method call expr, records the function it resolves to.
125 method_resolutions: FxHashMap<ExprId, FunctionId>, 125 method_resolutions: FxHashMap<ExprId, FunctionId>,
126 /// For each field access expr, records the field it resolves to. 126 /// For each field access expr, records the field it resolves to.
127 field_resolutions: FxHashMap<ExprId, StructFieldId>, 127 field_resolutions: FxHashMap<ExprId, FieldId>,
128 /// For each field in record literal, records the field it resolves to. 128 /// For each field in record literal, records the field it resolves to.
129 record_field_resolutions: FxHashMap<ExprId, StructFieldId>, 129 record_field_resolutions: FxHashMap<ExprId, FieldId>,
130 record_field_pat_resolutions: FxHashMap<PatId, StructFieldId>, 130 record_field_pat_resolutions: FxHashMap<PatId, FieldId>,
131 /// For each struct literal, records the variant it resolves to. 131 /// For each struct literal, records the variant it resolves to.
132 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>, 132 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>,
133 /// For each associated item record what it resolves to 133 /// For each associated item record what it resolves to
@@ -142,13 +142,13 @@ impl InferenceResult {
142 pub fn method_resolution(&self, expr: ExprId) -> Option<FunctionId> { 142 pub fn method_resolution(&self, expr: ExprId) -> Option<FunctionId> {
143 self.method_resolutions.get(&expr).copied() 143 self.method_resolutions.get(&expr).copied()
144 } 144 }
145 pub fn field_resolution(&self, expr: ExprId) -> Option<StructFieldId> { 145 pub fn field_resolution(&self, expr: ExprId) -> Option<FieldId> {
146 self.field_resolutions.get(&expr).copied() 146 self.field_resolutions.get(&expr).copied()
147 } 147 }
148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<StructFieldId> { 148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<FieldId> {
149 self.record_field_resolutions.get(&expr).copied() 149 self.record_field_resolutions.get(&expr).copied()
150 } 150 }
151 pub fn record_field_pat_resolution(&self, pat: PatId) -> Option<StructFieldId> { 151 pub fn record_field_pat_resolution(&self, pat: PatId) -> Option<FieldId> {
152 self.record_field_pat_resolutions.get(&pat).copied() 152 self.record_field_pat_resolutions.get(&pat).copied()
153 } 153 }
154 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> { 154 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> {
@@ -249,7 +249,7 @@ impl<'a> InferenceContext<'a> {
249 self.result.method_resolutions.insert(expr, func); 249 self.result.method_resolutions.insert(expr, func);
250 } 250 }
251 251
252 fn write_field_resolution(&mut self, expr: ExprId, field: StructFieldId) { 252 fn write_field_resolution(&mut self, expr: ExprId, field: FieldId) {
253 self.result.field_resolutions.insert(expr, field); 253 self.result.field_resolutions.insert(expr, field);
254 } 254 }
255 255
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 1fdb235a0..83f946eee 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -8,7 +8,7 @@ use hir_def::{
8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
9 path::{GenericArg, GenericArgs}, 9 path::{GenericArg, GenericArgs},
10 resolver::resolver_for_expr, 10 resolver::resolver_for_expr,
11 AdtId, AssocContainerId, Lookup, StructFieldId, 11 AdtId, AssocContainerId, FieldId, Lookup,
12}; 12};
13use hir_expand::name::Name; 13use hir_expand::name::Name;
14use ra_syntax::ast::RangeOp; 14use ra_syntax::ast::RangeOp;
@@ -216,9 +216,7 @@ impl<'a> InferenceContext<'a> {
216 for (field_idx, field) in fields.iter().enumerate() { 216 for (field_idx, field) in fields.iter().enumerate() {
217 let field_def = 217 let field_def =
218 variant_data.as_ref().and_then(|it| match it.field(&field.name) { 218 variant_data.as_ref().and_then(|it| match it.field(&field.name) {
219 Some(local_id) => { 219 Some(local_id) => Some(FieldId { parent: def_id.unwrap(), local_id }),
220 Some(StructFieldId { parent: def_id.unwrap(), local_id })
221 }
222 None => { 220 None => {
223 self.push_diagnostic(InferenceDiagnostic::NoSuchField { 221 self.push_diagnostic(InferenceDiagnostic::NoSuchField {
224 expr: tgt_expr, 222 expr: tgt_expr,
@@ -257,7 +255,7 @@ impl<'a> InferenceContext<'a> {
257 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), 255 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()),
258 TypeCtor::Adt(AdtId::StructId(s)) => { 256 TypeCtor::Adt(AdtId::StructId(s)) => {
259 self.db.struct_data(s).variant_data.field(name).map(|local_id| { 257 self.db.struct_data(s).variant_data.field(name).map(|local_id| {
260 let field = StructFieldId { parent: s.into(), local_id }; 258 let field = FieldId { parent: s.into(), local_id };
261 self.write_field_resolution(tgt_expr, field); 259 self.write_field_resolution(tgt_expr, field);
262 self.db.field_types(s.into())[field.local_id] 260 self.db.field_types(s.into())[field.local_id]
263 .clone() 261 .clone()
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs
index 7c2ad4384..54ec870df 100644
--- a/crates/ra_hir_ty/src/infer/pat.rs
+++ b/crates/ra_hir_ty/src/infer/pat.rs
@@ -7,7 +7,7 @@ use hir_def::{
7 expr::{BindingAnnotation, Pat, PatId, RecordFieldPat}, 7 expr::{BindingAnnotation, Pat, PatId, RecordFieldPat},
8 path::Path, 8 path::Path,
9 type_ref::Mutability, 9 type_ref::Mutability,
10 StructFieldId, 10 FieldId,
11}; 11};
12use hir_expand::name::Name; 12use hir_expand::name::Name;
13use test_utils::tested_by; 13use test_utils::tested_by;
@@ -69,7 +69,7 @@ impl<'a> InferenceContext<'a> {
69 for subpat in subpats { 69 for subpat in subpats {
70 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); 70 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name));
71 if let Some(local_id) = matching_field { 71 if let Some(local_id) = matching_field {
72 let field_def = StructFieldId { parent: def.unwrap(), local_id }; 72 let field_def = FieldId { parent: def.unwrap(), local_id };
73 self.result.record_field_pat_resolutions.insert(subpat.pat, field_def); 73 self.result.record_field_pat_resolutions.insert(subpat.pat, field_def);
74 } 74 }
75 75
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index c2812e178..b57214296 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -18,8 +18,8 @@ use hir_def::{
18 resolver::{HasResolver, Resolver, TypeNs}, 18 resolver::{HasResolver, Resolver, TypeNs},
19 type_ref::{TypeBound, TypeRef}, 19 type_ref::{TypeBound, TypeRef},
20 AdtId, AssocContainerId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule, 20 AdtId, AssocContainerId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule,
21 ImplId, LocalStructFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, 21 ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
22 UnionId, VariantId, 22 VariantId,
23}; 23};
24use ra_arena::map::ArenaMap; 24use ra_arena::map::ArenaMap;
25use ra_db::CrateId; 25use ra_db::CrateId;
@@ -682,7 +682,7 @@ pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig {
682pub(crate) fn field_types_query( 682pub(crate) fn field_types_query(
683 db: &dyn HirDatabase, 683 db: &dyn HirDatabase,
684 variant_id: VariantId, 684 variant_id: VariantId,
685) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>> { 685) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>> {
686 let var_data = variant_data(db.upcast(), variant_id); 686 let var_data = variant_data(db.upcast(), variant_id);
687 let (resolver, def): (_, GenericDefId) = match variant_id { 687 let (resolver, def): (_, GenericDefId) = match variant_id {
688 VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()), 688 VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()),
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index 846005baa..b6a96bb5c 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -117,7 +117,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
117 let macro_prefix = if node.file_id != file_id.into() { "!" } else { "" }; 117 let macro_prefix = if node.file_id != file_id.into() { "!" } else { "" };
118 format_to!( 118 format_to!(
119 buf, 119 buf,
120 "{}{} '{}': {}\n", 120 "{}{:?} '{}': {}\n",
121 macro_prefix, 121 macro_prefix,
122 range, 122 range,
123 ellipsize(text, 15), 123 ellipsize(text, 15),
@@ -134,7 +134,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
134 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; 134 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" };
135 format_to!( 135 format_to!(
136 buf, 136 buf,
137 "{}{}: expected {}, got {}\n", 137 "{}{:?}: expected {}, got {}\n",
138 macro_prefix, 138 macro_prefix,
139 range, 139 range,
140 mismatch.expected.display(&db), 140 mismatch.expected.display(&db),
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs
index b2c971f02..e6fb3e123 100644
--- a/crates/ra_hir_ty/src/tests/coercion.rs
+++ b/crates/ra_hir_ty/src/tests/coercion.rs
@@ -29,10 +29,10 @@ fn test() {
29} 29}
30"#), 30"#),
31 @r###" 31 @r###"
32 [11; 41) '{ ...4 }; }': () 32 11..41 '{ ...4 }; }': ()
33 [21; 22) 'a': i32 33 21..22 'a': i32
34 [30; 38) '{ 1i64 }': i64 34 30..38 '{ 1i64 }': i64
35 [32; 36) '1i64': i64 35 32..36 '1i64': i64
36 "###); 36 "###);
37} 37}
38 38
@@ -63,50 +63,50 @@ fn test2() {
63} 63}
64"#), 64"#),
65 @r###" 65 @r###"
66 [31; 32) '_': &[T] 66 31..32 '_': &[T]
67 [45; 56) '{ loop {} }': T 67 45..56 '{ loop {} }': T
68 [47; 54) 'loop {}': ! 68 47..54 'loop {}': !
69 [52; 54) '{}': () 69 52..54 '{}': ()
70 [65; 66) '_': S<&[T]> 70 65..66 '_': S<&[T]>
71 [82; 93) '{ loop {} }': T 71 82..93 '{ loop {} }': T
72 [84; 91) 'loop {}': ! 72 84..91 'loop {}': !
73 [89; 91) '{}': () 73 89..91 '{}': ()
74 [122; 133) '{ loop {} }': *mut [T; _] 74 122..133 '{ loop {} }': *mut [T; _]
75 [124; 131) 'loop {}': ! 75 124..131 'loop {}': !
76 [129; 131) '{}': () 76 129..131 '{}': ()
77 [160; 173) '{ gen() }': *mut [U] 77 160..173 '{ gen() }': *mut [U]
78 [166; 169) 'gen': fn gen<U>() -> *mut [U; _] 78 166..169 'gen': fn gen<U>() -> *mut [U; _]
79 [166; 171) 'gen()': *mut [U; _] 79 166..171 'gen()': *mut [U; _]
80 [186; 420) '{ ...rr); }': () 80 186..420 '{ ...rr); }': ()
81 [196; 199) 'arr': &[u8; _] 81 196..199 'arr': &[u8; _]
82 [212; 216) '&[1]': &[u8; _] 82 212..216 '&[1]': &[u8; _]
83 [213; 216) '[1]': [u8; _] 83 213..216 '[1]': [u8; _]
84 [214; 215) '1': u8 84 214..215 '1': u8
85 [227; 228) 'a': &[u8] 85 227..228 'a': &[u8]
86 [237; 240) 'arr': &[u8; _] 86 237..240 'arr': &[u8; _]
87 [250; 251) 'b': u8 87 250..251 'b': u8
88 [254; 255) 'f': fn f<u8>(&[u8]) -> u8 88 254..255 'f': fn f<u8>(&[u8]) -> u8
89 [254; 260) 'f(arr)': u8 89 254..260 'f(arr)': u8
90 [256; 259) 'arr': &[u8; _] 90 256..259 'arr': &[u8; _]
91 [270; 271) 'c': &[u8] 91 270..271 'c': &[u8]
92 [280; 287) '{ arr }': &[u8] 92 280..287 '{ arr }': &[u8]
93 [282; 285) 'arr': &[u8; _] 93 282..285 'arr': &[u8; _]
94 [297; 298) 'd': u8 94 297..298 'd': u8
95 [301; 302) 'g': fn g<u8>(S<&[u8]>) -> u8 95 301..302 'g': fn g<u8>(S<&[u8]>) -> u8
96 [301; 316) 'g(S { a: arr })': u8 96 301..316 'g(S { a: arr })': u8
97 [303; 315) 'S { a: arr }': S<&[u8]> 97 303..315 'S { a: arr }': S<&[u8]>
98 [310; 313) 'arr': &[u8; _] 98 310..313 'arr': &[u8; _]
99 [326; 327) 'e': [&[u8]; _] 99 326..327 'e': [&[u8]; _]
100 [341; 346) '[arr]': [&[u8]; _] 100 341..346 '[arr]': [&[u8]; _]
101 [342; 345) 'arr': &[u8; _] 101 342..345 'arr': &[u8; _]
102 [356; 357) 'f': [&[u8]; _] 102 356..357 'f': [&[u8]; _]
103 [371; 379) '[arr; 2]': [&[u8]; _] 103 371..379 '[arr; 2]': [&[u8]; _]
104 [372; 375) 'arr': &[u8; _] 104 372..375 'arr': &[u8; _]
105 [377; 378) '2': usize 105 377..378 '2': usize
106 [389; 390) 'g': (&[u8], &[u8]) 106 389..390 'g': (&[u8], &[u8])
107 [407; 417) '(arr, arr)': (&[u8], &[u8]) 107 407..417 '(arr, arr)': (&[u8], &[u8])
108 [408; 411) 'arr': &[u8; _] 108 408..411 'arr': &[u8; _]
109 [413; 416) 'arr': &[u8; _] 109 413..416 'arr': &[u8; _]
110 "### 110 "###
111 ); 111 );
112} 112}
@@ -120,11 +120,11 @@ fn test() {
120} 120}
121"#), 121"#),
122 @r###" 122 @r###"
123 [11; 40) '{ ...[1]; }': () 123 11..40 '{ ...[1]; }': ()
124 [21; 22) 'x': &[i32] 124 21..22 'x': &[i32]
125 [33; 37) '&[1]': &[i32; _] 125 33..37 '&[1]': &[i32; _]
126 [34; 37) '[1]': [i32; _] 126 34..37 '[1]': [i32; _]
127 [35; 36) '1': i32 127 35..36 '1': i32
128 "###); 128 "###);
129} 129}
130 130
@@ -150,31 +150,31 @@ fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) {
150} 150}
151"#), 151"#),
152 @r###" 152 @r###"
153 [258; 259) 'x': A<[T]> 153 258..259 'x': A<[T]>
154 [279; 284) '{ x }': A<[T]> 154 279..284 '{ x }': A<[T]>
155 [281; 282) 'x': A<[T]> 155 281..282 'x': A<[T]>
156 [296; 297) 'x': B<[T]> 156 296..297 'x': B<[T]>
157 [317; 322) '{ x }': B<[T]> 157 317..322 '{ x }': B<[T]>
158 [319; 320) 'x': B<[T]> 158 319..320 'x': B<[T]>
159 [334; 335) 'x': C<[T]> 159 334..335 'x': C<[T]>
160 [355; 360) '{ x }': C<[T]> 160 355..360 '{ x }': C<[T]>
161 [357; 358) 'x': C<[T]> 161 357..358 'x': C<[T]>
162 [370; 371) 'a': A<[u8; _]> 162 370..371 'a': A<[u8; _]>
163 [385; 386) 'b': B<[u8; _]> 163 385..386 'b': B<[u8; _]>
164 [400; 401) 'c': C<[u8; _]> 164 400..401 'c': C<[u8; _]>
165 [415; 481) '{ ...(c); }': () 165 415..481 '{ ...(c); }': ()
166 [425; 426) 'd': A<[{unknown}]> 166 425..426 'd': A<[{unknown}]>
167 [429; 433) 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]> 167 429..433 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]>
168 [429; 436) 'foo1(a)': A<[{unknown}]> 168 429..436 'foo1(a)': A<[{unknown}]>
169 [434; 435) 'a': A<[u8; _]> 169 434..435 'a': A<[u8; _]>
170 [446; 447) 'e': B<[u8]> 170 446..447 'e': B<[u8]>
171 [450; 454) 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]> 171 450..454 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]>
172 [450; 457) 'foo2(b)': B<[u8]> 172 450..457 'foo2(b)': B<[u8]>
173 [455; 456) 'b': B<[u8; _]> 173 455..456 'b': B<[u8; _]>
174 [467; 468) 'f': C<[u8]> 174 467..468 'f': C<[u8]>
175 [471; 475) 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]> 175 471..475 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]>
176 [471; 478) 'foo3(c)': C<[u8]> 176 471..478 'foo3(c)': C<[u8]>
177 [476; 477) 'c': C<[u8; _]> 177 476..477 'c': C<[u8; _]>
178 "### 178 "###
179 ); 179 );
180} 180}
@@ -193,24 +193,24 @@ fn test() {
193} 193}
194"#), 194"#),
195 @r###" 195 @r###"
196 [11; 12) 'x': &[T] 196 11..12 'x': &[T]
197 [28; 39) '{ loop {} }': &[T] 197 28..39 '{ loop {} }': &[T]
198 [30; 37) 'loop {}': ! 198 30..37 'loop {}': !
199 [35; 37) '{}': () 199 35..37 '{}': ()
200 [50; 126) '{ ... }; }': () 200 50..126 '{ ... }; }': ()
201 [60; 61) 'x': &[i32] 201 60..61 'x': &[i32]
202 [64; 123) 'if tru... }': &[i32] 202 64..123 'if tru... }': &[i32]
203 [67; 71) 'true': bool 203 67..71 'true': bool
204 [72; 97) '{ ... }': &[i32] 204 72..97 '{ ... }': &[i32]
205 [82; 85) 'foo': fn foo<i32>(&[i32]) -> &[i32] 205 82..85 'foo': fn foo<i32>(&[i32]) -> &[i32]
206 [82; 91) 'foo(&[1])': &[i32] 206 82..91 'foo(&[1])': &[i32]
207 [86; 90) '&[1]': &[i32; _] 207 86..90 '&[1]': &[i32; _]
208 [87; 90) '[1]': [i32; _] 208 87..90 '[1]': [i32; _]
209 [88; 89) '1': i32 209 88..89 '1': i32
210 [103; 123) '{ ... }': &[i32; _] 210 103..123 '{ ... }': &[i32; _]
211 [113; 117) '&[1]': &[i32; _] 211 113..117 '&[1]': &[i32; _]
212 [114; 117) '[1]': [i32; _] 212 114..117 '[1]': [i32; _]
213 [115; 116) '1': i32 213 115..116 '1': i32
214 "### 214 "###
215 ); 215 );
216} 216}
@@ -229,24 +229,24 @@ fn test() {
229} 229}
230"#), 230"#),
231 @r###" 231 @r###"
232 [11; 12) 'x': &[T] 232 11..12 'x': &[T]
233 [28; 39) '{ loop {} }': &[T] 233 28..39 '{ loop {} }': &[T]
234 [30; 37) 'loop {}': ! 234 30..37 'loop {}': !
235 [35; 37) '{}': () 235 35..37 '{}': ()
236 [50; 126) '{ ... }; }': () 236 50..126 '{ ... }; }': ()
237 [60; 61) 'x': &[i32] 237 60..61 'x': &[i32]
238 [64; 123) 'if tru... }': &[i32] 238 64..123 'if tru... }': &[i32]
239 [67; 71) 'true': bool 239 67..71 'true': bool
240 [72; 92) '{ ... }': &[i32; _] 240 72..92 '{ ... }': &[i32; _]
241 [82; 86) '&[1]': &[i32; _] 241 82..86 '&[1]': &[i32; _]
242 [83; 86) '[1]': [i32; _] 242 83..86 '[1]': [i32; _]
243 [84; 85) '1': i32 243 84..85 '1': i32
244 [98; 123) '{ ... }': &[i32] 244 98..123 '{ ... }': &[i32]
245 [108; 111) 'foo': fn foo<i32>(&[i32]) -> &[i32] 245 108..111 'foo': fn foo<i32>(&[i32]) -> &[i32]
246 [108; 117) 'foo(&[1])': &[i32] 246 108..117 'foo(&[1])': &[i32]
247 [112; 116) '&[1]': &[i32; _] 247 112..116 '&[1]': &[i32; _]
248 [113; 116) '[1]': [i32; _] 248 113..116 '[1]': [i32; _]
249 [114; 115) '1': i32 249 114..115 '1': i32
250 "### 250 "###
251 ); 251 );
252} 252}
@@ -265,31 +265,31 @@ fn test(i: i32) {
265} 265}
266"#), 266"#),
267 @r###" 267 @r###"
268 [11; 12) 'x': &[T] 268 11..12 'x': &[T]
269 [28; 39) '{ loop {} }': &[T] 269 28..39 '{ loop {} }': &[T]
270 [30; 37) 'loop {}': ! 270 30..37 'loop {}': !
271 [35; 37) '{}': () 271 35..37 '{}': ()
272 [48; 49) 'i': i32 272 48..49 'i': i32
273 [56; 150) '{ ... }; }': () 273 56..150 '{ ... }; }': ()
274 [66; 67) 'x': &[i32] 274 66..67 'x': &[i32]
275 [70; 147) 'match ... }': &[i32] 275 70..147 'match ... }': &[i32]
276 [76; 77) 'i': i32 276 76..77 'i': i32
277 [88; 89) '2': i32 277 88..89 '2': i32
278 [88; 89) '2': i32 278 88..89 '2': i32
279 [93; 96) 'foo': fn foo<i32>(&[i32]) -> &[i32] 279 93..96 'foo': fn foo<i32>(&[i32]) -> &[i32]
280 [93; 102) 'foo(&[2])': &[i32] 280 93..102 'foo(&[2])': &[i32]
281 [97; 101) '&[2]': &[i32; _] 281 97..101 '&[2]': &[i32; _]
282 [98; 101) '[2]': [i32; _] 282 98..101 '[2]': [i32; _]
283 [99; 100) '2': i32 283 99..100 '2': i32
284 [112; 113) '1': i32 284 112..113 '1': i32
285 [112; 113) '1': i32 285 112..113 '1': i32
286 [117; 121) '&[1]': &[i32; _] 286 117..121 '&[1]': &[i32; _]
287 [118; 121) '[1]': [i32; _] 287 118..121 '[1]': [i32; _]
288 [119; 120) '1': i32 288 119..120 '1': i32
289 [131; 132) '_': i32 289 131..132 '_': i32
290 [136; 140) '&[3]': &[i32; _] 290 136..140 '&[3]': &[i32; _]
291 [137; 140) '[3]': [i32; _] 291 137..140 '[3]': [i32; _]
292 [138; 139) '3': i32 292 138..139 '3': i32
293 "### 293 "###
294 ); 294 );
295} 295}
@@ -308,31 +308,31 @@ fn test(i: i32) {
308} 308}
309"#), 309"#),
310 @r###" 310 @r###"
311 [11; 12) 'x': &[T] 311 11..12 'x': &[T]
312 [28; 39) '{ loop {} }': &[T] 312 28..39 '{ loop {} }': &[T]
313 [30; 37) 'loop {}': ! 313 30..37 'loop {}': !
314 [35; 37) '{}': () 314 35..37 '{}': ()
315 [48; 49) 'i': i32 315 48..49 'i': i32
316 [56; 150) '{ ... }; }': () 316 56..150 '{ ... }; }': ()
317 [66; 67) 'x': &[i32] 317 66..67 'x': &[i32]
318 [70; 147) 'match ... }': &[i32] 318 70..147 'match ... }': &[i32]
319 [76; 77) 'i': i32 319 76..77 'i': i32
320 [88; 89) '1': i32 320 88..89 '1': i32
321 [88; 89) '1': i32 321 88..89 '1': i32
322 [93; 97) '&[1]': &[i32; _] 322 93..97 '&[1]': &[i32; _]
323 [94; 97) '[1]': [i32; _] 323 94..97 '[1]': [i32; _]
324 [95; 96) '1': i32 324 95..96 '1': i32
325 [107; 108) '2': i32 325 107..108 '2': i32
326 [107; 108) '2': i32 326 107..108 '2': i32
327 [112; 115) 'foo': fn foo<i32>(&[i32]) -> &[i32] 327 112..115 'foo': fn foo<i32>(&[i32]) -> &[i32]
328 [112; 121) 'foo(&[2])': &[i32] 328 112..121 'foo(&[2])': &[i32]
329 [116; 120) '&[2]': &[i32; _] 329 116..120 '&[2]': &[i32; _]
330 [117; 120) '[2]': [i32; _] 330 117..120 '[2]': [i32; _]
331 [118; 119) '2': i32 331 118..119 '2': i32
332 [131; 132) '_': i32 332 131..132 '_': i32
333 [136; 140) '&[3]': &[i32; _] 333 136..140 '&[3]': &[i32; _]
334 [137; 140) '[3]': [i32; _] 334 137..140 '[3]': [i32; _]
335 [138; 139) '3': i32 335 138..139 '3': i32
336 "### 336 "###
337 ); 337 );
338} 338}
@@ -353,24 +353,24 @@ fn test() {
353} 353}
354"#), 354"#),
355 @r###" 355 @r###"
356 [11; 145) '{ ... }; }': () 356 11..145 '{ ... }; }': ()
357 [21; 22) 't': &mut i32 357 21..22 't': &mut i32
358 [25; 31) '&mut 1': &mut i32 358 25..31 '&mut 1': &mut i32
359 [30; 31) '1': i32 359 30..31 '1': i32
360 [41; 42) 'x': *const i32 360 41..42 'x': *const i32
361 [45; 142) 'match ... }': *const i32 361 45..142 'match ... }': *const i32
362 [51; 52) '1': i32 362 51..52 '1': i32
363 [63; 64) '1': i32 363 63..64 '1': i32
364 [63; 64) '1': i32 364 63..64 '1': i32
365 [68; 69) 't': &mut i32 365 68..69 't': &mut i32
366 [68; 81) 't as *mut i32': *mut i32 366 68..81 't as *mut i32': *mut i32
367 [91; 92) '2': i32 367 91..92 '2': i32
368 [91; 92) '2': i32 368 91..92 '2': i32
369 [96; 97) 't': &mut i32 369 96..97 't': &mut i32
370 [96; 105) 't as &i32': &i32 370 96..105 't as &i32': &i32
371 [115; 116) '_': i32 371 115..116 '_': i32
372 [120; 121) 't': &mut i32 372 120..121 't': &mut i32
373 [120; 135) 't as *const i32': *const i32 373 120..135 't as *const i32': *const i32
374 "### 374 "###
375 ); 375 );
376} 376}
@@ -384,9 +384,9 @@ fn foo() -> u32 {
384} 384}
385"#, true), 385"#, true),
386 @r###" 386 @r###"
387 [17; 40) '{ ...own; }': ! 387 17..40 '{ ...own; }': !
388 [23; 37) 'return unknown': ! 388 23..37 'return unknown': !
389 [30; 37) 'unknown': u32 389 30..37 'unknown': u32
390 "### 390 "###
391 ); 391 );
392} 392}
@@ -404,24 +404,24 @@ fn test() {
404} 404}
405"#, true), 405"#, true),
406 @r###" 406 @r###"
407 [30; 31) 'x': &Foo 407 30..31 'x': &Foo
408 [39; 41) '{}': () 408 39..41 '{}': ()
409 [52; 133) '{ ...oo); }': () 409 52..133 '{ ...oo); }': ()
410 [58; 71) 'takes_ref_foo': fn takes_ref_foo(&Foo) 410 58..71 'takes_ref_foo': fn takes_ref_foo(&Foo)
411 [58; 77) 'takes_...(&Foo)': () 411 58..77 'takes_...(&Foo)': ()
412 [72; 76) '&Foo': &Foo 412 72..76 '&Foo': &Foo
413 [73; 76) 'Foo': Foo 413 73..76 'Foo': Foo
414 [83; 96) 'takes_ref_foo': fn takes_ref_foo(&Foo) 414 83..96 'takes_ref_foo': fn takes_ref_foo(&Foo)
415 [83; 103) 'takes_...&&Foo)': () 415 83..103 'takes_...&&Foo)': ()
416 [97; 102) '&&Foo': &&Foo 416 97..102 '&&Foo': &&Foo
417 [98; 102) '&Foo': &Foo 417 98..102 '&Foo': &Foo
418 [99; 102) 'Foo': Foo 418 99..102 'Foo': Foo
419 [109; 122) 'takes_ref_foo': fn takes_ref_foo(&Foo) 419 109..122 'takes_ref_foo': fn takes_ref_foo(&Foo)
420 [109; 130) 'takes_...&&Foo)': () 420 109..130 'takes_...&&Foo)': ()
421 [123; 129) '&&&Foo': &&&Foo 421 123..129 '&&&Foo': &&&Foo
422 [124; 129) '&&Foo': &&Foo 422 124..129 '&&Foo': &&Foo
423 [125; 129) '&Foo': &Foo 423 125..129 '&Foo': &Foo
424 [126; 129) 'Foo': Foo 424 126..129 'Foo': Foo
425 "### 425 "###
426 ); 426 );
427} 427}
@@ -439,26 +439,26 @@ fn test() {
439} 439}
440"#, true), 440"#, true),
441 @r###" 441 @r###"
442 [29; 30) 'x': &T 442 29..30 'x': &T
443 [41; 47) '{ *x }': T 443 41..47 '{ *x }': T
444 [43; 45) '*x': T 444 43..45 '*x': T
445 [44; 45) 'x': &T 445 44..45 'x': &T
446 [58; 127) '{ ...oo); }': () 446 58..127 '{ ...oo); }': ()
447 [64; 73) 'takes_ref': fn takes_ref<Foo>(&Foo) -> Foo 447 64..73 'takes_ref': fn takes_ref<Foo>(&Foo) -> Foo
448 [64; 79) 'takes_ref(&Foo)': Foo 448 64..79 'takes_ref(&Foo)': Foo
449 [74; 78) '&Foo': &Foo 449 74..78 '&Foo': &Foo
450 [75; 78) 'Foo': Foo 450 75..78 'Foo': Foo
451 [85; 94) 'takes_ref': fn takes_ref<&Foo>(&&Foo) -> &Foo 451 85..94 'takes_ref': fn takes_ref<&Foo>(&&Foo) -> &Foo
452 [85; 101) 'takes_...&&Foo)': &Foo 452 85..101 'takes_...&&Foo)': &Foo
453 [95; 100) '&&Foo': &&Foo 453 95..100 '&&Foo': &&Foo
454 [96; 100) '&Foo': &Foo 454 96..100 '&Foo': &Foo
455 [97; 100) 'Foo': Foo 455 97..100 'Foo': Foo
456 [107; 116) 'takes_ref': fn takes_ref<&&Foo>(&&&Foo) -> &&Foo 456 107..116 'takes_ref': fn takes_ref<&&Foo>(&&&Foo) -> &&Foo
457 [107; 124) 'takes_...&&Foo)': &&Foo 457 107..124 'takes_...&&Foo)': &&Foo
458 [117; 123) '&&&Foo': &&&Foo 458 117..123 '&&&Foo': &&&Foo
459 [118; 123) '&&Foo': &&Foo 459 118..123 '&&Foo': &&Foo
460 [119; 123) '&Foo': &Foo 460 119..123 '&Foo': &Foo
461 [120; 123) 'Foo': Foo 461 120..123 'Foo': Foo
462 "### 462 "###
463 ); 463 );
464} 464}
@@ -478,18 +478,18 @@ fn test() {
478} 478}
479"#, true), 479"#, true),
480 @r###" 480 @r###"
481 [127; 128) 'x': &str 481 127..128 'x': &str
482 [136; 138) '{}': () 482 136..138 '{}': ()
483 [169; 180) '{ loop {} }': String 483 169..180 '{ loop {} }': String
484 [171; 178) 'loop {}': ! 484 171..178 'loop {}': !
485 [176; 178) '{}': () 485 176..178 '{}': ()
486 [191; 236) '{ ... }); }': () 486 191..236 '{ ... }); }': ()
487 [197; 210) 'takes_ref_str': fn takes_ref_str(&str) 487 197..210 'takes_ref_str': fn takes_ref_str(&str)
488 [197; 233) 'takes_...g() })': () 488 197..233 'takes_...g() })': ()
489 [211; 232) '&{ ret...ng() }': &String 489 211..232 '&{ ret...ng() }': &String
490 [212; 232) '{ retu...ng() }': String 490 212..232 '{ retu...ng() }': String
491 [214; 228) 'returns_string': fn returns_string() -> String 491 214..228 'returns_string': fn returns_string() -> String
492 [214; 230) 'return...ring()': String 492 214..230 'return...ring()': String
493 "### 493 "###
494 ); 494 );
495} 495}
@@ -508,19 +508,19 @@ fn foo() {
508} 508}
509"#, true), 509"#, true),
510 @r###" 510 @r###"
511 [10; 106) '{ ... }; }': () 511 10..106 '{ ... }; }': ()
512 [20; 21) 'x': || -> &u32 512 20..21 'x': || -> &u32
513 [24; 103) '|| { ... }': || -> &u32 513 24..103 '|| { ... }': || -> &u32
514 [27; 103) '{ ... }': &u32 514 27..103 '{ ... }': &u32
515 [37; 82) 'if tru... }': () 515 37..82 'if tru... }': ()
516 [40; 44) 'true': bool 516 40..44 'true': bool
517 [45; 82) '{ ... }': ! 517 45..82 '{ ... }': !
518 [59; 71) 'return &1u32': ! 518 59..71 'return &1u32': !
519 [66; 71) '&1u32': &u32 519 66..71 '&1u32': &u32
520 [67; 71) '1u32': u32 520 67..71 '1u32': u32
521 [91; 97) '&&1u32': &&u32 521 91..97 '&&1u32': &&u32
522 [92; 97) '&1u32': &u32 522 92..97 '&1u32': &u32
523 [93; 97) '1u32': u32 523 93..97 '1u32': u32
524 "### 524 "###
525 ); 525 );
526} 526}
@@ -535,12 +535,12 @@ fn test() {
535} 535}
536"#, true), 536"#, true),
537 @r###" 537 @r###"
538 [8; 9) 'x': u32 538 8..9 'x': u32
539 [25; 30) '{ 1 }': isize 539 25..30 '{ 1 }': isize
540 [27; 28) '1': isize 540 27..28 '1': isize
541 [41; 79) '{ ...foo; }': () 541 41..79 '{ ...foo; }': ()
542 [51; 52) 'f': fn(u32) -> isize 542 51..52 'f': fn(u32) -> isize
543 [73; 76) 'foo': fn foo(u32) -> isize 543 73..76 'foo': fn foo(u32) -> isize
544 "### 544 "###
545 ); 545 );
546} 546}
@@ -554,12 +554,12 @@ fn test() {
554} 554}
555"#, true), 555"#, true),
556 @r###" 556 @r###"
557 [11; 55) '{ ...1 }; }': () 557 11..55 '{ ...1 }; }': ()
558 [21; 22) 'f': fn(u32) -> isize 558 21..22 'f': fn(u32) -> isize
559 [43; 52) '|x| { 1 }': |u32| -> isize 559 43..52 '|x| { 1 }': |u32| -> isize
560 [44; 45) 'x': u32 560 44..45 'x': u32
561 [47; 52) '{ 1 }': isize 561 47..52 '{ 1 }': isize
562 [49; 50) '1': isize 562 49..50 '1': isize
563 "### 563 "###
564 ); 564 );
565} 565}
@@ -577,11 +577,11 @@ impl<TT> S<TT> {
577} 577}
578"#, true), 578"#, true),
579 @r###" 579 @r###"
580 [51; 55) 'self': &S<TT> 580 51..55 'self': &S<TT>
581 [64; 87) '{ ... }': &TT 581 64..87 '{ ... }': &TT
582 [74; 81) '&self.t': &TT 582 74..81 '&self.t': &TT
583 [75; 79) 'self': &S<TT> 583 75..79 'self': &S<TT>
584 [75; 81) 'self.t': TT 584 75..81 'self.t': TT
585 "### 585 "###
586 ); 586 );
587} 587}
@@ -602,13 +602,13 @@ fn test() {
602} 602}
603"#, true), 603"#, true),
604 @r###" 604 @r###"
605 [162; 199) '{ ... 3]; }': () 605 162..199 '{ ... 3]; }': ()
606 [172; 173) 'f': &[usize] 606 172..173 'f': &[usize]
607 [186; 196) '&[1, 2, 3]': &[usize; _] 607 186..196 '&[1, 2, 3]': &[usize; _]
608 [187; 196) '[1, 2, 3]': [usize; _] 608 187..196 '[1, 2, 3]': [usize; _]
609 [188; 189) '1': usize 609 188..189 '1': usize
610 [191; 192) '2': usize 610 191..192 '2': usize
611 [194; 195) '3': usize 611 194..195 '3': usize
612 "### 612 "###
613 ); 613 );
614} 614}
@@ -642,19 +642,19 @@ fn test() {
642} 642}
643"#, true), 643"#, true),
644 @r###" 644 @r###"
645 [388; 573) '{ ...bj2; }': () 645 388..573 '{ ...bj2; }': ()
646 [398; 401) 'obj': &dyn Baz<i8, i16> 646 398..401 'obj': &dyn Baz<i8, i16>
647 [423; 425) '&S': &S<i8, i16> 647 423..425 '&S': &S<i8, i16>
648 [424; 425) 'S': S<i8, i16> 648 424..425 'S': S<i8, i16>
649 [435; 438) 'obj': &dyn Bar<usize, i8, i16> 649 435..438 'obj': &dyn Bar<usize, i8, i16>
650 [460; 463) 'obj': &dyn Baz<i8, i16> 650 460..463 'obj': &dyn Baz<i8, i16>
651 [473; 476) 'obj': &dyn Foo<i8, usize> 651 473..476 'obj': &dyn Foo<i8, usize>
652 [495; 498) 'obj': &dyn Bar<usize, i8, i16> 652 495..498 'obj': &dyn Bar<usize, i8, i16>
653 [508; 512) 'obj2': &dyn Baz<i8, i16> 653 508..512 'obj2': &dyn Baz<i8, i16>
654 [534; 536) '&S': &S<i8, i16> 654 534..536 '&S': &S<i8, i16>
655 [535; 536) 'S': S<i8, i16> 655 535..536 'S': S<i8, i16>
656 [546; 547) '_': &dyn Foo<i8, usize> 656 546..547 '_': &dyn Foo<i8, usize>
657 [566; 570) 'obj2': &dyn Baz<i8, i16> 657 566..570 'obj2': &dyn Baz<i8, i16>
658 "### 658 "###
659 ); 659 );
660} 660}
@@ -687,12 +687,12 @@ fn test() {
687} 687}
688"#, true), 688"#, true),
689 @r###" 689 @r###"
690 [292; 348) '{ ...obj; }': () 690 292..348 '{ ...obj; }': ()
691 [302; 305) 'obj': &dyn D 691 302..305 'obj': &dyn D
692 [316; 318) '&S': &S 692 316..318 '&S': &S
693 [317; 318) 'S': S 693 317..318 'S': S
694 [328; 331) 'obj': &dyn A 694 328..331 'obj': &dyn A
695 [342; 345) 'obj': &dyn D 695 342..345 'obj': &dyn D
696 "### 696 "###
697 ); 697 );
698} 698}
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index f2a9b1c40..6b5267232 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -67,12 +67,12 @@ fn main() {
67} 67}
68"#), 68"#),
69 @r###" 69 @r###"
70 ![0; 17) '{Foo(v...,2,])}': Foo 70 !0..17 '{Foo(v...,2,])}': Foo
71 ![1; 4) 'Foo': Foo({unknown}) -> Foo 71 !1..4 'Foo': Foo({unknown}) -> Foo
72 ![1; 16) 'Foo(vec![1,2,])': Foo 72 !1..16 'Foo(vec![1,2,])': Foo
73 ![5; 15) 'vec![1,2,]': {unknown} 73 !5..15 'vec![1,2,]': {unknown}
74 [156; 182) '{ ...,2); }': () 74 156..182 '{ ...,2); }': ()
75 [166; 167) 'x': Foo 75 166..167 'x': Foo
76 "### 76 "###
77 ); 77 );
78} 78}
@@ -100,14 +100,14 @@ fn main() {
100} 100}
101"#), 101"#),
102 @r###" 102 @r###"
103 ![0; 17) '{Foo(v...,2,])}': Foo 103 !0..17 '{Foo(v...,2,])}': Foo
104 ![1; 4) 'Foo': Foo({unknown}) -> Foo 104 !1..4 'Foo': Foo({unknown}) -> Foo
105 ![1; 16) 'Foo(vec![1,2,])': Foo 105 !1..16 'Foo(vec![1,2,])': Foo
106 ![5; 15) 'vec![1,2,]': {unknown} 106 !5..15 'vec![1,2,]': {unknown}
107 [195; 251) '{ ...,2); }': () 107 195..251 '{ ...,2); }': ()
108 [205; 206) 'x': Foo 108 205..206 'x': Foo
109 [228; 229) 'y': {unknown} 109 228..229 'y': {unknown}
110 [232; 248) 'crate:...!(1,2)': {unknown} 110 232..248 'crate:...!(1,2)': {unknown}
111 "### 111 "###
112 ); 112 );
113} 113}
@@ -131,11 +131,11 @@ fn main() {
131} 131}
132"#), 132"#),
133 @r###" 133 @r###"
134 ![0; 5) '42i32': i32 134 !0..5 '42i32': i32
135 ![0; 5) '42i32': i32 135 !0..5 '42i32': i32
136 [111; 164) '{ ...!(); }': () 136 111..164 '{ ...!(); }': ()
137 [121; 122) 'x': i32 137 121..122 'x': i32
138 [148; 149) 'y': i32 138 148..149 'y': i32
139 "### 139 "###
140 ); 140 );
141} 141}
@@ -172,51 +172,51 @@ fn spam() {
172} 172}
173"#), 173"#),
174 @r###" 174 @r###"
175 ![0; 6) '1isize': isize 175 !0..6 '1isize': isize
176 ![0; 6) '1isize': isize 176 !0..6 '1isize': isize
177 ![0; 6) '1isize': isize 177 !0..6 '1isize': isize
178 ![0; 6) '1isize': isize 178 !0..6 '1isize': isize
179 ![0; 6) '1isize': isize 179 !0..6 '1isize': isize
180 ![0; 6) '1isize': isize 180 !0..6 '1isize': isize
181 ![0; 6) '1isize': isize 181 !0..6 '1isize': isize
182 ![0; 6) '1isize': isize 182 !0..6 '1isize': isize
183 ![0; 6) '1isize': isize 183 !0..6 '1isize': isize
184 ![0; 6) '1isize': isize 184 !0..6 '1isize': isize
185 ![0; 6) '1isize': isize 185 !0..6 '1isize': isize
186 ![0; 6) '1isize': isize 186 !0..6 '1isize': isize
187 ![0; 6) '1isize': isize 187 !0..6 '1isize': isize
188 ![0; 6) '1isize': isize 188 !0..6 '1isize': isize
189 ![0; 6) '1isize': isize 189 !0..6 '1isize': isize
190 ![0; 6) '1isize': isize 190 !0..6 '1isize': isize
191 ![0; 6) '1isize': isize 191 !0..6 '1isize': isize
192 ![0; 6) '1isize': isize 192 !0..6 '1isize': isize
193 ![0; 6) '1isize': isize 193 !0..6 '1isize': isize
194 ![0; 6) '1isize': isize 194 !0..6 '1isize': isize
195 ![0; 6) '1isize': isize 195 !0..6 '1isize': isize
196 ![0; 6) '1isize': isize 196 !0..6 '1isize': isize
197 ![0; 6) '1isize': isize 197 !0..6 '1isize': isize
198 ![0; 6) '1isize': isize 198 !0..6 '1isize': isize
199 ![0; 6) '1isize': isize 199 !0..6 '1isize': isize
200 [54; 457) '{ ...!(); }': ! 200 54..457 '{ ...!(); }': !
201 [88; 109) 'spam!(...am!())': {unknown} 201 88..109 'spam!(...am!())': {unknown}
202 [115; 134) 'for _ ...!() {}': () 202 115..134 'for _ ...!() {}': ()
203 [119; 120) '_': {unknown} 203 119..120 '_': {unknown}
204 [132; 134) '{}': () 204 132..134 '{}': ()
205 [139; 149) '|| spam!()': || -> isize 205 139..149 '|| spam!()': || -> isize
206 [155; 171) 'while ...!() {}': () 206 155..171 'while ...!() {}': ()
207 [169; 171) '{}': () 207 169..171 '{}': ()
208 [176; 189) 'break spam!()': ! 208 176..189 'break spam!()': !
209 [195; 209) 'return spam!()': ! 209 195..209 'return spam!()': !
210 [215; 269) 'match ... }': isize 210 215..269 'match ... }': isize
211 [239; 240) '_': isize 211 239..240 '_': isize
212 [274; 290) 'spam!(...am!())': {unknown} 212 274..290 'spam!(...am!())': {unknown}
213 [296; 318) 'Spam {...m!() }': {unknown} 213 296..318 'Spam {...m!() }': {unknown}
214 [324; 340) 'spam!(...am!()]': {unknown} 214 324..340 'spam!(...am!()]': {unknown}
215 [365; 381) 'spam!(... usize': usize 215 365..381 'spam!(... usize': usize
216 [387; 395) '&spam!()': &isize 216 387..395 '&spam!()': &isize
217 [401; 409) '-spam!()': isize 217 401..409 '-spam!()': isize
218 [415; 431) 'spam!(...pam!()': {unknown} 218 415..431 'spam!(...pam!()': {unknown}
219 [437; 454) 'spam!(...pam!()': isize 219 437..454 'spam!(...pam!()': isize
220 "### 220 "###
221 ); 221 );
222} 222}
@@ -244,9 +244,9 @@ fn foo() {
244} 244}
245"#), 245"#),
246 @r###" 246 @r###"
247 ![0; 5) '42i32': i32 247 !0..5 '42i32': i32
248 [171; 206) '{ ...32); }': () 248 171..206 '{ ...32); }': ()
249 [181; 184) 'foo': i32 249 181..184 'foo': i32
250 "### 250 "###
251 ); 251 );
252} 252}
@@ -357,12 +357,12 @@ fn main() {
357} 357}
358"#), 358"#),
359 @r###" 359 @r###"
360 [159; 164) '{ 0 }': u64 360 159..164 '{ 0 }': u64
361 [161; 162) '0': u64 361 161..162 '0': u64
362 [175; 197) '{ ...f(); }': () 362 175..197 '{ ...f(); }': ()
363 [185; 187) '_a': u64 363 185..187 '_a': u64
364 [191; 192) 'f': fn f() -> u64 364 191..192 'f': fn f() -> u64
365 [191; 194) 'f()': u64 365 191..194 'f()': u64
366 "### 366 "###
367 ); 367 );
368} 368}
@@ -379,10 +379,10 @@ fn main() {
379} 379}
380"#), 380"#),
381 @r###" 381 @r###"
382 ![0; 6) '1usize': usize 382 !0..6 '1usize': usize
383 [11; 90) '{ ...!(); }': () 383 11..90 '{ ...!(); }': ()
384 [17; 66) 'macro_... }': {unknown} 384 17..66 'macro_... }': {unknown}
385 [75; 77) '_a': usize 385 75..77 '_a': usize
386 "### 386 "###
387 ); 387 );
388} 388}
@@ -399,9 +399,9 @@ fn main() {
399} 399}
400"#), 400"#),
401 @r###" 401 @r###"
402 ![0; 1) '0': i32 402 !0..1 '0': i32
403 [64; 88) '{ ...!(); }': () 403 64..88 '{ ...!(); }': ()
404 [74; 75) 'x': i32 404 74..75 'x': i32
405 "### 405 "###
406 ); 406 );
407} 407}
@@ -418,9 +418,9 @@ fn main() {
418} 418}
419"#), 419"#),
420 @r###" 420 @r###"
421 ![0; 2) '""': &str 421 !0..2 '""': &str
422 [64; 88) '{ ...!(); }': () 422 64..88 '{ ...!(); }': ()
423 [74; 75) 'x': &str 423 74..75 'x': &str
424 "### 424 "###
425 ); 425 );
426} 426}
@@ -437,9 +437,9 @@ fn main() {
437} 437}
438"#), 438"#),
439 @r###" 439 @r###"
440 ![0; 1) '0': i32 440 !0..1 '0': i32
441 [66; 92) '{ ...!(); }': () 441 66..92 '{ ...!(); }': ()
442 [76; 77) 'x': i32 442 76..77 'x': i32
443 "### 443 "###
444 ); 444 );
445} 445}
@@ -456,9 +456,9 @@ fn main() {
456} 456}
457"#), 457"#),
458 @r###" 458 @r###"
459 ![0; 13) '"helloworld!"': &str 459 !0..13 '"helloworld!"': &str
460 [66; 122) '{ ...")); }': () 460 66..122 '{ ...")); }': ()
461 [76; 77) 'x': &str 461 76..77 'x': &str
462 "### 462 "###
463 ); 463 );
464} 464}
@@ -591,9 +591,9 @@ fn main() {
591} 591}
592"#), 592"#),
593 @r###" 593 @r###"
594 ![0; 13) '"helloworld!"': &str 594 !0..13 '"helloworld!"': &str
595 [104; 161) '{ ...")); }': () 595 104..161 '{ ...")); }': ()
596 [114; 115) 'x': &str 596 114..115 'x': &str
597 "### 597 "###
598 ); 598 );
599} 599}
@@ -611,9 +611,9 @@ fn main() {
611} 611}
612"#), 612"#),
613 @r###" 613 @r###"
614 ![0; 5) '"bar"': &str 614 !0..5 '"bar"': &str
615 [88; 116) '{ ...o"); }': () 615 88..116 '{ ...o"); }': ()
616 [98; 99) 'x': &str 616 98..99 'x': &str
617 "### 617 "###
618 ); 618 );
619} 619}
@@ -703,12 +703,12 @@ fn main() {
703} 703}
704"#), 704"#),
705 @r###" 705 @r###"
706 [52; 111) '{ ... }; }': () 706 52..111 '{ ... }; }': ()
707 [62; 63) 'x': u32 707 62..63 'x': u32
708 [66; 108) 'match ... }': u32 708 66..108 'match ... }': u32
709 [72; 74) '()': () 709 72..74 '()': ()
710 [85; 92) 'unit!()': () 710 85..92 'unit!()': ()
711 [96; 101) '92u32': u32 711 96..101 '92u32': u32
712 "### 712 "###
713 ); 713 );
714} 714}
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs
index af3e5b12c..ab87f598a 100644
--- a/crates/ra_hir_ty/src/tests/method_resolution.rs
+++ b/crates/ra_hir_ty/src/tests/method_resolution.rs
@@ -22,14 +22,14 @@ fn test() {
22} 22}
23"#), 23"#),
24 @r###" 24 @r###"
25 [45; 49) 'self': &[T] 25 45..49 'self': &[T]
26 [56; 79) '{ ... }': T 26 56..79 '{ ... }': T
27 [66; 73) 'loop {}': ! 27 66..73 'loop {}': !
28 [71; 73) '{}': () 28 71..73 '{}': ()
29 [133; 160) '{ ...o"); }': () 29 133..160 '{ ...o"); }': ()
30 [139; 149) '<[_]>::foo': fn foo<u8>(&[u8]) -> u8 30 139..149 '<[_]>::foo': fn foo<u8>(&[u8]) -> u8
31 [139; 157) '<[_]>:..."foo")': u8 31 139..157 '<[_]>:..."foo")': u8
32 [150; 156) 'b"foo"': &[u8] 32 150..156 'b"foo"': &[u8]
33 "### 33 "###
34 ); 34 );
35} 35}
@@ -51,15 +51,15 @@ fn test() {
51} 51}
52"#), 52"#),
53 @r###" 53 @r###"
54 [49; 75) '{ ... }': A 54 49..75 '{ ... }': A
55 [59; 69) 'A { x: 0 }': A 55 59..69 'A { x: 0 }': A
56 [66; 67) '0': u32 56 66..67 '0': u32
57 [88; 122) '{ ...a.x; }': () 57 88..122 '{ ...a.x; }': ()
58 [98; 99) 'a': A 58 98..99 'a': A
59 [102; 108) 'A::new': fn new() -> A 59 102..108 'A::new': fn new() -> A
60 [102; 110) 'A::new()': A 60 102..110 'A::new()': A
61 [116; 117) 'a': A 61 116..117 'a': A
62 [116; 119) 'a.x': u32 62 116..119 'a.x': u32
63 "### 63 "###
64 ); 64 );
65} 65}
@@ -86,19 +86,19 @@ fn test() {
86} 86}
87"#), 87"#),
88 @r###" 88 @r###"
89 [47; 67) '{ ... }': A 89 47..67 '{ ... }': A
90 [57; 61) 'A::B': A 90 57..61 'A::B': A
91 [88; 108) '{ ... }': A 91 88..108 '{ ... }': A
92 [98; 102) 'A::C': A 92 98..102 'A::C': A
93 [121; 178) '{ ... c; }': () 93 121..178 '{ ... c; }': ()
94 [131; 132) 'a': A 94 131..132 'a': A
95 [135; 139) 'A::b': fn b() -> A 95 135..139 'A::b': fn b() -> A
96 [135; 141) 'A::b()': A 96 135..141 'A::b()': A
97 [147; 148) 'a': A 97 147..148 'a': A
98 [158; 159) 'c': A 98 158..159 'c': A
99 [162; 166) 'A::c': fn c() -> A 99 162..166 'A::c': fn c() -> A
100 [162; 168) 'A::c()': A 100 162..168 'A::c()': A
101 [174; 175) 'c': A 101 174..175 'c': A
102 "### 102 "###
103 ); 103 );
104} 104}
@@ -130,22 +130,22 @@ fn test() {
130} 130}
131"#), 131"#),
132 @r###" 132 @r###"
133 [56; 64) '{ A {} }': A 133 56..64 '{ A {} }': A
134 [58; 62) 'A {}': A 134 58..62 'A {}': A
135 [126; 132) '{ 99 }': u32 135 126..132 '{ 99 }': u32
136 [128; 130) '99': u32 136 128..130 '99': u32
137 [202; 210) '{ C {} }': C 137 202..210 '{ C {} }': C
138 [204; 208) 'C {}': C 138 204..208 'C {}': C
139 [241; 325) '{ ...g(); }': () 139 241..325 '{ ...g(); }': ()
140 [251; 252) 'x': A 140 251..252 'x': A
141 [255; 266) 'a::A::thing': fn thing() -> A 141 255..266 'a::A::thing': fn thing() -> A
142 [255; 268) 'a::A::thing()': A 142 255..268 'a::A::thing()': A
143 [278; 279) 'y': u32 143 278..279 'y': u32
144 [282; 293) 'b::B::thing': fn thing() -> u32 144 282..293 'b::B::thing': fn thing() -> u32
145 [282; 295) 'b::B::thing()': u32 145 282..295 'b::B::thing()': u32
146 [305; 306) 'z': C 146 305..306 'z': C
147 [309; 320) 'c::C::thing': fn thing() -> C 147 309..320 'c::C::thing': fn thing() -> C
148 [309; 322) 'c::C::thing()': C 148 309..322 'c::C::thing()': C
149 "### 149 "###
150 ); 150 );
151} 151}
@@ -169,15 +169,15 @@ fn test() {
169} 169}
170"#), 170"#),
171 @r###" 171 @r###"
172 [64; 67) 'val': T 172 64..67 'val': T
173 [82; 109) '{ ... }': Gen<T> 173 82..109 '{ ... }': Gen<T>
174 [92; 103) 'Gen { val }': Gen<T> 174 92..103 'Gen { val }': Gen<T>
175 [98; 101) 'val': T 175 98..101 'val': T
176 [123; 155) '{ ...32); }': () 176 123..155 '{ ...32); }': ()
177 [133; 134) 'a': Gen<u32> 177 133..134 'a': Gen<u32>
178 [137; 146) 'Gen::make': fn make<u32>(u32) -> Gen<u32> 178 137..146 'Gen::make': fn make<u32>(u32) -> Gen<u32>
179 [137; 152) 'Gen::make(0u32)': Gen<u32> 179 137..152 'Gen::make(0u32)': Gen<u32>
180 [147; 151) '0u32': u32 180 147..151 '0u32': u32
181 "### 181 "###
182 ); 182 );
183} 183}
@@ -201,13 +201,13 @@ fn test() {
201} 201}
202"#), 202"#),
203 @r###" 203 @r###"
204 [80; 104) '{ ... }': Gen<T> 204 80..104 '{ ... }': Gen<T>
205 [90; 98) 'loop { }': ! 205 90..98 'loop { }': !
206 [95; 98) '{ }': () 206 95..98 '{ }': ()
207 [118; 146) '{ ...e(); }': () 207 118..146 '{ ...e(); }': ()
208 [128; 129) 'a': Gen<u32> 208 128..129 'a': Gen<u32>
209 [132; 141) 'Gen::make': fn make<u32>() -> Gen<u32> 209 132..141 'Gen::make': fn make<u32>() -> Gen<u32>
210 [132; 143) 'Gen::make()': Gen<u32> 210 132..143 'Gen::make()': Gen<u32>
211 "### 211 "###
212 ); 212 );
213} 213}
@@ -255,13 +255,13 @@ fn test() {
255} 255}
256"#), 256"#),
257 @r###" 257 @r###"
258 [76; 100) '{ ... }': Gen<T> 258 76..100 '{ ... }': Gen<T>
259 [86; 94) 'loop { }': ! 259 86..94 'loop { }': !
260 [91; 94) '{ }': () 260 91..94 '{ }': ()
261 [114; 149) '{ ...e(); }': () 261 114..149 '{ ...e(); }': ()
262 [124; 125) 'a': Gen<u32> 262 124..125 'a': Gen<u32>
263 [128; 144) 'Gen::<...::make': fn make<u32>() -> Gen<u32> 263 128..144 'Gen::<...::make': fn make<u32>() -> Gen<u32>
264 [128; 146) 'Gen::<...make()': Gen<u32> 264 128..146 'Gen::<...make()': Gen<u32>
265 "### 265 "###
266 ); 266 );
267} 267}
@@ -286,13 +286,13 @@ fn test() {
286} 286}
287"#), 287"#),
288 @r###" 288 @r###"
289 [102; 126) '{ ... }': Gen<u32, T> 289 102..126 '{ ... }': Gen<u32, T>
290 [112; 120) 'loop { }': ! 290 112..120 'loop { }': !
291 [117; 120) '{ }': () 291 117..120 '{ }': ()
292 [140; 180) '{ ...e(); }': () 292 140..180 '{ ...e(); }': ()
293 [150; 151) 'a': Gen<u32, u64> 293 150..151 'a': Gen<u32, u64>
294 [154; 175) 'Gen::<...::make': fn make<u64>() -> Gen<u32, u64> 294 154..175 'Gen::<...::make': fn make<u64>() -> Gen<u32, u64>
295 [154; 177) 'Gen::<...make()': Gen<u32, u64> 295 154..177 'Gen::<...make()': Gen<u32, u64>
296 "### 296 "###
297 ); 297 );
298} 298}
@@ -340,13 +340,13 @@ fn test() {
340} 340}
341"#), 341"#),
342 @r###" 342 @r###"
343 [31; 35) 'self': &Self 343 31..35 'self': &Self
344 [110; 114) 'self': &Self 344 110..114 'self': &Self
345 [170; 228) '{ ...i128 }': () 345 170..228 '{ ...i128 }': ()
346 [176; 178) 'S1': S1 346 176..178 'S1': S1
347 [176; 187) 'S1.method()': u32 347 176..187 'S1.method()': u32
348 [203; 205) 'S2': S2 348 203..205 'S2': S2
349 [203; 214) 'S2.method()': i128 349 203..214 'S2.method()': i128
350 "### 350 "###
351 ); 351 );
352} 352}
@@ -387,14 +387,14 @@ mod bar_test {
387} 387}
388"#), 388"#),
389 @r###" 389 @r###"
390 [63; 67) 'self': &Self 390 63..67 'self': &Self
391 [169; 173) 'self': &Self 391 169..173 'self': &Self
392 [300; 337) '{ ... }': () 392 300..337 '{ ... }': ()
393 [310; 311) 'S': S 393 310..311 'S': S
394 [310; 320) 'S.method()': u32 394 310..320 'S.method()': u32
395 [416; 454) '{ ... }': () 395 416..454 '{ ... }': ()
396 [426; 427) 'S': S 396 426..427 'S': S
397 [426; 436) 'S.method()': i128 397 426..436 'S.method()': i128
398 "### 398 "###
399 ); 399 );
400} 400}
@@ -414,10 +414,10 @@ fn test() {
414} 414}
415"#), 415"#),
416 @r###" 416 @r###"
417 [33; 37) 'self': &Self 417 33..37 'self': &Self
418 [92; 111) '{ ...d(); }': () 418 92..111 '{ ...d(); }': ()
419 [98; 99) 'S': S 419 98..99 'S': S
420 [98; 108) 'S.method()': u32 420 98..108 'S.method()': u32
421 "### 421 "###
422 ); 422 );
423} 423}
@@ -443,17 +443,17 @@ fn test() {
443} 443}
444"#), 444"#),
445 @r###" 445 @r###"
446 [43; 47) 'self': &Self 446 43..47 'self': &Self
447 [82; 86) 'self': &Self 447 82..86 'self': &Self
448 [210; 361) '{ ..., i8 }': () 448 210..361 '{ ..., i8 }': ()
449 [216; 218) 'S1': S1 449 216..218 'S1': S1
450 [216; 228) 'S1.method1()': (u8, u16, u32) 450 216..228 'S1.method1()': (u8, u16, u32)
451 [250; 252) 'S1': S1 451 250..252 'S1': S1
452 [250; 262) 'S1.method2()': (u32, u16, u8) 452 250..262 'S1.method2()': (u32, u16, u8)
453 [284; 286) 'S2': S2 453 284..286 'S2': S2
454 [284; 296) 'S2.method1()': (i8, i16, {unknown}) 454 284..296 'S2.method1()': (i8, i16, {unknown})
455 [324; 326) 'S2': S2 455 324..326 'S2': S2
456 [324; 336) 'S2.method2()': ({unknown}, i16, i8) 456 324..336 'S2.method2()': ({unknown}, i16, i8)
457 "### 457 "###
458 ); 458 );
459} 459}
@@ -473,12 +473,12 @@ fn test() {
473} 473}
474"#), 474"#),
475 @r###" 475 @r###"
476 [33; 37) 'self': &Self 476 33..37 'self': &Self
477 [102; 127) '{ ...d(); }': () 477 102..127 '{ ...d(); }': ()
478 [108; 109) 'S': S<u32>(u32) -> S<u32> 478 108..109 'S': S<u32>(u32) -> S<u32>
479 [108; 115) 'S(1u32)': S<u32> 479 108..115 'S(1u32)': S<u32>
480 [108; 124) 'S(1u32...thod()': u32 480 108..124 'S(1u32...thod()': u32
481 [110; 114) '1u32': u32 481 110..114 '1u32': u32
482 "### 482 "###
483 ); 483 );
484} 484}
@@ -499,16 +499,16 @@ fn test() {
499} 499}
500"#), 500"#),
501 @r###" 501 @r###"
502 [87; 193) '{ ...t(); }': () 502 87..193 '{ ...t(); }': ()
503 [97; 99) 's1': S 503 97..99 's1': S
504 [105; 121) 'Defaul...efault': fn default<S>() -> S 504 105..121 'Defaul...efault': fn default<S>() -> S
505 [105; 123) 'Defaul...ault()': S 505 105..123 'Defaul...ault()': S
506 [133; 135) 's2': S 506 133..135 's2': S
507 [138; 148) 'S::default': fn default<S>() -> S 507 138..148 'S::default': fn default<S>() -> S
508 [138; 150) 'S::default()': S 508 138..150 'S::default()': S
509 [160; 162) 's3': S 509 160..162 's3': S
510 [165; 188) '<S as ...efault': fn default<S>() -> S 510 165..188 '<S as ...efault': fn default<S>() -> S
511 [165; 190) '<S as ...ault()': S 511 165..190 '<S as ...ault()': S
512 "### 512 "###
513 ); 513 );
514} 514}
@@ -531,16 +531,16 @@ fn test() {
531} 531}
532"#), 532"#),
533 @r###" 533 @r###"
534 [127; 211) '{ ...e(); }': () 534 127..211 '{ ...e(); }': ()
535 [137; 138) 'a': u32 535 137..138 'a': u32
536 [141; 148) 'S::make': fn make<S, u32>() -> u32 536 141..148 'S::make': fn make<S, u32>() -> u32
537 [141; 150) 'S::make()': u32 537 141..150 'S::make()': u32
538 [160; 161) 'b': u64 538 160..161 'b': u64
539 [164; 178) 'G::<u64>::make': fn make<G<u64>, u64>() -> u64 539 164..178 'G::<u64>::make': fn make<G<u64>, u64>() -> u64
540 [164; 180) 'G::<u6...make()': u64 540 164..180 'G::<u6...make()': u64
541 [190; 191) 'c': f64 541 190..191 'c': f64
542 [199; 206) 'G::make': fn make<G<f64>, f64>() -> f64 542 199..206 'G::make': fn make<G<f64>, f64>() -> f64
543 [199; 208) 'G::make()': f64 543 199..208 'G::make()': f64
544 "### 544 "###
545 ); 545 );
546} 546}
@@ -565,22 +565,22 @@ fn test() {
565} 565}
566"#), 566"#),
567 @r###" 567 @r###"
568 [135; 313) '{ ...e(); }': () 568 135..313 '{ ...e(); }': ()
569 [145; 146) 'a': (u32, i64) 569 145..146 'a': (u32, i64)
570 [149; 163) 'S::make::<i64>': fn make<S, u32, i64>() -> (u32, i64) 570 149..163 'S::make::<i64>': fn make<S, u32, i64>() -> (u32, i64)
571 [149; 165) 'S::mak...i64>()': (u32, i64) 571 149..165 'S::mak...i64>()': (u32, i64)
572 [175; 176) 'b': (u32, i64) 572 175..176 'b': (u32, i64)
573 [189; 196) 'S::make': fn make<S, u32, i64>() -> (u32, i64) 573 189..196 'S::make': fn make<S, u32, i64>() -> (u32, i64)
574 [189; 198) 'S::make()': (u32, i64) 574 189..198 'S::make()': (u32, i64)
575 [208; 209) 'c': (u32, i64) 575 208..209 'c': (u32, i64)
576 [212; 233) 'G::<u3...:<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64) 576 212..233 'G::<u3...:<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64)
577 [212; 235) 'G::<u3...i64>()': (u32, i64) 577 212..235 'G::<u3...i64>()': (u32, i64)
578 [245; 246) 'd': (u32, i64) 578 245..246 'd': (u32, i64)
579 [259; 273) 'G::make::<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64) 579 259..273 'G::make::<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64)
580 [259; 275) 'G::mak...i64>()': (u32, i64) 580 259..275 'G::mak...i64>()': (u32, i64)
581 [285; 286) 'e': (u32, i64) 581 285..286 'e': (u32, i64)
582 [301; 308) 'G::make': fn make<G<u32>, u32, i64>() -> (u32, i64) 582 301..308 'G::make': fn make<G<u32>, u32, i64>() -> (u32, i64)
583 [301; 310) 'G::make()': (u32, i64) 583 301..310 'G::make()': (u32, i64)
584 "### 584 "###
585 ); 585 );
586} 586}
@@ -599,10 +599,10 @@ fn test() {
599} 599}
600"#), 600"#),
601 @r###" 601 @r###"
602 [101; 127) '{ ...e(); }': () 602 101..127 '{ ...e(); }': ()
603 [111; 112) 'a': (S<i32>, i64) 603 111..112 'a': (S<i32>, i64)
604 [115; 122) 'S::make': fn make<S<i32>, i64>() -> (S<i32>, i64) 604 115..122 'S::make': fn make<S<i32>, i64>() -> (S<i32>, i64)
605 [115; 124) 'S::make()': (S<i32>, i64) 605 115..124 'S::make()': (S<i32>, i64)
606 "### 606 "###
607 ); 607 );
608} 608}
@@ -623,13 +623,13 @@ fn test() {
623} 623}
624"#), 624"#),
625 @r###" 625 @r###"
626 [131; 203) '{ ...e(); }': () 626 131..203 '{ ...e(); }': ()
627 [141; 142) 'a': (S<u64>, i64) 627 141..142 'a': (S<u64>, i64)
628 [158; 165) 'S::make': fn make<S<u64>, i64>() -> (S<u64>, i64) 628 158..165 'S::make': fn make<S<u64>, i64>() -> (S<u64>, i64)
629 [158; 167) 'S::make()': (S<u64>, i64) 629 158..167 'S::make()': (S<u64>, i64)
630 [177; 178) 'b': (S<u32>, i32) 630 177..178 'b': (S<u32>, i32)
631 [191; 198) 'S::make': fn make<S<u32>, i32>() -> (S<u32>, i32) 631 191..198 'S::make': fn make<S<u32>, i32>() -> (S<u32>, i32)
632 [191; 200) 'S::make()': (S<u32>, i32) 632 191..200 'S::make()': (S<u32>, i32)
633 "### 633 "###
634 ); 634 );
635} 635}
@@ -649,13 +649,13 @@ fn test() {
649} 649}
650"#), 650"#),
651 @r###" 651 @r###"
652 [107; 211) '{ ...>(); }': () 652 107..211 '{ ...>(); }': ()
653 [117; 118) 'a': (S<u64>, i64, u8) 653 117..118 'a': (S<u64>, i64, u8)
654 [121; 150) '<S as ...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8) 654 121..150 '<S as ...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
655 [121; 152) '<S as ...<u8>()': (S<u64>, i64, u8) 655 121..152 '<S as ...<u8>()': (S<u64>, i64, u8)
656 [162; 163) 'b': (S<u64>, i64, u8) 656 162..163 'b': (S<u64>, i64, u8)
657 [182; 206) 'Trait:...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8) 657 182..206 'Trait:...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
658 [182; 208) 'Trait:...<u8>()': (S<u64>, i64, u8) 658 182..208 'Trait:...<u8>()': (S<u64>, i64, u8)
659 "### 659 "###
660 ); 660 );
661} 661}
@@ -672,11 +672,11 @@ fn test<T: Trait>(t: T) {
672} 672}
673"#), 673"#),
674 @r###" 674 @r###"
675 [30; 34) 'self': &Self 675 30..34 'self': &Self
676 [64; 65) 't': T 676 64..65 't': T
677 [70; 89) '{ ...d(); }': () 677 70..89 '{ ...d(); }': ()
678 [76; 77) 't': T 678 76..77 't': T
679 [76; 86) 't.method()': u32 679 76..86 't.method()': u32
680 "### 680 "###
681 ); 681 );
682} 682}
@@ -693,11 +693,11 @@ fn test<U, T: Trait<U>>(t: T) {
693} 693}
694"#), 694"#),
695 @r###" 695 @r###"
696 [33; 37) 'self': &Self 696 33..37 'self': &Self
697 [71; 72) 't': T 697 71..72 't': T
698 [77; 96) '{ ...d(); }': () 698 77..96 '{ ...d(); }': ()
699 [83; 84) 't': T 699 83..84 't': T
700 [83; 93) 't.method()': U 700 83..93 't.method()': U
701 "### 701 "###
702 ); 702 );
703} 703}
@@ -719,18 +719,18 @@ fn test() {
719} 719}
720"#), 720"#),
721 @r###" 721 @r###"
722 [29; 33) 'self': Self 722 29..33 'self': Self
723 [111; 202) '{ ...(S); }': () 723 111..202 '{ ...(S); }': ()
724 [121; 122) 'x': u32 724 121..122 'x': u32
725 [130; 131) 'S': S 725 130..131 'S': S
726 [130; 138) 'S.into()': u32 726 130..138 'S.into()': u32
727 [148; 149) 'y': u64 727 148..149 'y': u64
728 [157; 158) 'S': S 728 157..158 'S': S
729 [157; 165) 'S.into()': u64 729 157..165 'S.into()': u64
730 [175; 176) 'z': u64 730 175..176 'z': u64
731 [179; 196) 'Into::...::into': fn into<S, u64>(S) -> u64 731 179..196 'Into::...::into': fn into<S, u64>(S) -> u64
732 [179; 199) 'Into::...nto(S)': u64 732 179..199 'Into::...nto(S)': u64
733 [197; 198) 'S': S 733 197..198 'S': S
734 "### 734 "###
735 ); 735 );
736} 736}
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs
index 6ea51d5d3..af291092d 100644
--- a/crates/ra_hir_ty/src/tests/patterns.rs
+++ b/crates/ra_hir_ty/src/tests/patterns.rs
@@ -30,54 +30,54 @@ fn test(x: &i32) {
30} 30}
31"#), 31"#),
32 @r###" 32 @r###"
33 [9; 10) 'x': &i32 33 9..10 'x': &i32
34 [18; 369) '{ ...o_x; }': () 34 18..369 '{ ...o_x; }': ()
35 [28; 29) 'y': &i32 35 28..29 'y': &i32
36 [32; 33) 'x': &i32 36 32..33 'x': &i32
37 [43; 45) '&z': &i32 37 43..45 '&z': &i32
38 [44; 45) 'z': i32 38 44..45 'z': i32
39 [48; 49) 'x': &i32 39 48..49 'x': &i32
40 [59; 60) 'a': i32 40 59..60 'a': i32
41 [63; 64) 'z': i32 41 63..64 'z': i32
42 [74; 80) '(c, d)': (i32, &str) 42 74..80 '(c, d)': (i32, &str)
43 [75; 76) 'c': i32 43 75..76 'c': i32
44 [78; 79) 'd': &str 44 78..79 'd': &str
45 [83; 95) '(1, "hello")': (i32, &str) 45 83..95 '(1, "hello")': (i32, &str)
46 [84; 85) '1': i32 46 84..85 '1': i32
47 [87; 94) '"hello"': &str 47 87..94 '"hello"': &str
48 [102; 152) 'for (e... }': () 48 102..152 'for (e... }': ()
49 [106; 112) '(e, f)': ({unknown}, {unknown}) 49 106..112 '(e, f)': ({unknown}, {unknown})
50 [107; 108) 'e': {unknown} 50 107..108 'e': {unknown}
51 [110; 111) 'f': {unknown} 51 110..111 'f': {unknown}
52 [116; 125) 'some_iter': {unknown} 52 116..125 'some_iter': {unknown}
53 [126; 152) '{ ... }': () 53 126..152 '{ ... }': ()
54 [140; 141) 'g': {unknown} 54 140..141 'g': {unknown}
55 [144; 145) 'e': {unknown} 55 144..145 'e': {unknown}
56 [158; 205) 'if let... }': () 56 158..205 'if let... }': ()
57 [165; 170) '[val]': [{unknown}] 57 165..170 '[val]': [{unknown}]
58 [166; 169) 'val': {unknown} 58 166..169 'val': {unknown}
59 [173; 176) 'opt': [{unknown}] 59 173..176 'opt': [{unknown}]
60 [177; 205) '{ ... }': () 60 177..205 '{ ... }': ()
61 [191; 192) 'h': {unknown} 61 191..192 'h': {unknown}
62 [195; 198) 'val': {unknown} 62 195..198 'val': {unknown}
63 [215; 221) 'lambda': |u64, u64, i32| -> i32 63 215..221 'lambda': |u64, u64, i32| -> i32
64 [224; 256) '|a: u6...b; c }': |u64, u64, i32| -> i32 64 224..256 '|a: u6...b; c }': |u64, u64, i32| -> i32
65 [225; 226) 'a': u64 65 225..226 'a': u64
66 [233; 234) 'b': u64 66 233..234 'b': u64
67 [236; 237) 'c': i32 67 236..237 'c': i32
68 [244; 256) '{ a + b; c }': i32 68 244..256 '{ a + b; c }': i32
69 [246; 247) 'a': u64 69 246..247 'a': u64
70 [246; 251) 'a + b': u64 70 246..251 'a + b': u64
71 [250; 251) 'b': u64 71 250..251 'b': u64
72 [253; 254) 'c': i32 72 253..254 'c': i32
73 [267; 279) 'ref ref_to_x': &&i32 73 267..279 'ref ref_to_x': &&i32
74 [282; 283) 'x': &i32 74 282..283 'x': &i32
75 [293; 302) 'mut mut_x': &i32 75 293..302 'mut mut_x': &i32
76 [305; 306) 'x': &i32 76 305..306 'x': &i32
77 [316; 336) 'ref mu...f_to_x': &mut &i32 77 316..336 'ref mu...f_to_x': &mut &i32
78 [339; 340) 'x': &i32 78 339..340 'x': &i32
79 [350; 351) 'k': &mut &i32 79 350..351 'k': &mut &i32
80 [354; 366) 'mut_ref_to_x': &mut &i32 80 354..366 'mut_ref_to_x': &mut &i32
81 "### 81 "###
82 ); 82 );
83} 83}
@@ -97,47 +97,47 @@ fn test(x: &i32) {
97} 97}
98"#, true), 98"#, true),
99 @r###" 99 @r###"
100 [18; 29) '{ loop {} }': T 100 18..29 '{ loop {} }': T
101 [20; 27) 'loop {}': ! 101 20..27 'loop {}': !
102 [25; 27) '{}': () 102 25..27 '{}': ()
103 [38; 39) 'x': &i32 103 38..39 'x': &i32
104 [47; 209) '{ ...) {} }': () 104 47..209 '{ ...) {} }': ()
105 [53; 76) 'if let...y() {}': () 105 53..76 'if let...y() {}': ()
106 [60; 65) '"foo"': &str 106 60..65 '"foo"': &str
107 [60; 65) '"foo"': &str 107 60..65 '"foo"': &str
108 [68; 71) 'any': fn any<&str>() -> &str 108 68..71 'any': fn any<&str>() -> &str
109 [68; 73) 'any()': &str 109 68..73 'any()': &str
110 [74; 76) '{}': () 110 74..76 '{}': ()
111 [81;