Commit Graph

49486 Commits

Author SHA1 Message Date
Stuart Cook
603b61df57 Rollup merge of #143075 - workingjubilee:interrupts-may-return-nevermore, r=davidtwco
compiler: Allow `extern "interrupt" fn() -> !`

While reviewing rust-lang/rust#142633 I overlooked a few details because I was kind of excited.

- Fixes rust-lang/rust#143072
2025-08-15 16:16:31 +10:00
Stuart Cook
e3a178234d Rollup merge of #142640 - Sa4dUs:ad-intrinsic, r=ZuseZ4
Implement autodiff using intrinsics

This PR aims to move autodiff logic to `autodiff` intrinsic. Allowing us to delete a great part of our frontend code and overall, simplify the compilation pipeline of autodiff functions.
2025-08-15 16:16:30 +10:00
Stuart Cook
1eeb8e8b15 Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov
Change the desugaring of `assert!` for better error output

In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

Now `assert!(val)` desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.
2025-08-15 16:16:29 +10:00
bors
8800ec1665 Auto merge of #144591 - RalfJung:pattern-valtrees, r=BoxyUwU
Patterns: represent constants as valtrees

Const patterns are always valtrees now. Let's represent that in the types. We use `ty::Value` for this since it nicely packages value and type, and has some convenient methods.

Cc `@Nadrieril` `@BoxyUwU`
2025-08-15 05:49:54 +00:00
Zalathar
c64c6d85e1 Use LLVMSetTailCallKind 2025-08-15 13:57:37 +10:00
bors
3507a749b3 Auto merge of #145407 - Kobzol:rollup-g6yhx82, r=Kobzol
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#137872 (Include whitespace in "remove |" suggestion and make it hidden)
 - rust-lang/rust#144631 (Fix test intrinsic-raw_eq-const-bad for big-endian)
 - rust-lang/rust#145233 (cfg_select: Support unbraced expressions)
 - rust-lang/rust#145261 (Improve tracing in bootstrap)
 - rust-lang/rust#145324 (Rename and document `ONLY_HOSTS` in bootstrap)
 - rust-lang/rust#145353 (bootstrap: Fix jemalloc 64K page support for aarch64 tools)
 - rust-lang/rust#145379 (bootstrap: Support passing `--timings` to cargo)
 - rust-lang/rust#145397 (Rust documentation, use `rustc-dev-guide` :3)
 - rust-lang/rust#145398 (Use `default_field_values` in `Resolver`)
 - rust-lang/rust#145401 (cleanup: Remove useless `[T].iter().last()`)
 - rust-lang/rust#145403 (Adjust error message grammar to be less awkward)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-14 23:30:10 +00:00
Josh Triplett
354fcf2b52 mbe: Handle applying macro_rules derives
Add infrastructure to apply a derive macro to arguments, consuming and
returning a `TokenTree` only.

Handle `SyntaxExtensionKind::MacroRules` when expanding a derive, if the
macro's kinds support derive.

Add tests covering various cases of `macro_rules` derives.

Note that due to a pre-existing FIXME in `expand.rs`, derives are
re-queued and some errors get emitted twice. Duplicate diagnostic
suppression makes them not visible, but the FIXME should still get
fixed.
2025-08-14 14:23:05 -07:00
Josh Triplett
8fb98ef368 mbe: Parse macro derive rules
This handles various kinds of errors, but does not allow applying the
derive yet.

This adds the feature gate `macro_derive`.
2025-08-14 13:53:57 -07:00
Jakub Beránek
8b387d84fe Deduplicate -L paths passed to rustc 2025-08-14 22:38:21 +02:00
Jakub Beránek
069892180b Rollup merge of #145403 - shepmaster:grammar, r=estebank
Adjust error message grammar to be less awkward

r? ``@estebank``
2025-08-14 21:48:48 +02:00
Jakub Beránek
603ee15f7c Rollup merge of #145401 - estebank:remove-useless-iter, r=compiler-errors
cleanup: Remove useless `[T].iter().last()`
2025-08-14 21:48:47 +02:00
Jakub Beránek
93e895bc64 Rollup merge of #145398 - estebank:use-default-fields-resolver, r=petrochenkov
Use `default_field_values` in `Resolver`

Change `Resolver` to use `feature(default_field_values)`. This change is non-exhaustive, as fields may have been added since I made this commit, and `Fx(Index/Hash)(Map/Set)` types would need to have a `const` constructable to change the majority of the fields left over.

Using default field values should make it easier to review when we add or remove fields to `Resolver` in the future, and highlight which fields are run-time dependent in `Resolver::new`.

r? ``@petrochenkov``
2025-08-14 21:48:46 +02:00
Jakub Beránek
01bd889098 Rollup merge of #145233 - joshtriplett:cfg-select-expr, r=jieyouxu
cfg_select: Support unbraced expressions

Tracking issue for `cfg_select`: rust-lang/rust#115585

When operating on expressions, `cfg_select!` can now handle expressions
without braces. (It still requires braces for other things, such as
items.)

Expand the test coverage and documentation accordingly.

---

I'm not sure whether deciding to extend `cfg_select!` in this way is T-lang or T-libs-api. I've labeled for both, with the request that both teams don't block on each other. :)
2025-08-14 21:48:42 +02:00
Jakub Beránek
18afb69767 Rollup merge of #137872 - estebank:extra-vert, r=compiler-errors
Include whitespace in "remove |" suggestion and make it hidden

Tweak error rendering of patterns with an extra `|` on either end.

Built on #137409. Only last commit is relevant.

? ``@compiler-errors``
2025-08-14 21:48:41 +02:00
bors
898aff704d Auto merge of #145085 - JonathanBrouwer:target_checking, r=jdonszelmann
Rework target checking for built-in attributes

This is a refactoring of target checking for built-in attributes.
This PR has the following goals:
- Only refactor the 80% of the attributes that are simple to target check. More complicated ones like `#[repr]` will be in a future PR. Tho I have written the code in such a way that this will be possible to add in the future.
- No breaking changes.
  - This part of the codebase is not very well tested though, we can do a crater run if we want to be sure.
  - I've spotted quite a few weird situations (like I don't think an impl block should be deprecated?). We can propose fixing these to  in a future PR

Fixes https://github.com/rust-lang/rust/issues/143780
Fixes https://github.com/rust-lang/rust/issues/138510

I've split it in commits and left a description on some of the commits to help review.
r? `@jdonszelmann`
2025-08-14 19:38:35 +00:00
Waffle Lapkin
fa18b3ebe2 drive-by: fix typo 2025-08-14 21:23:49 +02:00
Kivooeo
51df1dad6c fixed diagnostic 2025-08-14 17:28:50 +00:00
Jake Goulding
65d329d189 Adjust error message grammar to be less awkward 2025-08-14 12:50:07 -04:00
Marcelo Domínguez
e1d79b9aad Remove lto inline logic 2025-08-14 16:30:16 +00:00
Marcelo Domínguez
c9c1c17128 Remove inlining for autodiff handling 2025-08-14 16:30:16 +00:00
Marcelo Domínguez
250d77e5d7 Complete functionality and general cleanup 2025-08-14 16:30:15 +00:00
Marcelo Domínguez
5c631041aa Basic implementation of autodiff intrinsic 2025-08-14 16:29:58 +00:00
Esteban Küber
b67cd4c6cf cleanup: Remove useless [T].iter().last() 2025-08-14 16:28:56 +00:00
Jonathan Brouwer
5245c39972 Remove the old target checking logic 2025-08-14 18:18:42 +02:00
Jonathan Brouwer
35e04b67a6 Specify the list of allowed targets per attribute 2025-08-14 18:18:22 +02:00
Jonathan Brouwer
744d39ebe6 Allow attribute parsers to specify a list of allowed targets
Every acceptor gets an `ALLOWED_TARGETS` specification which can specify per target whether it is allowed, warned, or errored.
2025-08-14 18:11:56 +02:00
Jonathan Brouwer
e7ef23e90e Pass the target type down to parse_attribute_list 2025-08-14 18:11:56 +02:00
Jonathan Brouwer
106731f714 Improved Target type
- Added a few more variants which are needed for various attributes
- Previously a trait method with default block had the same target representation as a method in a `impl trait for` block, this has been changed (See `MethodKind`)
- Added `plural_name` for more precision on the form of the name
2025-08-14 18:11:47 +02:00
Esteban Küber
caadc8df35 Do not ICE on private type in field of unresolved struct 2025-08-14 15:59:32 +00:00
Vadim Petrochenkov
1652915816 resolve: Restructure resolve_ident_in_lexical_scope for better clarity 2025-08-14 18:50:58 +03:00
Vadim Petrochenkov
e6c96c151a resolve: Inline with_mod_rib 2025-08-14 18:50:57 +03:00
Vadim Petrochenkov
68ebbae2e8 resolve: Introduce RibKind::Block
to avoid confusing module items, blocks with items, and blocks without items.
2025-08-14 18:50:57 +03:00
Esteban Küber
eba1596ab1 Use default_field_values in Resolver 2025-08-14 15:48:47 +00:00
lcnr
3ebf611005 it's not a borrow checker limitation :< 2025-08-14 17:43:39 +02:00
lcnr
5c716bdc87 add comment 2025-08-14 17:43:39 +02:00
lcnr
8afe306c38 update comment 2025-08-14 16:07:24 +02:00
bors
be00ea1968 Auto merge of #144542 - sayantn:stabilize-sse4a-tbm, r=Amanieu,traviscross
Stabilize `sse4a` and `tbm` target features

