Skip to content

Subtree update of rust-analyzer #135207

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 192 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
192 commits
Select commit Hold shift + click to select a range
b80bb58
Show substitution where hovering over generic things
ChayimFriedman2 Dec 17, 2024
932a6d3
Move ty lowering diagnostic definitions into a separate module
ChayimFriedman2 Dec 4, 2024
b520666
internal: Standardize how we take iterator parameters in `SyntaxFactory`
Giga-Bowser Dec 18, 2024
b35a846
change config rust-analyzer.statusBar.documentSelector to showStatusBar
Dec 19, 2024
0d5b480
Treat ; as a terminator rather than something that can be glued toget…
gbbosak Dec 22, 2024
5e7ce33
minor: Break out of waiting for debugger on Windows using native debu…
PrototypeNM1 Dec 23, 2024
417dcc4
Merge pull request #18749 from PrototypeNM1/windows-debugger-wait
Veykril Dec 24, 2024
91fb189
Remove dangling outdated test module
Veykril Dec 24, 2024
9251d42
Back out "internal: Disable rustc test metrics"
Veykril Dec 24, 2024
a63d166
Merge pull request #18750 from Veykril/push-tyvtqpwrwvsr
Veykril Dec 24, 2024
b3308bc
Merge pull request #18722 from markmurphydev/status_bar_settings
Veykril Dec 24, 2024
eb80a6b
Merge pull request #18718 from Giga-Bowser/fix-syntaxfactory-intoiter…
Veykril Dec 24, 2024
8bfb2fe
Merge pull request #18707 from ChayimFriedman2/subst
Veykril Dec 24, 2024
4be8178
Cleanup target fetching for cargo metadata
Veykril Dec 24, 2024
9d44ee1
Unify handling of path diagnostics in hir-ty
ChayimFriedman2 Dec 22, 2024
9c55462
Merge pull request #18754 from Veykril/push-zkkzxrsxnqnm
Veykril Dec 24, 2024
6d10170
Merge pull request #18743 from ChayimFriedman2/e0107
Veykril Dec 24, 2024
1287b93
fix: Fix metrics workflow using the wrong download-artifact version
Veykril Dec 24, 2024
96f068c
Merge pull request #18755 from Veykril/push-psllyxqtywzs
Veykril Dec 24, 2024
9e7d296
fix missing name enum when hovering on fields in variants
roife Dec 24, 2024
022bece
Merge pull request #18756 from roife/fix-18751
Veykril Dec 25, 2024
b1c091c
Improve SCIP symbols
mgsloan Dec 26, 2024
bbc6242
Provide SCIP `external_symbols` + fix symbols provided with Document
mgsloan Dec 26, 2024
cd8522e
Use empty `SymbolInformation.signature_documentation.relative_path`
mgsloan Dec 26, 2024
08677cb
feat: Add TestDefs to find usage of Expect, Insta and Snapbox
roife Dec 25, 2024
60b4ed5
feat: support UpdateTest in codelens
roife Dec 25, 2024
147d1dd
feat: support UpdateTest in hover actions and runnables
roife Dec 25, 2024
2bfa83b
feat: add config `UpdateTest` to hover actions
roife Dec 25, 2024
c17dea9
fix: await setting config to `not ask before UpdateTest` and format
roife Dec 25, 2024
c8f29aa
fix incorrect name for UpdateTest config
roife Dec 25, 2024
d938414
optimize snapshot-testing macro detection and add tests
roife Dec 26, 2024
d6ec360
move env vars for snapshot tests to UpdateTest
roife Dec 26, 2024
e481a51
minor: format editor/code
roife Dec 26, 2024
27dd75d
internal: Workaround salsa cycles leaking
Veykril Dec 26, 2024
ec5e485
Merge pull request #18760 from Veykril/push-tkvlvvqyszrs
Veykril Dec 26, 2024
5290f20
internal: Swallow `error: config value is not set` cargo error
Veykril Dec 26, 2024
637700e
internal: wrap `salsa::Cycle`
davidbarsky Dec 26, 2024
bae8fb5
Merge pull request #18761 from Veykril/push-vktnzltnxupr
Veykril Dec 26, 2024
352116c
Merge pull request #18762 from davidbarsky/davidbarsky/wrap-salsa-can…
Veykril Dec 26, 2024
eea4a9a
Merge pull request #18744 from gbbosak/master
Veykril Dec 27, 2024
b2531ba
fix doc typo
Erithax Dec 27, 2024
8d8b42d
Merge pull request #18770 from Erithax/patch-1
lnicola Dec 27, 2024
a239113
Update crates/ide/src/moniker.rs
mgsloan Dec 27, 2024
77d5645
Update crates/ide/src/moniker.rs
mgsloan Dec 27, 2024
df99392
Message updates from review
mgsloan Dec 28, 2024
517d52d
Only include SCIP SymbolInformation for first inherent impl
mgsloan Dec 28, 2024
171be2b
fix: Fix flycheck diagnostics flickering for binary targets
Veykril Dec 28, 2024
73ae6a0
Downgrade salsa log levels
Veykril Dec 28, 2024
873cf25
Add DynTyExt::principal_id
Veykril Dec 28, 2024
47f497d
Merge pull request #18778 from Veykril/push-oontvoqmxkno
Veykril Dec 28, 2024
4ea29d6
Implement parameter variance inference
Veykril Dec 28, 2024
0e50c3c
Remove unnecessary VarianceTerm
Veykril Dec 28, 2024
d66a337
Get rid of constrain and solve steps
Veykril Dec 28, 2024
e54cf80
Simplify
Veykril Dec 28, 2024
bf27d88
Show variance of parameters on hover
Veykril Dec 28, 2024
30fa18c
Consider `Enum::Variant` even when it comes from a different crate
ChayimFriedman2 Dec 28, 2024
a102ea1
Describe variance resolution approach differences to rustc
Veykril Dec 29, 2024
54b75a1
Merge pull request #18779 from ChayimFriedman2/enum-variant
Veykril Dec 29, 2024
1f0696d
fix: Do not merge spans if they have different anchors
Veykril Dec 29, 2024
0337e79
Merge pull request #18784 from Veykril/push-pqtwsvquxoty
Veykril Dec 29, 2024
d5f7e78
Cleanup toolchain info fetching
Veykril Dec 29, 2024
8606441
Enforce a current directory being set for spawned commands
Veykril Dec 29, 2024
a4a6a43
Split out `ProjectWorkspace::load_cargo`
Veykril Dec 29, 2024
d105253
Force a current dir to be supplied for rustc info fetching
Veykril Dec 29, 2024
d3ebb14
Merge pull request #18774 from Veykril/push-ysppqxpuknnw
Veykril Dec 29, 2024
3d9a15b
Automatically cancel CI checks on new push to same PR
Veykril Dec 29, 2024
f36a93e
Inline toolchain_info module
Veykril Dec 29, 2024
bde1322
Merge pull request #18787 from Veykril/push-uymlpukspxqr
Veykril Dec 29, 2024
b570206
Merge pull request #18785 from Veykril/push-uvsqposqyvmo
Veykril Dec 29, 2024
7f757b9
fix: Fix invalid `-O` flag used by cfg discovery
Veykril Dec 29, 2024
259eaf9
Merge pull request #18789 from Veykril/push-sypxzqsvmzzp
Veykril Dec 29, 2024
ca0c8da
Generate a method for static retrieval of the SyntaxKind of a node, w…
ChayimFriedman2 Dec 30, 2024
be12c80
Add a function to convert a SyntaxKind to its text, where possible
ChayimFriedman2 Dec 30, 2024
a0c052f
Create a `quote!`-like API for crafting AST nodes
ChayimFriedman2 Dec 30, 2024
33f1f1d
Move some more AST makers to the quote macro
ChayimFriedman2 Dec 30, 2024
9016a4c
fix: avoid generating colliding names in extract_variable
roife Dec 30, 2024
d4b53f5
Decouple proc-macro server protocol from the server implementation
Veykril Dec 30, 2024
0affbd4
Cleanup proc-macro dylib handling
Veykril Dec 30, 2024
042528a
Move proc-macro protocol into legacy module
Veykril Dec 30, 2024
a081215
Merge pull request #18791 from roife/fix-18786
Veykril Dec 30, 2024
4a1c7d1
Merge pull request #18792 from Veykril/push-wonkvzozmmwz
Veykril Dec 30, 2024
b4ad30d
Remove unneeded conversions
ChayimFriedman2 Dec 30, 2024
6fa3b3f
Fix bug of "fill match arm" action in tokio::main macro
1hakusai1 Dec 30, 2024
39ba498
Merge pull request #18793 from ChayimFriedman2/fixup
Veykril Dec 30, 2024
56e05dc
Merge pull request #18794 from 1hakusai1/fix_fill_match_arm_in_tokio_…
Veykril Dec 30, 2024
20a7bf1
Merge pull request #18790 from ChayimFriedman2/proper-make
Veykril Dec 30, 2024
a0acb23
Fix render of literal to be rendered in codeblock
dfireBird Dec 30, 2024
65bf7f7
Merge pull request #18795 from dfireBird/fix-hover-render
Veykril Dec 30, 2024
dbf07ba
refactor snapshot-tests detection in runnables
roife Dec 30, 2024
8b66221
Add test cases for #10583
profetia Dec 30, 2024
b7cdd64
Make `impl HirDisplay for TraitRef` provide just the trait type
mgsloan Dec 30, 2024
2d434dd
TODO -> FIXME
mgsloan Dec 30, 2024
96fc18a
Remove erroneous omit of inherent impls
mgsloan Dec 30, 2024
8a032e4
Move `container_to_definition` function into `enclosing_definition`
mgsloan Dec 30, 2024
f581774
feat: show go-to-type-def actions for subst when hovering
roife Dec 31, 2024
1524ab1
Merge pull request #18801 from roife/fix-18799
Veykril Dec 31, 2024
8bb0fab
Merge pull request #18758 from mgsloan/scip-unique-symbols
Veykril Dec 31, 2024
b8fdfcc
Remove recursion_limit special casing in tests
Veykril Dec 31, 2024
7468106
Implement `<RaSpanServer as SourceFile>::eq`
Veykril Dec 31, 2024
8860d07
fix: incorrect file_id used for ranges in outgoing calls
roife Dec 31, 2024
fd7ef27
Merge pull request #18805 from Veykril/push-pzurvxvoolxs
Veykril Dec 31, 2024
88e630b
Merge pull request #18802 from roife/fix-18800
Veykril Dec 31, 2024
551a91a
fix: Populate cargo config env vars for crates
Veykril Dec 31, 2024
204c8d7
Base relative cargo configs onto the manifest
Veykril Dec 31, 2024
87c733c
Merge pull request #18807 from Veykril/push-vxopsoummyzx
Veykril Dec 31, 2024
258823d
Fix replace-if-let-with-match generates non-exhausive match
profetia Dec 30, 2024
431aab1
Remove CARGO_RUSTC_CURRENT_DIR
LHolten Dec 31, 2024
5b51c4c
Add back crate graph deduplication
LHolten Dec 31, 2024
03b7eb3
Add back tests removed in #18080
LHolten Dec 31, 2024
ccbc3d2
Add back optimizations
LHolten Dec 31, 2024
1334961
Merge pull request #18797 from profetia/issue10583
ChayimFriedman2 Dec 31, 2024
c95aa86
internal: Do not render closure ids in hover messages
Veykril Jan 1, 2025
854caf3
Merge pull request #18757 from roife/fix-17812
Veykril Jan 1, 2025
bd6ea14
Allow excluding specific traits from completion
ChayimFriedman2 Sep 24, 2024
528ed6b
Allow flyimporting excluded trait items if there is an exact match in…
ChayimFriedman2 Sep 29, 2024
24699bd
Merge pull request #18809 from Veykril/push-ktwrzsmzlplw
Veykril Jan 1, 2025
13af22d
Reduce the default autoimport exclusion list
Veykril Jan 1, 2025
786056c
Simplify completion config path resolutions
Veykril Jan 1, 2025
c84d09a
Revamp auto-import exclude config
Veykril Jan 1, 2025
c15e36a
Cleanup
Veykril Jan 1, 2025
74d0d4e
Merge pull request #18179 from ChayimFriedman2/omit-trait-completion
Veykril Jan 1, 2025
48d11df
Remove load_cargo_with_fake_sysroot
LHolten Jan 1, 2025
71d996f
Fix tests
LHolten Jan 1, 2025
efbbf57
fix: Fix flycheck cancellations leaving stale errors
Veykril Jan 2, 2025
ec46a15
Merge pull request #18817 from Veykril/push-zzkkotwuyqzt
Veykril Jan 2, 2025
d93ab14
Fix overflow detection in MIR evaluation
ChayimFriedman2 Jan 2, 2025
bd33815
Merge pull request #18819 from ChayimFriedman2/i128-max
Veykril Jan 2, 2025
ac9e280
fix no space insert before and after if value is only spaces
dfireBird Jan 2, 2025
b4f865a
Merge pull request #18820 from dfireBird/fix-space-char-on-literal-re…
Veykril Jan 2, 2025
4485cbb
Automatically sort crate graph
LHolten Jan 2, 2025
943ee02
Remove rust-analyzer duplicate crates integration tests
LHolten Jan 2, 2025
acb3490
Store token trees in contiguous `Vec` instead of as a tree
ChayimFriedman2 Oct 18, 2024
369a654
allow targetDir to be an absolute path
bryceberger Jan 2, 2025
954efa9
Merge pull request #18327 from ChayimFriedman2/flat-tt
Veykril Jan 3, 2025
70ba3b5
Merge pull request #18822 from bryceberger/targetdir-absolute
Veykril Jan 3, 2025
b763a97
minor: Encode TraitData bools as bitflags
Veykril Jan 3, 2025
1ae0258
Merge pull request #18825 from Veykril/push-sllokkprznkq
Veykril Jan 3, 2025
c5c45e9
fix: Clear flycheck diagnostics per package properly
Veykril Jan 3, 2025
2e7d94b
Merge pull request #18826 from Veykril/push-qnsqormwlwqm
Veykril Jan 3, 2025
40b37ee
minor: Honor `CARGO_TARGET_DIR` for cargo target dir config
Veykril Jan 3, 2025
b18979f
Add description field to edition manifest
lnicola Jan 3, 2025
31b45b0
Merge pull request #18827 from Veykril/push-zqsplmtwsxxk
Veykril Jan 3, 2025
e4b1b55
Disable rustc_test metrics again
Veykril Jan 3, 2025
e86b247
Merge pull request #18828 from lnicola/edition-description
lnicola Jan 3, 2025
9b0aa8e
Merge pull request #18829 from Veykril/push-ouvwrxoovwkr
Veykril Jan 3, 2025
fc3e0a1
fix: 18814
alibektas Jan 3, 2025
981645b
Merge pull request #18830 from alibektas/18814
Veykril Jan 3, 2025
b2892ef
Merge pull request #18806 from LHolten/deduplicate-crate-graph
Veykril Jan 3, 2025
b7dc464
Fix metrics workflow
lnicola Jan 3, 2025
bfafdd9
Merge pull request #18831 from lnicola/ci-rustc-tests
lnicola Jan 3, 2025
28b0a95
Hide synthetic locals from completions
Veykril Jan 4, 2025
c635d7e
Merge pull request #18835 from Veykril/push-wnmwwoktmpyt
Veykril Jan 4, 2025
2a84711
Support the new `CoercePointee` derive
ChayimFriedman2 Jan 2, 2025
7393621
Merge pull request #18821 from ChayimFriedman2/coerce-pointee
ChayimFriedman2 Jan 4, 2025
6aad736
fix: Fix relative .cargo env vars not working
Veykril Jan 6, 2025
f475723
Merge pull request #18841 from Veykril/push-lsuokpqkprqn
Veykril Jan 6, 2025
5ee1b0a
fix: Handle newstyle `rustc_intrinsic` safety correctly
Veykril Jan 6, 2025
aeae353
Merge pull request #18843 from Veykril/push-usuzxtzsnrpt
Veykril Jan 6, 2025
e47bb0d
fix: Fix flycheck getting confused which package to check
Veykril Jan 6, 2025
68c2241
Merge pull request #18845 from Veykril/push-yyuolqomnkys
Veykril Jan 6, 2025
0389235
fix: Be more permissive with completion resolve data
Veykril Jan 5, 2025
43b44cf
Merge pull request #18836 from Veykril/push-kksuoxxptvty
Veykril Jan 6, 2025
29c21d8
fix: Fix non-cargo flychecks immediately clearing received diagnostics
Veykril Jan 6, 2025
d0db503
Merge pull request #18848 from Veykril/push-kyyoskmvnutp
Veykril Jan 6, 2025
0b832bf
minor: New clippy lints
Veykril Jan 6, 2025
22ab7e3
Merge pull request #18846 from Veykril/push-kmspklwynynu
Veykril Jan 6, 2025
21b9e32
Fix a bug that was caused by fixup reversing
ChayimFriedman2 Jan 6, 2025
5afee0d
Merge pull request #18852 from ChayimFriedman2/proc-macro-panic
lnicola Jan 6, 2025
e18e1eb
Fix case where completion inside macro that expands to `#[test]` was …
ChayimFriedman2 Jan 6, 2025
e02b3ec
fix: clear diagnostics on cancel unconditionally, fixing #18854
davidbarsky Jan 6, 2025
78f89a6
Merge pull request #18858 from davidbarsky/davidbarsky/fix-18854
ChayimFriedman2 Jan 6, 2025
8db8e3c
Merge pull request #18853 from ChayimFriedman2/no-completion
lnicola Jan 7, 2025
4b38725
Set test-utils dependency version, since it's now being published
lnicola Jan 7, 2025
9344334
Merge pull request #18862 from lnicola/publish-test-utils
lnicola Jan 7, 2025
9294965
fix: Fix diagnostics not clearing between flychecks
alexkirsz Jan 7, 2025
4d3e6fe
lint
alexkirsz Jan 7, 2025
09a4ac5
fix: do not offer completions within macro strings
vishruth-thimmaiah Jan 1, 2025
9fb7c15
project-model: fix JSON project PackageRoot buildfile inclusion
bobozaur Jan 7, 2025
1287e29
Merge pull request #18866 from bobozaur/fix-fetching-on-buildfile-cha…
Veykril Jan 7, 2025
3f2f3e5
Merge pull request #18832 from vishruth-thimmaiah/fix_string_comp
ChayimFriedman2 Jan 7, 2025
f9a3c41
Merge pull request #18864 from alexkirsz/alexkirsz/fix-diagnostics-cl…
Veykril Jan 7, 2025
764ce49
Remove `rust-analyzer.cargo.sysrootQueryMetadata` config again
Veykril Dec 29, 2024
c360bf5
Merge pull request #18788 from Veykril/push-zxystwnotuvq
Veykril Jan 7, 2025
05770f2
target-triple -> target-tuple
Veykril Jan 7, 2025
d28a0b8
Align toolchain version fetching with other toolchain info querying
Veykril Jan 7, 2025
380439c
Add some smoke tests to toolchain_info
Veykril Jan 7, 2025
b039d3f
Drop unnecessary tracing::warn
Veykril Jan 7, 2025
21faec1
Merge pull request #18867 from Veykril/push-ntmxlropxkrr
Veykril Jan 7, 2025
8e4409c
Merge pull request #18870 from Veykril/push-vnpsptpolyol
Veykril Jan 7, 2025
aa1ef0a
Preparing for merge from rust-lang/rust
lnicola Jan 7, 2025
e103ab1
Merge from rust-lang/rust
lnicola Jan 7, 2025
fd1e955
Merge pull request #18874 from lnicola/sync-from-rust
lnicola Jan 7, 2025
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
6 changes: 5 additions & 1 deletion src/tools/rust-analyzer/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
pull_request:
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
Expand Down Expand Up @@ -103,7 +107,7 @@ jobs:
- name: Run analysis-stats on the rust standard libraries
if: matrix.os == 'ubuntu-latest'
env:
RUSTC_BOOTSTRAP: 1
RUSTC_BOOTSTRAP: 1
run: target/${{ matrix.target }}/debug/rust-analyzer analysis-stats --with-deps --no-sysroot --no-test $(rustc --print sysroot)/lib/rustlib/src/rust/library/

