Skip to content

Improve help message of from_over_into lint #7088

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
flip1995 opened this issue Apr 15, 2021 · 2 comments · Fixed by #7099
Closed

Improve help message of from_over_into lint #7088

flip1995 opened this issue Apr 15, 2021 · 2 comments · Fixed by #7099
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@flip1995
Copy link
Member

flip1995 commented Apr 15, 2021

impl Into<c_int> or Signal {
...
}

In this case [...] the fix is to change last impl to this:

impl From<Signal> for c_int {
...
}

It might be helpful if the recommendation actually printed the type so it was explicitly obvious (implied). Here is an example error:

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
   --> /mnt/host/source/src/platform/crosvm/sys_util/src/signal.rs:174:1
    |
174 | impl Into<c_int> for Signal {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: consider to implement `From` instead
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into

A better [help] message might look something like:

    = help: consider to implement `From<Signal>` instead

Originally posted by @Allen-Webb in #4894 (comment)

So the help message should at least mention the generic type that should be used. Maybe even produce an non-autoapplicable suggestion.

@flip1995 flip1995 added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions labels Apr 15, 2021
@Allen-Webb
Copy link

Just today I converted a few cases caught by the linter. One was even for a proc_macro. I think an autoapplicable suggestion might be possible but one hurdle would be coming up with an identifier $ident for the argument of from() that doesn't collide with any of the contents of the previous into(self) implementation. You would then replace self with $ident.

It seems like there may be some rare odd cases where From<> probably wouldn't be that useful such as for tuples that aren't given a named type and the developer might just silence the warning with an #[allow()], but even in those cases automatically converting them wouldn't be harmful.

Here are links the the gerrit CLs where I made the changes in case they are helpful cases when developing the help message:

@ABouttefeux
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants