Skip to content

Commit c0b5720

Browse files
committed
Fix generics mismatch errors for RPITITs on -Zlower-impl-trait-in-trait-to-assoc-ty
1 parent e386217 commit c0b5720

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+11
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),

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

+1-1
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
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

+3
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)