rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.93k stars 12.78k forks source link

Typo suggestion doesn't account for types #71040

Open jerryajay opened 4 years ago

jerryajay commented 4 years ago

When using multiple transmitters with a single receiver across multiple thread, the :help message is totally bonkers. Refer the backtrace lines 10 and 16:

use std::sync::mpsc::channel;
use std::thread;

fn main() {
    let (tx1, rx) = channel();
    let tx2 = tx1.clone();

    thread::spawn(move || {
        for i in 1..10 {
            tx.send(i);
        }
    });

    thread::spawn(move || {
        for i in 1..10 {
            tx.send(i);
        }
    });

    for i in 1..10 {
        println!("{}", rx.recv().unwrap());
    }
}

The auto-fix seems to be too ambitious at the moment by suggesting wrong fixes. Let me know if I need to file a RFC for this. JAVA's auto-fix seems smarter and Rust can definitely borrow some of it's implementation.

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

``` Compiling hello_world v0.1.0 (/home/jerry/rust-experiment/hello_world) error[E0425]: cannot find value `tx` in this scope --> src/main.rs:10:13 | 10 | tx.send(i); | ^^ help: a local variable with a similar name exists: `rx` error[E0425]: cannot find value `tx` in this scope --> src/main.rs:16:13 | 16 | tx.send(i); | ^^ help: a local variable with a similar name exists: `rx` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0425`. error: could not compile `hello_world`. To learn more, run the command again with --verbose. ```

LeSeulArtichaut commented 4 years ago

@rustbot modify labels: +A-diagnostics +C-enhancement -C-bug