Skip to content

"consider using a semicolon here" when ; is present with dbg!() inside inspect() #81943

Closed
@matthiaskrgr

Description

@matthiaskrgr
fn main() {
let sum: i32 = [1,2,3].iter().inspect(|n| dbg!(n) ).sum();
}

This will suggest adding a ;

error[E0308]: mismatched types
 --> src/main.rs:3:43
  |
3 | let sum: i32 = [1,2,3].iter().inspect(|n| dbg!(n) ).sum();
  |                                           ^^^^^^^
  |                                           |
  |                                           expected `()`, found `&&{integer}`
  |                                           expected this to be `()`
  |                                           help: consider using a semicolon here
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

But doing so will "break" the code even more and not fix the error:

error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> src/main.rs:2:50
 |
2 | let sum: i32 = [1,2,3].iter().inspect(|n| dbg!(n); ).sum();
 |                                                  ^ expected one of `)`, `,`, `.`, `?`, or an operator

error[E0308]: mismatched types
--> src/main.rs:2:43
 |
2 | let sum: i32 = [1,2,3].iter().inspect(|n| dbg!(n); ).sum();
 |                                           ^^^^^^^
 |                                           |
 |                                           expected `()`, found `&&{integer}`
 |                                           expected this to be `()`
 |                                           help: consider using a semicolon here
 |
 = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Could rust suggest adding { } around the macro?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`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