about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-08-26 09:51:46 +0900
committerGitHub <noreply@github.com>2022-08-26 09:51:46 +0900
commitd4a5ec17a73dd886d3a187659c032d5f9b95f0b9 (patch)
tree675ddc4bc40148870e7304f90aca483509da0fa2
parent684955591c6d1174d9b992e4115cb0e981430ba9 (diff)
parentb997af95fce1f1295f3b90ae33c575b6ded4f914 (diff)
downloadrust-d4a5ec17a73dd886d3a187659c032d5f9b95f0b9.tar.gz
rust-d4a5ec17a73dd886d3a187659c032d5f9b95f0b9.zip
Rollup merge of #100978 - nnethercote:fix-100948, r=petrochenkov
Handle `Err` in `ast::LitKind::to_token_lit`.

Fixes #100948.

r? ``@petrochenkov``
-rw-r--r--compiler/rustc_ast/src/util/literal.rs4
-rw-r--r--src/test/ui/unpretty/bad-literal.rs8
-rw-r--r--src/test/ui/unpretty/bad-literal.stderr10
-rw-r--r--src/test/ui/unpretty/bad-literal.stdout11
4 files changed, 32 insertions, 1 deletions
diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs
index 6a02a3b56f6..69a78d165ef 100644
--- a/compiler/rustc_ast/src/util/literal.rs
+++ b/compiler/rustc_ast/src/util/literal.rs
@@ -199,7 +199,9 @@ impl LitKind {
                 let symbol = if value { kw::True } else { kw::False };
                 (token::Bool, symbol, None)
             }
-            LitKind::Err => unreachable!(),
+            // This only shows up in places like `-Zunpretty=hir` output, so we
+            // don't bother to produce something useful.
+            LitKind::Err => (token::Err, Symbol::intern("<bad-literal>"), None),
         };
 
         token::Lit::new(kind, symbol, suffix)
diff --git a/src/test/ui/unpretty/bad-literal.rs b/src/test/ui/unpretty/bad-literal.rs
new file mode 100644
index 00000000000..6dcc0da30cc
--- /dev/null
+++ b/src/test/ui/unpretty/bad-literal.rs
@@ -0,0 +1,8 @@
+// compile-flags: -Zunpretty=hir
+// check-fail
+
+// In #100948 this caused an ICE with -Zunpretty=hir.
+fn main() {
+    1u;
+    //~^ ERROR invalid suffix `u` for number literal
+}
diff --git a/src/test/ui/unpretty/bad-literal.stderr b/src/test/ui/unpretty/bad-literal.stderr
new file mode 100644
index 00000000000..f3fcb4a4e92
--- /dev/null
+++ b/src/test/ui/unpretty/bad-literal.stderr
@@ -0,0 +1,10 @@
+error: invalid suffix `u` for number literal
+  --> $DIR/bad-literal.rs:6:5
+   |
+LL |     1u;
+   |     ^^ invalid suffix `u`
+   |
+   = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/unpretty/bad-literal.stdout b/src/test/ui/unpretty/bad-literal.stdout
new file mode 100644
index 00000000000..8df93327033
--- /dev/null
+++ b/src/test/ui/unpretty/bad-literal.stdout
@@ -0,0 +1,11 @@
+#[prelude_import]
+use ::std::prelude::rust_2015::*;
+#[macro_use]
+extern crate std;
+// compile-flags: -Zunpretty=hir
+// check-fail
+
+// In #100948 this caused an ICE with -Zunpretty=hir.
+fn main() {
+        <bad-literal>;
+    }