Commit Graph

52126 Commits

Author SHA1 Message Date
bors 526a91cbcc Auto merge of #150105 - jackh726:remove-expressions-coerce, r=BoxyUwU
Remove Expressions (and just use a Vec) in coerce

Let's see if this has much of a perf impact - would be nice to clean this up a bit

r? ghost
2025-12-19 00:27:29 +00:00
Jonathan Brouwer 5e9b3a08c8 Rollup merge of #150126 - bjorn3:sync_cg_clif-2025-12-18, r=bjorn3
Subtree sync for rustc_codegen_cranelift

Nothing too exciting since the last sync.

r? ``@ghost``

``@rustbot`` label +A-codegen +A-cranelift +T-compiler
2025-12-18 18:37:24 +01:00
Jonathan Brouwer 521aca2b17 Rollup merge of #150125 - Bryntet:parse_rustc_lint_opt_deny_field_access, r=JonathanBrouwer
Port `#[rustc_lint_opt_deny_field_access]` to attribute parser

r? ``@JonathanBrouwer``
2025-12-18 18:37:22 +01:00
Jonathan Brouwer ad4d6b9a17 Rollup merge of #150124 - DanielEScherzer:patch-1, r=petrochenkov
unstable.rs: fix typos in comments (implementatble -> implementable)
2025-12-18 18:37:21 +01:00
Jonathan Brouwer 4c9451bff8 Rollup merge of #150102 - jdonszelmann:fix-149982, r=Kivooeo
Fixed ICE for EII with multiple defaults due to duplicate definition in nameres

r? ``@jieyouxu`` (since you looked at the other one)

Fixes https://github.com/rust-lang/rust/issues/149982

Previously a [fix was proposed](https://github.com/rust-lang/rust/pull/149985) by ``@SATVIKsynopsis`` which I marked as co-author on the first commit for the test they contributed. I'm closing this previous PR.

Duplicate definitions of EII defaults shouldn't be possible. I want to still panic on them, since I want to know when other bugs exist. However, in this case the duplicate was caused by something more subtle: both eiis have the same name, and as such a "duplicate definition" error is given. However, the compiler gracefully continues compiling despite that, assuming only one of the two EIIs is actually defined.

Both defaults then name resolve, and find the same single remaining EII, and both register themselves to be its default, breaking the single-default assumption.

The solution: I added a span-delayed-bug, to make sure we only panic if we hadn't previously had this duplicate definition name resolution error.

Thanks to ``@SATVIKsynopsis`` for their attempt. Adding a diagnostic here could make some sense, but nonetheless I think this is the better solution here <3
Also thanks to ``@yaahc`` for debugging help, she made me understand the name resolution of the situation so much better and is just lovely in general :3

The last commit is something I tried during debugging, which felt like a relevant test to add (one where both eiis also have the same function name)
2025-12-18 18:37:21 +01:00
Jonathan Brouwer 1e496bc9e6 Rollup merge of #150024 - aerooneqq:recursive-delegation-2, r=petrochenkov
Support recursive delegation

This PR adds support for recursive delegations and is a part of the delegation feature rust-lang/rust#118212.

r? ``@petrochenkov``
2025-12-18 18:37:17 +01:00
Jonathan Brouwer b17df9b99a Rollup merge of #149952 - Delta17920:fix/149777-range-destructuring, r=fmease
Suggest struct pattern when destructuring Range with .. syntax

implemented a new diagnostic in rustc_resolve to detect invalid range destructuring attempts (e.g., let start..end = range). The fix identifies when resolution fails for identifiers acting as range bounds specifically handling cases where bounds are parsed as expressions and suggests the correct struct pattern syntax (std::ops::Range { start, end }). This replaces confusing "cannot find value" errors with actionable help, verified by a new UI test covering various identifier names.

Fixes rust-lang/rust#149777
2025-12-18 18:37:16 +01:00
Jonathan Brouwer d0e9f69016 Rollup merge of #149925 - folkertdev:cfg-select-parse-unused-branches, r=jdonszelmann
`cfg_select!`: parse unused branches

tracking issue: https://github.com/rust-lang/rust/issues/115585

Emit parse errors that are found in the branches that are not selected, like e.g. how `#[cfg(false)] { 1 ++ 2 }` still emits a parse error even though the expression is never used by the program. Parsing the unused branches was requested by T-lang https://github.com/rust-lang/rust/pull/149783#issuecomment-3647541611.
2025-12-18 18:37:15 +01:00
jackh726 a079cb98cd Remove Expressions (and just use a Vec) 2025-12-18 16:47:01 +00:00
bjorn3 c594c39b6f Merge commit '8de4afd39ba48f25be98684cdb7a96ec6da89d10' into sync_cg_clif-2025-12-18 2025-12-18 11:50:08 +00:00
Edvin Bryntesson cd4d899862 make all parsed rustc attributes error on duplicate 2025-12-18 12:30:05 +01:00
Edvin Bryntesson fe34b17c2a Port #[rustc_lint_opt_deny_field_access] to attribute parser 2025-12-18 12:19:07 +01:00
Daniel Scherzer 9571693990 unstable.rs: fix typos in comments (implementatble -> implementable) 2025-12-18 01:32:49 -08:00
aerooneqq ae5e0d5492 Support recursive delegation 2025-12-18 10:42:47 +03:00
bors ed0006a7ba Auto merge of #138961 - meithecatte:expr-use-visitor, r=Nadrieril,traviscross,ChayimFriedman2
Make closure capturing have consistent and correct behaviour around patterns

Reference PR:

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

This PR has two goals:
- firstly, it fixes rust-lang/rust#137467. In order to do so, it needs to introduce a small breaking change surrounding the interaction of closure captures with matching against enums with uninhabited variants. Yes – to fix an ICE!
    - this also fixes rust-lang/rust#138973, a slightly different case with the same root cause.
    - likewise, fixes rust-lang/rust#140011.
- secondly, it fixes rust-lang/rust#137553, making the closure capturing rules consistent between `let` patterns and `match` patterns. This is new insta-stable behavior.

## Background

This change concerns how precise closure captures interact with patterns. As a little known feature, patterns that require inspecting only part of a value will only cause that part of the value to get captured:

```rust
fn main() {
    let mut a = (21, 37);
    // only captures a.0, writing to a.1 does not invalidate the closure
    let mut f = || {
        let (ref mut x, _) = a;
        *x = 42;
    };
    a.1 = 69;
    f();
}
```

I was not able to find any discussion of this behavior being introduced, or discussion of its edge-cases, but it is [documented in the Rust reference](https://doc.rust-lang.org/reference/types/closure.html#r-type.closure.capture.precision.wildcard).

The currently stable behavior is as follows:
- if any pattern contains a binding, the place it binds gets captured (implemented in current `walk_pat`)
- patterns in refutable positions (`match`, `if let`, `let ... else`, but not destructuring `let` or destructuring function parameters) get processed as follows (`maybe_read_scrutinee`):
    - if matching against the pattern will at any point require inspecting a discriminant, or it includes a variable binding not followed by an ``@`-pattern,` capture *the entire scrutinee* by reference

You will note that this behavior is quite weird and it's hard to imagine a sensible rationale for at least some of its aspects. It has the following issues:
- firstly, it assumes that matching against an irrefutable pattern cannot possibly require inspecting any discriminants. With or-patterns, this isn't true, and it is the cause of the rust-lang/rust#137467 ICE.
- secondly, the presence of an ``@`-pattern` doesn't really have any semantics by itself. This is the weird behavior tracked as rust-lang/rust#137553.
- thirdly, the behavior is different between pattern-matching done through `let` and pattern-matching done through `match` – which is a superficial syntactic difference

This PR aims to address all of the above issues. The new behavior is as follows:
- like before, if a pattern contains a binding, the place it binds gets captured as required by the binding mode
- if matching against the pattern requires inspecting a disciminant, the place whose discriminant needs to be inspected gets captured by reference

"requires inspecting a discriminant" is also used here to mean "compare something with a constant" and other such decisions. For types other than ADTs, the details are not interesting and aren't changing.

## The breaking change

During closure capture analysis, matching an `enum` against a constructor is considered to require inspecting a discriminant if the `enum` has more than one variant. Notably, this is the case even if all the other variants happen to be uninhabited. This is motivated by implementation difficulties involved in querying whether types are inhabited before we're done with type inference – without moving mountains to make it happen, you hit this assert: https://github.com/rust-lang/rust/blob/43f0014ef0f242418674f49052ed39b70f73bc1c/compiler/rustc_middle/src/ty/inhabitedness/mod.rs#L121

Now, because the previous implementation did not concern itself with capturing the discriminants for irrefutable patterns at all, this is a breaking change – the following example, adapted from the testsuite, compiles on current stable, but will not compile with this PR:

```rust
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Void {}

pub fn main() {
    let mut r = Result::<Void, (u32, u32)>::Err((0, 0));
    let mut f = || {
        let Err((ref mut a, _)) = r;
        *a = 1;
    };
    let mut g = || {
    //~^ ERROR: cannot borrow `r` as mutable more than once at a time
        let Err((_, ref mut b)) = r;
        *b = 2;
    };
    f();
    g();
    assert_eq!(r, Err((1, 2)));
}
```

## Is the breaking change necessary?

One other option would be to double down, and introduce a set of syntactic rules for determining whether a sub-pattern is in an irrefutable position, instead of querying the types and checking how many variants there are.

**This would not eliminate the breaking change,** but it would limit it to more contrived examples, such as

```rust
let ((true, Err((ref mut a, _, _))) | (false, Err((_, ref mut a, _)))) = x;
```

In this example, the `Err`s would not be considered in an irrefutable position, because they are part of an or-pattern. However, current stable would treat this just like a tuple `(bool, (T, U, _))`.

While introducing such a distinction would limit the impact, I would say that the added complexity would not be commensurate with the benefit it introduces.

## The new insta-stable behavior

If a pattern in a `match` expression or similar has parts it will never read, this part will not be captured anymore:

```rust
fn main() {
    let mut a = (21, 37);
    // now only captures a.0, instead of the whole a
    let mut f = || {
        match a {
            (ref mut x, _) => *x = 42,
        }
    };
    a.1 = 69;
    f();
}
```

Note that this behavior was pretty much already present, but only accessible with this One Weird Trick™:

```rust
fn main() {
    let mut a = (21, 37);
    // both stable and this PR only capture a.0, because of the no-op `@-pattern`
    let mut f = || {
        match a {
            (ref mut x @ _, _) => *x = 42,
        }
    };
    a.1 = 69;
    f();
}
```

## The second, more practically-relevant breaking change

After running crater, we have discovered that the aforementioned insta-stable behavior, where sometimes closures will now capture less, can also manifest as a breaking change. This is because it is possible that previously a closure would capture an entire struct by-move, and now it'll start capturing only part of it – some by move, and some by reference. This then causes the closure to have a more restrictive lifetime than it did previously.

See:
- https://github.com/rust-lang/rust/pull/138961#issuecomment-2761888557
- https://github.com/EC-labs/cec-assignment/pull/1
- https://github.com/tryandromeda/andromeda/pull/43

## Implementation notes

The PR has two main commits:
- "ExprUseVisitor: properly report discriminant reads" makes `walk_pat` perform all necessary capturing. This is the part that fixes rust-lang/rust#137467.
- "ExprUseVisitor: remove maybe_read_scrutinee" removes the unnecessary "capture the entire scrutinee" behavior, fixing rust-lang/rust#137553.

The new logic stops making the distinction between one particular example that used to work, and another ICE, tracked as rust-lang/rust#119786. As this requires an unstable feature, I am leaving this as future work.
2025-12-18 03:54:48 +00:00
Jonathan Brouwer 3ef20b62fa Rollup merge of #150095 - Bryntet:parse_internal_rustc_attributes, r=JonathanBrouwer
Port `#[rustc_no_implicit_autorefs]`, `#[rustc_lint_opt_ty]`, and `#[rustc_lint_query_instability]` attributes to be parsed

This PR ports three simple internal rustc attributes to be parsed in a single PR to avoid having to resolve multiple rebase confilicts

r? ``@JonathanBrouwer``
2025-12-17 23:31:21 +01:00
Folkert de Vries 82ee8b21cb cfg_select!: emit parse errors in unused branches 2025-12-17 22:42:42 +01:00
Maja Kądziołka 2443fba3a2 Rewrite the comment on is_multivariant_adt
As Nadrieril remarked, the previous comment was misleadingly framed.
2025-12-17 20:47:48 +01:00
Maja Kądziołka a2e249cd26 ExprUseVisitor: resolve a FIXME – it's fine as is 2025-12-17 20:47:48 +01:00
Maja Kądziołka e6c59990bd add a comment: MatchPair and ExprUseVisitor must stay in sync 2025-12-17 20:47:48 +01:00
Maja Kądziołka 462b51a525 Add debug logging in hir_typeck::upvar
This aims to make each major part responsible for modifying the
precision be visible in the logs.
2025-12-17 20:47:48 +01:00
Maja Kądziołka e25803acea ExprUseVisitor: remove maybe_read_scrutinee
The split between walk_pat and maybe_read_scrutinee has now become
redundant.

Due to this change, one testcase within the testsuite has become similar
enough to a known ICE to also break. I am leaving this as future work,
as it requires feature(type_alias_impl_trait)
2025-12-17 20:47:47 +01:00
Maja Kądziołka 9cb47c6e8e ExprUseVisitor: properly report discriminant reads
This solves the "can't find the upvar" ICEs that resulted from
`maybe_read_scrutinee` being unfit for purpose.
2025-12-17 20:47:47 +01:00
Matthias Krüger 7180fd1659 Rollup merge of #150051 - Zalathar:thir-pat, r=Nadrieril
mir_build: Rename `TestCase` to `TestableCase`

In the spirit of rust-lang/rust#149946, this is another renaming of something I've always found confusing.

When lowering match conditions, there is a subtle distinction between the kind of *test* being performed (on a scrutinee place), the possible outcomes of that test, and the different “cases” (corresponding to pattern nodes) that the test is distinguishing. Cases imply a particular preferred test, but once a test is chosen it can also interact with other cases as well.

I have often mixed up `TestKind` and `TestCase`, since the names are so similar, and they share several variant names. Therefore, this PR renames `TestCase` to `TestableCase`, to emphasise that these are the things selected by whatever test is being performed.

There should be no change to compiler behaviour.
2025-12-17 18:46:17 +01:00
Matthias Krüger 5fb00f2f28 Rollup merge of #149919 - GuillaumeGomez:doc-metadata-encoding, r=lqd
Correctly encode doc attribute metadata

Follow-up of https://github.com/rust-lang/rust/pull/149645.

The change I made was slightly wrong. [Originally](https://github.com/rust-lang/rust/pull/149645/changes#diff-72bf3e63aae0c5f24a5ce78a560db321ac6ead9df5ada3e33462a7f7d6218a55) the check was:

```rust
        if let Some(item_list) = attr.meta_item_list() {
            for item in item_list {
                if !item.has_name(sym::inline) {
```

So we were checking that there was no `doc(inline)` attribute. This PR should fix it.

r? ``@lqd``
2025-12-17 18:46:17 +01:00
Edvin Bryntesson 96e453d713 Port #[rustc_lint_query_instability] to parsed attribute 2025-12-17 18:28:37 +01:00
Edvin Bryntesson 81d20363b3 Port #[rustc_lint_opt_ty] to parsed attribute 2025-12-17 18:23:49 +01:00
Edvin Bryntesson bbda675aac Port #[rustc_no_implicit_autorefs] to attribute parser 2025-12-17 18:22:19 +01:00
Jana Dönszelmann 1cd7cb1e8d turn panic into span_delayed_bug 2025-12-17 18:04:03 +01:00
delta17920 6fac0fac99 Apply review suggestions 2025-12-17 14:53:14 +00:00
delta17920 3e78653ec3 Fix grammar in suggestion message 2025-12-17 14:08:53 +00:00
delta17920 cb301751b3 Suggest struct pattern when destructuring Range with .. syntax 2025-12-17 14:08:53 +00:00
Jonathan Brouwer 84d441f558 Rollup merge of #150086 - Bryntet:parse_never_return_null_pointer, r=JonathanBrouwer
Port `#[rustc_never_returns_null_ptr]` to attribute parser

Ports `#[rustc_never_returns_null_ptr]` to be parsed using the attribute parser

r? `@JonathanBrouwer`
2025-12-17 12:49:22 +01:00
Jonathan Brouwer 093d175edd Rollup merge of #150044 - workingjubilee:avoid-suggesting-irrelevant-rename, r=jieyouxu
Avoid unhelpful suggestion when crate name is invalid

Pointing out they can set the crate's name is non-actionable: their problem is they found out how and set it incorrectly. Remove extraneous information that can only confuse the matter.
2025-12-17 12:49:21 +01:00
Jonathan Brouwer 56c00b0bca Rollup merge of #150008 - androm3da:bcain/va_arg_rs, r=folkertdev
Implement va_arg for Hexagon targets

Implements proper variadic argument handling for hexagon-unknown-linux-musl targets using a 3-pointer VaList structure compatible with LLVM's HexagonBuiltinVaList implementation.

* Handles register save area vs overflow area transition
* Provides proper 4-byte and 8-byte alignment for arguments
* Only activates for hexagon+musl targets via Arch::Hexagon & Env::Musl
2025-12-17 12:49:20 +01:00
Edvin Bryntesson 5692064521 Port #[rustc_never_returns_null_ptr] to attribute parser 2025-12-17 12:35:32 +01:00
Jubilee Young 25cc98f116 Avoid unhelpful suggestion when crate name is invalid
Pointing out they can set the crate's name is non-actionable:
their problem is they found out how and set it incorrectly.
Remove extraneous information that can only confuse the matter.
2025-12-16 20:43:26 -08:00
Brian Cain 4ff4b255d0 fixup! Implement va_arg for Hexagon Linux musl targets 2025-12-16 22:26:19 -06:00
Jacob Pratt 656d4e8a96 Rollup merge of #150072 - Bryntet:parse_no_link, r=JonathanBrouwer
Port #[no_link] to use attribute parser

Adds `#[no_link]` to the attribute parser, as well as adds tests making sure to FCW warn on `field`, `arm`, and `macrodef `
2025-12-16 23:10:12 -05:00
Jacob Pratt 641100c391 Rollup merge of #150060 - ZuseZ4:autodiff-dlopen-ice, r=Kobzol
autodiff: emit an error if we fail to find libEnzyme

Tested manually by moving libEnzyme-21.so away. We should adjust the error msg. once we have the component up.

It's the first usage within rustc of this experimental feature, but afaik we're open to dogfooding those for test purpose, right?

r? ``@Kobzol``
2025-12-16 23:10:10 -05:00
Jacob Pratt 66155a7df6 Rollup merge of #150000 - Bryntet:brynte/parse_legacy_const_generic_args, r=jonathanbrouwer,jdonszelmann
Port `#[rustc_legacy_const_generics]` to use attribute parser

Small PR that ports the `#[rustc_legacy_const_generics]` to use the new attribute parser!

r? JonathanBrouwer
2025-12-16 23:10:10 -05:00
Edvin Bryntesson 52bcaabdb8 Port #[no_link] to use attribute parser 2025-12-16 22:45:32 +01:00
Manuel Drehwald 793d990d11 Emit a proper error if we fail to find libEnzyme 2025-12-16 21:33:28 +01:00
bors 2dc30247c5 Auto merge of #150068 - JonathanBrouwer:rollup-45j7puz, r=JonathanBrouwer
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#147939 (Make `const BorrowMut` require `const Borrow` and make `const Fn` require `const FnMut`)
 - rust-lang/rust#149734 (Mirror GCC 9.5.0)
 - rust-lang/rust#149767 (Tidying up tests/ui/issues 33 tests [4/N])
 - rust-lang/rust#149804 (chore: fix some minor issues in the comments)
 - rust-lang/rust#149967 (custom `VaList` layout for Hexagon)
 - rust-lang/rust#150025 (dont create unnecessary `DefId`s under mgca)
 - rust-lang/rust#150032 (Use annotate-snippet as default emitter on stable)
 - rust-lang/rust#150033 (Add try_as_dyn and try_as_dyn_mut)
 - rust-lang/rust#150042 (rustc-dev-guide subtree update)
 - rust-lang/rust#150063 (Remove deny of manual-let-else)
 - rust-lang/rust#150064 (std: io: error: Add comment for UEFI unpacked repr use)

Failed merges:

 - rust-lang/rust#150044 (Avoid unhelpful suggestion when crate name is invalid)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-16 19:46:35 +00:00
Edvin Bryntesson 4bd0e65bde Port #[rustc_legacy_const_generics] to use attribute parser 2025-12-16 20:29:01 +01:00
Jonathan Brouwer 02c0e8f015 Rollup merge of #150063 - workingjubilee:remove-let-else-deny, r=Kivooeo
Remove deny of manual-let-else

During discussion on Zulip[^1], we found there was no strong consensus in favor of this in practice.

[^1]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.60deny.28clippy.3A.3Amanual_let_else.29.60.20proliferation/with/564085588
2025-12-16 20:21:12 +01:00
Jonathan Brouwer 25b73c4943 Rollup merge of #150033 - izagawd:try_as_dyn, r=oli-obk
Add try_as_dyn and try_as_dyn_mut

Tracking issue: https://github.com/rust-lang/rust/issues/144361

Continuation of: https://github.com/rust-lang/rust/pull/144363
2025-12-16 20:21:10 +01:00
Jonathan Brouwer f3fa567fdf Rollup merge of #150032 - Kivooeo:annotate-snippets-stable, r=Muscraft
Use annotate-snippet as default emitter on stable

This is implementation of https://github.com/rust-lang/rust/issues/149932

Now, after MCP was accepted, we can use annotate-snippet as default emitter for errors, that means that we not longer need of previous emitter, so this PR removed previous emitter and makes annotate-snippet new default one both on stable and nightly

(this PR does not remove a code of previous emitter it just removes a `Default` option of `HumanReadableErrorType` enum, and keeping only `HumanReadableErrorType::AnnotateSnippet` as it now uses by default)
2025-12-16 20:21:10 +01:00
Jonathan Brouwer 9308518af9 Rollup merge of #150025 - BoxyUwU:mgca_no_unused_defids, r=oli-obk
dont create unnecessary `DefId`s under mgca

Fixes rust-lang/rust#149977
Fixes rust-lang/rust#148838

Accidentally left this out of rust-lang/rust#149136 even though being able to do this was a large part of the point of the PR :3

First ICE was caused by the fact that we create a defid but never lower the nodeid associated with it to a hirid which later parts of the compiler can't handle.

See test for second ICE

r? oli-obk
2025-12-16 20:21:09 +01:00
Jubilee Young 0004d8d421 Remove deny of manual-let-else 2025-12-16 08:42:04 -08:00