Skip to content

Subtree update of rust-analyzer #134170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 152 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
95bf875
Fix a bug when synthetic AST node were searched in the AST ID map and…
ChayimFriedman2 Nov 25, 2024
f091ec6
Migrate `add_turbo_fish` to `SyntaxEditor`
ShoyuVanilla Nov 24, 2024
c876903
Add macro expansion test for raw variable names
Nov 26, 2024
4866fb4
Revert #18197
alibektas Nov 26, 2024
c33c951
Remove target.is_some() to handle it later inside ra::flycheck
alibektas Nov 26, 2024
f3d83ba
Preparing for merge from rust-lang/rust
lnicola Nov 28, 2024
ad6e993
Merge from rust-lang/rust
lnicola Nov 28, 2024
0d2b785
Merge pull request #18567 from lnicola/sync-from-rust
lnicola Nov 28, 2024
fb662a2
Remove redundant associated type bounds from dyn
compiler-errors Nov 30, 2024
b747197
Merge pull request #18577 from compiler-errors/redundant-dyn-atb
lnicola Nov 30, 2024
5a52142
Fix debug configuration querying not inheriting environment
Veykril Dec 2, 2024
0946570
Merge pull request #18586 from Veykril/push-kolxkxyntxtt
Veykril Dec 2, 2024
03ae70d
fix: Fix syntax fixup inserting unnecessary semicolons
Veykril Dec 2, 2024
54a1a96
Merge pull request #18587 from Veykril/push-urrlrursyrws
Veykril Dec 2, 2024
86387c8
Merge pull request #18561 from markmurphydev/macro_name_raw_variable
Veykril Dec 2, 2024
aede6e1
Advertise completions and inlay hints resolve server capabilities bas…
SomeoneToIgnore Dec 3, 2024
f555fc4
Merge pull request #18589 from SomeoneToIgnore/proper-resolve-adverti…
Veykril Dec 3, 2024
97feb03
Only show status bar item in relevant files
darichey Dec 3, 2024
f4c968a
Merge pull request #18592 from darichey/status-bar-visibility
Veykril Dec 3, 2024
fef7ca0
Merge pull request #18555 from ChayimFriedman2/issue-17321
Veykril Dec 3, 2024
879312e
Support `AsyncFnX` traits
ChayimFriedman2 Dec 3, 2024
b94c535
internal: Make exclude characters for typing assists configurable, de…
tareknaser Nov 17, 2024
68cd579
chore: deprecate `typing.autoClosingAngleBrackets` configuration
tareknaser Dec 3, 2024
337725d
Remove references to platform-intrinsic ABI
Dec 3, 2024
bc00304
Fixed another bug with glob imports
ChayimFriedman2 Dec 4, 2024
0d328a8
Improve soundness a bit by making `TaggedArcPtr::try_as_arc_owned()` …
ChayimFriedman2 Dec 4, 2024
45f0e81
Fix shadowing of record enum variant in patterns
ChayimFriedman2 Dec 4, 2024
01870ba
Merge pull request #18606 from ChayimFriedman2/improve-soundness-just…
lnicola Dec 4, 2024
941616e
Merge pull request #18607 from ChayimFriedman2/pattern-record-no-record
lnicola Dec 4, 2024
272aeca
Merge pull request #18595 from markmurphydev/remove_platform_intrinsic
lnicola Dec 4, 2024
c1c6e71
Merge pull request #18605 from ChayimFriedman2/wildcard-imports
Veykril Dec 4, 2024
d83f0fe
Merge pull request #18522 from tareknaser/configure_typing_exclude_chars
Veykril Dec 4, 2024
05aac8c
Better parser recovery for incomplete attributes
Veykril Dec 4, 2024
7efe7eb
fix: Don't create empty path nodes
Veykril Dec 4, 2024
1e47f7d
Update mbe test output
Veykril Dec 4, 2024
2f3e352
Merge pull request #18608 from Veykril/push-rrozmpnyknkx
Veykril Dec 4, 2024
d2ee916
Complete derive helper attributes
ChayimFriedman2 Dec 3, 2024
9296578
Extend reported unsafe operations
ChayimFriedman2 Dec 4, 2024
0370527
Merge pull request #18604 from ChayimFriedman2/complete-helpers
Veykril Dec 4, 2024
1b54eea
Merge pull request #18609 from ChayimFriedman2/unsafe-coverage
Veykril Dec 4, 2024
baf4862
feat: migrate `sort_items` assist to use `SyntaxFactory`
tareknaser Nov 27, 2024
a1fa497
refactor: change target parameter to a reference in add_rewrite method
tareknaser Dec 4, 2024
2b4dc9c
Fix parsing of parenthesized type args and RTN
Veykril Dec 3, 2024
609621d
Merge pull request #18593 from Veykril/push-nokqpzuqtmww
Veykril Dec 4, 2024
2a949d8
Store some hir_def Paths in the type ref source maps
ChayimFriedman2 Nov 19, 2024
63acf60
Lay the foundation for diagnostics in ty lowering, and implement a fi…
ChayimFriedman2 Nov 20, 2024
1aae522
Complete diagnostics in ty lowering groundwork
ChayimFriedman2 Nov 21, 2024
61e8403
feat: migrate introduce_named_generic assist to use SyntaxFactory
tareknaser Oct 28, 2024
7fa84a3
fix: remove make_mut from introduce_named_generic assist
tareknaser Oct 28, 2024
797eb3e
define syntax_editor_add_generic_param
tareknaser Oct 30, 2024
54b597c
fix: implement `syntax_editor_create_generic_param_list`
tareknaser Nov 12, 2024
e275203
fix: refactor syntax_editor_add_generic_param to handle new generic p…
tareknaser Nov 22, 2024
cfd5f7a
fix: refactor `syntax_editor_add_generic_param` to handle adding new …
tareknaser Nov 27, 2024
e7fd49c
fix: refactor `syntax_editor_add_generic_param`
tareknaser Dec 3, 2024
d453198
fix: correct token type for closing angle bracket
tareknaser Dec 3, 2024
b1e0d31
fix: refactor `introduce_named_generic` assist
tareknaser Dec 4, 2024
60e0e02
refactor: move editing for ast using `SyntaxEditor` to a separate file
tareknaser Dec 4, 2024
39aab98
Merge pull request #18541 from ChayimFriedman2/different-generic-args
Veykril Dec 4, 2024
d5f3ed8
Do not report warnings from proc macros, ever
ChayimFriedman2 Dec 4, 2024
6120a8a
fix: update `introduce_named_generic` to use `type_param` directly
tareknaser Dec 4, 2024
3640db2
Merge pull request #18611 from ChayimFriedman2/proc-macro-warn
Veykril Dec 4, 2024
a9afc99
Disable `<` typing handler again
Veykril Dec 5, 2024
b8db0c5
Merge pull request #18616 from Veykril/push-pkumxswtxspo
Veykril Dec 5, 2024
0a99a9f
fix: rename `syntax_editor_add_generic_param` to `add_generic_param`
tareknaser Dec 5, 2024
a19e1df
fix: Fix parsing of integer/keyword name refs in various places
Veykril Dec 5, 2024
4883a12
Merge pull request #18618 from Veykril/push-ysklqzomkyvp
Veykril Dec 5, 2024
7038073
fix: Panic when displaying generic params with defaults
ShoyuVanilla Dec 5, 2024
f9351a8
Merge pull request #18619 from ShoyuVanilla/issue-18613
Veykril Dec 5, 2024
085ea34
Parse lifetime bounds in lifetime param into TypeBoundList
Veykril Dec 5, 2024
0d8e511
Merge pull request #18620 from Veykril/push-pyulxnouvxkq
Veykril Dec 5, 2024
64832b0
fix: Resolve generic parameters within use captures
Veykril Dec 5, 2024
f31547d
Merge pull request #18621 from Veykril/push-suuyuvsmqpyq
Veykril Dec 5, 2024
6ef7f8e
Merge pull request #18483 from tareknaser/syntax_factory_introduce_na…
davidbarsky Dec 5, 2024
23339cb
Merge pull request #18538 from tareknaser/syntax_factory_sort_items
davidbarsky Dec 5, 2024
59a5b38
fix: Fix parsing of dyn T in generic arg on 2015 edition
Veykril Dec 5, 2024
d5c7e64
Merge pull request #18622 from Veykril/push-wlzptrukvyup
Veykril Dec 5, 2024
3db9b1d
fix: Fix parser getting stuck for bad asm expressions
Veykril Dec 6, 2024
c2253c2
Merge pull request #18625 from Veykril/push-npnxwpxuzlqz
Veykril Dec 6, 2024
069fb0f
Make bracket typing handler work on more things
Veykril Nov 4, 2024
2c91563
Add implict unsafety inlay hints for extern blocks
Veykril Dec 4, 2024
0267610
Merge pull request #18610 from Veykril/push-kynytqktmnxq
Veykril Dec 6, 2024
b4dc94d
Merge pull request #18474 from Veykril/push-nvtxykxkwnvs
Veykril Dec 6, 2024
8466efc
Merge pull request #18594 from ChayimFriedman2/async-closures
Veykril Dec 6, 2024
0631f46
Merge pull request #18563 from alibektas/workspace_key_high_precedence
Veykril Dec 6, 2024
2a06000
Merge pull request #18551 from ShoyuVanilla/migrate-turbofish-assist
Veykril Dec 6, 2024
a086560
Improve heuristics for on typing semicolon insertion
Veykril Dec 6, 2024
9549e47
Merge pull request #18627 from Veykril/push-tzvnrnytrksr
Veykril Dec 6, 2024
3fe75c7
Add typing handler for param list pipe
Veykril Dec 6, 2024
fbd6713
fix: Properly determine `SyntaxEditor` replacement intersection
Giga-Bowser Nov 17, 2024
25c0a00
fix: Don't produce `ChangedAncestor` for `SyntaxToken`s
Giga-Bowser Nov 17, 2024
8877598
minor: Add `token` constructor to `SyntaxFactory`
Giga-Bowser Nov 21, 2024
0eed197
minor: Add `expr_bin` constructor to `SyntaxFactory`
Giga-Bowser Nov 21, 2024
ff6b020
feat: Migrate `flip_binexpr` assist to `SyntaxEditor`
Giga-Bowser Nov 21, 2024
418ad88
feat: Migrate `flip_trait_bound` assist to `SyntaxEditor`
Giga-Bowser Nov 22, 2024
806ffb7
minor: Add `token_tree` constructor to `SyntaxFactory`
Giga-Bowser Nov 23, 2024
254198c
feat: Migrate `flip_comma` assist to `SyntaxEditor`
Giga-Bowser Nov 23, 2024
5b2fcf3
Merge pull request #18628 from Veykril/push-sqpymrtxysmw
Veykril Dec 6, 2024
667697e
Highlight right angle as part of fat arrow in macro rules arm
Veykril Dec 6, 2024
fb79ab7
Merge pull request #18629 from Veykril/push-wlsvxwomumpp
Veykril Dec 6, 2024
29a6631
Temporarily disable completion resolve support for helix
Veykril Dec 6, 2024
78496f8
Temporarily disable completion resolve support for neovim
Veykril Dec 6, 2024
998f978
Merge pull request #18630 from Veykril/push-ystzsxpywnxn
Veykril Dec 7, 2024
8358c13
Merge pull request #18575 from Giga-Bowser/flip-assists
Veykril Dec 7, 2024
afdf4c8
Watch for user config ratoml
alibektas Aug 25, 2024
1907786
Coerce two `FnDef`s to fn pointers even if they are the same, if they…
ChayimFriedman2 Dec 7, 2024
7625d76
Merge pull request #18633 from ChayimFriedman2/unify-fn
Veykril Dec 8, 2024
ee30005
Fix a test that didn't test what it should
ChayimFriedman2 Dec 8, 2024
30e3d23
fix: Map new replacement nodes to their mutable equivalents in `Synta…
Giga-Bowser Nov 18, 2024
b4c83da
Merge pull request #18531 from Giga-Bowser/map-new-nodes
Veykril Dec 9, 2024
c6e8a0e
Merge pull request #18635 from ChayimFriedman2/fix-test
Veykril Dec 9, 2024
3fc7101
Fix config guard lock for ratoml tests
Veykril Oct 30, 2024
c7b6c95
Merge pull request #18441 from Veykril/lw-psyvmlotlvqn
Veykril Dec 9, 2024
4148b53
Remove unstable attributes in minicore
lnicola Dec 9, 2024
be43a67
Merge pull request #18642 from lnicola/rm-minicore-unstable
lnicola Dec 9, 2024
b9f809a
Rename test fixture crates to ra_test_fixture
Veykril Dec 9, 2024
770265d
Remove patch sysroot cfg-if hack
Veykril Dec 9, 2024
dc9bcef
Merge pull request #18643 from Veykril/push-muwuzmowptnn
Veykril Dec 9, 2024
641bca6
Merge pull request #18644 from Veykril/push-nolvpzqvoqwx
Veykril Dec 9, 2024
67c9287
fix: Non-exhaustive structs may be empty
Veykril Dec 9, 2024
244b1fd
Merge pull request #18645 from Veykril/push-yruoyrvrsntw
Veykril Dec 9, 2024
2ad6d71
Disable pipe on typing handler
Veykril Dec 9, 2024
91adfec
Merge pull request #18647 from Veykril/push-nsrrmmnzzoym
Veykril Dec 9, 2024
ab6382e
minor: enhance name suggestion for `Arc<T>` and `Rc<T>`
roife Dec 9, 2024
cbc0069
Draft completion hashing
SomeoneToIgnore Dec 9, 2024
e8e3949
Always compute the hash when r-a wants the imports to be resolved
SomeoneToIgnore Dec 9, 2024
78ea49e
Stop excluding Helix from the general resolve path
SomeoneToIgnore Dec 9, 2024
160cb32
Unite more bool hashing
SomeoneToIgnore Dec 9, 2024
9aebb5c
crates/r-a: Fix typo in debug message
yuki0iq Dec 9, 2024
b203c73
Avoid hashing completion-related ranges as those may change during /r…
SomeoneToIgnore Dec 9, 2024
61c0b26
Clippy fixes
SomeoneToIgnore Dec 9, 2024
a73a6a0
Add diagnostic fix to remove unnecessary wrapper in type mismatch
Giga-Bowser Nov 1, 2024
4898f3f
fix: Handle the final statement in `SyntaxFactory::block_expr` properly
Giga-Bowser Nov 14, 2024
b76734f
minor: Migrate `remove_unnecessary_wrapper` to `SyntaxEditor`
Giga-Bowser Nov 15, 2024
edbfa31
Merge pull request #18650 from yuki0iq/fix-typo
lnicola Dec 10, 2024
95670ac
Merge pull request #18649 from roife/fix-issue-18648
lnicola Dec 10, 2024
f94953d
Address the feedback from Veykril
SomeoneToIgnore Dec 10, 2024
1ce1560
Address the feedback from pascalkuthe
SomeoneToIgnore Dec 10, 2024
3bc26ba
minor: Add `item_enum` constructor to `SyntaxFactory`
Giga-Bowser Dec 10, 2024
d9bb8fc
minor: Add `whitespace` constructor to `SyntaxFactory`
Giga-Bowser Dec 5, 2024
26e7e4f
minor: Add `ty_infer` constructor to `SyntaxFactory`
Giga-Bowser Dec 10, 2024
3b78166
minor: Migrate `generate_enum_variant` to `SyntaxEditor`
Giga-Bowser Dec 10, 2024
0b121ef
feat: preserve order of parameters in extract_functions
roife Dec 10, 2024
611c72f
Merge pull request #18656 from roife/fix-issue-18639
Veykril Dec 11, 2024
b20d1b8
Merge pull request #18657 from Giga-Bowser/generate-enum-variant
Veykril Dec 11, 2024
e1a27b8
Merge pull request #18653 from SomeoneToIgnore/hash-completions
Veykril Dec 11, 2024
536eea3
Merge pull request #18458 from Giga-Bowser/master
Veykril Dec 11, 2024
1649eb6
Preparing for merge from rust-lang/rust
lnicola Dec 11, 2024
5db2aa8
Merge from rust-lang/rust
lnicola Dec 11, 2024
884f57f
Bump rustc crates
lnicola Dec 11, 2024
e6fbb5c
fix: Swallow rustfmt parsing panics
Veykril Dec 11, 2024
8172088
Merge pull request #18662 from lnicola/sync-from-rust
lnicola Dec 11, 2024
a18e38e
Merge pull request #18663 from Veykril/push-syoklzkntykn
Veykril Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ dependencies = [
"vfs",
]

[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"

[[package]]
name = "bitflags"
version = "1.3.2"
Expand Down Expand Up @@ -509,6 +515,7 @@ dependencies = [
"base-db",
"cfg",
"either",
"expect-test",
"hir-def",
"hir-expand",
"hir-ty",
Expand All @@ -519,6 +526,9 @@ dependencies = [
"span",
"stdx",
"syntax",
"syntax-bridge",
"test-fixture",
"test-utils",
"tracing",
"triomphe",
"tt",
Expand Down Expand Up @@ -1492,9 +1502,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_abi"
version = "0.80.0"
version = "0.85.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613760a3071b25a67a8d7bc97b37c7fd4722562e9479137b83ae9cf8f8c1601a"
checksum = "af462c3a2d524b84a51b6848b439787f01b35c6c1086d3e3086a5f5eea92ed9a"
dependencies = [
"bitflags 2.6.0",
"ra-ap-rustc_index",
Expand All @@ -1503,20 +1513,19 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index"
version = "0.80.0"
version = "0.85.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b2bc6b4ecede8ff28295041e22c2e66853f8e0125990c05135bad3c30bad12c"
checksum = "be6bb8cb0ab78d94a222f1ffd3e87254cdfb57413382b8d6ebe26a85482f99d1"
dependencies = [
"arrayvec",
"ra-ap-rustc_index_macros",
"smallvec",
]

[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.80.0"
version = "0.85.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2374a39fb2d92d0509178c2b442eadca3cc10e403ef9729a040c1855b08ff261"
checksum = "c24b1641455b46e87435b7321219672077066e678963d239a4a2904732979b16"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -1525,29 +1534,29 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_lexer"
version = "0.80.0"
version = "0.85.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a2cf8e48b69af3ecc29ed3449892e8a999111d2f75212a78aa242e117cf1711"
checksum = "94daa86974417981fed2f12bd8fb00158dfa6fee561152bed689278c846d0272"
dependencies = [
"unicode-properties",
"unicode-xid",
]

[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.80.0"
version = "0.85.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d6f59a22b559263c5c42747ae362cf5d4fb272293fa119a4623f8ec288f9656"
checksum = "fc07f6bd581746f358e39c4b6bfe8d455b3d6ad1a857821016d0d42eeb5e1e3e"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
]

[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.80.0"
version = "0.85.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7d0575b54ffe09bc5d2f158454bc05f0c30c01d9992310965f854be50ae22b8"
checksum = "2f49b86e1276c1c3c72898410def29b699415f4e7d1dfb3531daf79794694372"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 2.0.0",
Expand Down Expand Up @@ -1645,6 +1654,7 @@ version = "0.0.0"
dependencies = [
"always-assert",
"anyhow",
"base64",
"cargo_metadata",
"cfg",
"crossbeam-channel",
Expand All @@ -1655,6 +1665,7 @@ dependencies = [
"hir-def",
"hir-ty",
"ide",
"ide-completion",
"ide-db",
"ide-ssr",
"intern",
Expand Down Expand Up @@ -1683,6 +1694,7 @@ dependencies = [
"stdx",
"syntax",
"syntax-bridge",
"tenthash",
"test-fixture",
"test-utils",
"tikv-jemallocator",
Expand Down Expand Up @@ -1986,6 +1998,12 @@ dependencies = [
"tt",
]

[[package]]
name = "tenthash"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d67f9f3cf70e0852941d7bc3cb884b49b24b8ee956baf91ad0abae31f5ef11fb"

[[package]]
name = "test-fixture"
version = "0.0.0"
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.80", default-features = false }
ra-ap-rustc_parse_format = { version = "0.80", default-features = false }
ra-ap-rustc_index = { version = "0.80", default-features = false }
ra-ap-rustc_abi = { version = "0.80", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.80", default-features = false }
ra-ap-rustc_lexer = { version = "0.85", default-features = false }
ra-ap-rustc_parse_format = { version = "0.85", default-features = false }
ra-ap-rustc_index = { version = "0.85", default-features = false }
ra-ap-rustc_abi = { version = "0.85", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.85", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.
test-fixture = { path = "./crates/test-fixture" }
Expand Down
23 changes: 0 additions & 23 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,29 +547,6 @@ impl CrateGraph {
None
}

// Work around for https://github.com/rust-lang/rust-analyzer/issues/6038.
// As hacky as it gets.
pub fn patch_cfg_if(&mut self) -> bool {
// we stupidly max by version in an attempt to have all duplicated std's depend on the same cfg_if so that deduplication still works
let cfg_if =
self.hacky_find_crate("cfg_if").max_by_key(|&it| self.arena[it].version.clone());
let std = self.hacky_find_crate("std").next();
match (cfg_if, std) {
(Some(cfg_if), Some(std)) => {
self.arena[cfg_if].dependencies.clear();
self.arena[std]
.dependencies
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
true
}
_ => false,
}
}

fn hacky_find_crate<'a>(&'a self, display_name: &'a str) -> impl Iterator<Item = CrateId> + 'a {
self.iter().filter(move |it| self[*it].display_name.as_deref() == Some(display_name))
}

/// Removes all crates from this crate graph except for the ones in `to_keep` and fixes up the dependencies.
/// Returns a mapping from old crate ids to new crate ids.
pub fn remove_crates_except(&mut self, to_keep: &[CrateId]) -> Vec<Option<CrateId>> {
Expand Down
140 changes: 133 additions & 7 deletions src/tools/rust-analyzer/crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
path::{ModPath, Path},
src::HasSource,
type_ref::{TypeRef, TypeRefId, TypesMap, TypesSourceMap},
BlockId, DefWithBodyId, HasModule, Lookup,
BlockId, DefWithBodyId, HasModule, Lookup, SyntheticSyntax,
};

/// A wrapper around [`span::SyntaxContextId`] that is intended only for comparisons.
Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct BodySourceMap {
field_map_back: FxHashMap<ExprId, FieldSource>,
pat_field_map_back: FxHashMap<PatId, PatFieldSource>,

types: TypesSourceMap,
pub types: TypesSourceMap,

// FIXME: Make this a sane struct.
template_map: Option<
Expand All @@ -160,9 +160,6 @@ pub struct BodySourceMap {
diagnostics: Vec<BodyDiagnostic>,
}

#[derive(Default, Debug, Eq, PartialEq, Clone, Copy)]
pub struct SyntheticSyntax;

#[derive(Debug, Eq, PartialEq)]
pub enum BodyDiagnostic {
InactiveCode { node: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions },
Expand Down Expand Up @@ -408,7 +405,8 @@ impl Body {
f(else_branch);
}
}
Expr::Let { expr, .. } => {
Expr::Let { expr, pat } => {
self.walk_exprs_in_pat(*pat, &mut f);
f(*expr);
}
Expr::Block { statements, tail, .. }
Expand Down Expand Up @@ -444,7 +442,10 @@ impl Body {
}
Expr::Match { expr, arms } => {
f(*expr);
arms.iter().map(|arm| arm.expr).for_each(f);
arms.iter().for_each(|arm| {
f(arm.expr);
self.walk_exprs_in_pat(arm.pat, &mut f);
});
}
Expr::Break { expr, .. }
| Expr::Return { expr }
Expand Down Expand Up @@ -505,6 +506,131 @@ impl Body {
}
}

pub fn walk_child_exprs_without_pats(&self, expr_id: ExprId, mut f: impl FnMut(ExprId)) {
let expr = &self[expr_id];
match expr {
Expr::Continue { .. }
| Expr::Const(_)
| Expr::Missing
| Expr::Path(_)
| Expr::OffsetOf(_)
| Expr::Literal(_)
| Expr::Underscore => {}
Expr::InlineAsm(it) => it.operands.iter().for_each(|(_, op)| match op {
AsmOperand::In { expr, .. }
| AsmOperand::Out { expr: Some(expr), .. }
| AsmOperand::InOut { expr, .. } => f(*expr),
AsmOperand::SplitInOut { in_expr, out_expr, .. } => {
f(*in_expr);
if let Some(out_expr) = out_expr {
f(*out_expr);
}
}
AsmOperand::Out { expr: None, .. }
| AsmOperand::Const(_)
| AsmOperand::Label(_)
| AsmOperand::Sym(_) => (),
}),
Expr::If { condition, then_branch, else_branch } => {
f(*condition);
f(*then_branch);
if let &Some(else_branch) = else_branch {
f(else_branch);
}
}
Expr::Let { expr, .. } => {
f(*expr);
}
Expr::Block { statements, tail, .. }
| Expr::Unsafe { statements, tail, .. }
| Expr::Async { statements, tail, .. } => {
for stmt in statements.iter() {
match stmt {
Statement::Let { initializer, else_branch, .. } => {
if let &Some(expr) = initializer {
f(expr);
}
if let &Some(expr) = else_branch {
f(expr);
}
}
Statement::Expr { expr: expression, .. } => f(*expression),
Statement::Item(_) => (),
}
}
if let &Some(expr) = tail {
f(expr);
}
}
Expr::Loop { body, .. } => f(*body),
Expr::Call { callee, args, .. } => {
f(*callee);
args.iter().copied().for_each(f);
}
Expr::MethodCall { receiver, args, .. } => {
f(*receiver);
args.iter().copied().for_each(f);
}
Expr::Match { expr, arms } => {
f(*expr);
arms.iter().map(|arm| arm.expr).for_each(f);
}
Expr::Break { expr, .. }
| Expr::Return { expr }
| Expr::Yield { expr }
| Expr::Yeet { expr } => {
if let &Some(expr) = expr {
f(expr);
}
}
Expr::Become { expr } => f(*expr),
Expr::RecordLit { fields, spread, .. } => {
for field in fields.iter() {
f(field.expr);
}
if let &Some(expr) = spread {
f(expr);
}
}
Expr::Closure { body, .. } => {
f(*body);
}
Expr::BinaryOp { lhs, rhs, .. } => {
f(*lhs);
f(*rhs);
}
Expr::Range { lhs, rhs, .. } => {
if let &Some(lhs) = rhs {
f(lhs);
}
if let &Some(rhs) = lhs {
f(rhs);
}
}
Expr::Index { base, index, .. } => {
f(*base);
f(*index);
}
Expr::Field { expr, .. }
| Expr::Await { expr }
| Expr::Cast { expr, .. }
| Expr::Ref { expr, .. }
| Expr::UnaryOp { expr, .. }
| Expr::Box { expr } => {
f(*expr);
}
Expr::Tuple { exprs, .. } => exprs.iter().copied().for_each(f),
Expr::Array(a) => match a {
Array::ElementList { elements, .. } => elements.iter().copied().for_each(f),
Array::Repeat { initializer, repeat } => {
f(*initializer);
f(*repeat)
}
},
&Expr::Assignment { target: _, value } => f(value),
}
}

pub fn walk_exprs_in_pat(&self, pat_id: PatId, f: &mut impl FnMut(ExprId)) {
self.walk_pats(pat_id, &mut |pat| {
if let Pat::Expr(expr) | Pat::ConstBlock(expr) = self[pat] {
Expand Down
14 changes: 7 additions & 7 deletions src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,20 +1510,20 @@ impl ExprCollector<'_> {
BuiltinShadowMode::Other,
None,
);
// Funnily enough, record structs/variants *can* be shadowed
// by pattern bindings (but unit or tuple structs/variants
// can't).
match resolved.take_values() {
Some(ModuleDefId::ConstId(_)) => (None, Pat::Path(name.into())),
Some(ModuleDefId::EnumVariantId(_)) => {
// this is only really valid for unit variants, but
// shadowing other enum variants with a pattern is
// an error anyway
Some(ModuleDefId::EnumVariantId(variant))
if self.db.variant_data(variant.into()).kind()
!= StructKind::Record =>
{
(None, Pat::Path(name.into()))
}
Some(ModuleDefId::AdtId(AdtId::StructId(s)))
if self.db.struct_data(s).variant_data.kind() != StructKind::Record =>
{
// Funnily enough, record structs *can* be shadowed
// by pattern bindings (but unit or tuple structs
// can't).
(None, Pat::Path(name.into()))
}
// shadowing statics is an error as well, so we just ignore that case here
Expand Down
Loading
Loading