Skip to content

odd suggestion for comma typo #72253

Closed
@ehuss

Description

@ehuss

In an obscure situation with a typo (where there is a comma instead of a period), rustc will suggest replacing the comma with a semicolon, which will fail to compile.

let a = std::process::Command::new("echo")
    .arg("1")
    ,arg("2")
    .output();

Produces the following error and suggestion:

error: expected `;`, found ``,``
 --> src/main.rs:4:5
  |
4 |     ,arg("2")
  |     ^ help: change this to `;`: `;`

error[E0425]: cannot find function `arg` in this scope
 --> src/main.rs:4:6
  |
4 |     ,arg("2")
  |      ^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.

Some observations:

  • This must be a let binding.
  • The method calls must be on separate lines (all on one line gives a different error).

I would expect this to provide the same error if it is all on one line ("expected one of ., ;, ?, or an operator"), possibly with a "maybe incorrect" suggestion to replace it with a period (maybe only if the following character is not whitespace?).

Note: Feel free to close this. This is really obscure, and I suspect it is not trivial to change, and it is fairly obvious what is wrong. I just thought it was strange, and I was doubly puzzled that the indentation mattered.

Meta

rustc 1.45.0-nightly (9912925 2020-05-10)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions