Skip to content

Commit 8669d38

Browse files
committed
extract the formaing string and the values
1 parent 5f30a07 commit 8669d38

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
@@ -446,13 +446,10 @@ pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option<Vec<&'tcx
446446
if args_assert_failed.len() >= 4;
447447
if let ExprKind::Call(_, args) = args_assert_failed[3].kind;
448448
if !args.is_empty();
449-
if let ExprKind::Match(expr_match, _, _ ) = args[0].kind;
450-
if let ExprKind::Match(tup_match, _, _) = expr_match.kind;
451-
if let ExprKind::Tup(tup_args_list) = tup_match.kind;
449+
if let Some (mut format_arg_expn) = FormatArgsExpn::parse(&args[0]);
452450
then {
453-
for arg in tup_args_list {
454-
vec_arg.push(arg);
455-
}
451+
vec_arg.push(format_arg_expn.format_string);
452+
vec_arg.append(&mut format_arg_expn.value_args);
456453
}
457454
}
458455
return Some(vec_arg);
@@ -524,6 +521,8 @@ impl FormatExpn<'tcx> {
524521

525522
/// A parsed `format_args!` expansion
526523
pub struct FormatArgsExpn<'tcx> {
524+
/// The fist argument, the fromat string, as an expr
525+
pub format_string: &'tcx Expr<'tcx>,
527526
/// Span of the first argument, the format string
528527
pub format_string_span: Span,
529528
/// Values passed after the format string
@@ -585,6 +584,7 @@ impl FormatArgsExpn<'tcx> {
585584
.collect();
586585
then {
587586
Some(FormatArgsExpn {
587+
format_string:strs_ref,
588588
format_string_span: strs_ref.span,
589589
value_args,
590590
format_string_parts,

0 commit comments

Comments
 (0)