rust/tests/pretty
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
..
autodiff remove llvm_enzyme and enzyme fallbacks from most places, enable the autodiff frontend on nightly 2025-12-19 11:02:57 -08:00
auxiliary Support attribute inheritance in delegation 2025-12-12 20:34:54 +03:00
postfix-match expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
asm.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
asm.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
ast-stmt-expr-attr.rs Use cfg(false) in UI tests 2025-04-03 21:41:58 +00:00
async.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
attr-derive.rs Update tests to use new proc-macro header 2024-11-27 07:18:25 -08:00
attr-fn-inner.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
attr-literals.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
attr-tokens-raw-ident.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
auto-trait.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
blank-lines.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-multiple-asterisks.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-trailing-whitespace.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-trailing-whitespace2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-wchar.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
block-comment-wchar.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-disambig.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
cast-lt.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
cast-lt.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
closure-reform-pretty.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
delegation-impl-reuse.pp Support syntax for one-line trait reuse 2025-12-23 10:34:23 +03:00
delegation-impl-reuse.rs Support syntax for one-line trait reuse 2025-12-23 10:34:23 +03:00
delegation-inherit-attributes.pp Support attribute inheritance in delegation 2025-12-12 20:34:54 +03:00
delegation-inherit-attributes.rs Support attribute inheritance in delegation 2025-12-12 20:34:54 +03:00
delegation.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
delegation_inline_attribute.pp Add inline attribute to generated delegation function if needed 2025-12-08 19:56:47 +03:00
delegation_inline_attribute.rs Add inline attribute to generated delegation function if needed 2025-12-08 19:56:47 +03:00
delimited-token-groups.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
disamb-stmt-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
do1.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
doc-comments.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
dollar-crate.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
dollar-crate.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
empty-impl.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
empty-lines.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
enum-variant-vis.rs Use cfg(false) in UI tests 2025-04-03 21:41:58 +00:00
example1.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
example2.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
example2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
expanded-and-path-remap-80832.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
expanded-and-path-remap-80832.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
fn-return.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
fn-types.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
fn-variadic.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
for-comment.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
format-args-str-escape.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
format-args-str-escape.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
gat-bounds.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
hir-delegation.pp Add inline attribute to generated delegation function if needed 2025-12-08 19:56:47 +03:00
hir-delegation.rs Add a HIR pretty printing test for delegation. 2025-04-10 14:09:37 +10:00
hir-fn-params.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
hir-fn-params.rs Add a pretty printing test for fn params. 2025-03-14 06:29:24 +11:00
hir-fn-variadic.pp c_variadic: Add future-incompatibility warning for ... arguments without a pattern outside of extern blocks 2025-11-10 14:33:56 +01:00
hir-fn-variadic.rs c_variadic: Add future-incompatibility warning for ... arguments without a pattern outside of extern blocks 2025-11-10 14:33:56 +01:00
hir-if-else.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
hir-if-else.rs Add pretty printing tests for if/else. 2025-04-25 14:33:14 +10:00
hir-lifetimes.pp Remove QPath::LangItem from ranges 2025-10-27 21:19:38 -05:00
hir-lifetimes.rs Add a HIR pretty-printing test focused on lifetimes. 2025-03-28 08:25:06 +11:00
hir-pretty-attr.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
hir-pretty-attr.rs pretty print hir attributes 2025-02-24 14:31:19 +01:00
hir-pretty-loop.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
hir-pretty-loop.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
hir-struct-expr.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
hir-struct-expr.rs Improve hir_pretty for struct expressions. 2025-03-30 11:21:51 +02:00
if-attr.rs Use cfg(false) in UI tests 2025-04-03 21:41:58 +00:00
if-else.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
if-else.rs Add pretty printing tests for if/else. 2025-04-25 14:33:14 +10:00
import-renames.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-4264.pp Document fmt::Arguments internal representation. 2025-11-12 12:48:39 +01:00
issue-4264.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-12590-a.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-12590-b.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-12590-c.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
issue-12590-c.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-19077.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-25031.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-30731.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-31073.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
issue-31073.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-68710-field-attr-proc-mac-lost.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-73626.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74745.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-85089.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
issue-85089.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
let.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
lifetime.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
macro.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
macro_rules.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
match-block-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
match-naked-expr-medium.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
match-naked-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nested-item-vis-defaultness.rs Use cfg(false) in UI tests 2025-04-03 21:41:58 +00:00
never-pattern.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
never-pattern.rs Add a pretty printing test involving a never pattern. 2025-04-24 19:19:51 +10:00
offset_of.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
path-type-bounds.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
pin-ergonomics-hir.pp Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
pin-ergonomics-hir.rs Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
pin-ergonomics.rs Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
postfix-yield.rs Update tests. 2025-04-15 11:14:23 +02:00
qpath-associated-type-bound.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
raw-address-of.rs stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
raw-str-nonexpr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
shebang-at-top.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
shebang-at-top.rs Put shebang at the top of pretty-print 2025-02-23 10:51:22 +01:00
stmt_expr_attributes.rs fix pretty test 2025-03-21 09:35:31 +01:00
struct-pattern.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
struct-tuple.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
tag-blank-lines.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
tests-are-sorted.pp expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
tests-are-sorted.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
top-level-doc-comments.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
trait-inner-attr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
trait-polarity.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
trait-safety.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
try-blocks.rs Experimentally add *heterogeneous* try blocks 2025-12-09 20:18:43 -08:00
unary-op-disambig.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
use-tree.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
vec-comments.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
vec-comments.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
where-clauses.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
yeet-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00