Commit Graph

300570 Commits

Author SHA1 Message Date
Stypox
708dc15cf1 Add InterpCx::layout_of with tracing, shadowing LayoutOf 2025-06-27 11:49:22 +02:00
bjorn3
4b7711520b Update comments 2025-06-27 09:49:18 +00:00
Hayashi Mikihiro
08a36de776 use placeholder_snippet
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2025-06-27 18:49:08 +09:00
Hayashi Mikihiro
6759aacb29 use name_generator
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2025-06-27 18:48:39 +09:00
xizheyin
e8ff13cd33 Fix typo
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-27 17:44:15 +08:00
Bastian Kersting
1087042e22 Insert checks for enum discriminants when debug assertions are enabled
Similar to the existing nullpointer and alignment checks, this checks
for valid enum discriminants on creation of enums through unsafe
transmutes. Essentially this sanitizes patterns like the following:
```rust
let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) };
```
An extension of this check will be done in a follow-up that explicitly
sanitizes for extern enum values that come into Rust from e.g. C/C++.

This check is similar to Miri's capabilities of checking for valid
construction of enum values.

This PR is inspired by saethlin@'s PR
https://github.com/rust-lang/rust/pull/104862. Thank you so much for
keeping this code up and the detailed comments!

I also pair-programmed large parts of this together with vabr-g@.
2025-06-27 09:37:36 +00:00
bjorn3
753c73a349 Split exported_symbols for generic and non-generic symbols
This reduces metadata decoder overhead during the monomorphization collector.
2025-06-27 09:34:20 +00:00
Stypox
5e1082899b Add tracing for instantiate_from_frame_and_normalize_erasing_regions 2025-06-27 11:32:32 +02:00
Stypox
89a636fb12 Add tracing to validate_operand 2025-06-27 10:15:27 +02:00
Oli Scherer
c51f05be30 Report infer ty errors during hir ty lowering
This centralizes the placeholder type error reporting in one location, but it also exposes the granularity at which we convert things from hir to ty more. E.g. previously infer types in where bounds were errored together with the function signature, but now they are independent.
2025-06-27 07:51:38 +00:00
Jonathan Brouwer
f98ea3d144 Port #[rustc_layout_scalar_valid_range_start/end] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-27 09:08:21 +02:00
bors
d51b6f9712 Auto merge of #142816 - Shourya742:2025-06-21-add-caching-layer-to-bootstrap, r=Kobzol
Add caching layer to bootstrap

This PR adds a caching layer to the bootstrap command execution context. It is still a work in progress but introduces the initial infrastructure for it.

r? `@Kobzol`
2025-06-27 07:08:16 +00:00
Jonathan Brouwer
9e35684072 Port #[used] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-27 08:58:26 +02:00
Ralf Jung
1365d3ba1f codegen_fn_attrs: make comment more precise 2025-06-27 08:39:17 +02:00
Lukas Wirth
502bac3449 Merge pull request #20110 from ChayimFriedman2/ambiguous-float
fix: Fix completion in when typing `integer.|`
2025-06-27 05:42:09 +00:00
David Wood
1fd13fddba tests: add #![rustc_no_implicit_bounds]
After reviewing all tests with `?Sized` and discussing with lcnr, these
tests seem like they could probably benefit from
`#![rustc_no_implicit_bounds]`.
2025-06-27 05:34:08 +00:00
bit-aloo
591df6c1b0 disable caching for cargo commands 2025-06-27 10:49:43 +05:30
bit-aloo
0eab328414 move execution context inside exec and prune execution context, use command directly from bootstrap command inside start, and not via as_command_mut 2025-06-27 10:39:35 +05:30
bit-aloo
18090924f9 make DeferredCommand a must use and move mark_as_executed inside finish process 2025-06-27 10:38:44 +05:30
bit-aloo
28f97108f1 add caching info on bootstrap command 2025-06-27 10:38:44 +05:30
bit-aloo
2e2baed5df refactor deferred command and make it compatible with new commandstate, remove extra caching logic from run and re-structure the changes 2025-06-27 10:38:42 +05:30
bit-aloo
2cf6552f5d add new command state in execution context 2025-06-27 10:38:07 +05:30
bit-aloo
5291c9fcec add do_not_cache method and update the warning on as_command_mut 2025-06-27 10:38:07 +05:30
bit-aloo
08d7b29719 use metadata for command cache key spawning directly from command 2025-06-27 10:38:07 +05:30
bit-aloo
42875e1a3b add command cache key, move to osstring, add should cache to bootstrap command 2025-06-27 10:38:06 +05:30
bit-aloo
59cb00ffbe add caching fields inside Bootstrap command 2025-06-27 10:38:06 +05:30
bendn
57cb419cc5 tests 2025-06-27 12:07:52 +07:00
bors
df32e15c56 Auto merge of #142223 - compiler-errors:perf-wf, r=lcnr
Fast path for WF goals in new solver

