Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
olegnn opened this issue Oct 20, 2019 · 0 comments · Fixed by #67010
Closed

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

olegnn opened this issue Oct 20, 2019 · 0 comments · Fixed by #67010
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@olegnn
Copy link
Contributor

olegnn commented Oct 20, 2019

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.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Oct 20, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this issue Dec 5, 2019
Accurately portray raw identifiers in error messages

When refering to or suggesting raw identifiers, refer to them with `r#`.

Fix rust-lang#65634.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Dec 5, 2019
Accurately portray raw identifiers in error messages

When refering to or suggesting raw identifiers, refer to them with `r#`.

Fix rust-lang#65634.
RalfJung added a commit to RalfJung/rust that referenced this issue Dec 5, 2019
Accurately portray raw identifiers in error messages

When refering to or suggesting raw identifiers, refer to them with `r#`.

Fix rust-lang#65634.
Centril added a commit to Centril/rust that referenced this issue Dec 5, 2019
Accurately portray raw identifiers in error messages

When refering to or suggesting raw identifiers, refer to them with `r#`.

Fix rust-lang#65634.
@bors bors closed this as completed in f6b435d Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants