rust-lang / rust-lang/rust-clippy

New lint: Use `Into`/`TryInto` in bounds as opposed to `From`/`TryFrom`

Open
#4,894 29 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When writing generic bounds such as:

fn foo<T>(a: T) where u32: From<T>;

Into should be preferred, like this:

fn foo<T>(a: T) where T: Into<u32>;

Why the former is bad: Into is a superset of From. In some cases coherence rules prevent implementing From but do allow implementing Into. As a result Into is more generic bound than From.

Category: Style, I guess?

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

Start with the generic-bound examples in the issue and inspect existing Rust Clippy lint implementations and tests for similar style checks. The work is complete when bounds using From or TryFrom are detected and the lint recommends the corresponding Into or TryInto form, with coverage for the examples shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.