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

Auto-fix wrongly suggesting scope issues during struct manipulations #71027

Open
jerryajay opened this issue Apr 11, 2020 · 2 comments
Open

Auto-fix wrongly suggesting scope issues during struct manipulations #71027

jerryajay opened this issue Apr 11, 2020 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jerryajay
Copy link

jerryajay commented Apr 11, 2020

Hi, there's a auto-fix bug. I'm using VSCode. The code explains itself:

I tried this code:

use std::fmt;
use std::fmt::Error;
use std::fmt::Formatter;

struct Structure(i32);

#[derive(Debug)]
struct Point {
    x : i32,
    y : i32,
}

impl fmt::Display for Structure {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        write!(f, "The value inside the structure is: {}", self.0)
    }
}


fn main() {
    let s = Structure(12);
    println!("{}", s);
    let point = {x = 12; y = 45};
    println!("{}")
}

I expected to see the auto-fix suggest ways to print Point correctly.

Instead, auto-fix in VSCode suggests changing x and y to s in line 23.
However, the error message from rust displays fine.

Meta

rustc --version --verbose:

rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-unknown-linux-gnu
release: 1.42.0
LLVM version: 9.0
Backtrace

RUST_BACKTRACE=1 cargo build
   Compiling hello_world v0.1.0 (/home/jerry/rust-experiment/hello_world)
error: 1 positional argument in format string, but no arguments were given
  --> src/main.rs:26:15
   |
26 |     println!("{}")
   |               ^^

error[E0425]: cannot find value `x` in this scope
  --> src/main.rs:23:9
   |
23 |         x = 12;
   |         ^ help: a local variable with a similar name exists: `s`

error[E0425]: cannot find value `y` in this scope
  --> src/main.rs:24:9
   |
24 |         y = 45;
   |         ^ help: a local variable with a similar name exists: `s`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0425`.
error: could not compile `hello_world`.

@jerryajay jerryajay added the C-bug Category: This is a bug. label Apr 11, 2020
@jonas-schievink
Copy link
Contributor

It's not really clear what this issue is about. Are you using RLS? I'm assuming it's displaying the suggestions in this error message?

error[E0425]: cannot find value `x` in this scope
  --> src/main.rs:23:18
   |
23 |     let point = {x = 12; y = 45};
   |                  ^ help: a local variable with a similar name exists: `s`

If so, that is definitely a correct error message and help, even if the result is not what you wanted (help is only a suggestion, not a solution, after all).

Maybe we can add extra diagnostics for syntax that looks like a C struct initializer, but I don't think too many people hit this.

@jerryajay
Copy link
Author

Yes, RLS is being used. Rust is powerful for a blatant help message like this. I'll submit a pull request for the extra diagnostics - time permitting.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Apr 11, 2020
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

2 participants