Auto merge of #29243 - skeleten:issue-29184, r=alexcrichton
Fixes #29184 This adds an error message for the use of the reserved `typeof` keyword, instead of reporting an ICE. Also adds a `compile-fail` test. I chose to add a `span_err` instead of removing to parser code, as to preserve the reservation of `typeof`.
This commit is contained in:
commit
7ee4e9e7ec
@ -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
|
||||
|
@ -3330,6 +3330,25 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8,
|
||||
```
|
||||
"##,
|
||||
|
||||
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! {
|
||||
|
13
src/test/compile-fail/issue-29184.rs
Normal file
13
src/test/compile-fail/issue-29184.rs
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user