Skip to content

Suggestion does not compile: use self with associated types #4140

Closed
@lopopolo

Description

@lopopolo
$ cargo clippy -V
clippy 0.0.212 (fc96aa03 2019-05-04)

I have two traits that have the same associated types that are shaped like From and TryFrom. I provide a default TryFrom implementation for types that implement From. Clippy suggests I modify the code below to replace the To::From and To::To references with Self::From and Self::To, which causes a recursive overflow.

pub trait FromMrb<T> {
    type From;
    type To;

    fn from_mrb(interp: &Mrb, value: T) -> Self;
}

pub trait TryFromMrb<T>
where
    Self: Sized,
{
    type From;
    type To;

    unsafe fn try_from_mrb(interp: &Mrb, value: T) -> Result<Self, Error<Self::From, Self::To>>;
}

impl<From, To> TryFromMrb<From> for To
where
    To: FromMrb<From>,
{
    type From = To::From;
    type To = To::To;

    unsafe fn try_from_mrb(interp: &Mrb, value: From) -> Result<Self, Error<Self::From, Self::To>> {
        Ok(FromMrb::from_mrb(interp, value))
    }
}
error: unnecessary structure name repetition
  --> mruby/src/convert.rs:50:17
   |
50 |     type From = To::From;
   |                 ^^ help: use the applicable keyword: `Self`
   |
note: lint level defined here
  --> mruby/src/lib.rs:1:22
   |
1  | #![deny(clippy::all, clippy::pedantic)]
   |                      ^^^^^^^^^^^^^^^^
   = note: #[deny(clippy::use_self)] implied by #[deny(clippy::pedantic)]
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

error: unnecessary structure name repetition
  --> mruby/src/convert.rs:51:15
   |
51 |     type To = To::To;
   |               ^^ help: use the applicable keyword: `Self`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions