Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.
Loading