Skip to content

Commit 3a81ade

Browse files
committed
Call type_of for opaque types later in compilation
This ensures that various wf checks have already been done before we typeck item bodies.
1 parent ef83742 commit 3a81ade

32 files changed

+356
-420
lines changed

compiler/rustc_typeck/src/check/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ pub(super) fn check_opaque<'tcx>(
385385
origin: &hir::OpaqueTyOrigin,
386386
) {
387387
check_opaque_for_inheriting_lifetimes(tcx, def_id, span);
388+
tcx.ensure().type_of(def_id);
388389
check_opaque_for_cycles(tcx, def_id, substs, span, origin);
389390
}
390391

compiler/rustc_typeck/src/collect.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
693693
// Desugared from `impl Trait`, so visited by the function's return type.
694694
hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn: Some(_), .. }) => {}
695695

696-
hir::ItemKind::OpaqueTy(..)
697-
| hir::ItemKind::TyAlias(..)
696+
// Don't call `type_of` on opaque types, since that depends on type
697+
// checking function bodies. `check_item_type` ensures that it's called
698+
// instead.
699+
hir::ItemKind::OpaqueTy(..) => {
700+
tcx.ensure().generics_of(def_id);
701+
tcx.ensure().predicates_of(def_id);
702+
}
703+
hir::ItemKind::TyAlias(..)
698704
| hir::ItemKind::Static(..)
699705
| hir::ItemKind::Const(..)
700706
| hir::ItemKind::Fn(..) => {

compiler/rustc_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
360360

361361
// this ensures that later parts of type checking can assume that items
362362
// have valid types and not error
363-
// FIXME(matthewjasper) We shouldn't need to do this.
363+
// FIXME(matthewjasper) We shouldn't need to use `track_errors`.
364364
tcx.sess.track_errors(|| {
365365
tcx.sess.time("type_collecting", || {
366366
for &module in tcx.hir().krate().modules.keys() {

src/test/ui/associated-type-bounds/duplicate.rs

-21
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ fn FW3<T>() where T: Iterator<Item: 'static, Item: 'static> {}
6060
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
6161

6262
fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> { iter::empty() }
63-
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
6463
fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> { iter::empty() }
65-
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
6664
fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> { iter::empty() }
67-
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
6865
fn FAPIT1(_: impl Iterator<Item: Copy, Item: Send>) {}
6966
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
7067
fn FAPIT2(_: impl Iterator<Item: Copy, Item: Copy>) {}
@@ -107,28 +104,16 @@ type TAW3<T> where T: Iterator<Item: 'static, Item: 'static> = T;
107104

108105
type ETAI1<T: Iterator<Item: Copy, Item: Send>> = impl Copy;
109106
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
110-
//~| ERROR could not find defining uses
111107
type ETAI2<T: Iterator<Item: Copy, Item: Copy>> = impl Copy;
112108
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
113-
//~| ERROR could not find defining uses
114109
type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy;
115110
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
116-
//~| ERROR could not find defining uses
117111
type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
118112
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
119-
//~| ERROR could not find defining uses
120-
//~| ERROR could not find defining uses
121-
//~| ERROR could not find defining uses
122113
type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
123114
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
124-
//~| ERROR could not find defining uses
125-
//~| ERROR could not find defining uses
126-
//~| ERROR could not find defining uses
127115
type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
128116
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
129-
//~| ERROR could not find defining uses
130-
//~| ERROR could not find defining uses
131-
//~| ERROR could not find defining uses
132117

133118
trait TRI1<T: Iterator<Item: Copy, Item: Send>> {}
134119
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
@@ -166,15 +151,9 @@ trait TRA3 { type A: Iterator<Item: 'static, Item: 'static>; }
166151

167152
type TADyn1 = dyn Iterator<Item: Copy, Item: Send>;
168153
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
169-
//~| ERROR could not find defining uses
170-
//~| ERROR could not find defining uses
171154
type TADyn2 = Box<dyn Iterator<Item: Copy, Item: Copy>>;
172155
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
173-
//~| ERROR could not find defining uses
174-
//~| ERROR could not find defining uses
175156
type TADyn3 = dyn Iterator<Item: 'static, Item: 'static>;
176157
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
177-
//~| ERROR could not find defining uses
178-
//~| ERROR could not find defining uses
179158

180159
fn main() {}

0 commit comments

Comments
 (0)