rust-lang/rust-clippy

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

Open

#4.894 aberto em 10 de dez. de 2019

Ver no GitHub
 (29 comments) (1 reaction) (0 assignees)Rust (1.391 forks)batch import
A-lintL-stylegood first issue

Métricas do repositório

Stars
 (10.406 stars)
Métricas de merge de PR
 (Mesclagem média 19d 22h) (113 fundiu PRs em 30d)

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?

Guia do colaborador