mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Merge commit '141fc695dca1df7cfc3c9803972ec19bb178dcbc' into sync-from-ra
This commit is contained in:
parent
d45ff2484f
commit
59f5d51852
5
.github/workflows/release.yaml
vendored
5
.github/workflows/release.yaml
vendored
@ -30,7 +30,6 @@ jobs:
|
|||||||
code-target: win32-x64
|
code-target: win32-x64
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: i686-pc-windows-msvc
|
target: i686-pc-windows-msvc
|
||||||
code-target: win32-ia32
|
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: aarch64-pc-windows-msvc
|
target: aarch64-pc-windows-msvc
|
||||||
code-target: win32-arm64
|
code-target: win32-arm64
|
||||||
@ -102,12 +101,12 @@ jobs:
|
|||||||
working-directory: editors/code
|
working-directory: editors/code
|
||||||
|
|
||||||
- name: Package Extension (release)
|
- name: Package Extension (release)
|
||||||
if: github.ref == 'refs/heads/release'
|
if: github.ref == 'refs/heads/release' && matrix.code-target
|
||||||
run: npx vsce package -o "../../dist/rust-analyzer-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }}
|
run: npx vsce package -o "../../dist/rust-analyzer-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }}
|
||||||
working-directory: editors/code
|
working-directory: editors/code
|
||||||
|
|
||||||
- name: Package Extension (nightly)
|
- name: Package Extension (nightly)
|
||||||
if: github.ref != 'refs/heads/release'
|
if: github.ref != 'refs/heads/release' && matrix.code-target
|
||||||
run: npx vsce package -o "../../dist/rust-analyzer-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }} --pre-release
|
run: npx vsce package -o "../../dist/rust-analyzer-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }} --pre-release
|
||||||
working-directory: editors/code
|
working-directory: editors/code
|
||||||
|
|
||||||
|
268
Cargo.lock
generated
268
Cargo.lock
generated
@ -28,15 +28,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.71"
|
version = "1.0.75"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arbitrary"
|
name = "arbitrary"
|
||||||
version = "1.3.0"
|
version = "1.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e"
|
checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayvec"
|
name = "arrayvec"
|
||||||
@ -44,17 +44,6 @@ version = "0.7.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atty"
|
|
||||||
version = "0.2.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi 0.1.19",
|
|
||||||
"libc",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -101,9 +90,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.3.2"
|
version = "2.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6dbe3c979c178231552ecba20214a8272df4e09f232a87aef4320cf06539aded"
|
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
@ -131,9 +120,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo_metadata"
|
name = "cargo_metadata"
|
||||||
version = "0.15.4"
|
version = "0.18.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a"
|
checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"camino",
|
"camino",
|
||||||
"cargo-platform",
|
"cargo-platform",
|
||||||
@ -171,21 +160,21 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-derive"
|
name = "chalk-derive"
|
||||||
version = "0.93.0"
|
version = "0.94.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "264726159011fc7f22c23eb51f49021ece6e71bc358b96e7f2e842db0b14162b"
|
checksum = "c0322d5289ceba3217a03c9af72aa403d87542822b753daa1da32e4b992a4e80"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.39",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-ir"
|
name = "chalk-ir"
|
||||||
version = "0.93.0"
|
version = "0.94.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d65c17407d4c756b8f7f84344acb0fb96364d0298822743219bb25769b6d00df"
|
checksum = "0946cbc6d9136980a24a2dddf1888b5f0aa978dda300a3aa470b55b777b6bf3c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
@ -194,9 +183,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-recursive"
|
name = "chalk-recursive"
|
||||||
version = "0.93.0"
|
version = "0.94.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "80e2cf7b70bedaaf3a8cf3c93b6120c2bb65be89389124028e724d19e209686e"
|
checksum = "4cd93fedbeeadc0cd4d0eb73bd061b621af99f5324a6a518264c8ef5e526e0ec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
@ -207,15 +196,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-solve"
|
name = "chalk-solve"
|
||||||
version = "0.93.0"
|
version = "0.94.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "afc67c548d3854f64e97e67dc5b7c88513425c5bfa347cff96b7992ae6379288"
|
checksum = "a254cff72303c58c82df421cfe9465606372b81588923fcf179922b7eaad9a53"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
"ena",
|
"ena",
|
||||||
"indexmap 1.9.3",
|
"indexmap 2.1.0",
|
||||||
"itertools",
|
"itertools 0.10.5",
|
||||||
"petgraph",
|
"petgraph",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"tracing",
|
"tracing",
|
||||||
@ -315,20 +304,20 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_arbitrary"
|
name = "derive_arbitrary"
|
||||||
version = "1.3.1"
|
version = "1.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8"
|
checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.39",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dissimilar"
|
name = "dissimilar"
|
||||||
version = "1.0.6"
|
version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e"
|
checksum = "86e3bdc80eee6e16b2b6b0f87fbc98c04bee3455e35174c0de1a125d0688c632"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dot"
|
name = "dot"
|
||||||
@ -344,9 +333,9 @@ checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.8.1"
|
version = "1.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ena"
|
name = "ena"
|
||||||
@ -387,9 +376,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fixedbitset"
|
name = "fixedbitset"
|
||||||
version = "0.2.0"
|
version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
|
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
@ -455,9 +444,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.0"
|
version = "0.14.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
@ -468,15 +457,6 @@ dependencies = [
|
|||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hermit-abi"
|
|
||||||
version = "0.1.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
@ -497,7 +477,7 @@ dependencies = [
|
|||||||
"hir-def",
|
"hir-def",
|
||||||
"hir-expand",
|
"hir-expand",
|
||||||
"hir-ty",
|
"hir-ty",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"profile",
|
"profile",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
@ -514,7 +494,7 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"base-db",
|
"base-db",
|
||||||
"bitflags 2.3.2",
|
"bitflags 2.4.1",
|
||||||
"cfg",
|
"cfg",
|
||||||
"cov-mark",
|
"cov-mark",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
@ -524,9 +504,9 @@ dependencies = [
|
|||||||
"fst",
|
"fst",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown 0.12.3",
|
||||||
"hir-expand",
|
"hir-expand",
|
||||||
"indexmap 2.0.0",
|
"indexmap 2.1.0",
|
||||||
"intern",
|
"intern",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"limit",
|
"limit",
|
||||||
"mbe",
|
"mbe",
|
||||||
@ -554,7 +534,7 @@ dependencies = [
|
|||||||
"expect-test",
|
"expect-test",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown 0.12.3",
|
||||||
"intern",
|
"intern",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"limit",
|
"limit",
|
||||||
"mbe",
|
"mbe",
|
||||||
@ -574,7 +554,7 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"base-db",
|
"base-db",
|
||||||
"bitflags 2.3.2",
|
"bitflags 2.4.1",
|
||||||
"chalk-derive",
|
"chalk-derive",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
"chalk-recursive",
|
"chalk-recursive",
|
||||||
@ -586,7 +566,7 @@ dependencies = [
|
|||||||
"hir-def",
|
"hir-def",
|
||||||
"hir-expand",
|
"hir-expand",
|
||||||
"intern",
|
"intern",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"limit",
|
"limit",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
@ -633,7 +613,7 @@ dependencies = [
|
|||||||
"ide-db",
|
"ide-db",
|
||||||
"ide-diagnostics",
|
"ide-diagnostics",
|
||||||
"ide-ssr",
|
"ide-ssr",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"oorandom",
|
"oorandom",
|
||||||
"profile",
|
"profile",
|
||||||
@ -659,7 +639,7 @@ dependencies = [
|
|||||||
"expect-test",
|
"expect-test",
|
||||||
"hir",
|
"hir",
|
||||||
"ide-db",
|
"ide-db",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"profile",
|
"profile",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"sourcegen",
|
"sourcegen",
|
||||||
@ -678,7 +658,7 @@ dependencies = [
|
|||||||
"expect-test",
|
"expect-test",
|
||||||
"hir",
|
"hir",
|
||||||
"ide-db",
|
"ide-db",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"profile",
|
"profile",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -699,8 +679,8 @@ dependencies = [
|
|||||||
"expect-test",
|
"expect-test",
|
||||||
"fst",
|
"fst",
|
||||||
"hir",
|
"hir",
|
||||||
"indexmap 2.0.0",
|
"indexmap 2.1.0",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"limit",
|
"limit",
|
||||||
"line-index 0.1.0-pre.1",
|
"line-index 0.1.0-pre.1",
|
||||||
"memchr",
|
"memchr",
|
||||||
@ -731,7 +711,7 @@ dependencies = [
|
|||||||
"expect-test",
|
"expect-test",
|
||||||
"hir",
|
"hir",
|
||||||
"ide-db",
|
"ide-db",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"profile",
|
"profile",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -750,7 +730,7 @@ dependencies = [
|
|||||||
"expect-test",
|
"expect-test",
|
||||||
"hir",
|
"hir",
|
||||||
"ide-db",
|
"ide-db",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"parser",
|
"parser",
|
||||||
"stdx",
|
"stdx",
|
||||||
@ -782,12 +762,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.0.0"
|
version = "2.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown 0.14.0",
|
"hashbrown 0.14.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -838,6 +818,15 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
@ -888,9 +877,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.148"
|
version = "0.2.150"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
|
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
@ -942,7 +931,7 @@ dependencies = [
|
|||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"ide",
|
"ide",
|
||||||
"ide-db",
|
"ide-db",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"proc-macro-api",
|
"proc-macro-api",
|
||||||
"project-model",
|
"project-model",
|
||||||
"tracing",
|
"tracing",
|
||||||
@ -1020,9 +1009,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.5.0"
|
version = "2.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memmap2"
|
name = "memmap2"
|
||||||
@ -1123,7 +1112,7 @@ version = "6.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
|
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.3.2",
|
"bitflags 2.4.1",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"filetime",
|
"filetime",
|
||||||
"fsevent-sys",
|
"fsevent-sys",
|
||||||
@ -1138,12 +1127,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.46.0"
|
version = "0.49.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
checksum = "c073d3c1930d0751774acf49e66653acecb416c3a54c6ec095a9b11caddb5a68"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"overload",
|
"windows-sys 0.48.0",
|
||||||
"winapi",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1152,7 +1140,7 @@ version = "1.15.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi 0.2.6",
|
"hermit-abi",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1186,12 +1174,6 @@ version = "11.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "overload"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
@ -1289,12 +1271,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "petgraph"
|
name = "petgraph"
|
||||||
version = "0.5.1"
|
version = "0.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
|
checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fixedbitset",
|
"fixedbitset",
|
||||||
"indexmap 1.9.3",
|
"indexmap 2.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1359,9 +1341,9 @@ version = "0.0.0"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.60"
|
version = "1.0.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406"
|
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@ -1389,7 +1371,7 @@ dependencies = [
|
|||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
"cfg",
|
"cfg",
|
||||||
"expect-test",
|
"expect-test",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"paths",
|
"paths",
|
||||||
"profile",
|
"profile",
|
||||||
@ -1454,12 +1436,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_abi"
|
name = "ra-ap-rustc_abi"
|
||||||
version = "0.18.0"
|
version = "0.19.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7082716cb2bbcd8b5f062fe950cbbc87f3aba022d6da4168db35af6732a7f15d"
|
checksum = "9a2ea80a299f04a896000ce17b76f3aa1d2fe59f347fbc99c4b8970316ef5a0d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"ra-ap-rustc_index 0.18.0",
|
"ra-ap-rustc_index 0.19.0",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1475,9 +1457,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_index"
|
name = "ra-ap-rustc_index"
|
||||||
version = "0.18.0"
|
version = "0.19.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "19e14b1fc835d6992b128a03a3f3a8365ba9f03e1c656a1670305f63f30d786d"
|
checksum = "4556489ef652e5eb6cdad6078fff08507badac80bfc1f79085c85a6d8b77ab5c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -1495,9 +1477,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_lexer"
|
name = "ra-ap-rustc_lexer"
|
||||||
version = "0.18.0"
|
version = "0.19.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1762abb25eb1e37c1823f62b5da0821bbcd870812318db084c9516c2f78d2dcd"
|
checksum = "90e573bf707e01fe2841dbdedeed42012004274db0edc0314e6e3e58a40598fc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-properties",
|
"unicode-properties",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
@ -1515,9 +1497,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon"
|
name = "rayon"
|
||||||
version = "1.7.0"
|
version = "1.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
|
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
"rayon-core",
|
"rayon-core",
|
||||||
@ -1525,14 +1507,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon-core"
|
name = "rayon-core"
|
||||||
version = "1.11.0"
|
version = "1.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
|
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"num_cpus",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1583,7 +1563,7 @@ dependencies = [
|
|||||||
"ide",
|
"ide",
|
||||||
"ide-db",
|
"ide-db",
|
||||||
"ide-ssr",
|
"ide-ssr",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"load-cargo",
|
"load-cargo",
|
||||||
"lsp-server 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lsp-server 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lsp-types",
|
"lsp-types",
|
||||||
@ -1634,8 +1614,8 @@ name = "rustc-dependencies"
|
|||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ra-ap-rustc_abi",
|
"ra-ap-rustc_abi",
|
||||||
"ra-ap-rustc_index 0.18.0",
|
"ra-ap-rustc_index 0.19.0",
|
||||||
"ra-ap-rustc_lexer 0.18.0",
|
"ra-ap-rustc_lexer 0.19.0",
|
||||||
"ra-ap-rustc_parse_format",
|
"ra-ap-rustc_parse_format",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1721,31 +1701,31 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.156"
|
version = "1.0.192"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4"
|
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.156"
|
version = "1.0.192"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d"
|
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 2.0.39",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.97"
|
version = "1.0.108"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a"
|
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 1.9.3",
|
"indexmap 2.1.0",
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
@ -1759,7 +1739,7 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.39",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1831,9 +1811,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.18"
|
version = "2.0.39"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
|
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1848,7 +1828,7 @@ checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.39",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1859,8 +1839,8 @@ dependencies = [
|
|||||||
"cov-mark",
|
"cov-mark",
|
||||||
"either",
|
"either",
|
||||||
"expect-test",
|
"expect-test",
|
||||||
"indexmap 2.0.0",
|
"indexmap 2.1.0",
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parser",
|
"parser",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@ -1894,15 +1874,15 @@ dependencies = [
|
|||||||
name = "text-edit"
|
name = "text-edit"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools",
|
"itertools 0.12.0",
|
||||||
"text-size",
|
"text-size",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "text-size"
|
name = "text-size"
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "288cb548dbe72b652243ea797201f3d481a0609a967980fcc5b2315ea811560a"
|
checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
@ -1921,7 +1901,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.39",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2005,11 +1985,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
version = "0.1.37"
|
version = "0.1.40"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tracing-attributes",
|
"tracing-attributes",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
@ -2017,20 +1996,20 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-attributes"
|
name = "tracing-attributes"
|
||||||
version = "0.1.26"
|
version = "0.1.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
|
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.39",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-core"
|
name = "tracing-core"
|
||||||
version = "0.1.31"
|
version = "0.1.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
|
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"valuable",
|
"valuable",
|
||||||
@ -2038,20 +2017,20 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-log"
|
name = "tracing-log"
|
||||||
version = "0.1.3"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
|
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
|
"once_cell",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.3.17"
|
version = "0.3.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
|
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
@ -2061,11 +2040,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-tree"
|
name = "tracing-tree"
|
||||||
version = "0.2.3"
|
version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4f9742d8df709837409dbb22aa25dd7769c260406f20ff48a2320b80a4a6aed0"
|
checksum = "65139ecd2c3f6484c3b99bc01c77afe21e95473630747c7aca525e78b0666675"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
@ -2175,7 +2153,7 @@ name = "vfs"
|
|||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fst",
|
"fst",
|
||||||
"indexmap 2.0.0",
|
"indexmap 2.1.0",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"paths",
|
"paths",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
@ -2388,18 +2366,18 @@ checksum = "f58e7b3ca8977093aae6b87b6a7730216fc4c53a6530bab5c43a783cd810c1a8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xshell"
|
name = "xshell"
|
||||||
version = "0.2.3"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "962c039b3a7b16cf4e9a4248397c6585c07547412e7d6a6e035389a802dcfe90"
|
checksum = "ce2107fe03e558353b4c71ad7626d58ed82efaf56c54134228608893c77023ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"xshell-macros",
|
"xshell-macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xshell-macros"
|
name = "xshell-macros"
|
||||||
version = "0.2.3"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1dbabb1cbd15a1d6d12d9ed6b35cc6777d4af87ab3ba155ea37215f20beab80c"
|
checksum = "7e2c411759b501fb9501aac2b1b2d287a6e93e5bdcf13c25306b23e1b716dd0e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
|
23
Cargo.toml
23
Cargo.toml
@ -90,18 +90,35 @@ la-arena = { version = "0.3.1" }
|
|||||||
lsp-server = { version = "0.7.4" }
|
lsp-server = { version = "0.7.4" }
|
||||||
|
|
||||||
# non-local crates
|
# non-local crates
|
||||||
|
anyhow = "1.0.75"
|
||||||
|
bitflags = "2.4.1"
|
||||||
|
cargo_metadata = "0.18.1"
|
||||||
|
dissimilar = "1.0.7"
|
||||||
|
either = "1.9.0"
|
||||||
|
indexmap = "2.1.0"
|
||||||
|
itertools = "0.12.0"
|
||||||
|
libc = "0.2.150"
|
||||||
smallvec = { version = "1.10.0", features = [
|
smallvec = { version = "1.10.0", features = [
|
||||||
"const_new",
|
"const_new",
|
||||||
"union",
|
"union",
|
||||||
"const_generics",
|
"const_generics",
|
||||||
] }
|
] }
|
||||||
|
tracing = "0.1.40"
|
||||||
|
tracing-tree = "0.3.0"
|
||||||
|
tracing-subscriber = { version = "0.3.18", default-features = false, features = [
|
||||||
|
"registry",
|
||||||
|
"fmt",
|
||||||
|
"tracing-log",
|
||||||
|
] }
|
||||||
smol_str = "0.2.0"
|
smol_str = "0.2.0"
|
||||||
nohash-hasher = "0.2.0"
|
nohash-hasher = "0.2.0"
|
||||||
text-size = "1.1.0"
|
text-size = "1.1.1"
|
||||||
serde = { version = "1.0.156", features = ["derive"] }
|
rayon = "1.8.0"
|
||||||
serde_json = "1.0.96"
|
serde = { version = "1.0.192", features = ["derive"] }
|
||||||
|
serde_json = "1.0.108"
|
||||||
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
|
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
|
||||||
# can't upgrade due to dashmap depending on 0.12.3 currently
|
# can't upgrade due to dashmap depending on 0.12.3 currently
|
||||||
hashbrown = { version = "0.12.3", features = [
|
hashbrown = { version = "0.12.3", features = [
|
||||||
"inline-more",
|
"inline-more",
|
||||||
], default-features = false }
|
], default-features = false }
|
||||||
|
xshell = "0.2.5"
|
||||||
|
@ -23,8 +23,8 @@ oorandom = "11.1.3"
|
|||||||
# We depend on both individually instead of using `features = ["derive"]` to microoptimize the
|
# We depend on both individually instead of using `features = ["derive"]` to microoptimize the
|
||||||
# build graph: if the feature was enabled, syn would be built early on in the graph if `smolstr`
|
# build graph: if the feature was enabled, syn would be built early on in the graph if `smolstr`
|
||||||
# supports `arbitrary`. This way, we avoid feature unification.
|
# supports `arbitrary`. This way, we avoid feature unification.
|
||||||
arbitrary = "1.3.0"
|
arbitrary = "1.3.2"
|
||||||
derive_arbitrary = "1.3.1"
|
derive_arbitrary = "1.3.2"
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
mbe.workspace = true
|
mbe.workspace = true
|
||||||
|
@ -12,9 +12,9 @@ rust-version.workspace = true
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cargo_metadata.workspace = true
|
||||||
crossbeam-channel = "0.5.8"
|
crossbeam-channel = "0.5.8"
|
||||||
tracing = "0.1.37"
|
tracing.workspace = true
|
||||||
cargo_metadata = "0.15.4"
|
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
@ -13,19 +13,19 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.7.2"
|
arrayvec = "0.7.2"
|
||||||
bitflags = "2.1.0"
|
bitflags.workspace = true
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
|
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
|
||||||
dashmap = { version = "=5.4.0", features = ["raw-api"] }
|
dashmap = { version = "=5.4.0", features = ["raw-api"] }
|
||||||
drop_bomb = "0.1.5"
|
drop_bomb = "0.1.5"
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
fst = { version = "0.4.7", default-features = false }
|
fst = { version = "0.4.7", default-features = false }
|
||||||
indexmap = "2.0.0"
|
indexmap.workspace = true
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
|
@ -54,7 +54,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
|
|||||||
let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false };
|
let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false };
|
||||||
if let DefWithBodyId::FunctionId(it) = owner {
|
if let DefWithBodyId::FunctionId(it) = owner {
|
||||||
p.buf.push('(');
|
p.buf.push('(');
|
||||||
body.params.iter().zip(&db.function_data(it).params).for_each(|(¶m, ty)| {
|
body.params.iter().zip(db.function_data(it).params.iter()).for_each(|(¶m, ty)| {
|
||||||
p.print_pat(param);
|
p.print_pat(param);
|
||||||
p.buf.push(':');
|
p.buf.push(':');
|
||||||
p.print_type_ref(ty);
|
p.print_type_ref(ty);
|
||||||
|
@ -34,7 +34,7 @@ use crate::{
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct FunctionData {
|
pub struct FunctionData {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub params: Vec<Interned<TypeRef>>,
|
pub params: Box<[Interned<TypeRef>]>,
|
||||||
pub ret_type: Interned<TypeRef>,
|
pub ret_type: Interned<TypeRef>,
|
||||||
pub attrs: Attrs,
|
pub attrs: Attrs,
|
||||||
pub visibility: RawVisibility,
|
pub visibility: RawVisibility,
|
||||||
@ -177,7 +177,7 @@ pub struct TypeAliasData {
|
|||||||
pub rustc_has_incoherent_inherent_impls: bool,
|
pub rustc_has_incoherent_inherent_impls: bool,
|
||||||
pub rustc_allow_incoherent_impl: bool,
|
pub rustc_allow_incoherent_impl: bool,
|
||||||
/// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl).
|
/// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl).
|
||||||
pub bounds: Vec<Interned<TypeBound>>,
|
pub bounds: Box<[Interned<TypeBound>]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeAliasData {
|
impl TypeAliasData {
|
||||||
@ -210,7 +210,7 @@ impl TypeAliasData {
|
|||||||
is_extern: matches!(loc.container, ItemContainerId::ExternBlockId(_)),
|
is_extern: matches!(loc.container, ItemContainerId::ExternBlockId(_)),
|
||||||
rustc_has_incoherent_inherent_impls,
|
rustc_has_incoherent_inherent_impls,
|
||||||
rustc_allow_incoherent_impl,
|
rustc_allow_incoherent_impl,
|
||||||
bounds: typ.bounds.to_vec(),
|
bounds: typ.bounds.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,6 +327,7 @@ pub struct ImplData {
|
|||||||
pub self_ty: Interned<TypeRef>,
|
pub self_ty: Interned<TypeRef>,
|
||||||
pub items: Vec<AssocItemId>,
|
pub items: Vec<AssocItemId>,
|
||||||
pub is_negative: bool,
|
pub is_negative: bool,
|
||||||
|
pub is_unsafe: bool,
|
||||||
// box it as the vec is usually empty anyways
|
// box it as the vec is usually empty anyways
|
||||||
pub attribute_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
|
pub attribute_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
|
||||||
}
|
}
|
||||||
@ -348,6 +349,7 @@ impl ImplData {
|
|||||||
let target_trait = impl_def.target_trait.clone();
|
let target_trait = impl_def.target_trait.clone();
|
||||||
let self_ty = impl_def.self_ty.clone();
|
let self_ty = impl_def.self_ty.clone();
|
||||||
let is_negative = impl_def.is_negative;
|
let is_negative = impl_def.is_negative;
|
||||||
|
let is_unsafe = impl_def.is_unsafe;
|
||||||
|
|
||||||
let mut collector =
|
let mut collector =
|
||||||
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::ImplId(id));
|
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::ImplId(id));
|
||||||
@ -357,7 +359,14 @@ impl ImplData {
|
|||||||
let items = items.into_iter().map(|(_, item)| item).collect();
|
let items = items.into_iter().map(|(_, item)| item).collect();
|
||||||
|
|
||||||
(
|
(
|
||||||
Arc::new(ImplData { target_trait, self_ty, items, is_negative, attribute_calls }),
|
Arc::new(ImplData {
|
||||||
|
target_trait,
|
||||||
|
self_ty,
|
||||||
|
items,
|
||||||
|
is_negative,
|
||||||
|
is_unsafe,
|
||||||
|
attribute_calls,
|
||||||
|
}),
|
||||||
diagnostics.into(),
|
diagnostics.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,10 @@ pub fn find_path(
|
|||||||
item: ItemInNs,
|
item: ItemInNs,
|
||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
let _p = profile::span("find_path");
|
let _p = profile::span("find_path");
|
||||||
find_path_inner(db, item, from, None, prefer_no_std)
|
find_path_inner(db, item, from, None, prefer_no_std, prefer_prelude)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_path_prefixed(
|
pub fn find_path_prefixed(
|
||||||
@ -32,9 +33,10 @@ pub fn find_path_prefixed(
|
|||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
prefix_kind: PrefixKind,
|
prefix_kind: PrefixKind,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
let _p = profile::span("find_path_prefixed");
|
let _p = profile::span("find_path_prefixed");
|
||||||
find_path_inner(db, item, from, Some(prefix_kind), prefer_no_std)
|
find_path_inner(db, item, from, Some(prefix_kind), prefer_no_std, prefer_prelude)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
@ -88,6 +90,7 @@ fn find_path_inner(
|
|||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
prefixed: Option<PrefixKind>,
|
prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
// - if the item is a builtin, it's in scope
|
// - if the item is a builtin, it's in scope
|
||||||
if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
|
if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
|
||||||
@ -109,6 +112,7 @@ fn find_path_inner(
|
|||||||
MAX_PATH_LEN,
|
MAX_PATH_LEN,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std || db.crate_supports_no_std(crate_root.krate),
|
prefer_no_std || db.crate_supports_no_std(crate_root.krate),
|
||||||
|
prefer_prelude,
|
||||||
)
|
)
|
||||||
.map(|(item, _)| item);
|
.map(|(item, _)| item);
|
||||||
}
|
}
|
||||||
@ -134,6 +138,7 @@ fn find_path_inner(
|
|||||||
from,
|
from,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
) {
|
) {
|
||||||
let data = db.enum_data(variant.parent);
|
let data = db.enum_data(variant.parent);
|
||||||
path.push_segment(data.variants[variant.local_id].name.clone());
|
path.push_segment(data.variants[variant.local_id].name.clone());
|
||||||
@ -156,6 +161,7 @@ fn find_path_inner(
|
|||||||
from,
|
from,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std || db.crate_supports_no_std(crate_root.krate),
|
prefer_no_std || db.crate_supports_no_std(crate_root.krate),
|
||||||
|
prefer_prelude,
|
||||||
scope_name,
|
scope_name,
|
||||||
)
|
)
|
||||||
.map(|(item, _)| item)
|
.map(|(item, _)| item)
|
||||||
@ -171,6 +177,7 @@ fn find_path_for_module(
|
|||||||
max_len: usize,
|
max_len: usize,
|
||||||
prefixed: Option<PrefixKind>,
|
prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<(ModPath, Stability)> {
|
) -> Option<(ModPath, Stability)> {
|
||||||
if max_len == 0 {
|
if max_len == 0 {
|
||||||
return None;
|
return None;
|
||||||
@ -236,6 +243,7 @@ fn find_path_for_module(
|
|||||||
from,
|
from,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
scope_name,
|
scope_name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -316,6 +324,7 @@ fn calculate_best_path(
|
|||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
mut prefixed: Option<PrefixKind>,
|
mut prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
scope_name: Option<Name>,
|
scope_name: Option<Name>,
|
||||||
) -> Option<(ModPath, Stability)> {
|
) -> Option<(ModPath, Stability)> {
|
||||||
if max_len <= 1 {
|
if max_len <= 1 {
|
||||||
@ -351,11 +360,14 @@ fn calculate_best_path(
|
|||||||
best_path_len - 1,
|
best_path_len - 1,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
) {
|
) {
|
||||||
path.0.push_segment(name);
|
path.0.push_segment(name);
|
||||||
|
|
||||||
let new_path = match best_path.take() {
|
let new_path = match best_path.take() {
|
||||||
Some(best_path) => select_best_path(best_path, path, prefer_no_std),
|
Some(best_path) => {
|
||||||
|
select_best_path(best_path, path, prefer_no_std, prefer_prelude)
|
||||||
|
}
|
||||||
None => path,
|
None => path,
|
||||||
};
|
};
|
||||||
best_path_len = new_path.0.len();
|
best_path_len = new_path.0.len();
|
||||||
@ -367,18 +379,18 @@ fn calculate_best_path(
|
|||||||
// too (unless we can't name it at all). It could *also* be (re)exported by the same crate
|
// too (unless we can't name it at all). It could *also* be (re)exported by the same crate
|
||||||
// that wants to import it here, but we always prefer to use the external path here.
|
// that wants to import it here, but we always prefer to use the external path here.
|
||||||
|
|
||||||
let crate_graph = db.crate_graph();
|
for dep in &db.crate_graph()[from.krate].dependencies {
|
||||||
let extern_paths = crate_graph[from.krate].dependencies.iter().filter_map(|dep| {
|
|
||||||
let import_map = db.import_map(dep.crate_id);
|
let import_map = db.import_map(dep.crate_id);
|
||||||
import_map.import_info_for(item).and_then(|info| {
|
let Some(import_info_for) = import_map.import_info_for(item) else { continue };
|
||||||
|
for info in import_info_for {
|
||||||
if info.is_doc_hidden {
|
if info.is_doc_hidden {
|
||||||
// the item or import is `#[doc(hidden)]`, so skip it as it is in an external crate
|
// the item or import is `#[doc(hidden)]`, so skip it as it is in an external crate
|
||||||
return None;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine best path for containing module and append last segment from `info`.
|
// Determine best path for containing module and append last segment from `info`.
|
||||||
// FIXME: we should guide this to look up the path locally, or from the same crate again?
|
// FIXME: we should guide this to look up the path locally, or from the same crate again?
|
||||||
let (mut path, path_stability) = find_path_for_module(
|
let Some((mut path, path_stability)) = find_path_for_module(
|
||||||
db,
|
db,
|
||||||
def_map,
|
def_map,
|
||||||
visited_modules,
|
visited_modules,
|
||||||
@ -388,22 +400,26 @@ fn calculate_best_path(
|
|||||||
max_len - 1,
|
max_len - 1,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
)?;
|
prefer_prelude,
|
||||||
|
) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
cov_mark::hit!(partially_imported);
|
cov_mark::hit!(partially_imported);
|
||||||
path.push_segment(info.name.clone());
|
path.push_segment(info.name.clone());
|
||||||
Some((
|
|
||||||
|
let path_with_stab = (
|
||||||
path,
|
path,
|
||||||
zip_stability(path_stability, if info.is_unstable { Unstable } else { Stable }),
|
zip_stability(path_stability, if info.is_unstable { Unstable } else { Stable }),
|
||||||
))
|
);
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
for path in extern_paths {
|
let new_path_with_stab = match best_path.take() {
|
||||||
let new_path = match best_path.take() {
|
Some(best_path) => {
|
||||||
Some(best_path) => select_best_path(best_path, path, prefer_no_std),
|
select_best_path(best_path, path_with_stab, prefer_no_std, prefer_prelude)
|
||||||
None => path,
|
}
|
||||||
};
|
None => path_with_stab,
|
||||||
update_best_path(&mut best_path, new_path);
|
};
|
||||||
|
update_best_path(&mut best_path, new_path_with_stab);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(module) = item.module(db) {
|
if let Some(module) = item.module(db) {
|
||||||
@ -420,17 +436,39 @@ fn calculate_best_path(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Select the best (most relevant) path between two paths.
|
||||||
|
/// This accounts for stability, path length whether std should be chosen over alloc/core paths as
|
||||||
|
/// well as ignoring prelude like paths or not.
|
||||||
fn select_best_path(
|
fn select_best_path(
|
||||||
old_path: (ModPath, Stability),
|
old_path @ (_, old_stability): (ModPath, Stability),
|
||||||
new_path: (ModPath, Stability),
|
new_path @ (_, new_stability): (ModPath, Stability),
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> (ModPath, Stability) {
|
) -> (ModPath, Stability) {
|
||||||
match (old_path.1, new_path.1) {
|
match (old_stability, new_stability) {
|
||||||
(Stable, Unstable) => return old_path,
|
(Stable, Unstable) => return old_path,
|
||||||
(Unstable, Stable) => return new_path,
|
(Unstable, Stable) => return new_path,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
const STD_CRATES: [Name; 3] = [known::std, known::core, known::alloc];
|
const STD_CRATES: [Name; 3] = [known::std, known::core, known::alloc];
|
||||||
|
|
||||||
|
let choose = |new_path: (ModPath, _), old_path: (ModPath, _)| {
|
||||||
|
let new_has_prelude = new_path.0.segments().iter().any(|seg| seg == &known::prelude);
|
||||||
|
let old_has_prelude = old_path.0.segments().iter().any(|seg| seg == &known::prelude);
|
||||||
|
match (new_has_prelude, old_has_prelude, prefer_prelude) {
|
||||||
|
(true, false, true) | (false, true, false) => new_path,
|
||||||
|
(true, false, false) | (false, true, true) => old_path,
|
||||||
|
// no prelude difference in the paths, so pick the smaller one
|
||||||
|
(true, true, _) | (false, false, _) => {
|
||||||
|
if new_path.0.len() < old_path.0.len() {
|
||||||
|
new_path
|
||||||
|
} else {
|
||||||
|
old_path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match (old_path.0.segments().first(), new_path.0.segments().first()) {
|
match (old_path.0.segments().first(), new_path.0.segments().first()) {
|
||||||
(Some(old), Some(new)) if STD_CRATES.contains(old) && STD_CRATES.contains(new) => {
|
(Some(old), Some(new)) if STD_CRATES.contains(old) && STD_CRATES.contains(new) => {
|
||||||
let rank = match prefer_no_std {
|
let rank = match prefer_no_std {
|
||||||
@ -451,23 +489,11 @@ fn select_best_path(
|
|||||||
let orank = rank(old);
|
let orank = rank(old);
|
||||||
match nrank.cmp(&orank) {
|
match nrank.cmp(&orank) {
|
||||||
Ordering::Less => old_path,
|
Ordering::Less => old_path,
|
||||||
Ordering::Equal => {
|
Ordering::Equal => choose(new_path, old_path),
|
||||||
if new_path.0.len() < old_path.0.len() {
|
|
||||||
new_path
|
|
||||||
} else {
|
|
||||||
old_path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ordering::Greater => new_path,
|
Ordering::Greater => new_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => choose(new_path, old_path),
|
||||||
if new_path.0.len() < old_path.0.len() {
|
|
||||||
new_path
|
|
||||||
} else {
|
|
||||||
old_path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,7 +596,13 @@ mod tests {
|
|||||||
/// `code` needs to contain a cursor marker; checks that `find_path` for the
|
/// `code` needs to contain a cursor marker; checks that `find_path` for the
|
||||||
/// item the `path` refers to returns that same path when called from the
|
/// item the `path` refers to returns that same path when called from the
|
||||||
/// module the cursor is in.
|
/// module the cursor is in.
|
||||||
fn check_found_path_(ra_fixture: &str, path: &str, prefix_kind: Option<PrefixKind>) {
|
#[track_caller]
|
||||||
|
fn check_found_path_(
|
||||||
|
ra_fixture: &str,
|
||||||
|
path: &str,
|
||||||
|
prefix_kind: Option<PrefixKind>,
|
||||||
|
prefer_prelude: bool,
|
||||||
|
) {
|
||||||
let (db, pos) = TestDB::with_position(ra_fixture);
|
let (db, pos) = TestDB::with_position(ra_fixture);
|
||||||
let module = db.module_at_position(pos);
|
let module = db.module_at_position(pos);
|
||||||
let parsed_path_file = syntax::SourceFile::parse(&format!("use {path};"));
|
let parsed_path_file = syntax::SourceFile::parse(&format!("use {path};"));
|
||||||
@ -589,11 +621,17 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.0
|
.0
|
||||||
.take_types()
|
.take_types()
|
||||||
.unwrap();
|
.expect("path does not resolve to a type");
|
||||||
|
|
||||||
let found_path =
|
let found_path = find_path_inner(
|
||||||
find_path_inner(&db, ItemInNs::Types(resolved), module, prefix_kind, false);
|
&db,
|
||||||
assert_eq!(found_path, Some(mod_path), "{prefix_kind:?}");
|
ItemInNs::Types(resolved),
|
||||||
|
module,
|
||||||
|
prefix_kind,
|
||||||
|
false,
|
||||||
|
prefer_prelude,
|
||||||
|
);
|
||||||
|
assert_eq!(found_path, Some(mod_path), "on kind: {prefix_kind:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_found_path(
|
fn check_found_path(
|
||||||
@ -603,10 +641,23 @@ mod tests {
|
|||||||
absolute: &str,
|
absolute: &str,
|
||||||
self_prefixed: &str,
|
self_prefixed: &str,
|
||||||
) {
|
) {
|
||||||
check_found_path_(ra_fixture, unprefixed, None);
|
check_found_path_(ra_fixture, unprefixed, None, false);
|
||||||
check_found_path_(ra_fixture, prefixed, Some(PrefixKind::Plain));
|
check_found_path_(ra_fixture, prefixed, Some(PrefixKind::Plain), false);
|
||||||
check_found_path_(ra_fixture, absolute, Some(PrefixKind::ByCrate));
|
check_found_path_(ra_fixture, absolute, Some(PrefixKind::ByCrate), false);
|
||||||
check_found_path_(ra_fixture, self_prefixed, Some(PrefixKind::BySelf));
|
check_found_path_(ra_fixture, self_prefixed, Some(PrefixKind::BySelf), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_found_path_prelude(
|
||||||
|
ra_fixture: &str,
|
||||||
|
unprefixed: &str,
|
||||||
|
prefixed: &str,
|
||||||
|
absolute: &str,
|
||||||
|
self_prefixed: &str,
|
||||||
|
) {
|
||||||
|
check_found_path_(ra_fixture, unprefixed, None, true);
|
||||||
|
check_found_path_(ra_fixture, prefixed, Some(PrefixKind::Plain), true);
|
||||||
|
check_found_path_(ra_fixture, absolute, Some(PrefixKind::ByCrate), true);
|
||||||
|
check_found_path_(ra_fixture, self_prefixed, Some(PrefixKind::BySelf), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1421,4 +1472,34 @@ pub mod error {
|
|||||||
"std::error::Error",
|
"std::error::Error",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn respects_prelude_setting() {
|
||||||
|
let ra_fixture = r#"
|
||||||
|
//- /main.rs crate:main deps:krate
|
||||||
|
$0
|
||||||
|
//- /krate.rs crate:krate
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::foo::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod foo {
|
||||||
|
pub struct Foo;
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
check_found_path(
|
||||||
|
ra_fixture,
|
||||||
|
"krate::foo::Foo",
|
||||||
|
"krate::foo::Foo",
|
||||||
|
"krate::foo::Foo",
|
||||||
|
"krate::foo::Foo",
|
||||||
|
);
|
||||||
|
check_found_path_prelude(
|
||||||
|
ra_fixture,
|
||||||
|
"krate::prelude::Foo",
|
||||||
|
"krate::prelude::Foo",
|
||||||
|
"krate::prelude::Foo",
|
||||||
|
"krate::prelude::Foo",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ impl GenericParams {
|
|||||||
let mut expander = Lazy::new(|| {
|
let mut expander = Lazy::new(|| {
|
||||||
(module.def_map(db), Expander::new(db, loc.source(db).file_id, module))
|
(module.def_map(db), Expander::new(db, loc.source(db).file_id, module))
|
||||||
});
|
});
|
||||||
for param in &func_data.params {
|
for param in func_data.params.iter() {
|
||||||
generic_params.fill_implicit_impl_trait_args(db, &mut expander, param);
|
generic_params.fill_implicit_impl_trait_args(db, &mut expander, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
//! A map of all publicly exported items in a crate.
|
//! A map of all publicly exported items in a crate.
|
||||||
|
|
||||||
use std::{collections::hash_map::Entry, fmt, hash::BuildHasherDefault};
|
use std::{fmt, hash::BuildHasherDefault};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use fst::{self, Streamer};
|
use fst::{self, raw::IndexedValue, Streamer};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
|
use rustc_hash::{FxHashSet, FxHasher};
|
||||||
|
use smallvec::SmallVec;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -20,31 +21,28 @@ use crate::{
|
|||||||
|
|
||||||
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||||
|
|
||||||
// FIXME: Support aliases: an item may be exported under multiple names, so `ImportInfo` should
|
|
||||||
// have `Vec<(Name, ModuleId)>` instead of `(Name, ModuleId)`.
|
|
||||||
/// Item import details stored in the `ImportMap`.
|
/// Item import details stored in the `ImportMap`.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct ImportInfo {
|
pub struct ImportInfo {
|
||||||
/// A name that can be used to import the item, relative to the crate's root.
|
/// A name that can be used to import the item, relative to the crate's root.
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
/// The module containing this item.
|
/// The module containing this item.
|
||||||
pub container: ModuleId,
|
pub container: ModuleId,
|
||||||
/// Whether the import is a trait associated item or not.
|
|
||||||
pub is_trait_assoc_item: bool,
|
|
||||||
/// Whether this item is annotated with `#[doc(hidden)]`.
|
/// Whether this item is annotated with `#[doc(hidden)]`.
|
||||||
pub is_doc_hidden: bool,
|
pub is_doc_hidden: bool,
|
||||||
/// Whether this item is annotated with `#[unstable(..)]`.
|
/// Whether this item is annotated with `#[unstable(..)]`.
|
||||||
pub is_unstable: bool,
|
pub is_unstable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ImportMapIndex = FxIndexMap<ItemInNs, (SmallVec<[ImportInfo; 1]>, IsTraitAssocItem)>;
|
||||||
|
|
||||||
/// A map from publicly exported items to its name.
|
/// A map from publicly exported items to its name.
|
||||||
///
|
///
|
||||||
/// Reexports of items are taken into account, ie. if something is exported under multiple
|
/// Reexports of items are taken into account, ie. if something is exported under multiple
|
||||||
/// names, the one with the shortest import path will be used.
|
/// names, the one with the shortest import path will be used.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ImportMap {
|
pub struct ImportMap {
|
||||||
map: FxIndexMap<ItemInNs, ImportInfo>,
|
map: ImportMapIndex,
|
||||||
|
|
||||||
/// List of keys stored in `map`, sorted lexicographically by their `ModPath`. Indexed by the
|
/// List of keys stored in `map`, sorted lexicographically by their `ModPath`. Indexed by the
|
||||||
/// values returned by running `fst`.
|
/// values returned by running `fst`.
|
||||||
///
|
///
|
||||||
@ -55,6 +53,12 @@ pub struct ImportMap {
|
|||||||
fst: fst::Map<Vec<u8>>,
|
fst: fst::Map<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
|
enum IsTraitAssocItem {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
}
|
||||||
|
|
||||||
impl ImportMap {
|
impl ImportMap {
|
||||||
pub(crate) fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
|
pub(crate) fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
|
||||||
let _p = profile::span("import_map_query");
|
let _p = profile::span("import_map_query");
|
||||||
@ -64,13 +68,18 @@ impl ImportMap {
|
|||||||
let mut importables: Vec<_> = map
|
let mut importables: Vec<_> = map
|
||||||
.iter()
|
.iter()
|
||||||
// We've only collected items, whose name cannot be tuple field.
|
// We've only collected items, whose name cannot be tuple field.
|
||||||
.map(|(&item, info)| (item, info.name.as_str().unwrap().to_ascii_lowercase()))
|
.flat_map(|(&item, (info, _))| {
|
||||||
|
info.iter()
|
||||||
|
.map(move |info| (item, info.name.as_str().unwrap().to_ascii_lowercase()))
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
importables.sort_by(|(_, lhs_name), (_, rhs_name)| lhs_name.cmp(rhs_name));
|
importables.sort_by(|(_, lhs_name), (_, rhs_name)| lhs_name.cmp(rhs_name));
|
||||||
|
importables.dedup();
|
||||||
|
|
||||||
// Build the FST, taking care not to insert duplicate values.
|
// Build the FST, taking care not to insert duplicate values.
|
||||||
let mut builder = fst::MapBuilder::memory();
|
let mut builder = fst::MapBuilder::memory();
|
||||||
let iter = importables.iter().enumerate().dedup_by(|lhs, rhs| lhs.1 .1 == rhs.1 .1);
|
let iter =
|
||||||
|
importables.iter().enumerate().dedup_by(|(_, (_, lhs)), (_, (_, rhs))| lhs == rhs);
|
||||||
for (start_idx, (_, name)) in iter {
|
for (start_idx, (_, name)) in iter {
|
||||||
let _ = builder.insert(name, start_idx as u64);
|
let _ = builder.insert(name, start_idx as u64);
|
||||||
}
|
}
|
||||||
@ -82,12 +91,12 @@ impl ImportMap {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn import_info_for(&self, item: ItemInNs) -> Option<&ImportInfo> {
|
pub fn import_info_for(&self, item: ItemInNs) -> Option<&[ImportInfo]> {
|
||||||
self.map.get(&item)
|
self.map.get(&item).map(|(info, _)| &**info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemInNs, ImportInfo> {
|
fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> ImportMapIndex {
|
||||||
let _p = profile::span("collect_import_map");
|
let _p = profile::span("collect_import_map");
|
||||||
|
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = db.crate_def_map(krate);
|
||||||
@ -95,11 +104,13 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
|
|||||||
|
|
||||||
// We look only into modules that are public(ly reexported), starting with the crate root.
|
// We look only into modules that are public(ly reexported), starting with the crate root.
|
||||||
let root = def_map.module_id(DefMap::ROOT);
|
let root = def_map.module_id(DefMap::ROOT);
|
||||||
let mut worklist = vec![(root, 0u32)];
|
let mut worklist = vec![root];
|
||||||
// Records items' minimum module depth.
|
let mut visited = FxHashSet::default();
|
||||||
let mut depth_map = FxHashMap::default();
|
|
||||||
|
|
||||||
while let Some((module, depth)) = worklist.pop() {
|
while let Some(module) = worklist.pop() {
|
||||||
|
if !visited.insert(module) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let ext_def_map;
|
let ext_def_map;
|
||||||
let mod_data = if module.krate == krate {
|
let mod_data = if module.krate == krate {
|
||||||
&def_map[module.local_id]
|
&def_map[module.local_id]
|
||||||
@ -127,62 +138,18 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
|
|||||||
ItemInNs::Macros(id) => Some(id.into()),
|
ItemInNs::Macros(id) => Some(id.into()),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let status @ (is_doc_hidden, is_unstable) =
|
let (is_doc_hidden, is_unstable) = attr_id.map_or((false, false), |attr_id| {
|
||||||
attr_id.map_or((false, false), |attr_id| {
|
let attrs = db.attrs(attr_id);
|
||||||
let attrs = db.attrs(attr_id);
|
(attrs.has_doc_hidden(), attrs.is_unstable())
|
||||||
(attrs.has_doc_hidden(), attrs.is_unstable())
|
});
|
||||||
});
|
|
||||||
|
|
||||||
let import_info = ImportInfo {
|
let import_info = ImportInfo {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
container: module,
|
container: module,
|
||||||
is_trait_assoc_item: false,
|
|
||||||
is_doc_hidden,
|
is_doc_hidden,
|
||||||
is_unstable,
|
is_unstable,
|
||||||
};
|
};
|
||||||
|
|
||||||
match depth_map.entry(item) {
|
|
||||||
Entry::Vacant(entry) => _ = entry.insert((depth, status)),
|
|
||||||
Entry::Occupied(mut entry) => {
|
|
||||||
let &(occ_depth, (occ_is_doc_hidden, occ_is_unstable)) = entry.get();
|
|
||||||
(depth, occ_depth);
|
|
||||||
let overwrite = match (
|
|
||||||
is_doc_hidden,
|
|
||||||
occ_is_doc_hidden,
|
|
||||||
is_unstable,
|
|
||||||
occ_is_unstable,
|
|
||||||
) {
|
|
||||||
// no change of hiddeness or unstableness
|
|
||||||
(true, true, true, true)
|
|
||||||
| (true, true, false, false)
|
|
||||||
| (false, false, true, true)
|
|
||||||
| (false, false, false, false) => depth < occ_depth,
|
|
||||||
|
|
||||||
// either less hidden or less unstable, accept
|
|
||||||
(true, true, false, true)
|
|
||||||
| (false, true, true, true)
|
|
||||||
| (false, true, false, true)
|
|
||||||
| (false, true, false, false)
|
|
||||||
| (false, false, false, true) => true,
|
|
||||||
// more hidden or unstable, discard
|
|
||||||
(true, true, true, false)
|
|
||||||
| (true, false, true, true)
|
|
||||||
| (true, false, true, false)
|
|
||||||
| (true, false, false, false)
|
|
||||||
| (false, false, true, false) => false,
|
|
||||||
|
|
||||||
// exchanges doc(hidden) for unstable (and vice-versa),
|
|
||||||
(true, false, false, true) | (false, true, true, false) => {
|
|
||||||
depth < occ_depth
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if !overwrite {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
entry.insert((depth, status));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ModuleDefId::TraitId(tr)) = item.as_module_def_id() {
|
if let Some(ModuleDefId::TraitId(tr)) = item.as_module_def_id() {
|
||||||
collect_trait_assoc_items(
|
collect_trait_assoc_items(
|
||||||
db,
|
db,
|
||||||
@ -193,13 +160,14 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
map.insert(item, import_info);
|
let (infos, _) =
|
||||||
|
map.entry(item).or_insert_with(|| (SmallVec::new(), IsTraitAssocItem::No));
|
||||||
|
infos.reserve_exact(1);
|
||||||
|
infos.push(import_info);
|
||||||
|
|
||||||
// If we've just added a module, descend into it. We might traverse modules
|
// If we've just added a module, descend into it.
|
||||||
// multiple times, but only if the module depth is smaller (else we `continue`
|
|
||||||
// above).
|
|
||||||
if let Some(ModuleDefId::ModuleId(mod_id)) = item.as_module_def_id() {
|
if let Some(ModuleDefId::ModuleId(mod_id)) = item.as_module_def_id() {
|
||||||
worklist.push((mod_id, depth + 1));
|
worklist.push(mod_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +178,7 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
|
|||||||
|
|
||||||
fn collect_trait_assoc_items(
|
fn collect_trait_assoc_items(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
map: &mut FxIndexMap<ItemInNs, ImportInfo>,
|
map: &mut ImportMapIndex,
|
||||||
tr: TraitId,
|
tr: TraitId,
|
||||||
is_type_in_ns: bool,
|
is_type_in_ns: bool,
|
||||||
trait_import_info: &ImportInfo,
|
trait_import_info: &ImportInfo,
|
||||||
@ -237,11 +205,14 @@ fn collect_trait_assoc_items(
|
|||||||
let assoc_item_info = ImportInfo {
|
let assoc_item_info = ImportInfo {
|
||||||
container: trait_import_info.container,
|
container: trait_import_info.container,
|
||||||
name: assoc_item_name.clone(),
|
name: assoc_item_name.clone(),
|
||||||
is_trait_assoc_item: true,
|
|
||||||
is_doc_hidden: attrs.has_doc_hidden(),
|
is_doc_hidden: attrs.has_doc_hidden(),
|
||||||
is_unstable: attrs.is_unstable(),
|
is_unstable: attrs.is_unstable(),
|
||||||
};
|
};
|
||||||
map.insert(assoc_item, assoc_item_info);
|
|
||||||
|
let (infos, _) =
|
||||||
|
map.entry(assoc_item).or_insert_with(|| (SmallVec::new(), IsTraitAssocItem::Yes));
|
||||||
|
infos.reserve_exact(1);
|
||||||
|
infos.push(assoc_item_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,10 +230,13 @@ impl fmt::Debug for ImportMap {
|
|||||||
let mut importable_names: Vec<_> = self
|
let mut importable_names: Vec<_> = self
|
||||||
.map
|
.map
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(item, _)| match item {
|
.map(|(item, (infos, _))| {
|
||||||
ItemInNs::Types(it) => format!("- {it:?} (t)",),
|
let l = infos.len();
|
||||||
ItemInNs::Values(it) => format!("- {it:?} (v)",),
|
match item {
|
||||||
ItemInNs::Macros(it) => format!("- {it:?} (m)",),
|
ItemInNs::Types(it) => format!("- {it:?} (t) [{l}]",),
|
||||||
|
ItemInNs::Values(it) => format!("- {it:?} (v) [{l}]",),
|
||||||
|
ItemInNs::Macros(it) => format!("- {it:?} (m) [{l}]",),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -272,7 +246,7 @@ impl fmt::Debug for ImportMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A way to match import map contents against the search query.
|
/// A way to match import map contents against the search query.
|
||||||
#[derive(Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
enum SearchMode {
|
enum SearchMode {
|
||||||
/// Import map entry should strictly match the query string.
|
/// Import map entry should strictly match the query string.
|
||||||
Exact,
|
Exact,
|
||||||
@ -345,6 +319,15 @@ impl Query {
|
|||||||
Self { case_sensitive: true, ..self }
|
Self { case_sensitive: true, ..self }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn matches_assoc_mode(&self, is_trait_assoc_item: IsTraitAssocItem) -> bool {
|
||||||
|
match (is_trait_assoc_item, self.assoc_mode) {
|
||||||
|
(IsTraitAssocItem::Yes, AssocSearchMode::Exclude)
|
||||||
|
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly) => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks whether the import map entry matches the query.
|
||||||
fn import_matches(
|
fn import_matches(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
@ -352,12 +335,8 @@ impl Query {
|
|||||||
enforce_lowercase: bool,
|
enforce_lowercase: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let _p = profile::span("import_map::Query::import_matches");
|
let _p = profile::span("import_map::Query::import_matches");
|
||||||
match (import.is_trait_assoc_item, self.assoc_mode) {
|
|
||||||
(true, AssocSearchMode::Exclude) => return false,
|
|
||||||
(false, AssocSearchMode::AssocItemsOnly) => return false,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// FIXME: Can we get rid of the alloc here?
|
||||||
let mut input = import.name.display(db.upcast()).to_string();
|
let mut input = import.name.display(db.upcast()).to_string();
|
||||||
let case_insensitive = enforce_lowercase || !self.case_sensitive;
|
let case_insensitive = enforce_lowercase || !self.case_sensitive;
|
||||||
if case_insensitive {
|
if case_insensitive {
|
||||||
@ -388,7 +367,7 @@ impl Query {
|
|||||||
pub fn search_dependencies(
|
pub fn search_dependencies(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
query: Query,
|
ref query: Query,
|
||||||
) -> FxHashSet<ItemInNs> {
|
) -> FxHashSet<ItemInNs> {
|
||||||
let _p = profile::span("search_dependencies").detail(|| format!("{query:?}"));
|
let _p = profile::span("search_dependencies").detail(|| format!("{query:?}"));
|
||||||
|
|
||||||
@ -406,31 +385,58 @@ pub fn search_dependencies(
|
|||||||
let mut stream = op.union();
|
let mut stream = op.union();
|
||||||
|
|
||||||
let mut res = FxHashSet::default();
|
let mut res = FxHashSet::default();
|
||||||
|
let mut common_importable_data_scratch = vec![];
|
||||||
while let Some((_, indexed_values)) = stream.next() {
|
while let Some((_, indexed_values)) = stream.next() {
|
||||||
for indexed_value in indexed_values {
|
for &IndexedValue { index, value } in indexed_values {
|
||||||
let import_map = &import_maps[indexed_value.index];
|
let import_map = &import_maps[index];
|
||||||
let importables = &import_map.importables[indexed_value.value as usize..];
|
let importables @ [importable, ..] = &import_map.importables[value as usize..] else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let common_importable_data = &import_map.map[&importables[0]];
|
let &(ref importable_data, is_trait_assoc_item) = &import_map.map[importable];
|
||||||
if !query.import_matches(db, common_importable_data, true) {
|
if !query.matches_assoc_mode(is_trait_assoc_item) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name shared by the importable items in this group.
|
common_importable_data_scratch.extend(
|
||||||
let common_importable_name =
|
importable_data
|
||||||
common_importable_data.name.to_smol_str().to_ascii_lowercase();
|
.iter()
|
||||||
// Add the items from this name group. Those are all subsequent items in
|
.filter(|&info| query.import_matches(db, info, true))
|
||||||
// `importables` whose name match `common_importable_name`.
|
// Name shared by the importable items in this group.
|
||||||
let iter = importables
|
.map(|info| info.name.to_smol_str()),
|
||||||
.iter()
|
);
|
||||||
.copied()
|
if common_importable_data_scratch.is_empty() {
|
||||||
.take_while(|item| {
|
continue;
|
||||||
common_importable_name
|
}
|
||||||
== import_map.map[item].name.to_smol_str().to_ascii_lowercase()
|
common_importable_data_scratch.sort();
|
||||||
})
|
common_importable_data_scratch.dedup();
|
||||||
.filter(|item| {
|
|
||||||
!query.case_sensitive // we've already checked the common importables name case-insensitively
|
let iter =
|
||||||
|| query.import_matches(db, &import_map.map[item], false)
|
common_importable_data_scratch.drain(..).flat_map(|common_importable_name| {
|
||||||
|
// Add the items from this name group. Those are all subsequent items in
|
||||||
|
// `importables` whose name match `common_importable_name`.
|
||||||
|
importables
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.take_while(move |item| {
|
||||||
|
let &(ref import_infos, assoc_mode) = &import_map.map[item];
|
||||||
|
query.matches_assoc_mode(assoc_mode)
|
||||||
|
&& import_infos.iter().any(|info| {
|
||||||
|
info.name
|
||||||
|
.to_smol_str()
|
||||||
|
.eq_ignore_ascii_case(&common_importable_name)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.filter(move |item| {
|
||||||
|
!query.case_sensitive || {
|
||||||
|
// we've already checked the common importables name case-insensitively
|
||||||
|
let &(ref import_infos, assoc_mode) = &import_map.map[item];
|
||||||
|
query.matches_assoc_mode(assoc_mode)
|
||||||
|
&& import_infos
|
||||||
|
.iter()
|
||||||
|
.any(|info| query.import_matches(db, info, false))
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
res.extend(iter);
|
res.extend(iter);
|
||||||
|
|
||||||
@ -457,6 +463,7 @@ mod tests {
|
|||||||
let mut importable_paths: Vec<_> = self
|
let mut importable_paths: Vec<_> = self
|
||||||
.map
|
.map
|
||||||
.iter()
|
.iter()
|
||||||
|
.flat_map(|(item, (info, _))| info.iter().map(move |info| (item, info)))
|
||||||
.map(|(item, info)| {
|
.map(|(item, info)| {
|
||||||
let path = render_path(db, info);
|
let path = render_path(db, info);
|
||||||
let ns = match item {
|
let ns = match item {
|
||||||
@ -495,7 +502,7 @@ mod tests {
|
|||||||
let (path, mark) = match assoc_item_path(&db, &dependency_imports, dependency) {
|
let (path, mark) = match assoc_item_path(&db, &dependency_imports, dependency) {
|
||||||
Some(assoc_item_path) => (assoc_item_path, "a"),
|
Some(assoc_item_path) => (assoc_item_path, "a"),
|
||||||
None => (
|
None => (
|
||||||
render_path(&db, dependency_imports.import_info_for(dependency)?),
|
render_path(&db, &dependency_imports.import_info_for(dependency)?[0]),
|
||||||
match dependency {
|
match dependency {
|
||||||
ItemInNs::Types(ModuleDefId::FunctionId(_))
|
ItemInNs::Types(ModuleDefId::FunctionId(_))
|
||||||
| ItemInNs::Values(ModuleDefId::FunctionId(_)) => "f",
|
| ItemInNs::Values(ModuleDefId::FunctionId(_)) => "f",
|
||||||
@ -543,7 +550,12 @@ mod tests {
|
|||||||
.items
|
.items
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, assoc_item_id)| &dependency_assoc_item_id == assoc_item_id)?;
|
.find(|(_, assoc_item_id)| &dependency_assoc_item_id == assoc_item_id)?;
|
||||||
Some(format!("{}::{}", render_path(db, trait_info), assoc_item_name.display(db.upcast())))
|
// FIXME: This should check all import infos, not just the first
|
||||||
|
Some(format!(
|
||||||
|
"{}::{}",
|
||||||
|
render_path(db, &trait_info[0]),
|
||||||
|
assoc_item_name.display(db.upcast())
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
@ -619,6 +631,7 @@ mod tests {
|
|||||||
main:
|
main:
|
||||||
- publ1 (t)
|
- publ1 (t)
|
||||||
- real_pu2 (t)
|
- real_pu2 (t)
|
||||||
|
- real_pu2::Pub (t)
|
||||||
- real_pub (t)
|
- real_pub (t)
|
||||||
- real_pub::Pub (t)
|
- real_pub::Pub (t)
|
||||||
"#]],
|
"#]],
|
||||||
@ -644,6 +657,7 @@ mod tests {
|
|||||||
- sub (t)
|
- sub (t)
|
||||||
- sub::Def (t)
|
- sub::Def (t)
|
||||||
- sub::subsub (t)
|
- sub::subsub (t)
|
||||||
|
- sub::subsub::Def (t)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -743,7 +757,9 @@ mod tests {
|
|||||||
- module (t)
|
- module (t)
|
||||||
- module::S (t)
|
- module::S (t)
|
||||||
- module::S (v)
|
- module::S (v)
|
||||||
|
- module::module (t)
|
||||||
- sub (t)
|
- sub (t)
|
||||||
|
- sub::module (t)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -709,6 +709,7 @@ pub struct Impl {
|
|||||||
pub target_trait: Option<Interned<TraitRef>>,
|
pub target_trait: Option<Interned<TraitRef>>,
|
||||||
pub self_ty: Interned<TypeRef>,
|
pub self_ty: Interned<TypeRef>,
|
||||||
pub is_negative: bool,
|
pub is_negative: bool,
|
||||||
|
pub is_unsafe: bool,
|
||||||
pub items: Box<[AssocItem]>,
|
pub items: Box<[AssocItem]>,
|
||||||
pub ast_id: FileAstId<ast::Impl>,
|
pub ast_id: FileAstId<ast::Impl>,
|
||||||
}
|
}
|
||||||
|
@ -396,14 +396,7 @@ impl<'a> Ctx<'a> {
|
|||||||
let bounds = self.lower_type_bounds(type_alias);
|
let bounds = self.lower_type_bounds(type_alias);
|
||||||
let generic_params = self.lower_generic_params(HasImplicitSelf::No, type_alias);
|
let generic_params = self.lower_generic_params(HasImplicitSelf::No, type_alias);
|
||||||
let ast_id = self.source_ast_id_map.ast_id(type_alias);
|
let ast_id = self.source_ast_id_map.ast_id(type_alias);
|
||||||
let res = TypeAlias {
|
let res = TypeAlias { name, visibility, bounds, generic_params, type_ref, ast_id };
|
||||||
name,
|
|
||||||
visibility,
|
|
||||||
bounds: bounds.into_boxed_slice(),
|
|
||||||
generic_params,
|
|
||||||
type_ref,
|
|
||||||
ast_id,
|
|
||||||
};
|
|
||||||
Some(id(self.data().type_aliases.alloc(res)))
|
Some(id(self.data().type_aliases.alloc(res)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,6 +492,7 @@ impl<'a> Ctx<'a> {
|
|||||||
let target_trait = impl_def.trait_().and_then(|tr| self.lower_trait_ref(&tr));
|
let target_trait = impl_def.trait_().and_then(|tr| self.lower_trait_ref(&tr));
|
||||||
let self_ty = self.lower_type_ref(&impl_def.self_ty()?);
|
let self_ty = self.lower_type_ref(&impl_def.self_ty()?);
|
||||||
let is_negative = impl_def.excl_token().is_some();
|
let is_negative = impl_def.excl_token().is_some();
|
||||||
|
let is_unsafe = impl_def.unsafe_token().is_some();
|
||||||
|
|
||||||
// We cannot use `assoc_items()` here as that does not include macro calls.
|
// We cannot use `assoc_items()` here as that does not include macro calls.
|
||||||
let items = impl_def
|
let items = impl_def
|
||||||
@ -513,7 +507,8 @@ impl<'a> Ctx<'a> {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let ast_id = self.source_ast_id_map.ast_id(impl_def);
|
let ast_id = self.source_ast_id_map.ast_id(impl_def);
|
||||||
let res = Impl { generic_params, target_trait, self_ty, is_negative, items, ast_id };
|
let res =
|
||||||
|
Impl { generic_params, target_trait, self_ty, is_negative, is_unsafe, items, ast_id };
|
||||||
Some(id(self.data().impls.alloc(res)))
|
Some(id(self.data().impls.alloc(res)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,13 +632,13 @@ impl<'a> Ctx<'a> {
|
|||||||
Interned::new(generics)
|
Interned::new(generics)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_type_bounds(&mut self, node: &dyn ast::HasTypeBounds) -> Vec<Interned<TypeBound>> {
|
fn lower_type_bounds(&mut self, node: &dyn ast::HasTypeBounds) -> Box<[Interned<TypeBound>]> {
|
||||||
match node.type_bound_list() {
|
match node.type_bound_list() {
|
||||||
Some(bound_list) => bound_list
|
Some(bound_list) => bound_list
|
||||||
.bounds()
|
.bounds()
|
||||||
.map(|it| Interned::new(TypeBound::from_ast(&self.body_ctx, it)))
|
.map(|it| Interned::new(TypeBound::from_ast(&self.body_ctx, it)))
|
||||||
.collect(),
|
.collect(),
|
||||||
None => Vec::new(),
|
None => Box::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,8 +388,18 @@ impl Printer<'_> {
|
|||||||
wln!(self);
|
wln!(self);
|
||||||
}
|
}
|
||||||
ModItem::Impl(it) => {
|
ModItem::Impl(it) => {
|
||||||
let Impl { target_trait, self_ty, is_negative, items, generic_params, ast_id: _ } =
|
let Impl {
|
||||||
&self.tree[it];
|
target_trait,
|
||||||
|
self_ty,
|
||||||
|
is_negative,
|
||||||
|
is_unsafe,
|
||||||
|
items,
|
||||||
|
generic_params,
|
||||||
|
ast_id: _,
|
||||||
|
} = &self.tree[it];
|
||||||
|
if *is_unsafe {
|
||||||
|
w!(self, "unsafe");
|
||||||
|
}
|
||||||
w!(self, "impl");
|
w!(self, "impl");
|
||||||
self.print_generic_params(generic_params);
|
self.print_generic_params(generic_params);
|
||||||
w!(self, " ");
|
w!(self, " ");
|
||||||
|
@ -152,7 +152,7 @@ impl TryFrom<ModuleId> for CrateRootModuleId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct ModuleId {
|
pub struct ModuleId {
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
/// If this `ModuleId` was derived from a `DefMap` for a block expression, this stores the
|
/// If this `ModuleId` was derived from a `DefMap` for a block expression, this stores the
|
||||||
|
@ -17,7 +17,7 @@ fn main() { column!(); }
|
|||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
macro_rules! column {() => {}}
|
macro_rules! column {() => {}}
|
||||||
|
|
||||||
fn main() { 0 as u32; }
|
fn main() { 0u32; }
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ fn main() { line!() }
|
|||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
macro_rules! line {() => {}}
|
macro_rules! line {() => {}}
|
||||||
|
|
||||||
fn main() { 0 as u32 }
|
fn main() { 0u32 }
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -970,3 +970,37 @@ builtin #format_args ("{}", &[0 2]);
|
|||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn eager_concat_line() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! concat {}
|
||||||
|
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! line {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
concat!("event ", line!());
|
||||||
|
}
|
||||||
|
|
||||||
|
"#,
|
||||||
|
expect![[r##"
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! concat {}
|
||||||
|
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! line {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
"event 0u32";
|
||||||
|
}
|
||||||
|
|
||||||
|
"##]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -13,11 +13,11 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
|
@ -78,7 +78,7 @@ pub fn find_builtin_macro(
|
|||||||
|
|
||||||
register_builtin! {
|
register_builtin! {
|
||||||
LAZY:
|
LAZY:
|
||||||
(column, Column) => column_expand,
|
(column, Column) => line_expand,
|
||||||
(file, File) => file_expand,
|
(file, File) => file_expand,
|
||||||
(line, Line) => line_expand,
|
(line, Line) => line_expand,
|
||||||
(module_path, ModulePath) => module_path_expand,
|
(module_path, ModulePath) => module_path_expand,
|
||||||
@ -127,11 +127,13 @@ fn line_expand(
|
|||||||
_tt: &tt::Subtree,
|
_tt: &tt::Subtree,
|
||||||
) -> ExpandResult<tt::Subtree> {
|
) -> ExpandResult<tt::Subtree> {
|
||||||
// dummy implementation for type-checking purposes
|
// dummy implementation for type-checking purposes
|
||||||
let expanded = quote! {
|
ExpandResult::ok(tt::Subtree {
|
||||||
0 as u32
|
delimiter: tt::Delimiter::unspecified(),
|
||||||
};
|
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
|
||||||
|
text: "0u32".into(),
|
||||||
ExpandResult::ok(expanded)
|
span: tt::Span::UNSPECIFIED,
|
||||||
|
}))],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_syntax_expand(
|
fn log_syntax_expand(
|
||||||
@ -164,19 +166,6 @@ fn stringify_expand(
|
|||||||
ExpandResult::ok(expanded)
|
ExpandResult::ok(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_expand(
|
|
||||||
_db: &dyn ExpandDatabase,
|
|
||||||
_id: MacroCallId,
|
|
||||||
_tt: &tt::Subtree,
|
|
||||||
) -> ExpandResult<tt::Subtree> {
|
|
||||||
// dummy implementation for type-checking purposes
|
|
||||||
let expanded = quote! {
|
|
||||||
0 as u32
|
|
||||||
};
|
|
||||||
|
|
||||||
ExpandResult::ok(expanded)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_expand(
|
fn assert_expand(
|
||||||
_db: &dyn ExpandDatabase,
|
_db: &dyn ExpandDatabase,
|
||||||
_id: MacroCallId,
|
_id: MacroCallId,
|
||||||
|
@ -12,15 +12,11 @@ use syntax::{
|
|||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast_id_map::AstIdMap,
|
ast_id_map::AstIdMap, builtin_attr_macro::pseudo_derive_attr_expansion,
|
||||||
builtin_attr_macro::pseudo_derive_attr_expansion,
|
builtin_fn_macro::EagerExpander, fixup, hygiene::HygieneFrame, tt, AstId, BuiltinAttrExpander,
|
||||||
builtin_fn_macro::EagerExpander,
|
BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo, ExpandError, ExpandResult,
|
||||||
fixup,
|
ExpandTo, HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId,
|
||||||
hygiene::HygieneFrame,
|
MacroDefKind, MacroFile, ProcMacroExpander,
|
||||||
name::{name, AsName},
|
|
||||||
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo,
|
|
||||||
ExpandError, ExpandResult, ExpandTo, HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind,
|
|
||||||
MacroCallLoc, MacroDefId, MacroDefKind, MacroFile, ProcMacroExpander,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Total limit on the number of tokens produced by any macro invocation.
|
/// Total limit on the number of tokens produced by any macro invocation.
|
||||||
@ -619,20 +615,7 @@ fn macro_expand(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip checking token tree limit for include! macro call
|
// Skip checking token tree limit for include! macro call
|
||||||
let skip_check_tt_count = match loc.kind {
|
if !loc.def.is_include() {
|
||||||
MacroCallKind::FnLike { ast_id, expand_to: _ } => {
|
|
||||||
if let Some(name_ref) =
|
|
||||||
ast_id.to_node(db).path().and_then(|p| p.segment()).and_then(|s| s.name_ref())
|
|
||||||
{
|
|
||||||
name_ref.as_name() == name!(include)
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if !skip_check_tt_count {
|
|
||||||
// Set a hard limit for the expanded tt
|
// Set a hard limit for the expanded tt
|
||||||
if let Err(value) = check_tt_count(&tt) {
|
if let Err(value) = check_tt_count(&tt) {
|
||||||
return value;
|
return value;
|
||||||
|
@ -13,20 +13,20 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
arrayvec = "0.7.2"
|
arrayvec = "0.7.2"
|
||||||
bitflags = "2.1.0"
|
bitflags.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
ena = "0.14.0"
|
ena = "0.14.0"
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
oorandom = "11.1.3"
|
oorandom = "11.1.3"
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
scoped-tls = "1.0.0"
|
scoped-tls = "1.0.0"
|
||||||
chalk-solve = { version = "0.93.0", default-features = false }
|
chalk-solve = { version = "0.94.0", default-features = false }
|
||||||
chalk-ir = "0.93.0"
|
chalk-ir = "0.94.0"
|
||||||
chalk-recursive = { version = "0.93.0", default-features = false }
|
chalk-recursive = { version = "0.94.0", default-features = false }
|
||||||
chalk-derive = "0.93.0"
|
chalk-derive = "0.94.0"
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
@ -47,11 +47,9 @@ limit.workspace = true
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
expect-test = "1.4.0"
|
expect-test = "1.4.0"
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
tracing-subscriber = { version = "0.3.16", default-features = false, features = [
|
tracing-subscriber.workspace = true
|
||||||
"registry",
|
tracing-tree.workspace = true
|
||||||
] }
|
|
||||||
tracing-tree = "0.2.1"
|
|
||||||
project-model = { path = "../project-model" }
|
project-model = { path = "../project-model" }
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
|
@ -28,6 +28,7 @@ pub trait TyExt {
|
|||||||
fn is_unknown(&self) -> bool;
|
fn is_unknown(&self) -> bool;
|
||||||
fn contains_unknown(&self) -> bool;
|
fn contains_unknown(&self) -> bool;
|
||||||
fn is_ty_var(&self) -> bool;
|
fn is_ty_var(&self) -> bool;
|
||||||
|
fn is_union(&self) -> bool;
|
||||||
|
|
||||||
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)>;
|
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)>;
|
||||||
fn as_builtin(&self) -> Option<BuiltinType>;
|
fn as_builtin(&self) -> Option<BuiltinType>;
|
||||||
@ -96,6 +97,10 @@ impl TyExt for Ty {
|
|||||||
matches!(self.kind(Interner), TyKind::InferenceVar(_, _))
|
matches!(self.kind(Interner), TyKind::InferenceVar(_, _))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_union(&self) -> bool {
|
||||||
|
matches!(self.adt_id(Interner), Some(AdtId(hir_def::AdtId::UnionId(_))))
|
||||||
|
}
|
||||||
|
|
||||||
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> {
|
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> {
|
||||||
match self.kind(Interner) {
|
match self.kind(Interner) {
|
||||||
TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)),
|
TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)),
|
||||||
|
@ -20,8 +20,8 @@ use crate::{
|
|||||||
method_resolution::{InherentImpls, TraitImpls, TyFingerprint},
|
method_resolution::{InherentImpls, TraitImpls, TyFingerprint},
|
||||||
mir::{BorrowckResult, MirBody, MirLowerError},
|
mir::{BorrowckResult, MirBody, MirLowerError},
|
||||||
Binders, CallableDefId, ClosureId, Const, FnDefId, GenericArg, ImplTraitId, InferenceResult,
|
Binders, CallableDefId, ClosureId, Const, FnDefId, GenericArg, ImplTraitId, InferenceResult,
|
||||||
Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, Substitution, TraitRef, Ty,
|
Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, Substitution,
|
||||||
TyDefId, ValueTyDefId,
|
TraitEnvironment, TraitRef, Ty, TyDefId, ValueTyDefId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
&self,
|
&self,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
subst: Substitution,
|
subst: Substitution,
|
||||||
env: Arc<crate::TraitEnvironment>,
|
env: Arc<TraitEnvironment>,
|
||||||
) -> Result<Arc<MirBody>, MirLowerError>;
|
) -> Result<Arc<MirBody>, MirLowerError>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::mir::monomorphized_mir_body_for_closure_query)]
|
#[salsa::invoke(crate::mir::monomorphized_mir_body_for_closure_query)]
|
||||||
@ -55,7 +55,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
&self,
|
&self,
|
||||||
def: ClosureId,
|
def: ClosureId,
|
||||||
subst: Substitution,
|
subst: Substitution,
|
||||||
env: Arc<crate::TraitEnvironment>,
|
env: Arc<TraitEnvironment>,
|
||||||
) -> Result<Arc<MirBody>, MirLowerError>;
|
) -> Result<Arc<MirBody>, MirLowerError>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::mir::borrowck_query)]
|
#[salsa::invoke(crate::mir::borrowck_query)]
|
||||||
@ -81,7 +81,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
&self,
|
&self,
|
||||||
def: GeneralConstId,
|
def: GeneralConstId,
|
||||||
subst: Substitution,
|
subst: Substitution,
|
||||||
trait_env: Option<Arc<crate::TraitEnvironment>>,
|
trait_env: Option<Arc<TraitEnvironment>>,
|
||||||
) -> Result<Const, ConstEvalError>;
|
) -> Result<Const, ConstEvalError>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::consteval::const_eval_static_query)]
|
#[salsa::invoke(crate::consteval::const_eval_static_query)]
|
||||||
@ -104,16 +104,12 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
&self,
|
&self,
|
||||||
def: AdtId,
|
def: AdtId,
|
||||||
subst: Substitution,
|
subst: Substitution,
|
||||||
env: Arc<crate::TraitEnvironment>,
|
env: Arc<TraitEnvironment>,
|
||||||
) -> Result<Arc<Layout>, LayoutError>;
|
) -> Result<Arc<Layout>, LayoutError>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::layout::layout_of_ty_query)]
|
#[salsa::invoke(crate::layout::layout_of_ty_query)]
|
||||||
#[salsa::cycle(crate::layout::layout_of_ty_recover)]
|
#[salsa::cycle(crate::layout::layout_of_ty_recover)]
|
||||||
fn layout_of_ty(
|
fn layout_of_ty(&self, ty: Ty, env: Arc<TraitEnvironment>) -> Result<Arc<Layout>, LayoutError>;
|
||||||
&self,
|
|
||||||
ty: Ty,
|
|
||||||
env: Arc<crate::TraitEnvironment>,
|
|
||||||
) -> Result<Arc<Layout>, LayoutError>;
|
|
||||||
|
|
||||||
#[salsa::invoke(crate::layout::target_data_layout_query)]
|
#[salsa::invoke(crate::layout::target_data_layout_query)]
|
||||||
fn target_data_layout(&self, krate: CrateId) -> Option<Arc<TargetDataLayout>>;
|
fn target_data_layout(&self, krate: CrateId) -> Option<Arc<TargetDataLayout>>;
|
||||||
@ -121,7 +117,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
#[salsa::invoke(crate::method_resolution::lookup_impl_method_query)]
|
#[salsa::invoke(crate::method_resolution::lookup_impl_method_query)]
|
||||||
fn lookup_impl_method(
|
fn lookup_impl_method(
|
||||||
&self,
|
&self,
|
||||||
env: Arc<crate::TraitEnvironment>,
|
env: Arc<TraitEnvironment>,
|
||||||
func: FunctionId,
|
func: FunctionId,
|
||||||
fn_subst: Substitution,
|
fn_subst: Substitution,
|
||||||
) -> (FunctionId, Substitution);
|
) -> (FunctionId, Substitution);
|
||||||
@ -149,10 +145,10 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
|
|
||||||
#[salsa::invoke(crate::lower::trait_environment_for_body_query)]
|
#[salsa::invoke(crate::lower::trait_environment_for_body_query)]
|
||||||
#[salsa::transparent]
|
#[salsa::transparent]
|
||||||
fn trait_environment_for_body(&self, def: DefWithBodyId) -> Arc<crate::TraitEnvironment>;
|
fn trait_environment_for_body(&self, def: DefWithBodyId) -> Arc<TraitEnvironment>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::lower::trait_environment_query)]
|
#[salsa::invoke(crate::lower::trait_environment_query)]
|
||||||
fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>;
|
fn trait_environment(&self, def: GenericDefId) -> Arc<TraitEnvironment>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::lower::generic_defaults_query)]
|
#[salsa::invoke(crate::lower::generic_defaults_query)]
|
||||||
#[salsa::cycle(crate::lower::generic_defaults_recover)]
|
#[salsa::cycle(crate::lower::generic_defaults_recover)]
|
||||||
@ -249,7 +245,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||||||
fn normalize_projection(
|
fn normalize_projection(
|
||||||
&self,
|
&self,
|
||||||
projection: crate::ProjectionTy,
|
projection: crate::ProjectionTy,
|
||||||
env: Arc<crate::TraitEnvironment>,
|
env: Arc<TraitEnvironment>,
|
||||||
) -> Ty;
|
) -> Ty;
|
||||||
|
|
||||||
#[salsa::invoke(trait_solve_wait)]
|
#[salsa::invoke(trait_solve_wait)]
|
||||||
|
@ -11,9 +11,3 @@ pub use crate::diagnostics::{
|
|||||||
},
|
},
|
||||||
unsafe_check::{missing_unsafe, unsafe_expressions, UnsafeExpr},
|
unsafe_check::{missing_unsafe, unsafe_expressions, UnsafeExpr},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
|
||||||
pub struct IncoherentImpl {
|
|
||||||
pub file_id: hir_expand::HirFileId,
|
|
||||||
pub impl_: syntax::AstPtr<syntax::ast::Impl>,
|
|
||||||
}
|
|
||||||
|
@ -19,8 +19,8 @@ use hir_def::{
|
|||||||
data::adt::VariantData,
|
data::adt::VariantData,
|
||||||
hir::{Pat, PatId},
|
hir::{Pat, PatId},
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
AdtId, AttrDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, ItemContainerId,
|
AdtId, AttrDefId, ConstId, EnumId, FunctionId, ItemContainerId, Lookup, ModuleDefId, ModuleId,
|
||||||
Lookup, ModuleDefId, ModuleId, StaticId, StructId,
|
StaticId, StructId,
|
||||||
};
|
};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
@ -290,8 +290,6 @@ impl<'a> DeclValidator<'a> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.validate_body_inner_items(func.into());
|
|
||||||
|
|
||||||
// Check whether non-snake case identifiers are allowed for this function.
|
// Check whether non-snake case identifiers are allowed for this function.
|
||||||
if self.allowed(func.into(), allow::NON_SNAKE_CASE, false) {
|
if self.allowed(func.into(), allow::NON_SNAKE_CASE, false) {
|
||||||
return;
|
return;
|
||||||
@ -568,11 +566,6 @@ impl<'a> DeclValidator<'a> {
|
|||||||
fn validate_enum(&mut self, enum_id: EnumId) {
|
fn validate_enum(&mut self, enum_id: EnumId) {
|
||||||
let data = self.db.enum_data(enum_id);
|
let data = self.db.enum_data(enum_id);
|
||||||
|
|
||||||
for (local_id, _) in data.variants.iter() {
|
|
||||||
let variant_id = EnumVariantId { parent: enum_id, local_id };
|
|
||||||
self.validate_body_inner_items(variant_id.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether non-camel case names are allowed for this enum.
|
// Check whether non-camel case names are allowed for this enum.
|
||||||
if self.allowed(enum_id.into(), allow::NON_CAMEL_CASE_TYPES, false) {
|
if self.allowed(enum_id.into(), allow::NON_CAMEL_CASE_TYPES, false) {
|
||||||
return;
|
return;
|
||||||
@ -697,8 +690,6 @@ impl<'a> DeclValidator<'a> {
|
|||||||
fn validate_const(&mut self, const_id: ConstId) {
|
fn validate_const(&mut self, const_id: ConstId) {
|
||||||
let data = self.db.const_data(const_id);
|
let data = self.db.const_data(const_id);
|
||||||
|
|
||||||
self.validate_body_inner_items(const_id.into());
|
|
||||||
|
|
||||||
if self.allowed(const_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
|
if self.allowed(const_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -747,8 +738,6 @@ impl<'a> DeclValidator<'a> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.validate_body_inner_items(static_id.into());
|
|
||||||
|
|
||||||
if self.allowed(static_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
|
if self.allowed(static_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -786,17 +775,4 @@ impl<'a> DeclValidator<'a> {
|
|||||||
|
|
||||||
self.sink.push(diagnostic);
|
self.sink.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: We don't currently validate names within `DefWithBodyId::InTypeConstId`.
|
|
||||||
/// Recursively validates inner scope items, such as static variables and constants.
|
|
||||||
fn validate_body_inner_items(&mut self, body_id: DefWithBodyId) {
|
|
||||||
let body = self.db.body(body_id);
|
|
||||||
for (_, block_def_map) in body.blocks(self.db.upcast()) {
|
|
||||||
for (_, module) in block_def_map.modules() {
|
|
||||||
for def_id in module.scope.declarations() {
|
|
||||||
self.validate_item(def_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -945,6 +945,7 @@ impl HirDisplay for Ty {
|
|||||||
ItemInNs::Types((*def_id).into()),
|
ItemInNs::Types((*def_id).into()),
|
||||||
module_id,
|
module_id,
|
||||||
false,
|
false,
|
||||||
|
true,
|
||||||
) {
|
) {
|
||||||
write!(f, "{}", path.display(f.db.upcast()))?;
|
write!(f, "{}", path.display(f.db.upcast()))?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -735,6 +735,32 @@ impl InferenceContext<'_> {
|
|||||||
self.walk_expr(expr);
|
self.walk_expr(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn restrict_precision_for_unsafe(&mut self) {
|
||||||
|
for capture in &mut self.current_captures {
|
||||||
|
let mut ty = self.table.resolve_completely(self.result[capture.place.local].clone());
|
||||||
|
if ty.as_raw_ptr().is_some() || ty.is_union() {
|
||||||
|
capture.kind = CaptureKind::ByRef(BorrowKind::Shared);
|
||||||
|
capture.place.projections.truncate(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i, p) in capture.place.projections.iter().enumerate() {
|
||||||
|
ty = p.projected_ty(
|
||||||
|
ty,
|
||||||
|
self.db,
|
||||||
|
|_, _, _| {
|
||||||
|
unreachable!("Closure field only happens in MIR");
|
||||||
|
},
|
||||||
|
self.owner.module(self.db.upcast()).krate(),
|
||||||
|
);
|
||||||
|
if ty.as_raw_ptr().is_some() || ty.is_union() {
|
||||||
|
capture.kind = CaptureKind::ByRef(BorrowKind::Shared);
|
||||||
|
capture.place.projections.truncate(i + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn adjust_for_move_closure(&mut self) {
|
fn adjust_for_move_closure(&mut self) {
|
||||||
for capture in &mut self.current_captures {
|
for capture in &mut self.current_captures {
|
||||||
if let Some(first_deref) =
|
if let Some(first_deref) =
|
||||||
@ -924,6 +950,7 @@ impl InferenceContext<'_> {
|
|||||||
self.result.mutated_bindings_in_closure.insert(item.place.local);
|
self.result.mutated_bindings_in_closure.insert(item.place.local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.restrict_precision_for_unsafe();
|
||||||
// closure_kind should be done before adjust_for_move_closure
|
// closure_kind should be done before adjust_for_move_closure
|
||||||
let closure_kind = self.closure_kind();
|
let closure_kind = self.closure_kind();
|
||||||
match capture_by {
|
match capture_by {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Compute the binary representation of a type
|
//! Compute the binary representation of a type
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy};
|
use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
layout::{
|
layout::{
|
||||||
@ -26,12 +28,6 @@ pub use self::{
|
|||||||
target::target_data_layout_query,
|
target::target_data_layout_query,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! user_error {
|
|
||||||
($it: expr) => {
|
|
||||||
return Err(LayoutError::UserError(format!($it).into()))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
mod adt;
|
mod adt;
|
||||||
mod target;
|
mod target;
|
||||||
|
|
||||||
@ -73,13 +69,38 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum LayoutError {
|
pub enum LayoutError {
|
||||||
UserError(Box<str>),
|
HasErrorConst,
|
||||||
|
HasErrorType,
|
||||||
|
HasPlaceholder,
|
||||||
|
InvalidSimdType,
|
||||||
|
NotImplemented,
|
||||||
|
RecursiveTypeWithoutIndirection,
|
||||||
SizeOverflow,
|
SizeOverflow,
|
||||||
TargetLayoutNotAvailable,
|
TargetLayoutNotAvailable,
|
||||||
HasPlaceholder,
|
|
||||||
HasErrorType,
|
|
||||||
NotImplemented,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
|
UserReprTooSmall,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for LayoutError {}
|
||||||
|
impl fmt::Display for LayoutError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
LayoutError::HasErrorConst => write!(f, "type contains an unevaluatable const"),
|
||||||
|
LayoutError::HasErrorType => write!(f, "type contains an error"),
|
||||||
|
LayoutError::HasPlaceholder => write!(f, "type contains placeholders"),
|
||||||
|
LayoutError::InvalidSimdType => write!(f, "invalid simd type definition"),
|
||||||
|
LayoutError::NotImplemented => write!(f, "not implemented"),
|
||||||
|
LayoutError::RecursiveTypeWithoutIndirection => {
|
||||||
|
write!(f, "recursive type without indirection")
|
||||||
|
}
|
||||||
|
LayoutError::SizeOverflow => write!(f, "size overflow"),
|
||||||
|
LayoutError::TargetLayoutNotAvailable => write!(f, "target layout not available"),
|
||||||
|
LayoutError::Unknown => write!(f, "unknown"),
|
||||||
|
LayoutError::UserReprTooSmall => {
|
||||||
|
write!(f, "the `#[repr]` hint is too small to hold the discriminants of the enum")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LayoutCx<'a> {
|
struct LayoutCx<'a> {
|
||||||
@ -118,9 +139,7 @@ fn layout_of_simd_ty(
|
|||||||
|
|
||||||
let f0_ty = match fields.iter().next() {
|
let f0_ty = match fields.iter().next() {
|
||||||
Some(it) => it.1.clone().substitute(Interner, subst),
|
Some(it) => it.1.clone().substitute(Interner, subst),
|
||||||
None => {
|
None => return Err(LayoutError::InvalidSimdType),
|
||||||
user_error!("simd type with zero fields");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// The element type and number of elements of the SIMD vector
|
// The element type and number of elements of the SIMD vector
|
||||||
@ -134,7 +153,7 @@ fn layout_of_simd_ty(
|
|||||||
// Extract the number of elements from the layout of the array field:
|
// Extract the number of elements from the layout of the array field:
|
||||||
let FieldsShape::Array { count, .. } = db.layout_of_ty(f0_ty.clone(), env.clone())?.fields
|
let FieldsShape::Array { count, .. } = db.layout_of_ty(f0_ty.clone(), env.clone())?.fields
|
||||||
else {
|
else {
|
||||||
user_error!("Array with non array layout");
|
return Err(LayoutError::Unknown);
|
||||||
};
|
};
|
||||||
|
|
||||||
(e_ty.clone(), count, true)
|
(e_ty.clone(), count, true)
|
||||||
@ -146,7 +165,7 @@ fn layout_of_simd_ty(
|
|||||||
// Compute the ABI of the element type:
|
// Compute the ABI of the element type:
|
||||||
let e_ly = db.layout_of_ty(e_ty, env.clone())?;
|
let e_ly = db.layout_of_ty(e_ty, env.clone())?;
|
||||||
let Abi::Scalar(e_abi) = e_ly.abi else {
|
let Abi::Scalar(e_abi) = e_ly.abi else {
|
||||||
user_error!("simd type with inner non scalar type");
|
return Err(LayoutError::Unknown);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compute the size and alignment of the vector:
|
// Compute the size and alignment of the vector:
|
||||||
@ -259,9 +278,7 @@ pub fn layout_of_ty_query(
|
|||||||
cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)?
|
cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)?
|
||||||
}
|
}
|
||||||
TyKind::Array(element, count) => {
|
TyKind::Array(element, count) => {
|
||||||
let count = try_const_usize(db, &count).ok_or(LayoutError::UserError(Box::from(
|
let count = try_const_usize(db, &count).ok_or(LayoutError::HasErrorConst)? as u64;
|
||||||
"unevaluated or mistyped const generic parameter",
|
|
||||||
)))? as u64;
|
|
||||||
let element = db.layout_of_ty(element.clone(), trait_env.clone())?;
|
let element = db.layout_of_ty(element.clone(), trait_env.clone())?;
|
||||||
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
|
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
|
||||||
|
|
||||||
@ -352,7 +369,7 @@ pub fn layout_of_ty_query(
|
|||||||
let mut unit = layout_of_unit(&cx, dl)?;
|
let mut unit = layout_of_unit(&cx, dl)?;
|
||||||
match unit.abi {
|
match unit.abi {
|
||||||
Abi::Aggregate { ref mut sized } => *sized = false,
|
Abi::Aggregate { ref mut sized } => *sized = false,
|
||||||
_ => user_error!("bug"),
|
_ => return Err(LayoutError::Unknown),
|
||||||
}
|
}
|
||||||
unit
|
unit
|
||||||
}
|
}
|
||||||
@ -418,7 +435,7 @@ pub fn layout_of_ty_recover(
|
|||||||
_: &Ty,
|
_: &Ty,
|
||||||
_: &Arc<TraitEnvironment>,
|
_: &Arc<TraitEnvironment>,
|
||||||
) -> Result<Arc<Layout>, LayoutError> {
|
) -> Result<Arc<Layout>, LayoutError> {
|
||||||
user_error!("infinite sized recursive type");
|
Err(LayoutError::RecursiveTypeWithoutIndirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, LayoutError> {
|
fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, LayoutError> {
|
||||||
|
@ -145,7 +145,7 @@ pub fn layout_of_adt_recover(
|
|||||||
_: &Substitution,
|
_: &Substitution,
|
||||||
_: &Arc<TraitEnvironment>,
|
_: &Arc<TraitEnvironment>,
|
||||||
) -> Result<Arc<Layout>, LayoutError> {
|
) -> Result<Arc<Layout>, LayoutError> {
|
||||||
user_error!("infinite sized recursive type");
|
Err(LayoutError::RecursiveTypeWithoutIndirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the appropriate Integer type and signedness for the given
|
/// Finds the appropriate Integer type and signedness for the given
|
||||||
@ -169,11 +169,7 @@ fn repr_discr(
|
|||||||
let discr = Integer::from_attr(dl, ity);
|
let discr = Integer::from_attr(dl, ity);
|
||||||
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
|
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
|
||||||
if discr < fit {
|
if discr < fit {
|
||||||
return Err(LayoutError::UserError(
|
return Err(LayoutError::UserReprTooSmall);
|
||||||
"Integer::repr_discr: `#[repr]` hint too small for \
|
|
||||||
discriminant range of enum "
|
|
||||||
.into(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
return Ok((discr, ity.is_signed()));
|
return Ok((discr, ity.is_signed()));
|
||||||
}
|
}
|
||||||
|
@ -210,16 +210,13 @@ fn recursive() {
|
|||||||
struct BoxLike<T: ?Sized>(*mut T);
|
struct BoxLike<T: ?Sized>(*mut T);
|
||||||
struct Goal(BoxLike<Goal>);
|
struct Goal(BoxLike<Goal>);
|
||||||
}
|
}
|
||||||
check_fail(
|
check_fail(r#"struct Goal(Goal);"#, LayoutError::RecursiveTypeWithoutIndirection);
|
||||||
r#"struct Goal(Goal);"#,
|
|
||||||
LayoutError::UserError("infinite sized recursive type".into()),
|
|
||||||
);
|
|
||||||
check_fail(
|
check_fail(
|
||||||
r#"
|
r#"
|
||||||
struct Foo<T>(Foo<T>);
|
struct Foo<T>(Foo<T>);
|
||||||
struct Goal(Foo<i32>);
|
struct Goal(Foo<i32>);
|
||||||
"#,
|
"#,
|
||||||
LayoutError::UserError("infinite sized recursive type".into()),
|
LayoutError::RecursiveTypeWithoutIndirection,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ pub use mapping::{
|
|||||||
lt_from_placeholder_idx, to_assoc_type_id, to_chalk_trait_id, to_foreign_def_id,
|
lt_from_placeholder_idx, to_assoc_type_id, to_chalk_trait_id, to_foreign_def_id,
|
||||||
to_placeholder_idx,
|
to_placeholder_idx,
|
||||||
};
|
};
|
||||||
|
pub use method_resolution::check_orphan_rules;
|
||||||
pub use traits::TraitEnvironment;
|
pub use traits::TraitEnvironment;
|
||||||
pub use utils::{all_super_traits, is_fn_unsafe_to_call};
|
pub use utils::{all_super_traits, is_fn_unsafe_to_call};
|
||||||
|
|
||||||
|
@ -1383,51 +1383,50 @@ pub(crate) fn generic_predicates_for_param_query(
|
|||||||
let ctx = TyLoweringContext::new(db, &resolver, def.into())
|
let ctx = TyLoweringContext::new(db, &resolver, def.into())
|
||||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||||
let generics = generics(db.upcast(), def);
|
let generics = generics(db.upcast(), def);
|
||||||
|
|
||||||
|
// we have to filter out all other predicates *first*, before attempting to lower them
|
||||||
|
let predicate = |pred: &&_| match pred {
|
||||||
|
WherePredicate::ForLifetime { target, bound, .. }
|
||||||
|
| WherePredicate::TypeBound { target, bound, .. } => {
|
||||||
|
let invalid_target = match target {
|
||||||
|
WherePredicateTypeTarget::TypeRef(type_ref) => {
|
||||||
|
ctx.lower_ty_only_param(type_ref) != Some(param_id)
|
||||||
|
}
|
||||||
|
&WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
|
||||||
|
let target_id = TypeOrConstParamId { parent: def, local_id };
|
||||||
|
target_id != param_id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if invalid_target {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
match &**bound {
|
||||||
|
TypeBound::ForLifetime(_, path) | TypeBound::Path(path, _) => {
|
||||||
|
// Only lower the bound if the trait could possibly define the associated
|
||||||
|
// type we're looking for.
|
||||||
|
|
||||||
|
let Some(assoc_name) = &assoc_name else { return true };
|
||||||
|
let Some(TypeNs::TraitId(tr)) =
|
||||||
|
resolver.resolve_path_in_type_ns_fully(db.upcast(), path)
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
all_super_traits(db.upcast(), tr).iter().any(|tr| {
|
||||||
|
db.trait_data(*tr).items.iter().any(|(name, item)| {
|
||||||
|
matches!(item, AssocItemId::TypeAliasId(_)) && name == assoc_name
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
TypeBound::Lifetime(_) | TypeBound::Error => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WherePredicate::Lifetime { .. } => false,
|
||||||
|
};
|
||||||
let mut predicates: Vec<_> = resolver
|
let mut predicates: Vec<_> = resolver
|
||||||
.where_predicates_in_scope()
|
.where_predicates_in_scope()
|
||||||
// we have to filter out all other predicates *first*, before attempting to lower them
|
.filter(predicate)
|
||||||
.filter(|pred| match pred {
|
|
||||||
WherePredicate::ForLifetime { target, bound, .. }
|
|
||||||
| WherePredicate::TypeBound { target, bound, .. } => {
|
|
||||||
match target {
|
|
||||||
WherePredicateTypeTarget::TypeRef(type_ref) => {
|
|
||||||
if ctx.lower_ty_only_param(type_ref) != Some(param_id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
|
|
||||||
let target_id = TypeOrConstParamId { parent: def, local_id };
|
|
||||||
if target_id != param_id {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match &**bound {
|
|
||||||
TypeBound::ForLifetime(_, path) | TypeBound::Path(path, _) => {
|
|
||||||
// Only lower the bound if the trait could possibly define the associated
|
|
||||||
// type we're looking for.
|
|
||||||
|
|
||||||
let assoc_name = match &assoc_name {
|
|
||||||
Some(it) => it,
|
|
||||||
None => return true,
|
|
||||||
};
|
|
||||||
let tr = match resolver.resolve_path_in_type_ns_fully(db.upcast(), path) {
|
|
||||||
Some(TypeNs::TraitId(tr)) => tr,
|
|
||||||
_ => return false,
|
|
||||||
};
|
|
||||||
|
|
||||||
all_super_traits(db.upcast(), tr).iter().any(|tr| {
|
|
||||||
db.trait_data(*tr).items.iter().any(|(name, item)| {
|
|
||||||
matches!(item, AssocItemId::TypeAliasId(_)) && name == assoc_name
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
TypeBound::Lifetime(_) | TypeBound::Error => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WherePredicate::Lifetime { .. } => false,
|
|
||||||
})
|
|
||||||
.flat_map(|pred| {
|
.flat_map(|pred| {
|
||||||
ctx.lower_where_predicate(pred, true).map(|p| make_binders(db, &generics, p))
|
ctx.lower_where_predicate(pred, true).map(|p| make_binders(db, &generics, p))
|
||||||
})
|
})
|
||||||
@ -1519,7 +1518,12 @@ pub(crate) fn trait_environment_query(
|
|||||||
|
|
||||||
let env = chalk_ir::Environment::new(Interner).add_clauses(Interner, clauses);
|
let env = chalk_ir::Environment::new(Interner).add_clauses(Interner, clauses);
|
||||||
|
|
||||||
Arc::new(TraitEnvironment { krate, block: None, traits_from_clauses: traits_in_scope, env })
|
Arc::new(TraitEnvironment {
|
||||||
|
krate,
|
||||||
|
block: None,
|
||||||
|
traits_from_clauses: traits_in_scope.into_boxed_slice(),
|
||||||
|
env,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the where clause(s) of an item with generics.
|
/// Resolve the where clause(s) of an item with generics.
|
||||||
|
@ -862,6 +862,62 @@ fn is_inherent_impl_coherent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks whether the impl satisfies the orphan rules.
|
||||||
|
///
|
||||||
|
/// Given `impl<P1..=Pn> Trait<T1..=Tn> for T0`, an `impl`` is valid only if at least one of the following is true:
|
||||||
|
/// - Trait is a local trait
|
||||||
|
/// - All of
|
||||||
|
/// - At least one of the types `T0..=Tn`` must be a local type. Let `Ti`` be the first such type.
|
||||||
|
/// - No uncovered type parameters `P1..=Pn` may appear in `T0..Ti`` (excluding `Ti`)
|
||||||
|
pub fn check_orphan_rules(db: &dyn HirDatabase, impl_: ImplId) -> bool {
|
||||||
|
let substs = TyBuilder::placeholder_subst(db, impl_);
|
||||||
|
let Some(impl_trait) = db.impl_trait(impl_) else {
|
||||||
|
// not a trait impl
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
let local_crate = impl_.lookup(db.upcast()).container.krate();
|
||||||
|
let is_local = |tgt_crate| tgt_crate == local_crate;
|
||||||
|
|
||||||
|
let trait_ref = impl_trait.substitute(Interner, &substs);
|
||||||
|
let trait_id = from_chalk_trait_id(trait_ref.trait_id);
|
||||||
|
if is_local(trait_id.module(db.upcast()).krate()) {
|
||||||
|
// trait to be implemented is local
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let unwrap_fundamental = |ty: Ty| match ty.kind(Interner) {
|
||||||
|
TyKind::Ref(_, _, referenced) => referenced.clone(),
|
||||||
|
&TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), ref subs) => {
|
||||||
|
let struct_data = db.struct_data(s);
|
||||||
|
if struct_data.flags.contains(StructFlags::IS_FUNDAMENTAL) {
|
||||||
|
let next = subs.type_parameters(Interner).next();
|
||||||
|
match next {
|
||||||
|
Some(ty) => ty,
|
||||||
|
None => ty,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => ty,
|
||||||
|
};
|
||||||
|
// - At least one of the types `T0..=Tn`` must be a local type. Let `Ti`` be the first such type.
|
||||||
|
let is_not_orphan = trait_ref.substitution.type_parameters(Interner).any(|ty| {
|
||||||
|
match unwrap_fundamental(ty).kind(Interner) {
|
||||||
|
&TyKind::Adt(AdtId(id), _) => is_local(id.module(db.upcast()).krate()),
|
||||||
|
TyKind::Error => true,
|
||||||
|
TyKind::Dyn(it) => it.principal().map_or(false, |trait_ref| {
|
||||||
|
is_local(from_chalk_trait_id(trait_ref.trait_id).module(db.upcast()).krate())
|
||||||
|
}),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// FIXME: param coverage
|
||||||
|
// - No uncovered type parameters `P1..=Pn` may appear in `T0..Ti`` (excluding `Ti`)
|
||||||
|
is_not_orphan
|
||||||
|
}
|
||||||
|
|
||||||
pub fn iterate_path_candidates(
|
pub fn iterate_path_candidates(
|
||||||
ty: &Canonical<Ty>,
|
ty: &Canonical<Ty>,
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
|
@ -684,8 +684,7 @@ fn infer_builtin_macros_line() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
!0..1 '0': i32
|
!0..4 '0u32': u32
|
||||||
!0..6 '0asu32': u32
|
|
||||||
63..87 '{ ...!(); }': ()
|
63..87 '{ ...!(); }': ()
|
||||||
73..74 'x': u32
|
73..74 'x': u32
|
||||||
"#]],
|
"#]],
|
||||||
@ -723,8 +722,7 @@ fn infer_builtin_macros_column() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
!0..1 '0': i32
|
!0..4 '0u32': u32
|
||||||
!0..6 '0asu32': u32
|
|
||||||
65..91 '{ ...!(); }': ()
|
65..91 '{ ...!(); }': ()
|
||||||
75..76 'x': u32
|
75..76 'x': u32
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -4439,42 +4439,42 @@ fn test(v: S<i32>) {
|
|||||||
fn associated_type_in_argument() {
|
fn associated_type_in_argument() {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
trait A {
|
trait A {
|
||||||
fn m(&self) -> i32;
|
fn m(&self) -> i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn x<T: B>(k: &<T as B>::Ty) {
|
fn x<T: B>(k: &<T as B>::Ty) {
|
||||||
k.m();
|
k.m();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct X;
|
struct X;
|
||||||
struct Y;
|
struct Y;
|
||||||
|
|
||||||
impl A for X {
|
impl A for X {
|
||||||
fn m(&self) -> i32 {
|
fn m(&self) -> i32 {
|
||||||
8
|
8
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl A for Y {
|
impl A for Y {
|
||||||
fn m(&self) -> i32 {
|
fn m(&self) -> i32 {
|
||||||
32
|
32
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trait B {
|
trait B {
|
||||||
type Ty: A;
|
type Ty: A;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl B for u16 {
|
impl B for u16 {
|
||||||
type Ty = X;
|
type Ty = X;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ttt() {
|
fn ttt() {
|
||||||
let inp = Y;
|
let inp = Y;
|
||||||
x::<u16>(&inp);
|
x::<u16>(&inp);
|
||||||
//^^^^ expected &X, got &Y
|
//^^^^ expected &X, got &Y
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ pub struct TraitEnvironment {
|
|||||||
pub krate: CrateId,
|
pub krate: CrateId,
|
||||||
pub block: Option<BlockId>,
|
pub block: Option<BlockId>,
|
||||||
// FIXME make this a BTreeMap
|
// FIXME make this a BTreeMap
|
||||||
pub(crate) traits_from_clauses: Vec<(Ty, TraitId)>,
|
pub(crate) traits_from_clauses: Box<[(Ty, TraitId)]>,
|
||||||
pub env: chalk_ir::Environment<Interner>,
|
pub env: chalk_ir::Environment<Interner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ impl TraitEnvironment {
|
|||||||
TraitEnvironment {
|
TraitEnvironment {
|
||||||
krate,
|
krate,
|
||||||
block: None,
|
block: None,
|
||||||
traits_from_clauses: Vec::new(),
|
traits_from_clauses: Box::default(),
|
||||||
env: chalk_ir::Environment::new(Interner),
|
env: chalk_ir::Environment::new(Interner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
arrayvec = "0.7.2"
|
arrayvec = "0.7.2"
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
once_cell = "1.17.1"
|
once_cell = "1.17.1"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//!
|
//!
|
||||||
//! This probably isn't the best way to do this -- ideally, diagnostics should
|
//! This probably isn't the best way to do this -- ideally, diagnostics should
|
||||||
//! be expressed in terms of hir types themselves.
|
//! be expressed in terms of hir types themselves.
|
||||||
pub use hir_ty::diagnostics::{CaseType, IncoherentImpl, IncorrectCase};
|
pub use hir_ty::diagnostics::{CaseType, IncorrectCase};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use cfg::{CfgExpr, CfgOptions};
|
use cfg::{CfgExpr, CfgOptions};
|
||||||
@ -53,6 +53,9 @@ diagnostics![
|
|||||||
PrivateAssocItem,
|
PrivateAssocItem,
|
||||||
PrivateField,
|
PrivateField,
|
||||||
ReplaceFilterMapNextWithFindMap,
|
ReplaceFilterMapNextWithFindMap,
|
||||||
|
TraitImplIncorrectSafety,
|
||||||
|
TraitImplMissingAssocItems,
|
||||||
|
TraitImplOrphan,
|
||||||
TypedHole,
|
TypedHole,
|
||||||
TypeMismatch,
|
TypeMismatch,
|
||||||
UndeclaredLabel,
|
UndeclaredLabel,
|
||||||
@ -280,3 +283,30 @@ pub struct MovedOutOfRef {
|
|||||||
pub ty: Type,
|
pub ty: Type,
|
||||||
pub span: InFile<SyntaxNodePtr>,
|
pub span: InFile<SyntaxNodePtr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct IncoherentImpl {
|
||||||
|
pub file_id: HirFileId,
|
||||||
|
pub impl_: AstPtr<ast::Impl>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct TraitImplOrphan {
|
||||||
|
pub file_id: HirFileId,
|
||||||
|
pub impl_: AstPtr<ast::Impl>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Split this off into the corresponding 4 rustc errors
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct TraitImplIncorrectSafety {
|
||||||
|
pub file_id: HirFileId,
|
||||||
|
pub impl_: AstPtr<ast::Impl>,
|
||||||
|
pub should_be_safe: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct TraitImplMissingAssocItems {
|
||||||
|
pub file_id: HirFileId,
|
||||||
|
pub impl_: AstPtr<ast::Impl>,
|
||||||
|
pub missing: Vec<(Name, AssocItem)>,
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! HirDisplay implementations for various hir types.
|
//! HirDisplay implementations for various hir types.
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
data::adt::VariantData,
|
data::adt::{StructKind, VariantData},
|
||||||
generics::{
|
generics::{
|
||||||
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
|
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
|
||||||
},
|
},
|
||||||
@ -163,7 +163,40 @@ impl HirDisplay for Struct {
|
|||||||
write!(f, "{}", self.name(f.db).display(f.db.upcast()))?;
|
write!(f, "{}", self.name(f.db).display(f.db.upcast()))?;
|
||||||
let def_id = GenericDefId::AdtId(AdtId::StructId(self.id));
|
let def_id = GenericDefId::AdtId(AdtId::StructId(self.id));
|
||||||
write_generic_params(def_id, f)?;
|
write_generic_params(def_id, f)?;
|
||||||
|
|
||||||
|
let variant_data = self.variant_data(f.db);
|
||||||
|
if let StructKind::Tuple = variant_data.kind() {
|
||||||
|
f.write_char('(')?;
|
||||||
|
let mut it = variant_data.fields().iter().peekable();
|
||||||
|
|
||||||
|
while let Some((id, _)) = it.next() {
|
||||||
|
let field = Field { parent: (*self).into(), id };
|
||||||
|
field.ty(f.db).hir_fmt(f)?;
|
||||||
|
if it.peek().is_some() {
|
||||||
|
f.write_str(", ")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f.write_str(");")?;
|
||||||
|
}
|
||||||
|
|
||||||
write_where_clause(def_id, f)?;
|
write_where_clause(def_id, f)?;
|
||||||
|
|
||||||
|
if let StructKind::Record = variant_data.kind() {
|
||||||
|
let fields = self.fields(f.db);
|
||||||
|
if fields.is_empty() {
|
||||||
|
f.write_str(" {}")?;
|
||||||
|
} else {
|
||||||
|
f.write_str(" {\n")?;
|
||||||
|
for field in self.fields(f.db) {
|
||||||
|
f.write_str(" ")?;
|
||||||
|
field.hir_fmt(f)?;
|
||||||
|
f.write_str(",\n")?;
|
||||||
|
}
|
||||||
|
f.write_str("}")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,6 +209,18 @@ impl HirDisplay for Enum {
|
|||||||
let def_id = GenericDefId::AdtId(AdtId::EnumId(self.id));
|
let def_id = GenericDefId::AdtId(AdtId::EnumId(self.id));
|
||||||
write_generic_params(def_id, f)?;
|
write_generic_params(def_id, f)?;
|
||||||
write_where_clause(def_id, f)?;
|
write_where_clause(def_id, f)?;
|
||||||
|
|
||||||
|
let variants = self.variants(f.db);
|
||||||
|
if !variants.is_empty() {
|
||||||
|
f.write_str(" {\n")?;
|
||||||
|
for variant in variants {
|
||||||
|
f.write_str(" ")?;
|
||||||
|
variant.hir_fmt(f)?;
|
||||||
|
f.write_str(",\n")?;
|
||||||
|
}
|
||||||
|
f.write_str("}")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,6 +233,18 @@ impl HirDisplay for Union {
|
|||||||
let def_id = GenericDefId::AdtId(AdtId::UnionId(self.id));
|
let def_id = GenericDefId::AdtId(AdtId::UnionId(self.id));
|
||||||
write_generic_params(def_id, f)?;
|
write_generic_params(def_id, f)?;
|
||||||
write_where_clause(def_id, f)?;
|
write_where_clause(def_id, f)?;
|
||||||
|
|
||||||
|
let fields = self.fields(f.db);
|
||||||
|
if !fields.is_empty() {
|
||||||
|
f.write_str(" {\n")?;
|
||||||
|
for field in self.fields(f.db) {
|
||||||
|
f.write_str(" ")?;
|
||||||
|
field.hir_fmt(f)?;
|
||||||
|
f.write_str(",\n")?;
|
||||||
|
}
|
||||||
|
f.write_str("}")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -559,7 +616,7 @@ impl HirDisplay for TypeAlias {
|
|||||||
write_where_clause(def_id, f)?;
|
write_where_clause(def_id, f)?;
|
||||||
if !data.bounds.is_empty() {
|
if !data.bounds.is_empty() {
|
||||||
f.write_str(": ")?;
|
f.write_str(": ")?;
|
||||||
f.write_joined(&data.bounds, " + ")?;
|
f.write_joined(data.bounds.iter(), " + ")?;
|
||||||
}
|
}
|
||||||
if let Some(ty) = &data.type_ref {
|
if let Some(ty) = &data.type_ref {
|
||||||
f.write_str(" = ")?;
|
f.write_str(" = ")?;
|
||||||
|
@ -34,7 +34,7 @@ pub mod symbols;
|
|||||||
|
|
||||||
mod display;
|
mod display;
|
||||||
|
|
||||||
use std::{iter, ops::ControlFlow};
|
use std::{iter, mem::discriminant, ops::ControlFlow};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
|
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
|
||||||
@ -54,14 +54,14 @@ use hir_def::{
|
|||||||
resolver::{HasResolver, Resolver},
|
resolver::{HasResolver, Resolver},
|
||||||
src::HasSource as _,
|
src::HasSource as _,
|
||||||
AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId,
|
AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId,
|
||||||
EnumId, EnumVariantId, ExternCrateId, FunctionId, GenericDefId, HasModule, ImplId,
|
EnumId, EnumVariantId, ExternCrateId, FunctionId, GenericDefId, GenericParamId, HasModule,
|
||||||
InTypeConstId, ItemContainerId, LifetimeParamId, LocalEnumVariantId, LocalFieldId, Lookup,
|
ImplId, InTypeConstId, ItemContainerId, LifetimeParamId, LocalEnumVariantId, LocalFieldId,
|
||||||
MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId,
|
||||||
TypeOrConstParamId, TypeParamId, UnionId,
|
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
|
||||||
};
|
};
|
||||||
use hir_expand::{name::name, MacroCallKind};
|
use hir_expand::{name::name, MacroCallKind};
|
||||||
use hir_ty::{
|
use hir_ty::{
|
||||||
all_super_traits, autoderef,
|
all_super_traits, autoderef, check_orphan_rules,
|
||||||
consteval::{try_const_usize, unknown_const_as_generic, ConstEvalError, ConstExt},
|
consteval::{try_const_usize, unknown_const_as_generic, ConstEvalError, ConstExt},
|
||||||
diagnostics::BodyValidationDiagnostic,
|
diagnostics::BodyValidationDiagnostic,
|
||||||
known_const_to_ast,
|
known_const_to_ast,
|
||||||
@ -90,17 +90,7 @@ use crate::db::{DefDatabase, HirDatabase};
|
|||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
attrs::{resolve_doc_path_on, HasAttrs},
|
attrs::{resolve_doc_path_on, HasAttrs},
|
||||||
diagnostics::{
|
diagnostics::*,
|
||||||
AnyDiagnostic, BreakOutsideOfLoop, CaseType, ExpectedFunction, InactiveCode,
|
|
||||||
IncoherentImpl, IncorrectCase, InvalidDeriveTarget, MacroDefError, MacroError,
|
|
||||||
MacroExpansionParseError, MalformedDerive, MismatchedArgCount,
|
|
||||||
MismatchedTupleStructPatArgCount, MissingFields, MissingMatchArms, MissingUnsafe,
|
|
||||||
MovedOutOfRef, NeedMut, NoSuchField, PrivateAssocItem, PrivateField,
|
|
||||||
ReplaceFilterMapNextWithFindMap, TypeMismatch, TypedHole, UndeclaredLabel,
|
|
||||||
UnimplementedBuiltinMacro, UnreachableLabel, UnresolvedExternCrate, UnresolvedField,
|
|
||||||
UnresolvedImport, UnresolvedMacroCall, UnresolvedMethodCall, UnresolvedModule,
|
|
||||||
UnresolvedProcMacro, UnusedMut, UnusedVariable,
|
|
||||||
},
|
|
||||||
has_source::HasSource,
|
has_source::HasSource,
|
||||||
semantics::{PathResolution, Semantics, SemanticsScope, TypeInfo, VisibleTraits},
|
semantics::{PathResolution, Semantics, SemanticsScope, TypeInfo, VisibleTraits},
|
||||||
};
|
};
|
||||||
@ -604,6 +594,7 @@ impl Module {
|
|||||||
|
|
||||||
let inherent_impls = db.inherent_impls_in_crate(self.id.krate());
|
let inherent_impls = db.inherent_impls_in_crate(self.id.krate());
|
||||||
|
|
||||||
|
let mut impl_assoc_items_scratch = vec![];
|
||||||
for impl_def in self.impl_defs(db) {
|
for impl_def in self.impl_defs(db) {
|
||||||
let loc = impl_def.id.lookup(db.upcast());
|
let loc = impl_def.id.lookup(db.upcast());
|
||||||
let tree = loc.id.item_tree(db.upcast());
|
let tree = loc.id.item_tree(db.upcast());
|
||||||
@ -614,19 +605,109 @@ impl Module {
|
|||||||
// FIXME: Once we diagnose the inputs to builtin derives, we should at least extract those diagnostics somehow
|
// FIXME: Once we diagnose the inputs to builtin derives, we should at least extract those diagnostics somehow
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let ast_id_map = db.ast_id_map(file_id);
|
||||||
|
|
||||||
for diag in db.impl_data_with_diagnostics(impl_def.id).1.iter() {
|
for diag in db.impl_data_with_diagnostics(impl_def.id).1.iter() {
|
||||||
emit_def_diagnostic(db, acc, diag);
|
emit_def_diagnostic(db, acc, diag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if inherent_impls.invalid_impls().contains(&impl_def.id) {
|
if inherent_impls.invalid_impls().contains(&impl_def.id) {
|
||||||
let ast_id_map = db.ast_id_map(file_id);
|
|
||||||
|
|
||||||
acc.push(IncoherentImpl { impl_: ast_id_map.get(node.ast_id()), file_id }.into())
|
acc.push(IncoherentImpl { impl_: ast_id_map.get(node.ast_id()), file_id }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
for item in impl_def.items(db) {
|
if !impl_def.check_orphan_rules(db) {
|
||||||
let def: DefWithBody = match item {
|
acc.push(TraitImplOrphan { impl_: ast_id_map.get(node.ast_id()), file_id }.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
let trait_ = impl_def.trait_(db);
|
||||||
|
let trait_is_unsafe = trait_.map_or(false, |t| t.is_unsafe(db));
|
||||||
|
let impl_is_negative = impl_def.is_negative(db);
|
||||||
|
let impl_is_unsafe = impl_def.is_unsafe(db);
|
||||||
|
|
||||||
|
let drop_maybe_dangle = (|| {
|
||||||
|
// FIXME: This can be simplified a lot by exposing hir-ty's utils.rs::Generics helper
|
||||||
|
let trait_ = trait_?;
|
||||||
|
let drop_trait = db.lang_item(self.krate().into(), LangItem::Drop)?.as_trait()?;
|
||||||
|
if drop_trait != trait_.into() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let parent = impl_def.id.into();
|
||||||
|
let generic_params = db.generic_params(parent);
|
||||||
|
let lifetime_params = generic_params.lifetimes.iter().map(|(local_id, _)| {
|
||||||
|
GenericParamId::LifetimeParamId(LifetimeParamId { parent, local_id })
|
||||||
|
});
|
||||||
|
let type_params = generic_params
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, it)| it.type_param().is_some())
|
||||||
|
.map(|(local_id, _)| {
|
||||||
|
GenericParamId::TypeParamId(TypeParamId::from_unchecked(
|
||||||
|
TypeOrConstParamId { parent, local_id },
|
||||||
|
))
|
||||||
|
});
|
||||||
|
let res = type_params
|
||||||
|
.chain(lifetime_params)
|
||||||
|
.any(|p| db.attrs(AttrDefId::GenericParamId(p)).by_key("may_dangle").exists());
|
||||||
|
Some(res)
|
||||||
|
})()
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
match (impl_is_unsafe, trait_is_unsafe, impl_is_negative, drop_maybe_dangle) {
|
||||||
|
// unsafe negative impl
|
||||||
|
(true, _, true, _) |
|
||||||
|
// unsafe impl for safe trait
|
||||||
|
(true, false, _, false) => acc.push(TraitImplIncorrectSafety { impl_: ast_id_map.get(node.ast_id()), file_id, should_be_safe: true }.into()),
|
||||||
|
// safe impl for unsafe trait
|
||||||
|
(false, true, false, _) |
|
||||||
|
// safe impl of dangling drop
|
||||||
|
(false, false, _, true) => acc.push(TraitImplIncorrectSafety { impl_: ast_id_map.get(node.ast_id()), file_id, should_be_safe: false }.into()),
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(trait_) = trait_ {
|
||||||
|
let items = &db.trait_data(trait_.into()).items;
|
||||||
|
let required_items = items.iter().filter(|&(_, assoc)| match *assoc {
|
||||||
|
AssocItemId::FunctionId(it) => !db.function_data(it).has_body(),
|
||||||
|
AssocItemId::ConstId(_) => true,
|
||||||
|
AssocItemId::TypeAliasId(it) => db.type_alias_data(it).type_ref.is_none(),
|
||||||
|
});
|
||||||
|
impl_assoc_items_scratch.extend(db.impl_data(impl_def.id).items.iter().map(
|
||||||
|
|&item| {
|
||||||
|
(
|
||||||
|
item,
|
||||||
|
match item {
|
||||||
|
AssocItemId::FunctionId(it) => db.function_data(it).name.clone(),
|
||||||
|
AssocItemId::ConstId(it) => {
|
||||||
|
db.const_data(it).name.as_ref().unwrap().clone()
|
||||||
|
}
|
||||||
|
AssocItemId::TypeAliasId(it) => db.type_alias_data(it).name.clone(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
let missing: Vec<_> = required_items
|
||||||
|
.filter(|(name, id)| {
|
||||||
|
!impl_assoc_items_scratch.iter().any(|(impl_item, impl_name)| {
|
||||||
|
discriminant(impl_item) == discriminant(id) && impl_name == name
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|(name, item)| (name.clone(), AssocItem::from(*item)))
|
||||||
|
.collect();
|
||||||
|
if !missing.is_empty() {
|
||||||
|
acc.push(
|
||||||
|
TraitImplMissingAssocItems {
|
||||||
|
impl_: ast_id_map.get(node.ast_id()),
|
||||||
|
file_id,
|
||||||
|
missing,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
impl_assoc_items_scratch.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
for &item in &db.impl_data(impl_def.id).items {
|
||||||
|
let def: DefWithBody = match AssocItem::from(item) {
|
||||||
AssocItem::Function(it) => it.into(),
|
AssocItem::Function(it) => it.into(),
|
||||||
AssocItem::Const(it) => it.into(),
|
AssocItem::Const(it) => it.into(),
|
||||||
AssocItem::TypeAlias(_) => continue,
|
AssocItem::TypeAlias(_) => continue,
|
||||||
@ -665,8 +746,15 @@ impl Module {
|
|||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item: impl Into<ItemInNs>,
|
item: impl Into<ItemInNs>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
hir_def::find_path::find_path(db, item.into().into(), self.into(), prefer_no_std)
|
hir_def::find_path::find_path(
|
||||||
|
db,
|
||||||
|
item.into().into(),
|
||||||
|
self.into(),
|
||||||
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a path that can be used to refer to the given item from within
|
/// Finds a path that can be used to refer to the given item from within
|
||||||
@ -677,6 +765,7 @@ impl Module {
|
|||||||
item: impl Into<ItemInNs>,
|
item: impl Into<ItemInNs>,
|
||||||
prefix_kind: PrefixKind,
|
prefix_kind: PrefixKind,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
hir_def::find_path::find_path_prefixed(
|
hir_def::find_path::find_path_prefixed(
|
||||||
db,
|
db,
|
||||||
@ -684,6 +773,7 @@ impl Module {
|
|||||||
self.into(),
|
self.into(),
|
||||||
prefix_kind,
|
prefix_kind,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1447,9 +1537,7 @@ impl DefWithBody {
|
|||||||
let (body, source_map) = db.body_with_source_map(self.into());
|
let (body, source_map) = db.body_with_source_map(self.into());
|
||||||
|
|
||||||
for (_, def_map) in body.blocks(db.upcast()) {
|
for (_, def_map) in body.blocks(db.upcast()) {
|
||||||
for diag in def_map.diagnostics() {
|
Module { id: def_map.module_id(DefMap::ROOT) }.diagnostics(db, acc);
|
||||||
emit_def_diagnostic(db, acc, diag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for diag in source_map.diagnostics() {
|
for diag in source_map.diagnostics() {
|
||||||
@ -3390,6 +3478,10 @@ impl Impl {
|
|||||||
db.impl_data(self.id).is_negative
|
db.impl_data(self.id).is_negative
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
|
||||||
|
db.impl_data(self.id).is_unsafe
|
||||||
|
}
|
||||||
|
|
||||||
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||||
self.id.lookup(db.upcast()).container.into()
|
self.id.lookup(db.upcast()).container.into()
|
||||||
}
|
}
|
||||||
@ -3398,6 +3490,10 @@ impl Impl {
|
|||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
src.file_id.as_builtin_derive_attr_node(db.upcast())
|
src.file_id.as_builtin_derive_attr_node(db.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_orphan_rules(self, db: &dyn HirDatabase) -> bool {
|
||||||
|
check_orphan_rules(db, self.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
|
@ -14,8 +14,8 @@ doctest = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
|
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
|
@ -14,5 +14,6 @@ pub struct AssistConfig {
|
|||||||
pub allowed: Option<Vec<AssistKind>>,
|
pub allowed: Option<Vec<AssistKind>>,
|
||||||
pub insert_use: InsertUseConfig,
|
pub insert_use: InsertUseConfig,
|
||||||
pub prefer_no_std: bool,
|
pub prefer_no_std: bool,
|
||||||
|
pub prefer_prelude: bool,
|
||||||
pub assist_emit_must_use: bool,
|
pub assist_emit_must_use: bool,
|
||||||
}
|
}
|
||||||
|
@ -2245,6 +2245,37 @@ impl b::LocalTrait for B {
|
|||||||
fn no_skip_default_2() -> Option<()> {
|
fn no_skip_default_2() -> Option<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn doc_hidden_nondefault_member() {
|
||||||
|
check_assist(
|
||||||
|
add_missing_impl_members,
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:b new_source_root:local
|
||||||
|
trait LocalTrait {
|
||||||
|
#[doc(hidden)]
|
||||||
|
fn no_skip_non_default() -> Option<()>;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
fn skip_default() -> Option<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- /main.rs crate:a deps:b
|
||||||
|
struct B;
|
||||||
|
impl b::Loc$0alTrait for B {}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
struct B;
|
||||||
|
impl b::LocalTrait for B {
|
||||||
|
fn no_skip_non_default() -> Option<()> {
|
||||||
|
${0:todo!()}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
|
@ -88,7 +88,13 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|variant| {
|
.filter_map(|variant| {
|
||||||
Some((
|
Some((
|
||||||
build_pat(ctx.db(), module, variant, ctx.config.prefer_no_std)?,
|
build_pat(
|
||||||
|
ctx.db(),
|
||||||
|
module,
|
||||||
|
variant,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)?,
|
||||||
variant.should_be_hidden(ctx.db(), module.krate()),
|
variant.should_be_hidden(ctx.db(), module.krate()),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@ -140,7 +146,13 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
||||||
let patterns = variants.into_iter().filter_map(|variant| {
|
let patterns = variants.into_iter().filter_map(|variant| {
|
||||||
build_pat(ctx.db(), module, variant, ctx.config.prefer_no_std)
|
build_pat(
|
||||||
|
ctx.db(),
|
||||||
|
module,
|
||||||
|
variant,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
(ast::Pat::from(make::tuple_pat(patterns)), is_hidden)
|
(ast::Pat::from(make::tuple_pat(patterns)), is_hidden)
|
||||||
@ -173,7 +185,13 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
||||||
let patterns = variants.into_iter().filter_map(|variant| {
|
let patterns = variants.into_iter().filter_map(|variant| {
|
||||||
build_pat(ctx.db(), module, variant.clone(), ctx.config.prefer_no_std)
|
build_pat(
|
||||||
|
ctx.db(),
|
||||||
|
module,
|
||||||
|
variant.clone(),
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
(ast::Pat::from(make::slice_pat(patterns)), is_hidden)
|
(ast::Pat::from(make::slice_pat(patterns)), is_hidden)
|
||||||
})
|
})
|
||||||
@ -440,11 +458,16 @@ fn build_pat(
|
|||||||
module: hir::Module,
|
module: hir::Module,
|
||||||
var: ExtendedVariant,
|
var: ExtendedVariant,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ast::Pat> {
|
) -> Option<ast::Pat> {
|
||||||
match var {
|
match var {
|
||||||
ExtendedVariant::Variant(var) => {
|
ExtendedVariant::Variant(var) => {
|
||||||
let path =
|
let path = mod_path_to_ast(&module.find_use_path(
|
||||||
mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var), prefer_no_std)?);
|
db,
|
||||||
|
ModuleDef::from(var),
|
||||||
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
|
)?);
|
||||||
|
|
||||||
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
|
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
|
||||||
Some(match var.source(db)?.value.kind() {
|
Some(match var.source(db)?.value.kind() {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
use either::Either;
|
||||||
use ide_db::defs::{Definition, NameRefClass};
|
use ide_db::defs::{Definition, NameRefClass};
|
||||||
use itertools::Itertools;
|
use syntax::{
|
||||||
use syntax::{ast, AstNode, SyntaxKind, T};
|
ast::{self, make, HasArgList},
|
||||||
|
ted, AstNode,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_context::{AssistContext, Assists},
|
assist_context::{AssistContext, Assists},
|
||||||
@ -25,21 +28,45 @@ use crate::{
|
|||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
let ident = ctx.find_token_syntax_at_offset(SyntaxKind::IDENT).or_else(|| {
|
let turbofish_target =
|
||||||
let arg_list = ctx.find_node_at_offset::<ast::ArgList>()?;
|
ctx.find_node_at_offset::<ast::PathSegment>().map(Either::Left).or_else(|| {
|
||||||
if arg_list.args().next().is_some() {
|
let callable_expr = ctx.find_node_at_offset::<ast::CallableExpr>()?;
|
||||||
return None;
|
|
||||||
}
|
if callable_expr.arg_list()?.args().next().is_some() {
|
||||||
cov_mark::hit!(add_turbo_fish_after_call);
|
return None;
|
||||||
cov_mark::hit!(add_type_ascription_after_call);
|
}
|
||||||
arg_list.l_paren_token()?.prev_token().filter(|it| it.kind() == SyntaxKind::IDENT)
|
|
||||||
})?;
|
cov_mark::hit!(add_turbo_fish_after_call);
|
||||||
let next_token = ident.next_token()?;
|
cov_mark::hit!(add_type_ascription_after_call);
|
||||||
if next_token.kind() == T![::] {
|
|
||||||
|
match callable_expr {
|
||||||
|
ast::CallableExpr::Call(it) => {
|
||||||
|
let ast::Expr::PathExpr(path) = it.expr()? else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(Either::Left(path.path()?.segment()?))
|
||||||
|
}
|
||||||
|
ast::CallableExpr::MethodCall(it) => Some(Either::Right(it)),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let already_has_turbofish = match &turbofish_target {
|
||||||
|
Either::Left(path_segment) => path_segment.generic_arg_list().is_some(),
|
||||||
|
Either::Right(method_call) => method_call.generic_arg_list().is_some(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if already_has_turbofish {
|
||||||
cov_mark::hit!(add_turbo_fish_one_fish_is_enough);
|
cov_mark::hit!(add_turbo_fish_one_fish_is_enough);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let name_ref = ast::NameRef::cast(ident.parent()?)?;
|
|
||||||
|
let name_ref = match &turbofish_target {
|
||||||
|
Either::Left(path_segment) => path_segment.name_ref()?,
|
||||||
|
Either::Right(method_call) => method_call.name_ref()?,
|
||||||
|
};
|
||||||
|
let ident = name_ref.ident_token()?;
|
||||||
|
|
||||||
let def = match NameRefClass::classify(&ctx.sema, &name_ref)? {
|
let def = match NameRefClass::classify(&ctx.sema, &name_ref)? {
|
||||||
NameRefClass::Definition(def) => def,
|
NameRefClass::Definition(def) => def,
|
||||||
NameRefClass::FieldShorthand { .. } | NameRefClass::ExternCrateShorthand { .. } => {
|
NameRefClass::FieldShorthand { .. } | NameRefClass::ExternCrateShorthand { .. } => {
|
||||||
@ -58,20 +85,27 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
|
|||||||
|
|
||||||
if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
|
if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
|
||||||
if let_stmt.colon_token().is_none() {
|
if let_stmt.colon_token().is_none() {
|
||||||
let type_pos = let_stmt.pat()?.syntax().last_token()?.text_range().end();
|
if let_stmt.pat().is_none() {
|
||||||
let semi_pos = let_stmt.syntax().last_token()?.text_range().end();
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("add_type_ascription", AssistKind::RefactorRewrite),
|
AssistId("add_type_ascription", AssistKind::RefactorRewrite),
|
||||||
"Add `: _` before assignment operator",
|
"Add `: _` before assignment operator",
|
||||||
ident.text_range(),
|
ident.text_range(),
|
||||||
|builder| {
|
|edit| {
|
||||||
|
let let_stmt = edit.make_mut(let_stmt);
|
||||||
|
|
||||||
if let_stmt.semicolon_token().is_none() {
|
if let_stmt.semicolon_token().is_none() {
|
||||||
builder.insert(semi_pos, ";");
|
ted::append_child(let_stmt.syntax(), make::tokens::semicolon());
|
||||||
}
|
}
|
||||||
match ctx.config.snippet_cap {
|
|
||||||
Some(cap) => builder.insert_snippet(cap, type_pos, ": ${0:_}"),
|
let placeholder_ty = make::ty_placeholder().clone_for_update();
|
||||||
None => builder.insert(type_pos, ": _"),
|
|
||||||
|
let_stmt.set_ty(Some(placeholder_ty.clone()));
|
||||||
|
|
||||||
|
if let Some(cap) = ctx.config.snippet_cap {
|
||||||
|
edit.add_placeholder_snippet(cap, placeholder_ty);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)?
|
)?
|
||||||
@ -91,38 +125,46 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
|
|||||||
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
|
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
|
||||||
"Add `::<>`",
|
"Add `::<>`",
|
||||||
ident.text_range(),
|
ident.text_range(),
|
||||||
|builder| {
|
|edit| {
|
||||||
builder.trigger_signature_help();
|
edit.trigger_signature_help();
|
||||||
match ctx.config.snippet_cap {
|
|
||||||
Some(cap) => {
|
let new_arg_list = match turbofish_target {
|
||||||
let fish_head = get_snippet_fish_head(number_of_arguments);
|
Either::Left(path_segment) => {
|
||||||
let snip = format!("::<{fish_head}>");
|
edit.make_mut(path_segment).get_or_create_generic_arg_list()
|
||||||
builder.insert_snippet(cap, ident.text_range().end(), snip)
|
|
||||||
}
|
}
|
||||||
None => {
|
Either::Right(method_call) => {
|
||||||
let fish_head = std::iter::repeat("_").take(number_of_arguments).format(", ");
|
edit.make_mut(method_call).get_or_create_generic_arg_list()
|
||||||
let snip = format!("::<{fish_head}>");
|
}
|
||||||
builder.insert(ident.text_range().end(), snip);
|
};
|
||||||
|
|
||||||
|
let fish_head = get_fish_head(number_of_arguments).clone_for_update();
|
||||||
|
|
||||||
|
// Note: we need to replace the `new_arg_list` instead of being able to use something like
|
||||||
|
// `GenericArgList::add_generic_arg` as `PathSegment::get_or_create_generic_arg_list`
|
||||||
|
// always creates a non-turbofish form generic arg list.
|
||||||
|
ted::replace(new_arg_list.syntax(), fish_head.syntax());
|
||||||
|
|
||||||
|
if let Some(cap) = ctx.config.snippet_cap {
|
||||||
|
for arg in fish_head.generic_args() {
|
||||||
|
edit.add_placeholder_snippet(cap, arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will create a snippet string with tabstops marked
|
/// This will create a turbofish generic arg list corresponding to the number of arguments
|
||||||
fn get_snippet_fish_head(number_of_arguments: usize) -> String {
|
fn get_fish_head(number_of_arguments: usize) -> ast::GenericArgList {
|
||||||
let mut fish_head = (1..number_of_arguments)
|
let args = (0..number_of_arguments).map(|_| make::type_arg(make::ty_placeholder()).into());
|
||||||
.format_with("", |i, f| f(&format_args!("${{{i}:_}}, ")))
|
make::turbofish_generic_arg_list(args)
|
||||||
.to_string();
|
|
||||||
|
|
||||||
// tabstop 0 is a special case and always the last one
|
|
||||||
fish_head.push_str("${0:_}");
|
|
||||||
fish_head
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_assist, check_assist_by_label, check_assist_not_applicable};
|
use crate::tests::{
|
||||||
|
check_assist, check_assist_by_label, check_assist_not_applicable,
|
||||||
|
check_assist_not_applicable_by_label,
|
||||||
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -363,6 +405,20 @@ fn main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_type_ascription_missing_pattern() {
|
||||||
|
check_assist_not_applicable_by_label(
|
||||||
|
add_turbo_fish,
|
||||||
|
r#"
|
||||||
|
fn make<T>() -> T {}
|
||||||
|
fn main() {
|
||||||
|
let = make$0()
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
"Add `: _` before assignment operator",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_turbo_fish_function_lifetime_parameter() {
|
fn add_turbo_fish_function_lifetime_parameter() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
@ -93,6 +93,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
|
|||||||
&ctx.sema,
|
&ctx.sema,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
);
|
);
|
||||||
if proposed_imports.is_empty() {
|
if proposed_imports.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -348,6 +348,7 @@ fn augment_references_with_imports(
|
|||||||
ModuleDef::Module(*target_module),
|
ModuleDef::Module(*target_module),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)
|
)
|
||||||
.map(|mod_path| {
|
.map(|mod_path| {
|
||||||
make::path_concat(mod_path_to_ast(&mod_path), make::path_from_text("Bool"))
|
make::path_concat(mod_path_to_ast(&mod_path), make::path_from_text("Bool"))
|
||||||
|
@ -50,7 +50,12 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
|
|||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod_path_to_ast(&module.find_use_path(ctx.db(), src_type_def, ctx.config.prefer_no_std)?)
|
mod_path_to_ast(&module.find_use_path(
|
||||||
|
ctx.db(),
|
||||||
|
src_type_def,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)?)
|
||||||
};
|
};
|
||||||
|
|
||||||
let dest_type = match &ast_trait {
|
let dest_type = match &ast_trait {
|
||||||
|
@ -205,6 +205,7 @@ fn augment_references_with_imports(
|
|||||||
ModuleDef::Module(*target_module),
|
ModuleDef::Module(*target_module),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)
|
)
|
||||||
.map(|mod_path| {
|
.map(|mod_path| {
|
||||||
make::path_concat(
|
make::path_concat(
|
||||||
|
@ -3,10 +3,12 @@ use ide_db::{
|
|||||||
defs::Definition,
|
defs::Definition,
|
||||||
search::{FileReference, SearchScope, UsageSearchResult},
|
search::{FileReference, SearchScope, UsageSearchResult},
|
||||||
};
|
};
|
||||||
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, FieldExpr, HasName, IdentPat, MethodCallExpr},
|
ast::{self, make, AstNode, FieldExpr, HasName, IdentPat, MethodCallExpr},
|
||||||
TextRange,
|
ted, T,
|
||||||
};
|
};
|
||||||
|
use text_edit::TextRange;
|
||||||
|
|
||||||
use crate::assist_context::{AssistContext, Assists, SourceChangeBuilder};
|
use crate::assist_context::{AssistContext, Assists, SourceChangeBuilder};
|
||||||
|
|
||||||
@ -61,27 +63,36 @@ pub(crate) fn destructure_tuple_binding_impl(
|
|||||||
acc.add(
|
acc.add(
|
||||||
AssistId("destructure_tuple_binding_in_sub_pattern", AssistKind::RefactorRewrite),
|
AssistId("destructure_tuple_binding_in_sub_pattern", AssistKind::RefactorRewrite),
|
||||||
"Destructure tuple in sub-pattern",
|
"Destructure tuple in sub-pattern",
|
||||||
data.range,
|
data.ident_pat.syntax().text_range(),
|
||||||
|builder| {
|
|edit| destructure_tuple_edit_impl(ctx, edit, &data, true),
|
||||||
edit_tuple_assignment(ctx, builder, &data, true);
|
|
||||||
edit_tuple_usages(&data, builder, ctx, true);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("destructure_tuple_binding", AssistKind::RefactorRewrite),
|
AssistId("destructure_tuple_binding", AssistKind::RefactorRewrite),
|
||||||
if with_sub_pattern { "Destructure tuple in place" } else { "Destructure tuple" },
|
if with_sub_pattern { "Destructure tuple in place" } else { "Destructure tuple" },
|
||||||
data.range,
|
data.ident_pat.syntax().text_range(),
|
||||||
|builder| {
|
|edit| destructure_tuple_edit_impl(ctx, edit, &data, false),
|
||||||
edit_tuple_assignment(ctx, builder, &data, false);
|
|
||||||
edit_tuple_usages(&data, builder, ctx, false);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn destructure_tuple_edit_impl(
|
||||||
|
ctx: &AssistContext<'_>,
|
||||||
|
edit: &mut SourceChangeBuilder,
|
||||||
|
data: &TupleData,
|
||||||
|
in_sub_pattern: bool,
|
||||||
|
) {
|
||||||
|
let assignment_edit = edit_tuple_assignment(ctx, edit, &data, in_sub_pattern);
|
||||||
|
let current_file_usages_edit = edit_tuple_usages(&data, edit, ctx, in_sub_pattern);
|
||||||
|
|
||||||
|
assignment_edit.apply();
|
||||||
|
if let Some(usages_edit) = current_file_usages_edit {
|
||||||
|
usages_edit.into_iter().for_each(|usage_edit| usage_edit.apply(edit))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option<TupleData> {
|
fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option<TupleData> {
|
||||||
if ident_pat.at_token().is_some() {
|
if ident_pat.at_token().is_some() {
|
||||||
// Cannot destructure pattern with sub-pattern:
|
// Cannot destructure pattern with sub-pattern:
|
||||||
@ -109,7 +120,6 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option<TupleDat
|
|||||||
}
|
}
|
||||||
|
|
||||||
let name = ident_pat.name()?.to_string();
|
let name = ident_pat.name()?.to_string();
|
||||||
let range = ident_pat.syntax().text_range();
|
|
||||||
|
|
||||||
let usages = ctx.sema.to_def(&ident_pat).map(|def| {
|
let usages = ctx.sema.to_def(&ident_pat).map(|def| {
|
||||||
Definition::Local(def)
|
Definition::Local(def)
|
||||||
@ -122,7 +132,7 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option<TupleDat
|
|||||||
.map(|i| generate_name(ctx, i, &name, &ident_pat, &usages))
|
.map(|i| generate_name(ctx, i, &name, &ident_pat, &usages))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Some(TupleData { ident_pat, range, ref_type, field_names, usages })
|
Some(TupleData { ident_pat, ref_type, field_names, usages })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_name(
|
fn generate_name(
|
||||||
@ -142,72 +152,100 @@ enum RefType {
|
|||||||
}
|
}
|
||||||
struct TupleData {
|
struct TupleData {
|
||||||
ident_pat: IdentPat,
|
ident_pat: IdentPat,
|
||||||
// name: String,
|
|
||||||
range: TextRange,
|
|
||||||
ref_type: Option<RefType>,
|
ref_type: Option<RefType>,
|
||||||
field_names: Vec<String>,
|
field_names: Vec<String>,
|
||||||
// field_types: Vec<Type>,
|
|
||||||
usages: Option<UsageSearchResult>,
|
usages: Option<UsageSearchResult>,
|
||||||
}
|
}
|
||||||
fn edit_tuple_assignment(
|
fn edit_tuple_assignment(
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
builder: &mut SourceChangeBuilder,
|
edit: &mut SourceChangeBuilder,
|
||||||
data: &TupleData,
|
data: &TupleData,
|
||||||
in_sub_pattern: bool,
|
in_sub_pattern: bool,
|
||||||
) {
|
) -> AssignmentEdit {
|
||||||
|
let ident_pat = edit.make_mut(data.ident_pat.clone());
|
||||||
|
|
||||||
let tuple_pat = {
|
let tuple_pat = {
|
||||||
let original = &data.ident_pat;
|
let original = &data.ident_pat;
|
||||||
let is_ref = original.ref_token().is_some();
|
let is_ref = original.ref_token().is_some();
|
||||||
let is_mut = original.mut_token().is_some();
|
let is_mut = original.mut_token().is_some();
|
||||||
let fields = data.field_names.iter().map(|name| {
|
let fields = data
|
||||||
ast::Pat::from(ast::make::ident_pat(is_ref, is_mut, ast::make::name(name)))
|
.field_names
|
||||||
});
|
.iter()
|
||||||
ast::make::tuple_pat(fields)
|
.map(|name| ast::Pat::from(make::ident_pat(is_ref, is_mut, make::name(name))));
|
||||||
|
make::tuple_pat(fields).clone_for_update()
|
||||||
};
|
};
|
||||||
|
|
||||||
let add_cursor = |text: &str| {
|
if let Some(cap) = ctx.config.snippet_cap {
|
||||||
// place cursor on first tuple item
|
// place cursor on first tuple name
|
||||||
let first_tuple = &data.field_names[0];
|
if let Some(ast::Pat::IdentPat(first_pat)) = tuple_pat.fields().next() {
|
||||||
text.replacen(first_tuple, &format!("$0{first_tuple}"), 1)
|
edit.add_tabstop_before(
|
||||||
};
|
cap,
|
||||||
|
first_pat.name().expect("first ident pattern should have a name"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// with sub_pattern: keep original tuple and add subpattern: `tup @ (_0, _1)`
|
AssignmentEdit { ident_pat, tuple_pat, in_sub_pattern }
|
||||||
if in_sub_pattern {
|
}
|
||||||
let text = format!(" @ {tuple_pat}");
|
struct AssignmentEdit {
|
||||||
match ctx.config.snippet_cap {
|
ident_pat: ast::IdentPat,
|
||||||
Some(cap) => {
|
tuple_pat: ast::TuplePat,
|
||||||
let snip = add_cursor(&text);
|
in_sub_pattern: bool,
|
||||||
builder.insert_snippet(cap, data.range.end(), snip);
|
}
|
||||||
}
|
|
||||||
None => builder.insert(data.range.end(), text),
|
impl AssignmentEdit {
|
||||||
};
|
fn apply(self) {
|
||||||
} else {
|
// with sub_pattern: keep original tuple and add subpattern: `tup @ (_0, _1)`
|
||||||
let text = tuple_pat.to_string();
|
if self.in_sub_pattern {
|
||||||
match ctx.config.snippet_cap {
|
self.ident_pat.set_pat(Some(self.tuple_pat.into()))
|
||||||
Some(cap) => {
|
} else {
|
||||||
let snip = add_cursor(&text);
|
ted::replace(self.ident_pat.syntax(), self.tuple_pat.syntax())
|
||||||
builder.replace_snippet(cap, data.range, snip);
|
}
|
||||||
}
|
|
||||||
None => builder.replace(data.range, text),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit_tuple_usages(
|
fn edit_tuple_usages(
|
||||||
data: &TupleData,
|
data: &TupleData,
|
||||||
builder: &mut SourceChangeBuilder,
|
edit: &mut SourceChangeBuilder,
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
in_sub_pattern: bool,
|
in_sub_pattern: bool,
|
||||||
) {
|
) -> Option<Vec<EditTupleUsage>> {
|
||||||
if let Some(usages) = data.usages.as_ref() {
|
let mut current_file_usages = None;
|
||||||
for (file_id, refs) in usages.iter() {
|
|
||||||
builder.edit_file(*file_id);
|
|
||||||
|
|
||||||
for r in refs {
|
if let Some(usages) = data.usages.as_ref() {
|
||||||
edit_tuple_usage(ctx, builder, r, data, in_sub_pattern);
|
// We need to collect edits first before actually applying them
|
||||||
|
// as mapping nodes to their mutable node versions requires an
|
||||||
|
// unmodified syntax tree.
|
||||||
|
//
|
||||||
|
// We also defer editing usages in the current file first since
|
||||||
|
// tree mutation in the same file breaks when `builder.edit_file`
|
||||||
|
// is called
|
||||||
|
|
||||||
|
if let Some((_, refs)) = usages.iter().find(|(file_id, _)| **file_id == ctx.file_id()) {
|
||||||
|
current_file_usages = Some(
|
||||||
|
refs.iter()
|
||||||
|
.filter_map(|r| edit_tuple_usage(ctx, edit, r, data, in_sub_pattern))
|
||||||
|
.collect_vec(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (file_id, refs) in usages.iter() {
|
||||||
|
if *file_id == ctx.file_id() {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit.edit_file(*file_id);
|
||||||
|
|
||||||
|
let tuple_edits = refs
|
||||||
|
.iter()
|
||||||
|
.filter_map(|r| edit_tuple_usage(ctx, edit, r, data, in_sub_pattern))
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
|
tuple_edits.into_iter().for_each(|tuple_edit| tuple_edit.apply(edit))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_file_usages
|
||||||
}
|
}
|
||||||
fn edit_tuple_usage(
|
fn edit_tuple_usage(
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
@ -215,25 +253,14 @@ fn edit_tuple_usage(
|
|||||||
usage: &FileReference,
|
usage: &FileReference,
|
||||||
data: &TupleData,
|
data: &TupleData,
|
||||||
in_sub_pattern: bool,
|
in_sub_pattern: bool,
|
||||||
) {
|
) -> Option<EditTupleUsage> {
|
||||||
match detect_tuple_index(usage, data) {
|
match detect_tuple_index(usage, data) {
|
||||||
Some(index) => edit_tuple_field_usage(ctx, builder, data, index),
|
Some(index) => Some(edit_tuple_field_usage(ctx, builder, data, index)),
|
||||||
None => {
|
None if in_sub_pattern => {
|
||||||
if in_sub_pattern {
|
cov_mark::hit!(destructure_tuple_call_with_subpattern);
|
||||||
cov_mark::hit!(destructure_tuple_call_with_subpattern);
|
return None;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no index access -> make invalid -> requires handling by user
|
|
||||||
// -> put usage in block comment
|
|
||||||
//
|
|
||||||
// Note: For macro invocations this might result in still valid code:
|
|
||||||
// When a macro accepts the tuple as argument, as well as no arguments at all,
|
|
||||||
// uncommenting the tuple still leaves the macro call working (see `tests::in_macro_call::empty_macro`).
|
|
||||||
// But this is an unlikely case. Usually the resulting macro call will become erroneous.
|
|
||||||
builder.insert(usage.range.start(), "/*");
|
|
||||||
builder.insert(usage.range.end(), "*/");
|
|
||||||
}
|
}
|
||||||
|
None => Some(EditTupleUsage::NoIndex(usage.range)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,19 +269,47 @@ fn edit_tuple_field_usage(
|
|||||||
builder: &mut SourceChangeBuilder,
|
builder: &mut SourceChangeBuilder,
|
||||||
data: &TupleData,
|
data: &TupleData,
|
||||||
index: TupleIndex,
|
index: TupleIndex,
|
||||||
) {
|
) -> EditTupleUsage {
|
||||||
let field_name = &data.field_names[index.index];
|
let field_name = &data.field_names[index.index];
|
||||||
|
let field_name = make::expr_path(make::ext::ident_path(field_name));
|
||||||
|
|
||||||
if data.ref_type.is_some() {
|
if data.ref_type.is_some() {
|
||||||
let ref_data = handle_ref_field_usage(ctx, &index.field_expr);
|
let (replace_expr, ref_data) = handle_ref_field_usage(ctx, &index.field_expr);
|
||||||
builder.replace(ref_data.range, ref_data.format(field_name));
|
let replace_expr = builder.make_mut(replace_expr);
|
||||||
|
EditTupleUsage::ReplaceExpr(replace_expr, ref_data.wrap_expr(field_name))
|
||||||
} else {
|
} else {
|
||||||
builder.replace(index.range, field_name);
|
let field_expr = builder.make_mut(index.field_expr);
|
||||||
|
EditTupleUsage::ReplaceExpr(field_expr.into(), field_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
enum EditTupleUsage {
|
||||||
|
/// no index access -> make invalid -> requires handling by user
|
||||||
|
/// -> put usage in block comment
|
||||||
|
///
|
||||||
|
/// Note: For macro invocations this might result in still valid code:
|
||||||
|
/// When a macro accepts the tuple as argument, as well as no arguments at all,
|
||||||
|
/// uncommenting the tuple still leaves the macro call working (see `tests::in_macro_call::empty_macro`).
|
||||||
|
/// But this is an unlikely case. Usually the resulting macro call will become erroneous.
|
||||||
|
NoIndex(TextRange),
|
||||||
|
ReplaceExpr(ast::Expr, ast::Expr),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EditTupleUsage {
|
||||||
|
fn apply(self, edit: &mut SourceChangeBuilder) {
|
||||||
|
match self {
|
||||||
|
EditTupleUsage::NoIndex(range) => {
|
||||||
|
edit.insert(range.start(), "/*");
|
||||||
|
edit.insert(range.end(), "*/");
|
||||||
|
}
|
||||||
|
EditTupleUsage::ReplaceExpr(target_expr, replace_with) => {
|
||||||
|
ted::replace(target_expr.syntax(), replace_with.clone_for_update().syntax())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct TupleIndex {
|
struct TupleIndex {
|
||||||
index: usize,
|
index: usize,
|
||||||
range: TextRange,
|
|
||||||
field_expr: FieldExpr,
|
field_expr: FieldExpr,
|
||||||
}
|
}
|
||||||
fn detect_tuple_index(usage: &FileReference, data: &TupleData) -> Option<TupleIndex> {
|
fn detect_tuple_index(usage: &FileReference, data: &TupleData) -> Option<TupleIndex> {
|
||||||
@ -296,7 +351,7 @@ fn detect_tuple_index(usage: &FileReference, data: &TupleData) -> Option<TupleIn
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(TupleIndex { index: idx, range: field_expr.syntax().text_range(), field_expr })
|
Some(TupleIndex { index: idx, field_expr })
|
||||||
} else {
|
} else {
|
||||||
// tuple index out of range
|
// tuple index out of range
|
||||||
None
|
None
|
||||||
@ -307,32 +362,34 @@ fn detect_tuple_index(usage: &FileReference, data: &TupleData) -> Option<TupleIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct RefData {
|
struct RefData {
|
||||||
range: TextRange,
|
|
||||||
needs_deref: bool,
|
needs_deref: bool,
|
||||||
needs_parentheses: bool,
|
needs_parentheses: bool,
|
||||||
}
|
}
|
||||||
impl RefData {
|
impl RefData {
|
||||||
fn format(&self, field_name: &str) -> String {
|
fn wrap_expr(&self, mut expr: ast::Expr) -> ast::Expr {
|
||||||
match (self.needs_deref, self.needs_parentheses) {
|
if self.needs_deref {
|
||||||
(true, true) => format!("(*{field_name})"),
|
expr = make::expr_prefix(T![*], expr);
|
||||||
(true, false) => format!("*{field_name}"),
|
|
||||||
(false, true) => format!("({field_name})"),
|
|
||||||
(false, false) => field_name.to_string(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.needs_parentheses {
|
||||||
|
expr = make::expr_paren(expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> RefData {
|
fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> (ast::Expr, RefData) {
|
||||||
let s = field_expr.syntax();
|
let s = field_expr.syntax();
|
||||||
let mut ref_data =
|
let mut ref_data = RefData { needs_deref: true, needs_parentheses: true };
|
||||||
RefData { range: s.text_range(), needs_deref: true, needs_parentheses: true };
|
let mut target_node = field_expr.clone().into();
|
||||||
|
|
||||||
let parent = match s.parent().map(ast::Expr::cast) {
|
let parent = match s.parent().map(ast::Expr::cast) {
|
||||||
Some(Some(parent)) => parent,
|
Some(Some(parent)) => parent,
|
||||||
Some(None) => {
|
Some(None) => {
|
||||||
ref_data.needs_parentheses = false;
|
ref_data.needs_parentheses = false;
|
||||||
return ref_data;
|
return (target_node, ref_data);
|
||||||
}
|
}
|
||||||
None => return ref_data,
|
None => return (target_node, ref_data),
|
||||||
};
|
};
|
||||||
|
|
||||||
match parent {
|
match parent {
|
||||||
@ -342,7 +399,7 @@ fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> Re
|
|||||||
// there might be a ref outside: `&(t.0)` -> can be removed
|
// there might be a ref outside: `&(t.0)` -> can be removed
|
||||||
if let Some(it) = it.syntax().parent().and_then(ast::RefExpr::cast) {
|
if let Some(it) = it.syntax().parent().and_then(ast::RefExpr::cast) {
|
||||||
ref_data.needs_deref = false;
|
ref_data.needs_deref = false;
|
||||||
ref_data.range = it.syntax().text_range();
|
target_node = it.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::Expr::RefExpr(it) => {
|
ast::Expr::RefExpr(it) => {
|
||||||
@ -351,8 +408,8 @@ fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> Re
|
|||||||
ref_data.needs_parentheses = false;
|
ref_data.needs_parentheses = false;
|
||||||
// might be surrounded by parens -> can be removed too
|
// might be surrounded by parens -> can be removed too
|
||||||
match it.syntax().parent().and_then(ast::ParenExpr::cast) {
|
match it.syntax().parent().and_then(ast::ParenExpr::cast) {
|
||||||
Some(parent) => ref_data.range = parent.syntax().text_range(),
|
Some(parent) => target_node = parent.into(),
|
||||||
None => ref_data.range = it.syntax().text_range(),
|
None => target_node = it.into(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// higher precedence than deref `*`
|
// higher precedence than deref `*`
|
||||||
@ -414,7 +471,7 @@ fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> Re
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ref_data
|
(target_node, ref_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -163,6 +163,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
|||||||
ModuleDef::from(control_flow_enum),
|
ModuleDef::from(control_flow_enum),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(mod_path) = mod_path {
|
if let Some(mod_path) = mod_path {
|
||||||
|
@ -384,6 +384,7 @@ fn process_references(
|
|||||||
*enum_module_def,
|
*enum_module_def,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
);
|
);
|
||||||
if let Some(mut mod_path) = mod_path {
|
if let Some(mut mod_path) = mod_path {
|
||||||
mod_path.pop_segment();
|
mod_path.pop_segment();
|
||||||
|
@ -58,8 +58,12 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
|||||||
|
|
||||||
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
||||||
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
||||||
let trait_path =
|
let trait_path = module.find_use_path(
|
||||||
module.find_use_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.prefer_no_std)?;
|
ctx.db(),
|
||||||
|
ModuleDef::Trait(trait_),
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)?;
|
||||||
|
|
||||||
let field_type = field.ty()?;
|
let field_type = field.ty()?;
|
||||||
let field_name = field.name()?;
|
let field_name = field.name()?;
|
||||||
@ -99,8 +103,12 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
|
|||||||
|
|
||||||
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
||||||
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
||||||
let trait_path =
|
let trait_path = module.find_use_path(
|
||||||
module.find_use_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.prefer_no_std)?;
|
ctx.db(),
|
||||||
|
ModuleDef::Trait(trait_),
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)?;
|
||||||
|
|
||||||
let field_type = field.ty()?;
|
let field_type = field.ty()?;
|
||||||
let target = field.syntax().text_range();
|
let target = field.syntax().text_range();
|
||||||
|
@ -67,6 +67,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
|||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let expr = use_trivial_constructor(
|
let expr = use_trivial_constructor(
|
||||||
|
@ -48,6 +48,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
|||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
|
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
|
||||||
|
@ -37,8 +37,11 @@ use crate::{
|
|||||||
// ```
|
// ```
|
||||||
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
||||||
let mut proposed_imports =
|
let mut proposed_imports = import_assets.search_for_relative_paths(
|
||||||
import_assets.search_for_relative_paths(&ctx.sema, ctx.config.prefer_no_std);
|
&ctx.sema,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
);
|
||||||
if proposed_imports.is_empty() {
|
if proposed_imports.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,12 @@ pub(crate) fn replace_derive_with_manual_impl(
|
|||||||
})
|
})
|
||||||
.flat_map(|trait_| {
|
.flat_map(|trait_| {
|
||||||
current_module
|
current_module
|
||||||
.find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_), ctx.config.prefer_no_std)
|
.find_use_path(
|
||||||
|
ctx.sema.db,
|
||||||
|
hir::ModuleDef::Trait(trait_),
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(mod_path_to_ast)
|
.map(mod_path_to_ast)
|
||||||
.zip(Some(trait_))
|
.zip(Some(trait_))
|
||||||
|
@ -68,6 +68,7 @@ pub(crate) fn replace_qualified_name_with_use(
|
|||||||
module,
|
module,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.flatten();
|
.flatten();
|
||||||
|
@ -30,6 +30,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
|
|||||||
skip_glob_imports: true,
|
skip_glob_imports: true,
|
||||||
},
|
},
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
|
prefer_prelude: true,
|
||||||
assist_emit_must_use: false,
|
assist_emit_must_use: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
|
|||||||
skip_glob_imports: true,
|
skip_glob_imports: true,
|
||||||
},
|
},
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
|
prefer_prelude: true,
|
||||||
assist_emit_must_use: false,
|
assist_emit_must_use: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -98,6 +100,11 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) {
|
|||||||
check(assist, ra_fixture, ExpectedResult::NotApplicable, None);
|
check(assist, ra_fixture, ExpectedResult::NotApplicable, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub(crate) fn check_assist_not_applicable_by_label(assist: Handler, ra_fixture: &str, label: &str) {
|
||||||
|
check(assist, ra_fixture, ExpectedResult::NotApplicable, Some(label));
|
||||||
|
}
|
||||||
|
|
||||||
/// Check assist in unresolved state. Useful to check assists for lazy computation.
|
/// Check assist in unresolved state. Useful to check assists for lazy computation.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) {
|
pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) {
|
||||||
|
@ -106,8 +106,18 @@ pub fn filter_assoc_items(
|
|||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.filter(|assoc_item| {
|
.filter(|assoc_item| {
|
||||||
!(ignore_items == IgnoreAssocItems::DocHiddenAttrPresent
|
if ignore_items == IgnoreAssocItems::DocHiddenAttrPresent
|
||||||
&& assoc_item.attrs(sema.db).has_doc_hidden())
|
&& assoc_item.attrs(sema.db).has_doc_hidden()
|
||||||
|
{
|
||||||
|
if let hir::AssocItem::Function(f) = assoc_item {
|
||||||
|
if !f.has_body(sema.db) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
})
|
})
|
||||||
// Note: This throws away items with no source.
|
// Note: This throws away items with no source.
|
||||||
.filter_map(|assoc_item| {
|
.filter_map(|assoc_item| {
|
||||||
|
@ -13,7 +13,7 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
|
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
|
@ -626,6 +626,7 @@ fn enum_variants_with_paths(
|
|||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(variant),
|
hir::ModuleDef::from(variant),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
) {
|
) {
|
||||||
// Variants with trivial paths are already added by the existing completion logic,
|
// Variants with trivial paths are already added by the existing completion logic,
|
||||||
// so we should avoid adding these twice
|
// so we should avoid adding these twice
|
||||||
|
@ -175,6 +175,7 @@ pub(crate) fn complete_expr_path(
|
|||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(strukt),
|
hir::ModuleDef::from(strukt),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)
|
)
|
||||||
.filter(|it| it.len() > 1);
|
.filter(|it| it.len() > 1);
|
||||||
|
|
||||||
@ -197,6 +198,7 @@ pub(crate) fn complete_expr_path(
|
|||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(un),
|
hir::ModuleDef::from(un),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)
|
)
|
||||||
.filter(|it| it.len() > 1);
|
.filter(|it| it.len() > 1);
|
||||||
|
|
||||||
|
@ -257,7 +257,12 @@ fn import_on_the_fly(
|
|||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
import_assets
|
import_assets
|
||||||
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
.search_for_imports(
|
||||||
|
&ctx.sema,
|
||||||
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(ns_filter)
|
.filter(ns_filter)
|
||||||
.filter(|import| {
|
.filter(|import| {
|
||||||
@ -299,7 +304,12 @@ fn import_on_the_fly_pat_(
|
|||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
import_assets
|
import_assets
|
||||||
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
.search_for_imports(
|
||||||
|
&ctx.sema,
|
||||||
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(ns_filter)
|
.filter(ns_filter)
|
||||||
.filter(|import| {
|
.filter(|import| {
|
||||||
@ -336,7 +346,12 @@ fn import_on_the_fly_method(
|
|||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
import_assets
|
import_assets
|
||||||
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
.search_for_imports(
|
||||||
|
&ctx.sema,
|
||||||
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|import| {
|
.filter(|import| {
|
||||||
!ctx.is_item_hidden(&import.item_to_import)
|
!ctx.is_item_hidden(&import.item_to_import)
|
||||||
|
@ -19,6 +19,7 @@ pub struct CompletionConfig {
|
|||||||
pub snippet_cap: Option<SnippetCap>,
|
pub snippet_cap: Option<SnippetCap>,
|
||||||
pub insert_use: InsertUseConfig,
|
pub insert_use: InsertUseConfig,
|
||||||
pub prefer_no_std: bool,
|
pub prefer_no_std: bool,
|
||||||
|
pub prefer_prelude: bool,
|
||||||
pub snippets: Vec<Snippet>,
|
pub snippets: Vec<Snippet>,
|
||||||
pub limit: Option<usize>,
|
pub limit: Option<usize>,
|
||||||
}
|
}
|
||||||
|
@ -263,6 +263,7 @@ pub fn resolve_completion_edits(
|
|||||||
candidate,
|
candidate,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
config.prefer_no_std,
|
config.prefer_no_std,
|
||||||
|
config.prefer_prelude,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.find(|mod_path| mod_path.display(db).to_string() == full_import_path);
|
.find(|mod_path| mod_path.display(db).to_string() == full_import_path);
|
||||||
|
@ -179,6 +179,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
|
|||||||
item,
|
item,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)?;
|
)?;
|
||||||
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item, None)))
|
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item, None)))
|
||||||
};
|
};
|
||||||
|
@ -68,6 +68,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
|||||||
callable: Some(CallableSnippets::FillArguments),
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
|
prefer_prelude: true,
|
||||||
insert_use: InsertUseConfig {
|
insert_use: InsertUseConfig {
|
||||||
granularity: ImportGranularity::Crate,
|
granularity: ImportGranularity::Crate,
|
||||||
prefix_kind: PrefixKind::Plain,
|
prefix_kind: PrefixKind::Plain,
|
||||||
|
@ -13,16 +13,16 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
rayon = "1.6.1"
|
rayon.workspace = true
|
||||||
fst = { version = "0.4.7", default-features = false }
|
fst = { version = "0.4.7", default-features = false }
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
arrayvec = "0.7.2"
|
arrayvec = "0.7.2"
|
||||||
indexmap = "2.0.0"
|
indexmap.workspace = true
|
||||||
memchr = "2.5.0"
|
memchr = "2.6.4"
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
nohash-hasher.workspace = true
|
nohash-hasher.workspace = true
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ line-index.workspace = true
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
expect-test = "1.4.0"
|
expect-test = "1.4.0"
|
||||||
oorandom = "11.1.3"
|
oorandom = "11.1.3"
|
||||||
xshell = "0.2.2"
|
xshell.workspace = true
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
test-utils.workspace = true
|
test-utils.workspace = true
|
||||||
|
@ -220,9 +220,10 @@ impl ImportAssets {
|
|||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
prefix_kind: PrefixKind,
|
prefix_kind: PrefixKind,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Vec<LocatedImport> {
|
) -> Vec<LocatedImport> {
|
||||||
let _p = profile::span("import_assets::search_for_imports");
|
let _p = profile::span("import_assets::search_for_imports");
|
||||||
self.search_for(sema, Some(prefix_kind), prefer_no_std)
|
self.search_for(sema, Some(prefix_kind), prefer_no_std, prefer_prelude)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This may return non-absolute paths if a part of the returned path is already imported into scope.
|
/// This may return non-absolute paths if a part of the returned path is already imported into scope.
|
||||||
@ -230,9 +231,10 @@ impl ImportAssets {
|
|||||||
&self,
|
&self,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Vec<LocatedImport> {
|
) -> Vec<LocatedImport> {
|
||||||
let _p = profile::span("import_assets::search_for_relative_paths");
|
let _p = profile::span("import_assets::search_for_relative_paths");
|
||||||
self.search_for(sema, None, prefer_no_std)
|
self.search_for(sema, None, prefer_no_std, prefer_prelude)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requires imports to by prefix instead of fuzzily.
|
/// Requires imports to by prefix instead of fuzzily.
|
||||||
@ -270,6 +272,7 @@ impl ImportAssets {
|
|||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
prefixed: Option<PrefixKind>,
|
prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Vec<LocatedImport> {
|
) -> Vec<LocatedImport> {
|
||||||
let _p = profile::span("import_assets::search_for");
|
let _p = profile::span("import_assets::search_for");
|
||||||
|
|
||||||
@ -281,6 +284,7 @@ impl ImportAssets {
|
|||||||
&self.module_with_candidate,
|
&self.module_with_candidate,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -594,11 +598,18 @@ fn get_mod_path(
|
|||||||
module_with_candidate: &Module,
|
module_with_candidate: &Module,
|
||||||
prefixed: Option<PrefixKind>,
|
prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
if let Some(prefix_kind) = prefixed {
|
if let Some(prefix_kind) = prefixed {
|
||||||
module_with_candidate.find_use_path_prefixed(db, item_to_search, prefix_kind, prefer_no_std)
|
module_with_candidate.find_use_path_prefixed(
|
||||||
|
db,
|
||||||
|
item_to_search,
|
||||||
|
prefix_kind,
|
||||||
|
prefer_no_std,
|
||||||
|
prefer_prelude,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
module_with_candidate.find_use_path(db, item_to_search, prefer_no_std)
|
module_with_candidate.find_use_path(db, item_to_search, prefer_no_std, prefer_prelude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +277,7 @@ impl Ctx<'_> {
|
|||||||
self.source_scope.db.upcast(),
|
self.source_scope.db.upcast(),
|
||||||
hir::ModuleDef::Trait(trait_ref),
|
hir::ModuleDef::Trait(trait_ref),
|
||||||
false,
|
false,
|
||||||
|
true,
|
||||||
)?;
|
)?;
|
||||||
match make::ty_path(mod_path_to_ast(&found_path)) {
|
match make::ty_path(mod_path_to_ast(&found_path)) {
|
||||||
ast::Type::PathType(path_ty) => Some(path_ty),
|
ast::Type::PathType(path_ty) => Some(path_ty),
|
||||||
@ -311,8 +312,12 @@ impl Ctx<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let found_path =
|
let found_path = self.target_module.find_use_path(
|
||||||
self.target_module.find_use_path(self.source_scope.db.upcast(), def, false)?;
|
self.source_scope.db.upcast(),
|
||||||
|
def,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
)?;
|
||||||
let res = mod_path_to_ast(&found_path).clone_for_update();
|
let res = mod_path_to_ast(&found_path).clone_for_update();
|
||||||
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
|
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
|
||||||
if let Some(segment) = res.segment() {
|
if let Some(segment) = res.segment() {
|
||||||
|
@ -584,7 +584,7 @@ impl<'a> FindUsages<'a> {
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
match NameRefClass::classify(self.sema, name_ref) {
|
match NameRefClass::classify(self.sema, name_ref) {
|
||||||
Some(NameRefClass::Definition(Definition::SelfType(impl_)))
|
Some(NameRefClass::Definition(Definition::SelfType(impl_)))
|
||||||
if impl_.self_ty(self.sema.db) == *self_ty =>
|
if impl_.self_ty(self.sema.db).as_adt() == self_ty.as_adt() =>
|
||||||
{
|
{
|
||||||
let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
|
let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
|
||||||
let reference = FileReference {
|
let reference = FileReference {
|
||||||
|
@ -140,10 +140,10 @@ impl SnippetEdit {
|
|||||||
.with_position()
|
.with_position()
|
||||||
.map(|pos| {
|
.map(|pos| {
|
||||||
let (snippet, index) = match pos {
|
let (snippet, index) = match pos {
|
||||||
itertools::Position::First(it) | itertools::Position::Middle(it) => it,
|
(itertools::Position::First, it) | (itertools::Position::Middle, it) => it,
|
||||||
// last/only snippet gets index 0
|
// last/only snippet gets index 0
|
||||||
itertools::Position::Last((snippet, _))
|
(itertools::Position::Last, (snippet, _))
|
||||||
| itertools::Position::Only((snippet, _)) => (snippet, 0),
|
| (itertools::Position::Only, (snippet, _)) => (snippet, 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
let range = match snippet {
|
let range = match snippet {
|
||||||
|
@ -13,9 +13,9 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
serde_json = "1.0.86"
|
serde_json.workspace = true
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
|
@ -599,12 +599,12 @@ fn main() {
|
|||||||
//^^^ 💡 warn: Static variable `bar` should have UPPER_SNAKE_CASE name, e.g. `BAR`
|
//^^^ 💡 warn: Static variable `bar` should have UPPER_SNAKE_CASE name, e.g. `BAR`
|
||||||
fn BAZ() {
|
fn BAZ() {
|
||||||
//^^^ 💡 warn: Function `BAZ` should have snake_case name, e.g. `baz`
|
//^^^ 💡 warn: Function `BAZ` should have snake_case name, e.g. `baz`
|
||||||
let INNER_INNER = 42;
|
let _INNER_INNER = 42;
|
||||||
//^^^^^^^^^^^ 💡 warn: Variable `INNER_INNER` should have snake_case name, e.g. `inner_inner`
|
//^^^^^^^^^^^^ 💡 warn: Variable `_INNER_INNER` should have snake_case name, e.g. `_inner_inner`
|
||||||
}
|
}
|
||||||
|
|
||||||
let INNER_LOCAL = 42;
|
let _INNER_LOCAL = 42;
|
||||||
//^^^^^^^^^^^ 💡 warn: Variable `INNER_LOCAL` should have snake_case name, e.g. `inner_local`
|
//^^^^^^^^^^^^ 💡 warn: Variable `_INNER_LOCAL` should have snake_case name, e.g. `_inner_local`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
@ -136,6 +136,7 @@ pub(crate) fn json_in_items(
|
|||||||
it,
|
it,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
config.prefer_no_std,
|
config.prefer_no_std,
|
||||||
|
config.prefer_prelude,
|
||||||
) {
|
) {
|
||||||
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
||||||
}
|
}
|
||||||
@ -148,6 +149,7 @@ pub(crate) fn json_in_items(
|
|||||||
it,
|
it,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
config.prefer_no_std,
|
config.prefer_no_std,
|
||||||
|
config.prefer_prelude,
|
||||||
) {
|
) {
|
||||||
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
|||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
ctx.config.prefer_prelude,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
use_trivial_constructor(
|
use_trivial_constructor(
|
||||||
|
@ -1225,6 +1225,22 @@ fn foo(mut foo: Foo) {
|
|||||||
};
|
};
|
||||||
call_me();
|
call_me();
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn regression_15670() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- minicore: fn
|
||||||
|
|
||||||
|
pub struct A {}
|
||||||
|
pub unsafe fn foo(a: *mut A) {
|
||||||
|
let mut b = || -> *mut A { &mut *a };
|
||||||
|
//^^^^^ 💡 warn: variable does not need to be mutable
|
||||||
|
let _ = b();
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
use hir::InFile;
|
||||||
|
use syntax::ast;
|
||||||
|
|
||||||
|
use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext, Severity};
|
||||||
|
|
||||||
|
// Diagnostic: trait-impl-incorrect-safety
|
||||||
|
//
|
||||||
|
// Diagnoses incorrect safety annotations of trait impls.
|
||||||
|
pub(crate) fn trait_impl_incorrect_safety(
|
||||||
|
ctx: &DiagnosticsContext<'_>,
|
||||||
|
d: &hir::TraitImplIncorrectSafety,
|
||||||
|
) -> Diagnostic {
|
||||||
|
Diagnostic::new(
|
||||||
|
DiagnosticCode::Ra("trait-impl-incorrect-safety", Severity::Error),
|
||||||
|
if d.should_be_safe {
|
||||||
|
"unsafe impl for safe trait"
|
||||||
|
} else {
|
||||||
|
"impl for unsafe trait needs to be unsafe"
|
||||||
|
},
|
||||||
|
adjusted_display_range::<ast::Impl>(
|
||||||
|
ctx,
|
||||||
|
InFile { file_id: d.file_id, value: d.impl_.syntax_node_ptr() },
|
||||||
|
&|impl_| {
|
||||||
|
if d.should_be_safe {
|
||||||
|
Some(match (impl_.unsafe_token(), impl_.impl_token()) {
|
||||||
|
(None, None) => return None,
|
||||||
|
(None, Some(t)) | (Some(t), None) => t.text_range(),
|
||||||
|
(Some(t1), Some(t2)) => t1.text_range().cover(t2.text_range()),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
impl_.impl_token().map(|t| t.text_range())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::tests::check_diagnostics;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
trait Safe {}
|
||||||
|
unsafe trait Unsafe {}
|
||||||
|
|
||||||
|
impl Safe for () {}
|
||||||
|
|
||||||
|
impl Unsafe for () {}
|
||||||
|
//^^^^ error: impl for unsafe trait needs to be unsafe
|
||||||
|
|
||||||
|
unsafe impl Safe for () {}
|
||||||
|
//^^^^^^^^^^^ error: unsafe impl for safe trait
|
||||||
|
|
||||||
|
unsafe impl Unsafe for () {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn drop_may_dangle() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
#[lang = "drop"]
|
||||||
|
trait Drop {}
|
||||||
|
struct S<T>;
|
||||||
|
struct L<'l>;
|
||||||
|
|
||||||
|
impl<T> Drop for S<T> {}
|
||||||
|
|
||||||
|
impl<#[may_dangle] T> Drop for S<T> {}
|
||||||
|
//^^^^ error: impl for unsafe trait needs to be unsafe
|
||||||
|
|
||||||
|
unsafe impl<T> Drop for S<T> {}
|
||||||
|
//^^^^^^^^^^^ error: unsafe impl for safe trait
|
||||||
|
|
||||||
|
unsafe impl<#[may_dangle] T> Drop for S<T> {}
|
||||||
|
|
||||||
|
impl<'l> Drop for L<'l> {}
|
||||||
|
|
||||||
|
impl<#[may_dangle] 'l> Drop for L<'l> {}
|
||||||
|
//^^^^ error: impl for unsafe trait needs to be unsafe
|
||||||
|
|
||||||
|
unsafe impl<'l> Drop for L<'l> {}
|
||||||
|
//^^^^^^^^^^^ error: unsafe impl for safe trait
|
||||||
|
|
||||||
|
unsafe impl<#[may_dangle] 'l> Drop for L<'l> {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn negative() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
trait Trait {}
|
||||||
|
|
||||||
|
impl !Trait for () {}
|
||||||
|
|
||||||
|
unsafe impl !Trait for () {}
|
||||||
|
//^^^^^^^^^^^ error: unsafe impl for safe trait
|
||||||
|
|
||||||
|
unsafe trait UnsafeTrait {}
|
||||||
|
|
||||||
|
impl !UnsafeTrait for () {}
|
||||||
|
|
||||||
|
unsafe impl !UnsafeTrait for () {}
|
||||||
|
//^^^^^^^^^^^ error: unsafe impl for safe trait
|
||||||
|
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inherent() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl S {}
|
||||||
|
|
||||||
|
unsafe impl S {}
|
||||||
|
//^^^^^^^^^^^ error: unsafe impl for safe trait
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
use hir::InFile;
|
||||||
|
use itertools::Itertools;
|
||||||
|
use syntax::{ast, AstNode};
|
||||||
|
|
||||||
|
use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext};
|
||||||
|
|
||||||
|
// Diagnostic: trait-impl-missing-assoc_item
|
||||||
|
//
|
||||||
|
// Diagnoses missing trait items in a trait impl.
|
||||||
|
pub(crate) fn trait_impl_missing_assoc_item(
|
||||||
|
ctx: &DiagnosticsContext<'_>,
|
||||||
|
d: &hir::TraitImplMissingAssocItems,
|
||||||
|
) -> Diagnostic {
|
||||||
|
let missing = d.missing.iter().format_with(", ", |(name, item), f| {
|
||||||
|
f(&match *item {
|
||||||
|
hir::AssocItem::Function(_) => "`fn ",
|
||||||
|
hir::AssocItem::Const(_) => "`const ",
|
||||||
|
hir::AssocItem::TypeAlias(_) => "`type ",
|
||||||
|
})?;
|
||||||
|
f(&name.display(ctx.sema.db))?;
|
||||||
|
f(&"`")
|
||||||
|
});
|
||||||
|
Diagnostic::new(
|
||||||
|
DiagnosticCode::RustcHardError("E0046"),
|
||||||
|
format!("not all trait items implemented, missing: {missing}"),
|
||||||
|
adjusted_display_range::<ast::Impl>(
|
||||||
|
ctx,
|
||||||
|
InFile { file_id: d.file_id, value: d.impl_.syntax_node_ptr() },
|
||||||
|
&|impl_| impl_.trait_().map(|t| t.syntax().text_range()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::tests::check_diagnostics;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
trait Trait {
|
||||||
|
const C: ();
|
||||||
|
type T;
|
||||||
|
fn f();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
const C: () = ();
|
||||||
|
type T = ();
|
||||||
|
fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
//^^^^^ error: not all trait items implemented, missing: `const C`
|
||||||
|
type T = ();
|
||||||
|
fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
//^^^^^ error: not all trait items implemented, missing: `const C`, `type T`, `fn f`
|
||||||
|
}
|
||||||
|
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn default() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
trait Trait {
|
||||||
|
const C: ();
|
||||||
|
type T = ();
|
||||||
|
fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
const C: () = ();
|
||||||
|
type T = ();
|
||||||
|
fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
//^^^^^ error: not all trait items implemented, missing: `const C`
|
||||||
|
type T = ();
|
||||||
|
fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
//^^^^^ error: not all trait items implemented, missing: `const C`
|
||||||
|
type T = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trait for () {
|
||||||
|
//^^^^^ error: not all trait items implemented, missing: `const C`
|
||||||
|
}
|
||||||
|
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
106
crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs
Normal file
106
crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
use hir::InFile;
|
||||||
|
|
||||||
|
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
|
||||||
|
|
||||||
|
// Diagnostic: trait-impl-orphan
|
||||||
|
//
|
||||||
|
// Only traits defined in the current crate can be implemented for arbitrary types
|
||||||
|
pub(crate) fn trait_impl_orphan(
|
||||||
|
ctx: &DiagnosticsContext<'_>,
|
||||||
|
d: &hir::TraitImplOrphan,
|
||||||
|
) -> Diagnostic {
|
||||||
|
Diagnostic::new_with_syntax_node_ptr(
|
||||||
|
ctx,
|
||||||
|
DiagnosticCode::RustcHardError("E0117"),
|
||||||
|
format!("only traits defined in the current crate can be implemented for arbitrary types"),
|
||||||
|
InFile::new(d.file_id, d.impl_.clone().into()),
|
||||||
|
)
|
||||||
|
// Not yet checked for false positives
|
||||||
|
.experimental()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::tests::check_diagnostics;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- /foo.rs crate:foo
|
||||||
|
pub trait Foo {}
|
||||||
|
//- /bar.rs crate:bar
|
||||||
|
pub struct Bar;
|
||||||
|
//- /main.rs crate:main deps:foo,bar
|
||||||
|
struct LocalType;
|
||||||
|
trait LocalTrait {}
|
||||||
|
impl foo::Foo for bar::Bar {}
|
||||||
|
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: only traits defined in the current crate can be implemented for arbitrary types
|
||||||
|
impl foo::Foo for LocalType {}
|
||||||
|
impl LocalTrait for bar::Bar {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generics() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- /foo.rs crate:foo
|
||||||
|
pub trait Foo<T> {}
|
||||||
|
//- /bar.rs crate:bar
|
||||||
|
pub struct Bar<T>(T);
|
||||||
|
//- /main.rs crate:main deps:foo,bar
|
||||||
|
struct LocalType<T>;
|
||||||
|
trait LocalTrait<T> {}
|
||||||
|
impl<T> foo::Foo<T> for bar::Bar<T> {}
|
||||||
|
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: only traits defined in the current crate can be implemented for arbitrary types
|
||||||
|
|
||||||
|
impl<T> foo::Foo<T> for bar::Bar<LocalType<T>> {}
|
||||||
|
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: only traits defined in the current crate can be implemented for arbitrary types
|
||||||
|
|
||||||
|
impl<T> foo::Foo<LocalType<T>> for bar::Bar<T> {}
|
||||||
|
|
||||||
|
impl<T> foo::Foo<bar::Bar<LocalType<T>>> for bar::Bar<LocalType<T>> {}
|
||||||
|
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: only traits defined in the current crate can be implemented for arbitrary types
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fundamental() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- /foo.rs crate:foo
|
||||||
|
pub trait Foo<T> {}
|
||||||
|
//- /bar.rs crate:bar
|
||||||
|
pub struct Bar<T>(T);
|
||||||
|
#[lang = "owned_box"]
|
||||||
|
#[fundamental]
|
||||||
|
pub struct Box<T>(T);
|
||||||
|
//- /main.rs crate:main deps:foo,bar
|
||||||
|
struct LocalType;
|
||||||
|
impl<T> foo::Foo<T> for bar::Box<T> {}
|
||||||
|
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: only traits defined in the current crate can be implemented for arbitrary types
|
||||||
|
impl<T> foo::Foo<T> for &LocalType {}
|
||||||
|
impl<T> foo::Foo<T> for bar::Box<LocalType> {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dyn_object() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- /foo.rs crate:foo
|
||||||
|
pub trait Foo<T> {}
|
||||||
|
//- /bar.rs crate:bar
|
||||||
|
pub struct Bar;
|
||||||
|
//- /main.rs crate:main deps:foo,bar
|
||||||
|
trait LocalTrait {}
|
||||||
|
impl<T> foo::Foo<T> for dyn LocalTrait {}
|
||||||
|
impl<T> foo::Foo<dyn LocalTrait> for Bar {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -278,6 +278,7 @@ struct Foo;
|
|||||||
struct Bar;
|
struct Bar;
|
||||||
impl core::ops::Deref for Foo {
|
impl core::ops::Deref for Foo {
|
||||||
type Target = Bar;
|
type Target = Bar;
|
||||||
|
fn deref(&self) -> &Self::Target { loop {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -290,6 +291,7 @@ struct Foo;
|
|||||||
struct Bar;
|
struct Bar;
|
||||||
impl core::ops::Deref for Foo {
|
impl core::ops::Deref for Foo {
|
||||||
type Target = Bar;
|
type Target = Bar;
|
||||||
|
fn deref(&self) -> &Self::Target { loop {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -737,6 +739,21 @@ fn f() -> i32 {
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
fn g() { return; }
|
fn g() { return; }
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn smoke_test_inner_items() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
fn f() {
|
||||||
|
fn inner() -> i32 {
|
||||||
|
return;
|
||||||
|
// ^^^^^^ error: expected i32, found ()
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,9 @@ mod handlers {
|
|||||||
pub(crate) mod private_assoc_item;
|
pub(crate) mod private_assoc_item;
|
||||||
pub(crate) mod private_field;
|
pub(crate) mod private_field;
|
||||||
pub(crate) mod replace_filter_map_next_with_find_map;
|
pub(crate) mod replace_filter_map_next_with_find_map;
|
||||||
|
pub(crate) mod trait_impl_orphan;
|
||||||
|
pub(crate) mod trait_impl_incorrect_safety;
|
||||||
|
pub(crate) mod trait_impl_missing_assoc_item;
|
||||||
pub(crate) mod typed_hole;
|
pub(crate) mod typed_hole;
|
||||||
pub(crate) mod type_mismatch;
|
pub(crate) mod type_mismatch;
|
||||||
pub(crate) mod unimplemented_builtin_macro;
|
pub(crate) mod unimplemented_builtin_macro;
|
||||||
@ -225,6 +228,7 @@ pub struct DiagnosticsConfig {
|
|||||||
// FIXME: We may want to include a whole `AssistConfig` here
|
// FIXME: We may want to include a whole `AssistConfig` here
|
||||||
pub insert_use: InsertUseConfig,
|
pub insert_use: InsertUseConfig,
|
||||||
pub prefer_no_std: bool,
|
pub prefer_no_std: bool,
|
||||||
|
pub prefer_prelude: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DiagnosticsConfig {
|
impl DiagnosticsConfig {
|
||||||
@ -247,6 +251,7 @@ impl DiagnosticsConfig {
|
|||||||
skip_glob_imports: false,
|
skip_glob_imports: false,
|
||||||
},
|
},
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
|
prefer_prelude: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,6 +361,9 @@ pub fn diagnostics(
|
|||||||
AnyDiagnostic::PrivateAssocItem(d) => handlers::private_assoc_item::private_assoc_item(&ctx, &d),
|
AnyDiagnostic::PrivateAssocItem(d) => handlers::private_assoc_item::private_assoc_item(&ctx, &d),
|
||||||
AnyDiagnostic::PrivateField(d) => handlers::private_field::private_field(&ctx, &d),
|
AnyDiagnostic::PrivateField(d) => handlers::private_field::private_field(&ctx, &d),
|
||||||
AnyDiagnostic::ReplaceFilterMapNextWithFindMap(d) => handlers::replace_filter_map_next_with_find_map::replace_filter_map_next_with_find_map(&ctx, &d),
|
AnyDiagnostic::ReplaceFilterMapNextWithFindMap(d) => handlers::replace_filter_map_next_with_find_map::replace_filter_map_next_with_find_map(&ctx, &d),
|
||||||
|
AnyDiagnostic::TraitImplIncorrectSafety(d) => handlers::trait_impl_incorrect_safety::trait_impl_incorrect_safety(&ctx, &d),
|
||||||
|
AnyDiagnostic::TraitImplMissingAssocItems(d) => handlers::trait_impl_missing_assoc_item::trait_impl_missing_assoc_item(&ctx, &d),
|
||||||
|
AnyDiagnostic::TraitImplOrphan(d) => handlers::trait_impl_orphan::trait_impl_orphan(&ctx, &d),
|
||||||
AnyDiagnostic::TypedHole(d) => handlers::typed_hole::typed_hole(&ctx, &d),
|
AnyDiagnostic::TypedHole(d) => handlers::typed_hole::typed_hole(&ctx, &d),
|
||||||
AnyDiagnostic::TypeMismatch(d) => handlers::type_mismatch::type_mismatch(&ctx, &d),
|
AnyDiagnostic::TypeMismatch(d) => handlers::type_mismatch::type_mismatch(&ctx, &d),
|
||||||
AnyDiagnostic::UndeclaredLabel(d) => handlers::undeclared_label::undeclared_label(&ctx, &d),
|
AnyDiagnostic::UndeclaredLabel(d) => handlers::undeclared_label::undeclared_label(&ctx, &d),
|
||||||
|
@ -5,7 +5,7 @@ use expect_test::Expect;
|
|||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::AssistResolveStrategy,
|
assists::AssistResolveStrategy,
|
||||||
base_db::{fixture::WithFixture, SourceDatabaseExt},
|
base_db::{fixture::WithFixture, SourceDatabaseExt},
|
||||||
RootDatabase,
|
LineIndexDatabase, RootDatabase,
|
||||||
};
|
};
|
||||||
use stdx::trim_indent;
|
use stdx::trim_indent;
|
||||||
use test_utils::{assert_eq_text, extract_annotations, MiniCore};
|
use test_utils::{assert_eq_text, extract_annotations, MiniCore};
|
||||||
@ -43,7 +43,8 @@ fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
|
|||||||
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id)
|
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id)
|
||||||
.pop()
|
.pop()
|
||||||
.expect("no diagnostics");
|
.expect("no diagnostics");
|
||||||
let fix = &diagnostic.fixes.expect("diagnostic misses fixes")[nth];
|
let fix =
|
||||||
|
&diagnostic.fixes.expect(&format!("{:?} diagnostic misses fixes", diagnostic.code))[nth];
|
||||||
let actual = {
|
let actual = {
|
||||||
let source_change = fix.source_change.as_ref().unwrap();
|
let source_change = fix.source_change.as_ref().unwrap();
|
||||||
let file_id = *source_change.source_file_edits.keys().next().unwrap();
|
let file_id = *source_change.source_file_edits.keys().next().unwrap();
|
||||||
@ -103,6 +104,7 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
|
|||||||
pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixture: &str) {
|
pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixture: &str) {
|
||||||
let (db, files) = RootDatabase::with_many_files(ra_fixture);
|
let (db, files) = RootDatabase::with_many_files(ra_fixture);
|
||||||
for file_id in files {
|
for file_id in files {
|
||||||
|
let line_index = db.line_index(file_id);
|
||||||
let diagnostics = super::diagnostics(&db, &config, &AssistResolveStrategy::All, file_id);
|
let diagnostics = super::diagnostics(&db, &config, &AssistResolveStrategy::All, file_id);
|
||||||
|
|
||||||
let expected = extract_annotations(&db.file_text(file_id));
|
let expected = extract_annotations(&db.file_text(file_id));
|
||||||
@ -136,8 +138,16 @@ pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixtur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
let fneg = expected.iter().filter(|x| !actual.contains(x)).collect::<Vec<_>>();
|
let fneg = expected
|
||||||
let fpos = actual.iter().filter(|x| !expected.contains(x)).collect::<Vec<_>>();
|
.iter()
|
||||||
|
.filter(|x| !actual.contains(x))
|
||||||
|
.map(|(range, s)| (line_index.line_col(range.start()), range, s))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let fpos = actual
|
||||||
|
.iter()
|
||||||
|
.filter(|x| !expected.contains(x))
|
||||||
|
.map(|(range, s)| (line_index.line_col(range.start()), range, s))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
panic!("Diagnostic test failed.\nFalse negatives: {fneg:?}\nFalse positives: {fpos:?}");
|
panic!("Diagnostic test failed.\nFalse negatives: {fneg:?}\nFalse positives: {fpos:?}");
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
nohash-hasher.workspace = true
|
nohash-hasher.workspace = true
|
||||||
|
|
||||||
|
@ -651,7 +651,7 @@ impl Match {
|
|||||||
for (path, resolved_path) in &template.resolved_paths {
|
for (path, resolved_path) in &template.resolved_paths {
|
||||||
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
||||||
let mod_path =
|
let mod_path =
|
||||||
module.find_use_path(sema.db, module_def, false).ok_or_else(|| {
|
module.find_use_path(sema.db, module_def, false, true).ok_or_else(|| {
|
||||||
match_error!("Failed to render template path `{}` at match location")
|
match_error!("Failed to render template path `{}` at match location")
|
||||||
})?;
|
})?;
|
||||||
self.rendered_template_paths.insert(path.clone(), mod_path);
|
self.rendered_template_paths.insert(path.clone(), mod_path);
|
||||||
|
@ -14,9 +14,9 @@ doctest = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
crossbeam-channel = "0.5.5"
|
crossbeam-channel = "0.5.5"
|
||||||
either = "1.7.0"
|
either.workspace = true
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
oorandom = "11.1.3"
|
oorandom = "11.1.3"
|
||||||
pulldown-cmark-to-cmark = "10.0.4"
|
pulldown-cmark-to-cmark = "10.0.4"
|
||||||
pulldown-cmark = { version = "0.9.1", default-features = false }
|
pulldown-cmark = { version = "0.9.1", default-features = false }
|
||||||
|
@ -14,12 +14,12 @@ pub struct ExpandedMacro {
|
|||||||
|
|
||||||
// Feature: Expand Macro Recursively
|
// Feature: Expand Macro Recursively
|
||||||
//
|
//
|
||||||
// Shows the full macro expansion of the macro at current cursor.
|
// Shows the full macro expansion of the macro at the current caret position.
|
||||||
//
|
//
|
||||||
// |===
|
// |===
|
||||||
// | Editor | Action Name
|
// | Editor | Action Name
|
||||||
//
|
//
|
||||||
// | VS Code | **rust-analyzer: Expand macro recursively**
|
// | VS Code | **rust-analyzer: Expand macro recursively at caret**
|
||||||
// |===
|
// |===
|
||||||
//
|
//
|
||||||
// image::https://user-images.githubusercontent.com/48062697/113020648-b3973180-917a-11eb-84a9-ecb921293dc5.gif[]
|
// image::https://user-images.githubusercontent.com/48062697/113020648-b3973180-917a-11eb-84a9-ecb921293dc5.gif[]
|
||||||
|
@ -1136,7 +1136,9 @@ impl Thing {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct Thing
|
struct Thing {
|
||||||
|
x: u32,
|
||||||
|
}
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -1155,7 +1157,9 @@ impl Thing {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct Thing
|
struct Thing {
|
||||||
|
x: u32,
|
||||||
|
}
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -1174,7 +1178,9 @@ impl Thing {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
enum Thing
|
enum Thing {
|
||||||
|
A,
|
||||||
|
}
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -1193,7 +1199,9 @@ impl Thing {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
enum Thing
|
enum Thing {
|
||||||
|
A,
|
||||||
|
}
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -2005,7 +2013,10 @@ fn test_hover_layout_of_enum() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
enum Foo // size = 16 (0x10), align = 8, niches = 254
|
enum Foo {
|
||||||
|
Variant1(u8, u16),
|
||||||
|
Variant2(i32, u8, i64),
|
||||||
|
} // size = 16 (0x10), align = 8, niches = 254
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -2346,7 +2357,7 @@ fn main() { let s$0t = S{ f1:0 }; }
|
|||||||
focus_range: 7..8,
|
focus_range: 7..8,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S",
|
description: "struct S {\n f1: u32,\n}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2379,7 +2390,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
|
|||||||
focus_range: 24..25,
|
focus_range: 24..25,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S<T>",
|
description: "struct S<T> {\n f1: T,\n}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -2392,7 +2403,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
|
|||||||
focus_range: 7..10,
|
focus_range: 7..10,
|
||||||
name: "Arg",
|
name: "Arg",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct Arg",
|
description: "struct Arg(u32);",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2438,7 +2449,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
|
|||||||
focus_range: 24..25,
|
focus_range: 24..25,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S<T>",
|
description: "struct S<T> {\n f1: T,\n}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -2451,7 +2462,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
|
|||||||
focus_range: 7..10,
|
focus_range: 7..10,
|
||||||
name: "Arg",
|
name: "Arg",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct Arg",
|
description: "struct Arg(u32);",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2487,7 +2498,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
|
|||||||
focus_range: 7..8,
|
focus_range: 7..8,
|
||||||
name: "A",
|
name: "A",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct A",
|
description: "struct A(u32);",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -2500,7 +2511,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
|
|||||||
focus_range: 22..23,
|
focus_range: 22..23,
|
||||||
name: "B",
|
name: "B",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct B",
|
description: "struct B(u32);",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -2514,7 +2525,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
|
|||||||
name: "C",
|
name: "C",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
container_name: "M",
|
container_name: "M",
|
||||||
description: "pub struct C",
|
description: "pub struct C(u32);",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2704,7 +2715,7 @@ fn main() { let s$0t = foo(); }
|
|||||||
focus_range: 39..41,
|
focus_range: 39..41,
|
||||||
name: "S1",
|
name: "S1",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S1",
|
description: "struct S1 {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -2717,7 +2728,7 @@ fn main() { let s$0t = foo(); }
|
|||||||
focus_range: 52..54,
|
focus_range: 52..54,
|
||||||
name: "S2",
|
name: "S2",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S2",
|
description: "struct S2 {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2808,7 +2819,7 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {}
|
|||||||
focus_range: 36..37,
|
focus_range: 36..37,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S",
|
description: "struct S {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2908,7 +2919,7 @@ fn foo(ar$0g: &impl Foo<S>) {}
|
|||||||
focus_range: 23..24,
|
focus_range: 23..24,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S",
|
description: "struct S {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -2945,7 +2956,7 @@ fn main() { let s$0t = foo(); }
|
|||||||
focus_range: 49..50,
|
focus_range: 49..50,
|
||||||
name: "B",
|
name: "B",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct B<T>",
|
description: "struct B<T> {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -3034,7 +3045,7 @@ fn foo(ar$0g: &dyn Foo<S>) {}
|
|||||||
focus_range: 23..24,
|
focus_range: 23..24,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S",
|
description: "struct S {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -3082,7 +3093,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
|
|||||||
focus_range: 50..51,
|
focus_range: 50..51,
|
||||||
name: "B",
|
name: "B",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct B<T>",
|
description: "struct B<T> {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HoverGotoTypeData {
|
HoverGotoTypeData {
|
||||||
@ -3108,7 +3119,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
|
|||||||
focus_range: 65..66,
|
focus_range: 65..66,
|
||||||
name: "S",
|
name: "S",
|
||||||
kind: Struct,
|
kind: Struct,
|
||||||
description: "struct S",
|
description: "struct S {}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -3335,7 +3346,7 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct ST<const C: usize = 1, T = Foo>
|
struct ST<const C: usize = 1, T = Foo>(T);
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -3356,7 +3367,7 @@ struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct ST<const C: usize = {const}, T = Foo>
|
struct ST<const C: usize = {const}, T = Foo>(T);
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -3378,7 +3389,7 @@ struct S$0T<const C: usize = VAL, T = Foo>(T);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct ST<const C: usize = VAL, T = Foo>
|
struct ST<const C: usize = VAL, T = Foo>(T);
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -5935,7 +5946,7 @@ pub struct Foo(i32);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub struct Foo // size = 4, align = 4
|
pub struct Foo(i32); // size = 4, align = 4
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -563,6 +563,7 @@ mod tests {
|
|||||||
use hir::ClosureStyle;
|
use hir::ClosureStyle;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use test_utils::extract_annotations;
|
use test_utils::extract_annotations;
|
||||||
|
use text_edit::{TextRange, TextSize};
|
||||||
|
|
||||||
use crate::inlay_hints::{AdjustmentHints, AdjustmentHintsMode};
|
use crate::inlay_hints::{AdjustmentHints, AdjustmentHintsMode};
|
||||||
use crate::DiscriminantHints;
|
use crate::DiscriminantHints;
|
||||||
@ -629,6 +630,22 @@ mod tests {
|
|||||||
expect.assert_debug_eq(&inlay_hints)
|
expect.assert_debug_eq(&inlay_hints)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub(super) fn check_expect_clear_loc(
|
||||||
|
config: InlayHintsConfig,
|
||||||
|
ra_fixture: &str,
|
||||||
|
expect: Expect,
|
||||||
|
) {
|
||||||
|
let (analysis, file_id) = fixture::file(ra_fixture);
|
||||||
|
let mut inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap();
|
||||||
|
inlay_hints.iter_mut().flat_map(|hint| &mut hint.label.parts).for_each(|hint| {
|
||||||
|
if let Some(loc) = &mut hint.linked_location {
|
||||||
|
loc.range = TextRange::empty(TextSize::from(0));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect.assert_debug_eq(&inlay_hints)
|
||||||
|
}
|
||||||
|
|
||||||
/// Computes inlay hints for the fixture, applies all the provided text edits and then runs
|
/// Computes inlay hints for the fixture, applies all the provided text edits and then runs
|
||||||
/// expect test.
|
/// expect test.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -78,7 +78,9 @@ mod tests {
|
|||||||
use expect_test::expect;
|
use expect_test::expect;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
inlay_hints::tests::{check_expect, check_with_config, DISABLED_CONFIG, TEST_CONFIG},
|
inlay_hints::tests::{
|
||||||
|
check_expect, check_expect_clear_loc, check_with_config, DISABLED_CONFIG, TEST_CONFIG,
|
||||||
|
},
|
||||||
InlayHintsConfig,
|
InlayHintsConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -444,7 +446,7 @@ fn main() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn shorten_iterator_chaining_hints() {
|
fn shorten_iterator_chaining_hints() {
|
||||||
check_expect(
|
check_expect_clear_loc(
|
||||||
InlayHintsConfig { chaining_hints: true, ..DISABLED_CONFIG },
|
InlayHintsConfig { chaining_hints: true, ..DISABLED_CONFIG },
|
||||||
r#"
|
r#"
|
||||||
//- minicore: iterators
|
//- minicore: iterators
|
||||||
@ -484,7 +486,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 10752..10760,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
@ -497,7 +499,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 10784..10788,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
@ -522,7 +524,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 10752..10760,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
@ -535,7 +537,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 10784..10788,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
@ -560,7 +562,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 10752..10760,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
@ -573,7 +575,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 10784..10788,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
@ -598,7 +600,7 @@ fn main() {
|
|||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
range: 24..30,
|
range: 0..0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
|
@ -683,6 +683,32 @@ enum Foo {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_self() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct S$0<T> {
|
||||||
|
t: PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> S<T> {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
t: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
S Struct FileId(0) 0..38 7..8
|
||||||
|
|
||||||
|
FileId(0) 48..49
|
||||||
|
FileId(0) 71..75
|
||||||
|
FileId(0) 86..90
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_all_refs_two_modules() {
|
fn test_find_all_refs_two_modules() {
|
||||||
check(
|
check(
|
||||||
|
@ -11,13 +11,13 @@ authors.workspace = true
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.62"
|
anyhow.workspace = true
|
||||||
crossbeam-channel = "0.5.5"
|
crossbeam-channel = "0.5.5"
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
|
|
||||||
ide.workspace = true
|
ide.workspace = true
|
||||||
ide-db.workspace =true
|
ide-db.workspace = true
|
||||||
proc-macro-api.workspace = true
|
proc-macro-api.workspace = true
|
||||||
project-model.workspace = true
|
project-model.workspace = true
|
||||||
tt.workspace = true
|
tt.workspace = true
|
||||||
|
@ -208,6 +208,7 @@ impl ProjectFolders {
|
|||||||
let entry = {
|
let entry = {
|
||||||
let mut dirs = vfs::loader::Directories::default();
|
let mut dirs = vfs::loader::Directories::default();
|
||||||
dirs.extensions.push("rs".into());
|
dirs.extensions.push("rs".into());
|
||||||
|
dirs.extensions.push("toml".into());
|
||||||
dirs.include.extend(root.include);
|
dirs.include.extend(root.include);
|
||||||
dirs.exclude.extend(root.exclude);
|
dirs.exclude.extend(root.exclude);
|
||||||
for excl in global_excludes {
|
for excl in global_excludes {
|
||||||
|
@ -15,7 +15,7 @@ doctest = false
|
|||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
tracing = "0.1.35"
|
tracing.workspace = true
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
syntax.workspace = true
|
syntax.workspace = true
|
||||||
|
@ -2,11 +2,6 @@
|
|||||||
//! It is intended to be completely decoupled from the
|
//! It is intended to be completely decoupled from the
|
||||||
//! parser, so as to allow to evolve the tree representation
|
//! parser, so as to allow to evolve the tree representation
|
||||||
//! and the parser algorithm independently.
|
//! and the parser algorithm independently.
|
||||||
//!
|
|
||||||
//! The `TreeSink` trait is the bridge between the parser and the
|
|
||||||
//! tree builder: the parser produces a stream of events like
|
|
||||||
//! `start node`, `finish node`, and `FileBuilder` converts
|
|
||||||
//! this stream to a real tree.
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -21,7 +21,7 @@ object = { version = "0.32.0", default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json = { workspace = true, features = ["unbounded_depth"] }
|
serde_json = { workspace = true, features = ["unbounded_depth"] }
|
||||||
tracing = "0.1.37"
|
tracing.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
memmap2 = "0.5.4"
|
memmap2 = "0.5.4"
|
||||||
snap = "1.1.0"
|
snap = "1.1.0"
|
||||||
|
@ -12,7 +12,7 @@ rust-version.workspace = true
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cargo_metadata = "0.15.0"
|
cargo_metadata.workspace = true
|
||||||
|
|
||||||
proc-macro-test-impl = { path = "imp", version = "0.0.0" }
|
proc-macro-test-impl = { path = "imp", version = "0.0.0" }
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ doctest = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
libc = "0.2.135"
|
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
|
libc.workspace = true
|
||||||
countme = { version = "3.0.1", features = ["enable"] }
|
countme = { version = "3.0.1", features = ["enable"] }
|
||||||
jemalloc-ctl = { version = "0.5.0", package = "tikv-jemalloc-ctl", optional = true }
|
jemalloc-ctl = { version = "0.5.0", package = "tikv-jemalloc-ctl", optional = true }
|
||||||
|
|
||||||
|
@ -12,16 +12,16 @@ rust-version.workspace = true
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "0.1.35"
|
anyhow.workspace = true
|
||||||
|
cargo_metadata.workspace = true
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
cargo_metadata = "0.15.0"
|
|
||||||
semver = "1.0.14"
|
semver = "1.0.14"
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
tracing.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
anyhow = "1.0.62"
|
|
||||||
la-arena.workspace = true
|
la-arena.workspace = true
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
base-db.workspace = true
|
base-db.workspace = true
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user