Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Hint suggesting using associated method instead of method uses incorrect syntax for generic method access #61412

Closed

Description

@daboross

Consider this example:

struct GenericAssocMethod<T>(T);
impl<T> GenericAssocMethod<T> {
    fn default_hello() {}
}

fn main() {
    let x = GenericAssocMethod(33i32);
    x.default_hello();
}

This errors with the following error:

error[E0599]: no method named `default_hello` found for type `GenericAssocMethod<i32>` in the current scope
 --> src/main.rs:8:7
  |
1 | struct GenericAssocMethod<T>(T);
  | -------------------------------- method `default_hello` not found for this
...
8 |     x.default_hello();
  |     --^^^^^^^^^^^^^
  |     | |
  |     | this is an associated function, not a method
  |     help: use associated function syntax instead: `GenericAssocMethod<i32>::default_hello`
  |
  = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in an impl for the type `GenericAssocMethod<_>`
 --> src/main.rs:3:5
  |
3 |     fn default_hello() {}
  |     ^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

The problem is that if I follow the hint exactly, I end up with GenericAssocMethod<i32>::default_hello();, which is invalid rust syntax.

Ideally, I believe suggesting GenericAssocMethod::<i32>::default_hello would be more beneficial.

Submitting this and #61411 as two separate issues, but I found both for the same hint.

Activity

  1. changed the title [-]Hint suggesting using associated method instead of method uses incorrect syntax for generic types[/-] [+]Hint suggesting using associated method instead of method uses incorrect syntax for generic method access[/+] on May 31, 2019
  2. added
    A-associated-items
    A-diagnostics
    A-suggestion-diagnostics
    C-enhancement
    on May 31, 2019
  3. added
    D-invalid-suggestion
    on Oct 5, 2019
  4. added 2 commits that reference this issue on Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsA-diagnosticsA-suggestion-diagnosticsC-enhancementD-invalid-suggestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions