about summary refs log tree commit diff
diff options
context:
space:
mode:
authorskeleten <janpelle.thomson@stud.tu-darmstadt.de>2015-10-22 22:08:46 +0200
committerskeleten <janpelle.thomson@stud.tu-darmstadt.de>2015-10-23 16:34:47 +0200
commit044a8fe6f6834afb3b159da7439c2740295157d3 (patch)
tree4ceba7c101930451deb4f4bb610b183dd125ae20
parente38210b195a4aaf91f3daa37dfcfd7059bd22ddc (diff)
downloadrust-044a8fe6f6834afb3b159da7439c2740295157d3.tar.gz
rust-044a8fe6f6834afb3b159da7439c2740295157d3.zip
Add error message for using `typeof` instead of an ICE.
This adds error E0516

fixing a type pointed out by @jonas-schievink
-rw-r--r--src/librustc_typeck/astconv.rs4
-rw-r--r--src/librustc_typeck/diagnostics.rs19
-rw-r--r--src/test/compile-fail/issue-29184.rs13
3 files changed, 35 insertions, 1 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index a05d9b19d23..d3939ab9a0a 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -1703,7 +1703,9 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
             }
         }
         hir::TyTypeof(ref _e) => {
-            tcx.sess.span_bug(ast_ty.span, "typeof is reserved but unimplemented");
+            span_err!(tcx.sess, ast_ty.span, E0516,
+                  "`typeof` is a reserved keyword but unimplemented");
+            tcx.types.err
         }
         hir::TyInfer => {
             // TyInfer also appears as the type of arguments or return
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 4746819f6a9..6fcd5f9072f 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -3331,6 +3331,25 @@ extern "platform-intrinsic" {
 ```
 "##,
 
+E0516: r##"
+The `typeof` keyword is currently reserved but unimplemented.
+Erroneous code example:
+
+```
+fn main() {
+    let x: typeof(92) = 92;
+}
+```
+
+Try using type inference instead. Example:
+
+```
+fn main() {
+    let x = 92;
+}
+```
+"##,
+
 }
 
 register_diagnostics! {
diff --git a/src/test/compile-fail/issue-29184.rs b/src/test/compile-fail/issue-29184.rs
new file mode 100644
index 00000000000..98fe12c1b9d
--- /dev/null
+++ b/src/test/compile-fail/issue-29184.rs
@@ -0,0 +1,13 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    let x: typeof(92) = 92; //~ ERROR `typeof` is a reserved keyword
+}