]> git.lizzy.rs Git - rust.git/commitdiff
Fix issue #64732
authorHaoran Wang <waharaxn@gmail.com>
Wed, 25 Sep 2019 21:22:46 +0000 (17:22 -0400)
committerHaoran Wang <waharaxn@gmail.com>
Thu, 26 Sep 2019 00:42:59 +0000 (20:42 -0400)
Based on issue #64732, when creating a byte literal with single quotes,
the suggestion message would indicate that you meant to write a `str` literal,
but we actually meant to write a byte string literal.

So I changed the unescape_error_reporting.rs to decide whether to print out
"if you meant to write a `str` literal, use double quotes",
or "if you meant to write a byte string literal, use double quotes".

src/libsyntax/parse/unescape_error_reporting.rs

index 7eee07e61a95df234151ad5ac728e388be5f328b..5565015179c2d5949a9291f72b5b1431b38b21c0 100644 (file)
@@ -47,6 +47,12 @@ pub(crate) fn emit_unescape_error(
                 .emit();
         }
         EscapeError::MoreThanOneChar => {
+            let msg = if mode.is_bytes() {
+                "if you meant to write a byte string literal, use double quotes"
+            } else {
+                "if you meant to write a `str` literal, use double quotes"
+            };
+
             handler
                 .struct_span_err(
                     span_with_quotes,
@@ -54,7 +60,7 @@ pub(crate) fn emit_unescape_error(
                 )
                 .span_suggestion(
                     span_with_quotes,
-                    "if you meant to write a `str` literal, use double quotes",
+                    msg,
                     format!("\"{}\"", lit),
                     Applicability::MachineApplicable,
                 ).emit()