about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-08-18Allow stability attributes on extern cratesJonathan Brouwer-0/+1
2025-08-18nll-relate: improve hr opaque types supportlcnr-9/+22
2025-08-18Rollup merge of #145485 - JonathanBrouwer:fix-deprecation-targets, ↵Stuart Cook-0/+5
r=jdonszelmann Fix deprecation attributes on foreign statics r? ````````@jdonszelmann```````` Fixes https://github.com/rust-lang/rust/issues/145437
2025-08-18Rollup merge of #145420 - Zalathar:llvm-c, r=WaffleLapkinStuart Cook-89/+14
cg_llvm: Use LLVM-C bindings for `LLVMSetTailCallKind`, `LLVMGetTypeKind` This PR replaces two existing `LLVMRust` bindings with equivalent calls to the LLVM-C API. For `LLVMGetTypeKind`, we avoid the UB hazard by declaring the foreign function to return `RawEnum<TypeKind>` (which is a wrapper around `u32`), and then perform checked conversion from `u32` to `TypeKind`.
2025-08-18Rollup merge of #145309 - winstonallo:issue-145271-fix, r=tgross35Stuart Cook-0/+9
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-18Rollup merge of #145208 - joshtriplett:mbe-derive, r=petrochenkovStuart Cook-20/+220
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-18Rollup merge of #145206 - scrabsha:push-uxovoqzrxnlx, r=jdonszelmannStuart Cook-91/+318
Port `#[custom_mir(..)]` to the new attribute system r? ``````````@jdonszelmann``````````
2025-08-18change riscv64a23 target reqirements comments: linux kernel 6.8.0, glibc 2.39Zhongyao Chen-1/+1
2025-08-17Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.Zachary S-7/+18
2025-08-17Add `-Zindirect-branch-cs-prefix` optionMiguel Ojeda-1/+13
This is intended to be used for Linux kernel RETPOLINE builds. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-08-17Add -Zindirect-branch-cs-prefix (from draft PR)Alice Ryhl-0/+12
2025-08-17resolve: debug for block modulebohan-1/+4
2025-08-17Auto merge of #145284 - nnethercote:type_name-print-regions, r=lcnrbors-45/+62
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-17Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obkbors-202/+230
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-16tidy now installs typos-cli as-needed via cargobinarycat-3/+3
2025-08-16Visit and print async_fut local for async drop.Camille Gillot-2/+12
2025-08-16Only unpack span data once.Camille Gillot-7/+7
2025-08-17refactor return type of `suggest_ampmut` into an enumDeadbeef-171/+178
2025-08-16Only scan each definition once.Camille GILLOT-13/+16
2025-08-16Simplify span_data_to_lines_and_cols.Camille Gillot-16/+14
2025-08-16Simplify decode_span.Camille Gillot-28/+23
2025-08-16run spellcheck as a tidy extra check in cibinarycat-2/+2
2025-08-16overhaul `&mut` suggestions in borrowck errorsDeadbeef-323/+360
2025-08-16Clean up parsers related to generic boundsLeón Orell Valerian Liehr-97/+79
2025-08-16remove `should_render` in `PrintAttribute` deriveDeadbeef-40/+20
2025-08-16Auto merge of #145304 - m-ou-se:simplify-panic, r=oli-obkbors-9/+6
Revert "Partially outline code inside the panic! macro". This reverts https://github.com/rust-lang/rust/pull/115670 Without any tests/benchmarks that show some improvement, it's hard to know whether the change had any positive effect. (And if it did, whether that effect is still achieved today.)
2025-08-16take attr style into account in attr diagnosticsJana Dönszelmann-13/+35
2025-08-16Fix deprecation attribute on foreign statics & typesJonathan Brouwer-0/+2
2025-08-16Don't show foreign types as an allowed target if the feature is not enabledJonathan Brouwer-0/+3
2025-08-16Add parentheses for closure when suggesting calling closureMu001999-6/+10
2025-08-16Remove `LlvmArchiveBuilder` and supporting code/bindingsZalathar-543/+6
2025-08-16Properly recover from parenthesized use-bounds (precise capturing)León Orell Valerian Liehr-16/+26
2025-08-15Auto merge of #145475 - jhpratt:rollup-jr0wado, r=jhprattbors-2/+209
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-15Rollup merge of #144922 - Kobzol:derive-from, r=nnethercoteJacob Pratt-2/+176
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-15Rollup merge of #144907 - ShoyuVanilla:no-const-async, r=fmeaseJacob Pratt-0/+33
fix: Reject async assoc fns of const traits/impls in ast_passes Fixes rust-lang/rust#117629
2025-08-15Auto merge of #142071 - lcnr:revealing-use, r=compiler-errorsbors-1/+12
`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-15Extend `QueryStability` to handle `IntoIterator` implementationsSamuel Moelius-50/+92
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-15Demote x86_64-apple-darwin to Tier 2 with host toolsJake Goulding-1/+1
Switch to only using aarch64 runners (implying we are now cross-compiling) and stop running tests. In the future, we could enable (some?) tests via Rosetta 2.
2025-08-15Detect missing `derive` on unresolved attribute even when not importedEsteban Küber-27/+39
``` 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-15Auto merge of #145450 - Kobzol:rollup-cqclix0, r=Kobzolbors-11/+22
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-15Rollup merge of #145430 - Urgau:drop_forget_useless-145427, r=lqdJakub Beránek-1/+1
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-15Rollup merge of #145408 - Kobzol:deduplicate-search-paths, r=petrochenkovJakub Beránek-10/+21
Deduplicate -L search paths For each -L passed to the compiler, we eagerly scan the whole directory. If it has a lot of files, that results in a lot of allocations. So it's needless to do this if some -L paths are actually duplicated (which can happen e.g. in the situation in the linked issue). This PR both deduplicates the args, and also teaches rustdoc not to pass duplicated args to merged doctests. Fixes: https://github.com/rust-lang/rust/issues/145375
2025-08-15Auto merge of #144991 - lcnr:ignore-usages-from-ignored-candidates, r=BoxyUwUbors-149/+386
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-15Sort mono items by symbol nameJakub Beránek-3/+20
2025-08-15Simplify the `args_cstr_buff` assertionZalathar-5/+4
2025-08-15Avoid an unnecessary intermediate `&mut` referenceZalathar-1/+1
The `NonNull::as_mut` method returns a mut *reference*, rather than the mut *pointer* that is intended here.
2025-08-15Avoid an explicit cast from `*const c_uchar` to `*const c_char`Zalathar-3/+3
As noted in the `ffi` module docs, passing pointer/length byte strings from Rust to C++ is easier if we declare them as `*const c_uchar` on the Rust side, but `const char *` (possibly signed) on the C++ side. This is allowed because both pointer types are ABI-compatible, regardless of char signedness.
2025-08-15Declare module `rustc_codegen_llvm::back` in the normal wayZalathar-8/+6
Declaring these submodules directly in `lib.rs` was needlessly confusing.
2025-08-15Implement `#[derive(From)]`Jakub Beránek-5/+161
2025-08-15Create unstable `From` builtin macro and register itJakub Beránek-0/+15