Commit graph

118 commits

Author SHA1 Message Date
Oscar Bray
dd8a98a9bc Fix pretty print tests with #[prelude_import] 2026-02-12 17:43:58 +00:00
Jonathan Brouwer
6dc27bf7de
Update uitests 2026-01-19 21:50:29 +01:00
Lukas Bergdoll
506762f3ff Explicitly export core and std macros
Currently all core and std macros are automatically added to the prelude
via #[macro_use]. However a situation arose where we want to add a new macro
`assert_matches` but don't want to pull it into the standard prelude for
compatibility reasons. By explicitly exporting the macros found in the core and
std crates we get to decide on a per macro basis and can later add them via
the rust_20xx preludes.
2026-01-13 08:47:48 +01:00
aerooneqq
3f477dd710 Recursive delegation improvements 2025-12-25 14:49:01 +03:00
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
aerooneqq
1de1885a63 Support syntax for one-line trait reuse 2025-12-23 10:34:23 +03:00
Manuel Drehwald
c34ea6e56d remove llvm_enzyme and enzyme fallbacks from most places, enable the autodiff frontend on nightly 2025-12-19 11:02:57 -08:00
aerooneqq
0a3fd24287 Support attribute inheritance in delegation 2025-12-12 20:34:54 +03:00
Matthias Krüger
02a58a9bee
Rollup merge of #149489 - scottmcm:try-bikeshed, r=nnethercote
Experimentally add *heterogeneous* `try` blocks

rust-lang/rust#148725 moved the default to being homogeneous; this adds heterogeneous ones back under an obvious-bikeshed syntax so people can experiment with that as well.

Essentially resolves rust-lang/rust#149025 by letting them move to this syntax instead.

New tracking issue: rust-lang/rust#149488
Related RFC: https://github.com/rust-lang/rfcs/pull/3721#issuecomment-3208342727 (specifically about experimenting)
2025-12-10 17:16:47 +01:00
Scott McMurray
4033d19b79 Experimentally add *heterogeneous* try blocks
148725 moved the default to being homogeneous; this adds heterogeneous ones back under an obvious-bikeshed syntax so people can experiment with that as well.

Essentially resolves 149025 by letting them move to this syntax instead.
2025-12-09 20:18:43 -08:00
aerooneqq
8cf942d89f Add inline attribute to generated delegation function if needed 2025-12-08 19:56:47 +03:00
Mara Bos
04c5e7b54a Document fmt::Arguments internal representation. 2025-11-12 12:48:39 +01:00
Mara Bos
7b42543f81 Bless tests. 2025-11-12 12:48:27 +01:00
Stuart Cook
3538bc18fe
Rollup merge of #143619 - beetrees:varargs-named, r=jdonszelmann
`c_variadic`: Add future-incompatibility warning for `...` arguments without a pattern outside of `extern` blocks

This PR makes `...` arguments without a pattern in non-foreign functions (such as the argument in `unsafe extern "C" fn f(...) {}`) a future-compatibility warning; making this error would be consistent with how `unsafe extern "C" fn f(u32) {}` is handled. Allowing `...` arguments without a pattern in non-foreign functions is a source of confusion for programmers coming from C, where the `...` parameter is never named and instead calling `va_start` is required; disallowing `...` arguments without a pattern also improves the overall consistency of the Rust language by matching the treatment of other arguments without patterns. `...` arguments without a pattern in `extern` blocks (such as `unsafe extern "C" { fn f(...); }`) continue to compile without warnings after this PR, as they are already stable and heavily used (and don't cause the mentioned confusion as they are just being used in function declarations).

As all the syntax gating for `c_variadic` has been done post-expansion, this is technically a breaking change. In particular, code like this has compiled on stable since Rust 1.35.0:
```rust
#[cfg(any())] // Equivalent to the more recent #[cfg(false)]
unsafe extern "C" fn bar(_: u32, ...) {}
```
Since this is more or less a stability hole and a Crater run shows only the `binrw` crate is using this, I think it would be ok to break this. This will require a lang FCP.

The idea of rejecting `...` pre-expansion was first raised here https://github.com/rust-lang/rust/pull/143546#issuecomment-3043142052.

Tracking issue: rust-lang/rust#44930
cc `@folkertdev` `@workingjubilee`
r? `@joshtriplett`
2025-11-11 21:09:33 +11:00
beetrees
02e1f4421d
c_variadic: Add future-incompatibility warning for ... arguments without a pattern outside of extern blocks 2025-11-10 14:33:56 +01:00
Frank King
5ef48ed448 Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
Cameron Steffen
7cbff63411 Remove QPath::LangItem from ranges 2025-10-27 21:19:38 -05:00
Marcelo Domínguez
cdd4118204 Update autodiff tests for the new intrinsics impl 2025-08-14 18:33:43 +00:00
Vadim Petrochenkov
c56f49dc34 expand: Micro-optimize prelude injection
Use `splice` to avoid shifting the other items twice.
Put `extern crate std;` first so it's already resolved when we resolve `::std::prelude::rust_20XX`.
2025-07-28 17:35:09 +03:00
Jonathan Brouwer
3303534dc8
Update uitest stderrs
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-23 13:33:23 +02:00
Jonathan Brouwer
3fa0ec91d8
Rewrite empty attribute lint
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-06 09:51:35 +02:00
Frank King
afdb54a673 Move the place in &pin mut $place when !Unpin to ensure soundness 2025-06-15 10:31:11 +08:00
Frank King
e627f88f88 Implement pinned borrows, part of pin_ergonomics 2025-06-15 10:21:29 +08:00
Matthias Krüger
b12bb2530b
Rollup merge of #134847 - dtolnay:asymmetrical, r=fmease
Implement asymmetrical precedence for closures and jumps

I have been through a series of asymmetrical precedence designs in Syn, and finally have one that I like and is worth backporting into rustc. It is based on just 2 bits of state: `next_operator_can_begin_expr` and `next_operator_can_continue_expr`.

Asymmetrical precedence is the thing that enables `(return 1) + 1` to require parentheses while `1 + return 1` does not, despite `+` always having stronger precedence than `return` [according to the Rust Reference](https://doc.rust-lang.org/1.83.0/reference/expressions.html#expression-precedence). This is facilitated by `next_operator_can_continue_expr`.

Relatedly, it is the thing that enables `(return) - 1` to require parentheses while `return + 1` does not, despite `+` and `-` having exactly the same precedence. This is facilitated by `next_operator_can_begin_expr`.

**Example:**

```rust
macro_rules! repro {
    ($e:expr) => {
        $e - $e;
        $e + $e;
    };
}

fn main() {
    repro!{return}
    repro!{return 1}
}
```

`-Zunpretty=expanded` **Before:**

```console
fn main() {
    (return) - (return);
    (return) + (return);
    (return 1) - (return 1);
    (return 1) + (return 1);
}
```

**After:**

```console
fn main() {
    (return) - return;
    return + return;
    (return 1) - return 1;
    (return 1) + return 1;
}
```
2025-06-13 05:16:54 +02:00
Marcelo Domínguez
8917ff6024 Update generic tests 2025-05-21 07:24:43 +00:00
Marcelo Domínguez
2041de7083 Update codegen and pretty tests
UI tests are pending, will depend on error messages change.
2025-05-21 07:24:42 +00:00
HaeNoe
e2b7278942
feat: add generated parameters to generated function
- update pretty printing tests
- only add generic parameters when function is actually generic (no empty turbofish)
2025-05-11 17:54:57 +02:00
HaeNoe
8b3228233e
feat: add test for generics in generated function 2025-05-11 17:54:57 +02:00
David Tolnay
6cca4ca82b
Implement asymmetrical precedence for closures and jumps 2025-05-03 23:27:29 -07:00
Nicholas Nethercote
e1a177bbba Improve hir pretty-printing of attributes. 2025-05-03 12:46:48 +10:00
Stuart Cook
8619438574
Rollup merge of #137474 - VlaDexa:shebang-placement, r=wesleywiser
pretty-print: Print shebang at the top of the output

Shebang should stay at the top of the file, even after pretty-printing.

Closes #134643
2025-05-02 22:16:57 +10:00
Mara Bos
86c6e7911d Bless pretty tests. 2025-05-01 12:31:44 +02:00
Nicholas Nethercote
bc8df506f6 Streamline the format macro.
Removing the unnecessary local variable speeds up compilation a little.
2025-04-28 06:56:13 +10:00
Matthias Krüger
405c8afce3
Rollup merge of #140280 - nnethercote:improve-if-else-printing, r=Urgau
Improve if/else pretty printing

AST/HIR pretty printing of if/else is currently pretty bad. This PR improves it a lot.

r? `@Nadrieril`
2025-04-27 16:08:59 +02:00
Matthias Krüger
4f7aed6791
Rollup merge of #140246 - nnethercote:fix-never-pattern-printing, r=Nadrieril
Fix never pattern printing

It's currently broken, but there's an easy fix.

r? `@Nadrieril`
2025-04-27 16:08:58 +02:00
Nicholas Nethercote
7ac2d1f1bd Improve HIR pretty-printing of if/else some more.
In the AST the "then" block is represented as a `Block`. In HIR the
"then" block is represented as an `Expr` that happens to always be.
`ExprKind::Block`. By deconstructing the `ExprKind::Block` to extract
the block within, things print properly.

For `issue-82392.rs`, note that we no longer print a type after the
"then" block. This is good, it now matches how we don't print a type for
the "else" block. (Well, we do print a type after the "else" block, but
it's for the whole if/else.)

Also tighten up some of the pattern matching -- these block expressions
within if/else will never have labels.
2025-04-26 06:35:44 +10:00
Nicholas Nethercote
e37c367482 Improve pretty printing of if/else.
By removing some of the over-indenting. AST pretty printing now looks
correct. HIR pretty printing is better, but still over-indents some.
2025-04-25 14:33:16 +10:00
Nicholas Nethercote
ee43aa356a Fix some pretty printing indents.
Indents for `cbox` and `ibox` are 0 or `INDENT_UNIT` (4) except for a
couple of places which are `INDENT_UNIT - 1` for no clear reason.

This commit changes the three space indents to four spaces.
2025-04-25 14:33:16 +10:00
Nicholas Nethercote
3d488f8e0c Add pretty printing tests for if/else.
The AST pretty printing is a bit wonky. The HIR pretty printing is
extremely wonky.
2025-04-25 14:33:14 +10:00
Nicholas Nethercote
49ca89dc36 Fix pretty printing of never pattern match arms. 2025-04-24 19:26:13 +10:00
Nicholas Nethercote
9f497008b0 Add a pretty printing test involving a never pattern.
This currently prints badly, with unclosed indentation.
2025-04-24 19:19:51 +10:00
bit-aloo
b8ca0073c8
move autodiff pretty test to a autodiff sub module 2025-04-22 09:53:08 +05:30
bit-aloo
a7c7119ed2
Added test 2025-04-22 09:08:33 +05:30
bors
a7c39b6861 Auto merge of #139114 - m-ou-se:super-let-pin, r=davidtwco
Implement `pin!()` using `super let`

Tracking issue for super let: https://github.com/rust-lang/rust/issues/139076

This uses `super let` to implement `pin!()`.

This means we can remove [the hack](https://github.com/rust-lang/rust/pull/138717) we had to put in to fix https://github.com/rust-lang/rust/issues/138596.

It also means we can remove the original hack to make `pin!()` work, which used a questionable public-but-unstable field rather than a proper private field.

While `super let` is still unstable and subject to change, it seems safe to assume that future Rust will always have a way to express `pin!()` in a compatible way, considering `pin!()` is already stable.

It'd help [the experiment](https://github.com/rust-lang/rust/issues/139076) to have `pin!()` use `super let`, so we can get some more experience with it.
2025-04-19 08:01:53 +00:00
Matthias Krüger
0de803c38d
Rollup merge of #138632 - clubby789:stabilize-cfg-boolean-lit, r=davidtwco,Urgau,traviscross
Stabilize `cfg_boolean_literals`

Closes #131204
`@rustbot` labels +T-lang +I-lang-nominated
This will end up conflicting with the test in #138293 so whichever doesn't land first will need updating

--

# Stabilization Report

## General design

### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

[RFC 3695](https://github.com/rust-lang/rfcs/pull/3695), none.

### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

None

### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

None

## Has a call-for-testing period been conducted? If so, what feedback was received?

Yes; only positive feedback was received.

## Implementation quality

### Summarize the major parts of the implementation and provide links into the code (or to PRs)

Implemented in [#131034](https://github.com/rust-lang/rust/pull/131034).

### Summarize existing test coverage of this feature

- [Basic usage, including `#[cfg()]`, `cfg!()` and `#[cfg_attr()]`](6d71251cf9/tests/ui/cfg/true-false.rs)
- [`--cfg=true/false` on the command line being accessible via `r#true/r#false`](6d71251cf9/tests/ui/cfg/raw-true-false.rs)
- [Interaction with the unstable `#[doc(cfg(..))]` feature](6d71251/tests/rustdoc-ui/cfg-boolean-literal.rs)
- [Denying `--check-cfg=cfg(true/false)`](6d71251/tests/ui/check-cfg/invalid-arguments.rs)
- Ensuring `--cfg false` on the command line doesn't change the meaning of `cfg(false)`: `tests/ui/cfg/cmdline-false.rs`
- Ensuring both `cfg(true)` and `cfg(false)` on the same item result in it being disabled: `tests/ui/cfg/both-true-false.rs`

### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

The above mentioned issue; it should not block as it interacts with another unstable feature.

### What FIXMEs are still in the code for that feature and why is it ok to leave them there?

None

### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization
- `@clubby789` (RFC)
- `@Urgau` (Implementation in rustc)

### Which tools need to be adjusted to support this feature. Has this work been done?

`rustdoc`'s  unstable`#[doc(cfg(..)]` has been updated to respect it. `cargo` has been updated with a forward compatibility lint to enable supporting it in cargo once stabilized.

## Type system and execution rules

### What updates are needed to the reference/specification? (link to PRs when they exist)

A few lines to be added to the reference for configuration predicates, specified in the RFC.
2025-04-17 06:25:15 +02:00
Mara Bos
1ca9300989 Update tests. 2025-04-15 11:14:23 +02:00
Nicholas Nethercote
16670e1676 Fix HIR pretty-printing of fns with just a variadic arg.
Avoid the extraneous comma.
2025-04-15 10:41:10 +10:00
Nicholas Nethercote
f8edc831ca Pretty-print PatKind::Missing as _.
Printing "no pattern" as `_` isn't ideal, but better than crashing, and
HIR pretty-printing already has plenty of imperfections. The added `f2`
and `f6` examples are ones that triggered the crash.

Note that some of the added examples are printed badly, e.g.
`fn(, ...)`. The next commit will fix those.

Fixes #139633.
2025-04-15 10:40:58 +10:00
Nicholas Nethercote
9bb1008e1d Avoid empty identifiers for delegate params and args.
Instead use `argN`. The empty identifiers could flow to
`Liveness::should_warn`, where they would trigger a bounds error.

Fixes #139512.
2025-04-10 14:46:53 +10:00
Nicholas Nethercote
3cb9966235 Add a HIR pretty printing test for delegation.
Note that some of the output is currently bogus, with missing params and
args:
```
fn add(: _, : _) -> _ { m::add(, ) }
```
The next commit will fix this.
2025-04-10 14:09:37 +10:00