@@ -5,7 +5,7 @@ use hir_expand::name::Name;
5
5
use rustc_dependencies:: parse_format as parse;
6
6
use syntax:: {
7
7
ast:: { self , IsString } ,
8
- AstToken , SmolStr , TextRange ,
8
+ SmolStr , TextRange , TextSize ,
9
9
} ;
10
10
11
11
use crate :: hir:: ExprId ;
@@ -170,15 +170,18 @@ pub(crate) fn parse(
170
170
mut args : FormatArgumentsCollector ,
171
171
is_direct_literal : bool ,
172
172
mut synth : impl FnMut ( Name ) -> ExprId ,
173
+ mut record_usage : impl FnMut ( Name , Option < TextRange > ) ,
173
174
) -> FormatArgs {
174
- let text = s. text ( ) ;
175
+ let text = s. text_without_quotes ( ) ;
175
176
let str_style = match s. quote_offsets ( ) {
176
177
Some ( offsets) => {
177
178
let raw = u32:: from ( offsets. quotes . 0 . len ( ) ) - 1 ;
178
- ( raw != 0 ) . then_some ( raw as usize )
179
+ // subtract 1 for the `r` prefix
180
+ ( raw != 0 ) . then ( || raw as usize - 1 )
179
181
}
180
182
None => None ,
181
183
} ;
184
+
182
185
let mut parser =
183
186
parse:: Parser :: new ( text, str_style, fmt_snippet, false , parse:: ParseMode :: Format ) ;
184
187
@@ -199,6 +202,7 @@ pub(crate) fn parse(
199
202
let to_span = |inner_span : parse:: InnerSpan | {
200
203
is_source_literal. then ( || {
201
204
TextRange :: new ( inner_span. start . try_into ( ) . unwrap ( ) , inner_span. end . try_into ( ) . unwrap ( ) )
205
+ - TextSize :: from ( str_style. map ( |it| it + 1 ) . unwrap_or ( 0 ) as u32 + 1 )
202
206
} )
203
207
} ;
204
208
@@ -230,9 +234,10 @@ pub(crate) fn parse(
230
234
Err ( index)
231
235
}
232
236
}
233
- ArgRef :: Name ( name, _span ) => {
237
+ ArgRef :: Name ( name, span ) => {
234
238
let name = Name :: new_text_dont_use ( SmolStr :: new ( name) ) ;
235
239
if let Some ( ( index, _) ) = args. by_name ( & name) {
240
+ record_usage ( name, span) ;
236
241
// Name found in `args`, so we resolve it to its index.
237
242
if index < args. explicit_args ( ) . len ( ) {
238
243
// Mark it as used, if it was an explicit argument.
@@ -246,6 +251,7 @@ pub(crate) fn parse(
246
251
// disabled (see RFC #2795)
247
252
// FIXME: Diagnose
248
253
}
254
+ record_usage ( name. clone ( ) , span) ;
249
255
Ok ( args. add ( FormatArgument {
250
256
kind : FormatArgumentKind :: Captured ( name. clone ( ) ) ,
251
257
// FIXME: This is problematic, we might want to synthesize a dummy
0 commit comments