Skip to content

Suggest to directly use a value instead of wrapping the unwrapped value #99416

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

Closed
kellerkindt opened this issue Jul 18, 2022 · 0 comments · Fixed by #99593
Closed

Suggest to directly use a value instead of wrapping the unwrapped value #99416

kellerkindt opened this issue Jul 18, 2022 · 0 comments · Fixed by #99593
Assignees
Labels
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.

Comments

@kellerkindt
Copy link
Contributor

Given the following code: this

pub struct MyWrapper(u32);

fn main() {
    let value = MyWrapper(123);
    some_fn(value.0);
}

fn some_fn(wrapped: MyWrapper) {
    drop(wrapped);
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
 --> src/main.rs:6:13
  |
6 |     some_fn(value.0);
  |             ^^^^^^^ expected struct `MyWrapper`, found `u32`
  |
help: try wrapping the expression in `MyWrapper`
  |
6 |     some_fn(MyWrapper(value.0));
  |             ++++++++++       +

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

Ideally the output should look like:

Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
 --> src/main.rs:6:13
  |
6 |     some_fn(value.0);
  |             ^^^^^^^ expected struct `MyWrapper`, found `u32`
  |
help: try using `value` directly
  |
6 |     some_fn(value);
  |             +++++

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

Just encountered this as I was refactoring code to properly use my tuple struct instead of an raw integer identifier.

@kellerkindt kellerkindt 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 Jul 18, 2022
@kellerkindt kellerkindt changed the title Suggest to directly use an value instead of wrapping the unwrapped value Suggest to directly use a value instead of wrapping the unwrapped value Jul 18, 2022
@TaKO8Ki TaKO8Ki self-assigned this Jul 20, 2022
@bors bors closed this as completed in d89e99a Jul 26, 2022
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants