Skip to content

Commit 814d317

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

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

Lines changed: 1 addition & 0 deletions
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 {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
12+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0412]: cannot find type `Bar` in this scope
2+
--> $DIR/dont-consider-unconstrained-rpitits.rs:9:18
3+
|
4+
LL | impl Foo<u8> for Bar {}
5+
| ^^^ not found in this scope
6+
7+
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
8+
--> $DIR/dont-consider-unconstrained-rpitits.rs:9:6
9+
|
10+
LL | impl Foo<u8> for Bar {}
11+
| ^^^---- help: remove the unnecessary generics
12+
| |
13+
| expected 0 generic arguments
14+
|
15+
note: trait defined here, with 0 generic parameters
16+
--> $DIR/dont-consider-unconstrained-rpitits.rs:5:7
17+
|
18+
LL | trait Foo {
19+
| ^^^
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0107, E0412.
24+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)