Skip to content

Commit

Permalink
Chore: Make Clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Aug 30, 2023
1 parent 85cd7fa commit bc3a2c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
14 changes: 7 additions & 7 deletions cargo-marker/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,27 @@ mod tests {

#[test]
fn test_marker_cli() {
let cli = MarkerCli::parse_from(&["cargo-marker", "check"]);
let cli = MarkerCli::parse_from(["cargo-marker", "check"]);
assert!(matches!(cli.command, Some(CliCommand::Check(_))));

let cli = MarkerCli::parse_from(&["cargo-marker"]);
assert!(matches!(cli.command, None));
let cli = MarkerCli::parse_from(["cargo-marker"]);
assert!(cli.command.is_none());
assert!(cli.check_args.cargo_args.is_empty());

let cli = MarkerCli::parse_from(&["cargo-marker", "--", "ducks", "penguins"]);
assert!(matches!(cli.command, None));
let cli = MarkerCli::parse_from(["cargo-marker", "--", "ducks", "penguins"]);
assert!(cli.command.is_none());
assert!(cli.check_args.cargo_args.len() == 2);
assert!(cli.check_args.cargo_args[0] == "ducks");
assert!(cli.check_args.cargo_args[1] == "penguins");

let cli = MarkerCli::parse_from(&["cargo-marker", "check", "--", "ducks", "penguins"]);
let cli = MarkerCli::parse_from(["cargo-marker", "check", "--", "ducks", "penguins"]);
assert!(cli.check_args.cargo_args.is_empty());
if let Some(CliCommand::Check(check_args)) = cli.command {
assert!(check_args.cargo_args.len() == 2);
assert!(check_args.cargo_args[0] == "ducks");
assert!(check_args.cargo_args[1] == "penguins");
} else {
assert!(false, "the `check` subcommand was not detected");
panic!("the `check` subcommand was not detected");
}
}
}
2 changes: 1 addition & 1 deletion marker_uilints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = { workspace = true }
crate-type = ["cdylib"]

[dependencies]
marker_api = { workspace = true }
marker_api = { workspace = true }
marker_utils = { workspace = true }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion marker_uilints/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ pub fn check_item<'ast>(cx: &'ast AstContext<'ast>, item: ItemKind<'ast>) {
format!("testing `contains_return` -> {res}"),
ident.span(),
|_| {},
)
);
}
}
14 changes: 6 additions & 8 deletions marker_utils/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use marker_api::{
/// The target scope, is checked when the respective `traverse_*` function is called
/// For example, [`traverse_body`] will visit a given body [`Body`], but will not enter
/// nested bodies, unless [`AllBodies`](VisitorScope::AllBodies) is defined.
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Default)]
pub enum VisitorScope {
/// All bodies are visited, this includes bodies from nested items and closures.
Expand All @@ -49,10 +50,7 @@ pub enum VisitorScope {
/// This visits every node, in the current scope, but won't enter nested bodies.
///
/// This is a good default, if you only want to analyze the context of the current
/// item or expression
///
/// If you want to visit an entire [`Body`], without visiting potentially nested bodies,
/// you can pass the body expression to the [`traverse_expr`] function.
/// item or expression.
#[default]
NoBodies,
}
Expand Down Expand Up @@ -100,8 +98,6 @@ pub fn traverse_item<'ast, B>(
visitor: &mut dyn Visitor<B>,
kind: ItemKind<'ast>,
) -> ControlFlow<B> {
visitor.visit_item(cx, kind)?;

/// A small wrapper around [`traverse_body`] that checks the defined scope
/// and validity of the [`BodyId`]
fn traverse_body_id<'ast, B>(
Expand All @@ -122,6 +118,8 @@ pub fn traverse_item<'ast, B>(
ControlFlow::Continue(())
}

visitor.visit_item(cx, kind)?;

match kind {
ItemKind::Mod(module) => {
for mod_item in module.items() {
Expand Down Expand Up @@ -151,7 +149,7 @@ pub fn traverse_item<'ast, B>(
for variant in item.variants() {
visitor.visit_variant(cx, variant)?;
if let Some(const_expr) = variant.discriminant() {
traverse_expr(cx, visitor, const_expr.expr())?
traverse_expr(cx, visitor, const_expr.expr())?;
}
}
},
Expand Down Expand Up @@ -434,7 +432,7 @@ pub fn for_each_expr<'ast, B, F: for<'a> FnMut(ExprKind<'a>) -> ControlFlow<B>>(
let mut visitor = ExprVisitor { f };

match node.traverse(cx, &mut visitor) {
ControlFlow::Continue(_) => None,
ControlFlow::Continue(()) => None,
ControlFlow::Break(b) => Some(b),
}
}

0 comments on commit bc3a2c7

Please sign in to comment.