Rust-clippy: should_implement_trait should not warn async methods

Created on 20 Jul 2019  路  3Comments  路  Source: rust-lang/rust-clippy

They are actually returning a different type than normal methods.

#![feature(async_await)]
#![warn(clippy::should_implement_trait)]

pub struct Foo;

impl Foo {
    // actual type: pub fn next(&mut self) -> impl Future<Output = Option<()>>
    pub async fn next(&mut self) -> Option<()> { //~ WARN: defining a method called `next` on this type; consider implementing the `std::iter::Iterator` trait or choosing a less ambiguous name
        unimplemented!()
    }
}

Playground

L-bug T-async-await good-first-issue

All 3 comments

The warning is mostly about the method name next. Since this is a style lint, I think it is totally fine, that the lint triggers here. Maybe calling the function next_async would be better here?

I kind of disagree, since the Stream trait actually also calls its method next(). If Stream was in std, this lint could refer to Stream, but as long as that's not the case, clippy would be better off not warning about this IMO (I've been hit by this multiple times and always just end up silencing the lint).

Was this page helpful?
0 / 5 - 0 ratings