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

invalid suggestion: self.field cannot be used with format args capture #98241

Closed
matthiaskrgr opened this issue Jun 18, 2022 · 2 comments · Fixed by #100058
Closed

invalid suggestion: self.field cannot be used with format args capture #98241

matthiaskrgr opened this issue Jun 18, 2022 · 2 comments · Fixed by #100058
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@matthiaskrgr
Copy link
Member

Given the following code:

struct A {
    foo: u32
}

impl A {
    fn func(&self) -> String {
        format!("{foo}")
    }
}

The current output is:

error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `foo` in this scope
 --> src/lib.rs:7:19
  |
7 |         format!("{foo}")
  |                   ^^^ help: you might have meant to use the available field: `self.foo`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground` due to previous error

Ideally the output should look like:

Note that {self.foo} is not accepted (yet..?) by the compiler, so we should suggest something like format!("{}", self.foo) I guess?

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 18, 2022
@JohnTitor JohnTitor added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Jun 19, 2022
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Jun 19, 2022

This is related to #97311.

@estebank
Copy link
Contributor

estebank commented Jul 7, 2022

CC #96999

If we fix that one, then we could close this one (as you'd be suggested the right thing after one additional error).

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 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.

4 participants