rust/tests/ui/methods
Matthias Krüger 35f6eee51a
Rollup merge of #121826 - estebank:e0277-root-obligation-2, r=oli-obk
Use root obligation on E0277 for some cases

When encountering trait bound errors that satisfy some heuristics that tell us that the relevant trait for the user comes from the root obligation and not the current obligation, we use the root predicate for the main message.

This allows to talk about "X doesn't implement Pattern<'_>" over the most specific case that just happened to fail, like  "char doesn't implement Fn(&mut char)" in
`tests/ui/traits/suggest-dereferences/root-obligation.rs`

The heuristics are:

 - the type of the leaf predicate is (roughly) the same as the type from the root predicate, as a proxy for "we care about the root"
 - the leaf trait and the root trait are different, so as to avoid talking about `&mut T: Trait` and instead remain talking about `T: Trait` instead
 - the root trait is not `Unsize`, as to avoid talking about it in `tests/ui/coercion/coerce-issue-49593-box-never.rs`.

```
error[E0277]: the trait bound `&char: Pattern<'_>` is not satisfied
  --> $DIR/root-obligation.rs:6:38
   |
LL |         .filter(|c| "aeiou".contains(c))
   |                             -------- ^ the trait `Fn<(char,)>` is not implemented for `&char`, which is required by `&char: Pattern<'_>`
   |                             |
   |                             required by a bound introduced by this call
   |
   = note: required for `&char` to implement `FnOnce<(char,)>`
   = note: required for `&char` to implement `Pattern<'_>`
note: required by a bound in `core::str::<impl str>::contains`
  --> $SRC_DIR/core/src/str/mod.rs:LL:COL
help: consider dereferencing here
   |
LL |         .filter(|c| "aeiou".contains(*c))
   |                                      +
```

Fix #79359, fix #119983, fix #118779, cc #118415 (the suggestion needs to change), cc #121398 (doesn't fix the underlying issue).
2024-03-05 06:40:31 +01:00
..
auxiliary
issues Be more lax in .into_iter() suggestion when encountering Iterator methods on non-Iterator 2024-03-03 18:53:36 +00:00
assign-to-method.rs Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
assign-to-method.stderr
call_method_unknown_pointee.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
call_method_unknown_pointee.stderr
disambiguate-associated-function-first-arg.rs fix broken CI and code review 2023-12-27 15:47:57 +08:00
disambiguate-associated-function-first-arg.stderr fix broken CI and code review 2023-12-27 15:47:57 +08:00
disambiguate-multiple-blanket-impl.rs Unify suggestion wording 2023-10-17 17:33:55 +00:00
disambiguate-multiple-blanket-impl.stderr Rework print_disambiguation_help 2023-11-07 05:23:09 +00:00
disambiguate-multiple-impl.rs Unify suggestion wording 2023-10-17 17:33:55 +00:00
disambiguate-multiple-impl.stderr Rework print_disambiguation_help 2023-11-07 05:23:09 +00:00
disambiguate-multiple-trait-2.rs Unify suggestion wording 2023-10-17 17:33:55 +00:00
disambiguate-multiple-trait-2.stderr Rework print_disambiguation_help 2023-11-07 05:23:09 +00:00
disambiguate-multiple-trait.rs Unify suggestion wording 2023-10-17 17:33:55 +00:00
disambiguate-multiple-trait.stderr Rework print_disambiguation_help 2023-11-07 05:23:09 +00:00
field-method-suggestion-using-return-ty.rs
field-method-suggestion-using-return-ty.stderr
inherent-bound-in-probe.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
inherent-bound-in-probe.stderr
issue-3707.rs
issue-3707.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-7950.rs Move tests 2024-03-03 16:30:48 -03:00
issue-7950.stderr Move tests 2024-03-03 16:30:48 -03:00
issue-19521.rs Move tests 2024-03-03 16:30:48 -03:00
issue-19521.stderr Move tests 2024-03-03 16:30:48 -03:00
method-ambig-one-trait-unknown-int-type.rs
method-ambig-one-trait-unknown-int-type.stderr
method-ambig-two-traits-cross-crate.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-ambig-two-traits-cross-crate.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ambig-two-traits-from-bounds.rs
method-ambig-two-traits-from-bounds.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ambig-two-traits-from-impls2.rs
method-ambig-two-traits-from-impls2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ambig-two-traits-from-impls.rs
method-ambig-two-traits-from-impls.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ambig-two-traits-with-default-method.rs
method-ambig-two-traits-with-default-method.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ambiguity-no-rcvr.rs Don't expect a rcvr in print_disambiguation_help 2023-11-12 19:59:13 +00:00
method-ambiguity-no-rcvr.stderr fix broken CI and code review 2023-12-27 15:47:57 +08:00
method-argument-inference-associated-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-call-err-msg.rs
method-call-err-msg.stderr Account for non-overlapping unmet trait bounds in suggestion 2024-01-30 19:26:13 +00:00
method-call-lifetime-args-fail.rs
method-call-lifetime-args-fail.stderr
method-call-lifetime-args-lint-fail.rs
method-call-lifetime-args-lint-fail.stderr
method-call-lifetime-args-lint.rs
method-call-lifetime-args-lint.stderr
method-call-lifetime-args-subst-index.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-call-lifetime-args-unresolved.rs
method-call-lifetime-args-unresolved.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-call-lifetime-args.rs
method-call-lifetime-args.stderr
method-call-type-binding.rs
method-call-type-binding.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-deref-to-same-trait-object-with-separate-params.rs
method-deref-to-same-trait-object-with-separate-params.stderr Rework print_disambiguation_help 2023-11-07 05:23:09 +00:00
method-early-bound-lifetimes-on-self.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-lookup-order.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-macro-backtrace.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-macro-backtrace.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-missing-call.rs
method-missing-call.stderr
method-mut-self-modifies-mut-slice-lvalue.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-normalize-bounds-issue-20604.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-not-found-but-doc-alias.rs
method-not-found-but-doc-alias.stderr Deduplicate some logic and reword output 2024-02-22 18:05:28 +00:00
method-not-found-generic-arg-elision.rs
method-not-found-generic-arg-elision.stderr
method-on-ambiguous-numeric-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-on-ambiguous-numeric-type.stderr macro_rules: Preserve all metavariable spans in a global side table 2024-02-18 11:19:24 +03:00
method-path-in-pattern.rs
method-path-in-pattern.stderr
method-probe-no-guessing-dyn-trait.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-projection.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-recursive-blanket-impl.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-recursive-blanket-impl.stderr Update tests 2024-02-07 10:42:01 +08:00
method-resolvable-path-in-pattern.rs
method-resolvable-path-in-pattern.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-self-arg-1.rs
method-self-arg-1.stderr
method-self-arg-2.rs
method-self-arg-2.stderr
method-self-arg-aux1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-self-arg-aux2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-self-arg-trait.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-self-arg.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-trait-object-with-hrtb.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-two-trait-defer-resolution-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-two-trait-defer-resolution-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-two-trait-defer-resolution-2.stderr Update tests 2024-02-07 10:42:01 +08:00
method-two-traits-distinguished-via-where-clause.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
method-two-traits-distinguished-via-where-clause.stderr Update tests 2024-02-07 10:42:01 +08:00
method-where-clause.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
suggest-method-on-call-with-macro-rcvr.rs
suggest-method-on-call-with-macro-rcvr.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00