Hopefully self-explanatory.
2025-06-27 03:57:45 +00:00
bors
e61dd437f3 Auto merge of #143074 - compiler-errors:rollup-cv64hdh, r=compiler-errors
Rollup of 18 pull requests

Successful merges:

 - rust-lang/rust#137843 (make RefCell unstably const)
 - rust-lang/rust#140942 (const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns)
 - rust-lang/rust#142549 (small iter.intersperse.fold() optimization)
 - rust-lang/rust#142637 (Remove some glob imports from the type system)
 - rust-lang/rust#142647 ([perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation)
 - rust-lang/rust#142700 (Remove incorrect comments in `Weak`)
 - rust-lang/rust#142927 (Add note to `find_const_ty_from_env`)
 - rust-lang/rust#142967 (Fix RwLock::try_write documentation for WouldBlock condition)
 - rust-lang/rust#142986 (Port `#[export_name]` to the new attribute parsing infrastructure)
 - rust-lang/rust#143001 (Rename run always )
 - rust-lang/rust#143010 (Update `browser-ui-test` version to `0.20.7`)
 - rust-lang/rust#143015 (Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`)
 - rust-lang/rust#143033 (Expand const-stabilized API links in relnotes)
 - rust-lang/rust#143041 (Remove cache for citool)
 - rust-lang/rust#143056 (Move an ACE test out of the GCI directory)
 - rust-lang/rust#143059 (Fix 1.88 relnotes)
 - rust-lang/rust#143067 (Tracking issue number for `iter_macro`)
 - rust-lang/rust#143073 (Fix some fixmes that were waiting for let chains)

Failed merges:

 - rust-lang/rust#143020 (codegen_fn_attrs: make comment more precise)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-27 00:44:20 +00:00
Michael Goulet
cb0b62121c Rollup merge of #143073 - yotamofek:pr/fix-let-chains-fixmes, r=compiler-errors
Fix some fixmes that were waiting for let chains

Was inspired by looking at rust-lang/rust#143066 and spotting two fixmes that were missed, so... r? `@compiler-errors`  😅

Yay, let chains!
2025-06-26 20:15:30 -04:00
Michael Goulet
434e3e5d45 Rollup merge of #143067 - GrigorenkoPV:142269, r=workingjubilee
Tracking issue number for `iter_macro`

Tracking issue: rust-lang/rust#142269
2025-06-26 20:15:30 -04:00
Michael Goulet
93810c9430 Rollup merge of #143059 - jieyouxu:slice-as-chunks, r=cuviper
Fix 1.88 relnotes

- Use stable std links for `impl Default for {*const,*mut} T`
- Add missing relnotes for https://github.com/rust-lang/rust/pull/139656
    ```rs
    impl [T] {
        const fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]);
        const fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]);
        const unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]];
        const fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]);
        const fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]);
        const unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]];
    }
    ```
- Add missing `mod ffi::c_str` and `hint::select_unpredictable`

r? `@cuviper`
2025-06-26 20:15:29 -04:00
Michael Goulet
49944c3685 Rollup merge of #143056 - fmease:mv-ace-test-out-of-gci-dir, r=BoxyUwU
Move an ACE test out of the GCI directory

In https://github.com/rust-lang/rust/pull/122988, a test pertaining to `associated_const_equality` was placed into the directory meant for `generic_const_items`. Let's move it where it belongs.

While at it, I took the time to further minimize the test and to add a description. You can use 1.67.1 (as reported in rust-lang/rust#108220) to verify that I didn't butcher it. For additional context, the issue was likely fixed in rust-lang/rust#112718 (but I'm also cc'ing rust-lang/rust#140467 which further fixed things up and has more context).

I only performed quick and dirty git/GitHub archeology, so I don't have the full picture here. For one, I'm not even sure if this regression test is worth it.

Anyway, I just want it gone from the GCI dir :)
2025-06-26 20:15:29 -04:00
Michael Goulet
4a32934022 Rollup merge of #143041 - Kobzol:matrix-no-cache, r=marcoieni
Remove cache for citool

I'm not sure why, but after the citool cache is loaded, compiling just build_helper and citool takes ~30s, which is very slow. Combined with the fact that just loading the cache takes ~15s, and we have to run a hacky workflow on master, which results [in benign failures](https://github.com/rust-lang/rust/actions?query=branch%3Amaster), I don't think it's worth it to use the cache here anymore.

A fresh build, now that we don't run citool tests on PR CI, takes just ~35-40s, so it's actually faster now *not* to cache. The trade-offs change quite often :)

r? ``@ghost``
2025-06-26 20:15:28 -04:00
Michael Goulet
335fde510b Rollup merge of #143033 - jieyouxu:expand-apis, r=cuviper
Expand const-stabilized API links in relnotes

Noticed while looking at the relnotes blog post https://github.com/rust-lang/blog.rust-lang.org/pull/1651#discussion_r2165569631.

r? ````@cuviper````
2025-06-26 20:15:27 -04:00
Michael Goulet
5fca4bd6d4 Rollup merge of #143015 - samueltardieu:pin-macro-diag-item, r=Urgau
Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`
2025-06-26 20:15:26 -04:00
Michael Goulet
4dca555efa Rollup merge of #143010 - GuillaumeGomez:update-browser-ui-test, r=Kobzol
Update `browser-ui-test` version to `0.20.7`

This new version fixes some bugs and improve error messages.

r? `````@Kobzol`````
2025-06-26 20:15:25 -04:00
Michael Goulet
80972ae68e Rollup merge of #143001 - Shourya742:2025-06-25-rename-run-always, r=Kobzol
Rename run always

This PR renames run_always to run_to_dry_run for better clarity, making the field's purpose more explicit and avoiding confusion with command caching behavior.

r? ``````@Kobzol``````
2025-06-26 20:15:24 -04:00
Michael Goulet
d3866007fa Rollup merge of #142986 - JonathanBrouwer:export_name_parser, r=jdonszelmann
Port `#[export_name]` to the new attribute parsing infrastructure

This PR contains two changes, in separate commits for reviewability:
- Ports `export_name` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197
- Moves the check for mixing export_name/no_mangle to check_attr.rs and improve the error message, which previously had a mix of 2021/2024 edition syntax

r? ``@jdonszelmann``
2025-06-26 20:15:23 -04:00
Michael Goulet
c5ac143b22 Rollup merge of #142967 - krikera:fix-rwlock-try-write-docs, r=jhpratt
Fix RwLock::try_write documentation for WouldBlock condition

Fix RwLock::try_write documentation for WouldBlock condition

The documentation incorrectly stated that try_write only fails when
'already locked exclusively', but it actually fails when there are
either shared (read) or exclusive (write) locks.

Fixes rust-lang/rust#142852
2025-06-26 20:15:22 -04:00
Michael Goulet
d712024aee Rollup merge of #142927 - compiler-errors:note-find-const, r=BoxyUwU
Add note to `find_const_ty_from_env`

Add a note to `find_const_ty_from_env` to explain why it has an `unwrap` which "often" causes ICEs.

Also, uplift it into the new trait solver. This avoids needing to go through the interner to call this method which is otherwise an inherent method in the compiler. I can remove this part if desired.

r? `@boxyuwu`
2025-06-26 20:15:22 -04:00
Michael Goulet
58cda76585 Rollup merge of #142700 - theemathas:remove-weak-comment, r=ibraheemdev
Remove incorrect comments in `Weak`

It is currently possible to create a dangling `Weak` to a DST by calling `Weak::new()` for a sized type, then doing an unsized coercion. Therefore, the comments are wrong.

