Skip to content

Commit 497e879

Browse files
committed
Remove old macro utils
1 parent a6ebea7 commit 497e879

File tree

4 files changed

+1
-146
lines changed

4 files changed

+1
-146
lines changed

clippy_utils/src/ast_utils.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)]
66

77
use crate::{both, over};
8-
use if_chain::if_chain;
98
use rustc_ast::ptr::P;
109
use rustc_ast::{self as ast, *};
1110
use rustc_span::symbol::Ident;
@@ -679,34 +678,3 @@ pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool {
679678
_ => false,
680679
}
681680
}
682-
683-
/// Extract args from an assert-like macro.
684-
///
685-
/// Currently working with:
686-
/// - `assert_eq!` and `assert_ne!`
687-
/// - `debug_assert_eq!` and `debug_assert_ne!`
688-
///
689-
/// For example:
690-
///
691-
/// `debug_assert_eq!(a, b)` will return Some([a, b])
692-
pub fn extract_assert_macro_args(mut expr: &Expr) -> Option<[&Expr; 2]> {
693-
if_chain! {
694-
if let ExprKind::If(_, ref block, _) = expr.kind;
695-
if let StmtKind::Semi(ref e) = block.stmts.get(0)?.kind;
696-
then {
697-
expr = e;
698-
}
699-
}
700-
if_chain! {
701-
if let ExprKind::Block(ref block, _) = expr.kind;
702-
if let StmtKind::Expr(ref expr) = block.stmts.get(0)?.kind;
703-
if let ExprKind::Match(ref match_expr, _) = expr.kind;
704-
if let ExprKind::Tup(ref tup) = match_expr.kind;
705-
if let [a, b, ..] = tup.as_slice();
706-
if let (&ExprKind::AddrOf(_, _, ref a), &ExprKind::AddrOf(_, _, ref b)) = (&a.kind, &b.kind);
707-
then {
708-
return Some([&*a, &*b]);
709-
}
710-
}
711-
None
712-
}

clippy_utils/src/higher.rs

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
33
#![deny(clippy::missing_docs_in_private_items)]
44

5-
use crate::macros::FormatArgsExpn;
65
use crate::ty::is_type_diagnostic_item;
76
use crate::{is_expn_of, match_def_path, paths};
87
use if_chain::if_chain;
98
use rustc_ast::ast::{self, LitKind};
109
use rustc_hir as hir;
11-
use rustc_hir::{
12-
Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath, StmtKind, UnOp,
13-
};
10+
use rustc_hir::{Arm, Block, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath};
1411
use rustc_lint::LateContext;
1512
use rustc_span::{sym, symbol, Span};
1613

@@ -429,85 +426,6 @@ pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
429426
}
430427
}
431428

