Skip to content

FP from_over_into: type_alias_impl_trait #9935

Closed

Description

@matthiaskrgr

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

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    on Nov 24, 2022
  2. added a commit that references this issue on Dec 2, 2022
    b43c9f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions