Skip to content

Commit

Permalink
Enable pedantic lints and fix violations
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Apr 27, 2024
1 parent d3620e4 commit dd4748b
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
3 changes: 2 additions & 1 deletion crates/red_knot/src/cache.rs
Expand Up @@ -101,6 +101,7 @@ pub struct Statistics {
}

impl Statistics {
#[allow(clippy::cast_precision_loss)]
pub fn hit_rate(&self) -> Option<f64> {
if self.hits + self.misses == 0 {
return None;
Expand Down Expand Up @@ -144,7 +145,7 @@ impl DebugStatistics {
pub struct ReleaseStatistics;

impl ReleaseStatistics {
#[inline(always)]
#[inline]
pub fn to_statistics(&self) -> Option<Statistics> {
None
}
Expand Down
2 changes: 0 additions & 2 deletions crates/red_knot/src/hir.rs
Expand Up @@ -18,8 +18,6 @@ use crate::files::FileId;
use std::fmt::Formatter;
use std::hash::{Hash, Hasher};

pub mod definition;

pub struct HirAstId<N: HasAstId> {
file_id: FileId,
node_id: TypedAstId<N>,
Expand Down
2 changes: 0 additions & 2 deletions crates/red_knot/src/lib.rs
@@ -1,5 +1,3 @@
#![allow(clippy::pedantic)]

use std::hash::BuildHasherDefault;
use std::path::{Path, PathBuf};

Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot/src/lint.rs
Expand Up @@ -30,9 +30,9 @@ where
source: source.text(),
};
visitor.visit_body(&ast.body);
diagnostics = visitor.diagnostics
diagnostics = visitor.diagnostics;
} else {
diagnostics.extend(parsed.errors().iter().map(|err| err.to_string()));
diagnostics.extend(parsed.errors().iter().map(std::string::ToString::to_string));
}

Diagnostics::from(diagnostics)
Expand Down
1 change: 1 addition & 0 deletions crates/red_knot/src/module.rs
Expand Up @@ -407,6 +407,7 @@ impl ModuleResolver {
}
}

#[allow(clippy::missing_fields_in_debug)]
impl std::fmt::Debug for ModuleResolver {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ModuleResolver")
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot/src/program/mod.rs
Expand Up @@ -50,7 +50,7 @@ impl Program {
self.source.parsed.remove(&change.id);
self.source.lint_syntax.remove(&change.id);
// TODO: remove all dependent modules as well
self.semantic.type_store.remove_module(&change.id);
self.semantic.type_store.remove_module(change.id);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/red_knot/src/symbols.rs
Expand Up @@ -229,7 +229,7 @@ impl SymbolTable {
pub(crate) fn defs(&self, symbol_id: SymbolId) -> &[Definition] {
self.defs
.get(&symbol_id)
.map(|defs| defs.as_slice())
.map(std::vec::Vec::as_slice)
.unwrap_or_default()
}

Expand Down Expand Up @@ -446,7 +446,7 @@ impl PreorderVisitor<'_> for SymbolTableBuilder {
alias.name.id.split('.').next().unwrap()
};
let def = Definition::Import(ImportDefinition {
module: alias.name.id.to_owned(),
module: alias.name.id.clone(),
});
self.add_symbol_with_def(symbol_name, def);
}
Expand Down Expand Up @@ -516,7 +516,7 @@ mod tests {
I: Iterator<Item = SymbolId>,
{
let mut symbols: Vec<_> = it.map(|sym| sym.name.as_str()).collect();
symbols.sort();
symbols.sort_unstable();
symbols
}

Expand Down
18 changes: 9 additions & 9 deletions crates/red_knot/src/types.rs
Expand Up @@ -47,8 +47,8 @@ pub struct TypeStore {
}

impl TypeStore {
pub fn remove_module(&mut self, file_id: &FileId) {
self.modules.remove(file_id);
pub fn remove_module(&mut self, file_id: FileId) {
self.modules.remove(&file_id);
}

pub fn cache_symbol_type(&mut self, file_id: FileId, symbol_id: SymbolId, ty: Type) {
Expand Down Expand Up @@ -300,7 +300,7 @@ impl ModuleTypeStore {

fn add_union(&mut self, elems: &[Type]) -> UnionTypeId {
let union_id = self.unions.push(UnionType {
elements: FxIndexSet::from_iter(elems.iter().copied()),
elements: elems.iter().copied().collect(),
});
UnionTypeId {
file_id: self.file_id,
Expand All @@ -310,8 +310,8 @@ impl ModuleTypeStore {

fn add_intersection(&mut self, positive: &[Type], negative: &[Type]) -> IntersectionTypeId {
let intersection_id = self.intersections.push(IntersectionType {
positive: FxIndexSet::from_iter(positive.iter().copied()),
negative: FxIndexSet::from_iter(negative.iter().copied()),
positive: positive.iter().copied().collect(),
negative: negative.iter().copied().collect(),
});
IntersectionTypeId {
file_id: self.file_id,
Expand Down Expand Up @@ -397,7 +397,7 @@ impl UnionType {
fn display(&self, f: &mut std::fmt::Formatter<'_>, store: &TypeStore) -> std::fmt::Result {
f.write_str("(")?;
let mut first = true;
for ty in self.elements.iter() {
for ty in &self.elements {
if !first {
f.write_str(" | ")?;
};
Expand Down Expand Up @@ -485,7 +485,7 @@ mod tests {
let id = store.add_union(file_id, &elems);
assert_eq!(
store.get_union(id).elements,
FxIndexSet::from_iter(elems.iter().copied())
elems.into_iter().collect::<FxIndexSet<_>>()
);
let union = Type::Union(id);
assert_eq!(format!("{}", union.display(&store)), "(C1 | C2)");
Expand All @@ -504,11 +504,11 @@ mod tests {
let id = store.add_intersection(file_id, &pos, &neg);
assert_eq!(
store.get_intersection(id).positive,
FxIndexSet::from_iter(pos.iter().copied())
pos.into_iter().collect::<FxIndexSet<_>>()
);
assert_eq!(
store.get_intersection(id).negative,
FxIndexSet::from_iter(neg.iter().copied())
neg.into_iter().collect::<FxIndexSet<_>>()
);
let intersection = Type::Intersection(id);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot/src/watch.rs
Expand Up @@ -60,8 +60,8 @@ impl FileWatcher {
}
}
// TODO proper error handling
Err(_err) => {
panic!("Error");
Err(err) => {
panic!("Error: {err}");
}
}
})
Expand Down

0 comments on commit dd4748b

Please sign in to comment.