|
2 | 2 |
|
3 | 3 | #![deny(clippy::missing_docs_in_private_items)]
|
4 | 4 |
|
5 |
| -use crate::macros::FormatArgsExpn; |
6 | 5 | use crate::ty::is_type_diagnostic_item;
|
7 | 6 | use crate::{is_expn_of, match_def_path, paths};
|
8 | 7 | use if_chain::if_chain;
|
9 | 8 | use rustc_ast::ast::{self, LitKind};
|
10 | 9 | 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}; |
14 | 11 | use rustc_lint::LateContext;
|
15 | 12 | use rustc_span::{sym, symbol, Span};
|
16 | 13 |
|
@@ -429,85 +426,6 @@ pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
|
429 | 426 | }
|
430 | 427 | }
|
431 | 428 |
|
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 |
| - |
511 | 429 | /// A parsed `Vec` initialization expression
|
512 | 430 | #[derive(Clone, Copy)]
|
513 | 431 | pub enum VecInitKind {
|
|
0 commit comments