Skip to content

Commit 2803453

Browse files
Rollup merge of #154819 - cijiugechu:fix-next-solver-inherent-iat-ice, r=jackh726
Fix ICE for inherent associated type mismatches Avoid projection-only suggestions for inherent associated types. Closes #154333 Closes #155204
2 parents 032b666 + 28b0ef6 commit 2803453

5 files changed

Lines changed: 158 additions & 0 deletions

File tree

compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ impl<T> Trait<T> for X {
606606
ty: Ty<'tcx>,
607607
) -> bool {
608608
let tcx = self.tcx;
609+
// FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
610+
if !matches!(proj_ty.kind, ty::AliasTyKind::Projection { .. }) {
611+
return false;
612+
}
609613
let Some(body_owner_def_id) = body_owner_def_id else {
610614
return false;
611615
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/155204>
2+
//@compile-flags: -Znext-solver=globally
3+
#![feature(inherent_associated_types)]
4+
pub struct Windows<T> {}
5+
//~^ ERROR type parameter `T` is never used
6+
7+
impl<T> Windows<fn(&())> {
8+
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
9+
type AssocType = impl Send;
10+
//~^ ERROR `impl Trait` in associated types is unstable
11+
//~| ERROR unconstrained opaque type
12+
fn ret(&self) -> Self::AssocType {
13+
//~^ ERROR type annotations needed
14+
()
15+
//~^ ERROR mismatched types
16+
}
17+
}
18+
//~^ ERROR `main` function not found
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
error[E0658]: `impl Trait` in associated types is unstable
2+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:9:22
3+
|
4+
LL | type AssocType = impl Send;
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
8+
= help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0601]: `main` function not found in crate `next_solver_opaque_inherent_fn_ptr_issue_155204`
12+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:17:2
13+
|
14+
LL | }
15+
| ^ consider adding a `main` function to `$DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs`
16+
17+
error[E0392]: type parameter `T` is never used
18+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:4:20
19+
|
20+
LL | pub struct Windows<T> {}
21+
| ^ unused type parameter
22+
|
23+
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
24+
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
25+
26+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
27+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:7:6
28+
|
29+
LL | impl<T> Windows<fn(&())> {
30+
| ^ unconstrained type parameter
31+
32+
error[E0282]: type annotations needed
33+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:12:22
34+
|
35+
LL | fn ret(&self) -> Self::AssocType {
36+
| ^^^^^^^^^^^^^^^ cannot infer type
37+
38+
error: unconstrained opaque type
39+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:9:22
40+
|
41+
LL | type AssocType = impl Send;
42+
| ^^^^^^^^^
43+
|
44+
= note: `AssocType` must be used in combination with a concrete type within the same impl
45+
46+
error[E0308]: mismatched types
47+
--> $DIR/next-solver-opaque-inherent-fn-ptr-issue-155204.rs:14:9
48+
|
49+
LL | fn ret(&self) -> Self::AssocType {
50+
| --------------- expected `Windows<for<'a> fn(&'a ())>::AssocType` because of return type
51+
LL |
52+
LL | ()
53+
| ^^ types differ
54+
|
55+
= note: expected associated type `Windows<for<'a> fn(&'a ())>::AssocType`
56+
found unit type `()`
57+
= help: consider constraining the associated type `Windows<for<'a> fn(&'a ())>::AssocType` to `()` or calling a method that returns `Windows<for<'a> fn(&'a ())>::AssocType`
58+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
59+
60+
error: aborting due to 7 previous errors
61+
62+
Some errors have detailed explanations: E0207, E0282, E0308, E0392, E0601, E0658.
63+
For more information about an error, try `rustc --explain E0207`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/154333>
2+
//@compile-flags: -Znext-solver=globally
3+
#![feature(inherent_associated_types)]
4+
5+
struct Foo;
6+
impl<const X: y> Foo {
7+
//~^ ERROR the const parameter `X` is not constrained by the impl trait, self type, or predicates
8+
//~| ERROR cannot find type `y` in this scope
9+
type ImplTrait = impl Clone;
10+
//~^ ERROR `impl Trait` in associated types is unstable
11+
//~| ERROR unconstrained opaque type
12+
fn f() -> Self::ImplTrait {
13+
()
14+
//~^ ERROR mismatched types
15+
}
16+
}
17+
//~^ ERROR `main` function not found
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
error[E0425]: cannot find type `y` in this scope
2+
--> $DIR/next-solver-opaque-inherent-no-ice.rs:6:15
3+
|
4+
LL | impl<const X: y> Foo {
5+
| ^ not found in this scope
6+
7+
error[E0658]: `impl Trait` in associated types is unstable
8+
--> $DIR/next-solver-opaque-inherent-no-ice.rs:9:22
9+
|
10+
LL | type ImplTrait = impl Clone;
11+
| ^^^^^^^^^^
12+
|
13+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
14+
= help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
15+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
16+
17+
error[E0601]: `main` function not found in crate `next_solver_opaque_inherent_no_ice`
18+
--> $DIR/next-solver-opaque-inherent-no-ice.rs:16:2
19+
|
20+
LL | }
21+
| ^ consider adding a `main` function to `$DIR/next-solver-opaque-inherent-no-ice.rs`
22+
23+
error[E0207]: the const parameter `X` is not constrained by the impl trait, self type, or predicates
24+
--> $DIR/next-solver-opaque-inherent-no-ice.rs:6:6
25+
|
26+
LL | impl<const X: y> Foo {
27+
| ^^^^^^^^^^ unconstrained const parameter
28+
|
29+
= note: expressions using a const parameter must map each value to a distinct output value
30+
= note: proving the result of expressions other than the parameter are unique is not supported
31+
32+
error: unconstrained opaque type
33+
--> $DIR/next-solver-opaque-inherent-no-ice.rs:9:22
34+
|
35+
LL | type ImplTrait = impl Clone;
36+
| ^^^^^^^^^^
37+
|
38+
= note: `ImplTrait` must be used in combination with a concrete type within the same impl
39+
40+
error[E0308]: mismatched types
41+
--> $DIR/next-solver-opaque-inherent-no-ice.rs:13:9
42+
|
43+
LL | fn f() -> Self::ImplTrait {
44+
| --------------- expected `Foo::ImplTrait` because of return type
45+
LL | ()
46+
| ^^ types differ
47+
|
48+
= note: expected associated type `Foo::ImplTrait`
49+
found unit type `()`
50+
= help: consider constraining the associated type `Foo::ImplTrait` to `()` or calling a method that returns `Foo::ImplTrait`
51+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
52+
53+
error: aborting due to 6 previous errors
54+
55+
Some errors have detailed explanations: E0207, E0308, E0425, E0601, E0658.
56+
For more information about an error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)