Skip to content

Commit 4065d4d

Browse files
committed
cleanup: no clippy warnings, no compiler warnings, and cargo fmt over the workspace
`cargo clippy --workspace --all-targets` is now silent (was 159 warnings) and `cargo fmt --all -- --check` is empty. Also removes the six planning documents under `docs/` that the release no longer ships — `architecture.md`, `cpp-format.md`, `format-strings.md`, `lsp-status.md`, `option-matrix.md`, `remaining.md`; `docs/configuration.md` stays. **What clippy could fix itself** (34 sites, applied by `clippy --fix`): `needless_borrow`, `useless_conversion`, `redundant_closure`, `manual_contains`, `collapsible_if`, `single_element_loop`, `while_let_loop`, `question_mark`, `match_like_matches_macro`, `sort_by_key`, `needless_update`, `print_literal`, `useless_format`, `iter_nth_zero`, `double_parens`, `chunks_exact_to_as_chunks`, `bind_instead_of_map`, `doc_lazy_continuation`, `obfuscated_if_else`, `needless_range_loop` in the formatter, `items_after_test_module` (the moved function is `init_depths`). **What it could not, and what each answer was:** * `too_many_arguments` / `type_complexity` (26 sites): answered with a **crate-level allow and a rationale** in `cpp_code_analysis` and `cpp_formatter` — a question in this layer is asked with `(index, scopes, root, path)` and then with what it is about, which is not a data clump to bundle, and the memo tables are spelled out where the reader checks them against the code that inserts into them. * `large_enum_variant` (1): allowed on the enum, with the reason — boxing the found case of `Known` would allocate on the hot path of every member lookup to save bytes in a value that lives for one question. * `len_without_is_empty` (1): `is_empty` added to `Surfaces`. * `wrong_self_convention` (1): `as_a_template` takes its receiver by value, so it is now `into_a_template`. * `zombie_processes` (1): the progress test kills its server and now **waits** on it. * `assertions_on_constants` (2): the ranking invariants in `matching.rs` are `const _: () = assert!(…)`, so a reordering fails the build instead of a test. * `ptr_arg` (1): `&PathBuf` → `&Path`. * `duplicated_attribute` (1): the inner `#![allow(dead_code)]` in `walk_cache.rs` duplicated the one on its `mod` declaration. * `empty_line_after_doc_comments` (14): each was a **floating doc block** with no item — the text is kept, as `//` comments, because pretending it documented the next item would have been a new lie. The one exception is the doc block that belonged to `fn read_a_template_id_here`, which is now where it belongs. * `items_after_test_module` (8): handled by the fix where it could move the item; `layout.rs`''s `init_depths` is the one that moved. * dead test helpers (2): `#[allow(dead_code)]` on the shared `assert_all_parse` (only some test binaries call it), and the unused `inside_the_call` in `c_project.rs` deleted. **One real correctness fix came out of it**: `features.rs` asserted `!if … { true } else { false } && !…`, which is a negation of a literal and read as "typeof is supported" — the test now says what it meant, `assert!(!strict_cpp.support(Feature::Typeof))`. Suites: `cpp_parser` 33, `cpp_code_analysis` 50, `cpp_ls --release` 18, `cpp_formatter` — all green; `cargo build --release --workspace` and `cargo clippy --workspace --all-targets` both warn-free.
1 parent a30a7f3 commit 4065d4d

76 files changed

Lines changed: 831 additions & 9349 deletions

Some content is hidden

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

