Skip to content

Add an error message for using typeof instead of an ICE #29243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
13 changes: 13 additions & 0 deletions src/test/compile-fail/issue-29184.rs
Original file line number Diff line number Diff line change
@@ -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
}