Skip to content

Commit 9853343

Browse files
Rollup merge of rust-lang#100185 - compiler-errors:issue-100183, r=wesleywiser
Fix `ReErased` leaking into typeck due to `typeof(...)` recovery Fixes rust-lang#100183
2 parents 52e003a + 315d12d commit 9853343

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26722672
self.normalize_ty(ast_ty.span, array_ty)
26732673
}
26742674
hir::TyKind::Typeof(ref e) => {
2675-
let ty = tcx.type_of(tcx.hir().local_def_id(e.hir_id));
2675+
let ty_erased = tcx.type_of(tcx.hir().local_def_id(e.hir_id));
2676+
let ty = tcx.fold_regions(ty_erased, |r, _| {
2677+
if r.is_erased() { tcx.lifetimes.re_static } else { r }
2678+
});
26762679
let span = ast_ty.span;
26772680
tcx.sess.emit_err(TypeofReservedKeywordUsed {
26782681
span,

src/test/ui/typeof/issue-100183.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct Struct {
2+
y: (typeof("hey"),),
3+
//~^ ERROR `typeof` is a reserved keyword but unimplemented
4+
}
5+
6+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0516]: `typeof` is a reserved keyword but unimplemented
2+
--> $DIR/issue-100183.rs:2:9
3+
|
4+
LL | y: (typeof("hey"),),
5+
| ^^^^^^^^^^^^^ reserved keyword
6+
|
7+
help: consider replacing `typeof(...)` with an actual type
8+
|
9+
LL | y: (&'static str,),
10+
| ~~~~~~~~~~~~
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0516`.

0 commit comments

Comments
 (0)