‎crates/cpp_code_analysis/src/cache/mod.rs‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@ const fn parse_fingerprint(text: &str) -> u64 {
151151
/// only grows is a `.cppls` that one day is the largest thing in the checkout.
152152
pub const CACHE_BUDGET_BYTES: u64 = 2 * 1024 * 1024 * 1024;
153153

154-
/// Sweep `<cache>/summaries`: remove what can never be served, then the oldest until the rest fits `budget_bytes`.
155-
///
156-
/// # Why this is needed, and why it is safe to run beside a session
157-
///
158-
/// The key contains [`READING_FINGERPRINT`], which is a hash of the readers' source, so **every change to a reader
159-
/// makes every entry written before it unreachable** — not wrong, just never asked for again. Nothing removed them.
160-
/// A developer of this crate, or a user upgrading it, left a whole project's worth of summaries behind each time.
161-
///
162-
/// A sweep only ever removes files a cache miss would rebuild: an unreachable file is never looked up, and a file
163-
/// removed for being old is one the next run re-derives. A file that disappears between the directory listing and
164-
/// the removal is somebody else's sweep, and is not an error. Writes are `.tmp` then rename
165-
/// ([`crate::index::write_summary`]), so a sweep never sees half a summary; a `.tmp` it finds is removed only when
166-
/// it is old enough that no writer can still own it.
167-
///
168-
/// A missing cache directory is an empty cache, and the sweep does not create it.
169-
///
170-
/// "Oldest" is by modification time — a hit does not rewrite an entry, so this is *first written*, not *last used*,
154+
// Sweep `<cache>/summaries`: remove what can never be served, then the oldest until the rest fits `budget_bytes`.
155+
//
156+
// # Why this is needed, and why it is safe to run beside a session
157+
//
158+
// The key contains [`READING_FINGERPRINT`], which is a hash of the readers' source, so **every change to a reader
159+
// makes every entry written before it unreachable** — not wrong, just never asked for again. Nothing removed them.
160+
// A developer of this crate, or a user upgrading it, left a whole project's worth of summaries behind each time.
161+
//
162+
// A sweep only ever removes files a cache miss would rebuild: an unreachable file is never looked up, and a file
163+
// removed for being old is one the next run re-derives. A file that disappears between the directory listing and
164+
// the removal is somebody else's sweep, and is not an error. Writes are `.tmp` then rename
165+
// ([`crate::index::write_summary`]), so a sweep never sees half a summary; a `.tmp` it finds is removed only when
166+
// it is old enough that no writer can still own it.
167+
//
168+
// A missing cache directory is an empty cache, and the sweep does not create it.
169+
//
170+
// "Oldest" is by modification time — a hit does not rewrite an entry, so this is *first written*, not *last used*,
171171

172172
/// The directory name this crate keeps its cache in, under the project root.
173173
///
@@ -378,11 +378,11 @@ mod tests {
378378
crate::index::write_summary(&summary, directory).expect("the summary is written")
379379
}
380380

381-
/// A summary another reader wrote is garbage the moment the reader changes; nothing else is touched.
381+
// A summary another reader wrote is garbage the moment the reader changes; nothing else is touched.
382382

383-
/// Over budget, the oldest go first — and only as many as it takes.
383+
// Over budget, the oldest go first — and only as many as it takes.
384384

385-
/// A project that has never been cached has nothing to sweep, and asking must not create the directory.
385+
// A project that has never been cached has nothing to sweep, and asking must not create the directory.
386386

387387
#[test]
388388
fn the_layout_is_sharded_and_inside_the_project() {

‎crates/cpp_code_analysis/src/completion/context.rs‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,37 @@ fn inside_a_comment_or_a_literal(root: &CppSyntaxNode, offset: usize) -> bool {
728728
.any(|node| CppSyntaxKind::from(node.kind()) == CppSyntaxKind::DocComment)
729729
}
730730

731+
/// **The name being typed in a condition** — `#if VERS|`, `#if defined(VERS|`, or the blank after the operator.
732+
///
733+
/// `segment_written` is handed the text from the argument`s start to the cursor and answers the word the cursor is
734+
/// in; the `>`/`<`/`!`/`(`/`)` of an expression are not name characters, so a condition like
735+
/// `#if VERSION >= 3 && defined(FEATURE|)` needs no special case — the word is whatever follows the last one.
736+
fn condition_argument(
737+
rest: &str,
738+
at: usize,
739+
written_before_cursor: usize,
740+
offset: usize,
741+
) -> CompletionContext {
742+
let _ = written_before_cursor;
743+
let trimmed = rest.trim_start();
744+
let skipped = rest.len() - trimmed.len();
745+
746+
// **The word the cursor is in**, which is not the first word of the argument: `defined(FEATU|)` has `defined`
747+
// in front of it, and answering with that word would offer the operators for a name being typed.
748+
let word_start = trimmed
749+
.rfind(|character: char| {
750+
!(character.is_alphanumeric()
751+
|| character == '_'
752+
|| character == '.'
753+
|| character == '/'
754+
|| character == '-')
755+
})
756+
.map_or(0, |found| found + 1);
757+
let (written, range) =
758+
segment_written(&trimmed[word_start..], at + skipped + word_start, offset);
759+
CompletionContext::Condition { written, range }
760+
}
761+
731762
#[cfg(test)]
732763
mod tests {
733764
use super::*;
@@ -933,34 +964,3 @@ mod tests {
933964
}
934965
}
935966
}
936-
937-
/// **The name being typed in a condition** — `#if VERS|`, `#if defined(VERS|`, or the blank after the operator.
938-
///
939-
/// `segment_written` is handed the text from the argument`s start to the cursor and answers the word the cursor is
940-
/// in; the `>`/`<`/`!`/`(`/`)` of an expression are not name characters, so a condition like
941-
/// `#if VERSION >= 3 && defined(FEATURE|)` needs no special case — the word is whatever follows the last one.
942-
fn condition_argument(
943-
rest: &str,
944-
at: usize,
945-
written_before_cursor: usize,
946-
offset: usize,
947-
) -> CompletionContext {
948-
let _ = written_before_cursor;
949-
let trimmed = rest.trim_start();
950-
let skipped = rest.len() - trimmed.len();
951-
952-
// **The word the cursor is in**, which is not the first word of the argument: `defined(FEATU|)` has `defined`
953-
// in front of it, and answering with that word would offer the operators for a name being typed.
954-
let word_start = trimmed
955-
.rfind(|character: char| {
956-
!(character.is_alphanumeric()
957-
|| character == '_'
958-
|| character == '.'
959-
|| character == '/'
960-
|| character == '-')
961-
})
962-
.map_or(0, |found| found + 1);
963-
let (written, range) =
964-
segment_written(&trimmed[word_start..], at + skipped + word_start, offset);
965-
CompletionContext::Condition { written, range }
966-
}

‎crates/cpp_code_analysis/src/completion/matching.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ mod tests {
303303
assert_eq!(quality("string", "str"), PREFIX);
304304
assert_eq!(quality("string", "STRING"), PREFIX);
305305
assert_eq!(quality("String", "str"), PREFIX);
306-
assert!(PREFIX > WORD_START);
306+
// **The ranking, checked at compile time**: the constants are the table beside them, and a reordering that broke
307+
// it would fail the build rather than a test in a suite nobody runs.
308+
const _: () = assert!(PREFIX > WORD_START);
307309
}
308310

309311
#[test]
@@ -335,7 +337,7 @@ mod tests {
335337
// one than a name it begins.
336338
assert!(quality("to_string", "string") <= WORD_PREFIX);
337339
assert_eq!(quality("to_string", "to"), PREFIX);
338-
assert!(WORD_PREFIX < WORD_START);
340+
const _: () = assert!(WORD_PREFIX < WORD_START);
339341
}
340342

341343
#[test]

‎crates/cpp_code_analysis/src/completion/mod.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ pub fn completion_with(
339339
// everything below is the query's own work, and the server's log line splits only the outside of it
340340
// (`view`/`completions`). Opt-in, on `CPPLS_TRACE_COMPLETION`, like this crate's other traces — see
341341

342-
343-
344342
match context {
345343
CompletionContext::Nothing => CompletionSet {
346344
replace: SourceRange::new(offset, 0),

‎crates/cpp_code_analysis/src/effect.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ impl Surfaces {
366366
pub fn len(&self) -> usize {
367367
self.held.lock().map(|held| held.len()).unwrap_or(0)
368368
}
369+
370+
/// **Nothing held** — the same question as `len() == 0`, written where a caller looks for it.
371+
pub fn is_empty(&self) -> bool {
372+
self.len() == 0
373+
}
369374
}
370375

371376
/// **How the chain reads files**: a provider and an include resolver, both as plain functions so that a caller can
@@ -725,13 +730,10 @@ mod tests {
725730
let mut applied = Macros::new();
726731
effect_of(&surface, &Macros::new()).apply(&mut applied);
727732
assert_eq!(
728-
applied.get("WITH_ARGS").map(|held| body_text(held)),
733+
applied.get("WITH_ARGS").map(body_text),
729734
Some("((x) + 1)".to_string())
730735
);
731-
assert_eq!(
732-
applied.get("PLAIN").map(|held| body_text(held)),
733-
Some("(1)".to_string())
734-
);
736+
assert_eq!(applied.get("PLAIN").map(body_text), Some("(1)".to_string()));
735737
}
736738

737739
/// A small include graph, in memory: the reader and resolver a chain needs.
@@ -926,7 +928,7 @@ mod tests {
926928
for name in names {
927929
let from_chain = table
928930
.get(name)
929-
.map(|held| body_text(held))
931+
.map(body_text)
930932
.map(|text| text.trim().to_string());
931933
let from_walk = view
932934
.body_text_of(name, usize::MAX)

‎crates/cpp_code_analysis/src/format/locator.rs‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ fn the_call_a_literal_is_in(
157157
let mut first = name_end;
158158
let mut qualified = false;
159159
let mut member = false;
160-
loop {
161-
let Some(before_this) = previous_significant(tokens, first) else {
162-
break;
163-
};
160+
while let Some(before_this) = previous_significant(tokens, first) {
164161
match tokens[before_this].kind {
165162
CppTokenKind::Scope => {
166163
// A leading `::` — `::printf`, the global scope. It is part of the spelling but not a qualifier:
@@ -382,9 +379,7 @@ fn the_format_kind_of(
382379
return Some(entry.syntax);
383380
}
384381

385-
let Some(&(_, kind, position)) = THE_TABLE.iter().find(|(name, _, _)| *name == bare) else {
386-
return None;
387-
};
382+
let &(_, kind, position) = THE_TABLE.iter().find(|(name, _, _)| *name == bare)?;
388383

389384
// **One name whose position depends on the library that declares it.** `sprintf` is the C library's
390385
// `sprintf(buffer, format, …)` — the format string is the second argument — and `fmt::sprintf(format, …)` is

‎crates/cpp_code_analysis/src/index/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ impl<'a, F: FileProvider> FileIndexer<'a, F> {
717717
// [`preprocess_with`], which is where the rule and its cost are stated.
718718
match self.seed {
719719
Some(seed) => {
720-
721720
crate::preprocess::preprocess_with_a_seed(source, tree.get_tokens(), seed)
722721
}
723722
None => crate::preprocess::preprocess(source, tree.get_tokens()),

‎crates/cpp_code_analysis/src/index/project.rs‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ pub(crate) fn classes_the_cursor_is_in(
11941194
/// [`DeclFact::bases`] — and filtering on a guess would hide members a consumer can legitimately see.
11951195
/// * No instantiation. A template class lists the members it was written with; a base written `Base<int>` is
11961196
/// looked up as the class `Base`.
1197+
///
11971198
/// **The members written in the class itself** — [`members_of`]'s first step, and nothing else.
11981199
///
11991200
/// [`members_of`] answers the question a *reader* asks ("what can I write after `.`"), and it walks the base chain
@@ -2383,7 +2384,6 @@ pub fn name_completions_traced(
23832384
path: &Path,
23842385
offset: usize,
23852386
) -> Known<NameCompletions> {
2386-
23872387
name_completions_at(index, scopes, root, path, offset)
23882388
}
23892389

@@ -4560,7 +4560,7 @@ pub(crate) fn operator_returns_of(
45604560
}
45614561
}
45624562

4563-
let class_view = class_file.as_deref().and_then((declaring));
4563+
let class_view = class_file.as_deref().and_then(declaring);
45644564
let (class_scopes, class_root, class_path) = match &class_view {
45654565
Some(view) => (&view.scopes, &view.root, view.path.as_path()),
45664566
None => (scopes, root, path),
@@ -4873,6 +4873,11 @@ fn pointee_type_name(written: &str) -> Option<String> {
48734873
/// thing for a consumer to be told.
48744874
///
48754875
/// [`UnknownType`]: UnknownReason::UnknownType
4876+
// **A big variant, kept inline on purpose.** `Known` answers for every expression the engine types, and boxing the
4877+
// found case would put an allocation on the hot path of every member lookup to save the difference between 392 and
4878+
// 48 bytes in an enum that lives for the length of one question. The variants are also matched on by value in a
4879+
// dozen places, where the box would be a deref at each site.
4880+
#[allow(clippy::large_enum_variant)]
48764881
enum NamedDeclaration {
48774882
/// A binding of the file being edited. Its spellings come from the tree the caller has.
48784883
Here(crate::Binding),
@@ -5044,9 +5049,7 @@ impl NamedDeclaration {
50445049
&fact.parameters,
50455050
written_arguments,
50465051
);
5047-
let Some(declared_in) = declaring(file.as_path()) else {
5048-
return None;
5049-
};
5052+
let declared_in = declaring(file.as_path())?;
50505053
let Known::Yes(binding) = crate::sema::resolve::definition_at(
50515054
&declared_in.scopes,
50525055
&declared_in.root,
@@ -5317,9 +5320,7 @@ fn a_trait_alias_resolved(
53175320
.map(|one| one.to_string())
53185321
.collect();
53195322
let bare = crate::sema::types::parse_type_spelling(&class);
5320-
let Some(class_name) = bare.class_name() else {
5321-
return None;
5322-
};
5323+
let class_name = bare.class_name()?;
53235324
let parameters = index.template_parameters_for(class_name, path, &arguments);
53245325
let defaults = index.template_parameter_defaults_for(class_name, path, &arguments);
53255326
let resolved = crate::sema::types::substituted_spelling_with_defaults(
@@ -7887,9 +7888,9 @@ fn member_fact_inner(
78877888
if let Some(declared_in) = qualified_from_the_index(index, path, bare)
78887889
&& let Some(found) =
78897890
direct_member(index, scopes, root, path, &declared_in, member, arguments)
7890-
{
7891-
return Known::Yes(found);
7892-
}
7891+
{
7892+
return Known::Yes(found);
7893+
}
78937894
}
78947895

78957896
// Inherited members, **level by level**: a member of a direct base hides a member of that base's own base,
@@ -8837,7 +8838,6 @@ fn bases_of(
88378838
path: &Path,
88388839
class: &str,
88398840
) -> Known<Vec<String>> {
8840-
88418841
bases_of_inner(index, scopes, root, path, class)
88428842
}
88438843

@@ -11082,8 +11082,6 @@ impl ProjectIndex {
1108211082
}
1108311083
}
1108411084

11085-
11086-
1108711085
order
1108811086
.into_iter()
1108911087
.filter_map(|path| {

‎crates/cpp_code_analysis/src/index/references.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,7 @@ mod tests {
797797
format!(
798798
"{}:{line}:{}",
799799
file.file_name().unwrap().to_string_lossy(),
800-
text[reference.range.start_offset..reference.range.end_offset()]
801-
.to_string()
800+
&text[reference.range.start_offset..reference.range.end_offset()]
802801
)
803802
})
804803
.collect(),

‎crates/cpp_code_analysis/src/index/store.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,10 @@ impl<F: FileProvider> SummaryStore<F> {
524524
/// **Start a generation**, so a collection can tell this run's rows from the last one's.
525525
pub fn begin_generation(&mut self) {
526526
if let Some(database) = self.summary_database()
527-
&& let Ok(generation) = database.begin_generation() {
528-
self.generation = generation;
529-
}
527+
&& let Ok(generation) = database.begin_generation()
528+
{
529+
self.generation = generation;
530+
}
530531
}
531532

532533
/// **A unit rendering the database already has**, by the closure key `Session::render_the_unit` computes.
@@ -861,7 +862,8 @@ impl<F: FileProvider> SummaryStore<F> {
861862
// **The database, and only the database.**
862863
let stored = self
863864
.summary_database()
864-
.and_then(|database| database.summary(key)).ok_or(());
865+
.and_then(|database| database.summary(key))
866+
.ok_or(());
865867
if let Ok(stored) = stored
866868
&& stored.key == key
867869
{

0 commit comments

Comments
 (0)