@@ -172,6 +172,11 @@ impl<'a> StringReader<'a> {
172
172
self . span_diagnostic . span_err ( sp, m)
173
173
}
174
174
175
+ /// Suggest some help with a given span.
176
+ pub fn help_span ( & self , sp : Span , m : & str ) {
177
+ self . span_diagnostic . span_help ( sp, m)
178
+ }
179
+
175
180
/// Report a fatal error spanning [`from_pos`, `to_pos`).
176
181
fn fatal_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> ! {
177
182
self . fatal_span ( codemap:: mk_sp ( from_pos, to_pos) , m)
@@ -182,6 +187,11 @@ impl<'a> StringReader<'a> {
182
187
self . err_span ( codemap:: mk_sp ( from_pos, to_pos) , m)
183
188
}
184
189
190
+ /// Suggest some help spanning [`from_pos`, `to_pos`).
191
+ fn help_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) {
192
+ self . help_span ( codemap:: mk_sp ( from_pos, to_pos) , m)
193
+ }
194
+
185
195
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
186
196
/// escaped character to the error message
187
197
fn fatal_span_char ( & self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) -> ! {
@@ -742,6 +752,13 @@ impl<'a> StringReader<'a> {
742
752
valid
743
753
}
744
754
}
755
+ 'u' if !ascii_only => {
756
+ self . err_span_ ( escaped_pos, self . last_pos ,
757
+ "incomplete unicode escape sequence" ) ;
758
+ self . help_span_ ( escaped_pos, self . last_pos ,
759
+ "format of unicode escape sequences is `\\ u{…}`" ) ;
760
+ false
761
+ }
745
762
'\n' if delim == '"' => {
746
763
self . consume_whitespace ( ) ;
747
764
true
@@ -757,16 +774,13 @@ impl<'a> StringReader<'a> {
757
774
if ascii_only { "unknown byte escape" }
758
775
else { "unknown character escape" } ,
759
776
c) ;
760
- let sp = codemap:: mk_sp ( escaped_pos, last_pos) ;
761
777
if e == '\r' {
762
- self . span_diagnostic . span_help (
763
- sp,
778
+ self . help_span_ ( escaped_pos, last_pos,
764
779
"this is an isolated carriage return; consider checking \
765
780
your editor and version control settings")
766
781
}
767
782
if ( e == '{' || e == '}' ) && !ascii_only {
768
- self . span_diagnostic . span_help (
769
- sp,
783
+ self . help_span_ ( escaped_pos, last_pos,
770
784
"if used in a formatting string, \
771
785
curly braces are escaped with `{{` and `}}`")
772
786
}
0 commit comments