Commit Graph

1160 Commits

Author SHA1 Message Date
Jana Dönszelmann
6072207a11
introduce new lint infra
lint on duplicates during attribute parsing
To do this we stuff them in the diagnostic context to be emitted after
hir is constructed
2025-06-12 09:56:47 +02:00
bjorn3
9223704f4b Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
Guillaume Gomez
93ca0af08c
Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-dead
Reduce `ast::ptr::P` to a typedef of `Box`

As per the MCP at https://github.com/rust-lang/compiler-team/issues/878.

r? `@fee1-dead`
2025-06-06 23:53:16 +02:00
Matthias Krüger
27a894f86f
Rollup merge of #137725 - oli-obk:i-want-to-move-it-move-it, r=compiler-errors,traviscross
Add `iter` macro

See related discussion in https://rust-lang.zulipchat.com/#narrow/channel/481571-t-lang.2Fgen/topic/iter!.20macro/near/500784563

very little error case testing so far, but the success path works.

There is also no `IterFn` trait yet, as T-lang didn't consider it something urgently needed I think we can implement it in follow-up PRs.

r? lang for the tests, `@compiler-errors` for the impl
2025-06-03 21:53:35 +02:00
Oli Scherer
5fbdfc3e10
Add iter macro
This adds an `iter!` macro that can be used to create movable
generators.

This also adds a yield_expr feature so the `yield` keyword can be used
within iter! macro bodies. This was needed because several unstable
features each need `yield` expressions, so this allows us to stabilize
them separately from any individual feature.

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03 10:52:32 -07:00
Matthias Krüger
19437666d9
Rollup merge of #141724 - Sol-Ell:issue-141141-fix, r=nnethercote
fix(#141141): When expanding `PartialEq`, check equality of scalar types first.

Fixes rust-lang/rust#141141.

Now, `cs_eq` function of `partial_eq.rs` compares [scalar types](https://doc.rust-lang.org/rust-by-example/primitives.html#scalar-types) first.

- Add `is_scalar` field to `FieldInfo`.
- Add `is_scalar` method to `TyKind`.
- Pass `FieldInfo` via `CsFold::Combine` and refactor code relying on it.
- Implement `TryFrom<&str>` and `TryFrom<Symbol>` for FloatTy.
- Implement `TryFrom<&str>` and `TryFrom<Symbol>` for IntTy.
- Implement `TryFrom<&str>` and `TryFrom<Symbol>` for UintTy.
2025-06-03 15:00:32 +02:00
Ell
a6a1c1b247 Separately check equality of the scalar types and compound types in the order of declaration. 2025-06-02 15:29:34 +03:00
bors
1ac1950c33 Auto merge of #141739 - GuillaumeGomez:rollup-ivboqwd, r=GuillaumeGomez
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#137574 (Make `std/src/num` mirror `core/src/num`)
 - rust-lang/rust#141384 (Enable review queue tracking)
 - rust-lang/rust#141448 (A variety of improvements to the codegen backends)
 - rust-lang/rust#141636 (avoid some usages of `&mut P<T>` in AST visitors)
 - rust-lang/rust#141676 (float: Disable `total_cmp` sNaN tests for `f16`)
 - rust-lang/rust#141705 (Add eslint as part of `tidy` run)
 - rust-lang/rust#141715 (Add `loongarch64` with `d` feature to `f32::midpoint` fast path)
 - rust-lang/rust#141723 (Provide secrets to try builds with new bors)
 - rust-lang/rust#141728 (Fix false documentation of FnCtxt::diverges)
 - rust-lang/rust#141729 (resolve target-libdir directly from rustc)
 - rust-lang/rust#141732 (creader: Remove extraenous String::clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-29 23:02:31 +00:00
Guillaume Gomez
2b08e4d399
Rollup merge of #141636 - fee1-dead-contrib:push-ntqvvxwuvrvx, r=petrochenkov
avoid some usages of `&mut P<T>` in AST visitors

It's a double indirection, and is also complicating our efforts at rust-lang/rust#127615.

r? `@ghost`
2025-05-29 17:02:59 +02:00
bors
13718eb788 Auto merge of #141595 - bjorn3:rustc_no_sysroot_proc_macro, r=onur-ozkan
Do not get proc_macro from the sysroot in rustc

With the stage0 refactor the proc_macro version found in the sysroot will no longer always match the proc_macro version that proc-macros get compiled with by the rustc executable that uses this proc_macro. This will cause problems as soon as the ABI of the bridge gets changed to implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the local version of proc_macro which will also be used in the sysroot that rustc will build.
2025-05-29 12:07:53 +00:00
Deadbeef
367a877147 avoid some usages of &mut P<T> in AST visitors 2025-05-29 12:54:55 +08:00
Jacob Pratt
0ac0285c3f
Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.

So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
       <-><----> <------------>
       /   |       \
   ident generics  variant_data
```

r? `@fee1-dead`
2025-05-29 04:49:43 +02:00
Trevor Gross
7f5f29b663
Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

This PR splits `#[autodiff]` macro so `#[autodiff(df, Reverse, args)]` would become `#[autodiff_reverse(df, args)]` and `#[autodiff(df, Forward, args)]` would become `#[autodiff_forwad(df, args)]`.
2025-05-28 10:28:08 -04:00
Nicholas Nethercote
4c4a40f6df Reorder ast::ItemKind::{Struct,Enum,Union} fields.
So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
       <-><----> <------------>
       /   |       \
   ident generics  variant_data
```
2025-05-28 15:48:45 +10:00
bjorn3
026baa1c6f Do not get proc_macro from the sysroot in rustc
With the stage0 refactor the proc_macro version found in the sysroot
will no longer always match the proc_macro version that proc-macros get
compiled with by the rustc executable that uses this proc_macro. This
will cause problems as soon as the ABI of the bridge gets changed to
implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the
local version of proc_macro which will also be used in the sysroot that
rustc will build.
2025-05-27 15:49:28 +00:00
Folkert de Vries
c7c0194d98
move asm parsing code into rustc_parse 2025-05-27 09:44:10 +02:00
Folkert de Vries
e3bbbeeafd
support #[cfg(...)] on arguments to the asm! macros 2025-05-27 09:44:04 +02:00
Nicholas Nethercote
991c91fdaa Reduce P<T> to a typedef of Box<T>.
Keep the `P` constructor function for now, to minimize immediate churn.

All the `into_inner` calls are removed, which is nice.
2025-05-27 13:29:24 +10:00
Nicholas Nethercote
6973fa08a3 Remove P::map.
It's barely used, and the places that use it are better if they don't.
2025-05-27 02:07:15 +10:00
Marcelo Domínguez
8dd62e8188 Update UI tests 2025-05-21 07:24:43 +00:00
Marcelo Domínguez
f92d84cc6e Initial naive implementation using Symbols to represent autodiff modes (Forward, Reverse)
Since the mode is no longer part of `meta_item`, we must insert it manually (otherwise macro expansion with `#[rustc_autodiff]` won't work).

This can be revised later if a more structured representation becomes necessary (using enums, annotated structs, etc).

Some tests are currently failing. I'll address them next.
2025-05-21 07:24:42 +00:00
Marcelo Domínguez
b725cf6af8 Disable autodiff bootstrapping 2025-05-21 07:24:33 +00:00
Marcelo Domínguez
b21c9e7bfb Split autodiff into autodiff_forward and autodiff_reverse
Pending fix.
```
error: cannot find a built-in macro with name `autodiff_forward`
    --> library\core\src\macros\mod.rs:1542:5
     |
1542 | /     pub macro autodiff_forward($item:item) {
1543 | |         /* compiler built-in */
1544 | |     }
     | |_____^

error: cannot find a built-in macro with name `autodiff_reverse`
    --> library\core\src\macros\mod.rs:1549:5
     |
1549 | /     pub macro autodiff_reverse($item:item) {
1550 | |         /* compiler built-in */
1551 | |     }
     | |_____^

error: could not compile `core` (lib) due to 2 previous errors
```
2025-05-20 11:58:26 +00:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
Stuart Cook
0513e3b463
Rollup merge of #140049 - haenoe:fix-autodiff-generics, r=ZuseZ4
fix autodiff macro on generic functions

heloo there!
This short PR allows applying the `autodiff` macro to generic functions like this one.
It only touches the frontend part, since the `rustc_autodiff` macro can already handle generics.
```rust
#[autodiff(d_square, Reverse, Duplicated, Active)]
fn square<T: std::ops::Mul<Output = T> + Copy>(x: &T) -> T {
    *x * *x
}
```
Thanks to Manuel for creating an issue on this. For more information on this see #140032
r? `@ZuseZ4`

As always: thanks for any piece of feedback!!

Fixes: #140032
Tracking issue for autodiff: https://github.com/rust-lang/rust/issues/124509
2025-05-19 13:24:53 +10:00
mejrs
178e09ed37 Remove rustc_attr_data_structures re-export from rustc_attr_parsing 2025-05-18 18:14:43 +02:00
Folkert de Vries
26e3a5041a
add AsmOptions with some named fields 2025-05-18 11:28:31 +02:00
Folkert de Vries
85053d1cd1
rename to get rid of the 'raw' concept 2025-05-18 11:28:31 +02:00
Folkert de Vries
e12d675739
delay error for unsupported options 2025-05-18 11:28:31 +02:00
Folkert de Vries
7ec06fc3b1
attempt to have rustfmt use the new logic
apparently it doesn't really use the asm parsing at present, so this may work?
2025-05-18 11:28:31 +02:00
Folkert de Vries
de8e305ba8
a new parser generating the exact same error messages
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-05-18 11:28:19 +02:00
Folkert de Vries
5af9652e5c
extract operand parser 2025-05-17 23:06:11 +02:00
Folkert de Vries
cd22c1b883
determine later whether an explicit reg was used 2025-05-17 23:06:10 +02:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02: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
56a0c7dfea
feat: propagate generics to generated function 2025-05-11 17:54:57 +02:00
Nicholas Nethercote
5ebcbfc1e1 Remove AstDeref.
It's a "utility trait to reduce boilerplate" implemented for `P` and
`AstNodeWrapper`, but removing it gives a net reduction of twenty lines
of code. It's also simpler to just implement
`HasNodeId`/`HasAttrs`/`HasTokens` directly on types instead of via
`AstDeref`.

(I decided to make this change when doing some related refactoring and
the error messages involving `AstDeref` and `HasAttrs` were hard to
understand; removing it helped a lot.)
2025-05-10 08:58:47 +10:00
Marijn Schouten
3d4737fb5e Remove duplicate impl of string unescape 2025-05-06 10:00:22 +00:00
Matthias Krüger
56e01fe1a4
Rollup merge of #140312 - nnethercote:DelimArgs-spacing, r=petrochenkov
Improve pretty-printing of braces

r? ````@petrochenkov````
2025-04-30 10:18:26 +02:00
bors
f242d6c26c Auto merge of #127516 - nnethercote:simplify-LazyAttrTokenStream, r=petrochenkov
Simplify `LazyAttrTokenStream`

`LazyAttrTokenStream` is an unpleasant type: `Lrc<Box<dyn ToAttrTokenStream>>`. Why does it look like that?
- There are two `ToAttrTokenStream` impls, one for the lazy case, and one for the case where we already have an `AttrTokenStream`.
- The lazy case (`LazyAttrTokenStreamImpl`) is implemented in `rustc_parse`, but `LazyAttrTokenStream` is defined in `rustc_ast`, which does not depend on `rustc_parse`. The use of the trait lets `rustc_ast` implicitly depend on `rustc_parse`. This explains the `dyn`.
- `LazyAttrTokenStream` must have a `size_of` as small as possible, because it's used in many AST nodes. This explains the `Lrc<Box<_>>`, which keeps it to one word. (It's required `Lrc<dyn _>` would be a fat pointer.)

This PR moves `LazyAttrTokenStreamImpl` (and a few other token stream things) from `rustc_parse` to `rustc_ast`. This lets us replace the `ToAttrTokenStream` trait with a two-variant enum and also remove the `Box`, changing `LazyAttrTokenStream` to `Lrc<LazyAttrTokenStreamInner>`. Plus it does a few cleanups.

r? `@petrochenkov`
2025-04-30 00:09:21 +00:00
Nicholas Nethercote
298c56f4ba Simplify LazyAttrTokenStream.
This commit does the following.
- Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to
  `Lrc<LazyAttrTokenStreamInner>`.
- Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which
  is a two-variant enum.
- Removes the `ToAttrTokenStream` trait and the two impls of it.

The recursion limit must be increased in some crates otherwise rustdoc
aborts.
2025-04-30 07:10:56 +10:00
Nicholas Nethercote
99f6b6328e Improve pretty-printing of braces.
Most notably, the `FIXME` for suboptimal printing of `use` groups in
`tests/ui/macros/stringify.rs` is fixed. And all other test output
changes result in pretty printed output being closer to the original
formatting in the source code.
2025-04-29 13:46:17 +10:00
Oli Scherer
b023856f29 Add or-patterns to pattern types 2025-04-28 07:50:18 +00:00
Oli Scherer
2134793792 Directly generate TyPat instead of TyPatKind 2025-04-28 07:36:59 +00:00
Oli Scherer
6338e364f0 Pull ast pattern type parsing out into a separate function 2025-04-28 07:36:59 +00:00
Oli Scherer
96918a4bd5 Prevent pattern type macro invocations from having trailing tokens 2025-04-28 07:36:59 +00:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Chris Denton
264249fbe1
Rollup merge of #140104 - Shourya742:2025-04-21-auto-diff-fails-on-impl-block, r=ZuseZ4
Fix auto diff failing on inherent impl blocks

closes: #139557

r? ``@ZuseZ4``
2025-04-22 15:24:07 +00:00
bit-aloo
c0c6d4280c
support both trait and non-trail associated declaration 2025-04-21 13:28:53 +05:30
Matthias Krüger
de9323973a remove a couple clones 2025-04-20 18:58:46 +02:00