Skip to content

Wrong suggestion for variable initialization #120634

Closed
@bowenxieoregon

Description

@bowenxieoregon

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions