Skip to content

Commit 950d845

Browse files
committed
Auto merge of #120198 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents c210ea2 + 5248fd8 commit 950d845

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

.editorconfig

Lines changed: 1 addition & 0 deletions
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

Cargo.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 64 additions & 9 deletions
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"

crates/base-db/src/input.rs

Lines changed: 43 additions & 8 deletions
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)