Skip to content

Incorrect help text when if and else differ by reference #82361

Closed
@isaacg1

Description

@isaacg1

I tried this code:

fn main() {
    if true {
        1
    } else {
        &1
    };
}  

I expected to see this happen: I expected that the help text would give syntactically correct code, or that there would be no help text.

Instead, this happened:

help: consider dereferencing the borrow
  |
4 |     } else *{
5 |         &1
6 |     };
  |

The provided code snippet is not valid - it tries to deference the else-block, which is impossible. Better would be to put the * inside the else-block.

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (83b30a639 2021-02-20)
binary: rustc
commit-hash: 83b30a639d5abd1270ade35d9bd92271f5a5ba18
commit-date: 2021-02-20
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Also occurs on stable, 1.50.0.

Metadata

Metadata

Assignees

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-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