Commit Graph

25287 Commits

Author SHA1 Message Date
Jacob Pratt fa82155e54 Rollup merge of #155680 - Amanieu:call-arg-move-index, r=cjgillot
Handle index projections in call destinations in DSE

Since call destinations are evaluated after call arguments, we can't turn copy arguments into moves if the same local is later used as an index projection in the call destination.

DSE call arg optimization: rust-lang/rust#113758

r? @cjgillot
cc @RalfJung
2026-04-25 01:21:52 -04:00
Jacob Pratt 0af72af1b8 Rollup merge of #154197 - yuk1ty:fix-redundant-clone-error2, r=adwinwhite
Avoid redundant clone suggestions in borrowck diagnostics

Fixes rust-lang/rust#153886

Removed redundant `.clone()` suggestions.

I found that there are two patterns to handle this issue while I was implementing:

- Should suggest only UFCS
- Should suggest only simple `.clone()`

For the target issue, we can just remove the UFCS (`<Option<String> as Clone>::clone(&selection.1)`) side.

However, for the `BorrowedContentSource::OverloadedDeref` pattern like `Rc<Vec<i32>>`, for instance the `borrowck-move-out-of-overloaded-auto-deref.rs` test case, I think we need to employ the UFCS way. The actual test case is:

```rust
//@ run-rustfix
use std::rc::Rc;

pub fn main() {
    let _x = Rc::new(vec![1, 2]).into_iter();
    //~^ ERROR [E0507]
}
```

And another error will be shown if we simply use the simple `.clone()` pattern. Like:

```rust
use std::rc::Rc;

pub fn main() {
    let _x = Rc::new(vec![1, 2]).clone().into_iter();
}
```

then we will get

```
error[E0507]: cannot move out of an `Rc`
   --> src/main.rs:5:14
    |
  5 |     let _x = Rc::new(vec![1, 2]).clone().into_iter();
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----------- value moved due to this method call
    |              |
    |              move occurs because value has type `Vec<i32>`, which does not implement the `Copy` trait
    |
note: `into_iter` takes ownership of the receiver `self`, which moves value
   --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/collect.rs:310:18
    |
310 |     fn into_iter(self) -> Self::IntoIter;
    |                  ^^^^
help: you can `clone` the value and consume it, but this might not be your desired behavior
    |
  5 -     let _x = Rc::new(vec![1, 2]).clone().into_iter();
  5 +     let _x = <Vec<i32> as Clone>::clone(&Rc::new(vec![1, 2])).into_iter();
    |

For more information about this error, try `rustc --explain E0507`.
```

[Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=7e767bed3f1c573c03642f20f454ed03)

In this case, `Rc::clone` only increments the reference count and returns a new `Rc<Vec<i32>>`; it does not grant ownership of the inner `Vec<i32>`. As a result, calling into_iter() attempts to move the `Vec<i32>`, leading to the same E0507 error again.

On the other hand, in UFCS form:

```
<Vec<i32> as Clone>::clone(&Rc::new(vec![1, 2])).into_iter()
```

This explicitly calls `<Vec<i32> as Clone>::clone`, and the argument `&Rc<Vec<i32>>` is treated as `&Vec<i32>` via Rc’s `Deref` implementation. As a result, the `Vec<i32>` itself is cloned, yielding an owned `Vec<i32>`, which allows `into_iter()` to succeed, if my understanding is correct.

I addressed the issue as far as I could find the edge cases but please advice me if I'm overlooking something.
2026-04-25 01:21:51 -04:00
Jacob Pratt d3eddcff9e Rollup merge of #155643 - qaijuang:fix-macro-missing-fragment-dollar-suggestion, r=eholk
Improve suggestion for $-prefixed fragment specifiers

Fixes rust-lang/rust#155505
2026-04-25 01:21:50 -04:00
bors 597d9e43be Auto merge of #155755 - JonathanBrouwer:rollup-oG1Wz3V, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#155754 (make the `core::ffi::va_list` module private)
 - rust-lang/rust#155522 (cmse: test returning `MaybeUninit<T>`)
 - rust-lang/rust#155741 (std: Refactor BufWriter::flush to use the `?` operator)
2026-04-25 00:13:26 +00:00
yuk1ty 61ff157bd4 Address custom type implementing Derefs to suggest UFCS clone 2026-04-25 08:46:06 +09:00
Jonathan Brouwer 39d84243b2 Rollup merge of #155522 - folkertdev:cmse-test-maybe-uninit, r=WaffleLapkin
cmse: test returning `MaybeUninit<T>`

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

Some tests from https://github.com/rust-lang/rust/pull/147697 that already work and are useful. Extracting them shrinks that (currently blocked) PR.

The code in `tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs` checks that `MaybeUninit<T>` is considered abi-compatible with `T`. The code in `tests/ui/cmse-nonsecure/cmse-nonsecure-entry/params-via-stack.rs` really only tests that no errors/warnings are emitted.

r? davidtwco
2026-04-25 00:08:10 +02:00
bors 80729d7ce0 Auto merge of #155662 - mejrs:this_the_thing, r=petrochenkov
Permit `{This}` in diagnostic attribute format literals

My motivation was that yesterday I wanted to write something like this and reference `$name` in the string literal.

```rust
pub mod sym {
   // stuff here
}

macro_rules! my_macro {
    ($name:ident $(,)?) => {{
        #[diagnostic::on_unknown(
            message = "this is not present in symbol table",
            note = "you must add it to rustc_span::symbol::symbol!"
        )]
        use sym::$name as name;
        // ...
    }}
}
```

That is (as far as I can tell) impossible or at least very unergonomic. This adds the ability to just reference the name of the item the attribute is on. I imagine that's useful for use inside macros generally, so it's also added for some other attributes.

The affected attributes are all unstable, it is not implemented for diagnostic::on_unimplemented (will do in its own PR).

Note that `{This}` is already usable in `#[rustc_on_unimplemented]`, so this does not implement it but just enables some more.

This PR also migrates one lint away from AttributeLintKind, and improves the messages for that lint.
2026-04-24 20:46:55 +00:00
Qai Juang 2b46d9204a Improve suggestion for $-prefixed fragment specifiers 2026-04-24 14:59:01 -04:00
mejrs c2916be8d7 Permit {This} in diagnostic attribute format literals 2026-04-24 19:59:32 +02:00
bors 7c61a357e3 Auto merge of #155745 - JonathanBrouwer:rollup-D6OSAOt, r=JonathanBrouwer
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#149452 (Refactor out common code into a `IndexItem::new` constructor)
 - rust-lang/rust#155621 (Document #[diagnostic::on_move] in the unstable book.)
 - rust-lang/rust#155635 (delegation: rename `Self` generic param to `This` in recursive delegations)
 - rust-lang/rust#155730 (Some cleanups around per parent disambiguators)
 - rust-lang/rust#153537 (rustc_codegen_ssa: Define ELF flag value for sparc-unknown-linux-gnu)
 - rust-lang/rust#155219 (Do not suggest borrowing enclosing calls for nested where-clause obligations)
 - rust-lang/rust#155408 (rustdoc: Fix Managarm C Library name in cfg pretty printer)
 - rust-lang/rust#155571 (Enable AddressSanitizer on arm-unknown-linux-gnueabihf and armv7-unknown-linux-gnueabihf)
 - rust-lang/rust#155713 (test: Add a regression test for Apple platforms aborting on `free`)
 - rust-lang/rust#155723 (Fix tier level for 5 thumb bare-metal ARM targets)
 - rust-lang/rust#155735 (Fix typo by removing extra 'to')
 - rust-lang/rust#155736 (Remove `AllVariants` workaround for rust-analyzer)
