Filter out RPITITs when suggesting unconstrained assoc type on too many generics

This commit is contained in:
Michael Goulet 2025-01-30 18:39:08 +00:00
parent a6434ef9c0
commit 88d7ea36e9
3 changed files with 32 additions and 0 deletions

View File

@ -495,6 +495,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
.iter()
.any(|constraint| constraint.ident.name == item.name)
})
.filter(|item| !item.is_impl_trait_in_trait())
.map(|item| self.tcx.item_ident(item.def_id).to_string())
.collect()
} else {

View File

@ -0,0 +1,14 @@
// There's a suggestion that turns `Iterator<u32>` into `Iterator<Item = u32>`
// if we have more generics than the trait wants. Let's not consider RPITITs
// for this, since that makes no sense right now.
trait Foo {
fn bar(self) -> impl Sized;
}
impl Foo<u8> for () {
//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
fn bar(self) -> impl Sized {}
}
fn main() {}

View File

@ -0,0 +1,17 @@
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/dont-consider-unconstrained-rpitits.rs:9:6
|
LL | impl Foo<u8> for () {
| ^^^---- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
note: trait defined here, with 0 generic parameters
--> $DIR/dont-consider-unconstrained-rpitits.rs:5:7
|
LL | trait Foo {
| ^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0107`.