9043 Commits

Author SHA1 Message Date
Matthias Krüger
b3827e4f37
Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJung
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-18 19:14:43 +02:00
bors
6c0a912e5a Auto merge of #144109 - matthiaskrgr:rollup-mz0mrww, r=matthiaskrgr
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-18 05:43:22 +00:00
Matthias Krüger
accf61dd42
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors
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-18 04:27:51 +02:00
bors
1aa5b22465 Auto merge of #143545 - compiler-errors:coroutine-obl, r=oli-obk
`-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-18 02:23:50 +00:00
bors
e466296627 Auto merge of #141762 - compiler-errors:witnesser, r=lcnr
Unify `CoroutineWitness` sooner in typeck, and stall coroutine obligations based off of `TypingEnv`

* Stall coroutine obligations based off of `TypingMode` in the old solver.
* Eagerly assign `TyKind::CoroutineWitness` to the witness arg of coroutines during typeck, rather than deferring them to the end of typeck.

r? lcnr

This is part of https://github.com/rust-lang/rust/issues/143017.
2025-07-17 20:02:22 +00:00
Oli Scherer
12eedafc38 Report the range of uninit bytes in CTFE errors 2025-07-17 20:00:51 +00:00
Michael Goulet
216cdb7b22 Eagerly unify coroutine witness in old solver 2025-07-17 17:42:28 +00:00
Deadbeef
69326878ee parse const trait Trait 2025-07-17 18:06:26 +08:00
bors
f8f6997469 Auto merge of #144044 - fmease:rollup-kg413pt, r=fmease
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test)
 - rust-lang/rust#143388 (Various refactors to the LTO handling code)
 - rust-lang/rust#143409 (Enable xgot feature for mips64 musl targets)
 - rust-lang/rust#143592 (UWP: link ntdll functions using raw-dylib)
 - rust-lang/rust#143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call)
 - rust-lang/rust#143678 (Added error for invalid char cast)
 - rust-lang/rust#143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - rust-lang/rust#143829 (Trim `BorrowedCursor` API)
 - rust-lang/rust#143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test)
 - rust-lang/rust#143856 (Linting public reexport of private dependencies)
 - rust-lang/rust#143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates)
 - rust-lang/rust#143922 (Improve path segment joining)
 - rust-lang/rust#143964 (Fix handling of SCRIPT_ARG in docker images)
 - rust-lang/rust#144002 (Update poison.rs)
 - rust-lang/rust#144016 (trait_sel: `MetaSized` always holds temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-17 05:24:30 +00:00
León Orell Valerian Liehr
7a85c5964d
Rollup merge of #143922 - nnethercote:join_path, r=petrochenkov
Improve path segment joining

Currently paths are joined with `::` in many places, in a variety of ways. This PR unifies things.

r? ``@petrochenkov``
2025-07-17 03:58:34 +02:00
León Orell Valerian Liehr
83288db888
Rollup merge of #143595 - fee1-dead-contrib:push-sylpykzkmynr, r=RalfJung,fee1-dead
add `const_make_global`; err for `const_allocate` ptrs if didn't call

Implements as discussed on Zulip: [#t-compiler/const-eval > const heap](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const.20heap/with/527125421)

r? ```@rust-lang/wg-const-eval```

Fixes https://github.com/rust-lang/rust/issues/129233
2025-07-17 03:58:30 +02:00
bors
014bd8290f Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwU
Implement unstable trait impl

This PR allows marking impls of stable trait with stable type as unstable.

## Approach

In std/core, an impl can be marked as unstable by annotating it with ``#[unstable_feature_bound(feat_name)]``. This will add a ``ClauseKind::Unstable_Feature(feat_name)`` to the list of predicates in ``predicates_of`` .

When an unstable impl's function is called, we will first iterate through all the goals in ``param_env`` to check if there is any ``ClauseKind::UnstableFeature(feat_name)`` in ``param_env``.

The existence of ``ClauseKind::Unstable_Feature(feat_name)`` in ``param_env`` means an``#[unstable_feature_bound(feat_name)]`` is present at the call site of the function, so we allow the check to succeed in this case.

If ``ClauseKind::UnstableFeature(feat_name)`` does not exist in ``param_env``, we will still allow the check to succeed for either of the cases below:
1. The feature is enabled through ``#[feature(feat_name)]`` outside of std / core.
2. We are in codegen because we may be monomorphizing a body from an upstream crate which had an unstable feature enabled that the downstream crate do not.

For the rest of the case, it will fail with ambiguity.

## Limitation

In this PR, we do not support:
1. using items that need ``#[unstable_feature_bound]`` within stable APIs
2. annotate main function with ``#[unstable_feature_bound]``
3. annotate ``#[unstable_feature_bound]`` on items other than free function and impl

## Acknowledgement
The design and mentoring are done by `@BoxyUwU`
2025-07-17 01:57:55 +00:00
Nicholas Nethercote
6414352bff Use join_path_syms in one more place.
This one is a bit marginal, because the segments are a mix of symbols
and strings.
2025-07-17 08:37:20 +10:00
Folkert de Vries
9c8ab89187
use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
Folkert de Vries
ec0ff720d1
add codegen_instance_attrs query
and use it for naked functions
2025-07-16 21:38:58 +02:00
Vadim Petrochenkov
babe2c0d0f resolve: Merge NameBindingKind::Module into NameBindingKind::Res 2025-07-16 08:28:17 +03:00
Deadbeef
3f2dc2bd1a add const_make_global; err for const_allocate ptrs if didn't call
Co-Authored-By: Ralf Jung <post@ralfj.de>
Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-16 00:32:12 +08:00
Michael Goulet
3634f46fdb Add alias for ArgOutlivesPredicate 2025-07-15 16:02:26 +00:00
Michael Goulet
e3f643c706 Consider outlives assumptions when proving auto traits for coroutine interiors 2025-07-15 16:02:26 +00:00
Michael Goulet
3e7dfaa510 Deduce outlives obligations from WF of coroutine interior types 2025-07-15 16:02:26 +00:00
Michael Goulet
7976ca2442 Add outlives to CoroutineWitnessTypes 2025-07-15 15:58:08 +00:00
tiif
7356ff7517 Implement other logics 2025-07-15 13:48:30 +00:00
tiif
1e5c7b2877 Add the core logic in old and new solvers 2025-07-15 13:48:30 +00:00
Jonathan Brouwer
a14baf1e56
Define datastructures for #[cfg] attribute, move StrippedCfgItem 2025-07-15 09:01:00 +02:00
bors
ad635e5d06 Auto merge of #143779 - JonathanBrouwer:automatically_derived_parser, r=oli-obk
Port `#[automatically_derived]` to the new attribute parsing infrastructure

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

