Skip to content

Commit 7ee4e9e

Browse files
committed
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`.
2 parents 9a85566 + 044a8fe commit 7ee4e9e

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/librustc_typeck/astconv.rs

+3-1
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

+19
Original file line numberDiff line numberDiff line change
@@ -3330,6 +3330,25 @@ extern "platform-intrinsic" {
33303330
```
33313331
"##,
33323332

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

33353354
register_diagnostics! {

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

+13
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)