Skip to content

Compiler suggests invalid syntax when identfier used in format is not available #121507

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

Closed
WojciechMula opened this issue Feb 23, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WojciechMula
Copy link

Code

struct Foo {
    foo: String,
}

impl Foo {
    fn dump(self) {
        println!("foo = {foo:?}")
    }
}

mod inner {
    fn foo() {}
}

Current output

error[E0425]: cannot find value `foo` in this scope
  --> src/lib.rs:7:26
   |
7  |         println!("foo = {foo:?}")
   |                          ^^^
   |
note: function `crate::inner::foo` exists but is inaccessible
  --> src/lib.rs:12:5
   |
12 |     fn foo() {}
   |     ^^^^^^^^ not accessible
help: you might have meant to use the available field
   |
7  |         println!("foo = {self.foo:?}")
   |                          +++++

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

Desired output

No response

Rationale and extra context

The hint println!("foo = {self.foo:?}") is not a valid code. In this case I'd expect to see either println("foo = {0:?}", self.foo) or no hint at all.

Other cases

No response

Rust Version

Link to the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c4d9e1a3e44b73f3e75bcc28014f25b1
Checked with both stable 1.76 and nightly 1.78.

Anything else?

No response

@WojciechMula WojciechMula 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 Feb 23, 2024
@jieyouxu jieyouxu added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Feb 23, 2024
@fmease
Copy link
Member

fmease commented Feb 24, 2024

Closing as duplicate of #105520.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2024
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-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants