Skip to content

Commit 9de1f4b

Browse files
committed
cleanup param expansion
1 parent 64928fd commit 9de1f4b

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

clippy_lints/src/format_args.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,10 @@ fn check_inline(cx: &LateContext<'_>, param: &FormatParam<'_>, inline_spans: &mu
182182
&& let Path { span, segments, .. } = path
183183
&& let [segment] = segments
184184
{
185-
// TODO: Note the inconsistency here, that we may want to address separately:
186-
// implicit, numbered, and starred `param.span` spans the whole relevant string:
187-
// the empty space between `{}`, or the entire value `1$`, `.2$`, or `.*`
188-
// but the named argument spans just the name itself, without the surrounding `.` and `$`.
189-
let replacement = if param.kind == Numbered || param.kind == Starred {
190-
match param.usage {
191-
FormatParamUsage::Argument => segment.ident.name.to_string(),
192-
FormatParamUsage::Width => format!("{}$", segment.ident.name),
193-
FormatParamUsage::Precision => format!(".{}$", segment.ident.name),
194-
}
195-
} else {
196-
segment.ident.name.to_string()
185+
let replacement = match param.usage {
186+
FormatParamUsage::Argument => segment.ident.name.to_string(),
187+
FormatParamUsage::Width => format!("{}$", segment.ident.name),
188+
FormatParamUsage::Precision => format!(".{}$", segment.ident.name),
197189
};
198190
inline_spans.push((param.span, replacement));
199191
let arg_span = expand_past_previous_comma(cx, *span);

clippy_utils/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,11 @@ impl<'tcx> Count<'tcx> {
643643
) -> Option<Self> {
644644
Some(match count {
645645
rpf::Count::CountIs(val) => Self::Is(val, span_from_inner(values.format_string_span, inner?)),
646-
rpf::Count::CountIsName(name, span) => Self::Param(FormatParam::new(
646+
rpf::Count::CountIsName(name, _) => Self::Param(FormatParam::new(
647647
usage,
648648
FormatParamKind::Named(Symbol::intern(name)),
649649
position?,
650-
span,
650+
inner?,
651651
values,
652652
)?),
653653
rpf::Count::CountIsParam(_) => Self::Param(FormatParam::new(

0 commit comments

Comments
 (0)