- name: clippy
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,6 @@ dependencies = [
"memmap2",
"object 0.33.0",
"paths",
"proc-macro-api",
"proc-macro-test",
"ra-ap-rustc_lexer",
"span",
Expand All @@ -1390,6 +1389,7 @@ version = "0.0.0"
dependencies = [
"proc-macro-api",
"proc-macro-srv",
"tt",
]

[[package]]
Expand Down
9 changes: 8 additions & 1 deletion src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ span = { path = "./crates/span", version = "0.0.0" }
stdx = { path = "./crates/stdx", version = "0.0.0" }
syntax = { path = "./crates/syntax", version = "0.0.0" }
syntax-bridge = { path = "./crates/syntax-bridge", version = "0.0.0" }
test-utils = { path = "./crates/test-utils", version = "0.0.0" }
toolchain = { path = "./crates/toolchain", version = "0.0.0" }
tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
Expand All @@ -93,7 +94,6 @@ ra-ap-rustc_pattern_analysis = { version = "0.87", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.
test-fixture = { path = "./crates/test-fixture" }
test-utils = { path = "./crates/test-utils" }

# In-tree crates that are published separately and follow semver. See lib/README.md
line-index = { version = "0.1.2" }
Expand Down Expand Up @@ -203,6 +203,13 @@ new_ret_no_self = "allow"
useless_asref = "allow"
# Has false positives
assigning_clones = "allow"
# Does not work with macros
vec_init_then_push = "allow"
# Our tests have a lot of these
literal_string_with_formatting_args = "allow"
# This lint has been empowered but now also triggers on cases where its invalid to do so
# due to it ignoring move analysis
unnecessary_map_or = "allow"

## Following lints should be tackled at some point
too_many_arguments = "allow"
Expand Down
4 changes: 4 additions & 0 deletions src/tools/rust-analyzer/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ disallowed-types = [
{ path = "std::collections::HashSet", reason = "use FxHashSet" },
{ path = "std::collections::hash_map::RandomState", reason = "use BuildHasherDefault<FxHasher>"}
]

disallowed-methods = [
{ path = "std::process::Command::new", reason = "use `toolchain::command` instead as it forces the choice of a working directory" },
]
19 changes: 12 additions & 7 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,25 @@ impl CrateGraph {
}
}

pub fn sort_deps(&mut self) {
self.arena
.iter_mut()
.for_each(|(_, data)| data.dependencies.sort_by_key(|dep| dep.crate_id));
}

/// Extends this crate graph by adding a complete second crate
/// graph and adjust the ids in the [`ProcMacroPaths`] accordingly.
///
/// This will deduplicate the crates of the graph where possible.
/// Furthermore dependencies are sorted by crate id to make deduplication easier.
///
/// Returns a map mapping `other`'s IDs to the new IDs in `self`.
pub fn extend(
&mut self,
mut other: CrateGraph,
proc_macros: &mut ProcMacroPaths,
) -> FxHashMap<CrateId, CrateId> {
// Sorting here is a bit pointless because the input is likely already sorted.
// However, the overhead is small and it makes the `extend` method harder to misuse.
self.arena
.iter_mut()
.for_each(|(_, data)| data.dependencies.sort_by_key(|dep| dep.crate_id));

let m = self.len();
let topo = other.crates_in_topological_order();
let mut id_map: FxHashMap<CrateId, CrateId> = FxHashMap::default();
for topo in topo {
Expand All @@ -513,7 +517,8 @@ impl CrateGraph {
crate_data.dependencies.iter_mut().for_each(|dep| dep.crate_id = id_map[&dep.crate_id]);
crate_data.dependencies.sort_by_key(|dep| dep.crate_id);

let new_id = self.arena.alloc(crate_data.clone());
let find = self.arena.iter().take(m).find_map(|(k, v)| (v == crate_data).then_some(k));
let new_id = find.unwrap_or_else(|| self.arena.alloc(crate_data.clone()));
id_map.insert(topo, new_id);
}

Expand Down
21 changes: 10 additions & 11 deletions src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl From<CfgAtom> for CfgExpr {

impl CfgExpr {
#[cfg(feature = "tt")]
pub fn parse<S>(tt: &tt::Subtree<S>) -> CfgExpr {
next_cfg_expr(&mut tt.token_trees.iter()).unwrap_or(CfgExpr::Invalid)
pub fn parse<S: Copy>(tt: &tt::TopSubtree<S>) -> CfgExpr {
next_cfg_expr(&mut tt.iter()).unwrap_or(CfgExpr::Invalid)
}

/// Fold the cfg by querying all basic `Atom` and `KeyValue` predicates.
Expand All @@ -66,19 +66,19 @@ impl CfgExpr {
}

#[cfg(feature = "tt")]
fn next_cfg_expr<S>(it: &mut std::slice::Iter<'_, tt::TokenTree<S>>) -> Option<CfgExpr> {
fn next_cfg_expr<S: Copy>(it: &mut tt::iter::TtIter<'_, S>) -> Option<CfgExpr> {
use intern::sym;
use tt::iter::TtElement;

let name = match it.next() {
None => return None,
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.sym.clone(),
Some(TtElement::Leaf(tt::Leaf::Ident(ident))) => ident.sym.clone(),
Some(_) => return Some(CfgExpr::Invalid),
};

// Peek
let ret = match it.as_slice().first() {
Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) if punct.char == '=' => {
match it.as_slice().get(1) {
let ret = match it.peek() {
Some(TtElement::Leaf(tt::Leaf::Punct(punct))) if punct.char == '=' => {
match it.remaining().flat_tokens().get(1) {
Some(tt::TokenTree::Leaf(tt::Leaf::Literal(literal))) => {
it.next();
it.next();
Expand All @@ -87,9 +87,8 @@ fn next_cfg_expr<S>(it: &mut std::slice::Iter<'_, tt::TokenTree<S>>) -> Option<C
_ => return Some(CfgExpr::Invalid),
}
}
Some(tt::TokenTree::Subtree(subtree)) => {
Some(TtElement::Subtree(_, mut sub_it)) => {
it.next();
let mut sub_it = subtree.token_trees.iter();
let mut subs = std::iter::from_fn(|| next_cfg_expr(&mut sub_it));
match name {
s if s == sym::all => CfgExpr::All(subs.collect()),
Expand All @@ -104,7 +103,7 @@ fn next_cfg_expr<S>(it: &mut std::slice::Iter<'_, tt::TokenTree<S>>) -> Option<C
};

// Eat comma separator
if let Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) = it.as_slice().first() {
if let Some(TtElement::Leaf(tt::Leaf::Punct(punct))) = it.peek() {
if punct.char == ',' {
it.next();
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/edition/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "edition"
version = "0.0.0"
description = "Rust edition support crate for rust-analyzer."
rust-version.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
76 changes: 31 additions & 45 deletions src/tools/rust-analyzer/crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A higher level attributes based on TokenTree, with also some shortcuts.

use std::{borrow::Cow, hash::Hash, ops, slice};
use std::{borrow::Cow, hash::Hash, ops};

use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
Expand All @@ -17,6 +17,7 @@ use syntax::{
AstPtr,
};
use triomphe::Arc;
use tt::iter::{TtElement, TtIter};

use crate::{
db::DefDatabase,
Expand Down Expand Up @@ -154,15 +155,15 @@ impl Attrs {

pub fn has_doc_hidden(&self) -> bool {
self.by_key(&sym::doc).tt_values().any(|tt| {
tt.delimiter.kind == DelimiterKind::Parenthesis &&
matches!(&*tt.token_trees, [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::hidden)
tt.top_subtree().delimiter.kind == DelimiterKind::Parenthesis &&
matches!(tt.token_trees().flat_tokens(), [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::hidden)
})
}

pub fn has_doc_notable_trait(&self) -> bool {
self.by_key(&sym::doc).tt_values().any(|tt| {
tt.delimiter.kind == DelimiterKind::Parenthesis &&
matches!(&*tt.token_trees, [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::notable_trait)
tt.top_subtree().delimiter.kind == DelimiterKind::Parenthesis &&
matches!(tt.token_trees().flat_tokens(), [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::notable_trait)
})
}

Expand Down Expand Up @@ -245,8 +246,8 @@ impl From<DocAtom> for DocExpr {
}

impl DocExpr {
fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
next_doc_expr(&mut tt.token_trees.iter()).unwrap_or(DocExpr::Invalid)
fn parse<S: Copy>(tt: &tt::TopSubtree<S>) -> DocExpr {
next_doc_expr(tt.iter()).unwrap_or(DocExpr::Invalid)
}

pub fn aliases(&self) -> &[Symbol] {
Expand All @@ -260,62 +261,47 @@ impl DocExpr {
}
}

fn next_doc_expr<S>(it: &mut slice::Iter<'_, tt::TokenTree<S>>) -> Option<DocExpr> {
fn next_doc_expr<S: Copy>(mut it: TtIter<'_, S>) -> Option<DocExpr> {
let name = match it.next() {
None => return None,
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.sym.clone(),
Some(TtElement::Leaf(tt::Leaf::Ident(ident))) => ident.sym.clone(),
Some(_) => return Some(DocExpr::Invalid),
};

// Peek
let ret = match it.as_slice().first() {
Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) if punct.char == '=' => {
match it.as_slice().get(1) {
Some(tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
let ret = match it.peek() {
Some(TtElement::Leaf(tt::Leaf::Punct(punct))) if punct.char == '=' => {
it.next();
match it.next() {
Some(TtElement::Leaf(tt::Leaf::Literal(tt::Literal {
symbol: text,
kind: tt::LitKind::Str,
..
}))) => {
it.next();
it.next();
DocAtom::KeyValue { key: name, value: text.clone() }.into()
}
}))) => DocAtom::KeyValue { key: name, value: text.clone() }.into(),
_ => return Some(DocExpr::Invalid),
}
}
Some(tt::TokenTree::Subtree(subtree)) => {
Some(TtElement::Subtree(_, subtree_iter)) => {
it.next();
let subs = parse_comma_sep(subtree);
let subs = parse_comma_sep(subtree_iter);
match &name {
s if *s == sym::alias => DocExpr::Alias(subs),
_ => DocExpr::Invalid,
}
}
_ => DocAtom::Flag(name).into(),
};

// Eat comma separator
if let Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) = it.as_slice().first() {
if punct.char == ',' {
it.next();
}
}
Some(ret)
}

fn parse_comma_sep<S>(subtree: &tt::Subtree<S>) -> Vec<Symbol> {
subtree
.token_trees
.iter()
.filter_map(|tt| match tt {
tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
kind: tt::LitKind::Str,
symbol,
..
})) => Some(symbol.clone()),
_ => None,
})
.collect()
fn parse_comma_sep<S>(iter: TtIter<'_, S>) -> Vec<Symbol> {
iter.filter_map(|tt| match tt {
TtElement::Leaf(tt::Leaf::Literal(tt::Literal {
kind: tt::LitKind::Str, symbol, ..
})) => Some(symbol.clone()),
_ => None,
})
.collect()
}

impl AttrsWithOwner {
Expand Down Expand Up @@ -563,7 +549,7 @@ pub struct AttrQuery<'attr> {
}

impl<'attr> AttrQuery<'attr> {
pub fn tt_values(self) -> impl Iterator<Item = &'attr crate::tt::Subtree> {
pub fn tt_values(self) -> impl Iterator<Item = &'attr crate::tt::TopSubtree> {
self.attrs().filter_map(|attr| attr.token_tree_value())
}

Expand All @@ -585,7 +571,7 @@ impl<'attr> AttrQuery<'attr> {

pub fn attrs(self) -> impl Iterator<Item = &'attr Attr> + Clone {
let key = self.key;
self.attrs.iter().filter(move |attr| attr.path.as_ident().map_or(false, |s| *s == *key))
self.attrs.iter().filter(move |attr| attr.path.as_ident().is_some_and(|s| *s == *key))
}

/// Find string value for a specific key inside token tree
Expand All @@ -596,12 +582,12 @@ impl<'attr> AttrQuery<'attr> {
/// ```
pub fn find_string_value_in_tt(self, key: &'attr Symbol) -> Option<&'attr str> {
self.tt_values().find_map(|tt| {
let name = tt.token_trees.iter()
.skip_while(|tt| !matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Ident(tt::Ident { sym, ..} )) if *sym == *key))
let name = tt.iter()
.skip_while(|tt| !matches!(tt, TtElement::Leaf(tt::Leaf::Ident(tt::Ident { sym, ..} )) if *sym == *key))
.nth(2);

match name {
Some(tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal{ symbol: text, kind: tt::LitKind::Str | tt::LitKind::StrRaw(_) , ..}))) => Some(text.as_str()),
Some(TtElement::Leaf(tt::Leaf::Literal(tt::Literal{ symbol: text, kind: tt::LitKind::Str | tt::LitKind::StrRaw(_) , ..}))) => Some(text.as_str()),
_ => None
}
})
Expand Down
12 changes: 6 additions & 6 deletions src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2216,11 +2216,11 @@ impl ExprCollector<'_> {
};
// This needs to match `Flag` in library/core/src/fmt/rt.rs.
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
| ((sign == Some(FormatSign::Minus)) as u32) << 1
| (alternate as u32) << 2
| (zero_pad as u32) << 3
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
| (((sign == Some(FormatSign::Minus)) as u32) << 1)
| ((alternate as u32) << 2)
| ((zero_pad as u32) << 3)
| (((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4)
| (((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5);
let flags = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
flags as u128,
Some(BuiltinUint::U32),
Expand Down Expand Up @@ -2468,7 +2468,7 @@ impl ExprCollector<'_> {

fn comma_follows_token(t: Option<syntax::SyntaxToken>) -> bool {
(|| syntax::algo::skip_trivia_token(t?.next_token()?, syntax::Direction::Next))()
.map_or(false, |it| it.kind() == syntax::T![,])
.is_some_and(|it| it.kind() == syntax::T![,])
}

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn your_stack_belongs_to_me() {
cov_mark::check!(your_stack_belongs_to_me);
lower(
r#"
#![recursion_limit = "32"]
macro_rules! n_nuple {
($e:tt) => ();
($($rest:tt)*) => {{
Expand All @@ -68,6 +69,7 @@ fn your_stack_belongs_to_me2() {
cov_mark::check!(overflow_but_not_me);
lower(
r#"
#![recursion_limit = "32"]
macro_rules! foo {
() => {{ foo!(); foo!(); }}
}
Expand All @@ -78,8 +80,6 @@ fn main() { foo!(); }

#[test]
fn recursion_limit() {
cov_mark::check!(your_stack_belongs_to_me);

lower(
r#"
#![recursion_limit = "2"]
Expand Down
Loading
Loading