Skip to content

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

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

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