@@ -64,20 +64,9 @@ impl PositionalNamedArg {
64
64
/// Determines what span to replace with the name of the named argument
65
65
fn get_span_to_replace ( & self , cx : & Context < ' _ , ' _ > ) -> Option < Span > {
66
66
if let Some ( inner_span) = & self . inner_span_to_replace {
67
- return match self . ty {
68
- PositionalNamedArgType :: Arg | PositionalNamedArgType :: Width => Some ( Span :: new (
69
- cx. fmtsp . lo ( ) + BytePos ( inner_span. start . try_into ( ) . unwrap ( ) ) ,
70
- cx. fmtsp . lo ( ) + BytePos ( inner_span. end . try_into ( ) . unwrap ( ) ) ,
71
- self . positional_named_arg_span . ctxt ( ) ,
72
- self . positional_named_arg_span . parent ( ) ,
73
- ) ) ,
74
- PositionalNamedArgType :: Precision => Some ( Span :: new (
75
- cx. fmtsp . lo ( ) + BytePos ( inner_span. start . try_into ( ) . unwrap ( ) ) + BytePos ( 1 ) ,
76
- cx. fmtsp . lo ( ) + BytePos ( inner_span. end . try_into ( ) . unwrap ( ) ) ,
77
- self . positional_named_arg_span . ctxt ( ) ,
78
- self . positional_named_arg_span . parent ( ) ,
79
- ) ) ,
80
- } ;
67
+ return Some (
68
+ cx. fmtsp . from_inner ( InnerSpan { start : inner_span. start , end : inner_span. end } ) ,
69
+ ) ;
81
70
} else if self . ty == PositionalNamedArgType :: Arg {
82
71
// In the case of a named argument whose position is implicit, there will not be a span
83
72
// to replace. Instead, we insert the name after the `{`, which is the first character
@@ -111,7 +100,7 @@ impl PositionalNamedArgsLint {
111
100
format_argument_index : usize ,
112
101
ty : PositionalNamedArgType ,
113
102
cur_piece : usize ,
114
- inner_span : Option < rustc_parse_format:: InnerSpan > ,
103
+ mut inner_span_to_replace : Option < rustc_parse_format:: InnerSpan > ,
115
104
names : & FxHashMap < Symbol , ( usize , Span ) > ,
116
105
) {
117
106
let named_arg = names
@@ -120,10 +109,19 @@ impl PositionalNamedArgsLint {
120
109
. map ( |found| found. clone ( ) ) ;
121
110
122
111
if let Some ( named_arg) = named_arg {
112
+ // In FormatSpec, `precision_span` starts at the leading `.`, which we want to keep in
113
+ // the lint suggestion, so increment `start` by 1 when `PositionalArgumentType` is
114
+ // `Precision`.
115
+ if ty == PositionalNamedArgType :: Precision {
116
+ inner_span_to_replace = inner_span_to_replace. map ( |mut is| {
117
+ is. start += 1 ;
118
+ is
119
+ } ) ;
120
+ }
123
121
self . positional_named_args . push ( PositionalNamedArg {
124
122
ty,
125
123
cur_piece,
126
- inner_span_to_replace : inner_span ,
124
+ inner_span_to_replace,
127
125
replacement : named_arg. 0 . clone ( ) ,
128
126
positional_named_arg_span : named_arg. 1 . 1 . clone ( ) ,
129
127
} ) ;
0 commit comments