diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-11 07:51:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-11 07:51:51 +0200 |
| commit | 32e0fe129d495d3d4dacdcd066d9e339534a8338 (patch) | |
| tree | 011962c5fbf99b4171d373e4adb0df9ff8760b52 /compiler/rustc_builtin_macros/src/format.rs | |
| parent | bd7075c69e7472001cc31b9060849a6c7bc90d3e (diff) | |
| parent | c4c518d2d496774ecc7a368e826480d1928ed1ab (diff) | |
| download | rust-32e0fe129d495d3d4dacdcd066d9e339534a8338.tar.gz rust-32e0fe129d495d3d4dacdcd066d9e339534a8338.zip | |
Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors
Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
Diffstat (limited to 'compiler/rustc_builtin_macros/src/format.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/format.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index ff82f0f2da7..f99530cad18 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -180,8 +180,8 @@ fn make_format_args( Ok((mut err, suggested)) => { if !suggested { if let ExprKind::Block(block, None) = &efmt.kind - && block.stmts.len() == 1 - && let StmtKind::Expr(expr) = &block.stmts[0].kind + && let [stmt] = block.stmts.as_slice() + && let StmtKind::Expr(expr) = &stmt.kind && let ExprKind::Path(None, path) = &expr.kind && path.is_potential_trivial_const_arg() { @@ -196,8 +196,8 @@ fn make_format_args( } else { let sugg_fmt = match args.explicit_args().len() { 0 => "{}".to_string(), - _ => { - format!("{}{{}}", "{} ".repeat(args.explicit_args().len())) + count => { + format!("{}{{}}", "{} ".repeat(count)) } }; err.span_suggestion( |
