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

Incorrect hint when calling associated method as method with Deref #61411

Closed

Description

@daboross

Here's a simple example:

use std::cell::RefCell;

struct HasAssocMethod;

impl HasAssocMethod {
    fn hello() {}
}
fn main() {
    let shared_state = RefCell::new(HasAssocMethod);
    
    let state = shared_state.borrow_mut();
    
    state.hello();
}

(playground)

This outputs the following error:

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `hello` found for type `std::cell::RefMut<'_, HasAssocMethod>` in the current scope
  --> src/main.rs:13:11
   |
13 |     state.hello();
   |     ------^^^^^
   |     |     |
   |     |     this is an associated function, not a method
   |     help: use associated function syntax instead: `std::cell::RefMut<'_, HasAssocMethod>::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 `HasAssocMethod`
  --> src/main.rs:6:5
   |
6  |     fn hello() {}
   |     ^^^^^^^^^^

error: aborting due to previous error

The hint is incorrect, as std::cell::RefMut<'_, HasAssocMethod>::hello(); does not exist. Ideally the compiler should suggest HasAssocMethod::hello();.

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

Activity

  1. added
    A-associated-items
    A-diagnostics
    A-suggestion-diagnostics
    C-bug
    on May 31, 2019
  2. added
    D-invalid-suggestion
    on Oct 5, 2019
  3. 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-bugD-invalid-suggestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions