Skip to content

Commit

Permalink
Rollup merge of rust-lang#109238 - spastorino:new-rpitit-12, r=compil…
Browse files Browse the repository at this point in the history
…er-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`
  • Loading branch information
matthiaskrgr authored Mar 17, 2023
2 parents 23cbfd4 + 2c57655 commit 6958548
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
11 changes: 11 additions & 0 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,17 @@ fn compare_number_of_generics<'tcx>(
return Ok(());
}

// We never need to emit a separate error for RPITITs, since if an RPITIT
// has mismatched type or const generic arguments, then the method that it's
// inheriting the generics from will also have mismatched arguments, and
// we'll report an error for that instead. Delay a bug for safety, though.
if tcx.opt_rpitit_info(trait_.def_id).is_some() {
return Err(tcx.sess.delay_span_bug(
rustc_span::DUMMY_SP,
"errors comparing numbers of generics of trait/impl functions were not emitted",
));
}

let matchings = [
("type", trait_own_counts.types, impl_own_counts.types),
("const", trait_own_counts.consts, impl_own_counts.consts),
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/async-await/in-trait/generics-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

trait Foo {
async fn foo<T>();
}

impl Foo for () {
async fn foo<const N: usize>() {}
//~^ ERROR: method `foo` has an incompatible generic parameter for trait `Foo` [E0053]
}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/async-await/in-trait/generics-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0053]: method `foo` has an incompatible generic parameter for trait `Foo`
--> $DIR/generics-mismatch.rs:11:18
|
LL | trait Foo {
| ---
LL | async fn foo<T>();
| - expected type parameter
...
LL | impl Foo for () {
| ---------------
LL | async fn foo<const N: usize>() {}
| ^^^^^^^^^^^^^^ found const parameter of type `usize`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0053`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters
--> $DIR/generics-mismatch.rs:11:12
--> $DIR/generics-mismatch.rs:14:12
|
LL | fn bar(&self) -> impl Sized;
| - expected 0 type parameters
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/impl-trait/in-trait/generics-mismatch.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters
--> $DIR/generics-mismatch.rs:14:12
|
LL | fn bar(&self) -> impl Sized;
| - expected 0 type parameters
...
LL | fn bar<T>(&self) {}
| ^ found 1 type parameter

error: aborting due to previous error

For more information about this error, try `rustc --explain E0049`.
3 changes: 3 additions & 0 deletions tests/ui/impl-trait/in-trait/generics-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

#![feature(return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]

Expand Down

0 comments on commit 6958548

Please sign in to comment.