@@ -57,7 +57,17 @@ pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable,
5757
5858/// `Ok` represents successfully retrieving the string literal at the correct
5959/// 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+ }
6171
6272/// - `Ok` is returned when the conversion to a string literal is unsuccessful,
6373/// but another type of expression is obtained instead.
@@ -90,7 +100,12 @@ pub(crate) fn expr_to_spanned_string<'a>(
90100 ExpandResult :: Ready ( Err ( match expr. kind {
91101 ast:: ExprKind :: Lit ( token_lit) => match ast:: LitKind :: from_token_lit ( token_lit) {
92102 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+ } ) ) ;
94109 }
95110 Ok ( ast:: LitKind :: ByteStr ( ..) ) => {
96111 let mut err = cx. dcx ( ) . struct_span_err ( expr. span , err_msg) ;
@@ -128,7 +143,7 @@ pub(crate) fn expr_to_string(
128143 Ok ( ( err, _) ) => err. emit ( ) ,
129144 Err ( guar) => guar,
130145 } )
131- . map ( |( symbol, style, _ ) | ( symbol, style) )
146+ . map ( |ExprToSpannedString { symbol, style, .. } | ( symbol, style) )
132147 } )
133148}
134149
@@ -183,7 +198,7 @@ pub(crate) fn get_single_str_spanned_from_tts(
183198 Ok ( ( err, _) ) => err. emit ( ) ,
184199 Err ( guar) => guar,
185200 } )
186- . map ( |( symbol, _style , span ) | ( symbol, span) )
201+ . map ( |ExprToSpannedString { symbol, span , .. } | ( symbol, span) )
187202 } )
188203}
189204
0 commit comments