From 9326cf7f0cc9a98aaf16c5dff5e7a311d1d4dfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 19 Jun 2023 09:14:04 +0300 Subject: [PATCH] Merge commit 'cd3bf9fe51676b520c546460e6d8919b8c8ff99f' into sync-from-ra --- .github/workflows/autopublish.yaml | 4 +- .github/workflows/ci.yaml | 8 +- Cargo.lock | 50 +- crates/base-db/src/fixture.rs | 6 +- crates/base-db/src/input.rs | 23 + crates/hir-def/src/body.rs | 50 +- crates/hir-def/src/body/lower.rs | 72 +- crates/hir-def/src/body/pretty.rs | 1 + crates/hir-def/src/db.rs | 23 +- crates/hir-def/src/expander.rs | 12 +- crates/hir-def/src/find_path.rs | 4 +- crates/hir-def/src/hir.rs | 20 +- crates/hir-def/src/hir/type_ref.rs | 119 +-- crates/hir-def/src/item_scope.rs | 4 - crates/hir-def/src/item_tree.rs | 6 - crates/hir-def/src/lib.rs | 301 +++++++- .../builtin_derive_macro.rs | 70 +- .../macro_expansion_tests/builtin_fn_macro.rs | 48 +- crates/hir-def/src/nameres.rs | 23 +- crates/hir-def/src/nameres/collector.rs | 102 ++- crates/hir-def/src/path.rs | 4 +- crates/hir-def/src/path/lower.rs | 4 +- crates/hir-def/src/resolver.rs | 38 +- crates/hir-expand/src/ast_id_map.rs | 7 +- crates/hir-expand/src/attrs.rs | 10 +- crates/hir-expand/src/builtin_derive_macro.rs | 154 ++-- crates/hir-expand/src/builtin_fn_macro.rs | 147 ++-- crates/hir-expand/src/db.rs | 108 ++- crates/hir-expand/src/eager.rs | 84 +- crates/hir-expand/src/lib.rs | 72 +- crates/hir-expand/src/proc_macro.rs | 11 +- crates/hir-ty/Cargo.toml | 8 +- crates/hir-ty/src/autoderef.rs | 24 +- crates/hir-ty/src/chalk_db.rs | 4 +- crates/hir-ty/src/consteval.rs | 36 +- crates/hir-ty/src/consteval/tests.rs | 11 + crates/hir-ty/src/db.rs | 1 + crates/hir-ty/src/diagnostics/unsafe_check.rs | 7 +- crates/hir-ty/src/display.rs | 43 +- crates/hir-ty/src/infer.rs | 47 +- crates/hir-ty/src/infer/closure.rs | 3 +- crates/hir-ty/src/infer/expr.rs | 5 +- crates/hir-ty/src/infer/mutability.rs | 4 +- crates/hir-ty/src/infer/path.rs | 17 +- crates/hir-ty/src/interner.rs | 2 +- crates/hir-ty/src/layout/tests.rs | 35 +- crates/hir-ty/src/lower.rs | 119 +-- crates/hir-ty/src/method_resolution.rs | 2 +- crates/hir-ty/src/mir/borrowck.rs | 16 +- crates/hir-ty/src/mir/eval.rs | 18 +- crates/hir-ty/src/mir/lower.rs | 8 +- crates/hir-ty/src/mir/pretty.rs | 3 + crates/hir-ty/src/tests.rs | 2 + crates/hir-ty/src/tests/regression.rs | 23 + crates/hir-ty/src/tests/simple.rs | 48 ++ crates/hir-ty/src/tests/traits.rs | 10 +- crates/hir-ty/src/utils.rs | 30 +- crates/hir/src/from_id.rs | 3 + crates/hir/src/lib.rs | 92 ++- crates/hir/src/semantics.rs | 18 +- crates/hir/src/source_analyzer.rs | 7 +- crates/hir/src/symbols.rs | 1 + .../src/handlers/add_missing_impl_members.rs | 363 ++++++++- .../src/handlers/extract_type_alias.rs | 49 +- .../src/handlers/generate_delegate_methods.rs | 25 +- .../src/handlers/generate_function.rs | 102 ++- .../ide-assists/src/handlers/inline_call.rs | 3 +- .../src/handlers/inline_const_as_literal.rs | 722 ++++++++++++++++++ crates/ide-assists/src/handlers/raw_string.rs | 3 +- .../replace_derive_with_manual_impl.rs | 28 +- crates/ide-assists/src/lib.rs | 2 + crates/ide-assists/src/tests/generated.rs | 21 + crates/ide-assists/src/utils.rs | 95 ++- crates/ide-completion/src/completions/dot.rs | 122 ++- .../src/completions/item_list/trait_impl.rs | 108 ++- crates/ide-db/src/apply_change.rs | 34 +- crates/ide-db/src/path_transform.rs | 169 +++- crates/ide-db/src/search.rs | 2 + .../ide-db/src/test_data/test_doc_alias.txt | 42 +- .../test_symbol_index_collection.txt | 134 ++-- crates/ide/src/hover/tests.rs | 43 ++ crates/ide/src/inlay_hints/chaining.rs | 12 +- crates/ide/src/lib.rs | 2 +- crates/ide/src/syntax_highlighting.rs | 3 + .../test_data/highlight_strings.html | 3 + crates/ide/src/syntax_highlighting/tests.rs | 3 + crates/parser/src/grammar/types.rs | 2 + .../parser/inline/ok/0017_array_type.rast | 5 +- .../test_data/parser/ok/0030_traits.rast | 5 +- .../parser/ok/0043_complex_assignment.rast | 5 +- crates/proc-macro-srv/src/server.rs | 6 +- crates/project-model/src/workspace.rs | 6 + crates/rust-analyzer/Cargo.toml | 3 +- crates/rust-analyzer/src/cli.rs | 17 +- .../rust-analyzer/src/cli/analysis_stats.rs | 328 +++++--- crates/rust-analyzer/src/cli/diagnostics.rs | 8 +- crates/rust-analyzer/src/cli/flags.rs | 20 +- .../rust-analyzer/src/cli/progress_report.rs | 41 +- crates/rust-analyzer/src/dispatch.rs | 48 +- crates/rust-analyzer/src/global_state.rs | 35 +- .../src/handlers/notification.rs | 4 +- crates/rust-analyzer/src/handlers/request.rs | 24 +- crates/rust-analyzer/src/main_loop.rs | 82 +- crates/rust-analyzer/src/reload.rs | 45 +- crates/rust-analyzer/src/to_proto.rs | 33 +- crates/rust-analyzer/tests/slow-tests/main.rs | 13 +- crates/syntax/rust.ungram | 2 +- crates/syntax/src/ast/generated/nodes.rs | 2 +- crates/syntax/src/ast/make.rs | 6 +- crates/test-utils/src/fixture.rs | 4 + crates/test-utils/src/minicore.rs | 51 +- docs/user/manual.adoc | 21 +- editors/code/.vscodeignore | 1 + lib/la-arena/src/lib.rs | 6 + 114 files changed, 3893 insertions(+), 1252 deletions(-) create mode 100644 crates/ide-assists/src/handlers/inline_const_as_literal.rs diff --git a/.github/workflows/autopublish.yaml b/.github/workflows/autopublish.yaml index 7090c94d93c..15cedab1272 100644 --- a/.github/workflows/autopublish.yaml +++ b/.github/workflows/autopublish.yaml @@ -28,7 +28,7 @@ jobs: - name: Publish Crates env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - PATCH: ${{ github.run_number }} + RUN_NUMBER: ${{ github.run_number }} shell: bash run: | git config --global user.email "runner@gha.local" @@ -53,4 +53,4 @@ jobs: # Remove library crates from the workspaces so we don't auto-publish them as well sed -i 's/ "lib\/\*",//' ./Cargo.toml find crates/rust-analyzer -type f -name '*.rs' -exec sed -i 's/rust_analyzer/ra_ap_rust_analyzer/g' {} + - cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$PATCH + cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$(($RUN_NUMBER + 133)) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 622da105fdd..31bb7eed8d7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,6 +24,7 @@ jobs: pull-requests: read outputs: typescript: ${{ steps.filter.outputs.typescript }} + proc_macros: ${{ steps.filter.outputs.proc_macros }} steps: - uses: actions/checkout@v3 - uses: dorny/paths-filter@4067d885736b84de7c414f582ac45897079b0a78 @@ -45,8 +46,8 @@ jobs: runs-on: ${{ matrix.os }} env: CC: deny_c - RUST_CHANNEL: "${{ needs.changes.outputs.proc_macros == 'true' && 'nightly' || 'stable'}}" - USE_SYSROOT_ABI: "${{ needs.changes.outputs.proc_macros == 'true' && '--features sysroot-abi' || ''}}" + RUST_CHANNEL: "${{ needs.changes.outputs.proc_macros == 'true' && 'nightly' || 'stable' }}" + USE_SYSROOT_ABI: "${{ needs.changes.outputs.proc_macros == 'true' && '--features sysroot-abi' || '' }}" strategy: fail-fast: false @@ -62,7 +63,8 @@ jobs: - name: Install Rust toolchain run: | rustup update --no-self-update ${{ env.RUST_CHANNEL }} - rustup component add rustfmt rust-src + rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src + rustup default ${{ env.RUST_CHANNEL }} - name: Cache Dependencies uses: Swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894 diff --git a/Cargo.lock b/Cargo.lock index e36aef6a6aa..50c81ca279e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,21 +177,21 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chalk-derive" -version = "0.89.0" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea176c50987dc4765961aa165001e8eb5a722a26308c5797a47303ea91686aab" +checksum = "c59178fded594fe78c47b841520e5a4399d00fe15fffee19b945958a878cd02d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.15", "synstructure", ] [[package]] name = "chalk-ir" -version = "0.89.0" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473b480241695428c14e8f84f1c9a47ef232450a50faf3a4041e5c9dc11e0a3b" +checksum = "8824be92876823b828d551bb792f79eb1f69c69d1948abf69fccbf84e448e57b" dependencies = [ "bitflags 1.3.2", "chalk-derive", @@ -200,9 +200,9 @@ dependencies = [ [[package]] name = "chalk-recursive" -version = "0.89.0" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6764b4fe67cac3a3758185084efbfbd39bf0352795824ba849ddd2b64cd4bb28" +checksum = "1e110d1260809c238072d1c8ef84060e39983e8ea9d4c6f74b19b0ebbf8904dc" dependencies = [ "chalk-derive", "chalk-ir", @@ -213,9 +213,9 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.89.0" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55a7e6160966eceb6e7dcc2f479a2af4c477aaf5bccbc640d82515995ab1a6cc" +checksum = "12200b19abf4b0633095f7bd099f3ef609d314754b6adb358c68cc04d10589e5" dependencies = [ "chalk-derive", "chalk-ir", @@ -327,7 +327,7 @@ checksum = "f3cdeb9ec472d588e539a818b2dee436825730da08ad0017c4b1a17676bdc8b7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1505,7 +1505,6 @@ dependencies = [ "parking_lot 0.12.1", "parking_lot_core 0.9.6", "proc-macro-api", - "proc-macro-srv-cli", "profile", "project-model", "rayon", @@ -1578,7 +1577,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1637,7 +1636,7 @@ checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1660,7 +1659,7 @@ checksum = "395627de918015623b32e7669714206363a7fc00382bf477e72c1f7533e8eafc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1731,14 +1730,25 @@ dependencies = [ ] [[package]] -name = "synstructure" -version = "0.12.6" +name = "syn" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", "quote", - "syn", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", "unicode-xid", ] @@ -1811,7 +1821,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1913,7 +1923,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] diff --git a/crates/base-db/src/fixture.rs b/crates/base-db/src/fixture.rs index 5b11343173b..d3abc3870b7 100644 --- a/crates/base-db/src/fixture.rs +++ b/crates/base-db/src/fixture.rs @@ -215,7 +215,7 @@ pub fn parse_with_proc_macros( None, default_cfg, Default::default(), - Env::default(), + Env::new_for_test_fixture(), false, CrateOrigin::Local { repo: None, name: None }, default_target_data_layout @@ -259,7 +259,7 @@ pub fn parse_with_proc_macros( None, Default::default(), Default::default(), - Env::default(), + Env::new_for_test_fixture(), false, CrateOrigin::Lang(LangCrateOrigin::Core), target_layout.clone(), @@ -298,7 +298,7 @@ pub fn parse_with_proc_macros( None, Default::default(), Default::default(), - Env::default(), + Env::new_for_test_fixture(), true, CrateOrigin::Local { repo: None, name: None }, target_layout, diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index e8d521b42f8..f2e523675bc 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -151,6 +151,12 @@ pub enum CrateOrigin { Lang(LangCrateOrigin), } +impl CrateOrigin { + pub fn is_local(&self) -> bool { + matches!(self, CrateOrigin::Local { .. }) + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum LangCrateOrigin { Alloc, @@ -333,6 +339,17 @@ pub struct Env { entries: FxHashMap, } +impl Env { + pub fn new_for_test_fixture() -> Self { + Env { + entries: FxHashMap::from_iter([( + String::from("__ra_is_test_fixture"), + String::from("__ra_is_test_fixture"), + )]), + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Dependency { pub crate_id: CrateId, @@ -456,6 +473,12 @@ pub fn iter(&self) -> impl Iterator + '_ { self.arena.iter().map(|(idx, _)| idx) } + // FIXME: used for `handle_hack_cargo_workspace`, should be removed later + #[doc(hidden)] + pub fn iter_mut(&mut self) -> impl Iterator + '_ { + self.arena.iter_mut() + } + /// Returns an iterator over all transitive dependencies of the given crate, /// including the crate itself. pub fn transitive_deps(&self, of: CrateId) -> impl Iterator { diff --git a/crates/hir-def/src/body.rs b/crates/hir-def/src/body.rs index 36626ed1a9b..94dc39b1175 100644 --- a/crates/hir-def/src/body.rs +++ b/crates/hir-def/src/body.rs @@ -37,6 +37,9 @@ pub struct Body { pub pats: Arena, pub bindings: Arena, pub labels: Arena