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 tweak suggestion for argument-position impl ?Sized 2023-06-15 12:00:57 +02:00
apit-unsized.stderr change std::marker::Sized to just Sized 2023-06-15 12:01:38 +02:00
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 Walk through full path in point_at_path_if_possible 2023-08-25 19:05:38 +00:00
enum-unit-variant-trait-bound.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
impl-bound-with-references-error.rs Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
impl-bound-with-references-error.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
impl-derived-implicit-sized-bound-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl-derived-implicit-sized-bound-2.stderr Use single label for method not found due to unmet bound 2024-01-26 20:47:19 +00:00
impl-derived-implicit-sized-bound.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl-derived-implicit-sized-bound.stderr Use single label for method not found due to unmet bound 2024-01-26 20:47:19 +00:00
impl-missing-where-clause-lifetimes-from-trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl-missing-where-clause-lifetimes-from-trait.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-75961.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-82038.rs diagnostics: add test case for trait bounds diagnostic 2023-09-07 11:36:23 -07:00
issue-82038.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
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 Suggest arry::from_fn for array initialization 2024-01-21 09:57:26 +08:00
issue-119530-sugg-from-fn.stderr Remove extra # from url 2024-01-24 00:41:45 +01:00
mismatch-fn-trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
mismatch-fn-trait.stderr Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
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 Show number in error message even for one error 2023-11-24 19:15:52 +01:00
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 Show number in error message even for one error 2023-11-24 19:15:52 +01:00
suggest-maybe-sized-bound.rs Fix suggestion span for ?Sized 2024-02-12 11:33:11 +09:00
suggest-maybe-sized-bound.stderr Fix suggestion span for ?Sized 2024-02-12 11:33:11 +09:00
unsized-bound.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unsized-bound.stderr review comment: change wording 2024-02-01 03:31:03 +00:00