Skip to content

Commit 315d12d

Browse files
Fix ReErased leaking into typeck due to typeof recovery
1 parent d77da9d commit 315d12d

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
@@ -2667,7 +2667,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26672667
self.normalize_ty(ast_ty.span, array_ty)
26682668
}
26692669
hir::TyKind::Typeof(ref e) => {
2670-
let ty = tcx.type_of(tcx.hir().local_def_id(e.hir_id));
2670+
let ty_erased = tcx.type_of(tcx.hir().local_def_id(e.hir_id));
2671+
let ty = tcx.fold_regions(ty_erased, |r, _| {
2672+
if r.is_erased() { tcx.lifetimes.re_static } else { r }
2673+
});
26712674
let span = ast_ty.span;
26722675
tcx.sess.emit_err(TypeofReservedKeywordUsed {
26732676
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)