mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 17:53:56 +00:00
6499eb5577
Detect when method call on argument could be removed to fulfill failed trait bound When encountering ```rust struct Foo; struct Bar; impl From<Bar> for Foo { fn from(_: Bar) -> Self { Foo } } fn qux(_: impl From<Bar>) {} fn main() { qux(Bar.into()); } ``` Suggest removing `.into()`: ``` error[E0283]: type annotations needed --> f100.rs:8:13 | 8 | qux(Bar.into()); | --- ^^^^ | | | required by a bound introduced by this call | = note: cannot satisfy `_: From<Bar>` note: required by a bound in `qux` --> f100.rs:6:16 | 6 | fn qux(_: impl From<Bar>) {} | ^^^^^^^^^ required by this bound in `qux` help: try using a fully qualified path to specify the expected types | 8 | qux(<Bar as Into<T>>::into(Bar)); | +++++++++++++++++++++++ ~ help: consider removing this method call, as the receiver has type `Bar` and `Bar: From<Bar>` trivially holds | 8 - qux(Bar.into()); 8 + qux(Bar); | ``` Fix #71252 |
||
---|---|---|
.. | ||
apit-unsized.rs | ||
apit-unsized.stderr | ||
argument-with-unnecessary-method-call.rs | ||
argument-with-unnecessary-method-call.stderr | ||
enum-unit-variant-trait-bound.rs | ||
enum-unit-variant-trait-bound.stderr | ||
impl-bound-with-references-error.rs | ||
impl-bound-with-references-error.stderr | ||
impl-derived-implicit-sized-bound-2.rs | ||
impl-derived-implicit-sized-bound-2.stderr | ||
impl-derived-implicit-sized-bound.rs | ||
impl-derived-implicit-sized-bound.stderr | ||
impl-missing-where-clause-lifetimes-from-trait.rs | ||
impl-missing-where-clause-lifetimes-from-trait.stderr | ||
issue-75961.rs | ||
issue-82038.rs | ||
issue-82038.stderr | ||
issue-93008.rs | ||
issue-94680.rs | ||
issue-94999.rs | ||
issue-95640.rs | ||
issue-119530-sugg-from-fn.rs | ||
issue-119530-sugg-from-fn.stderr | ||
mismatch-fn-trait.rs | ||
mismatch-fn-trait.stderr | ||
restrict-assoc-type-of-generic-bound.fixed | ||
restrict-assoc-type-of-generic-bound.rs | ||
restrict-assoc-type-of-generic-bound.stderr | ||
shadowed-path-in-trait-bound-suggestion.fixed | ||
shadowed-path-in-trait-bound-suggestion.rs | ||
shadowed-path-in-trait-bound-suggestion.stderr | ||
suggest-maybe-sized-bound.rs | ||
suggest-maybe-sized-bound.stderr | ||
unsized-bound.rs | ||
unsized-bound.stderr |