Skip to content

"no method found for type parameter" missing generic args #132407

Closed
@lcnr

Description

@lcnr

Code

trait Trait<I> {
    fn method(&self) {}
}

fn foo<T>(value: T) {
    value.method()
}

Current output

error[E0599]: no method named `method` found for type parameter `T` in the current scope
 --> src/lib.rs:6:11
  |
5 | fn foo<T>(value: T) {
  |        - method `method` not found for this type parameter
6 |     value.method()
  |           ^^^^^^ method not found in `T`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `T` with it:
  |
5 | fn foo<T: Trait>(value: T) {
  |         +++++++

Desired output

error[E0599]: no method named `method` found for type parameter `T` in the current scope
 --> src/lib.rs:6:11
  |
5 | fn foo<T>(value: T) {
  |        - method `method` not found for this type parameter
6 |     value.method()
  |           ^^^^^^ method not found in `T`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `T` with it:
  |
5 | fn foo<T: Trait<_>>(value: T) {
  |         ++++++++++

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions