diff --git a/cargo-marker/src/cli.rs b/cargo-marker/src/cli.rs index e79579d7..85640cad 100644 --- a/cargo-marker/src/cli.rs +++ b/cargo-marker/src/cli.rs @@ -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"); } } } diff --git a/marker_uilints/src/utils.rs b/marker_uilints/src/utils.rs index 9aaf15b0..d1c1cf53 100644 --- a/marker_uilints/src/utils.rs +++ b/marker_uilints/src/utils.rs @@ -21,6 +21,6 @@ pub fn check_item<'ast>(cx: &'ast AstContext<'ast>, item: ItemKind<'ast>) { format!("testing `contains_return` -> {res}"), ident.span(), |_| {}, - ) + ); } } diff --git a/marker_utils/src/visitor.rs b/marker_utils/src/visitor.rs index 6426ee52..577eafec 100644 --- a/marker_utils/src/visitor.rs +++ b/marker_utils/src/visitor.rs @@ -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. @@ -100,8 +101,6 @@ pub fn traverse_item<'ast, B>( visitor: &mut dyn Visitor, kind: ItemKind<'ast>, ) -> ControlFlow { - 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>( @@ -122,6 +121,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() { @@ -151,7 +152,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())?; } } }, @@ -434,7 +435,7 @@ pub fn for_each_expr<'ast, B, F: for<'a> FnMut(ExprKind<'a>) -> ControlFlow>( let mut visitor = ExprVisitor { f }; match node.traverse(cx, &mut visitor) { - ControlFlow::Continue(_) => None, + ControlFlow::Continue(()) => None, ControlFlow::Break(b) => Some(b), } }