Skip to content

Commit 9e8a0fa

Browse files
committed
Lint debug prints and disallowed types with clippy
1 parent 850ba2f commit 9e8a0fa

File tree

64 files changed

+170
-229
lines changed

Some content is hidden

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

64 files changed

+170
-229
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105

106106
- name: clippy
107107
if: matrix.os == 'ubuntu-latest'
108-
run: cargo clippy --all-targets
108+
run: cargo clippy --all-targets -- -D clippy::disallowed_macros -D clippy::dbg_macro -D clippy::todo -D clippy::print_stdout -D clippy::print_stderr
109109

110110
# Weird targets to catch non-portable code
111111
rust-cross:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ len_without_is_empty = "allow"
164164
enum_variant_names = "allow"
165165
# Builder pattern disagrees
166166
new_ret_no_self = "allow"
167+
# Has a bunch of false positives
168+
useless_asref = "allow"
167169

168170
## Following lints should be tackled at some point
169171
borrowed_box = "allow"
@@ -178,9 +180,12 @@ type_complexity = "allow"
178180
wrong_self_convention = "allow"
179181

180182
## warn at following lints
183+
# CI raises these to deny
181184
dbg_macro = "warn"
182185
todo = "warn"
183-
unimplemented = "allow"
186+
print_stdout = "warn"
187+
print_stderr = "warn"
188+
184189
rc_buffer = "warn"
185190
# FIXME enable this, we use this pattern a lot so its annoying work ...
186191
# str_to_string = "warn"

clippy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
disallowed-types = [
2+
{ path = "std::collections::HashMap", reason = "use FxHashMap" },
3+
{ path = "std::collections::HashSet", reason = "use FxHashSet" },
4+
{ path = "std::collections::hash_map::RandomState", reason = "use BuildHasherDefault<FxHasher>"}
5+
]

crates/flycheck/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,7 @@ impl CargoActor {
493493
// Skip certain kinds of messages to only spend time on what's useful
494494
JsonMessage::Cargo(message) => match message {
495495
cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => {
496-
self.sender
497-
.send(CargoMessage::CompilerArtifact(Box::new(artifact)))
498-
.unwrap();
496+
self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap();
499497
}
500498
cargo_metadata::Message::CompilerMessage(msg) => {
501499
self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap();
@@ -539,8 +537,9 @@ impl CargoActor {
539537
}
540538
}
541539

540+
#[allow(clippy::large_enum_variant)]
542541
enum CargoMessage {
543-
CompilerArtifact(Box<cargo_metadata::Artifact>),
542+
CompilerArtifact(cargo_metadata::Artifact),
544543
Diagnostic(Diagnostic),
545544
}
546545

crates/hir-def/src/body/lower.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,10 +1980,7 @@ fn pat_literal_to_hir(lit: &ast::LiteralPat) -> Option<(Literal, ast::Literal)>
19801980
let ast_lit = lit.literal()?;
19811981
let mut hir_lit: Literal = ast_lit.kind().into();
19821982
if lit.minus_token().is_some() {
1983-
let Some(h) = hir_lit.negate() else {
1984-
return None;
1985-
};
1986-
hir_lit = h;
1983+
hir_lit = hir_lit.negate()?;
19871984
}
19881985
Some((hir_lit, ast_lit))
19891986
}

crates/hir-def/src/item_scope.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,15 @@ impl ItemScope {
222222
self.declarations.iter().copied()
223223
}
224224

225-
pub fn extern_crate_decls(
226-
&self,
227-
) -> impl Iterator<Item = ExternCrateId> + ExactSizeIterator + '_ {
225+
pub fn extern_crate_decls(&self) -> impl ExactSizeIterator<Item = ExternCrateId> + '_ {
228226
self.extern_crate_decls.iter().copied()
229227
}
230228

231-
pub fn use_decls(&self) -> impl Iterator<Item = UseId> + ExactSizeIterator + '_ {
229+
pub fn use_decls(&self) -> impl ExactSizeIterator<Item = UseId> + '_ {
232230
self.use_decls.iter().copied()
233231
}
234232

235-
pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
233+
pub fn impls(&self) -> impl ExactSizeIterator<Item = ImplId> + '_ {
236234
self.impls.iter().copied()
237235
}
238236

crates/hir-ty/src/layout/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::collections::HashMap;
2-
31
use chalk_ir::{AdtId, TyKind};
42
use either::Either;
53
use hir_def::db::DefDatabase;
4+
use rustc_hash::FxHashMap;
65
use test_fixture::WithFixture;
76
use triomphe::Arc;
87

@@ -16,7 +15,7 @@ use crate::{
1615
mod closure;
1716

1817
fn current_machine_data_layout() -> String {
19-
project_model::target_data_layout::get(None, None, &HashMap::default()).unwrap()
18+
project_model::target_data_layout::get(None, None, &FxHashMap::default()).unwrap()
2019
}
2120

2221
fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Arc<Layout>, LayoutError> {

crates/hir-ty/src/tests.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod regression;
1010
mod simple;
1111
mod traits;
1212

13-
use std::{collections::HashMap, env};
13+
use std::env;
1414

1515
use base_db::{FileRange, SourceDatabaseExt};
1616
use expect_test::Expect;
@@ -25,6 +25,7 @@ use hir_def::{
2525
};
2626
use hir_expand::{db::ExpandDatabase, InFile};
2727
use once_cell::race::OnceBool;
28+
use rustc_hash::FxHashMap;
2829
use stdx::format_to;
2930
use syntax::{
3031
ast::{self, AstNode, HasName},
@@ -90,9 +91,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
9091
let (db, files) = TestDB::with_many_files(ra_fixture);
9192

9293
let mut had_annotations = false;
93-
let mut mismatches = HashMap::new();
94-
let mut types = HashMap::new();
95-
let mut adjustments = HashMap::<_, Vec<_>>::new();
94+
let mut mismatches = FxHashMap::default();
95+
let mut types = FxHashMap::default();
96+
let mut adjustments = FxHashMap::<_, Vec<_>>::default();
9697
for (file_id, annotations) in db.extract_annotations() {
9798
for (range, expected) in annotations {
9899
let file_range = FileRange { file_id, range };

crates/hir-ty/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ struct LoggingRustIrDatabaseLoggingOnDrop<'a>(LoggingRustIrDatabase<Interner, Ch
187187

188188
impl Drop for LoggingRustIrDatabaseLoggingOnDrop<'_> {
189189
fn drop(&mut self) {
190-
eprintln!("chalk program:\n{}", self.0);
190+
tracing::info!("chalk program:\n{}", self.0);
191191
}
192192
}
193193

0 commit comments

Comments
 (0)