rust/compiler
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
..
rustc disable size asserts in the compiler when randomizing layouts 2024-08-31 23:56:45 +02:00
rustc_abi Rollup merge of #132255 - workingjubilee:layout-is-🏚️, r=compiler-errors 2024-10-28 10:18:50 -07:00
rustc_arena move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
rustc_ast fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
rustc_ast_ir Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
rustc_ast_lowering Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot 2024-10-29 03:11:39 -07:00
rustc_ast_passes Rollup merge of #132214 - fmease:mv-impl-trait-val-paths, r=compiler-errors 2024-10-27 19:49:07 +01:00
rustc_ast_pretty fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
rustc_attr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_baked_icu_data Don't add warn(unreachable_pub) to rustc_baked_icu. 2024-08-16 08:46:52 +10:00
rustc_borrowck Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercote 2024-10-30 06:40:37 +01:00
rustc_builtin_macros Auto merge of #131284 - dingxiangfei2009:rename-smart-ptr-to-coerce-referent, r=compiler-errors 2024-10-27 17:04:12 +00:00
rustc_codegen_cranelift cg_clif: Rename LayoutS to LayoutData 2024-10-27 22:32:40 -07:00
rustc_codegen_gcc Effects cleanup 2024-10-26 10:19:07 +08:00
rustc_codegen_llvm Rollup merge of #132342 - Zalathar:operand-bundle, r=workingjubilee 2024-10-30 06:40:38 +01:00
rustc_codegen_ssa TypingMode 🤔 2024-10-29 17:01:24 +01:00
rustc_const_eval Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercote 2024-10-30 06:40:37 +01:00
rustc_data_structures Replace an FTP link in comments with an equivalent HTTPS link 2024-10-24 17:02:11 +11:00
rustc_driver
rustc_driver_impl fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
rustc_error_codes Reject generic self types. 2024-10-30 10:48:08 +00:00
rustc_error_messages Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_errors Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot 2024-10-29 03:11:39 -07:00
rustc_expand Rollup merge of #132332 - nnethercote:use-token_descr-more, r=estebank 2024-10-30 06:40:36 +01:00
rustc_feature Rollup merge of #131984 - dingxiangfei2009:stabilize-if-let-rescope, r=traviscross,lcnr 2024-10-29 18:38:57 +01:00
rustc_fluent_macro use tracked_path in rustc_fluent_macro 2024-10-19 22:32:38 +08:00
rustc_fs_util Couple of changes to make it easier to compile rustc for wasm 2024-09-26 19:51:14 +00:00
rustc_graphviz Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_hir Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
rustc_hir_analysis Reject generic self types. 2024-10-30 10:48:08 +00:00
rustc_hir_pretty Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
rustc_hir_typeck Reject generic self types. 2024-10-30 10:48:08 +00:00
rustc_incremental nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_index Rollup merge of #130625 - heiseish:issue-124028-fix, r=jieyouxu 2024-10-10 12:49:18 +02:00
rustc_index_macros Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_infer TypingMode 🤔 2024-10-29 17:01:24 +01:00
rustc_interface fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
rustc_lexer Reserve guarded string literals (RFC 3593) 2024-10-08 18:21:16 -06:00
rustc_lint Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errors 2024-10-30 06:40:34 +01:00
rustc_lint_defs Auto merge of #125116 - blyxyas:ignore-allowed-lints-final, r=cjgillot 2024-10-26 16:37:43 +00:00
rustc_llvm Rollup merge of #132342 - Zalathar:operand-bundle, r=workingjubilee 2024-10-30 06:40:38 +01:00
rustc_log Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_macros give a better error for tuple structs in derive(Diagnostic) 2024-10-27 21:23:28 -04:00
rustc_metadata Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot 2024-10-29 03:11:39 -07:00
rustc_middle TypingMode 🤔 2024-10-29 17:01:24 +01:00
rustc_mir_build Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errors 2024-10-30 06:40:34 +01:00
rustc_mir_dataflow Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercote 2024-10-30 06:40:37 +01:00
rustc_mir_transform Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercote 2024-10-30 06:40:37 +01:00
rustc_monomorphize Auto merge of #132171 - matthiaskrgr:rollup-tp75ge7, r=matthiaskrgr 2024-10-26 06:53:53 +00:00
rustc_next_trait_solver remove outdated debug_assertion 2024-10-29 17:01:24 +01:00
rustc_parse Rollup merge of #132332 - nnethercote:use-token_descr-more, r=estebank 2024-10-30 06:40:36 +01:00
rustc_parse_format Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_passes TypingMode 🤔 2024-10-29 17:01:24 +01:00
rustc_pattern_analysis compiler: Add rustc_abi dependence to the compiler 2024-10-27 21:10:58 -07:00
rustc_privacy Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
rustc_query_impl Handle rustc_query_impl cases of rustc::potential_query_instability lint 2024-10-03 12:47:08 +03:00
rustc_query_system fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
rustc_resolve Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot 2024-10-29 03:11:39 -07:00
rustc_sanitizers Rollup merge of #131049 - compiler-errors:more-validation, r=spastorino 2024-10-22 15:28:38 +02:00
rustc_serialize Fix explicit_iter_loop in rustc_serialize 2024-10-16 15:44:16 +02:00
rustc_session Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot 2024-10-29 03:11:39 -07:00
rustc_smir stable_mir: Directly use types from rustc_abi 2024-10-28 10:13:19 -07:00
rustc_span Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot 2024-10-29 03:11:39 -07:00
rustc_symbol_mangling compiler: Add rustc_abi dependence to the compiler 2024-10-27 21:10:58 -07:00
rustc_target Auto merge of #131900 - mrkajetanp:target-feature-pauth-lr, r=Amanieu 2024-10-27 00:09:49 +00:00
rustc_trait_selection Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errors 2024-10-30 06:40:34 +01:00
rustc_traits TypingMode 🤔 2024-10-29 17:01:24 +01:00
rustc_transmute Rollup merge of #132255 - workingjubilee:layout-is-🏚️, r=compiler-errors 2024-10-28 10:18:50 -07:00
rustc_ty_utils TypingMode 🤔 2024-10-29 17:01:24 +01:00
rustc_type_ir Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errors 2024-10-30 06:40:34 +01:00
rustc_type_ir_macros do not relate Abi and Safety 2024-10-22 23:13:04 +02:00
stable_mir Rollup merge of #132085 - celinval:update-smir-doc, r=compiler-errors 2024-10-24 23:23:55 -07:00