Commit Graph

48471 Commits

Author SHA1 Message Date
许杰友 Jieyou Xu (Joe)
4be8c49cdc Rollup merge of #143558 - joshtriplett:mbe-refactors, r=SparrowLii
mbe: Refactors and function extractions in `compile_declarative_macro`

These refactors help pave the way for parsing attribute rules.

Best reviewed commit-by-commit.

- **mbe: Simplify compile_declarative_macro by factoring out some variables**
- **mbe: Factor out a helper to check an LHS**
- **mbe: Factor out a helper to check for unexpected EOF in definition**
- **mbe: Clarify comments about error handling in `compile_declarative_macro`**
2025-07-07 19:45:42 +08:00
许杰友 Jieyou Xu (Joe)
b6015a68de Rollup merge of #143551 - compiler-errors:root-sub, r=cjgillot
Dont resolve instance of root in `mir_callgraph_cyclic`

`Instance::try_resolve` on a default trait body method will always fail, since it's still possible to further substitute. This leads to a cycle, since in `tests/mir-opt/inline_default_trait_body.rs`, both `Trait::a` and `Trait::b` need to consider the other to be cyclical, but since we couldn't resolve a body, we'd just consider *nothing* to be cyclical.

The root instance we care about when computing `mir_callgraph_cyclic` is trivial to compute (it's just `InstanceKind::Item`), so just replace it with a call to `Instance::new_raw`.

r? `@cjgillot` `@oli-obk`

Fixes rust-lang/rust#143534
2025-07-07 19:45:41 +08:00
许杰友 Jieyou Xu (Joe)
eed55947ac Rollup merge of #143528 - RalfJung:stack-pop-cleanup, r=oli-obk
interpret: rename StackPopCleanup

The name `StackPopCleanup` stopped making sense a long time ago IMO -- in the common case, it has nothing to do with "cleanup", and everything with where the program should jump next. If we didn't have unwinding this would be just the return block, but given that we do have unwinding I figured maybe "continuation" would be a good name. This comes up in [continuation-passing style](https://en.wikipedia.org/wiki/Continuation-passing_style) and refers to where the program will *continue* when a function is done. So from a PL perspective it is the most fitting term I think -- but it may be too jargony.

r? `@oli-obk` what do you think?
2025-07-07 19:45:41 +08:00
许杰友 Jieyou Xu (Joe)
02aa4ff12f Rollup merge of #143524 - makai410:smir-move-back, r=oli-obk
Move `stable_mir` back to its own crate

We've finished the refactoring, so it's time to move `stable_mir` back to its own crate.

This PR leaves an empty `rustc_internal` module with a `#[deprecated]` attribute in `rustc_smir` to let users know we just moved it to `stable_mir`.
2025-07-07 19:45:40 +08:00
许杰友 Jieyou Xu (Joe)
4ba4b5f24f Rollup merge of #143482 - ia0:fix, r=fee1-dead
Fix short linker error output

This PR does 2 things:

- It removes the braces when there's a single element. This is required since brace expansion (at least in bash and zsh) only triggers if there's at least 2 elements.

- It removes the extra `.rlib` suffixes of the elements. See https://github.com/rust-lang/rust/pull/135707#discussion_r2185212393 for context.

Running `cargo +stage1 build` on the following program:

```rust
unsafe extern "C" {
    fn foo() -> libc::c_int;
}

fn main() {
    let x = unsafe { foo() } as u32;
    // println!("{}", data_encoding::BASE64.encode(&x.to_le_bytes()));
}
```

Gives the following diff before and after the PR:

```diff
-/tmp/foo/target/debug/deps/{liblibc-faf416f178830595.rlib}.rlib
+/tmp/foo/target/debug/deps/liblibc-faf416f178830595.rlib
```

Running on the same program with the additional dependency, we get the following diff:

```diff
-/tmp/foo/target/debug/deps/{liblibc-faf416f178830595.rlib,libdata_encoding-84bb5aadfa9e8839.rlib}.rlib
+/tmp/foo/target/debug/deps/{liblibc-faf416f178830595,libdata_encoding-84bb5aadfa9e8839}.rlib
```
2025-07-07 19:45:40 +08:00
Pavel Grigorenko
bb8b741c32 Port #[export_stable] to the new attribute system 2025-07-07 14:33:20 +03:00
bors
25cf7d13c9 Auto merge of #143035 - ywxt:less-work-steal, r=oli-obk
Only work-steal in the main loop for rustc_thread_pool

This PR is a replica of <https://github.com/rust-lang/rustc-rayon/pull/12> that only retained work-steal in the main loop for rustc_thread_pool.

r? `@oli-obk`

cc `@SparrowLii` `@Zoxc` `@cuviper`

Updates rust-lang/rust#113349
2025-07-07 11:16:16 +00:00
lcnr
3ddcf8b94c remove has_nested 2025-07-07 11:19:58 +02:00
bohan
e1720d7396 consider nested cases for duplicate RPITIT 2025-07-07 17:09:39 +08:00
xizheyin
796b4d1fb4 Point to correct argument in Func Call when Self type fails trait bound
When a trait bound fails due to the Self type parameter, adjust_fulfillment_errors
now correctly points to the corresponding function argument instead of incorrectly
pointing to other arguments.

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-07 16:47:15 +08:00
Oli Scherer
62929b9420 Add ty_span query 2025-07-07 08:13:12 +00:00
Martin Nordholts
aa364cac52 compiler: Deduplicate must_emit_unwind_tables() comments
There is one comment at a call site and one comment in the function
definition that are mostly saying the same thing. Fold the call site
comment into the function definition comment to reduce duplication.

There are actually some inaccuracies in the comments but let's
deduplicate before we address the inaccuracies.
2025-07-07 09:34:34 +02:00
Martin Nordholts
1eff043e7a rustc_codegen_llvm: Remove reference to non-existing no_landing_pads()
Removing this reference was forgotten in eb4725fc54. Grepping for
no_landing_pads returns no hits after this.
2025-07-07 09:34:34 +02:00
Edoardo Marangoni
93f1201c06 compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
Julien Cretin
cdbdd8a4ad Reverse comparison order
Co-authored-by: beef <ent3rm4n@gmail.com>
2025-07-07 08:49:10 +02:00
Josh Triplett
ef0465a7eb mbe: Clarify comments about error handling in compile_declarative_macro 2025-07-06 20:49:12 -07:00
Josh Triplett
493cdf2269 mbe: Factor out a helper to check for unexpected EOF in definition
Will get called additional times when expanding parsing to cover
attributes
2025-07-06 20:49:12 -07:00
Josh Triplett
87cd178159 mbe: Factor out a helper to check an LHS
This currently gets called only once, but will get called multiple times
when handling attributes.
2025-07-06 20:49:12 -07:00
Josh Triplett
8d5eb6badb mbe: Simplify compile_declarative_macro by factoring out some variables 2025-07-06 20:49:12 -07: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
Jacob Pratt
3e76cd796f Rollup merge of #143535 - reallesee:patch-1, r=jdonszelmann
Remove duplicate word

Deleted a duplicated word to improve text clarity.

contains contains - contains
2025-07-07 03:26:08 +02:00
Jacob Pratt
a1b51aa400 Rollup merge of #143456 - joshtriplett:mbe-unused-rules-bitset, r=lqd
mbe: Change `unused_macro_rules` to a `DenseBitSet`

Now that it only contains indexes, and no other information, a bitset provides a more compact and simpler representation.

This builds on <https://github.com/rust-lang/rust/pull/143416>. Only the last commit is new.
2025-07-07 03:26:07 +02:00
Jacob Pratt
11b24c108d Rollup merge of #143344 - JonathanBrouwer:path-parser, r=jdonszelmann
Port `#[path]` to the new attribute parsing infrastructure

Ports `#[path]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197

This PR duplicates a change from https://github.com/rust-lang/rust/pull/143237
Draft until that one is merged
2025-07-07 03:26:06 +02:00
Jacob Pratt
d748e70fea Rollup merge of #143206 - Jules-Bertholet:align-attr-fixes, r=workingjubilee
Align attr fixes

- Remove references to the superseded `repr(align)` syntax
- Allow the attribute on fn items in `extern` blocks
- Test attribute in combination with `async fn` and `dyn`

r? workingjubilee

Tracking issue: https://github.com/rust-lang/rust/issues/82232
`@rustbot` label A-attributes F-fn_align T-compiler
2025-07-07 03:26:05 +02:00
Michael Goulet
a40274d6cc Dont resolve instance of root in mir_callgraph_cyclic 2025-07-06 23:01:45 +00: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
Jules Bertholet
a1cefee8d5 Support #[align(…)] on fns in extern blocks 2025-07-06 16:56:41 -04:00
Jules Bertholet
97a7b9b1b4 Remove repr(align) code 2025-07-06 16:56:39 -04:00
Jonathan Brouwer
244d64e60b Port #[path] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-06 22:19:16 +02:00
Jonathan Brouwer
ef3d7741e5 Move check for new attribute to check_builtin_meta_item
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-06 22:18:58 +02:00
bors
a84ab0ce6c Auto merge of #143509 - cjgillot:copy-prop-noborrow, r=tmiasko
Do not unify borrowed locals in CopyProp.

Instead of trying yet another scheme to unify borrowed locals in CopyProp, let's just stop trying. We had already enough miscompilations because of this.

I'm convinced it's possible to have both unification of some borrowed locals and soundness, but I don't have a simple and convincing formulation yet.

Fixes https://github.com/rust-lang/rust/issues/143491
2025-07-06 19:58:07 +00:00
Josh Triplett
8ee1e9817c mbe: Change unused_macro_rules to a DenseBitSet
Now that it only contains indexes, and no other information, a bitset
provides a more compact and simpler representation.
2025-07-06 12:02:23 -07:00
Micke
8b65c2f85f Remove duplicate word 2025-07-06 20:06:46 +02:00
Michael Goulet
b63f920ccf More carefully consider span context when suggesting remove &mut 2025-07-06 17:36:35 +00:00
Ralf Jung
7775166528 interpret: rename StackPopCleanup 2025-07-06 16:07:35 +02: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
Matthias Krüger
bae6714fe2 Rollup merge of #143492 - Diggsey:db-fix-object-ambiguity, r=RalfJung
Use `object` crate from crates.io to fix windows build error

See https://rust-lang.zulipchat.com/#narrow/channel/386786-rustc-codegen-gcc/topic/Cannot.20compile.20rustc.20on.20Windows.2010/with/527240094
2025-07-06 15:56:13 +02:00
Matthias Krüger
017fe2fb8f Rollup merge of #143252 - JonathanBrouwer:rewrite_empty_attribute, r=jdonszelmann
Rewrite empty attribute lint for new attribute parser

cc `@jdonszelmann`
2025-07-06 15:56:12 +02:00
Makai
c42a9ac602 move stable_mir back to its own crate and move rustc_internal to thestable_mir crate
As part of this reorganization, some traits need to be moved from `rustc_smir::context::traits` to `stable_mir::unstable::internal_cx`. These traits are specifically designed for `InternalCx` to clarify the behavior of different functions that share the same name. This move is necessary to avoid orphan rule violations.
2025-07-06 12:25:42 +00:00
Camille GILLOT
bab9c752e8 Do not unify borrowed locals in CopyProp. 2025-07-06 10:14:07 +00:00
Matthias Krüger
534c09a779 Rollup merge of #143484 - bvanjoi:issue-140796, r=compiler-errors
distinguish the duplicate item of rpitit

Fixes rust-lang/rust#140796

r? compiler

cc `@Zoxc`
2025-07-06 10:03:23 +02:00
Matthias Krüger
6fb00b1514 Rollup merge of #143477 - folkertdev:use-is-multiple-of, r=joshtriplett
use `is_multiple_of` and `div_ceil`

In tricky logic, these functions are much more informative than the manual implementations. They also catch subtle bugs:

- the manual `is_multiple_of` often does not handle division by zero
- manual `div_ceil` often does not consider overflow

The transformation is free for `is_multiple_of` if the divisor is compile-time known to be non-zero. For `div_ceil` there is a small cost to considering overflow. Here is some assembly https://godbolt.org/z/5zP8KaE1d.
2025-07-06 10:03:23 +02:00
Matthias Krüger
71b73e529a Rollup merge of #143416 - joshtriplett:mbe-simplifications, r=nnethercote
mbe: Defer checks for `compile_error!` until reporting an unused macro rule

The current MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking.

Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused.

In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes.

This builds atop a couple of minor MBE refactors. I would suggest reviewing commit-by-commit.

The overall result is a further simplification of the macro code.
2025-07-06 10:03:22 +02:00
Jonathan Brouwer
33f2cc7eda Fix line break after ":" in unpretty attribute print
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-06 09:51:47 +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
bohan
5bbab8967d distinguish the duplicate item of rpitit 2025-07-06 14:04:40 +08:00
bors
febb10d0a2 Auto merge of #143507 - matthiaskrgr:rollup-lpg7t12, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#143238 (Port `#[ignore]` to the new attribute parsing infrastructure)
 - rust-lang/rust#143441 (Stop using `Key` trait unnecessarily)
 - rust-lang/rust#143478 (Miri subtree update)
 - rust-lang/rust#143486 (remove armv5te-unknown-linux-gnueabi target maintainer)
 - rust-lang/rust#143489 (Complete rustc_ast::mut_visit for spans.)
 - rust-lang/rust#143494 (Remove yields_in_scope from the scope tree.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-06 04:09:12 +00: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
dianne
68d860f8be remove DesugaringKind::CondTemporary 2025-07-05 17:14:06 -07:00
dianne
75cea03e03 de-duplicate condition scoping logic 2025-07-05 17:14:06 -07:00