@@ -5,7 +5,7 @@ use crate::symbol::{sym, Symbol};
5
5
use crate :: parse:: unescape;
6
6
use crate :: parse:: unescape_error_reporting:: { emit_unescape_error, push_escaped_char} ;
7
7
8
- use errors:: { FatalError , Diagnostic , DiagnosticBuilder } ;
8
+ use errors:: { Applicability , FatalError , Diagnostic , DiagnosticBuilder } ;
9
9
use syntax_pos:: { BytePos , Pos , Span , NO_EXPANSION } ;
10
10
use core:: unicode:: property:: Pattern_White_Space ;
11
11
@@ -1172,12 +1172,6 @@ impl<'a> StringReader<'a> {
1172
1172
if self . is_eof ( ) {
1173
1173
self . fail_unterminated_raw_string ( start_bpos, hash_count) ;
1174
1174
}
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;
1181
1175
let c = self . ch . unwrap ( ) ;
1182
1176
match c {
1183
1177
'"' => {
@@ -1206,6 +1200,30 @@ impl<'a> StringReader<'a> {
1206
1200
}
1207
1201
1208
1202
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
+
1209
1227
let symbol = if valid {
1210
1228
self . name_from_to ( content_start_bpos, content_end_bpos)
1211
1229
} else {
0 commit comments