Skip to content

Commit 044a8fe

Browse files
committed
Add error message for using typeof instead of an ICE.
This adds error E0516 fixing a type pointed out by @jonas-schievink
1 parent e38210b commit 044a8fe

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,9 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
17031703
}
17041704
}
17051705
hir::TyTypeof(ref _e) => {
1706-
tcx.sess.span_bug(ast_ty.span, "typeof is reserved but unimplemented");
1706+
span_err!(tcx.sess, ast_ty.span, E0516,
1707+
"`typeof` is a reserved keyword but unimplemented");
1708+
tcx.types.err
17071709
}
17081710
hir::TyInfer => {
17091711
// TyInfer also appears as the type of arguments or return

src/librustc_typeck/diagnostics.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,25 @@ extern "platform-intrinsic" {
33313331
```
33323332
"##,
33333333

3334+
E0516: r##"
3335+
The `typeof` keyword is currently reserved but unimplemented.
3336+
Erroneous code example:
3337+
3338+
```
3339+
fn main() {
3340+
let x: typeof(92) = 92;
3341+
}
3342+
```
3343+
3344+
Try using type inference instead. Example:
3345+
3346+
```
3347+
fn main() {
3348+
let x = 92;
3349+
}
3350+
```
3351+
"##,
3352+
33343353
}
33353354

33363355
register_diagnostics! {

src/test/compile-fail/issue-29184.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x: typeof(92) = 92; //~ ERROR `typeof` is a reserved keyword
13+
}

0 commit comments

Comments
 (0)