Skip to content

Incorrect compiler hints for traits with methods defined using raw identifiers #65634

Closed

Description

@olegnn

Code:

#![allow(non_camel_case_types)]

trait r#async {
    fn r#struct(&self) {
        println!("async");
    }
}

trait r#await {
    fn r#struct(&self) {
        println!("await");
    }
}

struct r#fn {}

impl r#async for r#fn {}
impl r#await for r#fn {}

fn main() {
    r#fn {}.r#struct();
}

(Playground)

Error:

error[E0034]: multiple applicable items in scope
  --> src/main.rs:22:13
   |
22 |     r#fn {}.r#struct();
   |             ^^^^^^^^ multiple `struct` found
   |
note: candidate #1 is defined in an impl of the trait `async` for the type `fn`
  --> src/main.rs:5:5
   |
5  |     fn r#struct(&self) {
   |     ^^^^^^^^^^^^^^^^^^
   = help: to disambiguate the method call, write `async::struct(r#fn {})` instead
note: candidate #2 is defined in an impl of the trait `await` for the type `fn`
  --> src/main.rs:11:5
   |
11 |     fn r#struct(&self) {
   |     ^^^^^^^^^^^^^^^^^^
   = help: to disambiguate the method call, write `await::struct(r#fn {})` instead

async::struct(r#fn {}) should be r#async::r#struct(&r#fn {})and await::struct(r#fn {}) should be r#await::r#struct(&r#fn {}). It also misses that function signatures require not self but &self, however this also happens when not using raw identifiers, so I will open another issue for this case.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    C-bugCategory: This is a bug.
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
    and removed
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    on Oct 20, 2019
  2. added a commit that references this issue on Dec 4, 2019
    f6b435d
  3. added 2 commits that reference this issue on Dec 5, 2019
    89931eb
    2750309
  4. added a commit that references this issue on Dec 5, 2019
    36a1303
  5. added a commit that references this issue on Dec 5, 2019
    8e6cf86
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-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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