This PR stabilizes the feature flag `sse4a_target_feature` and `tbm_target_feature` (tracking issue rust-lang/rust#44839).

# Public API
The 2 `x86` target features `sse4a` and `tbm`

Also, these were added in LLVM2.6 and LLVM3.4-rc1, respectively, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too!

As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now. The intrinsics were stabilized *long* ago, in 1.27.0

Reference PR:

- https://github.com/rust-lang/reference/pull/1949

cc `@rust-lang/lang`

`@rustbot` label I-lang-nominated
r? lang
2025-08-14 14:01:12 +00:00
xizheyin
3ce555f631 Add FnContext in parser for diagnostic
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-14 21:31:47 +08:00
LorrensP-2158466
ff560d3c9a resolve prelude import at build_reduced_graph phase 2025-08-14 15:28:35 +02:00
lcnr
7e29b8877a ignore head usages of ignored candidates 2025-08-14 14:38:00 +02:00
Zalathar
ecce90b3ef coverage: Remove intermediate data structures from mapping creation 2025-08-14 21:35:23 +10:00
Nicholas Nethercote
8296ad0456 Print regions in type_name.
Currently they are skipped, which is a bit weird, and it sometimes
causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`.

Most regions are erased by the time `type_name` does its work. So all
regions are now printed as `'_` in non-optional places. Not perfect, but
better than the status quo.

`c_name` is updated to trim lifetimes from MIR pass names, so that the
`PASS_NAMES` sanity check still works. It is also renamed as
`simplify_pass_type_name` and made non-const, because it doesn't need
to be const and the non-const implementation is much shorter.

The commit also renames `should_print_region` as
`should_print_optional_region`, which makes it clearer that it only
applies to some regions.

Fixes #145168.
2025-08-14 21:13:06 +10:00
Guillaume Gomez
762b7ecdb0 Rollup merge of #145372 - petrochenkov:noresmacpath, r=jackh726
resolve: Miscellaneous cleanups

See individual commits.

All noticed when reviewing recent PRs to name resolution.
2025-08-14 11:39:41 +02:00
Guillaume Gomez
707e956946 Rollup merge of #145361 - xizheyin:145294, r=compiler-errors
Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved

Fixes rust-lang/rust#145294

I initially tried the desired suggestion in this issue, but since that suggestion occurs in the expected type, it is inappropriate to suggest for expected expressions (see other suggest methods in the same file). I believe that suppressing the incorrect suggestion is the more appropriate choice here.

I opted for a slightly more general approach: when the expected type and actual type are the same ADT (e.g., both are Result in this example), we assume that code tend to compare the internal generic parameters(i.e. `Option<&str>` vs `Option<String>`, instead of `E = _` vs `Result<Option<String>>>`). When `E` is an unresolved infer type in the expected type (`_` in this example), we should not wrapp the actual type.

Two commits show the difference.

r? compiler
2025-08-14 11:39:40 +02:00
Guillaume Gomez
44d3217c20 Rollup merge of #145323 - scrabsha:push-pqwvmznzzmpr, r=jdonszelmann
Port the `#[linkage]` attribute to the new attribute system

r? `@jdonszelmann`
2025-08-14 11:39:39 +02:00
Guillaume Gomez
ad21c6d898 Rollup merge of #145266 - camsteffen:reduce-queries, r=petrochenkov
Reduce some queries around associated items
2025-08-14 11:39:38 +02:00
Guillaume Gomez
6ac5c28412 Rollup merge of #144727 - Stypox:add-tracing-to-resolve, r=RalfJung
Add tracing to resolve-related functions

Resolve-related functions are not called often but still make up for ~3% of execution time for non-repetitive programs (as seen in the first table below, obtained from running the rust snippet at the bottom with `n=1`). On the other hand, for repetitive programs they become less relevant (I tested the same snippet but with `n=100` and got ~1.5%), and it appears that only `try_resolve` is called more often (see the last two tables).

The first table was obtained by opening the trace file in https://ui.perfetto.dev and running the following query:

```sql
select "TOTAL PROGRAM DURATION" as name, count(*), max(ts + dur) as "sum(dur)", 100.0 as "%", null as "min(dur)", null as "max(dur)", null as "avg(dur)", null as "stddev(dur)" from slices union select "TOTAL OVER ALL SPANS (excluding events)" as name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" and dur > 0 union select name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" group by name order by sum(dur) desc, count(*) desc
```

<img width="1687" height="242" alt="image" src="https://github.com/user-attachments/assets/4d4bd890-869b-40f3-a473-8e4c42b02da4" />

The following two tables show how many `resolve` spans there per subname/subcategory, and how much time is spent in each. The first is for `n=1` and the second for `n=100`. The query that was used is:

```sql
select args.string_value as name, count(*), max(dur), avg(dur), sum(dur) from slices inner join args USING (arg_set_id) where args.key = "args." || slices.name and name = "resolve" group by args.string_value
```

<img width="1688" height="159" alt="image" src="https://github.com/user-attachments/assets/a8749856-c099-492e-a86e-6d67b146af9c" />

<img width="1688" height="159" alt="image" src="https://github.com/user-attachments/assets/ce3ac1b5-5c06-47d9-85a6-9b921aea348e" />

The snippet I tested with Miri to obtain the above traces is:

```rust
fn main() {
    let n: usize = std::env::args().nth(1).unwrap().parse().unwrap();
    let mut v = (0..n).into_iter().collect::<Vec<_>>();
    for i in &mut v {
        *i += 1;
    }
}
```
2025-08-14 11:39:35 +02:00
Ralf Jung
2330afab63 Apply suggestions from code review
Co-authored-by: Boxy <rust@boxyuwu.dev>
2025-08-14 09:44:22 +02:00
Ralf Jung
e2cc7757e1 avoid unnecessary type sanity checks 2025-08-14 09:44:22 +02:00
Ralf Jung
dbc030e034 shrink TestBranch::Constant and PatRangeBoundary::Finite 2025-08-14 09:44:22 +02:00