1
Fork 0

Call type_of for opaque types later in compilation

This ensures that various wf checks have already been done before we
typeck item bodies.
This commit is contained in:
Matthew Jasper 2020-09-26 17:56:03 +01:00
parent ef83742b2b
commit 3a81adeca2
32 changed files with 361 additions and 425 deletions

View file

@ -385,6 +385,7 @@ pub(super) fn check_opaque<'tcx>(
origin: &hir::OpaqueTyOrigin,
) {
check_opaque_for_inheriting_lifetimes(tcx, def_id, span);
tcx.ensure().type_of(def_id);
check_opaque_for_cycles(tcx, def_id, substs, span, origin);
}

View file

@ -693,8 +693,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
// Desugared from `impl Trait`, so visited by the function's return type.
hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn: Some(_), .. }) => {}
hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::TyAlias(..)
// Don't call `type_of` on opaque types, since that depends on type
// checking function bodies. `check_item_type` ensures that it's called
// instead.
hir::ItemKind::OpaqueTy(..) => {
tcx.ensure().generics_of(def_id);
tcx.ensure().predicates_of(def_id);
}
hir::ItemKind::TyAlias(..)
| hir::ItemKind::Static(..)
| hir::ItemKind::Const(..)
| hir::ItemKind::Fn(..) => {

View file

@ -360,7 +360,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
// this ensures that later parts of type checking can assume that items
// have valid types and not error
// FIXME(matthewjasper) We shouldn't need to do this.
// FIXME(matthewjasper) We shouldn't need to use `track_errors`.
tcx.sess.track_errors(|| {
tcx.sess.time("type_collecting", || {
for &module in tcx.hir().krate().modules.keys() {