rust/tests/ui/traits/bound
Matthias Krüger bc0dfaa048
Rollup merge of #144801 - estebank:issue-144734, r=spastorino
Suggest bounds in more cases, accounting for type parameters referenced in predicate

Use a `ty::Visitor` to see if the failed predicate references a type parameter. If it does, then we only suggest adding a bound to an (associated) item only if the referenced parameter is present in its generics.

Provide adding bound suggestion in trait and impl associated functions in cases we previously weren't:

```
error[E0277]: `?` couldn't convert the error to `ApplicationError`
  --> $DIR/suggest-complex-bound-on-method.rs:18:16
   |
LL |         t.run()?;
   |           -----^ the trait `From<<T as Trait>::Error>` is not implemented for `ApplicationError`
   |           |
   |           this can't be annotated with `?` because it has type `Result<_, <T as Trait>::Error>`
   |
note: `ApplicationError` needs to implement `From<<T as Trait>::Error>`
  --> $DIR/suggest-complex-bound-on-method.rs:12:1
   |
LL | enum ApplicationError {
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
   |
LL |     fn thing<T: Trait>(&self, t: T) -> Result<(), ApplicationError> where ApplicationError: From<<T as Trait>::Error> {
   |                                                                     +++++++++++++++++++++++++++++++++++++++++++++++++
```

Fix rust-lang/rust#144734.
2025-09-06 13:03:15 +02:00
..
auxiliary
assoc-fn-bound-root-obligation.rs Remove detail from label/note that is already available in other note 2024-10-29 16:26:57 +00:00
assoc-fn-bound-root-obligation.stderr Remove detail from label/note that is already available in other note 2024-10-29 16:26:57 +00:00
basic.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
generic_trait.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
impl-comparison-duplicates.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
in-arc.rs compiletest: Add a //@ needs-threads directive 2024-03-06 12:35:07 -08:00
multiple.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
not-on-bare-trait-2021.rs Don't assume traits used as type are trait objs 2024-10-11 17:36:04 +02:00
not-on-bare-trait-2021.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
not-on-bare-trait.rs Account for multiple trait bounds in bare trait object suggestion 2024-01-03 18:59:42 +00:00
not-on-bare-trait.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
not-on-struct.rs
not-on-struct.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
on-structs-and-enums-in-fns.rs
on-structs-and-enums-in-fns.stderr
on-structs-and-enums-in-impls.rs
on-structs-and-enums-in-impls.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
on-structs-and-enums-locals.rs
on-structs-and-enums-locals.stderr Do not gather local all together at the beginning of typeck 2025-05-05 14:27:09 +00:00
on-structs-and-enums-rpass.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
on-structs-and-enums-static.rs Check statics' type in type_of. 2025-07-25 23:39:26 +00:00
on-structs-and-enums-static.stderr Check statics' type in type_of. 2025-07-25 23:39:26 +00:00
on-structs-and-enums-xc.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
on-structs-and-enums-xc.stderr
on-structs-and-enums-xc1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
on-structs-and-enums-xc1.stderr Do not gather local all together at the beginning of typeck 2025-05-05 14:27:09 +00:00
on-structs-and-enums.rs
on-structs-and-enums.stderr reword trait bound suggestion message to include the bounds 2024-12-07 21:26:20 +00:00
recursion.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
same-crate-name.rs compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
same-crate-name.stderr compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
sugar.rs
sugar.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
suggest-complex-bound-on-method.fixed Suggest bounds in more cases, accounting for type parameters referenced in predicate 2025-08-04 16:12:58 +00:00
suggest-complex-bound-on-method.rs Suggest bounds in more cases, accounting for type parameters referenced in predicate 2025-08-04 16:12:58 +00:00
suggest-complex-bound-on-method.stderr Suggest bounds in more cases, accounting for type parameters referenced in predicate 2025-08-04 16:12:58 +00:00
unknown-assoc-with-const-arg.rs Don't try and handle unfed type_of on anon consts 2024-12-03 23:39:51 +00:00
unknown-assoc-with-const-arg.stderr Don't try and handle unfed type_of on anon consts 2024-12-03 23:39:51 +00:00