rust-lang / rust-lang/rust-clippy

Warn on dyn AsyncTrait + Unpin

Open
#7,603 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

This lint will detect usage of dyn AsyncTrait + Unpin for various different choices for AsyncTrait. It should also trigger when a + Send is added.

The suggested replacement should be Pin<Box<dyn AsyncTrait>>. This is strictly more powerful than the + Unpin version.

The lint should at least apply to these traits: Future, Stream, AsyncRead, AsyncWrite. It might even make sense to apply it to all traits.

Categories (optional)
  • Kind: style

The advantage is that changing the type like this allows storing non-Unpin types in the trait object.

Drawbacks

None.

Example
use futures::stream::Stream;

fn new_stream() -> Box<dyn Stream<Item = i32> + Unpin> {
    Box::new(futures::stream::iter(vec![1, 2, 3]))
}

Could be written as:

use futures::stream::Stream;

fn new_stream() -> Pin<Box<dyn Stream<Item = i32>>> {
    Box::pin(futures::stream::iter(vec![1, 2, 3]))
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the Rust examples in the issue and determine the lint's supported scope: at least Future, Stream, AsyncRead, and AsyncWrite, with + Send handled too. Done means detecting the shown dyn forms and suggesting Pin<Box<dyn ...>>; the issue names no source file or test, so repository navigation and test discovery are required.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.