about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-07-19Auto merge of #144166 - matthiaskrgr:rollup-wccepuo, r=matthiaskrgrbors-35/+66
Rollup of 10 pull requests Successful merges: - rust-lang/rust#141076 (fix Zip unsoundness (again)) - rust-lang/rust#142444 (adding run-make test to autodiff) - rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner) - rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia) - rust-lang/rust#144083 (miri sleep tests: increase slack) - rust-lang/rust#144092 (bootstrap: Detect musl hosts) - rust-lang/rust#144098 (Do not lint private-in-public for RPITIT) - rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`) - rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling) - rust-lang/rust#144115 (fix outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-19Auto merge of #143784 - scottmcm:enums-again-new-ex2, r=dianqkbors-30/+130
Simplify discriminant codegen for niche-encoded variants which don't wrap across an integer boundary Inspired by rust-lang/rust#139729, this attempts to be a much-simpler and more-localized change while still making a difference. (Specifically, this does not try to solve the problem with select-sinking, leaving that to be fixed by https://github.com/llvm/llvm-project/issues/134024 -- once it gets released -- instead of in rustc's codegen.) What this *does* improve is checking for the variant in a 3+ variant enum when that variant is the type providing the niche. Something like `if let Foo::WithBool(_) = ...` previously compiled to `ugt(add(x, -2), 2)`, which is non-trivial to think about because it's depending on the unsigned wrapping to shift the 0/1 up above 2. With this PR it compiles to just `ult(x, 2)`, which is probably what you'd have written yourself if you were doing it by hand to look for "is this byte a bool?". That's done by leaving most of the codegen alone, but adding a couple new special cases to the `is_niche` check. The default looks at the relative discriminant, but in the common cases where there's no wraparound involved, we can just check the original value, rather than the offsetted one. The first commit just adds some tests, so the best way to see the effect of this change is to look at the second commit and how it updates the test expectations.
2025-07-19Rollup merge of #144115 - lcnr:auto-trait-comment, r=compiler-errorsMatthias Krüger-4/+2
fix outdated comment cc rust-lang/rust#84857 r? types
2025-07-19Rollup merge of #144103 - xizheyin:emit-unless, r=compiler-errorsMatthias Krüger-15/+15
Rename `emit_unless` to `emit_unless_delay` `emit_unless` is very unintuitive and confusing. The first impression is as if it will only emit if the parameter is true, without the altnative "delay as a bug". `emit_unless_delay` expresses two things: 1. emit unless the `delay` parameter is true 2. either *emit immediately* or *delay as bug* r? `@compiler-errors`
2025-07-19Rollup merge of #144098 - cjgillot:lint-rpitit, r=compiler-errorsMatthias Krüger-0/+8
Do not lint private-in-public for RPITIT Fixes the hard error introduced by https://github.com/rust-lang/rust/pull/143357 Instead of trying to accept this hard error directly, this PR copies tests from https://github.com/rust-lang/rust/pull/144020 and removes the error. If the behaviour is actually desirable, the second commit can be reverted with a proper crater run. cc https://github.com/rust-lang/rust/issues/143531 for bookkeeping r? `@compiler-errors`
2025-07-19Rollup merge of #143704 - compiler-errors:cycle-exotic, r=cjgillotMatthias Krüger-16/+28
Be a bit more careful around exotic cycles in in the inliner Copied from the comment here: https://github.com/rust-lang/rust/issues/143700#issuecomment-3053810353 --- ```rust #![feature(fn_traits)] #[inline] pub fn a() { FnOnce::call_once(a, ()); FnOnce::call_once(b, ()); } #[inline] pub fn b() { FnOnce::call_once(b, ()); FnOnce::call_once(a, ()); } ``` This should demonstrate the issue. For ease of discussion, I'm gonna call the two fn-def types `{a}` and `{b}`. When collecting the cyclic local callees in `mir_callgraph_cyclic` for `a`, we first check the first call terminator in `a`. We end up calling process on `<{a} as FnOnce>::call_once`, which ends up visiting `a`'s instance again. This is cyclical. However, we don't end up marking `FnOnce::call_once` as a cyclical def id because it's a foreign item. That's fine. When visiting the second call terminator in `a`, which is `<{b} as FnOnce>::call_once`, we end up recursing into `b`. We check the first terminator, which is `<{b} as FnOnce>::call_once`, but although that is its own mini cycle, it doesn't consider itself a cycle for the purpose of this query because it doesn't involve the *root*. However, when we visit the *second* terminator in `b`, which is `<{a} as FnOnce>::call_once`, we end up **erroneously** *not* considering that call to be cyclical since we've already inserted it into our set of seen instances, and as a consequence we don't recurse into it. This means that we never collect `b` as recursive. Do this in the flipped case too, and we end up having two functions which mututally do not consider each other to be recursive participants. This leads to a query cycle. --- I ended up also renaming some variables so I could more clearly understand their responsibilities in this code. Let me know if the renames are not welcome. Fixes https://github.com/rust-lang/rust/issues/143700 r? `@cjgillot`
2025-07-19Rollup merge of #142444 - KMJ-007:autodiff-codegen-test, r=ZuseZ4Matthias Krüger-0/+13
adding run-make test to autodiff r? `@ZuseZ4`
2025-07-19Auto merge of #144145 - matthiaskrgr:rollup-swc74s4, r=matthiaskrgrbors-501/+502
Rollup of 9 pull requests Successful merges: - rust-lang/rust#138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter) - rust-lang/rust#142673 (Show the offset, length and memory of uninit read errors) - rust-lang/rust#142693 (More robustly deal with relaxed bounds and improve their diagnostics) - rust-lang/rust#143382 (stabilize `const_slice_reverse`) - rust-lang/rust#143928 (opt-dist: make llvm builds optional) - rust-lang/rust#143961 (Correct which exploit mitigations are enabled by default) - rust-lang/rust#144050 (Fix encoding of link_section and no_mangle cross crate) - rust-lang/rust#144059 (Refactor `CrateLoader` into the `CStore`) - rust-lang/rust#144123 (Generalize `unsize` and `unsize_into` destinations) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-18Auto merge of #144140 - GuillaumeGomez:subtree-update_cg_gcc_2025-07-18, ↵bors-629/+82
r=GuillaumeGomez Subtree update cg gcc 2025 07 18 cc `@antoyo` r? ghost
2025-07-18Remove forgotten git annotationsGuillaume Gomez-7/+0
2025-07-19rename `emit_unless` to `emit_unless_delay`xizheyin-15/+15
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-18Rollup merge of #144123 - oli-obk:ctfe-unsize, r=RalfJungMatthias Krüger-4/+5
Generalize `unsize` and `unsize_into` destinations Just something that I noticed during other work. We do this for most such functions, so let's do it here, too. r? ``@RalfJung``
2025-07-18Rollup merge of #144059 - LorrensP-2158466:remove-crate-loader, r=petrochenkovMatthias Krüger-158/+169
Refactor `CrateLoader` into the `CStore` Removes the `CrateLoader` and moves the code to `CStore`. Now, if you want to use the `CrateLoader`, you can just use `CStore`. Should we rename `creader.rs` to `cstore.rs`? r? ``@petrochenkov``
2025-07-18Rollup merge of #144050 - JonathanBrouwer:cross-crate-reexport, r=jdonszelmannMatthias Krüger-4/+4
Fix encoding of link_section and no_mangle cross crate Fixes https://github.com/rust-lang/rust/issues/144004 ``@bjorn3`` suggested using the `codegen_fn_attrs` query but given that these attributes are not that common it's probably fine to just always encode them. I can also go for that solution if it is preferred but that would require more changes. r? ``@jdonszelmann`` ``@fmease`` (whoever feels like it)
2025-07-18Rollup merge of #142693 - fmease:unbound-bettering, r=compiler-errorsMatthias Krüger-316/+270
More robustly deal with relaxed bounds and improve their diagnostics Scaffolding for https://github.com/rust-lang/rust/issues/135229 (CC https://github.com/rust-lang/rust/pull/135331) Fixes https://github.com/rust-lang/rust/issues/136944 (6th commit). Fixes https://github.com/rust-lang/rust/issues/142718 (8th commit).
2025-07-18Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJungMatthias Krüger-10/+28
Show the offset, length and memory of uninit read errors r? ``@RalfJung`` I want to improve memory dumps in general. Not sure yet how to do so best within rust diagnostics, but in a perfect world I could generate a dummy in-memory file (that contains the rendered memory dump) that we then can then provide regular rustc `Span`s to. So we'd basically report normal diagnostics for them with squiggly lines and everything.
2025-07-18Rollup merge of #138554 - xizheyin:issue-138401, r=chenyukangMatthias Krüger-9/+26
Distinguish delim kind to decide whether to emit unexpected closing delimiter Fixes #138401
2025-07-18Be a bit more careful around exotic cycles in in the inlinerMichael Goulet-16/+28
2025-07-18Merge commit 'f682d09eefc6700b9e5851ef193847959acf4fac' into ↵Guillaume Gomez-625/+85
subtree-update_cg_gcc_2025-07-18
2025-07-18Auto merge of #143845 - cjgillot:stability-query, r=jieyouxubors-653/+507
Split-up stability_index query This PR aims to move deprecation and stability processing away from the monolithic `stability_index` query, and directly implement `lookup_{deprecation,stability,body_stability,const_stability}` queries. The basic idea is to: - move per-attribute sanity checks into `check_attr.rs`; - move attribute compatibility checks into the `MissingStabilityAnnotations` visitor; - progressively dismantle the `Annotator` visitor and the `stability_index` query. The first commit contains functional change, and now warns when `#[automatically_derived]` is applied on a non-trait impl block. The other commits should not change visible behaviour. Perf in https://github.com/rust-lang/rust/pull/143845#issuecomment-3066308630 shows small but consistent improvement, except for unused-warnings case. That case being a stress test, I'm leaning towards accepting the regression. This PR changes `check_attr`, so has a high conflict rate on that file. This should not cause issues for review.
2025-07-18Generalize `unsize` and `unsize_into` destinationsOli Scherer-4/+5
2025-07-18Rollup merge of #144029 - lichuang:fix_issue_143740, r=compiler-errorsMatthias Krüger-1/+2
Fix wrong messages from methods with the same name from different traits fix issue https://github.com/rust-lang/rust/issues/143740
2025-07-18Rollup merge of #144013 - petrochenkov:disambunder, r=oli-obkMatthias Krüger-45/+58
resolve: Make disambiguators for underscore bindings module-local Disambiguators attached to underscore name bindings (like `const _: u8 = something;`) do not need to be globally unique, they just need to be unique inside the module in which they live, because the bindings in a module are basically kept as `Map<BindingKey, SomeData>`. Also, the specific values of the disambiguators are not important, so a glob import of `const _` may have a different disambiguator than the original `const _` itself. So in this PR the disambiguator is just set to the current number of bindings in the module. This removes one more piece of global mutable state from resolver and unblocks https://github.com/rust-lang/rust/pull/143884.
2025-07-18Rollup merge of #143997 - Coder-256:stable-mir-macro-hygiene, r=oli-obkMatthias Krüger-9/+9
Use $crate in macros for rustc_public (aka stable_mir) This makes `#[macro_use] extern crate rustc_public` unnecessary (which brings all of `rustc_public`'s macros into scope for the entire crate); instead, now you can simply use `rustc_public::run!()`.
2025-07-18Rollup merge of #143925 - oli-obk:slice-const-partialeq, r=fee1-deadMatthias Krüger-5/+66
Make slice comparisons const This needed a fix for `derive_const`, too, as it wasn't usable in libcore anymore as trait impls need const stability attributes. I think we can't use the same system as normal trait impls while `const_trait_impl` is still unstable. r? ```@fee1-dead``` cc rust-lang/rust#143800
2025-07-18Rollup merge of #143699 - compiler-errors:async-drop-fund, r=oli-obkMatthias Krüger-2/+7
Make `AsyncDrop` check that it's being implemented on a local ADT Fixes https://github.com/rust-lang/rust/issues/143691
2025-07-18Rollup merge of #143280 - xizheyin:143152-1, r=compiler-errorsMatthias Krüger-1/+13
Remove duplicate error about raw underscore lifetime Fixes rust-lang/rust#143152 r? ```@fee1-dead```
2025-07-18Deduplicate `unmatched_delims` in `rustc_parse` to reduce confusionxizheyin-9/+26
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-18inline CrateLoader inside of CStoreLorrensP-2158466-158/+169
2025-07-18HIR ty lowering: Validate `PointeeSized` boundsLeón Orell Valerian Liehr-74/+34
2025-07-18Don't reject *multiple* relaxed bounds, reject *duplicate* ones.León Orell Valerian Liehr-29/+17
Having multiple relaxed bounds like `?Sized + ?Iterator` is actually *fine*. We actually want to reject *duplicate* relaxed bounds like `?Sized + ?Sized` because these most certainly represent a user error. Note that this doesn't mean that we accept more code because a bound like `?Iterator` is still invalid as it's not relaxing a *default* trait and the only way to define / use more default bounds is under the experimental and internal feature `more_maybe_bounds` plus `lang_items` plus unstable flag `-Zexperimental-default-bounds` (historical context: for the longest time, bounds like `?Iterator` were actually allowed and lead to a hard warning). Ultimately, this simply *reframes* the diagnostic. The scope of `more_maybe_bounds` / `-Zexperimental-default-bounds` remains unchanged as well.
2025-07-18Reword diagnostic about relaxing non-`Sized` boundLeón Orell Valerian Liehr-32/+42
* The phrasing "only does something for" made sense back when this diagnostic was a (hard) warning. Now however, it's simply a hard error and thus completely rules out "doing something". * The primary message was way too long * The new wording more closely mirrors the wording we use for applying other bound modifiers (like `const` and `async`) to incompatible traits. * "all other traits are not bound by default" is no longer accurate under Sized Hierarchy. E.g., traits and assoc tys are (currently) bounded by `MetaSized` by default but can't be relaxed using `?MetaSized` (instead, you relax it by adding `PointeeSized`). * I've decided against adding any diagnositic notes or suggestions for now like "trait `Trait` can't be relaxed as it's not bound by default" which would be incorrect for `MetaSized` and assoc tys as mentioned above) or "consider changing `?MetaSized` to `PointeeSized`" as the Sized Hierarchy impl is still WIP)
2025-07-18Reword diagnostics about relaxed bounds in invalid contextsLeón Orell Valerian Liehr-5/+21
2025-07-18Show the memory of uninit readsOli Scherer-7/+22
2025-07-18update commentlcnr-4/+2
2025-07-18Auto merge of #144109 - matthiaskrgr:rollup-mz0mrww, r=matthiaskrgrbors-399/+525
Rollup of 11 pull requests Successful merges: - rust-lang/rust#142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - rust-lang/rust#143271 (Store the type of each GVN value) - rust-lang/rust#143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - rust-lang/rust#143719 (Emit warning when there is no space between `-o` and arg) - rust-lang/rust#143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - rust-lang/rust#143891 (Port `#[coverage]` to the new attribute system) - rust-lang/rust#143967 (constify `Option` methods) - rust-lang/rust#144008 (Fix false positive double negations with macro invocation) - rust-lang/rust#144010 (Boostrap: add warning on `optimize = false`) - rust-lang/rust#144049 (rustc-dev-guide subtree update) - rust-lang/rust#144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-18Rollup merge of #144008 - anatawa12:fix-double-negations, r=compiler-errorsMatthias Krüger-0/+2
Fix false positive double negations with macro invocation This PR fixes false positive double_negations lint when macro expansion has negation and macro caller also has negations. Fix rust-lang/rust#143980
2025-07-18Rollup merge of #143891 - scrabsha:push-xxtttopqoprr, r=jdonszelmannMatthias Krüger-28/+149
Port `#[coverage]` to the new attribute system r? ``````@jdonszelmann``````
2025-07-18Rollup merge of #143846 - usamoi:gc, r=bjorn3Matthias Krüger-39/+1
pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests Exported symbols are added as GC roots in linking, so `--gc-sections` won't hurt `-Zexport-executable-symbols`. Fixes the run-make test to work on Linux. Enable the ui test on more targets. cc rust-lang/rust#84161
2025-07-18Rollup merge of #143719 - xizheyin:142812-1, r=jieyouxuMatthias Krüger-0/+51
Emit warning when there is no space between `-o` and arg Closes rust-lang/rust#142812 `getopt` doesn't seem to have an API to check this, so we have to check the args manually. r? compiler
2025-07-18Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errorsMatthias Krüger-34/+67
fix `-Zsanitizer=kcfi` on `#[naked]` functions fixes https://github.com/rust-lang/rust/issues/143266 With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call). My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`. r? codegen ````@rustbot```` label +A-naked cc ````@maurer```` ````@rcvalle````
2025-07-18Rollup merge of #143271 - cjgillot:gvn-types, r=oli-obkMatthias Krüger-298/+255
Store the type of each GVN value MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities. This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code. Fixes rust-lang/rust#128094 Fixes rust-lang/rust#135128 r? ``````@ghost`````` for perf
2025-07-18Auto merge of #143545 - compiler-errors:coroutine-obl, r=oli-obkbors-56/+373
`-Zhigher-ranked-assumptions`: Consider WF of coroutine witness when proving outlives assumptions ### TL;DR This PR introduces an unstable flag `-Zhigher-ranked-assumptions` which tests out a new algorithm for dealing with some of the higher-ranked outlives problems that come from auto trait bounds on coroutines. See: * rust-lang/rust#110338 While it doesn't fix all of the issues, it certainly fixed many of them, so I'd like to get this landed so people can test the flag on their own code. ### Background Consider, for example: ```rust use std::future::Future; trait Client { type Connecting<'a>: Future + Send where Self: 'a; fn connect(&self) -> Self::Connecting<'_>; } fn call_connect<C>(c: C) -> impl Future + Send where C: Client + Send + Sync, { async move { c.connect().await } } ``` Due to the fact that we erase the lifetimes in a coroutine, we can think of the interior type of the async block as something like: `exists<'r, 's> { C, &'r C, C::Connecting<'s> }`. The first field is the `c` we capture, the second is the auto-ref that we perform on the call to `.connect()`, and the third is the resulting future we're awaiting at the first and only await point. Note that every region is uniquified differently in the interior types. For the async block to be `Send`, we must prove that both of the interior types are `Send`. First, we have an `exists<'r, 's>` binder, which needs to be instantiated universally since we treat the regions in this binder as *unknown*[^exist]. This gives us two types: `{ &'!r C, C::Connecting<'!s> }`. Proving `&'!r C: Send` is easy due to a [`Send`](https://doc.rust-lang.org/nightly/std/marker/trait.Send.html#impl-Send-for-%26T) impl for references. Proving `C::Connecting<'!s>: Send` can only be done via the item bound, which then requires `C: '!s` to hold (due to the `where Self: 'a` on the associated type definition). Unfortunately, we don't know that `C: '!s` since we stripped away any relationship between the interior type and the param `C`. This leads to a bogus borrow checker error today! ### Approach Coroutine interiors are well-formed by virtue of them being borrow-checked, as long as their callers are invoking their parent functions in a well-formed way, then substitutions should also be well-formed. Therefore, in our example above, we should be able to deduce the assumption that `C: '!s` holds from the well-formedness of the interior type `C::Connecting<'!s>`. This PR introduces the notion of *coroutine assumptions*, which are the outlives assumptions that we can assume hold due to the well-formedness of a coroutine's interior types. These are computed alongside the coroutine types in the `CoroutineWitnessTypes` struct. When we instantiate the binder when proving an auto trait for a coroutine, we instantiate the `CoroutineWitnessTypes` and stash these newly instantiated assumptions in the region storage in the `InferCtxt`. Later on in lexical region resolution or MIR borrowck, we use these registered assumptions to discharge any placeholder outlives obligations that we would otherwise not be able to prove. ### How well does it work? I've added a ton of tests of different reported situations that users have shared on issues like rust-lang/rust#110338, and an (anecdotally) large number of those examples end up working straight out of the box! Some limitations are described below. ### How badly does it not work? The behavior today is quite rudimentary, since we currently discharge the placeholder assumptions pretty early in region resolution. This manifests itself as some limitations on the code that we accept. For example, `tests/ui/async-await/higher-ranked-auto-trait-11.rs` continues to fail. In that test, we must prove that a placeholder is equal to a universal for a param-env candidate to hold when proving an auto trait, e.g. `'!1 = 'a` is required to prove `T: Trait<'!1>` in a param-env that has `T: Trait<'a>`. Unfortunately, at that point in the MIR body, we only know that the placeholder is equal to some body-local existential NLL var `'?2`, which only gets equated to the universal `'a` when being stored into the return local later on in MIR borrowck. This could be fixed by integrating these assumptions into the type outlives machinery in a more first-class way, and delaying things to the end of MIR typeck when we know the full relationship between existential and universal NLL vars. Doing this integration today is quite difficult today. `tests/ui/async-await/higher-ranked-auto-trait-11.rs` fails because we don't compute the full transitive outlives relations between placeholders. In that test, we have in our region assumptions that some `'!1 = '!2` and `'!2 = '!3`, but we must prove `'!1 = '!3`. This can be fixed by computing the set of coroutine outlives assumptions in a more transitive way, or as I mentioned above, integrating these assumptions into the type outlives machinery in a more first-class way, since it's already responsible for the transitive outlives assumptions of universals. ### Moving forward I'm still quite happy with this implementation, and I'd like to land it for testing. I may work on overhauling both the way we compute these coroutine assumptions and also how we deal with the assumptions during (lexical/nll) region checking. But for now, I'd like to give users a chance to try out this new `-Zhigher-ranked-assumptions` flag to uncover more shortcomings. [^exist]: Instantiating this binder with infer regions would be incomplete, since we'd be asking for *some* instantiation of the interior types, not proving something for *all* instantiations of the interior types.
2025-07-18AST lowering: More robustly deal with relaxed boundsLeón Orell Valerian Liehr-149/+145
2025-07-18Update comment about `where Ty:`León Orell Valerian Liehr-10/+6
We no longer move trait predicates where the self ty is a ty param to "the bounds of a ty param".
2025-07-18HIR ty lowering: Validate relaxed bounds in trait object typesLeón Orell Valerian Liehr-3/+0
Only relevant to the internal feature `more_maybe_bounds`.
2025-07-18HIR ty lowering: Simplify signature of `lower_poly_trait_ref`León Orell Valerian Liehr-26/+17
2025-07-17Do not check privacy for RPITIT.Camille GILLOT-0/+8
2025-07-17Fix formatting.Camille GILLOT-6/+7
2025-07-17Correct comments.Camille GILLOT-4/+2