@@ -57,7 +57,17 @@ pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable,
57
57
58
58
/// `Ok` represents successfully retrieving the string literal at the correct
59
59
/// position, e.g., `println("abc")`.
60
- type ExprToSpannedStringResult < ' a > = Result < ( Symbol , ast:: StrStyle , Span ) , UnexpectedExprKind < ' a > > ;
60
+ pub ( crate ) type ExprToSpannedStringResult < ' a > = Result < ExprToSpannedString , UnexpectedExprKind < ' a > > ;
61
+
62
+ pub ( crate ) struct ExprToSpannedString {
63
+ pub symbol : Symbol ,
64
+ pub style : ast:: StrStyle ,
65
+ pub span : Span ,
66
+ /// The raw string literal, with no escaping or processing.
67
+ ///
68
+ /// Generally only useful for lints that care about the raw bytes the user wrote.
69
+ pub uncooked_symbol : ( ast:: token:: LitKind , Symbol ) ,
70
+ }
61
71
62
72
/// - `Ok` is returned when the conversion to a string literal is unsuccessful,
63
73
/// but another type of expression is obtained instead.
@@ -90,7 +100,12 @@ pub(crate) fn expr_to_spanned_string<'a>(
90
100
ExpandResult :: Ready ( Err ( match expr. kind {
91
101
ast:: ExprKind :: Lit ( token_lit) => match ast:: LitKind :: from_token_lit ( token_lit) {
92
102
Ok ( ast:: LitKind :: Str ( s, style) ) => {
93
- return ExpandResult :: Ready ( Ok ( ( s, style, expr. span ) ) ) ;
103
+ return ExpandResult :: Ready ( Ok ( ExprToSpannedString {
104
+ symbol : s,
105
+ style,
106
+ span : expr. span ,
107
+ uncooked_symbol : ( token_lit. kind , token_lit. symbol ) ,
108
+ } ) ) ;
94
109
}
95
110
Ok ( ast:: LitKind :: ByteStr ( ..) ) => {
96
111
let mut err = cx. dcx ( ) . struct_span_err ( expr. span , err_msg) ;
@@ -128,7 +143,7 @@ pub(crate) fn expr_to_string(
128
143
Ok ( ( err, _) ) => err. emit ( ) ,
129
144
Err ( guar) => guar,
130
145
} )
131
- . map ( |( symbol, style, _ ) | ( symbol, style) )
146
+ . map ( |ExprToSpannedString { symbol, style, .. } | ( symbol, style) )
132
147
} )
133
148
}
134
149
@@ -183,7 +198,7 @@ pub(crate) fn get_single_str_spanned_from_tts(
183
198
Ok ( ( err, _) ) => err. emit ( ) ,
184
199
Err ( guar) => guar,
185
200
} )
186
- . map ( |( symbol, _style , span ) | ( symbol, span) )
201
+ . map ( |ExprToSpannedString { symbol, span , .. } | ( symbol, span) )
187
202
} )
188
203
}
189
204
0 commit comments