Skip to content
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

Subtree update of rust-analyzer #120198

Merged
merged 157 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
1ceb2ea
Show which roots are being scanned in progress messages
9999years Sep 19, 2023
e6dd522
fix: add err recovery for use_tree_list parsing
Young-Flash Jan 11, 2024
afe05fe
fix broken test
Young-Flash Jan 11, 2024
45eea57
add in-comment test case for use_tree_list_err_recovery
Young-Flash Jan 11, 2024
4a6b16b
order use trees following rustfmt's algorithm for ordering imports
davidsemakula Jan 11, 2024
22cda95
fix: failed to infer OUT_DIR when workspace root contains symlink
wasd96040501 Jan 12, 2024
7c3744e
internal: Speedup line index calculation via NEON for aarch64
roife Jan 12, 2024
d0b310f
fix: add USE_TREE_LIST_FIRST_SET
Young-Flash Jan 12, 2024
6033b66
test: correct expected test result
Young-Flash Jan 12, 2024
df53828
internal: add inline for move_mask in line-index
roife Jan 12, 2024
22ae5f4
order merged use trees
davidsemakula Jan 12, 2024
db3f0f1
improve use tree simple path comparison logic
davidsemakula Jan 12, 2024
d4b43d5
improve ordered use tree merging implementation
davidsemakula Jan 14, 2024
02d21f2
Add a stable #visual-studio anchor to the Manual
dtolnay Jan 14, 2024
0b19e48
Auto merge of #16361 - dtolnay-contrib:visualstudio, r=Veykril
bors Jan 15, 2024
c7eb52d
internal: Add unstable config for loading the sysroot sources via `ca…
Veykril Jan 13, 2024
a616c4d
Auto merge of #16356 - Veykril:sysroot-metadata, r=Veykril
bors Jan 15, 2024
d80d2fc
Eagerly lower enum variants in CrateDefMap construction
Veykril Jan 15, 2024
6bbd106
Merge commit '9d8889cdfcc3aa0302353fc988ed21ff9bc9925c' into sync-fro…
lnicola Jan 15, 2024
2d72ec7
Deduplicate
Veykril Jan 15, 2024
1669344
Thinner DefDiagnostics
Veykril Jan 15, 2024
180e9b2
Cleanup
Veykril Jan 15, 2024
a356172
internal: re-generate lints.rs
mohe2015 Dec 25, 2023
f937673
fix: rename generator to coroutine
mohe2015 Dec 25, 2023
fe35447
fix: rename generator to coroutine also in dependencies
mohe2015 Dec 25, 2023
ff71513
Merge branch 'master' into sync-from-rust
lnicola Jan 16, 2024
a2aee95
Merge remote-tracking branch 'upstream/master' into sync-from-rust
lnicola Jan 16, 2024
b9fd12b
Auto merge of #16364 - lnicola:sync-from-rust, r=lnicola
bors Jan 16, 2024
4de8954
Auto merge of #16196 - mohe2015:rename-generator-to-coroutine, r=Veykril
bors Jan 16, 2024
5df53c9
Auto merge of #16351 - Veykril:eager-enum-variant, r=Veykril
bors Jan 16, 2024
18abb12
Auto merge of #16350 - roife:neon-support-for-line-index, r=Veykril
bors Jan 16, 2024
87e609a
Auto merge of #15868 - wasd96040501:fix/symlink2, r=Veykril
bors Jan 16, 2024
3981508
Rename Message::Progress::file field to dir
Veykril Jan 16, 2024
c9afd41
Auto merge of #15636 - 9999years:show-which-roots-are-scanned, r=Veykril
bors Jan 16, 2024
659d4f9
Impl fmt::Display for Span
Veykril Jan 16, 2024
cf905cf
Put layout comment to the top of hovers
Veykril Jan 16, 2024
90a1b48
Render AstIds in item-tree view
Veykril Jan 16, 2024
54f2111
internal: Make data queries transparent over their diagnostics variant
Veykril Jan 16, 2024
f675b5e
Don't early exit on panics in rustc_tests command
Veykril Jan 16, 2024
35e05e0
Bump smol_str
Veykril Jan 16, 2024
2d5ce88
Auto merge of #16366 - Veykril:transp-queries, r=Veykril
bors Jan 16, 2024
5b2a2bc
remove unnecessary ref patterns
davidsemakula Jan 16, 2024
1f91c48
move is_upper_snake_case to stdx
davidsemakula Jan 16, 2024
8f4f5a6
fix: Make value_ty query fallible
Veykril Jan 16, 2024
63c4e69
Auto merge of #16367 - Veykril:value-ty, r=Veykril
bors Jan 16, 2024
0a8c784
Auto merge of #16352 - davidsemakula:rustfmt-import-sort-algo, r=Veykril
bors Jan 16, 2024
6584e63
minor: Simplify
Veykril Jan 16, 2024
e7a8d21
Auto merge of #16369 - Veykril:simplify, r=Veykril
bors Jan 16, 2024
384488c
feat: Hover for literals showing additional value information
Veykril Jan 16, 2024
e2df3f2
Auto merge of #16370 - Veykril:hover-lit, r=Veykril
bors Jan 16, 2024
7c94c29
fix: make let_stmts inserted in inline_call correctly indented
roife Jan 16, 2024
82e8355
feat: Show notable trait impls on hover
Veykril Jan 16, 2024
7777a81
Auto merge of #16374 - Veykril:hover-notable, r=Veykril
bors Jan 16, 2024
ffeaee8
Goto type actions for notable trait hovers
Veykril Jan 16, 2024
0a75a8c
Notable traits for type info hovers
Veykril Jan 16, 2024
0333646
Auto merge of #16375 - Veykril:hover-notable, r=Veykril
bors Jan 16, 2024
d48498f
fix: better handling of SelfParam in inline_call
roife Jan 17, 2024
920e99a
test: add tests for variant kinds of SelfParam in inline_call
roife Jan 17, 2024
21723cb
Run metadata on sysroot for CI metrics
Veykril Jan 17, 2024
f4fec4f
Auto merge of #16378 - roife:fix/issue-15470, r=Veykril
bors Jan 17, 2024
2b02df2
Auto merge of #16380 - Veykril:sysroot-ci, r=Veykril
bors Jan 17, 2024
5916da2
Handle `macro_rules!` as MACRO_CALL
Urhengulas Jan 8, 2024
76c67dd
Fix test
Urhengulas Jan 17, 2024
c820980
Auto merge of #16314 - Urhengulas:macro_rule-as-macro-name, r=Veykril
bors Jan 17, 2024
0bdbf49
fix: Fix progress reporting getting stuck
Veykril Jan 17, 2024
5b62ebc
Auto merge of #16383 - Veykril:progress, r=Veykril
bors Jan 17, 2024
8359126
minor: Make use of some new `SmolStr` improvements
Veykril Jan 17, 2024
27b0636
Fix sysroot metadata in metrics
lnicola Jan 17, 2024
a19372f
Auto merge of #16387 - lnicola:metrics-sysroot, r=Veykril
bors Jan 17, 2024
84a3b52
properly order raw idents when ordering use trees
davidsemakula Jan 17, 2024
9d9b343
Auto merge of #16389 - davidsemakula:order-use-tree-raw-ident, r=lnicola
bors Jan 17, 2024
57d4b5b
add "one" import granularity
davidsemakula Jan 14, 2024
4f176b3
update import granularity config and docs
davidsemakula Jan 14, 2024
7db4117
respect "one" import granularity config in merge imports assist
davidsemakula Jan 15, 2024
9bd9a17
Add a new config to allow renaming of non-local items
alibektas Jan 17, 2024
04ce4ce
internal: speedup LineEndings calculation using 'memchr'
roife Jan 18, 2024
8bb500a
Auto merge of #16395 - roife:internal/speed-up-LineEndings-with-memch…
bors Jan 18, 2024
2dfa9b8
Auto merge of #16384 - Veykril:smolstr, r=Veykril
bors Jan 18, 2024
1c61326
add use_tree_completion test
Young-Flash Jan 18, 2024
bd26403
fix panic with reference in macro
Young-Flash Jan 18, 2024
0bf986d
add test case with marco reference
Young-Flash Jan 18, 2024
5074486
Fix rename test fixtures not accounting for multi file edits
Veykril Jan 18, 2024
1ab8c7f
Auto merge of #16349 - Young-Flash:use_error_recovery, r=Veykril
bors Jan 18, 2024
2102091
v2
alibektas Jan 18, 2024
b599de1
Refactor `macro_call` to be consistent with other functions
Urhengulas Jan 18, 2024
f913d4f
Refactor if-else
Urhengulas Jan 9, 2024
bfc2e56
Add tests for intra-doc links
Urhengulas Jan 9, 2024
c817286
Handle intra-doc links with anchor
Urhengulas Jan 18, 2024
fad4fa1
`cargo clippy --fix`
Urhengulas Jan 18, 2024
2185396
Fix CI
Urhengulas Jan 18, 2024
28c7fa8
Fix CI 2
Urhengulas Jan 18, 2024
255cde7
Fix CI 3
Urhengulas Jan 18, 2024
a5b89ff
Auto merge of #16391 - alibektas:15656/renaming_allowed_by_config, r=…
bors Jan 18, 2024
6d31416
Auto merge of #16385 - Urhengulas:fix-tra-doc-links, r=Veykril
bors Jan 18, 2024
48af3ef
Auto merge of #16397 - Urhengulas:refactor-parser, r=Veykril
bors Jan 18, 2024
67c1c2b
update merge item assist implementation for "one" import granularity
davidsemakula Jan 18, 2024
3f4c6da
Auto merge of #16372 - davidsemakula:import-granularity-one, r=Veykril
bors Jan 18, 2024
431040f
Update bail message referencing config
alibektas Jan 18, 2024
85c9a83
Auto merge of #16398 - Urhengulas:satisfy-clippy, r=Veykril
bors Jan 19, 2024
1889c6c
Copy lint tables from https://github.com/rust-lang/rust-analyzer/pull…
Urhengulas Jan 19, 2024
3041164
Temporarily allow all lints which occur
Urhengulas Jan 19, 2024
1fdf306
Move some lints to temporary list
Urhengulas Jan 19, 2024
0becb6c
Update crates/ide-db/src/rename.rs
alibektas Jan 19, 2024
0347f81
Update tests
alibektas Jan 19, 2024
3a722bd
feat:Record FnAbi
Veykril Jan 17, 2024
46e3831
Stub out FnAbi::partial_eq as a workaround for now
Veykril Jan 19, 2024
03d4a6d
Auto merge of #16400 - alibektas:15656/update_bail_message_ref_config…
bors Jan 19, 2024
04edfa1
Auto merge of #16388 - Veykril:fn-abi, r=Veykril
bors Jan 19, 2024
4087dcf
Add comment about false positive clippy lint
Urhengulas Jan 19, 2024
2a239b9
Auto merge of #16401 - Urhengulas:lint-table, r=Veykril
bors Jan 19, 2024
3409645
bind_instead_of_map
Urhengulas Jan 19, 2024
b5eca5f
collapsible_if
Urhengulas Jan 19, 2024
6573768
iter_kv_map
Urhengulas Jan 19, 2024
4184c6a
collapsible_match
Urhengulas Jan 19, 2024
882289b
double_parens
Urhengulas Jan 19, 2024
2a500d5
for_kv_map
Urhengulas Jan 19, 2024
60dda08
manual_find
Urhengulas Jan 19, 2024
d8ad4af
manual_map
Urhengulas Jan 19, 2024
6a2a603
let_and_return
Urhengulas Jan 19, 2024
c629ec7
clone_on_copy
Urhengulas Jan 19, 2024
9e4f94c
no_effect
Urhengulas Jan 19, 2024
6709eab
never_loop
Urhengulas Jan 19, 2024
eb7aec5
map_clone
Urhengulas Jan 19, 2024
8982ff3
get_first
Urhengulas Jan 19, 2024
84494d1
from_str_radix_10
Urhengulas Jan 19, 2024
5753981
explicit_auto_deref
Urhengulas Jan 19, 2024
c27b6b5
filter_map_bool_then
Urhengulas Jan 19, 2024
2ae2512
if_same_then_else
Urhengulas Jan 19, 2024
add40c8
match_like_matches_macro
Urhengulas Jan 19, 2024
d351cb8
match_single_binding
Urhengulas Jan 19, 2024
3839f9a
needless_borrow
Urhengulas Jan 19, 2024
a342e93
needless_lifetimes
Urhengulas Jan 19, 2024
6699c90
needless_pass_by_value
Urhengulas Jan 19, 2024
e58b683
needless_return
Urhengulas Jan 19, 2024
e6f9f4c
nonminimal_bool
Urhengulas Jan 19, 2024
bef3551
non_minimal_cfg
Urhengulas Jan 19, 2024
0df3049
only_used_in_recursion
Urhengulas Jan 19, 2024
4858a37
op_ref
Urhengulas Jan 19, 2024
7e8568b
option_map_unit_fn
Urhengulas Jan 19, 2024
692212b
partialeq_to_none
Urhengulas Jan 19, 2024
9527e24
redundant_locals
Urhengulas Jan 19, 2024
6738edc
ptr_arg
Urhengulas Jan 19, 2024
3cf1358
question_mark
Urhengulas Jan 19, 2024
5a62a0d
redundant_closure
Urhengulas Jan 19, 2024
71d4dba
redundant_pattern_matching
Urhengulas Jan 19, 2024
159b4c9
search_is_some
Urhengulas Jan 19, 2024
9dd07f0
should_implement_trait
Urhengulas Jan 19, 2024
b1a0c9a
single_match
Urhengulas Jan 19, 2024
9e83779
redundant_locals
Urhengulas Jan 19, 2024
67cfbf2
Auto merge of #16404 - Urhengulas:satisfy-clippy, r=Veykril
bors Jan 19, 2024
f9b5e0d
minor: use `reference.range` to get original range
Young-Flash Jan 20, 2024
0c76421
Auto merge of #16396 - Young-Flash:fix_marco, r=Veykril
bors Jan 20, 2024
721e790
include `for` in convert to guarded return assist
dfireBird Jan 20, 2024
5aa7583
add max_line_length to .editorconfig
davidsemakula Jan 20, 2024
d4926c1
Auto merge of #16405 - dfireBird:guarded-return-for-loop, r=lnicola
bors Jan 20, 2024
a911652
Auto merge of #16406 - davidsemakula:editorconfig, r=lnicola
bors Jan 20, 2024
595b4c3
Merge commit 'a9116523604c998e7781f60d3b5a6f586e0414a9' into sync-fro…
lnicola Jan 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
max_line_length = 100

[*.md]
indent_size = 2
Expand Down
25 changes: 13 additions & 12 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "chalk-derive"
version = "0.95.0"
version = "0.96.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "329427f28cd2bddaacd47c4dcd3d7082d315c61fb164394c690fe98c1b6ee9d3"
checksum = "5676cea088c32290fe65c82895be9d06dd21e0fa49bb97ca840529e9417ab71a"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -172,9 +172,9 @@ dependencies = [

[[package]]
name = "chalk-ir"
version = "0.95.0"
version = "0.96.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1e1659238bd598d0f7dbc5034cf1ff46010a3d6827704c9ed443c8359cb484"
checksum = "ff550c2cdd63ff74394214dce03d06386928a641c0f08837535f04af573a966d"
dependencies = [
"bitflags 2.4.1",
"chalk-derive",
Expand All @@ -183,9 +183,9 @@ dependencies = [

[[package]]
name = "chalk-recursive"
version = "0.95.0"
version = "0.96.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3e0bff0ba1bed11407384fcec0353aeb6888901e63cb47d04505ec47adad847"
checksum = "4c4559e5c9b200240453b07d893f9c3c74413b53b0d33cbe272c68b0b77aa1c3"
dependencies = [
"chalk-derive",
"chalk-ir",
Expand All @@ -196,9 +196,9 @@ dependencies = [

[[package]]
name = "chalk-solve"
version = "0.95.0"
version = "0.96.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9c46d501cf83732a91056c0c846ae7a16d6b3c67a6a6bb5e9cc0a2e91563b6"
checksum = "0882e68ce9eb5a0a2413806538494d19df6ee520ab17d1faf489e952f32e98b8"
dependencies = [
"chalk-derive",
"chalk-ir",
Expand Down Expand Up @@ -1001,9 +1001,9 @@ dependencies = [

[[package]]
name = "memchr"
version = "2.6.4"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"

[[package]]
name = "memmap2"
Expand Down Expand Up @@ -1532,6 +1532,7 @@ dependencies = [
"lsp-server 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lsp-types",
"mbe",
"memchr",
"mimalloc",
"nohash-hasher",
"num_cpus",
Expand Down Expand Up @@ -1712,9 +1713,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"

[[package]]
name = "smol_str"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c"
checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49"
dependencies = [
"serde",
]
Expand Down
73 changes: 64 additions & 9 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ dissimilar = "1.0.7"
either = "1.9.0"
expect-test = "1.4.0"
hashbrown = { version = "0.14", features = [
"inline-more",
"inline-more",
], default-features = false }
indexmap = "2.1.0"
itertools = "0.12.0"
Expand All @@ -118,11 +118,11 @@ semver = "1.0.14"
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
smallvec = { version = "1.10.0", features = [
"const_new",
"union",
"const_generics",
"const_new",
"union",
"const_generics",
] }
smol_str = "0.2.0"
smol_str = "0.2.1"
text-size = "1.1.1"
tracing = "0.1.40"
tracing-tree = "0.3.0"
Expand All @@ -138,8 +138,63 @@ xshell = "0.2.5"
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
dashmap = { version = "=5.5.3", features = ["raw-api"] }

[workspace.lints.rust]
rust_2018_idioms = "warn"
unused_lifetimes = "warn"
semicolon_in_expressions_from_macros = "warn"

[workspace.lints.clippy]
collapsible_if = "allow"
needless_pass_by_value = "allow"
nonminimal_bool = "allow"
redundant_pattern_matching = "allow"
# FIXME Remove the tidy test once the lint table is stable

## lint groups
complexity = { level = "warn", priority = -1 }
correctness = { level = "deny", priority = -1 }
perf = { level = "deny", priority = -1 }
restriction = { level = "allow", priority = -1 }
style = { level = "warn", priority = -1 }
suspicious = { level = "warn", priority = -1 }

## allow following lints
# () makes a fine error in most cases
result_unit_err = "allow"
# We don't expose public APIs that matter like this
len_without_is_empty = "allow"
# We have macros that rely on this currently
enum_variant_names = "allow"
# Builder pattern disagrees
new_ret_no_self = "allow"

## Following lints should be tackled at some point
borrowed_box = "allow"
borrow_deref_ref = "allow"
derivable_impls = "allow"
derived_hash_with_manual_eq = "allow"
field_reassign_with_default = "allow"
forget_non_drop = "allow"
format_collect = "allow"
large_enum_variant = "allow"
needless_doctest_main = "allow"
new_without_default = "allow"
non_canonical_clone_impl = "allow"
non_canonical_partial_ord_impl = "allow"
self_named_constructors = "allow"
skip_while_next = "allow"
too_many_arguments = "allow"
toplevel_ref_arg = "allow"
type_complexity = "allow"
unnecessary_cast = "allow"
unnecessary_filter_map = "allow"
unnecessary_lazy_evaluations = "allow"
unnecessary_mut_passed = "allow"
useless_conversion = "allow"
useless_format = "allow"
wildcard_in_or_patterns = "allow"
wrong_self_convention = "allow"

## warn at following lints
dbg_macro = "warn"
todo = "warn"
unimplemented = "allow"
rc_buffer = "warn"
# FIXME enable this, we use this pattern a lot so its annoying work ...
# str_to_string = "warn"
51 changes: 43 additions & 8 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::{fmt, mem, ops, str::FromStr};

use cfg::CfgOptions;
use la_arena::{Arena, Idx};
use la_arena::{Arena, Idx, RawIdx};
use rustc_hash::{FxHashMap, FxHashSet};
use semver::Version;
use syntax::SmolStr;
Expand Down Expand Up @@ -157,6 +157,10 @@ impl CrateOrigin {
pub fn is_lib(&self) -> bool {
matches!(self, CrateOrigin::Library { .. })
}

pub fn is_lang(&self) -> bool {
matches!(self, CrateOrigin::Lang { .. })
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand All @@ -174,7 +178,7 @@ impl From<&str> for LangCrateOrigin {
match s {
"alloc" => LangCrateOrigin::Alloc,
"core" => LangCrateOrigin::Core,
"proc-macro" => LangCrateOrigin::ProcMacro,
"proc-macro" | "proc_macro" => LangCrateOrigin::ProcMacro,
"std" => LangCrateOrigin::Std,
"test" => LangCrateOrigin::Test,
_ => LangCrateOrigin::Other,
Expand Down Expand Up @@ -257,6 +261,7 @@ impl ReleaseChannel {
}
}

#[allow(clippy::should_implement_trait)]
pub fn from_str(str: &str) -> Option<Self> {
Some(match str {
"" | "stable" => ReleaseChannel::Stable,
Expand Down Expand Up @@ -326,7 +331,7 @@ impl CrateData {
return false;
}

if let Some(_) = opts.next() {
if opts.next().is_some() {
return false;
}
}
Expand Down Expand Up @@ -522,7 +527,7 @@ impl CrateGraph {
self.arena.iter().map(|(idx, _)| idx)
}

// FIXME: used for `handle_hack_cargo_workspace`, should be removed later
// FIXME: used for fixing up the toolchain sysroot, should be removed and done differently
#[doc(hidden)]
pub fn iter_mut(&mut self) -> impl Iterator<Item = (CrateId, &mut CrateData)> + '_ {
self.arena.iter_mut()
Expand Down Expand Up @@ -619,7 +624,12 @@ impl CrateGraph {
/// This will deduplicate the crates of the graph where possible.
/// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id.
/// If the crate dependencies were sorted, the resulting graph from this `extend` call will also have the crate dependencies sorted.
pub fn extend(&mut self, mut other: CrateGraph, proc_macros: &mut ProcMacroPaths) {
pub fn extend(
&mut self,
mut other: CrateGraph,
proc_macros: &mut ProcMacroPaths,
on_finished: impl FnOnce(&FxHashMap<CrateId, CrateId>),
) {
let topo = other.crates_in_topological_order();
let mut id_map: FxHashMap<CrateId, CrateId> = FxHashMap::default();
for topo in topo {
Expand All @@ -630,7 +640,7 @@ impl CrateGraph {
let res = self.arena.iter().find_map(|(id, data)| {
match (&data.origin, &crate_data.origin) {
(a, b) if a == b => {
if data.eq_ignoring_origin_and_deps(&crate_data, false) {
if data.eq_ignoring_origin_and_deps(crate_data, false) {
return Some((id, false));
}
}
Expand All @@ -642,8 +652,8 @@ impl CrateGraph {
// version and discard the library one as the local version may have
// dev-dependencies that we want to keep resolving. See #15656 for more
// information.
if data.eq_ignoring_origin_and_deps(&crate_data, true) {
return Some((id, if a.is_local() { false } else { true }));
if data.eq_ignoring_origin_and_deps(crate_data, true) {
return Some((id, !a.is_local()));
}
}
(_, _) => return None,
Expand All @@ -670,6 +680,8 @@ impl CrateGraph {

*proc_macros =
mem::take(proc_macros).into_iter().map(|(id, macros)| (id_map[&id], macros)).collect();

on_finished(&id_map);
}

fn find_path(
Expand Down Expand Up @@ -721,6 +733,29 @@ impl CrateGraph {
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>> {
let mut id_map = vec![None; self.arena.len()];
self.arena = std::mem::take(&mut self.arena)
.into_iter()
.filter_map(|(id, data)| if to_keep.contains(&id) { Some((id, data)) } else { None })
.enumerate()
.map(|(new_id, (id, data))| {
id_map[id.into_raw().into_u32() as usize] =
Some(CrateId::from_raw(RawIdx::from_u32(new_id as u32)));
data
})
.collect();
for (_, data) in self.arena.iter_mut() {
data.dependencies.iter_mut().for_each(|dep| {
dep.crate_id =
id_map[dep.crate_id.into_raw().into_u32() as usize].expect("crate was filtered")
});
}
id_map
}
}

impl ops::Index<CrateId> for CrateGraph {
Expand Down
Loading
Loading