Skip to content

Commit b606d16

Browse files
committed
Auto merge of rust-lang#90891 - nbdd0121:format, r=Mark-Simulacrum
Create `core::fmt::ArgumentV1` with generics instead of fn pointer Split from (and prerequisite of) rust-lang#90488, as this seems to have perf implication. `@rustbot` label: +T-libs
2 parents bf66aed + bee482b commit b606d16

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

clippy_lints/src/index_refutable_slice.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::higher::IfLet;
44
use clippy_utils::ty::is_copy;
55
use clippy_utils::{is_expn_of, is_lint_allowed, meets_msrv, msrvs, path_to_local};
66
use if_chain::if_chain;
7-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
7+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
88
use rustc_errors::Applicability;
99
use rustc_hir as hir;
1010
use rustc_hir::intravisit::{self, Visitor};
@@ -92,9 +92,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
9292
extract_msrv_attr!(LateContext);
9393
}
9494

95-
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxHashMap<hir::HirId, SliceLintInformation> {
95+
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> {
9696
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
97-
let mut slices: FxHashMap<hir::HirId, SliceLintInformation> = FxHashMap::default();
97+
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
9898
pat.walk_always(|pat| {
9999
if let hir::PatKind::Binding(binding, value_hir_id, ident, sub_pat) = pat.kind {
100100
// We'll just ignore mut and ref mut for simplicity sake right now
@@ -208,10 +208,10 @@ impl SliceLintInformation {
208208

209209
fn filter_lintable_slices<'a, 'tcx>(
210210
cx: &'a LateContext<'tcx>,
211-
slice_lint_info: FxHashMap<hir::HirId, SliceLintInformation>,
211+
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
212212
max_suggested_slice: u64,
213213
scope: &'tcx hir::Expr<'tcx>,
214-
) -> FxHashMap<hir::HirId, SliceLintInformation> {
214+
) -> FxIndexMap<hir::HirId, SliceLintInformation> {
215215
let mut visitor = SliceIndexLintingVisitor {
216216
cx,
217217
slice_lint_info,
@@ -225,7 +225,7 @@ fn filter_lintable_slices<'a, 'tcx>(
225225

226226
struct SliceIndexLintingVisitor<'a, 'tcx> {
227227
cx: &'a LateContext<'tcx>,
228-
slice_lint_info: FxHashMap<hir::HirId, SliceLintInformation>,
228+
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
229229
max_suggested_slice: u64,
230230
}
231231

clippy_utils/src/macros.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,13 @@ impl<'tcx> FormatArgsExpn<'tcx> {
339339
expr_visitor_no_bodies(|e| {
340340
// if we're still inside of the macro definition...
341341
if e.span.ctxt() == expr.span.ctxt() {
342-
// ArgumnetV1::new(<value>, <format_trait>::fmt)
342+
// ArgumnetV1::new_<format_trait>(<value>)
343343
if_chain! {
344-
if let ExprKind::Call(callee, [val, fmt_path]) = e.kind;
344+
if let ExprKind::Call(callee, [val]) = e.kind;
345345
if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind;
346-
if seg.ident.name == sym::new;
347346
if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind;
348347
if path.segments.last().unwrap().ident.name == sym::ArgumentV1;
349-
if let ExprKind::Path(QPath::Resolved(_, path)) = fmt_path.kind;
350-
if let [.., fmt_trait, _fmt] = path.segments;
348+
if seg.ident.name.as_str().starts_with("new_");
351349
then {
352350
let val_idx = if_chain! {
353351
if val.span.ctxt() == expr.span.ctxt();
@@ -361,7 +359,19 @@ impl<'tcx> FormatArgsExpn<'tcx> {
361359
formatters.len()
362360
}
363361
};
364-
formatters.push((val_idx, fmt_trait.ident.name));
362+
let fmt_trait = match seg.ident.name.as_str() {
363+
"new_display" => "Display",
364+
"new_debug" => "Debug",
365+
"new_lower_exp" => "LowerExp",
366+
"new_upper_exp" => "UpperExp",
367+
"new_octal" => "Octal",
368+
"new_pointer" => "Pointer",
369+
"new_binary" => "Binary",
370+
"new_lower_hex" => "LowerHex",
371+
"new_upper_hex" => "UpperHex",
372+
_ => unreachable!(),
373+
};
374+
formatters.push((val_idx, Symbol::intern(fmt_trait)));
365375
}
366376
}
367377
if let ExprKind::Struct(QPath::Resolved(_, path), ..) = e.kind {

0 commit comments

Comments
 (0)