Skip to content

Commit f2f5ca6

Browse files
committed
extract the formaing string and the values
1 parent 88cabf2 commit f2f5ca6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

clippy_lints/src/bool_assert_comparison.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison {
112112
let arg_span = match fmt_args {
113113
[] => None,
114114
[a] => Some(format!(
115-
".., {}",
115+
"{}",
116116
Sugg::hir_with_applicability(cx, a, "..", &mut applicability)
117117
)),
118118
_ => {
119119
let mut args = format!(
120-
".., {}",
120+
"{}",
121121
Sugg::hir_with_applicability(cx, fmt_args[0], "..", &mut applicability)
122122
);
123123
for el in &fmt_args[1..] {

clippy_utils/src/higher.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,10 @@ pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option<Vec<&'tcx
448448
if args_assert_failed.len() >= 4;
449449
if let ExprKind::Call(_, args) = args_assert_failed[3].kind;
450450
if !args.is_empty();
451-
if let ExprKind::Match(expr_match, _, _ ) = args[0].kind;
452-
if let ExprKind::Match(tup_match, _, _) = expr_match.kind;
453-
if let ExprKind::Tup(tup_args_list) = tup_match.kind;
451+
if let Some (mut format_arg_expn) = FormatArgsExpn::parse(&args[0]);
454452
then {
455-
for arg in tup_args_list {
456-
vec_arg.push(arg);
457-
}
453+
vec_arg.push(format_arg_expn.format_string);
454+
vec_arg.append(&mut format_arg_expn.value_args);
458455
}
459456
}
460457
return Some(vec_arg);
@@ -526,6 +523,8 @@ impl FormatExpn<'tcx> {
526523

527524
/// A parsed `format_args!` expansion
528525
pub struct FormatArgsExpn<'tcx> {
526+
/// The fist argument, the fromat string, as an expr
527+
pub format_string: &'tcx Expr<'tcx>,
529528
/// Span of the first argument, the format string
530529
pub format_string_span: Span,
531530
/// Values passed after the format string
@@ -582,6 +581,7 @@ impl FormatArgsExpn<'tcx> {
582581
if let ExprKind::Array(args) = arm.body.kind;
583582
then {
584583
Some(FormatArgsExpn {
584+
format_string:strs_ref,
585585
format_string_span: strs_ref.span,
586586
value_args,
587587
format_string_parts,

0 commit comments

Comments
 (0)