Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Apr 18, 2024
1 parent 4c45e7e commit 7c6b06f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/red_knot/src/ast_ids.rs
Expand Up @@ -275,7 +275,7 @@ pub struct TypedNodeKey<N: AstNode> {

impl<N: AstNode> TypedNodeKey<N> {
pub fn new(node_key: NodeKey) -> Option<Self> {
N::can_cast(node_key.kind).then(|| TypedNodeKey {
N::can_cast(node_key.kind).then_some(TypedNodeKey {
inner: node_key,
_marker: PhantomData,
})
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot/src/db.rs
Expand Up @@ -309,5 +309,5 @@ pub fn definitions(db: &dyn Db, source_text: SourceText) -> Arc<Definitions> {
let ast = parsed.ast(db);
let ids = ast_ids(db, source_text);

Arc::new(Definitions::from_module(ast, &*ids, source_text.file(db)))
Arc::new(Definitions::from_module(ast, &ids, source_text.file(db)))
}
24 changes: 9 additions & 15 deletions crates/red_knot/src/hir/definition.rs
Expand Up @@ -417,34 +417,28 @@ impl DefinitionsVisitor<'_> {
fn lower_type_parameter(&mut self, type_parameter: &TypeParam) -> TypeParameterId {
match type_parameter {
TypeParam::TypeVar(type_var) => {
let id = self
.definitions
self.definitions
.type_parameters
.push(TypeParameter::TypeVar(TypeParameterTypeVar {
name: Name::new(&type_var.name),
ast_id: self.ast_id(type_var),
}));
id
}))
}
TypeParam::ParamSpec(param_spec) => {
let id = self
.definitions
self.definitions
.type_parameters
.push(TypeParameter::ParamSpec(TypeParameterParamSpec {
name: Name::new(&param_spec.name),
ast_id: self.ast_id(param_spec),
}));
id
}))
}
TypeParam::TypeVarTuple(type_var_tuple) => {
let id = self
.definitions
self.definitions
.type_parameters
.push(TypeParameter::TypeVarTuple(TypeParameterTypeVarTuple {
name: Name::new(&type_var_tuple.name),
ast_id: self.ast_id(type_var_tuple),
}));
id
}))
}
}
}
Expand Down Expand Up @@ -546,17 +540,17 @@ impl PreorderVisitor<'_> for DefinitionsVisitor<'_> {
fn visit_except_handler(&mut self, except_handler: &'_ ExceptHandler) {
match except_handler {
ExceptHandler::ExceptHandler(except_handler) => {
self.lower_except_handler(except_handler)
self.lower_except_handler(except_handler);
}
}
}

fn visit_with_item(&mut self, with_item: &'_ WithItem) {
self.lower_with_item(&with_item);
self.lower_with_item(with_item);
}

fn visit_match_case(&mut self, match_case: &'_ MatchCase) {
self.lower_match_case(&match_case);
self.lower_match_case(match_case);
self.visit_body(&match_case.body);
}
}
12 changes: 6 additions & 6 deletions crates/red_knot/src/module.rs
Expand Up @@ -53,7 +53,7 @@ impl ModuleName {
Some(Self(name))
}

pub fn components(&self) -> impl Iterator<Item = &str> + DoubleEndedIterator {
pub fn components(&self) -> impl DoubleEndedIterator<Item = &str> {
self.0.split('.')
}

Expand Down Expand Up @@ -208,7 +208,7 @@ impl ModuleResolver {

/// Returns the module for a given id.
pub fn module(&self, id: ModuleId) -> &Module {
self.modules.get(&id).unwrap()
&self.modules[&id]
}

/// Updates the last modified time for the module corresponding to `path`.
Expand Down Expand Up @@ -257,7 +257,7 @@ impl ModuleResolver {
if module.path().root() == &root_path {
let normalized = path.canonicalize().ok()?;

if !module.path().resolved().starts_with(&normalized) {
if !module.path().resolved().starts_with(normalized) {
// This path is for a module with the same name but with a different precedence. For example:
// ```
// src/foo.py
Expand Down Expand Up @@ -507,8 +507,8 @@ mod tests {
let baz = bar.join("baz.py");

std::fs::create_dir_all(&bar)?;
std::fs::write(&foo.join("__init__.py"), "")?;
std::fs::write(&bar.join("__init__.py"), "")?;
std::fs::write(foo.join("__init__.py"), "")?;
std::fs::write(bar.join("__init__.py"), "")?;
std::fs::write(&baz, "print('Hello, world!')")?;

let baz_id = test_case.resolver.resolve(ModuleName::new("foo.bar.baz"));
Expand All @@ -535,7 +535,7 @@ mod tests {
let baz = bar.join("baz.py");

std::fs::create_dir_all(&bar)?;
std::fs::write(&foo.join("__init__.py"), "")?;
std::fs::write(foo.join("__init__.py"), "")?;
std::fs::write(&baz, "print('Hello, world!')")?;

let baz_id = test_case.resolver.resolve(ModuleName::new("foo.bar.baz"));
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_ast/src/node.rs
Expand Up @@ -17,7 +17,7 @@ pub trait AstNode: Ranged {
fn cast(kind: AnyNode) -> Option<Self>
where
Self: Sized;
fn cast_ref<'a>(kind: AnyNodeRef<'a>) -> Option<Self::Ref<'a>>;
fn cast_ref(kind: AnyNodeRef<'_>) -> Option<Self::Ref<'_>>;

fn can_cast(kind: NodeKind) -> bool;

Expand Down

0 comments on commit 7c6b06f

Please sign in to comment.