Skip to content

Commit bfe4c5f

Browse files
committed
Move opaque type checks from the hir item types visitor onto the wfcheck of the opaqe type itself
1 parent 81a964c commit bfe4c5f

File tree

8 files changed

+151
-141
lines changed

8 files changed

+151
-141
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,17 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
770770
} else {
771771
check_opaque(tcx, def_id);
772772
}
773+
774+
tcx.ensure_ok().generics_of(def_id);
775+
tcx.ensure_ok().predicates_of(def_id);
776+
tcx.ensure_ok().explicit_item_bounds(def_id);
777+
tcx.ensure_ok().explicit_item_self_bounds(def_id);
778+
tcx.ensure_ok().item_bounds(def_id);
779+
tcx.ensure_ok().item_self_bounds(def_id);
780+
if tcx.is_conditionally_const(def_id) {
781+
tcx.ensure_ok().explicit_implied_const_bounds(def_id);
782+
tcx.ensure_ok().const_conditions(def_id);
783+
}
773784
}
774785
DefKind::TyAlias => {
775786
check_type_alias_type_params_are_used(tcx, def_id);

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,6 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
321321
intravisit::walk_expr(self, expr);
322322
}
323323

324-
/// Don't call `type_of` on opaque types, since that depends on type checking function bodies.
325-
/// `check_item_type` ensures that it's called instead.
326-
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
327-
let def_id = opaque.def_id;
328-
self.tcx.ensure_ok().generics_of(def_id);
329-
self.tcx.ensure_ok().predicates_of(def_id);
330-
self.tcx.ensure_ok().explicit_item_bounds(def_id);
331-
self.tcx.ensure_ok().explicit_item_self_bounds(def_id);
332-
self.tcx.ensure_ok().item_bounds(def_id);
333-
self.tcx.ensure_ok().item_self_bounds(def_id);
334-
if self.tcx.is_conditionally_const(def_id) {
335-
self.tcx.ensure_ok().explicit_implied_const_bounds(def_id);
336-
self.tcx.ensure_ok().const_conditions(def_id);
337-
}
338-
intravisit::walk_opaque_ty(self, opaque);
339-
}
340-
341324
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
342325
lower_trait_item(self.tcx, trait_item.trait_item_id());
343326
intravisit::walk_trait_item(self, trait_item);

tests/ui/associated-inherent-types/issue-109299-1.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: unconstrained opaque type
2+
--> $DIR/issue-109299-1.rs:10:10
3+
|
4+
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `X` must be used in combination with a concrete type within the same crate
8+
19
error[E0220]: associated type `Cursor` not found for `Lexer<T>` in the current scope
210
--> $DIR/issue-109299-1.rs:10:40
311
|
@@ -23,14 +31,6 @@ LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
2331
- `Lexer<i32>`
2432
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2533

26-
error: unconstrained opaque type
27-
--> $DIR/issue-109299-1.rs:10:10
28-
|
29-
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
|
32-
= note: `X` must be used in combination with a concrete type within the same crate
33-
3434
error: aborting due to 3 previous errors
3535

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

tests/ui/associated-type-bounds/duplicate.stderr

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,6 @@ LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
198198
| |
199199
| `Item` bound here first
200200

201-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
202-
--> $DIR/duplicate.rs:133:42
203-
|
204-
LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
205-
| ---------- ^^^^^^^^^^ re-bound here
206-
| |
207-
| `Item` bound here first
208-
|
209-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
210-
211201
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
212202
--> $DIR/duplicate.rs:139:42
213203
|
@@ -216,33 +206,13 @@ LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
216206
| |
217207
| `Item` bound here first
218208

219-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
220-
--> $DIR/duplicate.rs:139:42
221-
|
222-
LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
223-
| ---------- ^^^^^^^^^^ re-bound here
224-
| |
225-
| `Item` bound here first
226-
|
227-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
228-
229-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
230-
--> $DIR/duplicate.rs:145:45
231-
|
232-
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
233-
| ------------- ^^^^^^^^^^^^^ re-bound here
234-
| |
235-
| `Item` bound here first
236-
237209
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
238210
--> $DIR/duplicate.rs:145:45
239211
|
240212
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
241213
| ------------- ^^^^^^^^^^^^^ re-bound here
242214
| |
243215
| `Item` bound here first
244-
|
245-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
246216

