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

FP from_over_into: type_alias_impl_trait #9935

Closed
matthiaskrgr opened this issue Nov 24, 2022 · 0 comments · Fixed by #9982
Closed

FP from_over_into: type_alias_impl_trait #9935

matthiaskrgr opened this issue Nov 24, 2022 · 0 comments · Fixed by #9982
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

from_over_into

Reproducer

I tried this code:

#![feature(type_alias_impl_trait)]

type T = impl Sized;

struct Foo;

impl Into<T> for Foo {
    fn into(self) -> T {}
}

fn main(){
    let _: T = Foo.into();
}

I saw this happen:
cargo clippy --fix -- -Aclippy::all -Wclippy::from_over_into

    Checking f v0.1.0 (/tmp/f)
warning: failed to automatically apply fixes suggested by rustc to crate `f`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0119]: conflicting implementations of trait `std::convert::From<T>` for type `T`
 --> src/main.rs:7:1
  |
7 | impl From<Foo> for T {
  | ^^^^^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `core`:
          - impl<T> std::convert::From<T> for T;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
Original diagnostics will follow.

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
 --> src/main.rs:7:1
  |
7 | impl Into<T> for Foo {
  | ^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
  = note: requested on the command line with `-W clippy::from-over-into`
help: replace the `Into` implentation with `From<Foo>`
  |
7 ~ impl From<Foo> for T {
8 ~     fn from(val: Foo) -> Self {}
  |

warning: `f` (bin "f") generated 1 warning (run `cargo fix --bin "f"` to apply 1 suggestion)
warning: `f` (bin "f" test) generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s

I expected to see this happen:

Version

No response

Additional Labels

No response

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels Nov 24, 2022
@bors bors closed this as completed in b43c9f7 Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant