rust/tests/ui/self
Adrian Taylor 6d8d79595e Reject generic self types.
The RFC for arbitrary self types v2 declares that we should reject
"generic" self types. This commit does so.

The definition of "generic" was unclear in the RFC, but has been
explored in
https://github.com/rust-lang/rust/issues/129147
and the conclusion is that "generic" means any `self` type which
is a type parameter defined on the method itself, or references
to such a type.

This approach was chosen because other definitions of "generic"
don't work. Specifically,
* we can't filter out generic type _arguments_, because that would
  filter out Rc<Self> and all the other types of smart pointer
  we want to support;
* we can't filter out all type params, because Self itself is a
  type param, and because existing Rust code depends on other
  type params declared on the type (as opposed to the method).

This PR decides to make a new error code for this case, instead of
reusing the existing E0307 error. This makes the code a
bit more complex, but it seems we have an opportunity to provide
specific diagnostics for this case so we should do so.

This PR filters out generic self types whether or not the
'arbitrary self types' feature is enabled. However, it's believed
that it can't have any effect on code which uses stable Rust, since
there are no stable traits which can be used to indicate a valid
generic receiver type, and thus it would have been impossible to
write code which could trigger this new error case.
It is however possible that this could break existing code which
uses either of the unstable `arbitrary_self_types` or
`receiver_trait` features. This breakage is intentional; as
we move arbitrary self types towards stabilization we don't want
to continue to support generic such types.

This PR adds lots of extra tests to arbitrary-self-from-method-substs.
Most of these are ways to trigger a "type mismatch" error which
9b82580c73/compiler/rustc_hir_typeck/src/method/confirm.rs (L519)
hopes can be minimized by filtering out generics in this way.
We remove a FIXME from confirm.rs suggesting that we make this change.
It's still possible to cause type mismatch errors, and a subsequent
PR may be able to improve diagnostics in this area, but it's harder
to cause these errors without contrived uses of the turbofish.

This is a part of the arbitrary self types v2 project,
https://github.com/rust-lang/rfcs/pull/3519
https://github.com/rust-lang/rust/issues/44874

r? @wesleywiser
2024-10-30 10:48:08 +00:00
..
auxiliary
elision Bless ui tests. 2024-10-04 23:38:41 +00:00
arbitrary_self_type_mut_difference.rs
arbitrary_self_type_mut_difference.stderr
arbitrary_self_types_needing_box_or_arc_wrapping.fixed
arbitrary_self_types_needing_box_or_arc_wrapping.rs
arbitrary_self_types_needing_box_or_arc_wrapping.stderr
arbitrary_self_types_needing_mut_pin.fixed
arbitrary_self_types_needing_mut_pin.rs
arbitrary_self_types_needing_mut_pin.stderr
arbitrary_self_types_nested.rs
arbitrary_self_types_pin_lifetime_impl_trait-async.rs
arbitrary_self_types_pin_lifetime_impl_trait-async.stderr Bless test fallout 2024-08-17 12:43:25 -04:00
arbitrary_self_types_pin_lifetime_impl_trait.rs
arbitrary_self_types_pin_lifetime_impl_trait.stderr Bless test fallout 2024-08-17 12:43:25 -04:00
arbitrary_self_types_pin_lifetime_mismatch-async.rs
arbitrary_self_types_pin_lifetime_mismatch-async.stderr Bless ui tests. 2024-10-04 23:38:41 +00:00
arbitrary_self_types_pin_lifetime_mismatch.rs Run rustfmt on modified tests 2024-05-17 20:31:13 +00:00
arbitrary_self_types_pin_lifetime_mismatch.stderr Detect when a lifetime is being reused in suggestion 2024-05-17 21:23:47 +00:00
arbitrary_self_types_pin_lifetime-async.rs
arbitrary_self_types_pin_lifetime.rs
arbitrary_self_types_pin_needing_borrow.rs
arbitrary_self_types_pin_needing_borrow.stderr
arbitrary_self_types_pointers_and_wrappers.rs UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
arbitrary_self_types_raw_pointer_struct.rs Arbitrary self types v2: pointers feature gate. 2024-08-27 17:32:35 +00:00
arbitrary_self_types_raw_pointer_trait.rs Arbitrary self types v2: pointers feature gate. 2024-08-27 17:32:35 +00:00
arbitrary_self_types_silly.rs
arbitrary_self_types_stdlib_pointers.rs
arbitrary_self_types_struct.rs
arbitrary_self_types_trait.rs
arbitrary_self_types_unsized_struct.rs
arbitrary-self-from-method-substs-ice.rs Reject generic self types. 2024-10-30 10:48:08 +00:00
arbitrary-self-from-method-substs-ice.stderr Reject generic self types. 2024-10-30 10:48:08 +00:00
arbitrary-self-from-method-substs.default.stderr Reject generic self types. 2024-10-30 10:48:08 +00:00
arbitrary-self-from-method-substs.feature.stderr Reject generic self types. 2024-10-30 10:48:08 +00:00
arbitrary-self-from-method-substs.rs Reject generic self types. 2024-10-30 10:48:08 +00:00
arbitrary-self-opaque.rs Require any function with a tait in its signature to actually constrain a hidden type 2024-06-12 08:53:59 +00:00
arbitrary-self-opaque.stderr Bless ui tests. 2024-10-04 23:38:41 +00:00
arbitrary-self-types-dyn-incompatible.curr.stderr UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
arbitrary-self-types-dyn-incompatible.rs UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
builtin-superkinds-self-type.rs
by-value-self-in-mut-slot.rs
class-missing-self.rs
class-missing-self.stderr
dyn-compatibility-sized-self-by-value-self.rs UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
dyn-compatibility-sized-self-generic-method.rs UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
dyn-compatibility-sized-self-return-Self.rs UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00
explicit_self_xcrate_exe.rs
explicit-self-closures.rs
explicit-self-generic.rs
explicit-self-objects-uniq.rs
explicit-self.rs
issue-61882-2.rs
issue-61882-2.stderr
issue-61882.rs
issue-61882.stderr
move-self.rs
objects-owned-object-owned-method.rs
point-at-arbitrary-self-type-method.rs
point-at-arbitrary-self-type-method.stderr
point-at-arbitrary-self-type-trait-method.rs
point-at-arbitrary-self-type-trait-method.stderr
self_lifetime-async.rs elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
self_lifetime-async.stderr elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
self_lifetime.rs elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
self_lifetime.stderr elided_named_lifetimes: bless & add tests 2024-08-31 15:35:42 +03:00
self_type_keyword-2.rs
self_type_keyword-2.stderr
self_type_keyword.rs
self_type_keyword.stderr Deny keyword lifetimes pre-expansion 2024-07-16 12:06:25 -04:00
self-ctor-nongeneric.rs Warn/error on self ctor from outer item in inner item 2024-05-18 13:08:34 -04:00
self-ctor-nongeneric.stderr Warn/error on self ctor from outer item in inner item 2024-05-18 13:08:34 -04:00
self-ctor.rs Warn/error on self ctor from outer item in inner item 2024-05-18 13:08:34 -04:00
self-ctor.stderr Warn/error on self ctor from outer item in inner item 2024-05-18 13:08:34 -04:00
self-impl-2.rs
self-impl.rs
self-impl.stderr
self-in-mut-slot-default-method.rs
self-in-mut-slot-immediate-value.rs
self-in-typedefs.rs
self-infer.rs
self-infer.stderr
self-re-assign.rs
self-shadowing-import.rs
self-type-param.rs
self-vs-path-ambiguity.rs
self-vs-path-ambiguity.stderr Make parse error suggestions verbose and fix spans 2024-07-12 03:02:57 +00:00
string-self-append.rs
suggest-self-2.rs
suggest-self-2.stderr
suggest-self.rs
suggest-self.stderr
ufcs-explicit-self.rs
uniq-self-in-mut-slot.rs
where-for-self.rs Update tests for hidden references to mutable static 2024-09-13 14:10:56 +03:00