rust/tests/ui/trait-bounds
León Orell Valerian Liehr 6499eb5577
Rollup merge of #121100 - estebank:issue-71252, r=compiler-errors
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
2024-02-18 05:10:16 +01:00
..
apit-unsized.rs
apit-unsized.stderr
argument-with-unnecessary-method-call.rs Detect when method call on argument could be removed to fulfill failed trait bound 2024-02-16 04:28:05 +00:00
argument-with-unnecessary-method-call.stderr Detect when method call on argument could be removed to fulfill failed trait bound 2024-02-16 04:28:05 +00:00
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 [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-82038.rs
issue-82038.stderr
issue-93008.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-94680.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-94999.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-95640.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
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 [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
restrict-assoc-type-of-generic-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
restrict-assoc-type-of-generic-bound.stderr
shadowed-path-in-trait-bound-suggestion.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
shadowed-path-in-trait-bound-suggestion.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
shadowed-path-in-trait-bound-suggestion.stderr
suggest-maybe-sized-bound.rs
suggest-maybe-sized-bound.stderr
unsized-bound.rs
unsized-bound.stderr