Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lolbinarycat opened this issue Jun 10, 2024 · 1 comment · Fixed by #126455
Closed

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

lolbinarycat opened this issue Jun 10, 2024 · 1 comment · Fixed by #126455
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link

lolbinarycat commented Jun 10, 2024

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

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 10, 2024
@jieyouxu jieyouxu added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Jun 10, 2024
@surechen
Copy link
Contributor

@rustbot claim

surechen added a commit to surechen/rust that referenced this issue Jun 14, 2024
surechen added a commit to surechen/rust that referenced this issue Jun 14, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jun 24, 2024
For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.

For [E0308]: mismatched types, when expr is in an arm's body, and it is the end expr without a semicolon of the block, not add semicolon ';' at the end of it.

fixes rust-lang#126222

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 24, 2024
For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.

For [E0308]: mismatched types, when expr is in an arm's body, and it is the end expr without a semicolon of the block, not add semicolon ';' at the end of it.

fixes rust-lang#126222

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
@bors bors closed this as completed in e8b5ba1 Jun 24, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 24, 2024
Rollup merge of rust-lang#126455 - surechen:fix_126222, r=estebank

For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.

For [E0308]: mismatched types, when expr is in an arm's body, and it is the end expr without a semicolon of the block, not add semicolon ';' at the end of it.

fixes rust-lang#126222

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants