diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2020-09-26 17:56:03 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2020-09-26 17:56:03 +0100 |
| commit | 3a81adeca2b81a3c54bbbe07afafedea79f92c42 (patch) | |
| tree | 6668f0f18848e469fa6c67ba4d6352189d9d8bcb /compiler | |
| parent | ef83742b2bf9cb26c54576dad76418d872b52a99 (diff) | |
| download | rust-3a81adeca2b81a3c54bbbe07afafedea79f92c42.tar.gz rust-3a81adeca2b81a3c54bbbe07afafedea79f92c42.zip | |
Call `type_of` for opaque types later in compilation
This ensures that various wf checks have already been done before we typeck item bodies.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_typeck/src/check/check.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/collect.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/lib.rs | 2 |
3 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 2daa0354acb..0647be2dfde 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -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); } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index a571bd58abc..d6985f3bd4d 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -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(..) => { diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 84efb92582e..dd6621a3f11 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -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() { |
