diff options
| author | bors <bors@rust-lang.org> | 2019-01-01 09:10:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-01 09:10:23 +0000 |
| commit | 7a2779a4624db2b9ef1f114a9a9acf9ca5c29d0c (patch) | |
| tree | d77fec6ca827b9ac39c572ec2d546c5938aa5564 /src/libsyntax | |
| parent | 0432798fdb4437119b3704cd891b412ba30e5c83 (diff) | |
| parent | 30961c958da9181a623ea215ed1fd62006f73a85 (diff) | |
| download | rust-7a2779a4624db2b9ef1f114a9a9acf9ca5c29d0c.tar.gz rust-7a2779a4624db2b9ef1f114a9a9acf9ca5c29d0c.zip | |
Auto merge of #57210 - estebank:str-err, r=zackmdavis
Tweak unicode escape diagnostics
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index d13de002968..ecb34e43c59 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -945,12 +945,36 @@ impl<'a> StringReader<'a> { self.scan_unicode_escape(delim) && !ascii_only } else { let span = self.mk_sp(start, self.pos); - self.sess.span_diagnostic - .struct_span_err(span, "incorrect unicode escape sequence") - .span_help(span, - "format of unicode escape sequences is \ - `\\u{…}`") - .emit(); + let mut suggestion = "\\u{".to_owned(); + let mut err = self.sess.span_diagnostic.struct_span_err( + span, + "incorrect unicode escape sequence", + ); + let mut i = 0; + while let (Some(ch), true) = (self.ch, i < 6) { + if ch.is_digit(16) { + suggestion.push(ch); + self.bump(); + i += 1; + } else { + break; + } + } + if i != 0 { + suggestion.push('}'); + err.span_suggestion_with_applicability( + self.mk_sp(start, self.pos), + "format of unicode escape sequences uses braces", + suggestion, + Applicability::MaybeIncorrect, + ); + } else { + err.span_help( + span, + "format of unicode escape sequences is `\\u{...}`", + ); + } + err.emit(); false }; if ascii_only { |