432-
/// Extract args from an assert-like macro.
433-
/// Currently working with:
434-
/// - `assert!`, `assert_eq!` and `assert_ne!`
435-
/// - `debug_assert!`, `debug_assert_eq!` and `debug_assert_ne!`
436-
/// For example:
437-
/// `assert!(expr)` will return `Some([expr])`
438-
/// `debug_assert_eq!(a, b)` will return `Some([a, b])`
439-
pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option<Vec<&'tcx Expr<'tcx>>> {
440-
/// Try to match the AST for a pattern that contains a match, for example when two args are
441-
/// compared
442-
fn ast_matchblock(matchblock_expr: &'tcx Expr<'tcx>) -> Option<Vec<&Expr<'_>>> {
443-
if_chain! {
444-
if let ExprKind::Match(headerexpr, _, _) = &matchblock_expr.kind;
445-
if let ExprKind::Tup([lhs, rhs]) = &headerexpr.kind;
446-
if let ExprKind::AddrOf(BorrowKind::Ref, _, lhs) = lhs.kind;
447-
if let ExprKind::AddrOf(BorrowKind::Ref, _, rhs) = rhs.kind;
448-
then {
449-
return Some(vec![lhs, rhs]);
450-
}
451-
}
452-
None
453-
}
454-
455-
if let ExprKind::Block(block, _) = e.kind {
456-
if block.stmts.len() == 1 {
457-
if let StmtKind::Semi(matchexpr) = block.stmts.get(0)?.kind {
458-
// macros with unique arg: `{debug_}assert!` (e.g., `debug_assert!(some_condition)`)
459-
if_chain! {
460-
if let Some(If { cond, .. }) = If::hir(matchexpr);
461-
if let ExprKind::Unary(UnOp::Not, condition) = cond.kind;
462-
then {
463-
return Some(vec![condition]);
464-
}
465-
}
466-
467-
// debug macros with two args: `debug_assert_{ne, eq}` (e.g., `assert_ne!(a, b)`)
468-
if_chain! {
469-
if let ExprKind::Block(matchblock,_) = matchexpr.kind;
470-
if let Some(matchblock_expr) = matchblock.expr;
471-
then {
472-
return ast_matchblock(matchblock_expr);
473-
}
474-
}
475-
}
476-
} else if let Some(matchblock_expr) = block.expr {
477-
// macros with two args: `assert_{ne, eq}` (e.g., `assert_ne!(a, b)`)
478-
return ast_matchblock(matchblock_expr);
479-
}
480-
}
481-
None
482-
}
483-
484-
/// A parsed `panic!` expansion
485-
pub struct PanicExpn<'tcx> {
486-
/// Span of `panic!(..)`
487-
pub call_site: Span,
488-
/// Inner `format_args!` expansion
489-
pub format_args: FormatArgsExpn<'tcx>,
490-
}
491-
492-
impl PanicExpn<'tcx> {
493-
/// Parses an expanded `panic!` invocation
494-
pub fn parse(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<Self> {
495-
if_chain! {
496-
if let ExprKind::Call(_, [format_args]) = expr.kind;
497-
let expn_data = expr.span.ctxt().outer_expn_data();
498-
if let Some(format_args) = FormatArgsExpn::parse(cx, format_args);
499-
then {
500-
Some(PanicExpn {
501-
call_site: expn_data.call_site,
502-
format_args,
503-
})
504-
} else {
505-
None
506-
}
507-
}
508-
}
509-
}
510-
511429
/// A parsed `Vec` initialization expression
512430
#[derive(Clone, Copy)]
513431
pub enum VecInitKind {

clippy_utils/src/lib.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,32 +1667,6 @@ pub fn match_libc_symbol(cx: &LateContext<'_>, did: DefId, name: &str) -> bool {
16671667
path.first().map_or(false, |s| s.as_str() == "libc") && path.last().map_or(false, |s| s.as_str() == name)
16681668
}
16691669

1670-
pub fn match_panic_call(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
1671-
if let ExprKind::Call(func, [arg]) = expr.kind {
1672-
expr_path_res(cx, func)
1673-
.opt_def_id()
1674-
.map_or(false, |id| match_panic_def_id(cx, id))
1675-
.then(|| arg)
1676-
} else {
1677-
None
1678-
}
1679-
}
1680-
1681-
pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool {
1682-
match_any_def_paths(
1683-
cx,
1684-
did,
1685-
&[
1686-
&paths::BEGIN_PANIC,
1687-
&paths::PANIC_ANY,
1688-
&paths::PANICKING_PANIC,
1689-
&paths::PANICKING_PANIC_FMT,
1690-
&paths::PANICKING_PANIC_STR,
1691-
],
1692-
)
1693-
.is_some()
1694-
}
1695-
16961670
/// Returns the list of condition expressions and the list of blocks in a
16971671
/// sequence of `if/else`.
16981672
/// E.g., this returns `([a, b], [c, d, e])` for the expression

clippy_utils/src/paths.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub const ASSERT_MACRO: [&str; 4] = ["core", "macros", "builtin", "assert"];
2525
pub const ASSERT_NE_MACRO: [&str; 3] = ["core", "macros", "assert_ne"];
2626
pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
2727
pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
28-
pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"];
2928
/// Preferably use the diagnostic item `sym::Borrow` where possible
3029
pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"];
3130
pub const BORROW_MUT_TRAIT: [&str; 3] = ["core", "borrow", "BorrowMut"];
@@ -110,10 +109,6 @@ pub const OPTION_SOME: [&str; 4] = ["core", "option", "Option", "Some"];
110109
pub const ORD: [&str; 3] = ["core", "cmp", "Ord"];
111110
pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"];
112111
pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"];
113-
pub(super) const PANICKING_PANIC: [&str; 3] = ["core", "panicking", "panic"];
114-
pub(super) const PANICKING_PANIC_FMT: [&str; 3] = ["core", "panicking", "panic_fmt"];
115-
pub(super) const PANICKING_PANIC_STR: [&str; 3] = ["core", "panicking", "panic_str"];
116-
pub(super) const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"];
117112
pub const PARKING_LOT_RAWMUTEX: [&str; 3] = ["parking_lot", "raw_mutex", "RawMutex"];
118113
pub const PARKING_LOT_RAWRWLOCK: [&str; 3] = ["parking_lot", "raw_rwlock", "RawRwLock"];
119114
pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"];

0 commit comments

Comments
 (0)