Skip to content

Commit ef71f10

Browse files
committed
Auto merge of rust-lang#120198 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents d9d89fd + 595b4c3 commit ef71f10

File tree

315 files changed

+7171
-4498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+7171
-4498
lines changed

src/tools/rust-analyzer/.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ end_of_line = lf
88
insert_final_newline = true
99
indent_style = space
1010
indent_size = 4
11+
max_line_length = 100
1112

1213
[*.md]
1314
indent_size = 2

src/tools/rust-analyzer/Cargo.lock

+13-12
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
160160

161161
[[package]]
162162
name = "chalk-derive"
163-
version = "0.95.0"
163+
version = "0.96.0"
164164
source = "registry+https://github.com/rust-lang/crates.io-index"
165-
checksum = "329427f28cd2bddaacd47c4dcd3d7082d315c61fb164394c690fe98c1b6ee9d3"
165+
checksum = "5676cea088c32290fe65c82895be9d06dd21e0fa49bb97ca840529e9417ab71a"
166166
dependencies = [
167167
"proc-macro2",
168168
"quote",
@@ -172,9 +172,9 @@ dependencies = [
172172

173173
[[package]]
174174
name = "chalk-ir"
175-
version = "0.95.0"
175+
version = "0.96.0"
176176
source = "registry+https://github.com/rust-lang/crates.io-index"
177-
checksum = "9e1e1659238bd598d0f7dbc5034cf1ff46010a3d6827704c9ed443c8359cb484"
177+
checksum = "ff550c2cdd63ff74394214dce03d06386928a641c0f08837535f04af573a966d"
178178
dependencies = [
179179
"bitflags 2.4.1",
180180
"chalk-derive",
@@ -183,9 +183,9 @@ dependencies = [
183183

184184
[[package]]
185185
name = "chalk-recursive"
186-
version = "0.95.0"
186+
version = "0.96.0"
187187
source = "registry+https://github.com/rust-lang/crates.io-index"
188-
checksum = "b3e0bff0ba1bed11407384fcec0353aeb6888901e63cb47d04505ec47adad847"
188+
checksum = "4c4559e5c9b200240453b07d893f9c3c74413b53b0d33cbe272c68b0b77aa1c3"
189189
dependencies = [
190190
"chalk-derive",
191191
"chalk-ir",
@@ -196,9 +196,9 @@ dependencies = [
196196

197197
[[package]]
198198
name = "chalk-solve"
199-
version = "0.95.0"
199+
version = "0.96.0"
200200
source = "registry+https://github.com/rust-lang/crates.io-index"
201-
checksum = "eb9c46d501cf83732a91056c0c846ae7a16d6b3c67a6a6bb5e9cc0a2e91563b6"
201+
checksum = "0882e68ce9eb5a0a2413806538494d19df6ee520ab17d1faf489e952f32e98b8"
202202
dependencies = [
203203
"chalk-derive",
204204
"chalk-ir",
@@ -1001,9 +1001,9 @@ dependencies = [
10011001

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

10081008
[[package]]
10091009
name = "memmap2"
@@ -1532,6 +1532,7 @@ dependencies = [
15321532
"lsp-server 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
15331533
"lsp-types",
15341534
"mbe",
1535+
"memchr",
15351536
"mimalloc",
15361537
"nohash-hasher",
15371538
"num_cpus",
@@ -1712,9 +1713,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
17121713

17131714
[[package]]
17141715
name = "smol_str"
1715-
version = "0.2.0"
1716+
version = "0.2.1"
17161717
source = "registry+https://github.com/rust-lang/crates.io-index"
1717-
checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c"
1718+
checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49"
17181719
dependencies = [
17191720
"serde",
17201721
]

src/tools/rust-analyzer/Cargo.toml

+64-9
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ dissimilar = "1.0.7"
105105
either = "1.9.0"
106106
expect-test = "1.4.0"
107107
hashbrown = { version = "0.14", features = [
108-
"inline-more",
108+
"inline-more",
109109
], default-features = false }
110110
indexmap = "2.1.0"
111111
itertools = "0.12.0"
@@ -118,11 +118,11 @@ semver = "1.0.14"
118118
serde = { version = "1.0.192", features = ["derive"] }
119119
serde_json = "1.0.108"
120120
smallvec = { version = "1.10.0", features = [
121-
"const_new",
122-
"union",
123-
"const_generics",
121+
"const_new",
122+
"union",
123+
"const_generics",
124124
] }
125-
smol_str = "0.2.0"
125+
smol_str = "0.2.1"
126126
text-size = "1.1.1"
127127
tracing = "0.1.40"
128128
tracing-tree = "0.3.0"
@@ -138,8 +138,63 @@ xshell = "0.2.5"
138138
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
139139
dashmap = { version = "=5.5.3", features = ["raw-api"] }
140140

141+
[workspace.lints.rust]
142+
rust_2018_idioms = "warn"
143+
unused_lifetimes = "warn"
144+
semicolon_in_expressions_from_macros = "warn"
145+
141146
[workspace.lints.clippy]
142-
collapsible_if = "allow"
143-
needless_pass_by_value = "allow"
144-
nonminimal_bool = "allow"
145-
redundant_pattern_matching = "allow"
147+
# FIXME Remove the tidy test once the lint table is stable
148+
149+
## lint groups
150+
complexity = { level = "warn", priority = -1 }
151+
correctness = { level = "deny", priority = -1 }
152+
perf = { level = "deny", priority = -1 }
153+
restriction = { level = "allow", priority = -1 }
154+
style = { level = "warn", priority = -1 }
155+
suspicious = { level = "warn", priority = -1 }
156+
157+
## allow following lints
158+
# () makes a fine error in most cases
159+
result_unit_err = "allow"
160+
# We don't expose public APIs that matter like this
161+
len_without_is_empty = "allow"
162+
# We have macros that rely on this currently
163+
enum_variant_names = "allow"
164+
# Builder pattern disagrees
165+
new_ret_no_self = "allow"
166+
167+
## Following lints should be tackled at some point
168+
borrowed_box = "allow"
169+
borrow_deref_ref = "allow"
170+
derivable_impls = "allow"
171+
derived_hash_with_manual_eq = "allow"
172+
field_reassign_with_default = "allow"
173+
forget_non_drop = "allow"
174+
format_collect = "allow"
175+
large_enum_variant = "allow"
176+
needless_doctest_main = "allow"
177+
new_without_default = "allow"
178+
non_canonical_clone_impl = "allow"
179+
non_canonical_partial_ord_impl = "allow"
180+
self_named_constructors = "allow"
181+
skip_while_next = "allow"
182+
too_many_arguments = "allow"
183+
toplevel_ref_arg = "allow"
184+
type_complexity = "allow"
185+
unnecessary_cast = "allow"
186+
unnecessary_filter_map = "allow"
187+
unnecessary_lazy_evaluations = "allow"
188+
unnecessary_mut_passed = "allow"
189+
useless_conversion = "allow"
190+
useless_format = "allow"
191+
wildcard_in_or_patterns = "allow"
192+
wrong_self_convention = "allow"
193+
194+
## warn at following lints
195+
dbg_macro = "warn"
196+
todo = "warn"
197+
unimplemented = "allow"
198+
rc_buffer = "warn"
199+
# FIXME enable this, we use this pattern a lot so its annoying work ...
200+
# str_to_string = "warn"

src/tools/rust-analyzer/crates/base-db/src/input.rs

+43-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use std::{fmt, mem, ops, str::FromStr};
1010

1111
use cfg::CfgOptions;
12-
use la_arena::{Arena, Idx};
12+
use la_arena::{Arena, Idx, RawIdx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
1414
use semver::Version;
1515
use syntax::SmolStr;
@@ -157,6 +157,10 @@ impl CrateOrigin {
157157
pub fn is_lib(&self) -> bool {
158158
matches!(self, CrateOrigin::Library { .. })
159159
}
160+
161+
pub fn is_lang(&self) -> bool {
162+
matches!(self, CrateOrigin::Lang { .. })
163+
}
160164
}
161165

162166
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -174,7 +178,7 @@ impl From<&str> for LangCrateOrigin {
174178
match s {
175179
"alloc" => LangCrateOrigin::Alloc,
176180
"core" => LangCrateOrigin::Core,
177-
"proc-macro" => LangCrateOrigin::ProcMacro,
181+
"proc-macro" | "proc_macro" => LangCrateOrigin::ProcMacro,
178182
"std" => LangCrateOrigin::Std,
179183
"test" => LangCrateOrigin::Test,
180184
_ => LangCrateOrigin::Other,
@@ -257,6 +261,7 @@ impl ReleaseChannel {
257261
}
258262
}
259263

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

329-
if let Some(_) = opts.next() {
334+
if opts.next().is_some() {
330335
return false;
331336
}
332337
}
@@ -522,7 +527,7 @@ impl CrateGraph {
522527
self.arena.iter().map(|(idx, _)| idx)
523528
}
524529

525-
// FIXME: used for `handle_hack_cargo_workspace`, should be removed later
530+
// FIXME: used for fixing up the toolchain sysroot, should be removed and done differently
526531
#[doc(hidden)]
527532
pub fn iter_mut(&mut self) -> impl Iterator<Item = (CrateId, &mut CrateData)> + '_ {
528533
self.arena.iter_mut()
@@ -619,7 +624,12 @@ impl CrateGraph {
619624
/// This will deduplicate the crates of the graph where possible.
620625
/// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id.
621626
/// If the crate dependencies were sorted, the resulting graph from this `extend` call will also have the crate dependencies sorted.
622-
pub fn extend(&mut self, mut other: CrateGraph, proc_macros: &mut ProcMacroPaths) {
627+
pub fn extend(
628+
&mut self,
629+
mut other: CrateGraph,
630+
proc_macros: &mut ProcMacroPaths,
631+
on_finished: impl FnOnce(&FxHashMap<CrateId, CrateId>),
632+
) {
623633
let topo = other.crates_in_topological_order();
624634
let mut id_map: FxHashMap<CrateId, CrateId> = FxHashMap::default();
625635
for topo in topo {
@@ -630,7 +640,7 @@ impl CrateGraph {
630640
let res = self.arena.iter().find_map(|(id, data)| {
631641
match (&data.origin, &crate_data.origin) {
632642
(a, b) if a == b => {
633-
if data.eq_ignoring_origin_and_deps(&crate_data, false) {
643+
if data.eq_ignoring_origin_and_deps(crate_data, false) {
634644
return Some((id, false));
635645
}
636646
}
@@ -642,8 +652,8 @@ impl CrateGraph {
642652
// version and discard the library one as the local version may have
643653
// dev-dependencies that we want to keep resolving. See #15656 for more
644654
// information.
645-
if data.eq_ignoring_origin_and_deps(&crate_data, true) {
646-
return Some((id, if a.is_local() { false } else { true }));
655+
if data.eq_ignoring_origin_and_deps(crate_data, true) {
656+
return Some((id, !a.is_local()));
647657
}
648658
}
649659
(_, _) => return None,
@@ -670,6 +680,8 @@ impl CrateGraph {
670680

671681
*proc_macros =
672682
mem::take(proc_macros).into_iter().map(|(id, macros)| (id_map[&id], macros)).collect();
683+
684+
on_finished(&id_map);
673685
}
674686

675687
fn find_path(
@@ -721,6 +733,29 @@ impl CrateGraph {
721733
fn hacky_find_crate<'a>(&'a self, display_name: &'a str) -> impl Iterator<Item = CrateId> + 'a {
722734
self.iter().filter(move |it| self[*it].display_name.as_deref() == Some(display_name))
723735
}
736+
737+
/// Removes all crates from this crate graph except for the ones in `to_keep` and fixes up the dependencies.
738+
/// Returns a mapping from old crate ids to new crate ids.
739+
pub fn remove_crates_except(&mut self, to_keep: &[CrateId]) -> Vec<Option<CrateId>> {
740+
let mut id_map = vec![None; self.arena.len()];
741+
self.arena = std::mem::take(&mut self.arena)
742+
.into_iter()
743+
.filter_map(|(id, data)| if to_keep.contains(&id) { Some((id, data)) } else { None })
744+
.enumerate()
745+
.map(|(new_id, (id, data))| {
746+
id_map[id.into_raw().into_u32() as usize] =
747+
Some(CrateId::from_raw(RawIdx::from_u32(new_id as u32)));
748+
data
749+
})
750+
.collect();
751+
for (_, data) in self.arena.iter_mut() {
752+
data.dependencies.iter_mut().for_each(|dep| {
753+
dep.crate_id =
754+
id_map[dep.crate_id.into_raw().into_u32() as usize].expect("crate was filtered")
755+
});
756+
}
757+
id_map
758+
}
724759
}
725760

726761
impl ops::Index<CrateId> for CrateGraph {

0 commit comments

Comments
 (0)