r? `@oli-obk`
cc `@jdonszelmann`
2025-07-14 04:29:53 +00:00
bors
9c3064e131 Auto merge of #143357 - cjgillot:no-assoc-item-kind, r=compiler-errors
Retire hir::*ItemRef.

This information was kept for various places that iterate on HIR to know about trait-items and impl-items.

This PR replaces them by uses of the `associated_items` query that contain pretty much the same information.

This shortens many spans to just `def_span`, which can be easier to read.
2025-07-13 22:39:10 +00:00
Camille GILLOT
36bc0948e0 Generalize TyCtxt::item_name. 2025-07-13 13:50:00 +00:00
Camille GILLOT
277b0ecf34 Remove hir::AssocItemKind. 2025-07-13 13:50:00 +00:00
Matthias Krüger
762b3143fc
Rollup merge of #143634 - nia-e:init-and-wildcards, r=RalfJung
interpret/allocation: expose init + write_wildcards on a range

Part of https://github.com/rust-lang/miri/pull/4456, so that we can mark down when a foreign access to our memory happened. Should this also move `prepare_for_native_access()` itself into Miri, given that everything there can be implemented on Miri's side?

r? `````@RalfJung`````
2025-07-13 15:15:58 +02:00
Michael Goulet
736bfa12de Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
bohan
47e15d90e1 query RPITIT in a trait or impl 2025-07-13 02:52:13 +08:00
bohan
dc6c3300fc compute all rpitit of a trait 2025-07-13 02:52:13 +08:00
Jonathan Brouwer
ef82007ed7
Port #[automatically_derived] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-12 17:48:50 +02:00
Matthias Krüger
1d2aa4d8dd
Rollup merge of #143769 - tmiasko:rm-backward-switch-int, r=lqd
Remove support for SwitchInt edge effects in backward dataflow

Those effects are untested and unused. Remove them along with the implementation of `BasicBlocks::switch_sources`.
2025-07-11 19:45:26 +02:00
Matthias Krüger
b18064f2f2
Rollup merge of #143716 - workingjubilee:document-some-codegen-backend-stuff, r=bjorn3,fee1-dead
compiler: doc/comment some codegen-for-functions interfaces

An out-of-date comment gets updated and some underdocumented functions get documented.
2025-07-11 19:45:24 +02:00
Matthias Krüger
c8780fff6a
Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmann
Port several trait/coherence-related attributes the new attribute system

Part of rust-lang/rust#131229

This ports:
- `#[const_trait]`
- `#[rustc_deny_explicit_impl]`
- `#[rustc_do_not_implement_via_object]`
- `#[rustc_coinductive]`
- `#[type_const]`
- `#[rustc_specialization_trait]`
- `#[rustc_unsafe_specialization_marker]`
- `#[marker]`
- `#[fundamental]`
- `#[rustc_paren_sugar]`
- `#[rustc_allow_incoherent_impl]`
- `#[rustc_coherence_is_core]`

This also changes `#[marker]` to error on duplicates instead of warning.
cc rust-lang/rust#142838, but I don't think it matters too much, since it's unstable.

r? ``@oli-obk``
2025-07-11 19:45:22 +02:00
Tomasz Miąsko
5b6d661039 Remove support for SwitchInt edge effects in backward dataflow analyses
Those effects are untested and unused. Remove them along with
the implementation of `BasicBlocks::switch_sources`.
2025-07-11 10:56:50 +02:00
bors
855e0fe46e Auto merge of #142911 - mejrs:unsized, r=compiler-errors
Remove support for dynamic allocas

Followup to rust-lang/rust#141811
2025-07-11 05:27:32 +00:00
Trevor Gross
3a1bb04166
Rollup merge of #143744 - fmease:lta-expand-proper-depth, r=compiler-errors
Properly track the depth when expanding free alias types

Decrease the depth after the fold so as not to affect the depth for unrelated same-level constituent types. My bad.

Fixes rust-lang/rust#142419.
2025-07-10 20:20:41 -04:00
León Orell Valerian Liehr
341f12df67
Properly track the depth when expanding free alias types 2025-07-10 19:49:32 +02:00
Nia Espera
8d0e0c6d6f
interpret/allocation: expose init + write_wildcards on a range 2025-07-10 16:33:31 +02:00
Jubilee Young
04bb68ac86 compiler: recomment needs_fn_once_adapter_shim
This requires digging up ffee9566bbd7728e6411e6094105d6905373255d
and reading the comments there to understand that the callee in
resolve_closure previously directly handled a function pointer value.
2025-07-09 20:53:23 -07:00
Oli Scherer
486ffda9dc Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
Pavel Grigorenko
e584ed0de2 Port #[rustc_coherence_is_core] to the new attribute system 2025-07-09 01:26:39 +03:00
Pavel Grigorenko
507ebced16 Port #[fundamental] to the new attribute system 2025-07-09 01:26:27 +03:00
Pavel Grigorenko
813ec60744 Port #[type_const] to the new attribute system 2025-07-09 01:06:29 +03:00
Pavel Grigorenko
62f58dbb2d Port #[const_trait] to the new attribute system 2025-07-09 01:03:00 +03:00
mejrs
25eb3829e5 Error on moving unsized values rather than ICE'ing 2025-07-08 22:37:12 +02:00
bors
2783fc43fd Auto merge of #143621 - matthiaskrgr:rollup-p1ce8l7, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#142098 (Implement `int_format_into` feature)
 - rust-lang/rust#143567 (Point to correct argument in Func Call when Self type fails trait bound)
 - rust-lang/rust#143570 (consider nested cases for duplicate RPITIT)
 - rust-lang/rust#143571 (remove `has_nested` from builtin candidates)
 - rust-lang/rust#143586 (Fix wrong cache event query key)
 - rust-lang/rust#143589 (const-block-as-pattern: do not refer to no-longer-existing nightly feature)
 - rust-lang/rust#143608 (Fix in std::String docs)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-08 03:30:58 +00:00
Matthias Krüger
b29f039ae3
Rollup merge of #143571 - lcnr:has_nested-bb, r=compiler-errors
remove `has_nested` from builtin candidates

it's no longer necessary

r? types
2025-07-08 03:09:57 +02:00