Use `panic` instead of `unreachable` for invalid arguments (#3816)

This commit is contained in:
Charlie Marsh 2023-03-30 11:40:53 -04:00 committed by GitHub
parent 01357f62e5
commit 0b586d5451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 13 additions and 13 deletions

View File

@ -4735,7 +4735,7 @@ impl<'a> Checker<'a> {
);
}
} else {
unreachable!("Expected ExprKind::Lambda");
unreachable!("Expected ExprKind::For | ExprKind::AsyncFor");
}
}
}

View File

@ -512,7 +512,7 @@ pub fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
/// PIE807
pub fn reimplemented_list_builtin(checker: &mut Checker, expr: &Expr) {
let ExprKind::Lambda { args, body } = &expr.node else {
unreachable!("Expected ExprKind::Lambda");
panic!("Expected ExprKind::Lambda");
};
if args.args.is_empty()
&& args.kwonlyargs.is_empty()

View File

@ -119,7 +119,7 @@ fn reverse_comparison(expr: &Expr, locator: &Locator, stylist: &Stylist) -> Resu
whitespace_before,
whitespace_after,
},
_ => unreachable!("Expected comparison operator"),
_ => panic!("Expected comparison operator"),
};
let mut state = CodegenState {

View File

@ -141,7 +141,7 @@ fn fix_banned_relative_import(
};
let StmtKind::ImportFrom { names, .. } = &stmt.node else {
unreachable!("Expected StmtKind::ImportFrom");
panic!("Expected StmtKind::ImportFrom");
};
let content = unparse_stmt(
&create_stmt(StmtKind::ImportFrom {

View File

@ -317,6 +317,6 @@ pub fn unused_arguments(
vec![]
}
}
_ => unreachable!("Expected ScopeKind::Function | ScopeKind::Lambda"),
_ => panic!("Expected ScopeKind::Function | ScopeKind::Lambda"),
}
}

View File

@ -116,7 +116,7 @@ pub fn annotate_imports<'a>(
inline,
});
}
_ => unreachable!("Expected StmtKind::Import | StmtKind::ImportFrom"),
_ => panic!("Expected StmtKind::Import | StmtKind::ImportFrom"),
}
}
annotated

View File

@ -22,7 +22,7 @@ impl From<&Cmpop> for EqCmpop {
match cmpop {
Cmpop::Eq => EqCmpop::Eq,
Cmpop::NotEq => EqCmpop::NotEq,
_ => unreachable!("Expected Cmpop::Eq | Cmpop::NotEq"),
_ => panic!("Expected Cmpop::Eq | Cmpop::NotEq"),
}
}
}

View File

@ -23,7 +23,7 @@ impl From<&Cmpop> for IsCmpop {
match cmpop {
Cmpop::Is => IsCmpop::Is,
Cmpop::IsNot => IsCmpop::IsNot,
_ => unreachable!("Expected Cmpop::Is | Cmpop::IsNot"),
_ => panic!("Expected Cmpop::Is | Cmpop::IsNot"),
}
}
}

View File

@ -48,7 +48,7 @@ pub fn yield_outside_function(checker: &mut Checker, expr: &Expr) {
ExprKind::Yield { .. } => DeferralKeyword::Yield,
ExprKind::YieldFrom { .. } => DeferralKeyword::YieldFrom,
ExprKind::Await { .. } => DeferralKeyword::Await,
_ => unreachable!("Expected ExprKind::Yield | ExprKind::YieldFrom | ExprKind::Await"),
_ => panic!("Expected ExprKind::Yield | ExprKind::YieldFrom | ExprKind::Await"),
};
checker.diagnostics.push(Diagnostic::new(
YieldOutsideFunction { keyword },

View File

@ -66,6 +66,6 @@ pub fn deprecated_c_element_tree(checker: &mut Checker, stmt: &Stmt) {
}
}
}
_ => unreachable!("Expected StmtKind::Import | StmtKind::ImportFrom"),
_ => panic!("Expected StmtKind::Import | StmtKind::ImportFrom"),
}
}

View File

@ -241,7 +241,7 @@ fn format_import_from(
content
})
} else {
unreachable!("Expected ImportNames::Aliases | ImportNames::Star");
panic!("Expected ImportNames::Aliases | ImportNames::Star");
}
}

View File

@ -77,7 +77,7 @@ fn tuple_diagnostic(checker: &mut Checker, target: &Expr, aliases: &[&Expr]) {
let mut diagnostic = Diagnostic::new(OSErrorAlias { name: None }, Range::from(target));
if checker.patch(diagnostic.kind.rule()) {
let ExprKind::Tuple { elts, ..} = &target.node else {
unreachable!("expected ExprKind::Tuple");
panic!("Expected ExprKind::Tuple");
};
// Filter out any `OSErrors` aliases.

View File

@ -42,7 +42,7 @@ fn collect_names(expr: &Expr) -> Vec<&str> {
match &expr.node {
ExprKind::Name { id, .. } => vec![id],
ExprKind::Tuple { elts, .. } => elts.iter().flat_map(collect_names).collect(),
_ => unreachable!("Expected: ExprKind::Name | ExprKind::Tuple"),
_ => panic!("Expected: ExprKind::Name | ExprKind::Tuple"),
}
}