Auto merge of #90891 - nbdd0121:format, r=Mark-Simulacrum
Create `core::fmt::ArgumentV1` with generics instead of fn pointer Split from (and prerequisite of) #90488, as this seems to have perf implication. `@rustbot` label: +T-libs
This commit is contained in:
commit
b606d160c8
@ -4,7 +4,7 @@ use clippy_utils::higher::IfLet;
|
||||
use clippy_utils::ty::is_copy;
|
||||
use clippy_utils::{is_expn_of, is_lint_allowed, meets_msrv, msrvs, path_to_local};
|
||||
use if_chain::if_chain;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
@ -92,9 +92,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
|
||||
extract_msrv_attr!(LateContext);
|
||||
}
|
||||
|
||||
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxHashMap<hir::HirId, SliceLintInformation> {
|
||||
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> {
|
||||
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
|
||||
let mut slices: FxHashMap<hir::HirId, SliceLintInformation> = FxHashMap::default();
|
||||
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
|
||||
pat.walk_always(|pat| {
|
||||
if let hir::PatKind::Binding(binding, value_hir_id, ident, sub_pat) = pat.kind {
|
||||
// We'll just ignore mut and ref mut for simplicity sake right now
|
||||
@ -208,10 +208,10 @@ impl SliceLintInformation {
|
||||
|
||||
fn filter_lintable_slices<'a, 'tcx>(
|
||||
cx: &'a LateContext<'tcx>,
|
||||
slice_lint_info: FxHashMap<hir::HirId, SliceLintInformation>,
|
||||
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
|
||||
max_suggested_slice: u64,
|
||||
scope: &'tcx hir::Expr<'tcx>,
|
||||
) -> FxHashMap<hir::HirId, SliceLintInformation> {
|
||||
) -> FxIndexMap<hir::HirId, SliceLintInformation> {
|
||||
let mut visitor = SliceIndexLintingVisitor {
|
||||
cx,
|
||||
slice_lint_info,
|
||||
@ -225,7 +225,7 @@ fn filter_lintable_slices<'a, 'tcx>(
|
||||
|
||||
struct SliceIndexLintingVisitor<'a, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
slice_lint_info: FxHashMap<hir::HirId, SliceLintInformation>,
|
||||
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
|
||||
max_suggested_slice: u64,
|
||||
}
|
||||
|
||||
|
@ -339,15 +339,13 @@ impl<'tcx> FormatArgsExpn<'tcx> {
|
||||
expr_visitor_no_bodies(|e| {
|
||||
// if we're still inside of the macro definition...
|
||||
if e.span.ctxt() == expr.span.ctxt() {
|
||||
// ArgumnetV1::new(<value>, <format_trait>::fmt)
|
||||
// ArgumnetV1::new_<format_trait>(<value>)
|
||||
if_chain! {
|
||||
if let ExprKind::Call(callee, [val, fmt_path]) = e.kind;
|
||||
if let ExprKind::Call(callee, [val]) = e.kind;
|
||||
if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind;
|
||||
if seg.ident.name == sym::new;
|
||||
if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind;
|
||||
if path.segments.last().unwrap().ident.name == sym::ArgumentV1;
|
||||
if let ExprKind::Path(QPath::Resolved(_, path)) = fmt_path.kind;
|
||||
if let [.., fmt_trait, _fmt] = path.segments;
|
||||
if seg.ident.name.as_str().starts_with("new_");
|
||||
then {
|
||||
let val_idx = if_chain! {
|
||||
if val.span.ctxt() == expr.span.ctxt();
|
||||
@ -361,7 +359,19 @@ impl<'tcx> FormatArgsExpn<'tcx> {
|
||||
formatters.len()
|
||||
}
|
||||
};
|
||||
formatters.push((val_idx, fmt_trait.ident.name));
|
||||
let fmt_trait = match seg.ident.name.as_str() {
|
||||
"new_display" => "Display",
|
||||
"new_debug" => "Debug",
|
||||
"new_lower_exp" => "LowerExp",
|
||||
"new_upper_exp" => "UpperExp",
|
||||
"new_octal" => "Octal",
|
||||
"new_pointer" => "Pointer",
|
||||
"new_binary" => "Binary",
|
||||
"new_lower_hex" => "LowerHex",
|
||||
"new_upper_hex" => "UpperHex",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
formatters.push((val_idx, Symbol::intern(fmt_trait)));
|
||||
}
|
||||
}
|
||||
if let ExprKind::Struct(QPath::Resolved(_, path), ..) = e.kind {
|
||||
|
Loading…
x
Reference in New Issue
Block a user