mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
6d8d79595e
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
|
||
---|---|---|
.. | ||
auxiliary | ||
elision | ||
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 | ||
arbitrary_self_types_pin_lifetime_impl_trait.rs | ||
arbitrary_self_types_pin_lifetime_impl_trait.stderr | ||
arbitrary_self_types_pin_lifetime_mismatch-async.rs | ||
arbitrary_self_types_pin_lifetime_mismatch-async.stderr | ||
arbitrary_self_types_pin_lifetime_mismatch.rs | ||
arbitrary_self_types_pin_lifetime_mismatch.stderr | ||
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 | ||
arbitrary_self_types_raw_pointer_struct.rs | ||
arbitrary_self_types_raw_pointer_trait.rs | ||
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 | ||
arbitrary-self-from-method-substs-ice.stderr | ||
arbitrary-self-from-method-substs.default.stderr | ||
arbitrary-self-from-method-substs.feature.stderr | ||
arbitrary-self-from-method-substs.rs | ||
arbitrary-self-opaque.rs | ||
arbitrary-self-opaque.stderr | ||
arbitrary-self-types-dyn-incompatible.curr.stderr | ||
arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr | ||
arbitrary-self-types-dyn-incompatible.rs | ||
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 | ||
dyn-compatibility-sized-self-generic-method.rs | ||
dyn-compatibility-sized-self-return-Self.rs | ||
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 | ||
self_lifetime-async.stderr | ||
self_lifetime.rs | ||
self_lifetime.stderr | ||
self_type_keyword-2.rs | ||
self_type_keyword-2.stderr | ||
self_type_keyword.rs | ||
self_type_keyword.stderr | ||
self-ctor-nongeneric.rs | ||
self-ctor-nongeneric.stderr | ||
self-ctor.rs | ||
self-ctor.stderr | ||
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 | ||
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 |