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

type_alias_impl_trait: from_over_into does not apply #10983

Closed
matthiaskrgr opened this issue Jun 18, 2023 · 3 comments
Closed

type_alias_impl_trait: from_over_into does not apply #10983

matthiaskrgr opened this issue Jun 18, 2023 · 3 comments
Labels
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

Comments

@matthiaskrgr
Copy link
Member

Summary

.

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();
}
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: `#[warn(clippy::from_over_into)]` on by default
help: replace the `Into` implementation with `From<Foo>`
  |
7 ~ impl From<Foo> for T {
8 ~     fn from(val: Foo) -> Self {}
  |

warning: 1 warning emitted

the suggestion does not apply:

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.

Version

rustc 1.72.0-nightly (3b2073f07 2023-06-17)
binary: rustc
commit-hash: 3b2073f0762cff4d3d625bb10017e0ce4e7abe50
commit-date: 2023-06-17
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

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 labels Jun 18, 2023
@Alexendoo
Copy link
Member

I wondered how the Into would be allowed since it could also result in a T -> T conversion, turns out that ICEs so this behaviour may be subject to change

@compiler-errors
Copy link
Member

Yeah, this is afaict a coherence bug.

@Alexendoo
Copy link
Member

Original snippet now errors - rust-lang/rust#112780

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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants