Commit Graph

21219 Commits

Author SHA1 Message Date
Stuart Cook
2beb54c451 Rollup merge of #140956 - Kixunil:impl-partialeq-str-for-path, r=Amanieu
`impl PartialEq<{str,String}> for {Path,PathBuf}`

This is a revival of #105877

Comparison of paths and strings is expected to be possible and needed e.g. in tests. This change adds the impls os `PartialEq` between strings and paths, both owned and unsized, in both directions.

ACP: https://github.com/rust-lang/libs-team/issues/151
2025-08-19 14:18:14 +10:00
Zhongyao Chen
45ea228c42 completely remove rva23s64 2025-08-19 10:33:54 +08:00
bors
9eb4a26520 Auto merge of #145489 - joshtriplett:cfg-if-not, r=Amanieu
library: Migrate from `cfg_if` to `cfg_select`

Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does.

Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-08-18 19:37:33 +00:00
Caiweiran
9d08596a2e tests: fix RISC-V failures and adjust transmute-scalar.rs target
Resolve several ./x test failures on RISC-V caused by ABI and codegen
differences. Update multiple codegen-llvm tests for compatibility, and
explicitly set the target for transmute-scalar.rs to x86_64 to ensure
consistent behavior across hosts.
2025-08-18 19:37:13 +00:00
Augie Fackler
79d30067f3 cleanup: make run-make test use run_in_tmpdir
We had an issue on our LLVM-head Rust builder where it got stuck with
this test failing because it was reusing the tmpdir between runs and
something broke the incremental compile. Everything seems to work fine
with run_in_tmpdir in this test. tests/run-make/uefi-qemu also uses the
same tmpdir across runs, but I don't have the right environment to test
that so I didn't try fixing it. That is the only use of
std::env::temp_dir left in run-make tests after this fix.
2025-08-18 15:28:48 -04:00
Jieyou Xu
ddd99930f3 Turn invalid index suffixes into hard errors 2025-08-18 21:57:11 +08:00
Jieyou Xu
eb3441b25a Add test coverage for proc-macro invalid tup index suffixes 2025-08-18 21:57:10 +08:00
Jieyou Xu
d7f7443a95 Expand tuple-index-suffix test coverage
Actually, the accidentally accepted invalid suffixes also include tuple
struct indexing positions, struct numeral field name positions. So
before changing anything, first expand test coverage, so we can observe
the effect of bumping the non-lint pseudo-FCW warning into a hard error.
2025-08-18 21:57:09 +08:00
Jieyou Xu
ea44f12f72 Rename and move tuple index suffix regression test
To make it more obvious what it's testing.

This is its own commit to make git blame easier.
2025-08-18 21:57:09 +08:00
Deadbeef
c335d5781d ignore frontmatters in TokenStream::new 2025-08-18 20:28:29 +08:00
Jakub Beránek
a6a760edaf Remove the From derive macro from prelude
To avoid backwards compatibility problems.
2025-08-18 13:12:19 +02:00
Bastian Kersting
95bdb34494 Remove the no_sanitize attribute in favor of sanitize
This removes the #[no_sanitize] attribute, which was behind an unstable
feature named no_sanitize. Instead, we introduce the sanitize attribute
which is more powerful and allows to be extended in the future (instead
of just focusing on turning sanitizers off).

This also makes sanitize(kernel_address = ..) attribute work with
-Zsanitize=address

To do it the same as how clang disables address sanitizer, we now
disable ASAN on sanitize(kernel_address = "off") and KASAN on
sanitize(address = "off").

The same was added to clang in https://reviews.llvm.org/D44981.
2025-08-18 08:45:28 +00:00
Bastian Kersting
3ef065bf87 Implement the #[sanitize(..)] attribute
This change implements the #[sanitize(..)] attribute, which opts to
replace the currently unstable #[no_sanitize]. Essentially the new
attribute works similar as #[no_sanitize], just with more flexible
options regarding where it is applied. E.g. it is possible to turn
a certain sanitizer either on or off:
`#[sanitize(address = "on|off")]`

This attribute now also applies to more places, e.g. it is possible
to turn off a sanitizer for an entire module or impl block:
```rust
\#[sanitize(address = "off")]
mod foo {
    fn unsanitized(..) {}

    #[sanitize(address = "on")]
    fn sanitized(..) {}
}

\#[sanitize(thread = "off")]
impl MyTrait for () {
    ...
}
```

This attribute is enabled behind the unstable `sanitize` feature.
2025-08-18 08:30:00 +00:00
lcnr
f5e43d5ee3 nll-relate: improve hr opaque types support 2025-08-18 09:09:42 +02:00
Stuart Cook
ab57f43bc8 Rollup merge of #145485 - JonathanBrouwer:fix-deprecation-targets, r=jdonszelmann
Fix deprecation attributes on foreign statics

r? ````````@jdonszelmann````````

Fixes https://github.com/rust-lang/rust/issues/145437
2025-08-18 15:31:15 +10:00
Stuart Cook
3a694c7595 Rollup merge of #145355 - clubby789:option-match-eq, r=nikic
Add codegen test for issue 122734

Closes rust-lang/rust#122734
2025-08-18 15:31:12 +10:00
Stuart Cook
1e454c64b2 Rollup merge of #145309 - winstonallo:issue-145271-fix, r=tgross35
Fix `-Zregparm` for LLVM builtins

This fixes the issue where `-Zregparm=N` was not working correctly when calling LLVM intrinsics

By default on `x86-32`, arguments are passed on the stack. The `-Zregparm=N` flag allows the first `N` arguments to be passed in registers instead.

When calling intrinsics like `memset`, LLVM still passes parameters on the stack, which prevents optimizations like tail calls.

As proposed by ````@tgross35,```` I fixed this by setting the `NumRegisterParameters` LLVM module flag to `N` when the `-Zregparm=N` is set.

