@@ -5,7 +5,7 @@ use crate::symbol::{sym, Symbol};
55use crate :: parse:: unescape;
66use crate :: parse:: unescape_error_reporting:: { emit_unescape_error, push_escaped_char} ;
77
8- use errors:: { FatalError , Diagnostic , DiagnosticBuilder } ;
8+ use errors:: { Applicability , FatalError , Diagnostic , DiagnosticBuilder } ;
99use syntax_pos:: { BytePos , Pos , Span , NO_EXPANSION } ;
1010use core:: unicode:: property:: Pattern_White_Space ;
1111
@@ -1172,12 +1172,6 @@ impl<'a> StringReader<'a> {
11721172 if self . is_eof ( ) {
11731173 self . fail_unterminated_raw_string ( start_bpos, hash_count) ;
11741174 }
1175- // if self.ch_is('"') {
1176- // content_end_bpos = self.pos;
1177- // for _ in 0..hash_count {
1178- // self.bump();
1179- // if !self.ch_is('#') {
1180- // continue 'outer;
11811175 let c = self . ch . unwrap ( ) ;
11821176 match c {
11831177 '"' => {
@@ -1206,6 +1200,30 @@ impl<'a> StringReader<'a> {
12061200 }
12071201
12081202 self . bump ( ) ;
1203+ if self . ch_is ( '#' ) {
1204+ let lo = self . pos ;
1205+ while self . ch_is ( '#' ) {
1206+ self . bump ( ) ;
1207+ }
1208+
1209+ let sp = self . mk_sp ( start_bpos, self . pos ) ;
1210+ let sp_beg = self . mk_sp ( BytePos ( start_bpos. 0 + 1 ) , BytePos ( start_bpos. 0 + 1 + hash_count as u32 ) ) ;
1211+ let sp_end = self . mk_sp ( BytePos ( lo. 0 - hash_count as u32 ) , self . pos ) ;
1212+
1213+ let mut err = self . sess . span_diagnostic . struct_span_err ( sp, "too many `#` when terminating raw string" ) ;
1214+ err. span_label ( sp_beg, format ! ( "The raw string has {} leading `#`..." , hash_count) ) ;
1215+ err. span_label ( sp_end, format ! ( "...but is closed with {}." , self . pos. 0 - lo. 0 + hash_count as u32 ) ) ;
1216+ err. span_suggestion_hidden (
1217+ self . mk_sp ( lo, self . pos ) ,
1218+ "remove the unneeded `#`" ,
1219+ String :: new ( ) ,
1220+ Applicability :: MachineApplicable ,
1221+ ) ;
1222+
1223+ err. emit ( ) ;
1224+ valid = false ;
1225+ }
1226+
12091227 let symbol = if valid {
12101228 self . name_from_to ( content_start_bpos, content_end_bpos)
12111229 } else {
0 commit comments