rust/compiler
Jonathan Brouwer e156286fa5
Rollup merge of #150130 - aerooneqq:delegation-one-line-trait-impl, r=petrochenkov
Support syntax for one-line trait reuse

This PR adds support for reusing the whole trait with a one-line reuse syntax and is part of the delegation feature rust-lang/rust#118212:
```rust
trait T {
  fn foo(&self);
}

struct S;
impl T for S { ... }

struct Wrapper(S);
reuse impl T for Wrapper { self.0 }
```

The core idea is that we already have support for glob reuse, so in this scenario we want to transform one-line reuse into a trait impl block with a glob reuse in the following way:
```rust
//Before
reuse impl T for Wrapper { self.0 }

//After
impl T for Wrapper {
  reuse T::* { self.0 }
}
```

It seems like this task can be solved during parsing stage, when we encountered a one-line trait reuse, we can expand into this impl block right away, and the code which was already written to expand glob delegations will take care about the rest. We will copy trait path into glob reuse path.

The implementation of the transformation reuses already existing methods for `impl` parsing, however, we do not parse inner `impl` items, instead we parse "inner items" as delegation body. Thus, we do not have to deal with generics, consts, unsafe and other `impl` related features.

Other syntax possibility is trying to shorten one-line reuse by replacing `impl` keyword with `reuse` keyword:
```rust
reuse T for Wrapper { self.0 }
```
In this case implementation may become more complicated, and the syntax more confusing, as keywords such as `const` or `unsafe` will precede `reuse`, and there are also generics:
```rust
unsafe reuse<T1, T2> T for Wrapper { self.0 }
```

In the first (currently implemented) version reuse is placed in the beginning of the item, and it is clear that we will reuse trait implementation, while in the second, shorter version, the `reuse` keyword may be lost in generics and keywords that may precede `impl`.

r? ``@petrochenkov``
2025-12-23 12:01:01 +01:00
..
rustc Auto merge of #148925 - madsmtm:jemalloc-perf, r=Kobzol 2025-11-23 20:34:07 +00:00
rustc_abi layout: Store inverse memory index in FieldsShape::Arbitrary 2025-12-18 22:25:34 +01:00
rustc_arena Handle bootstrap cfgs 2025-12-19 15:04:30 -08:00
rustc_ast Fix typo 2025-12-22 16:50:41 +01:00
rustc_ast_ir Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
rustc_ast_lowering Rollup merge of #150098 - Bryntet:perf-testing, r=JonathanBrouwer 2025-12-22 17:33:36 +01:00
rustc_ast_passes hir/trait_sel: prohibit scalable vectors in types 2025-12-16 11:00:12 +00:00
rustc_ast_pretty rustdoc: handle macro expansions in types 2025-12-21 23:23:17 +08:00
rustc_attr_parsing Port #[cfi_encoding] to attribute parser 2025-12-21 22:11:33 +01:00
rustc_baked_icu_data Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_borrowck Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_builtin_macros Auto merge of #150133 - ZuseZ4:enzyme-frontend-nightly, r=jieyouxu 2025-12-23 02:49:04 +00:00
rustc_codegen_cranelift Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_codegen_gcc Merge commit '02f889aec5' 2025-12-21 00:13:38 +01:00
rustc_codegen_llvm Auto merge of #150133 - ZuseZ4:enzyme-frontend-nightly, r=jieyouxu 2025-12-23 02:49:04 +00:00
rustc_codegen_ssa Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_const_eval Auto merge of #150187 - RalfJung:visitor-in-mem-order, r=nnethercote 2025-12-22 13:52:39 +00:00
rustc_data_structures Auto merge of #149273 - bjorn3:crate_locator_improvements, r=petrochenkov 2025-12-14 09:16:11 +00:00
rustc_driver Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_driver_impl Overhaul filename handling for cross-compiler consistency 2025-12-12 07:33:09 +01:00
rustc_error_codes Rollup merge of #149949 - JonathanBrouwer:error_cleanup, r=jdonszelmann 2025-12-14 20:04:56 +01:00
rustc_error_messages Remove unused pop_span_label method 2025-11-21 14:16:12 +00:00
rustc_errors remove fixme & update stderr files 2025-12-16 13:23:48 +00:00
rustc_expand Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco 2025-12-13 14:32:09 +00:00
rustc_feature Auto merge of #150177 - matthiaskrgr:rollup-4cw3gdw, r=matthiaskrgr 2025-12-20 05:17:27 +00:00
rustc_fluent_macro move and rename proc_macro::tracked_{env::var,path::path} 2025-11-26 22:44:25 +01:00
rustc_fs_util Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_graphviz change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_hashes some cleanups in compiler 2025-10-12 08:08:30 +00:00
rustc_hir Port #[cfi_encoding] to attribute parser 2025-12-21 22:11:33 +01:00
rustc_hir_analysis Handle bootstrap cfgs 2025-12-19 15:04:30 -08:00
rustc_hir_id rustc_hir_id: Add a comment explaining why the crate exists 2025-08-20 15:04:00 -07:00
rustc_hir_pretty remove support for type-of 2025-11-25 10:19:44 +01:00
rustc_hir_typeck Detail expectation on non-() block tail in if then condition with no else 2025-12-22 13:55:49 +00:00
rustc_incremental Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_index layout: Store inverse memory index in FieldsShape::Arbitrary 2025-12-18 22:25:34 +01:00
rustc_index_macros Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_infer Moved struct Placeholder<T> 2025-12-09 13:40:18 +00:00
rustc_interface Rollup merge of #150032 - Kivooeo:annotate-snippets-stable, r=Muscraft 2025-12-16 20:21:10 +01:00
rustc_lexer Update memchr to 2.7.6 2025-09-26 17:53:49 +02:00
rustc_lint Rollup merge of #150166 - Urgau:const-item-lint-150157, r=Kivooeo 2025-12-22 20:11:54 +01:00
rustc_lint_defs Update compiler/rustc_lint_defs/src/builtin.rs 2025-12-19 15:04:30 -08:00
rustc_llvm feat: dlopen Enzyme 2025-12-16 00:31:32 +09:00
rustc_log Restrict sysroot crate imports to those defined in this repo. 2025-10-15 13:17:25 +01:00
rustc_macros Rollup merge of #149400 - Skgland:tracked_mod, r=Amanieu 2025-12-09 17:36:48 +01:00
rustc_metadata Dogfood strip_circumfix 2025-12-20 13:56:25 +02:00
rustc_middle Rollup merge of #150098 - Bryntet:perf-testing, r=JonathanBrouwer 2025-12-22 17:33:36 +01:00
rustc_mir_build Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_mir_dataflow Introduce Operand::RuntimeChecks. 2025-12-14 17:25:53 +00:00
rustc_mir_transform Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_monomorphize mono: require target feature for scalable vectors 2025-12-16 11:01:26 +00:00
rustc_next_trait_solver revert one change from rustc_next_trait_solver 2025-12-12 17:55:26 +00:00
rustc_parse Support syntax for one-line trait reuse 2025-12-23 10:34:23 +03:00
rustc_parse_format Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_passes Port #[cfi_encoding] to attribute parser 2025-12-21 22:11:33 +01:00
rustc_pattern_analysis change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_privacy Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_proc_macro Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_public Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_public_bridge Overhaul filename handling for cross-compiler consistency 2025-12-12 07:33:09 +01:00
rustc_query_impl Lock shards while collecting active jobs. 2025-11-14 09:01:22 +08:00
rustc_query_system Also check in case it tries to mark red node as green 2025-12-12 16:44:17 +03:00
rustc_resolve Rollup merge of #150155 - Aditya-PS-05:fix/ice-150103-root-in-suggestions, r=estebank 2025-12-22 17:33:37 +01:00
rustc_sanitizers Port #[cfi_encoding] to attribute parser 2025-12-21 22:11:33 +01:00
rustc_serialize Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_session Avoid unhelpful suggestion when crate name is invalid 2025-12-16 20:43:26 -08:00
rustc_span Rollup merge of #149989 - Urgau:filenames-post-improvements, r=davidtwco 2025-12-19 23:38:58 +01:00
rustc_symbol_mangling Rollup merge of #148452 - Fulgen301:pdb-large-symbols-v0, r=jackh726 2025-11-26 23:32:05 +11:00
rustc_target Rollup merge of #149512 - adamgemmell:dev/adagem01/armv7-d32-fix, r=Amanieu 2025-12-21 21:16:33 +01:00
rustc_thread_pool change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_trait_selection Dogfood strip_circumfix 2025-12-20 13:56:25 +02:00
rustc_traits add const_of_item query and use it in normalization 2025-11-08 13:50:47 -05:00
rustc_transmute layout: Store inverse memory index in FieldsShape::Arbitrary 2025-12-18 22:25:34 +01:00
rustc_ty_utils layout: Store inverse memory index in FieldsShape::Arbitrary 2025-12-18 22:25:34 +01:00
rustc_type_ir Rollup merge of #150033 - izagawd:try_as_dyn, r=oli-obk 2025-12-16 20:21:10 +01:00
rustc_type_ir_macros Provide an extended framework for type visit, for use in rust-analyzer 2025-12-16 01:47:28 +02:00
rustc_windows_rc [win] Use find-msvc-tools instead of cc to find the linker and rc on Windows 2025-09-19 12:00:30 -07:00