Skip to content

"you might have meant to return this value" suggests invalid syntax #126222

Closed

Description

Code

fn dothing() -> i32 {
    match 5 {
        x => dbg!(x),
    }
    todo!()
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:3:14
  |
3 |         x => dbg!(x),
  |              ^^^^^^^ expected `()`, found integer
  |
  = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have meant to return this value
  |
3 |         x => return dbg!(x);,
  |              ++++++        +

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:3:14
  |
3 |         x => dbg!(x),
  |              ^^^^^^^ expected `()`, found integer
  |
  = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have meant to return this value
  |
3 |         x => return dbg!(x),
  |              ++++++        

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

Rationale and extra context

when using #![feature(rustc_private)] i even got this suggestion recommending i return DefKind from the GlobalCtxt::enter closure, which isn't even remotely the right type. it also seems to only show up when using macros? all around quite strange.

Other cases

No response

Rust Version

rustc 1.81.0-nightly (a70b2ae57 2024-06-09)
binary: rustc
commit-hash: a70b2ae57713ed0e7411c059d582ab382fc4166a
commit-date: 2024-06-09
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

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