Skip to content
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

Fix ReErased leaking into typeck due to typeof(...) recovery #100185

Merged
merged 1 commit into from
Sep 13, 2022
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
5 changes: 4 additions & 1 deletion compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.normalize_ty(ast_ty.span, array_ty)
}
hir::TyKind::Typeof(ref e) => {
let ty = tcx.type_of(tcx.hir().local_def_id(e.hir_id));
let ty_erased = tcx.type_of(tcx.hir().local_def_id(e.hir_id));
let ty = tcx.fold_regions(ty_erased, |r, _| {
if r.is_erased() { tcx.lifetimes.re_static } else { r }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely makes more sense to never create the ReErased in the first place...

Copy link
Member Author

@compiler-errors compiler-errors Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require changing the type_of query behavior for anon consts -- not sure what that would break though. I guess anon consts should be treating all those lifetimes as ReStatic like other consts though 🤔

Copy link
Member Author

@compiler-errors compiler-errors Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackh726: Oh... sooo this calls the typeck query on the body of the AnonConst, so all non-late lifetimes (incl ReStatic) are erased during writeback. Don't think I can avoid getting ReErased when I call tcx.type_of.

});
let span = ast_ty.span;
tcx.sess.emit_err(TypeofReservedKeywordUsed {
span,
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/typeof/issue-100183.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct Struct {
y: (typeof("hey"),),
//~^ ERROR `typeof` is a reserved keyword but unimplemented
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/ui/typeof/issue-100183.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0516]: `typeof` is a reserved keyword but unimplemented
--> $DIR/issue-100183.rs:2:9
|
LL | y: (typeof("hey"),),
| ^^^^^^^^^^^^^ reserved keyword
|
help: consider replacing `typeof(...)` with an actual type
|
LL | y: (&'static str,),
| ~~~~~~~~~~~~

error: aborting due to previous error

For more information about this error, try `rustc --explain E0516`.