rust-lang/rust-clippy

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

Open

#4894 aperta il 10 dic 2019

Vedi su GitHub
 (29 commenti) (1 reazione) (0 assegnatari)Rust (1391 fork)batch import
A-lintL-stylegood first issue

Metriche repository

Star
 (10.406 star)
Metriche merge PR
 (Merge medio 19g 22h) (113 PR mergiate in 30 g)

Descrizione

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?

Guida contributor