rust-lang/rust-clippy

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

Open

#4.894 geöffnet am 10. Dez. 2019

Auf GitHub ansehen
 (29 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Rust (1.391 Forks)batch import
A-lintL-stylegood first issue

Repository-Metriken

Stars
 (10.406 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 22h) (113 gemergte PRs in 30 T)

Beschreibung

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