rust/tests/ui/object-safety
Matthias Krüger f75a1954eb
Rollup merge of #127692 - veera-sivarajan:bugfix-125139, r=estebank
Suggest `impl Trait` for References to Bare Trait in Function Header

Fixes #125139

This PR suggests `impl Trait` when `&Trait` is found as a function parameter type or return type. This makes use of existing diagnostics by adding `peel_refs()` when checking for type equality.

Additionaly, it makes a few other improvements:
1. Checks if functions inside impl blocks have bare trait in their headers.
2. Introduces a trait `NextLifetimeParamName` similar to the existing `NextTypeParamName` for suggesting a lifetime name. Also, abstracts out the common logic between the two trait impls.

### Related Issues
I ran into a bunch of related diagnostic issues but couldn't fix them within the scope of this PR. So, I have created the following issues:
1. [Misleading Suggestion when Returning a Reference to a Bare Trait from a Function](https://github.com/rust-lang/rust/issues/127689)
2. [Verbose Error When a Function Takes a Bare Trait as Parameter](https://github.com/rust-lang/rust/issues/127690)
3. [Incorrect Suggestion when Returning a Bare Trait from a Function](https://github.com/rust-lang/rust/issues/127691)

r​? ```@estebank``` since you implemented  #119148
2024-09-03 19:13:23 +02:00
..
almost-supertrait-associated-type.rs Fix unsoundness when associated types dont actually come from supertraits 2024-07-15 14:17:32 -04:00
almost-supertrait-associated-type.stderr Fix unsoundness when associated types dont actually come from supertraits 2024-07-15 14:17:32 -04:00
assoc_const_bounds.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
assoc_const_bounds_sized.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
assoc_type_bounds.rs Detect object safety errors when assoc type is missing 2023-10-30 22:12:07 +00:00
assoc_type_bounds.stderr Detect object safety errors when assoc type is missing 2023-10-30 22:12:07 +00:00
assoc_type_bounds2.rs Detect object safety errors when assoc type is missing 2023-10-30 22:12:07 +00:00
assoc_type_bounds2.stderr Detect object safety errors when assoc type is missing 2023-10-30 22:12:07 +00:00
assoc_type_bounds_implicit_sized.fixed [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
assoc_type_bounds_implicit_sized.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
assoc_type_bounds_implicit_sized.stderr Update tests 2024-02-07 10:42:01 +08:00
assoc_type_bounds_sized.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
assoc_type_bounds_sized_others.rs Detect object safety errors when assoc type is missing 2023-10-30 22:12:07 +00:00
assoc_type_bounds_sized_others.stderr Detect object safety errors when assoc type is missing 2023-10-30 22:12:07 +00:00
assoc_type_bounds_sized_unnecessary.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
assoc_type_bounds_sized_unnecessary.stderr Fix remaining cases 2024-06-21 19:00:18 -04:00
assoc_type_bounds_sized_used.rs Do not require associated types with Self: Sized to uphold bounds when confirming object candidate 2023-09-02 05:08:38 +00:00
assoc_type_bounds_sized_used.stderr Suggest relaxing implicit `type Assoc: Sized;` bound 2023-10-19 00:07:16 +00:00
avoid-ice-on-warning-2.new.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
avoid-ice-on-warning-2.old.stderr Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errors 2024-02-14 18:32:19 +00:00
avoid-ice-on-warning-2.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
avoid-ice-on-warning-3.new.stderr Avoid ICE in trait without `dyn` lint 2024-01-29 18:33:52 +00:00
avoid-ice-on-warning-3.old.stderr Be less confident when `dyn` suggestion is not checked for object safety 2024-02-09 20:47:50 -08:00
avoid-ice-on-warning-3.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
avoid-ice-on-warning.new.stderr Make parse error suggestions verbose and fix spans 2024-07-12 03:02:57 +00:00
avoid-ice-on-warning.old.stderr Make parse error suggestions verbose and fix spans 2024-07-12 03:02:57 +00:00
avoid-ice-on-warning.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
bare-trait-dont-suggest-dyn.new.fixed tests/ui: remove workaround for broken revisioned run-rustfix test 2024-04-07 17:06:15 +00:00
bare-trait-dont-suggest-dyn.new.stderr tests/ui: remove workaround for broken revisioned run-rustfix test 2024-04-07 17:06:15 +00:00
bare-trait-dont-suggest-dyn.old.stderr tests/ui: remove workaround for broken revisioned run-rustfix test 2024-04-07 17:06:15 +00:00
bare-trait-dont-suggest-dyn.rs tests/ui: remove workaround for broken revisioned run-rustfix test 2024-04-07 17:06:15 +00:00
call-when-assoc-ty-is-sized.rs Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
erroneous_signature.rs Don't ICE when deducing future output if other errors already occurred 2024-01-17 16:27:57 +00:00
erroneous_signature.stderr Don't ICE when deducing future output if other errors already occurred 2024-01-17 16:27:57 +00:00
issue-19538.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-19538.stderr On object safety error, mention new enum as alternative 2023-10-29 23:55:46 +00:00
issue-102762.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
issue-102762.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
issue-102933.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
issue-106247.rs Make WHERE_CLAUSES_OBJECT_SAFETY a regular object safety violation 2024-06-03 09:49:04 -04:00
item-bounds-can-reference-self.rs Item bounds can reference self projections and still be object safe 2024-07-15 14:16:48 -04:00
object-safety-associated-consts.curr.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-associated-consts.object_safe_for_dispatch.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
object-safety-associated-consts.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-bounds.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
object-safety-bounds.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
object-safety-by-value-self-use.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
object-safety-by-value-self-use.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
object-safety-by-value-self.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-generics.curr.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-generics.object_safe_for_dispatch.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-generics.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-issue-22040.rs Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-issue-22040.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-mentions-Self.curr.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-mentions-Self.object_safe_for_dispatch.stderr Note base types of coercion 2023-05-12 00:10:52 +00:00
object-safety-mentions-Self.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-no-static.curr.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-no-static.object_safe_for_dispatch.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
object-safety-no-static.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-phantom-fn.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-sized-2.curr.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-sized-2.object_safe_for_dispatch.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
object-safety-sized-2.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-sized.curr.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-sized.object_safe_for_dispatch.stderr Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
object-safety-sized.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
object-safety-supertrait-mentions-GAT.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
object-safety-supertrait-mentions-GAT.stderr always show and explain sub region 2023-10-08 09:59:51 +00:00
object-safety-supertrait-mentions-Self.rs Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
object-safety-supertrait-mentions-Self.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs Suggest `impl Trait` for References to Bare Trait in Function Header 2024-08-19 15:19:43 -04:00
reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr Suggest `impl Trait` for References to Bare Trait in Function Header 2024-08-19 15:19:43 -04:00