rust-lang/rust-clippy

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

Open

#4,894 建立於 2019年12月10日

在 GitHub 查看
 (29 留言) (1 反應) (0 負責人)Rust (1,391 fork)batch import
A-lintL-stylegood first issue

倉庫指標

Star
 (10,406 star)
PR 合併指標
 (平均合併 19天 22小時) (30 天內合併 113 個 PR)

描述

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?

貢獻者指南