2026-04-24 17:30:32 +00:00
Jonathan Brouwer 3ad0c706e6 Rollup merge of #155713 - tgross35:150898-regression-test, r=dianqk
test: Add a regression test for Apple platforms aborting on `free`

Add a regression test for https://github.com/rust-lang/rust/issues/150898 to make users aware that if this test failures, they may encounter unusual behavior elsewhere.
2026-04-24 18:19:19 +02:00
Jonathan Brouwer 39d5d45b9a Rollup merge of #155408 - teor2345:rustdoc-env-names, r=lolbinarycat
rustdoc: Fix Managarm C Library name in cfg pretty printer

Like rust-lang/rust#155293, this was introduced in https://github.com/rust-lang/rust/pull/154328.

Unlike that PR, I don't think there's any need to backport, because this cfg is not used anywhere in the standard library.
(I searched for `"mlibc"`, the only place it's used in rust-lang/rust is the HTML doc test.)

#### Other Minor Fixes

Remove a FIXME comment in the pretty printer, `os = "none"` is always bare metal:
https://github.com/rust-lang/rust/blob/d227e48c560e915fe7c0b8b3e821680a3a0ba739/compiler/rustc_target/src/spec/mod.rs#L3179

Fix a comment typo, ignore another typo in vendored sources.
2026-04-24 18:19:18 +02:00
Jonathan Brouwer a51a163574 Rollup merge of #155219 - nataliakokoromyti:fix-155088-borrow-suggestion-v2, r=JohnTitor
Do not suggest borrowing enclosing calls for nested where-clause obligations

In rust-lang/rust#155088, the compiler was blaming the whole call expr instead of the value that  actually failed the trait bound, so for foo(&[String::from("a")]) it was suggesting stuff like &foo(...). I changed the suggestion logic so it only emits borrow help if the expr it found actually matches the failed self type,  and used the same check for the “similar impl exists” help too. So now the compiler should give the normal error + required bound note.

Fix rust-lang/rust#155088
2026-04-24 18:19:17 +02:00
Jonathan Brouwer ef162a52dc Rollup merge of #155635 - aerooneqq:delegation-generics-Self-rename, r=petrochenkov
delegation: rename `Self` generic param to `This` in recursive delegations

This PR supports renaming of `Self` generic parameter to `This` in recursive delegations scenario, this allows propagation of `This` as we rely on `Self` naming to check whether it is implicit Self of a trait. Comment with a bit deeper explanation is in `uplift_delegation_generic_params`. Part of rust-lang/rust#118212.

r? @petrochenkov
2026-04-24 18:19:15 +02:00
Jonathan Brouwer e873839964 Rollup merge of #155621 - mejrs:document_diagnostic_on_move, r=chenyukang
Document #[diagnostic::on_move] in the unstable book.

Also adds the attribute on `std::fs::File` to stay consistent with the prose in the unstable book entry.

cc @estebank @rperier

Rendered:
<img width="791" height="903" alt="image" src="https://github.com/user-attachments/assets/a27a5211-7717-4f7f-a514-8316dccc78d5" />
<img width="779" height="390" alt="image" src="https://github.com/user-attachments/assets/a983108d-575e-4551-ab14-28611344e9b0" />
2026-04-24 18:19:14 +02:00
yuk1ty f69946ac64 Avoid redundant clone suggestions in borrowck diagnostics 2026-04-24 23:00:28 +09:00
bors acb65f36a0 Auto merge of #155645 - dianqk:update-llvm, r=nikic
Update LLVM to 22.1.4

Unlocks https://github.com/rust-lang/rust/pull/155249.

I made a new branch that removes CI checks for macOS and reverts https://github.com/rust-lang/llvm-project/commit/24b53fbc67d989ff0216c9b36369426828ac3b91.
2026-04-24 13:55:36 +00:00
Trevor Gross 150905c3de test: Add a regression test for Apple platforms aborting on free
Add a regression test for RUST-150898 to make users aware that if this
test fails, they may encounter unusual behavior elsewhere.

Original repro authored by dianqk.
2026-04-24 05:33:03 -04:00
aerooneqq 7f2a98d1fc Rename Self generic param to This in recursive delegations 2026-04-24 09:59:20 +03:00
Jacob Pratt 1230f74ad5 Rollup merge of #155698 - fmease:no-struct-pat-tuple-index-shorthand, r=mu001999
Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression

Split out of PR rust-lang/rust#154492. This fixes a correctness regression introduced in PR rust-lang/rust#81235 from 2021. Crater was run in my other PR and didn't report any real regressions (https://github.com/rust-lang/rust/pull/154492#issuecomment-4187544786); a rerun has been issued for a few spurious builds (https://github.com/rust-lang/rust/pull/154492#issuecomment-4237077272) but I'm certain it won't find anything either.

This is a theoretical breaking change that doesn't need any T-lang input IMHO since it's such a minute, niche and crystal clear bug that's not worth bothering them with (such a decision is not unprecedented). I'm adding it to the compatibility section of the release notes as is customary.

The Reference doesn't need updating since it didn't adopt this bug and thus accurately describes this part of the grammar as it used to be before 2021-02-23 and as it's meant to be.

The majority of the diff is doc comment additions & necessary UI test restructurings.
2026-04-24 02:42:52 -04:00
Jacob Pratt cdba0cea17 Rollup merge of #155379 - ashivaram23:mir-query-cycle, r=saethlin
Avoid query cycles in DataflowConstProp

Fixes rust-lang/rust#155376 by skipping coroutines.
2026-04-24 02:42:50 -04:00
Jacob Pratt b9cf909390 Rollup merge of #155081 - reddevilmidzy:ui-fixme, r=Kivooeo
Move and clean up some ui test

`ui/reserved` -> `ui/keyword`
`ui/deref-patterns` -> `ui/pattern/deref-patterns`
`ui/unknown-unstable-lints` -> `ui/lint/unknown-lints`

Tests related to unknown_lints that were located above lint have also been moved to a subdirectory, and duplicate tests have been deleted.

And delete unnecessary `//@ check-fail`

r? Kivooeo
2026-04-24 02:42:49 -04:00
Ben Kimock 4b1f3926de Avoid query cycles in DataflowConstProp
* Avoid query cycles in DataflowConstProp
* Add -Zmir-opt-level=0 to the test
2026-04-24 03:04:03 +00:00
Trevor Gross 6c683adbdf Rollup merge of #153482 - DanielEScherzer:test-references-macros, r=ehuss
tests/ui/macros: add annotations for reference rules
2026-04-23 20:32:48 -04:00
Trevor Gross 85468d1fdb Rollup merge of #155660 - folkertdev:sparc64-c-variadic, r=tgross35
c-variadic: fix for sparc64

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

Turns out it's a big-endian target that right-adjusts values in the stack slots.

Apparently these tests do get run occasionally, though i don't think test failures are usually turned into issues on this repo. I guess we could add an assembly test here too, though really you just have to run these tests. I've tried this locally with qemu, and it passes all c-variadic tests.

cc @thejpster @glaubitz
r? tgross35
2026-04-23 20:32:48 -04:00
dianqk 250beb3174 explicit-tail-calls: disable two tests on LoongArch for LLVM 22 also
Tail call support for LoongArch was reverted in LLVM 22 also.
2026-04-24 06:36:32 +08:00
León Orell Valerian Liehr 07d015e566 Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression 2026-04-23 22:28:00 +02:00
Folkert de Vries 797059769e c-variadic: fix for sparc64
validated versus https://godbolt.org/z/qrM37rY6n
2026-04-23 14:46:44 +02:00
Guillaume Gomez 8a4df7744f Rollup merge of #155637 - qaijuang:fix-e0191-empty-dyn-trait-suggestion, r=fmease
Fix E0191 suggestion for empty dyn trait args

Fixes rust-lang/rust#155578.
2026-04-23 14:42:49 +02:00
Guillaume Gomez 8c3864b6cc Rollup merge of #155561 - cijiugechu:fix/need-type-info-underscore-wording, r=adwinwhite
Use singular wording for single _ placeholders in type suggestions

While looking this part of code, I noticed this FIXME and fixed it :)
2026-04-23 14:42:48 +02:00
Guillaume Gomez abce9f98d7 Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt
Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-04-23 14:42:47 +02:00
Guillaume Gomez 0595fcd195 Rollup merge of #154957 - lapla-cogito:issue_153891, r=oli-obk
Fix ICE when const closure appears inside a non-const trait method