```rust
// compiler/rust_codegen_llvm/src/context.rs#375-382
if let Some(regparm_count) = sess.opts.unstable_opts.regparm {
    llvm::add_module_flag_u32(
        llmod,
        llvm::ModuleFlagMergeBehavior::Error,
        "NumRegisterParameters",
        regparm_count,
    );
}
```
[Here](https://rust.godbolt.org/z/YMezreo48) is a before/after compiler explorer.

Here is the final result for the code snippet in the original issue:
```asm
entrypoint:
        push    esi
        mov     esi, eax
        mov     eax, ecx
        mov     ecx, esi
        pop     esi
        jmp     memset   ; Tail call parameters in registers
```

Fixes: https://github.com/rust-lang/rust/issues/145271
2025-08-18 15:31:11 +10:00
Stuart Cook
152b43c7cb Rollup merge of #145208 - joshtriplett:mbe-derive, r=petrochenkov
Implement declarative (`macro_rules!`) derive macros (RFC 3698)

This is a draft for review, and should not be merged yet.

This is layered atop https://github.com/rust-lang/rust/pull/145153 , and has
only two additional commits atop that. The first handles parsing and provides a
test for various parse errors. The second implements expansion and handles
application.

This implements RFC 3698, "Declarative (`macro_rules!`) derive macros".
Tracking issue: https://github.com/rust-lang/rust/issues/143549

This has one remaining issue, which I could use some help debugging: in
`tests/ui/macros/macro-rules-derive-error.rs`, the diagnostics for
`derive(fn_only)` (for a `fn_only` with no `derive` rules) and
`derive(ForwardReferencedDerive)` both get emitted twice, as a duplicate
diagnostic.

From what I can tell via adding some debugging code,
`unresolved_macro_suggestions` is getting called twice from
`finalize_macro_resolutions` for each of them, because
`self.single_segment_macro_resolutions` has two entries for the macro, with two
different `parent_scope` values. I'm not clear on why that happened; it doesn't
happen with the equivalent code using attrs.

I'd welcome any suggestions for fixing this.
2025-08-18 15:31:10 +10:00
Josh Triplett
c44c1bbe87 Fix up library crate order in linker test 2025-08-17 15:45:05 -07:00
Zachary S
c7cd1b3b9d Do not consider a T: !Sized candidate to satisfy a T: !MetaSized obligation. 2025-08-17 13:37:32 -05:00
Oneirical
75e0263af9 Rehome tests/ui/issues/ tests [5/?] 2025-08-17 13:01:02 -04:00
Miguel Ojeda
1a29d9c23f Add -Zindirect-branch-cs-prefix option
This is intended to be used for Linux kernel RETPOLINE builds.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-08-17 16:51:42 +02:00
Alice Ryhl
1cd7080c3a Add -Zindirect-branch-cs-prefix (from draft PR) 2025-08-17 16:50:23 +02:00
Samuel Moelius
3b0ff9cb69 Add //@ ignore-stage1 to query_stability.rs test 2025-08-17 10:32:13 -04:00
nilptr
12eb1a0bce feat(lldb debug info): improve enum value formatting in lldb 2025-08-17 21:15:18 +08:00
bors
425a9c0a0e Auto merge of #145284 - nnethercote:type_name-print-regions, r=lcnr
Print regions in `type_name`.

Currently they are skipped, which is a bit weird, and it sometimes causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`.

Most regions are erased by the time `type_name` does its work. So all regions are now printed as `'_` in non-optional places. Not perfect, but better than the status quo.

`c_name` is updated to trim lifetimes from MIR pass names, so that the `PASS_NAMES` sanity check still works. It is also renamed as `simplify_pass_type_name` and made non-const, because it doesn't need to be const and the non-const implementation is much shorter.

The commit also renames `should_print_region` as `should_print_optional_region`, which makes it clearer that it only applies to some regions.

Fixes rust-lang/rust#145168.

r? `@lcnr`
2025-08-17 10:24:20 +00:00
bors
99ba556567 Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obk
const-eval: full support for pointer fragments

This fixes https://github.com/rust-lang/const-eval/issues/72 and makes `swap_nonoverlapping` fully work in const-eval by enhancing per-byte provenance tracking with tracking of *which* of the bytes of the pointer this one is. Later, if we see all the same bytes in the exact same order, we can treat it like a whole pointer again without ever risking a leak of the data bytes (that encode the offset into the allocation). This lifts the limitation that was discussed quite a bit in https://github.com/rust-lang/rust/pull/137280.

For a concrete piece of code that used to fail and now works properly consider this example doing a byte-for-byte memcpy in const without using intrinsics:
```rust
use std::{mem::{self, MaybeUninit}, ptr};

type Byte = MaybeUninit<u8>;

const unsafe fn memcpy(dst: *mut Byte, src: *const Byte, n: usize) {
    let mut i = 0;
    while i < n {
        *dst.add(i) = *src.add(i);
        i += 1;
    }
}

const _MEMCPY: () = unsafe {
    let ptr = &42;
    let mut ptr2 = ptr::null::<i32>();
    // Copy from ptr to ptr2.
    memcpy(&mut ptr2 as *mut _ as *mut _, &ptr as *const _ as *const _, mem::size_of::<&i32>());
    assert!(*ptr2 == 42);
};
```
What makes this code tricky is that pointers are "opaque blobs" in const-eval, we cannot just let people look at the individual bytes since *we don't know what those bytes look like* -- that depends on the absolute address the pointed-to object will be placed at. The code above "breaks apart" a pointer into individual bytes, and then puts them back together in the same order elsewhere. This PR implements the logic to properly track how those individual bytes relate to the original pointer, and to recognize when they are in the right order again.

We still reject constants where the final value contains a not-fully-put-together pointer: I have no idea how one could construct an LLVM global where one byte is defined as "the 3rd byte of a pointer to that other global over there" -- and even if LLVM supports this somehow, we can leave implementing that to a future PR. It seems unlikely to me anyone would even want this, but who knows.^^

This also changes the behavior of Miri, by tracking the order of bytes with provenance and only considering a pointer to have valid provenance if all bytes are in the original order again. This is related to https://github.com/rust-lang/unsafe-code-guidelines/issues/558. It means one cannot implement XOR linked lists with strict provenance any more, which is however only of theoretical interest. Practically I am curious if anyone will show up with any code that Miri now complains about - that would be interesting data. Cc `@rust-lang/opsem`
2025-08-17 04:33:31 +00:00
Deadbeef
4335405fa7 overhaul &mut suggestions in borrowck errors 2025-08-16 22:34:17 +08:00
León Orell Valerian Liehr
f8f7c27d4f Clean up parsers related to generic bounds 2025-08-16 16:15:58 +02:00
Jana Dönszelmann
70e26c1b7b take attr style into account in attr diagnostics 2025-08-16 10:51:09 +02:00
Jonathan Brouwer
a69ba29a0f Fix deprecation attribute on foreign statics & types 2025-08-16 09:44:43 +02:00
Mu001999
5e8c2c3aec Add parentheses for closure when suggesting calling closure 2025-08-16 15:07:38 +08:00
Mu001999
57feb7fc01 old testcase output 2025-08-16 15:01:17 +08:00
León Orell Valerian Liehr
eb3e0d4c8a Properly recover from parenthesized use-bounds (precise capturing) 2025-08-16 01:21:35 +02:00
bors
1ae7c49072 Auto merge of #145475 - jhpratt:rollup-jr0wado, r=jhpratt
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#143717 (Add `Default` impls for `Pin`ned `Box`, `Rc`, `Arc`)
 - rust-lang/rust#144054 (Stabilize as_array_of_cells)
 - rust-lang/rust#144907 (fix: Reject async assoc fns of const traits/impls in ast_passes)
 - rust-lang/rust#144922 (Implement `#[derive(From)]`)
 - rust-lang/rust#144963 (Stabilize `core::iter::chain`)
 - rust-lang/rust#145436 (fix(tests/rmake/wasm-unexpected-features): change features from `WASM1` to `MVP`)
 - rust-lang/rust#145453 (Remove duplicated tracing span in bootstrap)
 - rust-lang/rust#145454 (Fix tracing debug representation of steps without arguments in bootstrap)
 - rust-lang/rust#145455 (Do not copy files in `copy_src_dirs` in dry run)
 - rust-lang/rust#145462 (Stabilize `const_exposed_provenance` feature)
 - rust-lang/rust#145466 (Enable new `[range-diff]` feature in triagebot)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-15 23:10:31 +00:00
Jacob Pratt
58c08c512b Rollup merge of #145436 - StackOverflowExcept1on:patch-1, r=alexcrichton
fix(tests/rmake/wasm-unexpected-features): change features from `WASM1` to `MVP`

missed this in rust-lang/rust#145275
since test calls `rustc` with  `-C target-cpu mvp`
try-job: `test-various`
2025-08-15 18:13:30 -04:00
Jacob Pratt
2b1a288dfc Rollup merge of #144922 - Kobzol:derive-from, r=nnethercote
Implement `#[derive(From)]`

Implements the `#[derive(From)]` feature ([tracking issue](https://github.com/rust-lang/rust/issues/144889), [RFC](https://github.com/rust-lang/rfcs/pull/3809)).

It allows deriving the `From` impl on structs and tuple structs with exactly one field. Some implementation notes:
- I wasn't exactly sure which spans to use in the derive generating code, so I just used `span` everywhere. I don't know if it's the Right Thing To Do. In particular the errors when `#[derive(From)]` is used on a struct with an unsized field are weirdly duplicated.
- I had to solve an import stability problem, where if I just added the unstable `macro From` to `core::convert`, previously working code like `use std::convert::From` would suddenly require an unstable feature gate, because rustc would think that you're trying to import the unstable macro. `@petrochenkov` suggested that I add the macro the the core prelude instead. This has worked well, although it only works in edition 2021+. Not sure if I botched the prelude somehow and it should live elsewhere (?).
- I had to add `Ty::AstTy`, because the `from` function receives an argument with the type of the single field, and the existing variants of the `Ty` enum couldn't represent an arbitrary type.
2025-08-15 18:13:28 -04:00
Jacob Pratt
d077146a15 Rollup merge of #144907 - ShoyuVanilla:no-const-async, r=fmease
fix: Reject async assoc fns of const traits/impls in ast_passes

Fixes rust-lang/rust#117629
2025-08-15 18:13:28 -04:00
Jacob Pratt
7a05f26a3b Rollup merge of #144054 - jsimmons:stabilize-as-array-of-cells, r=tgross35
Stabilize as_array_of_cells

This PR stabilizes

```rust
impl<T, const N: usize> Cell<[T; N]> {
    pub const fn as_array_of_cells(&self) -> &[Cell<T>; N];
}
```

Stabilization report: https://github.com/rust-lang/rust/issues/88248#issuecomment-3082986863
Closes: https://github.com/rust-lang/rust/issues/88248
2025-08-15 18:13:27 -04:00
bors
cd7cbe818e Auto merge of #142071 - lcnr:revealing-use, r=compiler-errors
`apply_member_constraints`: fix placeholder check

Checking whether the member region is *an existential region from a higher universe* is just wrong and I am pretty sure we've added that check by accident as the naming was just horribly confusing before rust-lang/rust#140466.

I've encountered this issue separately while working on rust-lang/rust#139587, but feel like it's probably easier to separately FCP this change. This allows the following code to compile
```rust
trait Proj<'a> {
    type Assoc;
}
impl<'a, 'b, F: FnOnce() -> &'b ()> Proj<'a> for F {
    type Assoc = ();
}

fn is_proj<F: for<'a> Proj<'a>>(f: F) {}
fn define<'a>() -> impl Sized + use<'a> {
    // This adds a use of `opaque::<'a>` with hidden type `&'unconstrained_b ()`.
    // 'unconstrained_b is an inference variable from a higher universe as it gets
    // created inside of the binder of `F: for<'a> Proj<'a>`. This previously
    // caused us to not apply member constraints. We now do, constraining
    // it to `'a`.
    is_proj(define::<'a>);
    &()
}

fn main() {}
```

This should not be breaking change, even in theory. Applying member constraints is incomplete in rare circumstances which means that applying them in more cases can cause spurious errors, cc rust-lang/rust#140569/rust-lang/rust#142073. However, as we always skipped these member regions in `apply_member_constraints` the skipped region is guaranteed to cause an error in `check_member_constraints` later on.
2025-08-15 18:52:12 +00:00
Michael Howell
8511e40e72 rustdoc-search: search backend with partitioned suffix tree 2025-08-15 10:26:03 -07:00
Kivooeo
b951b5dca1 stabilize strict provenance atomic ptr 2025-08-15 16:56:11 +00:00
Kivooeo
489940ee1d stabilize array repeat 2025-08-15 16:42:21 +00:00
Samuel Moelius
c3c2c23e0d Extend QueryStability to handle IntoIterator implementations
Fix adjacent code

Fix duplicate warning; merge test into `tests/ui-fulldeps/internal-lints`

Use `rustc_middle::ty::FnSig::inputs`

Address two review comments

- https://github.com/rust-lang/rust/pull/139345#discussion_r2109006991
- https://github.com/rust-lang/rust/pull/139345#discussion_r2109058588

Use `Instance::try_resolve`

Import `rustc_middle::ty::Ty` as `Ty` rather than `MiddleTy`

Simplify predicate handling

Add more `#[allow(rustc::potential_query_instability)]` following rebase

Remove two `#[allow(rustc::potential_query_instability)]` following rebase

Address review comment

Update compiler/rustc_lint/src/internal.rs

Co-authored-by: lcnr <rust@lcnr.de>
2025-08-15 12:10:54 -04:00
Esteban Küber
8baab4cdf7 Detect missing derive on unresolved attribute even when not imported
```
error: cannot find attribute `sede` in this scope
  --> $DIR/missing-derive-3.rs:20:7
   |
LL |     #[sede(untagged)]
   |       ^^^^
   |
help: the derive macros `Deserialize` and `Serialize` accept the similarly named `serde` attribute
   |
LL |     #[serde(untagged)]
   |         +

error: cannot find attribute `serde` in this scope
  --> $DIR/missing-derive-3.rs:14:7
   |
LL |     #[serde(untagged)]
   |       ^^^^^
   |
note: `serde` is imported here, but it is a crate, not an attribute
  --> $DIR/missing-derive-3.rs:4:1
   |
LL | extern crate serde;
   | ^^^^^^^^^^^^^^^^^^^
help: `serde` is an attribute that can be used by the derive macros `Deserialize` and `Serialize`, you might be missing a `derive` attribute
   |
LL + #[derive(Deserialize, Serialize)]
LL | enum B {
   |
```
2025-08-15 15:56:45 +00:00
bors
8b1889cc22 Auto merge of #145450 - Kobzol:rollup-cqclix0, r=Kobzol
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#144210 (std: thread: Return error if setting thread stack size fails)
 - rust-lang/rust#145310 (Reduce usage of `compiler_for` in bootstrap)
 - rust-lang/rust#145311 (ci: clean windows disk space in background)
 - rust-lang/rust#145340 (Split codegen backend check step into two and don't run it with `x check compiler`)
 - rust-lang/rust#145408 (Deduplicate -L search paths)
 - rust-lang/rust#145412 (Windows: Replace `GetThreadId`+`GetCurrentThread` with `GetCurrentThreadId`)
 - rust-lang/rust#145413 (bootstrap: Reduce dependencies)
 - rust-lang/rust#145426 (Fix typos in bootstrap.example.toml)
 - rust-lang/rust#145430 (Fix wrong spans with external macros in the `dropping_copy_types` lint)
 - rust-lang/rust#145431 (Enhance UI test output handling for runtime errors)
 - rust-lang/rust#145448 (Autolabel `src/tools/{rustfmt,rust-analyzer}` changes with `T-{rustfmt,rust-analyzer}`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-15 15:44:03 +00:00
Jakub Beránek
c97a9c82b2 Rollup merge of #145430 - Urgau:drop_forget_useless-145427, r=lqd
Fix wrong spans with external macros in the `dropping_copy_types` lint

This PR fixes some wrong spans manipulations when external macros are involved.

Specifically we didn't make sure the spans had the same context, which kind-of make our spans manipulations go wrong and produce weird spans. We fix that by making sure they have the same context.

Fixes https://github.com/rust-lang/rust/issues/145427
2025-08-15 16:04:01 +02:00
StackOverflowExcept1on
f36ab498ce fix(tests/rmake/wasm-unexpected-features): change features from WASM1 to MVP 2025-08-15 15:48:46 +03:00
bors
c018ae5389 Auto merge of #144991 - lcnr:ignore-usages-from-ignored-candidates, r=BoxyUwU
ignore head usages from ignored candidates

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/210. The test now takes 0.8s to compile, which seems good enough to me. We are actually still walking the entire graph here, we're just avoiding unnecessary reruns.

The basic idea is that if we've only accessed a cycle head inside of a candidate which didn't impact the final result of our goal, we don't need to rerun that cycle head even if is the used provisional result differs from the final result.

We also use this information when rebasing goals over their cycle heads. If a goal doesn't actually depend on the result of that cycle head, rebasing always succeeds. However, we still need to make sure we track the fact that we relied on the cycle head at all to avoid query instability.

It is implemented by tracking the number of `HeadUsages` for every head while evaluating goals. We then also track the head usages while evaluating a single candidate, which the search graph returns as `CandidateHeadUsages`. If there is now an always applicable candidate  candidate we know that all other candidates with that source did not matter. We then call `fn ignore_candidate_head_usages` to remove the usages while evaluating this single candidate from the total. If the final `HeadUsages` end up empty, we know that the result of this cycle head did not matter when evaluating its nested goals.
2025-08-15 12:35:09 +00:00
Jakub Beránek
6f1c998ca9 Sort mono items by symbol name 2025-08-15 14:04:32 +02:00