247217
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
248218
--> $DIR/duplicate.rs:151:40
@@ -340,60 +310,6 @@ LL | type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy;
340310
| |
341311
| `Item` bound here first
342312

343-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
344-
--> $DIR/duplicate.rs:189:40
345-
|
346-
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
347-
| ---------- ^^^^^^^^^^ re-bound here
348-
| |
349-
| `Item` bound here first
350-
351-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
352-
--> $DIR/duplicate.rs:189:40
353-
|
354-
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
355-
| ---------- ^^^^^^^^^^ re-bound here
356-
| |
357-
| `Item` bound here first
358-
|
359-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
360-
361-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
362-
--> $DIR/duplicate.rs:193:40
363-
|
364-
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
365-
| ---------- ^^^^^^^^^^ re-bound here
366-
| |
367-
| `Item` bound here first
368-
369-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
370-
--> $DIR/duplicate.rs:193:40
371-
|
372-
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
373-
| ---------- ^^^^^^^^^^ re-bound here
374-
| |
375-
| `Item` bound here first
376-
|
377-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
378-
379-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
380-
--> $DIR/duplicate.rs:197:43
381-
|
382-
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
383-
| ------------- ^^^^^^^^^^^^^ re-bound here
384-
| |
385-
| `Item` bound here first
386-
387-
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
388-
--> $DIR/duplicate.rs:197:43
389-
|
390-
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
391-
| ------------- ^^^^^^^^^^^^^ re-bound here
392-
| |
393-
| `Item` bound here first
394-
|
395-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
396-
397313
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
398314
--> $DIR/duplicate.rs:202:36
399315
|
@@ -664,6 +580,16 @@ LL | type A: Iterator<Item: 'static, Item: 'static>;
664580
|
665581
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
666582

583+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
584+
--> $DIR/duplicate.rs:133:42
585+
|
586+
LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
587+
| ---------- ^^^^^^^^^^ re-bound here
588+
| |
589+
| `Item` bound here first
590+
|
591+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
592+
667593
error[E0282]: type annotations needed
668594
--> $DIR/duplicate.rs:136:5
669595
|
@@ -675,6 +601,16 @@ help: consider specifying the generic argument
675601
LL | iter::empty::<T>()
676602
| +++++
677603

604+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
605+
--> $DIR/duplicate.rs:139:42
606+
|
607+
LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
608+
| ---------- ^^^^^^^^^^ re-bound here
609+
| |
610+
| `Item` bound here first
611+
|
612+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
613+
678614
error[E0282]: type annotations needed
679615
--> $DIR/duplicate.rs:142:5
680616
|
@@ -686,6 +622,16 @@ help: consider specifying the generic argument
686622
LL | iter::empty::<T>()
687623
| +++++
688624

625+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
626+
--> $DIR/duplicate.rs:145:45
627+
|
628+
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
629+
| ------------- ^^^^^^^^^^^^^ re-bound here
630+
| |
631+
| `Item` bound here first
632+
|
633+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
634+
689635
error[E0282]: type annotations needed
690636
--> $DIR/duplicate.rs:148:5
691637
|
@@ -729,6 +675,24 @@ LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
729675
|
730676
= note: `ETAI4` must be used in combination with a concrete type within the same crate
731677

678+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
679+
--> $DIR/duplicate.rs:189:40
680+
|
681+
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
682+
| ---------- ^^^^^^^^^^ re-bound here
683+
| |
684+
| `Item` bound here first
685+
686+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
687+
--> $DIR/duplicate.rs:189:40
688+
|
689+
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
690+
| ---------- ^^^^^^^^^^ re-bound here
691+
| |
692+
| `Item` bound here first
693+
|
694+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
695+
732696
error: unconstrained opaque type
733697
--> $DIR/duplicate.rs:193:14
734698
|
@@ -737,6 +701,24 @@ LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
737701
|
738702
= note: `ETAI5` must be used in combination with a concrete type within the same crate
739703

704+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
705+
--> $DIR/duplicate.rs:193:40
706+
|
707+
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
708+
| ---------- ^^^^^^^^^^ re-bound here
709+
| |
710+
| `Item` bound here first
711+
712+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
713+
--> $DIR/duplicate.rs:193:40
714+
|
715+
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
716+
| ---------- ^^^^^^^^^^ re-bound here
717+
| |
718+
| `Item` bound here first
719+
|
720+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
721+
740722
error: unconstrained opaque type
741723
--> $DIR/duplicate.rs:197:14
742724
|
@@ -745,6 +727,24 @@ LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
745727
|
746728
= note: `ETAI6` must be used in combination with a concrete type within the same crate
747729

730+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
731+
--> $DIR/duplicate.rs:197:43
732+
|
733+
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
734+
| ------------- ^^^^^^^^^^^^^ re-bound here
735+
| |
736+
| `Item` bound here first
737+
738+
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
739+
--> $DIR/duplicate.rs:197:43
740+
|
741+
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
742+
| ------------- ^^^^^^^^^^^^^ re-bound here
743+
| |
744+
| `Item` bound here first
745+
|
746+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
747+
748748
error: aborting due to 87 previous errors
749749

750750
Some errors have detailed explanations: E0282, E0719.

tests/ui/query-system/issue-83479.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type PairCoupledTypes: Trait<
88
}],
99
> = impl Trait<
1010
//~^ ERROR: cannot find trait `Trait` in this scope
11+
//~| ERROR: unconstrained opaque type
1112
[u32; {
1213
static FOO: usize; //~ ERROR: free static item without body
1314
}],

tests/ui/query-system/issue-83479.stderr

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | static FOO: usize;
2020
| help: provide a definition for the static: `= <expr>;`
2121

2222
error: free static item without body
23-
--> $DIR/issue-83479.rs:12:9
23+
--> $DIR/issue-83479.rs:13:9
2424
|
2525
LL | static FOO: usize;
2626
| ^^^^^^^^^^^^^^^^^-
@@ -39,6 +39,21 @@ error[E0405]: cannot find trait `Trait` in this scope
3939
LL | > = impl Trait<
4040
| ^^^^^ not found in this scope
4141

42-
error: aborting due to 5 previous errors
42+
error: unconstrained opaque type
43+
--> $DIR/issue-83479.rs:9:5
44+
|
45+
LL | > = impl Trait<
46+
| _____^
47+
LL | |
48+
LL | |
49+
LL | | [u32; {
50+
LL | | static FOO: usize;
51+
LL | | }],
52+
LL | | >;
53+
| |_^
54+
|
55+
= note: `PairCoupledTypes` must be used in combination with a concrete type within the same crate
56+
57+
error: aborting due to 6 previous errors
4358

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

tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ help: replace the generic bound with the associated type
4848
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
4949
| +++++++
5050

51-
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
52-
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
53-
|
54-
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
55-
| ^^^^^ expected 1 generic argument
56-
|
57-
note: trait defined here, with 1 generic parameter: `T`
58-
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11
59-
|
60-
LL | pub trait Trait<T> {
61-
| ^^^^^ -
62-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
63-
help: replace the generic bound with the associated type
64-
|
65-
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
66-
| +++++++
67-
6851
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
6952
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:18
7053
|
@@ -127,6 +110,23 @@ note: struct defined here, with 1 generic parameter: `T`
127110
LL | struct Struct<T: Trait<u32, String>> {
128111
| ^^^^^^ -
129112

113+
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
114+
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
115+
|
116+
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
117+
| ^^^^^ expected 1 generic argument
118+
|
119+
note: trait defined here, with 1 generic parameter: `T`
120+
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11
121+
|
122+
LL | pub trait Trait<T> {
123+
| ^^^^^ -
124+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
125+
help: replace the generic bound with the associated type
126+
|
127+
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
128+
| +++++++
129+
130130
error: aborting due to 9 previous errors
131131

132132
Some errors have detailed explanations: E0107, E0207.

0 commit comments

Comments
 (0)