Fixes rust-lang/rust#153891

`hir_body_const_context()` unconditionally delegated to the parent's const context for const closures, returning `None` when the parent had no const context. This caused `mir_const_qualif()` to hit a `span_bug!`, since `mir_promoted()` had already decided to call it based on the closure's own syntactic constness. Fall back to `ConstContext::ConstFn` when the parent's const context is `None`, so that the const closure body is still properly const-checked rather than triggering an ICE.

Examining [another attempt](https://github.com/rust-lang/rust/pull/153900/changes) at this issue (which has already been closed), I thought that its approach represents a workaround fix to avoid inconsistencies in the caller of `mir_promoted()`, whereas I think the correct behavior is for `hir_body_const_context()` itself to return the proper value.
2026-04-23 14:42:47 +02:00
Guillaume Gomez aebbe6bb5f Rollup merge of #155644 - aerooneqq:delegation-self-ty-propagation-2, r=petrochenkov
delegation: support self ty propagation for functions in free to trait reuse

This PR adds support for self types specified in free to trait reuse. Up to this point we always generated `Self` despite the fact whether self type was specified or not. Now we use it in signature inheritance. Moreover we no more generate `Self` for static methods. Part of rust-lang/rust#118212.

```rust
trait Trait<T> {
  fn foo<const B: bool>(&self) {}
  fn bar() {}
}

impl<T> Trait<T> for usize {}

reuse <usize as Trait>::foo;

// Desugaring (no `Self` as usize is specified)
fn foo<T, const B: bool>(self: &usize) {
  <usize as Trait::<T>>::foo::<B>(self)
}

reuse Trait::bar;

// Desugaring (no `Self` as static method)
fn bar<T>() {
  Trait::<T>::bar(); //~ERROR: type annotations needed
}
```

r? @petrochenkov
2026-04-23 14:42:46 +02:00
Guillaume Gomez 4f4c1d553e Rollup merge of #155469 - Jules-Bertholet:titlecase-idents, r=petrochenkov
Account for titlecase in casing lints

Puts https://github.com/rust-lang/rust/issues/153892 to work.

Also contains fixes for Greek final sigma casing.

There are probably still some edge cases left to fix. Ideally we would use https://www.unicode.org/reports/tr55/#Identifier-Chunks as a base.

@rustbot label A-Unicode A-diagnostics A-lints A-suggestion-diagnostics
2026-04-23 14:42:45 +02:00
Qai Juang 4d2b607aa8 Fix E0191 suggestion for empty dyn trait args
* Fix E0191 suggestion for empty dyn trait args
* Fix tidy check
* address code nit
* fold test into existing E0191 test
2026-04-23 12:32:33 +00:00
Amanieu d'Antras b15544d52f Handle index projections in call destinations in DSE
Since call destinations are evaluated after call arguments, we can't
turn copy arguments into moves if the same local is later used as an
index projection in the call destination.
2026-04-23 11:17:22 +01:00
Jonathan Brouwer 610bfadb9b Rollup merge of #155630 - Zalathar:skip-filecheck, r=jieyouxu
Make `//@ skip-filecheck` a normal compiletest directive

The `skip-filecheck` directive is currently used by mir-opt tests, to suppress the default behaviour of running LLVM's `FileCheck` tool to check MIR output against FileCheck rules in the test file.

The `skip-filecheck` directive was not included in the big migration to `//@` directive syntax (https://github.com/rust-lang/rust/pull/121370), perhaps because it was parsed and processed in the *miropt-test-tools* helper crate, not in compiletest itself.

Recently I noticed that a small number of *codegen-llvm* tests were using the `//@ build-pass` directive, which has the non-obvious effect of skipping FileCheck in codegen tests. That's quite confusing, so I decided to have the mir-opt tests migrate over to a proper `//@ skip-filecheck` directive, which could then be used by codegen tests as well.

(I also added skip-filecheck support to assembly tests, which are very similar to codegen tests, though there are currently no assembly tests that actually use `//@ skip-filecheck`.)

---

Support for using `//@ build-pass` in codegen tests to skip FileCheck was introduced in https://github.com/rust-lang/rust/pull/113603. With hindsight, I think doing things that way was pretty clearly a  mistake, and we'll be better off with `//@ skip-filecheck`.

r? jieyouxu
2026-04-23 09:38:24 +02:00
Jonathan Brouwer d289cc7f53 Rollup merge of #155614 - folkertdev:rename-next-arg, r=tgross35
c-variadic: rename `VaList::arg` to `VaList::next_arg`

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

per [the T-libs-api meeting](https://hackmd.io/d9D6vUnuTnCWygkc3hffEw#nominated-rusttf44930-Tracking-issue-for-RFC-2137-Support-defining-C-compatible-variadic-functions-in-Rust-c_variadic), rename `VaList::arg` to `VaList::next_arg`.
2026-04-23 09:38:23 +02:00
Jonathan Brouwer 6cc506c5db Rollup merge of #152576 - folkertdev:mips-va-arg, r=tgross35
c-variadic: use `emit_ptr_va_arg` for  mips

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

After reading the implementation carefully, I believe it really is just `emit_ptr_va_arg`.

The LLVM implementation can be found here: https://github.com/llvm/llvm-project/blob/289a3292be0c6a3df86bcdf5be7dd05b79a5570c/llvm/lib/Target/Mips/MipsISelLowering.cpp#L2338.

r? workingjubilee
2026-04-23 09:38:22 +02:00
Jonathan Brouwer 280345333a Rollup merge of #154819 - cijiugechu:fix-next-solver-inherent-iat-ice, r=jackh726
Fix ICE for inherent associated type mismatches

Avoid projection-only suggestions for inherent associated types.

Closes rust-lang/rust#154333
Closes rust-lang/rust#155204
2026-04-23 09:38:20 +02:00
teor c0441d42ed Fix Mlibc env pretty print to Managarm C Library 2026-04-23 17:07:21 +10:00
aerooneqq 78435a9ff8 Remove #![allow(incomplete_features)] from delegation tests 2026-04-23 09:37:48 +03:00
Jules Bertholet 0dca30756d Account for titlecase in casing lints 2026-04-23 00:43:18 -04:00
Folkert de Vries e9ab558406 va_arg: use emit_ptr_va_arg for mips 2026-04-23 01:20:59 +02:00
Folkert de Vries 328d05309c c-variadic: add mips assembly test 2026-04-23 01:09:37 +02:00
bors 913e4bea83 Auto merge of #155655 - JonathanBrouwer:rollup-KFUw3UR, r=JonathanBrouwer
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#154794 (Add on_unmatch_args)
 - rust-lang/rust#155133 (Document precision considerations of `Duration`-float methods)
 - rust-lang/rust#154283 (Remove `nodes_in_current_session` field and related assertions)
 - rust-lang/rust#155374 (rustdoc: fix a few spots where emit isn't respected)
 - rust-lang/rust#155587 (Immediately feed visibility on DefId creation)
 - rust-lang/rust#155622 (c-variadic: `va_arg` fixes )
 - rust-lang/rust#155629 (rustc_public: Add `constness` & `asyncness` in `FnDef`)
 - rust-lang/rust#155632 (Some metadata cleanups)
 - rust-lang/rust#155639 (BinOpAssign always returns unit)
 - rust-lang/rust#155647 (rustc-dev-guide subtree update)
2026-04-22 19:16:27 +00:00
Jonathan Brouwer c4b5ea9625 Rollup merge of #155639 - oli-obk:builtin-binop-const, r=nnethercote
BinOpAssign always returns unit

I don't know why we treated assign ops as returning their binop type sometimes, but it's usually ignored later anyway and mostly affects infer vars.

Also updated a comment from 11 years ago when SIMD types apparently had builtin `==` logic.
2026-04-22 19:18:32 +02:00
Jonathan Brouwer b0d794f425 Rollup merge of #155629 - cijiugechu:fn_constness, r=makai410
rustc_public: Add `constness` & `asyncness` in `FnDef`

Resolves [https://github.com/rust-lang/project-stable-mir/issues/111](https://github.com/rust-lang/project-stable-mir/issues/111).
2026-04-22 19:18:31 +02:00
Jonathan Brouwer dcde112616 Rollup merge of #155374 - notriddle:non-static-dep-info, r=fmease
rustdoc: fix a few spots where emit isn't respected

Addresses the third list item of rust-lang/rust#155298
2026-04-22 19:18:29 +02:00
bors f676c20edd Auto merge of #155343 - dianqk:indirect-by-ref, r=nikic
codegen: Copy to an alloca when the argument is neither by-val nor by-move for indirect pointer.



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

When a value is passed via an indirect pointer, the value needs to be copied to a new alloca. For x86_64-unknown-linux-gnu, `Thing` is the case:

```rust
#[derive(Clone, Copy)]
struct Thing(usize, usize, usize);

pub fn foo() {
    let thing = Thing(0, 0, 0);
    bar(thing);
    assert_eq!(thing.0, 0);
}

#[inline(never)]
#[unsafe(no_mangle)]
pub fn bar(mut thing: Thing) {
    thing.0 = 1;
}
```

Before passing the thing to the bar function, the thing needs to be copied to an alloca that is passed to bar.

```llvm
%0 = alloca [24 x i8], align 8
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %thing, i64 24, i1 false)
call void @bar(ptr %0)
```

This patch applies the rule to the untupled arguments as well.

```rust
#![feature(fn_traits)]

#[derive(Clone, Copy)]
struct Thing(usize, usize, usize);

#[inline(never)]
#[unsafe(no_mangle)]
pub fn foo() {
    let thing = (Thing(0, 0, 0),);
    (|mut thing: Thing| {
        thing.0 = 1;
    }).call(thing);
    assert_eq!(thing.0.0, 0);
}
```

For this case, this patch changes from

```llvm
; call example::foo::{closure#0}
call void @_RNCNvCs15qdZVLwHPA_7example3foo0B3_(ptr ..., ptr %thing)
```

to

```llvm
%0 = alloca [24 x i8], align 8
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %thing, i64 24, i1 false)
; call example::foo::{closure#0}
call void @_RNCNvCs15qdZVLwHPA_7example3foo0B3_(ptr ..., ptr %0)
```

However, the same rule cannot be applied to tail calls that would be unsound, because the caller's stack frame is overwritten by the callee's stack frame. Fortunately, https://github.com/rust-lang/rust/pull/151143 has already handled the special case. We must not copy again.

No copy is needed for by-move arguments, because the argument is passed to the called "in-place".

No copy is also needed for by-val arguments, because the attribute implies that a hidden copy of the pointee is made between the caller and the callee.


NOTE: The patch has a trick for tail calls that we pass by-move. We can choose to copy an alloca even for by-move arguments, but tail calls require MUST-by-move.
2026-04-22 15:47:21 +00:00