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

cargo clippy failed to apply fixes #112502

Closed
wayhoww opened this issue Jun 10, 2023 · 3 comments · Fixed by rust-lang/rust-clippy#14409
Closed

cargo clippy failed to apply fixes #112502

wayhoww opened this issue Jun 10, 2023 · 3 comments · Fixed by rust-lang/rust-clippy#14409
Assignees
Labels
A-clippy Area: Clippy C-bug Category: This is a bug.

Comments

@wayhoww
Copy link

wayhoww commented Jun 10, 2023

I'm sorry, but I don't have enough knowledge to identify and solve this problem. I have searched existing issues, but I couldn't find any relevant reports (it's possible that there are too many issues to locate). Therefore, I am submitting this issue here according to the instructions in the error message.

Clippy: clippy 0.1.70 (90c5418 2023-05-31)
Rustc: rustc 1.70.0 (90c5418 2023-05-31)

Code

struct Type(i64);

impl Into<i64> for Type {
    fn into(self: Self) -> i64 {
        self.0
    }
}

fn main() {
    println!("Hello, world!");
}

Message

warning: failed to automatically apply fixes suggested by rustc to crate `test_clippy`

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: expected parameter name, found `:`
 --> src/main.rs:4:22
  |
4 |     fn from(val: Type: Self) -> Self {
  |                      ^ expected parameter name

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
 --> src/main.rs:4:22
  |
4 |     fn from(val: Type: Self) -> Self {
  |                      ^
  |                      |
  |                      expected one of 7 possible tokens
  |                      help: missing `,`

warning: consider choosing a more descriptive name
 --> src/main.rs:4:18
  |
4 |     fn from(val: Type: Self) -> Self {
  |                  ^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits
  = note: `#[warn(clippy::just_underscores_and_digits)]` on by default

error[E0050]: method `from` has 2 parameters but the declaration in trait `std::convert::From::from` has 1
 --> src/main.rs:4:18
  |
4 |     fn from(val: Type: Self) -> Self {
  |                  ^^^^^^^^^^ expected 1 parameter, found 2
  |
  = note: `from` from trait: `fn(T) -> Self`

error: aborting due to 3 previous errors; 1 warning emitted

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

warning: the type of the `self` parameter does not need to be arbitrary
 --> src/main.rs:4:13
  |
4 |     fn into(self: Self) -> i64 {
  |             ^^^^^^^^^^ help: consider to change this parameter to: `self`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type
  = note: `#[warn(clippy::needless_arbitrary_self_type)]` on by default

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
 --> src/main.rs:3:1
  |
3 | impl Into<i64> for Type {
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
          https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
  = 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` implentation with `From<Type>`
  |
3 ~ impl From<Type> for i64 {
4 ~     fn from(val: Type: Self) -> Self {
5 ~         val.0
  |

warning: `test_clippy` (bin "test_clippy") generated 2 warnings (1 duplicate) (run `cargo clippy --fix --bin "test_clippy"` to apply 1 suggestion)
warning: `test_clippy` (bin "test_clippy" test) generated 2 warnings (1 duplicate) (run `cargo clippy --fix --bin "test_clippy" --tests` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
@wayhoww wayhoww added the C-bug Category: This is a bug. label Jun 10, 2023
@Jules-Bertholet
Copy link
Contributor

@rustbot label A-clippy

@rustbot rustbot added the A-clippy Area: Clippy label Jun 10, 2023
@KonaeAkira
Copy link
Contributor

@rustbot claim

@KonaeAkira
Copy link
Contributor

KonaeAkira commented Mar 14, 2025

Issue also reproducible using self: Type instead of self: Self to avoid involving the needless_arbitrary_self_type lint, like so:

struct Type(i64);

impl Into<i64> for Type {
    fn into(self: Type) -> i64 {
        self.0
    }
}

github-merge-queue bot pushed a commit to rust-lang/rust-clippy that referenced this issue Mar 15, 2025
fixes [#112502](rust-lang/rust#112502)

changelog: [`from_over_into`]: fix invalid code suggestion when self
parameter has type annotation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-clippy Area: Clippy C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants