Move opaque type checks from the hir item types visitor onto the wfcheck of the opaqe type itself

This commit is contained in:
Oli Scherer 2025-06-05 10:01:07 +00:00
parent 81a964c23e
commit bfe4c5f78c
8 changed files with 167 additions and 157 deletions

View file

@ -770,6 +770,17 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
} else {
check_opaque(tcx, def_id);
}
tcx.ensure_ok().generics_of(def_id);
tcx.ensure_ok().predicates_of(def_id);
tcx.ensure_ok().explicit_item_bounds(def_id);
tcx.ensure_ok().explicit_item_self_bounds(def_id);
tcx.ensure_ok().item_bounds(def_id);
tcx.ensure_ok().item_self_bounds(def_id);
if tcx.is_conditionally_const(def_id) {
tcx.ensure_ok().explicit_implied_const_bounds(def_id);
tcx.ensure_ok().const_conditions(def_id);
}
}
DefKind::TyAlias => {
check_type_alias_type_params_are_used(tcx, def_id);

View file

@ -321,23 +321,6 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
intravisit::walk_expr(self, expr);
}
/// 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.
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
let def_id = opaque.def_id;
self.tcx.ensure_ok().generics_of(def_id);
self.tcx.ensure_ok().predicates_of(def_id);
self.tcx.ensure_ok().explicit_item_bounds(def_id);
self.tcx.ensure_ok().explicit_item_self_bounds(def_id);
self.tcx.ensure_ok().item_bounds(def_id);
self.tcx.ensure_ok().item_self_bounds(def_id);
if self.tcx.is_conditionally_const(def_id) {
self.tcx.ensure_ok().explicit_implied_const_bounds(def_id);
self.tcx.ensure_ok().const_conditions(def_id);
}
intravisit::walk_opaque_ty(self, opaque);
}
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
lower_trait_item(self.tcx, trait_item.trait_item_id());
intravisit::walk_trait_item(self, trait_item);

View file

@ -1,3 +1,11 @@
error: unconstrained opaque type
--> $DIR/issue-109299-1.rs:10:10
|
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `X` must be used in combination with a concrete type within the same crate
error[E0220]: associated type `Cursor` not found for `Lexer<T>` in the current scope
--> $DIR/issue-109299-1.rs:10:40
|
@ -23,14 +31,6 @@ LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
- `Lexer<i32>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type
--> $DIR/issue-109299-1.rs:10:10
|
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `X` must be used in combination with a concrete type within the same crate
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0220`.

View file

@ -198,16 +198,6 @@ LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:133:42
|
LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:139:42
|
@ -216,24 +206,6 @@ LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:139:42
|
LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:145:45
|
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:145:45
|
@ -241,8 +213,6 @@ LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:151:40
@ -340,60 +310,6 @@ LL | type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy;
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:202:36
|
@ -664,6 +580,16 @@ LL | type A: Iterator<Item: 'static, Item: 'static>;
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:133:42
|
LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0282]: type annotations needed
--> $DIR/duplicate.rs:136:5
|
@ -675,6 +601,16 @@ help: consider specifying the generic argument
LL | iter::empty::<T>()
| +++++
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:139:42
|
LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0282]: type annotations needed
--> $DIR/duplicate.rs:142:5
|
@ -686,6 +622,16 @@ help: consider specifying the generic argument
LL | iter::empty::<T>()
| +++++
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:145:45
|
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0282]: type annotations needed
--> $DIR/duplicate.rs:148:5
|
@ -729,6 +675,24 @@ LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
|
= note: `ETAI4` must be used in combination with a concrete type within the same crate
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type
--> $DIR/duplicate.rs:193:14
|
@ -737,6 +701,24 @@ LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
|
= note: `ETAI5` must be used in combination with a concrete type within the same crate
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type
--> $DIR/duplicate.rs:197:14
|
@ -745,6 +727,24 @@ LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
|
= note: `ETAI6` must be used in combination with a concrete type within the same crate
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 87 previous errors
Some errors have detailed explanations: E0282, E0719.

View file

@ -8,6 +8,7 @@ type PairCoupledTypes: Trait<
}],
> = impl Trait<
//~^ ERROR: cannot find trait `Trait` in this scope
//~| ERROR: unconstrained opaque type
[u32; {
static FOO: usize; //~ ERROR: free static item without body
}],

View file

@ -20,7 +20,7 @@ LL | static FOO: usize;
| help: provide a definition for the static: `= <expr>;`
error: free static item without body
--> $DIR/issue-83479.rs:12:9
--> $DIR/issue-83479.rs:13:9
|
LL | static FOO: usize;
| ^^^^^^^^^^^^^^^^^-
@ -39,6 +39,21 @@ error[E0405]: cannot find trait `Trait` in this scope
LL | > = impl Trait<
| ^^^^^ not found in this scope
error: aborting due to 5 previous errors
error: unconstrained opaque type
--> $DIR/issue-83479.rs:9:5
|
LL | > = impl Trait<
| _____^
LL | |
LL | |
LL | | [u32; {
LL | | static FOO: usize;
LL | | }],
LL | | >;
| |_^
|
= note: `PairCoupledTypes` must be used in combination with a concrete type within the same crate
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0405`.

View file

@ -48,23 +48,6 @@ help: replace the generic bound with the associated type
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
| +++++++
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
| ^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11
|
LL | pub trait Trait<T> {
| ^^^^^ -
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: replace the generic bound with the associated type
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
| +++++++
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:18
|
@ -127,6 +110,23 @@ note: struct defined here, with 1 generic parameter: `T`
LL | struct Struct<T: Trait<u32, String>> {
| ^^^^^^ -
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
| ^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11
|
LL | pub trait Trait<T> {
| ^^^^^ -
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: replace the generic bound with the associated type
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
| +++++++
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0107, E0207.

View file

@ -32,35 +32,6 @@ LL | x: impl ~const PartialEq + ~const Destruct,
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:16:13
|
@ -71,6 +42,25 @@ note: `PartialEq` can't be used with `~const` because it isn't annotated with `#
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:23:22
|
@ -89,6 +79,16 @@ LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy {
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:27:22
|