From 631cd5845e8de329d0e227aaa707d7ea228b8f8f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:29 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/rust-analyzer/Cargo.lock | 18 +- .../rust-analyzer/bench_data/numerous_macro_rules | 4 +- src/tools/rust-analyzer/crates/flycheck/src/lib.rs | 109 +- src/tools/rust-analyzer/crates/hir-def/src/adt.rs | 19 +- src/tools/rust-analyzer/crates/hir-def/src/attr.rs | 48 +- src/tools/rust-analyzer/crates/hir-def/src/body.rs | 71 +- .../rust-analyzer/crates/hir-def/src/body/lower.rs | 202 +-- .../crates/hir-def/src/body/pretty.rs | 103 +- .../rust-analyzer/crates/hir-def/src/body/scope.rs | 50 +- .../crates/hir-def/src/body/tests/block.rs | 22 + .../crates/hir-def/src/child_by_source.rs | 3 +- src/tools/rust-analyzer/crates/hir-def/src/data.rs | 70 +- src/tools/rust-analyzer/crates/hir-def/src/db.rs | 15 +- src/tools/rust-analyzer/crates/hir-def/src/expr.rs | 70 +- .../rust-analyzer/crates/hir-def/src/generics.rs | 44 +- .../rust-analyzer/crates/hir-def/src/import_map.rs | 2 + .../rust-analyzer/crates/hir-def/src/item_scope.rs | 1 + .../rust-analyzer/crates/hir-def/src/item_tree.rs | 17 +- .../crates/hir-def/src/item_tree/lower.rs | 137 +- .../crates/hir-def/src/item_tree/pretty.rs | 29 +- src/tools/rust-analyzer/crates/hir-def/src/keys.rs | 5 +- .../rust-analyzer/crates/hir-def/src/lang_item.rs | 6 +- src/tools/rust-analyzer/crates/hir-def/src/lib.rs | 17 +- .../crates/hir-def/src/macro_expansion_tests.rs | 2 +- .../src/macro_expansion_tests/builtin_fn_macro.rs | 2 +- .../src/macro_expansion_tests/mbe/regression.rs | 1 + .../rust-analyzer/crates/hir-def/src/nameres.rs | 32 +- .../crates/hir-def/src/nameres/collector.rs | 41 +- .../crates/hir-def/src/nameres/path_resolution.rs | 4 +- .../hir-def/src/nameres/tests/incremental.rs | 1 + src/tools/rust-analyzer/crates/hir-def/src/path.rs | 4 +- .../rust-analyzer/crates/hir-def/src/path/lower.rs | 4 +- .../rust-analyzer/crates/hir-def/src/resolver.rs | 258 +++- .../rust-analyzer/crates/hir-def/src/test_db.rs | 8 +- .../rust-analyzer/crates/hir-def/src/type_ref.rs | 62 +- .../rust-analyzer/crates/hir-def/src/visibility.rs | 31 +- .../rust-analyzer/crates/hir-expand/src/attrs.rs | 12 +- .../crates/hir-expand/src/builtin_attr_macro.rs | 8 +- .../crates/hir-expand/src/builtin_derive_macro.rs | 28 +- .../crates/hir-expand/src/builtin_fn_macro.rs | 58 +- .../rust-analyzer/crates/hir-expand/src/db.rs | 51 +- .../rust-analyzer/crates/hir-expand/src/eager.rs | 8 +- .../rust-analyzer/crates/hir-expand/src/fixup.rs | 3 +- .../rust-analyzer/crates/hir-expand/src/hygiene.rs | 18 +- .../rust-analyzer/crates/hir-expand/src/lib.rs | 88 +- .../crates/hir-expand/src/mod_path.rs | 10 +- .../crates/hir-expand/src/proc_macro.rs | 19 +- src/tools/rust-analyzer/crates/hir-ty/Cargo.toml | 9 +- .../rust-analyzer/crates/hir-ty/src/builder.rs | 9 + .../rust-analyzer/crates/hir-ty/src/chalk_db.rs | 3 +- .../rust-analyzer/crates/hir-ty/src/chalk_ext.rs | 22 +- .../rust-analyzer/crates/hir-ty/src/consteval.rs | 503 ++----- .../crates/hir-ty/src/consteval/tests.rs | 955 +++++++++++- src/tools/rust-analyzer/crates/hir-ty/src/db.rs | 25 +- .../rust-analyzer/crates/hir-ty/src/diagnostics.rs | 6 + .../crates/hir-ty/src/diagnostics/decl_check.rs | 5 +- .../crates/hir-ty/src/diagnostics/expr.rs | 31 +- .../crates/hir-ty/src/diagnostics/match_check.rs | 3 +- .../crates/hir-ty/src/diagnostics/unsafe_check.rs | 6 +- .../rust-analyzer/crates/hir-ty/src/display.rs | 187 ++- src/tools/rust-analyzer/crates/hir-ty/src/infer.rs | 215 ++- .../crates/hir-ty/src/infer/coerce.rs | 60 +- .../rust-analyzer/crates/hir-ty/src/infer/expr.rs | 849 +++++++---- .../rust-analyzer/crates/hir-ty/src/infer/pat.rs | 312 ++-- .../rust-analyzer/crates/hir-ty/src/infer/path.rs | 147 +- .../rust-analyzer/crates/hir-ty/src/infer/unify.rs | 5 +- .../crates/hir-ty/src/inhabitedness.rs | 19 +- .../rust-analyzer/crates/hir-ty/src/interner.rs | 4 +- .../rust-analyzer/crates/hir-ty/src/layout.rs | 16 +- .../rust-analyzer/crates/hir-ty/src/layout/adt.rs | 13 +- .../crates/hir-ty/src/layout/tests.rs | 21 +- src/tools/rust-analyzer/crates/hir-ty/src/lib.rs | 49 +- src/tools/rust-analyzer/crates/hir-ty/src/lower.rs | 30 +- .../crates/hir-ty/src/method_resolution.rs | 213 ++- src/tools/rust-analyzer/crates/hir-ty/src/mir.rs | 863 +++++++++++ .../crates/hir-ty/src/mir/borrowck.rs | 223 +++ .../rust-analyzer/crates/hir-ty/src/mir/eval.rs | 1253 ++++++++++++++++ .../rust-analyzer/crates/hir-ty/src/mir/lower.rs | 1581 ++++++++++++++++++++ .../crates/hir-ty/src/mir/lower/as_place.rs | 237 +++ .../rust-analyzer/crates/hir-ty/src/mir/pretty.rs | 348 +++++ .../rust-analyzer/crates/hir-ty/src/test_db.rs | 8 +- src/tools/rust-analyzer/crates/hir-ty/src/tests.rs | 40 +- .../crates/hir-ty/src/tests/coercion.rs | 3 +- .../crates/hir-ty/src/tests/diagnostics.rs | 21 + .../crates/hir-ty/src/tests/method_resolution.rs | 15 +- .../crates/hir-ty/src/tests/patterns.rs | 30 +- .../crates/hir-ty/src/tests/regression.rs | 52 +- .../crates/hir-ty/src/tests/simple.rs | 84 +- .../crates/hir-ty/src/tests/traits.rs | 71 +- src/tools/rust-analyzer/crates/hir-ty/src/utils.rs | 7 +- src/tools/rust-analyzer/crates/hir/src/attrs.rs | 5 +- src/tools/rust-analyzer/crates/hir/src/db.rs | 5 +- .../rust-analyzer/crates/hir/src/diagnostics.rs | 50 +- src/tools/rust-analyzer/crates/hir/src/display.rs | 49 +- src/tools/rust-analyzer/crates/hir/src/from_id.rs | 13 +- .../rust-analyzer/crates/hir/src/has_source.rs | 21 +- src/tools/rust-analyzer/crates/hir/src/lib.rs | 541 +++++-- .../rust-analyzer/crates/hir/src/semantics.rs | 44 +- .../crates/hir/src/semantics/source_to_def.rs | 38 +- .../crates/hir/src/source_analyzer.rs | 49 +- src/tools/rust-analyzer/crates/hir/src/symbols.rs | 4 + .../ide-assists/src/handlers/add_explicit_type.rs | 4 +- .../src/handlers/convert_iter_for_each_to_for.rs | 19 +- .../src/handlers/convert_match_to_let_else.rs | 85 +- .../ide-assists/src/handlers/extract_function.rs | 25 +- .../ide-assists/src/handlers/extract_variable.rs | 2 +- .../ide-assists/src/handlers/fix_visibility.rs | 4 + .../ide-assists/src/handlers/generate_function.rs | 150 +- .../src/handlers/generate_is_empty_from_len.rs | 9 +- .../ide-assists/src/handlers/generate_new.rs | 2 +- .../crates/ide-assists/src/handlers/inline_call.rs | 40 +- .../src/handlers/inline_local_variable.rs | 11 +- .../crates/ide-assists/src/handlers/remove_dbg.rs | 136 +- .../src/handlers/replace_if_let_with_match.rs | 27 +- .../src/handlers/replace_method_eager_lazy.rs | 310 ++++ .../src/handlers/replace_or_with_or_else.rs | 364 ----- .../rust-analyzer/crates/ide-assists/src/lib.rs | 11 +- .../crates/ide-assists/src/tests/generated.rs | 84 +- .../crates/ide-completion/src/completions.rs | 19 +- .../crates/ide-completion/src/completions/dot.rs | 8 +- .../ide-completion/src/completions/flyimport.rs | 5 +- .../crates/ide-completion/src/completions/type.rs | 4 +- .../crates/ide-completion/src/context.rs | 17 +- .../crates/ide-completion/src/context/analysis.rs | 62 +- .../crates/ide-completion/src/context/tests.rs | 12 + .../crates/ide-completion/src/item.rs | 3 +- .../crates/ide-completion/src/render.rs | 3 + .../crates/ide-completion/src/render/macro_.rs | 59 + .../crates/ide-completion/src/render/pattern.rs | 26 +- .../crates/ide-completion/src/tests/attribute.rs | 4 +- .../crates/ide-completion/src/tests/pattern.rs | 1 + .../crates/ide-completion/src/tests/record.rs | 60 + .../crates/ide-completion/src/tests/special.rs | 1 + .../crates/ide-db/src/active_parameter.rs | 1 + .../crates/ide-db/src/apply_change.rs | 66 +- src/tools/rust-analyzer/crates/ide-db/src/defs.rs | 30 +- .../rust-analyzer/crates/ide-db/src/helpers.rs | 10 +- .../crates/ide-db/src/imports/import_assets.rs | 2 +- src/tools/rust-analyzer/crates/ide-db/src/lib.rs | 12 +- .../rust-analyzer/crates/ide-db/src/rename.rs | 105 +- .../rust-analyzer/crates/ide-db/src/search.rs | 50 +- .../crates/ide-db/src/source_change.rs | 8 + .../crates/ide-db/src/use_trivial_constructor.rs | 34 + .../crates/ide-db/src/use_trivial_contructor.rs | 34 - .../src/handlers/break_outside_of_loop.rs | 23 +- .../src/handlers/expected_function.rs | 39 + .../src/handlers/incoherent_impl.rs | 77 + .../ide-diagnostics/src/handlers/incorrect_case.rs | 2 +- .../ide-diagnostics/src/handlers/missing_fields.rs | 4 +- .../src/handlers/missing_match_arms.rs | 5 +- .../ide-diagnostics/src/handlers/missing_unsafe.rs | 381 ++++- .../src/handlers/mutability_errors.rs | 649 ++++++++ .../ide-diagnostics/src/handlers/no_such_field.rs | 2 +- .../src/handlers/private_assoc_item.rs | 38 + .../ide-diagnostics/src/handlers/private_field.rs | 20 + .../replace_filter_map_next_with_find_map.rs | 15 +- .../ide-diagnostics/src/handlers/type_mismatch.rs | 86 +- .../src/handlers/unresolved_field.rs | 148 ++ .../src/handlers/unresolved_method.rs | 131 ++ .../src/handlers/unresolved_module.rs | 2 +- .../crates/ide-diagnostics/src/lib.rs | 12 +- .../rust-analyzer/crates/ide-ssr/src/matching.rs | 2 +- .../rust-analyzer/crates/ide/src/doc_links.rs | 15 +- .../rust-analyzer/crates/ide/src/file_structure.rs | 79 +- .../crates/ide/src/goto_definition.rs | 25 +- .../crates/ide/src/goto_implementation.rs | 1 + .../crates/ide/src/goto_type_definition.rs | 2 +- .../crates/ide/src/highlight_related.rs | 57 +- src/tools/rust-analyzer/crates/ide/src/hover.rs | 1 + .../rust-analyzer/crates/ide/src/hover/render.rs | 31 +- .../rust-analyzer/crates/ide/src/hover/tests.rs | 350 ++++- .../crates/ide/src/inlay_hints/adjustment.rs | 51 +- .../crates/ide/src/inlay_hints/bind_pat.rs | 117 +- .../crates/ide/src/inlay_hints/chaining.rs | 12 +- .../crates/ide/src/inlay_hints/discriminant.rs | 10 +- src/tools/rust-analyzer/crates/ide/src/lib.rs | 5 + src/tools/rust-analyzer/crates/ide/src/markup.rs | 2 +- src/tools/rust-analyzer/crates/ide/src/moniker.rs | 3 + .../rust-analyzer/crates/ide/src/move_item.rs | 1 + .../crates/ide/src/navigation_target.rs | 26 +- .../rust-analyzer/crates/ide/src/references.rs | 32 + src/tools/rust-analyzer/crates/ide/src/rename.rs | 22 + .../rust-analyzer/crates/ide/src/runnables.rs | 290 +++- .../rust-analyzer/crates/ide/src/signature_help.rs | 269 +++- .../rust-analyzer/crates/ide/src/static_index.rs | 1 + .../ide/src/syntax_highlighting/highlight.rs | 5 +- .../crates/ide/src/syntax_highlighting/inject.rs | 1 + .../crates/ide/src/syntax_highlighting/tags.rs | 1 + .../test_data/highlight_attributes.html | 2 +- .../crates/ide/src/syntax_highlighting/tests.rs | 2 +- src/tools/rust-analyzer/crates/ide/src/view_mir.rs | 29 + .../rust-analyzer/crates/parser/src/grammar.rs | 4 + .../crates/parser/src/grammar/attributes.rs | 2 +- .../crates/parser/src/grammar/expressions.rs | 28 +- .../crates/parser/src/grammar/expressions/atom.rs | 10 +- .../crates/parser/src/grammar/items/traits.rs | 2 +- .../crates/parser/src/grammar/paths.rs | 6 + .../crates/parser/src/grammar/patterns.rs | 15 +- .../crates/parser/src/syntax_kind/generated.rs | 1 + .../err/0049_let_else_right_curly_brace_for.rast | 58 + .../err/0049_let_else_right_curly_brace_for.rs | 6 + .../err/0050_let_else_right_curly_brace_loop.rast | 46 + .../err/0050_let_else_right_curly_brace_loop.rs | 6 + .../err/0051_let_else_right_curly_brace_match.rast | 85 ++ .../err/0051_let_else_right_curly_brace_match.rs | 8 + .../err/0052_let_else_right_curly_brace_while.rast | 49 + .../err/0052_let_else_right_curly_brace_while.rs | 6 + .../err/0053_let_else_right_curly_brace_if.rast | 57 + .../err/0053_let_else_right_curly_brace_if.rs | 7 + .../inline/err/0016_angled_path_without_qual.rast | 49 + .../inline/err/0016_angled_path_without_qual.rs | 2 + .../err/0017_let_else_right_curly_brace.rast | 69 + .../inline/err/0017_let_else_right_curly_brace.rs | 1 + .../parser/inline/ok/0151_trait_alias.rast | 2 +- .../inline/ok/0177_trait_alias_where_clause.rast | 4 +- .../crates/project-model/src/build_scripts.rs | 85 +- .../crates/project-model/src/cargo_workspace.rs | 8 +- .../rust-analyzer/crates/project-model/src/lib.rs | 2 +- .../crates/project-model/src/sysroot.rs | 21 +- .../crates/project-model/src/tests.rs | 15 +- .../crates/project-model/src/workspace.rs | 206 +-- .../crates/rust-analyzer/src/cli/analysis_stats.rs | 193 ++- .../crates/rust-analyzer/src/cli/diagnostics.rs | 4 +- .../crates/rust-analyzer/src/cli/lsif.rs | 5 +- .../crates/rust-analyzer/src/cli/scip.rs | 5 +- .../crates/rust-analyzer/src/cli/ssr.rs | 5 +- .../crates/rust-analyzer/src/config.rs | 71 +- .../crates/rust-analyzer/src/dispatch.rs | 36 + .../crates/rust-analyzer/src/handlers.rs | 22 +- .../crates/rust-analyzer/src/lsp_ext.rs | 8 + .../crates/rust-analyzer/src/lsp_utils.rs | 40 +- .../crates/rust-analyzer/src/main_loop.rs | 82 +- .../crates/rust-analyzer/src/reload.rs | 134 +- .../crates/rust-analyzer/src/to_proto.rs | 4 +- src/tools/rust-analyzer/crates/syntax/Cargo.toml | 1 + src/tools/rust-analyzer/crates/syntax/rust.ungram | 10 +- src/tools/rust-analyzer/crates/syntax/src/ast.rs | 12 +- .../crates/syntax/src/ast/expr_ext.rs | 43 +- .../crates/syntax/src/ast/generated/nodes.rs | 43 +- .../crates/syntax/src/ast/node_ext.rs | 81 +- .../rust-analyzer/crates/syntax/src/ast/traits.rs | 4 +- .../crates/syntax/src/tests/ast_src.rs | 1 + .../crates/syntax/src/tests/sourcegen_ast.rs | 1 + .../rust-analyzer/crates/test-utils/src/fixture.rs | 4 +- .../crates/test-utils/src/minicore.rs | 51 + .../rust-analyzer/crates/toolchain/src/lib.rs | 21 +- src/tools/rust-analyzer/docs/dev/lsp-extensions.md | 13 +- .../rust-analyzer/docs/user/generated_config.adoc | 15 +- src/tools/rust-analyzer/lib/la-arena/src/map.rs | 6 + 249 files changed, 14422 insertions(+), 3537 deletions(-) create mode 100644 src/tools/rust-analyzer/crates/hir-ty/src/mir.rs create mode 100644 src/tools/rust-analyzer/crates/hir-ty/src/mir/borrowck.rs create mode 100644 src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs create mode 100644 src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs create mode 100644 src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/as_place.rs create mode 100644 src/tools/rust-analyzer/crates/hir-ty/src/mir/pretty.rs create mode 100644 src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs delete mode 100644 src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_or_with_or_else.rs create mode 100644 src/tools/rust-analyzer/crates/ide-db/src/use_trivial_constructor.rs delete mode 100644 src/tools/rust-analyzer/crates/ide-db/src/use_trivial_contructor.rs create mode 100644 src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/expected_function.rs create mode 100644 src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/incoherent_impl.rs create mode 100644 src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mutability_errors.rs create mode 100644 src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_field.rs create mode 100644 src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_method.rs create mode 100644 src/tools/rust-analyzer/crates/ide/src/view_mir.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0049_let_else_right_curly_brace_for.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0049_let_else_right_curly_brace_for.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0050_let_else_right_curly_brace_loop.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0050_let_else_right_curly_brace_loop.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0051_let_else_right_curly_brace_match.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0051_let_else_right_curly_brace_match.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0052_let_else_right_curly_brace_while.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0052_let_else_right_curly_brace_while.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0053_let_else_right_curly_brace_if.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/err/0053_let_else_right_curly_brace_if.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/inline/err/0016_angled_path_without_qual.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/inline/err/0016_angled_path_without_qual.rs create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/inline/err/0017_let_else_right_curly_brace.rast create mode 100644 src/tools/rust-analyzer/crates/parser/test_data/parser/inline/err/0017_let_else_right_curly_brace.rs (limited to 'src/tools/rust-analyzer') diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index ec1977672..25242c602 100644 --- a/src/tools/rust-analyzer/Cargo.lock +++ b/src/tools/rust-analyzer/Cargo.lock @@ -169,9 +169,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chalk-derive" -version = "0.88.0" +version = "0.89.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4df80a3fbc1f0e59f560eeeebca94bf655566a8ad3023c210a109deb6056455a" +checksum = "ea176c50987dc4765961aa165001e8eb5a722a26308c5797a47303ea91686aab" dependencies = [ "proc-macro2", "quote", @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "chalk-ir" -version = "0.88.0" +version = "0.89.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f39e5272016916956298cceea5147006f897972c274a768ed4d6e074efe5d3fb" +checksum = "473b480241695428c14e8f84f1c9a47ef232450a50faf3a4041e5c9dc11e0a3b" dependencies = [ "bitflags", "chalk-derive", @@ -192,9 +192,9 @@ dependencies = [ [[package]] name = "chalk-recursive" -version = "0.88.0" +version = "0.89.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9d60b42ad7478d3e027e2f9ea4e99fbbb8fdee0c8c3cf068be269f57e603618" +checksum = "6764b4fe67cac3a3758185084efbfbd39bf0352795824ba849ddd2b64cd4bb28" dependencies = [ "chalk-derive", "chalk-ir", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.88.0" +version = "0.89.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab30620ea5b36819525eaab2204f4b8e1842fc7ee36826424a28bef59ae7fecf" +checksum = "55a7e6160966eceb6e7dcc2f479a2af4c477aaf5bccbc640d82515995ab1a6cc" dependencies = [ "chalk-derive", "chalk-ir", @@ -572,6 +572,7 @@ dependencies = [ "chalk-recursive", "chalk-solve", "cov-mark", + "either", "ena", "expect-test", "hir-def", @@ -1714,6 +1715,7 @@ name = "syntax" version = "0.0.0" dependencies = [ "cov-mark", + "either", "expect-test", "indexmap", "itertools", diff --git a/src/tools/rust-analyzer/bench_data/numerous_macro_rules b/src/tools/rust-analyzer/bench_data/numerous_macro_rules index bf89ed594..7610a3ae1 100644 --- a/src/tools/rust-analyzer/bench_data/numerous_macro_rules +++ b/src/tools/rust-analyzer/bench_data/numerous_macro_rules @@ -341,8 +341,8 @@ macro_rules! __ra_macro_fixture339 {($name : ident )=>{ impl Clone for $name macro_rules! __ra_macro_fixture340 {([$($stack : tt )*])=>{$($stack )* }; ([$($stack : tt )*]{$($tail : tt )* })=>{$($stack )* { remove_sections_inner ! ([]$($tail )*); }}; ([$($stack : tt )*]$t : tt $($tail : tt )*)=>{ remove_sections ! ([$($stack )* $t ]$($tail )*); }; } macro_rules! __ra_macro_fixture341 {($t : ty ,$z : expr )=>{ impl Zero for $t { fn zero ()-> Self {$z as $t } fn is_zero (& self )-> bool { self == & Self :: zero ()}}}; } macro_rules! __ra_macro_fixture342 {($($ident : ident ),* $(,)?)=>{$(# [ allow ( bad_style )] pub const $ident : super :: Name = super :: Name :: new_inline ( stringify ! ($ident )); )* }; } -macro_rules! __ra_macro_fixture343 {($($trait : ident =>$expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinDeriveExpander {$($trait ),* } impl BuiltinDeriveExpander { pub fn expand (& self , db : & dyn AstDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> Result < tt :: Subtree , mbe :: ExpandError > { let expander = match * self {$(BuiltinDeriveExpander ::$trait =>$expand , )* }; expander ( db , id , tt )} fn find_by_name ( name : & name :: Name )-> Option < Self > { match name {$(id if id == & name :: name ! [$trait ]=> Some ( BuiltinDeriveExpander ::$trait ), )* _ => None , }}}}; } -macro_rules! __ra_macro_fixture344 {( LAZY : $(($name : ident , $kind : ident )=>$expand : ident ),* , EAGER : $(($e_name : ident , $e_kind : ident )=>$e_expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinFnLikeExpander {$($kind ),* }# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum EagerExpander {$($e_kind ),* } impl BuiltinFnLikeExpander { pub fn expand (& self , db : & dyn AstDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> ExpandResult < tt :: Subtree > { let expander = match * self {$(BuiltinFnLikeExpander ::$kind =>$expand , )* }; expander ( db , id , tt )}} impl EagerExpander { pub fn expand (& self , db : & dyn AstDatabase , arg_id : EagerMacroId , tt : & tt :: Subtree , )-> ExpandResult < Option < ( tt :: Subtree , FragmentKind )>> { let expander = match * self {$(EagerExpander ::$e_kind =>$e_expand , )* }; expander ( db , arg_id , tt )}} fn find_by_name ( ident : & name :: Name )-> Option < Either < BuiltinFnLikeExpander , EagerExpander >> { match ident {$(id if id == & name :: name ! [$name ]=> Some ( Either :: Left ( BuiltinFnLikeExpander ::$kind )), )* $(id if id == & name :: name ! [$e_name ]=> Some ( Either :: Right ( EagerExpander ::$e_kind )), )* _ => return None , }}}; } +macro_rules! __ra_macro_fixture343 {($($trait : ident =>$expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinDeriveExpander {$($trait ),* } impl BuiltinDeriveExpander { pub fn expand (& self , db : & dyn ExpandDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> Result < tt :: Subtree , mbe :: ExpandError > { let expander = match * self {$(BuiltinDeriveExpander ::$trait =>$expand , )* }; expander ( db , id , tt )} fn find_by_name ( name : & name :: Name )-> Option < Self > { match name {$(id if id == & name :: name ! [$trait ]=> Some ( BuiltinDeriveExpander ::$trait ), )* _ => None , }}}}; } +macro_rules! __ra_macro_fixture344 {( LAZY : $(($name : ident , $kind : ident )=>$expand : ident ),* , EAGER : $(($e_name : ident , $e_kind : ident )=>$e_expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinFnLikeExpander {$($kind ),* }# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum EagerExpander {$($e_kind ),* } impl BuiltinFnLikeExpander { pub fn expand (& self , db : & dyn ExpandDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> ExpandResult < tt :: Subtree > { let expander = match * self {$(BuiltinFnLikeExpander ::$kind =>$expand , )* }; expander ( db , id , tt )}} impl EagerExpander { pub fn expand (& self , db : & dyn ExpandDatabase , arg_id : EagerMacroId , tt : & tt :: Subtree , )-> ExpandResult < Option < ( tt :: Subtree , FragmentKind )>> { let expander = match * self {$(EagerExpander ::$e_kind =>$e_expand , )* }; expander ( db , arg_id , tt )}} fn find_by_name ( ident : & name :: Name )-> Option < Either < BuiltinFnLikeExpander , EagerExpander >> { match ident {$(id if id == & name :: name ! [$name ]=> Some ( Either :: Left ( BuiltinFnLikeExpander ::$kind )), )* $(id if id == & name :: name ! [$e_name ]=> Some ( Either :: Right ( EagerExpander ::$e_kind )), )* _ => return None , }}}; } macro_rules! __ra_macro_fixture345 {($($ty : ty =>$this : ident $im : block );*)=>{$(impl ToTokenTree for $ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . into (); leaf . into ()}} impl ToTokenTree for &$ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . clone (). into (); leaf . into ()}})* }} macro_rules! __ra_macro_fixture346 {($name : ident )=>{ impl $crate :: salsa :: InternKey for $name { fn from_intern_id ( v : $crate :: salsa :: InternId )-> Self {$name ( v )} fn as_intern_id (& self )-> $crate :: salsa :: InternId { self . 0 }}}; } macro_rules! __ra_macro_fixture347 {($($var : ident ($t : ty )),+ )=>{$(impl From <$t > for AttrOwner { fn from ( t : $t )-> AttrOwner { AttrOwner ::$var ( t )}})+ }; } diff --git a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs index 11f7b068e..accb14a51 100644 --- a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs +++ b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs @@ -76,7 +76,7 @@ impl fmt::Display for FlycheckConfig { #[derive(Debug)] pub struct FlycheckHandle { // XXX: drop order is significant - sender: Sender, + sender: Sender, _thread: jod_thread::JoinHandle, id: usize, } @@ -89,7 +89,7 @@ impl FlycheckHandle { workspace_root: AbsPathBuf, ) -> FlycheckHandle { let actor = FlycheckActor::new(id, sender, config, workspace_root); - let (sender, receiver) = unbounded::(); + let (sender, receiver) = unbounded::(); let thread = jod_thread::Builder::new() .name("Flycheck".to_owned()) .spawn(move || actor.run(receiver)) @@ -99,12 +99,12 @@ impl FlycheckHandle { /// Schedule a re-start of the cargo check worker. pub fn restart(&self) { - self.sender.send(Restart::Yes).unwrap(); + self.sender.send(StateChange::Restart).unwrap(); } /// Stop this cargo check worker. pub fn cancel(&self) { - self.sender.send(Restart::No).unwrap(); + self.sender.send(StateChange::Cancel).unwrap(); } pub fn id(&self) -> usize { @@ -149,9 +149,9 @@ pub enum Progress { DidFailToRestart(String), } -enum Restart { - Yes, - No, +enum StateChange { + Restart, + Cancel, } /// A [`FlycheckActor`] is a single check instance of a workspace. @@ -172,7 +172,7 @@ struct FlycheckActor { } enum Event { - Restart(Restart), + RequestStateChange(StateChange), CheckEvent(Option), } @@ -191,30 +191,31 @@ impl FlycheckActor { self.send(Message::Progress { id: self.id, progress }); } - fn next_event(&self, inbox: &Receiver) -> Option { + fn next_event(&self, inbox: &Receiver) -> Option { let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver); if let Ok(msg) = inbox.try_recv() { // give restarts a preference so check outputs don't block a restart or stop - return Some(Event::Restart(msg)); + return Some(Event::RequestStateChange(msg)); } select! { - recv(inbox) -> msg => msg.ok().map(Event::Restart), + recv(inbox) -> msg => msg.ok().map(Event::RequestStateChange), recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())), } } - fn run(mut self, inbox: Receiver) { + fn run(mut self, inbox: Receiver) { 'event: while let Some(event) = self.next_event(&inbox) { match event { - Event::Restart(Restart::No) => { + Event::RequestStateChange(StateChange::Cancel) => { + tracing::debug!(flycheck_id = self.id, "flycheck cancelled"); self.cancel_check_process(); } - Event::Restart(Restart::Yes) => { + Event::RequestStateChange(StateChange::Restart) => { // Cancel the previously spawned process self.cancel_check_process(); while let Ok(restart) = inbox.recv_timeout(Duration::from_millis(50)) { // restart chained with a stop, so just cancel - if let Restart::No = restart { + if let StateChange::Cancel = restart { continue 'event; } } @@ -255,10 +256,20 @@ impl FlycheckActor { } Event::CheckEvent(Some(message)) => match message { CargoMessage::CompilerArtifact(msg) => { + tracing::trace!( + flycheck_id = self.id, + artifact = msg.target.name, + "artifact received" + ); self.report_progress(Progress::DidCheckCrate(msg.target.name)); } CargoMessage::Diagnostic(msg) => { + tracing::trace!( + flycheck_id = self.id, + message = msg.message, + "diagnostic received" + ); self.send(Message::AddDiagnostic { id: self.id, workspace_root: self.root.clone(), @@ -445,42 +456,56 @@ impl CargoActor { // simply skip a line if it doesn't parse, which just ignores any // erroneous output. - let mut error = String::new(); - let mut read_at_least_one_message = false; + let mut stdout_errors = String::new(); + let mut stderr_errors = String::new(); + let mut read_at_least_one_stdout_message = false; + let mut read_at_least_one_stderr_message = false; + let process_line = |line: &str, error: &mut String| { + // Try to deserialize a message from Cargo or Rustc. + let mut deserializer = serde_json::Deserializer::from_str(line); + deserializer.disable_recursion_limit(); + if let Ok(message) = JsonMessage::deserialize(&mut deserializer) { + match message { + // Skip certain kinds of messages to only spend time on what's useful + JsonMessage::Cargo(message) => match message { + cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => { + self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap(); + } + cargo_metadata::Message::CompilerMessage(msg) => { + self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap(); + } + _ => (), + }, + JsonMessage::Rustc(message) => { + self.sender.send(CargoMessage::Diagnostic(message)).unwrap(); + } + } + return true; + } + + error.push_str(line); + error.push('\n'); + return false; + }; let output = streaming_output( self.stdout, self.stderr, &mut |line| { - read_at_least_one_message = true; - - // Try to deserialize a message from Cargo or Rustc. - let mut deserializer = serde_json::Deserializer::from_str(line); - deserializer.disable_recursion_limit(); - if let Ok(message) = JsonMessage::deserialize(&mut deserializer) { - match message { - // Skip certain kinds of messages to only spend time on what's useful - JsonMessage::Cargo(message) => match message { - cargo_metadata::Message::CompilerArtifact(artifact) - if !artifact.fresh => - { - self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap(); - } - cargo_metadata::Message::CompilerMessage(msg) => { - self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap(); - } - _ => (), - }, - JsonMessage::Rustc(message) => { - self.sender.send(CargoMessage::Diagnostic(message)).unwrap(); - } - } + if process_line(line, &mut stdout_errors) { + read_at_least_one_stdout_message = true; } }, &mut |line| { - error.push_str(line); - error.push('\n'); + if process_line(line, &mut stderr_errors) { + read_at_least_one_stderr_message = true; + } }, ); + + let read_at_least_one_message = + read_at_least_one_stdout_message || read_at_least_one_stderr_message; + let mut error = stdout_errors; + error.push_str(&stderr_errors); match output { Ok(_) => Ok((read_at_least_one_message, error)), Err(e) => Err(io::Error::new(e.kind(), format!("{e:?}: {error}"))), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/adt.rs b/src/tools/rust-analyzer/crates/hir-def/src/adt.rs index 9bc1c54a3..b336f59ff 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/adt.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/adt.rs @@ -40,6 +40,7 @@ pub struct StructData { pub repr: Option, pub visibility: RawVisibility, pub rustc_has_incoherent_inherent_impls: bool, + pub fundamental: bool, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -173,10 +174,10 @@ impl StructData { let item_tree = loc.id.item_tree(db); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); - let rustc_has_incoherent_inherent_impls = item_tree - .attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()) - .by_key("rustc_has_incoherent_inherent_impls") - .exists(); + let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()); + let rustc_has_incoherent_inherent_impls = + attrs.by_key("rustc_has_incoherent_inherent_impls").exists(); + let fundamental = attrs.by_key("fundamental").exists(); let strukt = &item_tree[loc.id.value]; let (variant_data, diagnostics) = lower_fields( @@ -196,6 +197,7 @@ impl StructData { repr, visibility: item_tree[strukt.visibility].clone(), rustc_has_incoherent_inherent_impls, + fundamental, }), diagnostics.into(), ) @@ -215,10 +217,10 @@ impl StructData { let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); - let rustc_has_incoherent_inherent_impls = item_tree - .attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()) - .by_key("rustc_has_incoherent_inherent_impls") - .exists(); + let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()); + let rustc_has_incoherent_inherent_impls = + attrs.by_key("rustc_has_incoherent_inherent_impls").exists(); + let fundamental = attrs.by_key("fundamental").exists(); let union = &item_tree[loc.id.value]; let (variant_data, diagnostics) = lower_fields( @@ -238,6 +240,7 @@ impl StructData { repr, visibility: item_tree[union.visibility].clone(), rustc_has_incoherent_inherent_impls, + fundamental, }), diagnostics.into(), ) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs index fcd92ad33..200072c17 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs @@ -300,6 +300,7 @@ impl AttrsWithOwner { AdtId::UnionId(it) => attrs_from_item_tree(it.lookup(db).id, db), }, AttrDefId::TraitId(it) => attrs_from_item_tree(it.lookup(db).id, db), + AttrDefId::TraitAliasId(it) => attrs_from_item_tree(it.lookup(db).id, db), AttrDefId::MacroId(it) => match it { MacroId::Macro2Id(it) => attrs_from_item_tree(it.lookup(db).id, db), MacroId::MacroRulesId(it) => attrs_from_item_tree(it.lookup(db).id, db), @@ -315,26 +316,14 @@ impl AttrsWithOwner { let src = it.parent().child_source(db); RawAttrs::from_attrs_owner( db.upcast(), - src.with_value(src.value[it.local_id()].as_ref().either( - |it| match it { - ast::TypeOrConstParam::Type(it) => it as _, - ast::TypeOrConstParam::Const(it) => it as _, - }, - |it| it as _, - )), + src.with_value(&src.value[it.local_id()]), ) } GenericParamId::TypeParamId(it) => { let src = it.parent().child_source(db); RawAttrs::from_attrs_owner( db.upcast(), - src.with_value(src.value[it.local_id()].as_ref().either( - |it| match it { - ast::TypeOrConstParam::Type(it) => it as _, - ast::TypeOrConstParam::Const(it) => it as _, - }, - |it| it as _, - )), + src.with_value(&src.value[it.local_id()]), ) } GenericParamId::LifetimeParamId(it) => { @@ -404,6 +393,7 @@ impl AttrsWithOwner { AttrDefId::StaticId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::ConstId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::TraitId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), + AttrDefId::TraitAliasId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::TypeAliasId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::MacroId(id) => match id { MacroId::Macro2Id(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), @@ -412,28 +402,14 @@ impl AttrsWithOwner { }, AttrDefId::ImplId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::GenericParamId(id) => match id { - GenericParamId::ConstParamId(id) => { - id.parent().child_source(db).map(|source| match &source[id.local_id()] { - Either::Left(ast::TypeOrConstParam::Type(id)) => { - ast::AnyHasAttrs::new(id.clone()) - } - Either::Left(ast::TypeOrConstParam::Const(id)) => { - ast::AnyHasAttrs::new(id.clone()) - } - Either::Right(id) => ast::AnyHasAttrs::new(id.clone()), - }) - } - GenericParamId::TypeParamId(id) => { - id.parent().child_source(db).map(|source| match &source[id.local_id()] { - Either::Left(ast::TypeOrConstParam::Type(id)) => { - ast::AnyHasAttrs::new(id.clone()) - } - Either::Left(ast::TypeOrConstParam::Const(id)) => { - ast::AnyHasAttrs::new(id.clone()) - } - Either::Right(id) => ast::AnyHasAttrs::new(id.clone()), - }) - } + GenericParamId::ConstParamId(id) => id + .parent() + .child_source(db) + .map(|source| ast::AnyHasAttrs::new(source[id.local_id()].clone())), + GenericParamId::TypeParamId(id) => id + .parent() + .child_source(db) + .map(|source| ast::AnyHasAttrs::new(source[id.local_id()].clone())), GenericParamId::LifetimeParamId(id) => id .parent .child_source(db) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body.rs b/src/tools/rust-analyzer/crates/hir-def/src/body.rs index 8fd9255b8..b70e658ef 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body.rs @@ -24,7 +24,9 @@ use syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr}; use crate::{ attr::Attrs, db::DefDatabase, - expr::{dummy_expr_id, Expr, ExprId, Label, LabelId, Pat, PatId}, + expr::{ + dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat, + }, item_scope::BuiltinShadowMode, macro_id_to_def_id, nameres::DefMap, @@ -270,7 +272,7 @@ pub struct Mark { pub struct Body { pub exprs: Arena, pub pats: Arena, - pub or_pats: FxHashMap>, + pub bindings: Arena, pub labels: Arena