Skip to content

Commit de0fbeb

Browse files
authored
Rollup merge of #109238 - spastorino:new-rpitit-12, r=compiler-errors
Fix generics mismatch errors for RPITITs on -Zlower-impl-trait-in-trait-to-assoc-ty This PR stops reporting errors due to different count of generics on the new synthesized associated types for RPITITs. Those were already reported when we compare the function on the triat with the function on the impl. r? `@compiler-errors`
2 parents 794d541 + a12665a commit de0fbeb

File tree

7 files changed

+76
-1
lines changed

7 files changed

+76
-1
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,17 @@ fn compare_number_of_generics<'tcx>(
12051205
return Ok(());
12061206
}
12071207

1208+
// We never need to emit a separate error for RPITITs, since if an RPITIT
1209+
// has mismatched type or const generic arguments, then the method that it's
1210+
// inheriting the generics from will also have mismatched arguments, and
1211+
// we'll report an error for that instead. Delay a bug for safety, though.
1212+
if tcx.opt_rpitit_info(trait_.def_id).is_some() {
1213+
return Err(tcx.sess.delay_span_bug(
1214+
rustc_span::DUMMY_SP,
1215+
"errors comparing numbers of generics of trait/impl functions were not emitted",
1216+
));
1217+
}
1218+
12081219
let matchings = [
12091220
("type", trait_own_counts.types, impl_own_counts.types),
12101221
("const", trait_own_counts.consts, impl_own_counts.consts),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0053]: method `foo` has an incompatible generic parameter for trait `Foo`
2+
--> $DIR/generics-mismatch.rs:13:18
3+
|
4+
LL | trait Foo {
5+
| ---
6+
LL | async fn foo<T>();
7+
| - expected type parameter
8+
...
9+
LL | impl Foo for () {
10+
| ---------------
11+
LL | async fn foo<const N: usize>() {}
12+
| ^^^^^^^^^^^^^^ found const parameter of type `usize`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0053`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0053]: method `foo` has an incompatible generic parameter for trait `Foo`
2+
--> $DIR/generics-mismatch.rs:13:18
3+
|
4+
LL | trait Foo {
5+
| ---
6+
LL | async fn foo<T>();
7+
| - expected type parameter
8+
...
9+
LL | impl Foo for () {
10+
| ---------------
11+
LL | async fn foo<const N: usize>() {}
12+
| ^^^^^^^^^^^^^^ found const parameter of type `usize`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0053`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition: 2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
4+
5+
#![feature(async_fn_in_trait)]
6+
#![allow(incomplete_features)]
7+
8+
trait Foo {
9+
async fn foo<T>();
10+
}
11+
12+
impl Foo for () {
13+
async fn foo<const N: usize>() {}
14+
//~^ ERROR: method `foo` has an incompatible generic parameter for trait `Foo` [E0053]
15+
}
16+
17+
fn main() {}

tests/ui/impl-trait/in-trait/generics-mismatch.stderr renamed to tests/ui/impl-trait/in-trait/generics-mismatch.current.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters
2-
--> $DIR/generics-mismatch.rs:11:12
2+
--> $DIR/generics-mismatch.rs:14:12
33
|
44
LL | fn bar(&self) -> impl Sized;
55
| - expected 0 type parameters
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters
2+
--> $DIR/generics-mismatch.rs:14:12
3+
|
4+
LL | fn bar(&self) -> impl Sized;
5+
| - expected 0 type parameters
6+
...
7+
LL | fn bar<T>(&self) {}
8+
| ^ found 1 type parameter
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0049`.

tests/ui/impl-trait/in-trait/generics-mismatch.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
2+
// revisions: current next
3+
14
#![feature(return_position_impl_trait_in_trait)]
25
#![allow(incomplete_features)]
36

0 commit comments

Comments
 (0)