Skip to content

Commit 88d7ea3

Browse files
Filter out RPITITs when suggesting unconstrained assoc type on too many generics
1 parent a6434ef commit 88d7ea3

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Diff for: compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+1
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
495495
.iter()
496496
.any(|constraint| constraint.ident.name == item.name)
497497
})
498+
.filter(|item| !item.is_impl_trait_in_trait())
498499
.map(|item| self.tcx.item_ident(item.def_id).to_string())
499500
.collect()
500501
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// There's a suggestion that turns `Iterator<u32>` into `Iterator<Item = u32>`
2+
// if we have more generics than the trait wants. Let's not consider RPITITs
3+
// for this, since that makes no sense right now.
4+
5+
trait Foo {
6+
fn bar(self) -> impl Sized;
7+
}
8+
9+
impl Foo<u8> for () {
10+
//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
11+
fn bar(self) -> impl Sized {}
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
2+
--> $DIR/dont-consider-unconstrained-rpitits.rs:9:6
3+
|
4+
LL | impl Foo<u8> for () {
5+
| ^^^---- help: remove the unnecessary generics
6+
| |
7+
| expected 0 generic arguments
8+
|
9+
note: trait defined here, with 0 generic parameters
10+
--> $DIR/dont-consider-unconstrained-rpitits.rs:5:7
11+
|
12+
LL | trait Foo {
13+
| ^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)