@@ -20,7 +20,6 @@ pub use Flag::*;
2020pub use Piece :: * ;
2121pub use Position :: * ;
2222
23- use rustc_lexer:: unescape;
2423use std:: iter;
2524use std:: str;
2625use std:: string;
@@ -314,11 +313,12 @@ impl<'a> Parser<'a> {
314313 append_newline : bool ,
315314 mode : ParseMode ,
316315 ) -> Parser < ' a > {
317- let input_string_kind = find_width_map_from_snippet ( s , snippet, style) ;
316+ let input_string_kind = find_width_map_from_snippet ( snippet, style) ;
318317 let ( width_map, is_literal) = match input_string_kind {
319318 InputStringKind :: Literal { width_mappings } => ( width_mappings, true ) ,
320319 InputStringKind :: NotALiteral => ( Vec :: new ( ) , false ) ,
321320 } ;
321+
322322 Parser {
323323 mode,
324324 input : s,
@@ -856,7 +856,6 @@ impl<'a> Parser<'a> {
856856/// written code (code snippet) and the `InternedString` that gets processed in the `Parser`
857857/// in order to properly synthesise the intra-string `Span`s for error diagnostics.
858858fn find_width_map_from_snippet (
859- input : & str ,
860859 snippet : Option < string:: String > ,
861860 str_style : Option < usize > ,
862861) -> InputStringKind {
@@ -869,27 +868,8 @@ fn find_width_map_from_snippet(
869868 return InputStringKind :: Literal { width_mappings : Vec :: new ( ) } ;
870869 }
871870
872- // Strip quotes.
873871 let snippet = & snippet[ 1 ..snippet. len ( ) - 1 ] ;
874872
875- // Macros like `println` add a newline at the end. That technically doens't make them "literals" anymore, but it's fine
876- // since we will never need to point our spans there, so we lie about it here by ignoring it.
877- // Since there might actually be newlines in the source code, we need to normalize away all trailing newlines.
878- // If we only trimmed it off the input, `format!("\n")` would cause a mismatch as here we they actually match up.
879- // Alternatively, we could just count the trailing newlines and only trim one from the input if they don't match up.
880- let input_no_nl = input. trim_end_matches ( '\n' ) ;
881- let Ok ( unescaped) = unescape_string ( snippet) else {
882- return InputStringKind :: NotALiteral ;
883- } ;
884-
885- let unescaped_no_nl = unescaped. trim_end_matches ( '\n' ) ;
886-
887- if unescaped_no_nl != input_no_nl {
888- // The source string that we're pointing at isn't our input, so spans pointing at it will be incorrect.
889- // This can for example happen with proc macros that respan generated literals.
890- return InputStringKind :: NotALiteral ;
891- }
892-
893873 let mut s = snippet. char_indices ( ) ;
894874 let mut width_mappings = vec ! [ ] ;
895875 while let Some ( ( pos, c) ) = s. next ( ) {
@@ -972,19 +952,6 @@ fn find_width_map_from_snippet(
972952 InputStringKind :: Literal { width_mappings }
973953}
974954
975- fn unescape_string ( string : & str ) -> Result < string:: String , unescape:: EscapeError > {
976- let mut buf = string:: String :: new ( ) ;
977- let mut error = Ok ( ( ) ) ;
978- unescape:: unescape_literal ( string, unescape:: Mode :: Str , & mut |_, unescaped_char| {
979- match unescaped_char {
980- Ok ( c) => buf. push ( c) ,
981- Err ( err) => error = Err ( err) ,
982- }
983- } ) ;
984-
985- error. map ( |_| buf)
986- }
987-
988955// Assert a reasonable size for `Piece`
989956#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
990957rustc_data_structures:: static_assert_size!( Piece <' _>, 16 ) ;
0 commit comments