1188 Commits

Author SHA1 Message Date
Jonathan Brouwer
38dd6f5206
Allow Early stage to emit errors 2025-07-15 09:01:03 +02:00
Folkert de Vries
3689b80b75
make cfg_select a builtin macro 2025-07-13 14:34:40 +02:00
Jacob Pratt
7eea141b87
Rollup merge of #143544 - workingjubilee:rename-bare-fn, r=fmease
compiler: rename BareFn to FnPtr

At some point "BareFn" was the chosen name for a "bare" function, without the niceties of `~fn`, `&fn`, or a few other ways of writing a function type. However, at some point the syntax for a "bare function" and any other function diverged even more. We started calling them what they are: function pointers, denoted by their own syntax.

However, we never changed the *internal* name for these, as this divergence was very gradual. Personally, I have repeatedly searched for "FnPtr" and gotten confused until I find the name is BareFn, only to forget this until the next time, since I don't routinely interact with the higher-level AST and HIR. But even tools that interact with these internal types only touch on them in a few places, making a migration easy enough. Let's use a more intuitive and obvious name, as this 12+ year old name has little to do with current Rust.
2025-07-07 03:26:09 +02:00
Jubilee Young
0a4f87a144 compiler: rename {ast,hir}::BareFn* to FnPtr*
Fix some comments and related types and locals where it is obvious, e.g.
- bare_fn -> fn_ptr
- LifetimeBinderKind::BareFnType -> LifetimeBinderKind::FnPtrType

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-07-06 15:03:08 -07:00
Matthias Krüger
bff79a7517
Rollup merge of #143518 - joshtriplett:sort-attrs, r=Kobzol
rustc_builtin_macros: Make sure registered attributes stay sorted

As with the list of builtin macros, use tidy to make sure the list of
builtin attributes stays sorted.
2025-07-06 15:56:14 +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
Josh Triplett
e99f9c5ffc rustc_builtin_macros: Make sure registered attributes stay sorted
As with the list of builtin macros, use tidy to make sure the list of
builtin attributes stays sorted.
2025-07-05 20:21:51 -07:00
Jacob Pratt
05f5690d81
Rollup merge of #143380 - cjgillot:kw_span, r=compiler-errors
Replace kw_span by full span for generic const parameters.

Small simplification extracted from https://github.com/rust-lang/rust/pull/127241
2025-07-04 05:47:27 +02:00
Camille GILLOT
3380bfd1a0 Replace kw_span by full span. 2025-07-03 14:59:27 +00:00
klensy
c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
Josh Stone
e851e3e16e Update cfg(bootstrap) 2025-07-01 10:55:49 -07:00
Nicholas Nethercote
478f8287c0 Introduce ByteSymbol.
It's like `Symbol` but for byte strings. The interner is now used for
both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"`
you'll get a `Symbol` and a `ByteSymbol` with the same index and the
characters will only be stored once.

The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to
make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate
`ast::LitKind` in HIR. The latter change reduces peak memory by a
non-trivial amount on literal-heavy benchmarks such as `deep-vector` and
`tuple-stress`.

`Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some
changes so that they can handle normal strings and byte strings.

This change does slow down compilation of programs that use
`include_bytes!` on large files, because the contents of those files are
now interned (hashed). This makes `include_bytes!` more similar to
`include_str!`, though `include_bytes!` contents still aren't escaped,
and hashing is still much cheaper than escaping.
2025-06-30 20:42:27 +10:00
Jana Dönszelmann
63c5a84b74
Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk
Add runtime check to avoid overwrite arg in `Diag`

## Origin PR description
At first, I set up a `debug_assert` check for the arg method to make sure that `args` in `Diag` aren't easily overwritten, and I added the `remove_arg()` method, so that if you do need to overwrite an arg, then you can explicitly call `remove_arg()` to remove it first, then call `arg()` to overwrite it.

For the code before the rust-lang/rust#142015 change, it won't compile because it will report an error
```
arg `instance`already exists.
```

This PR also modifies all diagnostics that fail the check to pass the check. There are two cases of check failure:

1. ~~Between *the parent diagnostic and the subdiagnostic*, or *between the subdiagnostics* have the same field between them. In this case, I renamed the conflicting fields.~~
2. ~~For subdiagnostics stored in `Vec`, the rendering may iteratively write the same arg over and over again. In this case, I changed the auto-generation with `derive(SubDiagnostic)` to manually implementing `SubDiagnostic` and manually rendered it with `eagerly_translate()`, similar to https://github.com/rust-lang/rust/issues/142031#issuecomment-2984812090, and after rendering it I manually deleted useless arg with the newly added `remove_arg` method.~~

## Final Decision

After trying and discussing, we made a final decision.

For `#[derive(Subdiagnostic)]`, This PR made two changes:

1. After the subdiagnostic is rendered, remove all args of this subdiagnostic, which allows for usage like `Vec<Subdiag>`.
2. Store `diag.args` before setting arguments, so that you can restore the contents of the main diagnostic after deleting the arguments after subdiagnostic is rendered, to avoid deleting the main diagnostic's arg when they have the same name args.
2025-06-25 22:14:55 +02:00
xizheyin
d2d17c60bd
Add runtime check to avoid overwrite arg easily in diag and store and restore snapshot when set subdiag arg
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-25 21:07:16 +08:00
Guillaume Gomez
0377330be4
Rollup merge of #142704 - tgross35:remove-concat_idents, r=fee1-dead
Remove the deprecated unstable `concat_idents!` macro

In [rust-lang/rust#137653], the lang and libs-API teams did a joint FCP to deprecate
and eventually remove the long-unstable `concat_idents!` macro. The
deprecation is landing in 1.88, so do the removal here (target version
1.90).

This macro has been superseded by the more recent `${concat(...)}`
metavariable expression language feature, which avoids some of the
limitations of `concat_idents!`. The metavar expression is unstably
available under the [`macro_metavar_expr_concat`] feature.

History is mildly interesting here: `concat_idents!` goes back to 2011
when it was introduced with 513276e595f8 ("Add #concat_idents[] and
#ident_to_str[]"). The syntax looks a bit different but it still works
about the same:

    let asdf_fdsa = "<.<";
    assert(#concat_idents[asd,f_f,dsa] == "<.<");

    assert(#ident_to_str[use_mention_distinction]
           == "use_mention_distinction");

(That test existed from introduction until its removal here.)

Closes: https://github.com/rust-lang/rust/issues/29599

[rust-lang/rust#137653]: https://github.com/rust-lang/rust/pull/137653
[`macro_metavar_expr_concat`]: https://github.com/rust-lang/rust/issues/124225
2025-06-24 15:39:38 +02:00
Trevor Gross
0e4de4ceb0 Remove the deprecated concat_idents! macro
In [137653], the lang and libs-API teams did a joint FCP to deprecate
and eventually remove the long-unstable `concat_idents!` macro. The
deprecation is landing in 1.88, so do the removal here (target version
1.90).

This macro has been superseded by the more recent `${concat(...)}`
metavariable expression language feature, which avoids some of the
limitations of `concat_idents!`. The metavar expression is unstably
available under the [`macro_metavar_expr_concat`] feature.

History is mildly interesting here: `concat_idents!` goes back to 2011
when it was introduced with 513276e595f8 ("Add #concat_idents[] and
about the same:

    let asdf_fdsa = "<.<";
    assert(#concat_idents[asd,f_f,dsa] == "<.<");

    assert(#ident_to_str[use_mention_distinction]
           == "use_mention_distinction");

(That test existed from introduction until its removal here.)

Closes: https://www.github.com/rust-lang/rust/issues/29599

[137653]: https://www.github.com/rust-lang/rust/pull/137653
[`macro_metavar_expr_concat`]: https://www.github.com/rust-lang/rust/issues/124225
2025-06-24 11:07:16 +00:00
bors
111e9bc64b Auto merge of #142878 - GuillaumeGomez:rollup-53dohob, r=GuillaumeGomez
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#142458 (Merge unboxed trait object error suggestion into regular dyn incompat error)
 - rust-lang/rust#142593 (Add a warning to LateContext::get_def_path)
 - rust-lang/rust#142594 (Add DesugaringKind::FormatLiteral)
 - rust-lang/rust#142740 (Clean-up `FnCtxt::is_destruct_assignment_desugaring`)
 - rust-lang/rust#142780 (Port `#[must_use]` to new attribute parsing infrastructure)
 - rust-lang/rust#142798 (Don't fail to parse a struct if a semicolon is used to separate fields)
 - rust-lang/rust#142856 (Add a few inline directives in rustc_serialize.)
 - rust-lang/rust#142868 (remove few allow(dead_code))
 - rust-lang/rust#142874 (cranelift: fix target feature name typo: "fxsr")
 - rust-lang/rust#142877 (Document why tidy checks if `eslint` is installed via `npm`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-22 17:10:28 +00:00
bors
c2ec7532ee Auto merge of #142706 - fee1-dead-contrib:push-zsznlqyrzsqo, r=oli-obk
completely deduplicate `Visitor` and `MutVisitor`

r? oli-obk

This closes rust-lang/rust#127615.

### Discussion

> * Give every `MutVisitor::visit_*` method a corresponding `flat_map_*` method.

Not every AST node exists in a location where they can be mapped to multiple instances of themselves. Not every AST node exists in a location where they can be removed from existence (e.g. `filter_map_expr`). I don't think this is doable.

> * Give every `MutVisitor::visit_*` method a corresponding `Visitor` method and vice versa

The only three remaining method-level asymmetries after this PR are `visit_stmt` and `visit_nested_use_tree` (only on `Visitor`) and `visit_span` (only on `MutVisitor`).

`visit_stmt` doesn't seem applicable to `MutVisitor` because `walk_flat_map_stmt_kind` will ask `flat_map_item` / `filter_map_expr` to potentially turn a single `Stmt` to multiple based on what a visitor wants. So only using `flat_map_stmt` seems appropriate.

`visit_nested_use_tree` is used for `rustc_resolve` to track stuff. Not useful for `MutVisitor` for now.

`visit_span` is currently not used for `MutVisitor` already, it was just kept in case we want to revive rust-lang/rust#127241. cc `@cjgillot` maybe we could remove for now and re-insert later if we find a use-case? It does involve some extra effort to maintain.

* Remaining FIXMEs

`visit_lifetime` has an extra param for `Visitor` that's not in `MutVisitor`. This is again something only used by `rustc_resolve`. I think we can keep that symmetry for now.
2025-06-22 14:03:44 +00:00
mejrs
b1d18129d1 Implement DesugaringKind::FormatLiteral 2025-06-22 10:58:25 +02:00
Jana Dönszelmann
c693bc268a
Rollup merge of #142698 - tgross35:concat-byte-cstr-diag, r=petrochenkov
Improve diagnostics for `concat_bytes!` with C string  literals

Use the same error as other invalid types for `concat_bytes!`, rather
than using `ConcatCStrLit` from `concat!`. Also add more information
with a note about why this doesn't work, and a suggestion to use a
null-terminated byte string instead.
2025-06-21 15:32:06 +02:00
Nicholas Nethercote
1edf201937 Avoid some unnecessary symbol interning.
- `Ident::from_str_and_span` -> `Ident::new` when the string is
  pre-interned.
- `Ident::from_str` -> `Ident::with_dummy_span` when the string is
  pre-interned.
- `_d` and `_e` are unused.
2025-06-20 13:18:41 +10:00
Nicholas Nethercote
4a1f445142 Use a symbol for ExpansionConfig::crate_name.
This avoids some symbol interning and `to_string` conversions.
2025-06-20 13:17:39 +10:00
Trevor Gross
044c99df78 Improve diagnostics for concat_bytes! with C string literals
Use the same error as other invalid types for `concat_bytes!`, rather
than using `ConcatCStrLit` from `concat!`. Also add more information
with a note about why this doesn't work, and a suggestion to use a
null-terminated byte string instead.
2025-06-19 16:13:20 +00:00
Deadbeef
3da58e673a completely deduplicate Visitor and MutVisitor 2025-06-19 17:50:44 +08:00
Deadbeef
4eaca5d1de remove walk_item_kind from MutVisitor
just using `walk_item` instead would be okay.
2025-06-19 13:50:15 +08:00
Jacob Pratt
e95fb09dfb
Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkov
avoid `&mut P<T>` in `visit_expr` etc methods

trying a different way than rust-lang/rust#141636
r? ghost
2025-06-17 23:19:34 +02:00
Deadbeef
96fd9fc2dd use if let guards where possible 2025-06-15 15:46:20 +08:00
Deadbeef
5f0dd44b3b avoid &mut P<T> in visit_expr etc methods 2025-06-12 17:36:03 +08:00
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