These comments were added in <https://github.com/rust-lang/rust/pull/73845>. As far as I can tell, the guarantee in the comment was only previously used in the `as_ptr` method. However, the current implementation of `as_ptr` no longer relies on this guarantee.
2025-06-26 20:15:20 -04:00
Michael Goulet
25e239c193 Rollup merge of #142647 - compiler-errors:less-work-in-coherence, r=lcnr
[perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation

First compute hard errors without diagnostics, then ambiguities with diagnostics since we need to know if any of them overflowed.
2025-06-26 20:15:20 -04:00
Michael Goulet
48d311898b Rollup merge of #142637 - compiler-errors:less-globs, r=lcnr
Remove some glob imports from the type system

Namely, remove the glob imports for `BoundRegionConversionTime`, `RegionVariableOrigin`, `SubregionOrigin`, `TyOrConstInferVar`, `RegionResolutionError`, `SelectionError`, `ProjectionCandidate`, `ProjectionCandidateSet`, and some more specific scoped globs (like `Inserted` in the impl overlap graph construction.

These glob imports are IMO very low value, since they're not used nearly as often as other globs (like `TyKind`).
2025-06-26 20:15:19 -04:00
Michael Goulet
9820197e12 Rollup merge of #142549 - the8472:intersperse-fold-tweak, r=tgross35
small iter.intersperse.fold() optimization

No need to call into fold when the first item is already None, this avoids some redundant work for empty iterators.

"But it uses Fuse" one might want to protest, but Fuse is specialized and may call into the inner iterator anyway.
2025-06-26 20:15:18 -04:00
Michael Goulet
36cde67894 Rollup merge of #140942 - RalfJung:const-ref-to-mut, r=oli-obk
const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns

This fixes https://github.com/rust-lang/rust/issues/140653 by accepting code such as this:
```rust
static FOO: AtomicU32 = AtomicU32::new(0);
const C: &'static AtomicU32 = &FOO;
```
This can be written entirely in safe code, so there can't really be anything wrong with it.

We also accept the much more questionable following code, since it looks very similar to the interpreter:
```rust
static mut FOO2: u32 = 0;
const C2: &'static u32 = unsafe { &mut FOO2 };
```
Using this without causing UB is at least very hard (the details are unclear since it is related to how the aliasing model deals with the staging of const-eval vs runtime code).

If a constant like `C2` is used as a pattern, we emit an error:
```
error: constant BAD_PATTERN cannot be used as pattern
  --> $DIR/const_refs_to_static_fail.rs:30:9
   |
LL |         BAD_PATTERN => {},
   |         ^^^^^^^^^^^
   |
   = note: constants that reference mutable or external memory cannot be used as pattern
```
(If you somehow manage to build a pattern with constant `C`, you'd get the same error, but that should be impossible: we don't have a type that can be used in patterns and that has interior mutability.)

The same treatment is afforded for shared references to `extern static`, for the same reason: the const evaluation is entirely fine with it, we just can't build a pattern for it -- and when using interior mutability, this can be totally sound.

We do still not accept anything where there is an `&mut` in the final value of the const, as that should always require unsafe code and it's hard to imagine a sound use-case that would require this.
2025-06-26 20:15:17 -04:00
Michael Goulet
0446a0d14b Rollup merge of #137843 - Daniel-Aaron-Bloom:const_cell, r=oli-obk
make RefCell unstably const

Now that we can do interior mutability in `const`, most of the `RefCell` API can be `const fn`. The main exceptions are APIs which use `FnOnce` (`RefCell::replace_with` and `Ref[Mut]::[filter_]map[_split]`) and `RefCell::take` which calls `Default::default`.

Tracking issue: #137844
2025-06-26 20:15:17 -04:00
Yotam Ofek
174cb47a46 Fix some fixmes that were waiting for let chains 2025-06-26 23:36:46 +00:00
Josh Triplett
07760822db mbe: Fold calls to check_meta_variables into the parser loop 2025-06-26 15:20:56 -07:00
Josh Triplett
6c04e0a7ae Rewrite macro_rules! parser to not use the MBE engine itself
The `macro_rules!` parser was written to match the series of rules using
the macros-by-example (MBE) engine and a hand-written equivalent of the
left-hand side of a MBE macro. This was complex to read, difficult to
extend, and produced confusing error messages. Because it was using the
MBE engine, any parse failure would be reported as if some macro was
being applied to the `macro_rules!` invocation itself; for instance,
errors would talk about "macro invocation", "macro arguments", and
"macro call", when they were actually about the macro *definition*.

And in practice, the `macro_rules!` parser only used the MBE engine to
extract the left-hand side and right-hand side of each rule as a token
tree, and then parsed the rest using a separate parser.

Rewrite it to parse the series of rules using a simple loop, instead.
This makes it more extensible in the future, and improves error
messages. For instance, omitting a semicolon between rules will result
in "expected `;`" and "unexpected token", rather than the confusing "no
rules expected this token in macro call".

This work was greatly aided by pair programming with Vincenzo Palazzo
and Eric Holk.
2025-06-26 15:20:42 -07:00