diff options
| author | bors <bors@rust-lang.org> | 2021-11-09 05:33:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-11-09 05:33:16 +0000 |
| commit | 60952bc3da442cf2ea11dcc9c80a461a659bbcd7 (patch) | |
| tree | 5c0793aef63ff65a56795a5852e448a64e054137 /src | |
| parent | c57704f3eb4319cc93513c232e9c434a73af46d2 (diff) | |
| parent | 8e21f3a4d7a8a5a90ee21f00aed101340221a8b6 (diff) | |
| download | rust-60952bc3da442cf2ea11dcc9c80a461a659bbcd7.tar.gz rust-60952bc3da442cf2ea11dcc9c80a461a659bbcd7.zip | |
Auto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-se
Don't destructure args tuple in format_args! This allows Clippy to parse the HIR more simply since `arg0` is changed to `_args.0`. (cc rust-lang/rust-clippy#7843). From rustc's perspective, I think this is something between a lateral move and a tiny improvement since there are fewer bindings. r? `@m-ou-se`
Diffstat (limited to 'src')
6 files changed, 10 insertions, 16 deletions
diff --git a/src/test/pretty/dollar-crate.pp b/src/test/pretty/dollar-crate.pp index f4be3c1c63a..84eda08d203 100644 --- a/src/test/pretty/dollar-crate.pp +++ b/src/test/pretty/dollar-crate.pp @@ -12,7 +12,7 @@ fn main() { { ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &match () { - () => [], + _args => [], })); }; } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 199aee05622..529daab9038 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -45,7 +45,7 @@ pub fn bar() ({ as ()) { - () + _args => ([] as diff --git a/src/test/ui/attributes/key-value-expansion.stderr b/src/test/ui/attributes/key-value-expansion.stderr index ef59381f5f2..e59216fe902 100644 --- a/src/test/ui/attributes/key-value-expansion.stderr +++ b/src/test/ui/attributes/key-value-expansion.stderr @@ -19,8 +19,8 @@ error: unexpected token: `{ let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""], &match (&"u8",) { - (arg0,) => - [::core::fmt::ArgumentV1::new(arg0, + _args => + [::core::fmt::ArgumentV1::new(_args.0, ::core::fmt::Display::fmt)], })); res diff --git a/src/test/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr b/src/test/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr index 36d6450c9a2..ee394d64a1d 100644 --- a/src/test/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr +++ b/src/test/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr @@ -9,7 +9,7 @@ LL | let c1 : () = c; | expected due to this | = note: expected unit type `()` - found closure `[mod1::f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#25t, extern "rust-call" fn(()), _#26t]]` + found closure `[mod1::f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#22t, extern "rust-call" fn(()), _#23t]]` help: use parentheses to call this closure | LL | let c1 : () = c(); diff --git a/src/test/ui/closures/print/closure-print-generic-verbose-2.stderr b/src/test/ui/closures/print/closure-print-generic-verbose-2.stderr index 91926f233d3..11b9fa7e40c 100644 --- a/src/test/ui/closures/print/closure-print-generic-verbose-2.stderr +++ b/src/test/ui/closures/print/closure-print-generic-verbose-2.stderr @@ -9,7 +9,7 @@ LL | let c1 : () = c; | expected due to this | = note: expected unit type `()` - found closure `[f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#25t, extern "rust-call" fn(()), _#26t]]` + found closure `[f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#22t, extern "rust-call" fn(()), _#23t]]` help: use parentheses to call this closure | LL | let c1 : () = c(); diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs index b3a9a1de2ec..733cc97c845 100644 --- a/src/tools/clippy/clippy_utils/src/higher.rs +++ b/src/tools/clippy/clippy_utils/src/higher.rs @@ -3,12 +3,12 @@ #![deny(clippy::missing_docs_in_private_items)] use crate::ty::is_type_diagnostic_item; -use crate::{is_expn_of, last_path_segment, match_def_path, path_to_local_id, paths}; +use crate::{is_expn_of, last_path_segment, match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{self, LitKind}; use rustc_hir as hir; use rustc_hir::{ - Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, PatKind, QPath, StmtKind, UnOp, + Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath, StmtKind, UnOp, }; use rustc_lint::LateContext; use rustc_span::{sym, symbol, ExpnKind, Span, Symbol}; @@ -513,8 +513,6 @@ pub struct FormatArgsExpn<'tcx> { pub format_string_parts: &'tcx [Expr<'tcx>], /// Symbols corresponding to [`Self::format_string_parts`] pub format_string_symbols: Vec<Symbol>, - /// Match arm patterns, the `arg0`, etc. from the next field `args` - pub arg_names: &'tcx [Pat<'tcx>], /// Expressions like `ArgumentV1::new(arg0, Debug::fmt)` pub args: &'tcx [Expr<'tcx>], /// The final argument passed to `Arguments::new_v1_formatted`, if applicable @@ -559,7 +557,6 @@ impl FormatArgsExpn<'tcx> { _ => None, }) .collect(); - if let PatKind::Tuple(arg_names, None) = arm.pat.kind; if let ExprKind::Array(args) = arm.body.kind; then { Some(FormatArgsExpn { @@ -567,7 +564,6 @@ impl FormatArgsExpn<'tcx> { value_args, format_string_parts, format_string_symbols, - arg_names, args, fmt_expr, }) @@ -594,10 +590,8 @@ impl FormatArgsExpn<'tcx> { if let Ok(i) = usize::try_from(position); let arg = &self.args[i]; if let ExprKind::Call(_, [arg_name, _]) = arg.kind; - if let Some(j) = self - .arg_names - .iter() - .position(|pat| path_to_local_id(arg_name, pat.hir_id)); + if let ExprKind::Field(_, j) = arg_name.kind; + if let Ok(j) = j.name.as_str().parse::<usize>(); then { Some(FormatArgsArg { value: self.value_args[j], arg, fmt: Some(fmt) }) } else { |
