Skip to content

Wrong suggestion for variable initialization #120634

New issue

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

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

Already on GitHub? # to your account

Closed
bowenxieoregon opened this issue Feb 4, 2024 · 1 comment · Fixed by #120646
Closed

Wrong suggestion for variable initialization #120634

bowenxieoregon opened this issue Feb 4, 2024 · 1 comment · Fixed by #120646
Assignees
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

@bowenxieoregon
Copy link

bowenxieoregon commented Feb 4, 2024

Code

struct Struct {
    e: i32
}

fn main() {
    let (a, b , c , d , e);

    let _f: i32;

    // (a, b) = (1, 2);
    // [c, .., d, _] = [1, 2, 3, 4, 5];
    // Struct { e, .. } = Struct { e: 5 };

    assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]);
}

Current output

--> src/main.rs:14:34
   |
6  |     let (a , b , c , d , e);
   |          - binding declared here but left uninitialized
...
14 |     assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]);
   |                                  ^ `a` used here but it isn't initialized
   |
help: consider assigning a value
   |
6  |     let (a = 0 , b , c , d , e);
   |            +++

Desired output

the suggestion: let (a = 0 , b , c , d , e); is contrary to Rust syntax.

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: aarch64-apple-darwin
release: 1.74.1
LLVM version: 17.0.4

Anything else?

No response

@bowenxieoregon bowenxieoregon 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 4, 2024
@clubby789 clubby789 self-assigned this Feb 4, 2024
@trevyn
Copy link
Contributor

trevyn commented Feb 4, 2024

fn main() {
    let (a, );
    let _b: u8 = a;
}

@rustbot label +D-invalid-suggestion

@rustbot rustbot added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Feb 4, 2024
@bors bors closed this as completed in 80549a8 Mar 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 1, 2024
Rollup merge of rust-lang#120646 - clubby789:uninit-destructuring-sugg, r=michaelwoerister

Fix incorrect suggestion for uninitialized binding in pattern

Fixes rust-lang#120634
# for free to join this conversation on GitHub. Already have an account? # 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