about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-01-13Rollup merge of #135450 - hoodmane:wasm-eh-abort-fix, r=workingjubileeJacob Pratt-3/+3
Fix emscripten-wasm-eh with unwind=abort If we build the standard library with wasm-eh then we need to link with `-fwasm-exceptions` even if we compile with `panic=abort`. Without this change, linking a `panic=abort` crate fails with: `undefined symbol: __cpp_exception`. Followup to #131830. r? workingjubilee
2025-01-13Rollup merge of #135441 - compiler-errors:redundant-captures-lint, r=lqdJacob Pratt-1/+1
Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024 I never got sign-off on #127672 for this lint being warn by default in edition 2024, so let's turn downgrade this lint to allow for now. Should be backported so it ships with the edition. ```@rustbot``` label: +beta-nominated
2025-01-13Rollup merge of #135440 - lcnr:yeeeeeeeeeeeeeeeeeeeeeeet, r=compiler-errorsJacob Pratt-32/+24
rm unnecessary `OpaqueTypeDecl` wrapper
2025-01-13Rollup merge of #134977 - estebank:issue-112357, r=BoxyUwUJacob Pratt-5/+193
Detect `mut arg: &Ty` meant to be `arg: &mut Ty` and provide structured suggestion When a newcomer attempts to use an "out parameter" using borrows, they sometimes get confused and instead of mutating the borrow they try to mutate the function-local binding instead. This leads to either type errors (due to assigning an owned value to a mutable binding of reference type) or a multitude of lifetime errors and unused binding warnings. This change adds a suggestion to the type error ``` error[E0308]: mismatched types --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:6:14 | LL | fn change_object(mut object: &Object) { | ------- expected due to this parameter type LL | let object2 = Object; LL | object = object2; | ^^^^^^^ expected `&Object`, found `Object` | help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding | LL ~ fn change_object(object: &mut Object) { LL | let object2 = Object; LL ~ *object = object2; | ``` and to the unused assignment lint ``` error: value assigned to `object` is never read --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:11:5 | LL | object = &object2; | ^^^^^^ | note: the lint level is defined here --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:1:9 | LL | #![deny(unused_assignments, unused_variables)] | ^^^^^^^^^^^^^^^^^^ help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding | LL ~ fn change_object2(object: &mut Object) { LL | let object2 = Object; LL ~ *object = object2; | ``` Fix #112357.
2025-01-13Rollup merge of #134498 - oli-obk:push-wmxynprsyxvr, r=compiler-errorsJacob Pratt-9/+15
Fix cycle error only occurring with -Zdump-mir fixes #134205 During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building). Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
2025-01-13Fix emscripten-wasm-eh with unwind=abortHood Chatham-3/+3
If we build the standard library with wasm-eh then we need to link with `-fwasm-exceptions` even if we compile with `panic=abort` Without this change, linking a `panic=abort` crate fails with: `undefined symbol: __cpp_exception`. Followup to #131830.
2025-01-13Make sure to mark IMPL_TRAIT_REDUNDANT_CAPTURES as Allow in edition 2024Michael Goulet-1/+1
2025-01-13rm unnecessary `OpaqueTypeDecl` wrapperlcnr-32/+24
2025-01-13Auto merge of #135204 - RalfJung:win64-zst, r=SparrowLiibors-29/+39
fix handling of ZST in win64 ABI on windows-msvc targets The Microsoft calling conventions do not really say anything about ZST since they do not seem to exist in MSVC. However, both GCC and clang allow passing ZST over `__attribute__((ms_abi))` functions (which matches our `extern "win64" fn`) on `windows-gnu` targets, and therefore implicitly define a de-facto ABI for these types (and lucky enough they seem to define the same ABI). This ABI should be the same for windows-msvc and windows-gnu targets, so we use this as a hint for how to implement this ABI everywhere: we always pass ZST by-ref. The best alternative would be to just reject compiling functions which cannot exist in MSVC, but that would be a breaking change. Cc `@programmerjake` `@ChrisDenton` Fixes https://github.com/rust-lang/rust/issues/132893
2025-01-13Auto merge of #135167 - mzacho:depth-limit-const-eval-query, r=oli-obkbors-28/+20
Depth limit const eval query Currently the const-eval query doesn't have a recursion limit or timeout, causing the complier to freeze in an infinite loop, see #125718. This PR depth limits the `eval_to_const_value_raw` query (with the [`recursion_limit`](https://doc.rust-lang.org/reference/attributes/limits.html) attribute) and improves the diagnostics for query overflow errors, so spans are reported for other dep kinds than `layout_of` (e.g. `eval_to_const_value_raw`). fixes #125718 fixes #114192
2025-01-13Auto merge of #135371 - Mark-Simulacrum:no-alloc-case-cmp, r=compiler-errorsbors-3/+5
Remove allocations from case-insensitive comparison to keywords Follows up on work in 99d02fb40fd339255ed08596ebeb41e9b8a09d45, expanding the alloc-free comparisons to more cases of case-insensitive keyword matching. r? ghost for perf
2025-01-12Rollup merge of #135407 - joshtriplett:more-clippy, r=compiler-errorsGuillaume Gomez-10/+7
Deny various clippy lints Almost all of these clippy lints have zero occurrences. Two of them have one each, and this PR fixes those.
2025-01-12Rollup merge of #135406 - Aditya-PS-05:fix/unstable-lint-docs, r=compiler-errorsGuillaume Gomez-0/+5
Update unstable lint docs to include required feature attributes closes #135298 ## Summary This PR updates the documentation examples for the following unstable lints to ensure they include the necessary feature attributes for proper usage: - fuzzy_provenance_casts - lossy_provenance_casts - unqualified_local_imports - test_unstable_lint ## Changes Made: - Added the appropriate #![feature(...)] attributes to the example code for each lint. - Updated the examples to produce correct and meaningful warnings, ensuring they align with current lint behavior. Reference: - Used the `must_not_suspend` lint documentation as a template for these updates.
2025-01-12Rollup merge of #135383 - BoxyUwU:cov_tag_ptr, r=compiler-errorsGuillaume Gomez-985/+291
De-abstract tagged ptr and make it covariant In #135272 I needed to use a tagged ptr in `hir::TyKind` in order to not regress hir type sizes. Unfortunately the existing `CopyTaggedPtr` abstraction is insufficient as it makes the `'hir` lifetime invariant. I spent some time trying to keep existing functionality while making it covariant but in the end I realised that actually we dont use *any* of this code *anywhere* in rustc, so I've just removed everything and replaced it with a much less general abstraction that is suitable for what I need in #135272. Idk if anyone has a preference for just keeping all the abstractions here in case anyone needs them in the future :woman_shrugging:
2025-01-13remove test_unstable_lint featureAditya-PS-05-1/+2
2025-01-12De-abstract tagged pointer abstractionBoxy-985/+291
2025-01-12Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgrbors-112/+123
Rollup of 6 pull requests Successful merges: - #129259 (Add inherent versions of MaybeUninit methods for slices) - #135374 (Suggest typo fix when trait path expression is typo'ed) - #135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass) - #135378 (Remove a bunch of diagnostic stashing that doesn't do anything) - #135397 (compiletest: add erroneous variant to `string_enum`s conversions error) - #135398 (add more crash tests) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-12Update unstable lint docs to include required feature attributesAditya-PS-05-0/+4
2025-01-12Deny `clippy:;four_forward_slashes` and fix the only occurrenceJosh Triplett-1/+1
2025-01-12Deny `clippy::format_in_format_args` and fix the only occurrenceJosh Triplett-9/+6
2025-01-12on Windows, consistently pass ZST by-refRalf Jung-50/+15
2025-01-12Rollup merge of #135378 - compiler-errors:unnecessary-stashing, r=chenyukangMatthias Krüger-63/+14
Remove a bunch of diagnostic stashing that doesn't do anything #121669 removed a bunch of conditional diagnostic stashing/canceling, but left around the `steal` calls which just emitted the error eagerly instead of canceling the diagnostic. I think that these no-op `steal` calls don't do much and are confusing to encounter, so let's remove them. The net effect is: 1. We emit more duplicated errors, since stashing has the side effect of duplicating diagnostics. This is not a big deal, since outside of `-Zdeduplicate-diagnostics=no`, the errors are already being deduplicated by the compiler. 2. It changes the order of diagnostics, since we're no longer stashing and then later stealing the errors. I don't think this matters much for the changes that the UI test suite manifests, and it makes these errors less order dependent.
2025-01-12Rollup merge of #135377 - compiler-errors:impossible-step, r=oli-obkMatthias Krüger-46/+59
Make MIR cleanup for functions with impossible predicates into a real MIR pass It's a bit jarring to see the body of a function with an impossible-to-satisfy where clause suddenly go to a single `unreachable` terminator when looking at the MIR dump output in order, and I discovered it's because we manually replace the body outside of a MIR pass. Let's make it into a fully flegded MIR pass so it's more clear what it's doing and when it's being applied.
2025-01-12Rollup merge of #135374 - compiler-errors:typo-trait-method, r=fee1-deadMatthias Krüger-2/+49
Suggest typo fix when trait path expression is typo'ed When users write something like `Default::defualt()` (notice the typo), failure to resolve the erroneous `defualt` item will cause resolution + lowering to interpret this as a type-dependent path whose self type is `Default` which is a trait object without `dyn`, rather than a trait function like `<_ as Default>::default()`. Try to provide a bit of guidance in this situation when we can detect the typo. Fixes https://github.com/rust-lang/rust/issues/135349
2025-01-12Rollup merge of #129259 - clarfonthey:maybe_uninit_slices, r=tgross35Matthias Krüger-1/+1
Add inherent versions of MaybeUninit methods for slices This is my attempt to un-stall #63569 and #79995, by creating methods that mirror the existing `MaybeUninit` API: ```rust impl<T> MaybeUninit<T> { pub fn write(&mut self, value: T) -> &mut T; pub fn as_bytes(&self) -> &[MaybeUninit<u8>]; pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]; pub unsafe fn assume_init_drop(&mut self); pub unsafe fn assume_init_ref(&self) -> &T; pub unsafe fn assume_init_mut(&mut self) -> &mut T; } ``` Adding these APIs: ```rust impl<T> [MaybeUninit<T>] { // replacing copy_from_slice; renamed to avoid conflict pub fn write_copy_of_slice(&mut self, value: &[T]) -> &mut [T] where T: Copy; // replacing clone_from_slice; renamed to avoid conflict pub fn write_clone_of_slice(&mut self, value: &[T]) -> &mut [T] where T: Clone; // identical to non-slice versions; no conflict pub fn as_bytes(&self) -> &[MaybeUninit<u8>]; pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]; pub unsafe fn assume_init_drop(&mut self); pub unsafe fn assume_init_ref(&self) -> &[T]; pub unsafe fn assume_init_mut(&mut self) -> &mut [T]; } ``` Since the `assume_init` methods are identical to those on non-slices, they feel pretty natural. The main issue with the write methods is naming, as discussed in #79995 among other places. My rationale: * The term "write" should be in them somewhere, to mirror the other API, and this pretty much automatically makes them not collide with any other inherent slice methods. * I chose `write_clone_of_slice` and `write_copy_of_slice` since `clone` and `copy` are being used as objects here, whereas they're being used as actions in `clone_from_slice` and `copy_from_slice`. The final "weird" thing I've done in this PR is remove a link to `Vec<T>` from `assume_init_drop` (both copies, since they're effectively copied docs), since there's no good way to link to `Vec` for something that can occur both on the page for `std/primitive.slice.html` and `std/vec/struct.Vec.html`, since the code here lives in libcore and can't use intra-doc-linking to mention `Vec`. (see: #121436) The reason why this method shows up both on `Vec<T>` and `[T]` is because the `[T]` docs are automatically inlined on `Vec<T>`'s page, since it implements `Deref`. It's unfortunate that rustdoc doesn't have a way of dealing with this at the moment, but it is what it is, and it's a reasonable compromise for now.
2025-01-12Auto merge of #135396 - matthiaskrgr:rollup-zublg1c, r=matthiaskrgrbors-14/+11
Rollup of 5 pull requests Successful merges: - #135266 (Remove emsdk version update from 1.84.0 relnotes) - #135364 (Cleanup `suggest_binding_for_closure_capture_self` diag in borrowck) - #135375 (allow rustdoc-js tests to be run at stage0) - #135379 (Make (unstable API) `UniqueRc` invariant for soundness) - #135389 (compiletest: include stage0-sysroot libstd dylib in recipe dylib search path) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-12Rollup merge of #135364 - yotamofek:borrowck-diag-fix, r=compiler-errorsMatthias Krüger-14/+11
Cleanup `suggest_binding_for_closure_capture_self` diag in borrowck Mostly grammar fix/improvement, but also a small cleanup to use iterators instead of for loops for collecting into a vector.
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-1/+1
2025-01-11Address PR feedbackScott McMurray-9/+11
2025-01-11[mir-opt] simplify `Repeat`s that don't actually repeat the operandScott McMurray-11/+30
2025-01-11Make MIR cleanup for functions with impossible predicates into a real MIR passMichael Goulet-46/+59
2025-01-11Remove a bunch of diagnostic stashing that doesn't do anythingMichael Goulet-63/+14
2025-01-11Suggest typos when trait path expression is typodMichael Goulet-2/+49
2025-01-11Remove allocations from case-insensitive comparison to keywordsMark Rousskov-3/+5
2025-01-11Rollup merge of #135314 - compiler-errors:eagerly-mono-closures, r=wesleywiserMatthias Krüger-0/+44
Eagerly collect mono items for non-generic closures This allows users to use `-Zprint-mono-items=eager` to eagerly monomorphize closures and coroutine bodies, in case they want to inspect the LLVM or ASM for those items. `-Zprint-mono-items`, which used to be called `-Zprint-trans-items`, was originally added in https://github.com/rust-lang/rust/pull/30900: > Eager mode is meant to be used in conjunction with incremental compilation > where a stable set of translation items is more important than a minimal > one. Thus, eager mode will instantiate drop-glue for every drop-able type > in the crate, even of no drop call for that type exists (yet). It will > also instantiate default implementations of trait methods, something that > otherwise is only done on demand. Although it remains an unstable option, its purpose has somewhat expanded since then, and as far as I can tell it's generally useful for cases when you want to monomorphize as many items as possible, even if they're unreachable. Specifically, it's useful for debugging since you can look at the codegen'd body of a function, since we don't emit items that are not reachable in monomorphization. And even more specifically, it would be very to monomorphize the coroutine body of an async fn, since those you can't easily call those without a runtime. This PR enables this usecase since we now monomorphize `DefKind::Closure`.
2025-01-11Rollup merge of #135205 - lqd:bitsets, r=Mark-SimulacrumMatthias Krüger-362/+379
Rename `BitSet` to `DenseBitSet` r? `@Mark-Simulacrum` as you requested this in https://github.com/rust-lang/rust/pull/134438#discussion_r1890659739 after such a confusion. This PR renames `BitSet` to `DenseBitSet` to make it less obvious as the go-to solution for bitmap needs, as well as make its representation (and positives/negatives) clearer. It also expands the comments there to hopefully make it clearer when it's not a good fit, with some alternative bitsets types. (This migrates the subtrees cg_gcc and clippy to use the new name in separate commits, for easier review by their respective owners, but they can obvs be squashed)
2025-01-11Rollup merge of #134776 - estebank:vanilla-ice, r=lcnrMatthias Krüger-51/+76
Avoid ICE: Account for `for<'a>` types when checking for non-structural type in constant as pattern When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways. Slight tweak to output to remove unnecessary context as a drive-by. Fix #134764.
2025-01-11Rollup merge of #134030 - folkertdev:min-fn-align, r=workingjubileeMatthias Krüger-3/+34
add `-Zmin-function-alignment` tracking issue: https://github.com/rust-lang/rust/issues/82232 This PR adds the `-Zmin-function-alignment=<align>` flag, that specifies a minimum alignment for all* functions. ### Motivation This feature is requested by RfL [here](https://github.com/rust-lang/rust/issues/128830): > i.e. the equivalents of `-fmin-function-alignment` ([GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fmin-function-alignment_003dn), Clang does not support it) / `-falign-functions` ([GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-falign-functions), [Clang](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang1-falign-functions)). > > For the Linux kernel, the behavior wanted is that of GCC's `-fmin-function-alignment` and Clang's `-falign-functions`, i.e. align all functions, including cold functions. > > There is [`feature(fn_align)`](https://github.com/rust-lang/rust/issues/82232), but we need to do it globally. ### Behavior The `fn_align` feature does not have an RFC. It was decided at the time that it would not be necessary, but maybe we feel differently about that now? In any case, here are the semantics of this flag: - `-Zmin-function-alignment=<align>` specifies the minimum alignment of all* functions - the `#[repr(align(<align>))]` attribute can be used to override the function alignment on a per-function basis: when `-Zmin-function-alignment` is specified, the attribute's value is only used when it is higher than the value passed to `-Zmin-function-alignment`. - the target may decide to use a higher value (e.g. on x86_64 the minimum that LLVM generates is 16) - The highest supported alignment in rust is `2^29`: I checked a bunch of targets, and they all emit the `.p2align 29` directive for targets that align functions at all (some GPU stuff does not have function alignment). *: Only with `build-std` would the minimum alignment also be applied to `std` functions. --- cc `@ojeda` r? `@workingjubilee` you were active on the tracking issue
2025-01-11collect diag suggestions instead of pushing into vector repeatedlyYotam Ofek-12/+9
2025-01-11improve clunky grammar in borrowck diagnosticYotam Ofek-1/+1
2025-01-11fix `it's` -> `its` in doc commentYotam Ofek-1/+1
2025-01-11migrate `rustc_codegen_gcc` to the `DenseBitSet` nameRémy Rakic-5/+5
2025-01-11document the use-cases of `DenseBitSet` a bit moreRémy Rakic-1/+7
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-356/+367
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2025-01-11Auto merge of #135274 - saethlin:array-repeats, r=compiler-errorsbors-0/+30
Add an InstSimplify for repetitive array expressions I noticed in https://github.com/rust-lang/rust/pull/135068#issuecomment-2569955426 that GVN's implementation of this same transform was quite profitable on the deep-vector benchmark. But of course GVN doesn't run in unoptimized builds, so this is my attempt to write a version of this transform that benefits the deep-vector case and is fast enough to run in InstSimplify. The benchmark suite indicates that this is effective.
2025-01-11Auto merge of #135258 - oli-obk:push-ktzskvxuwnlt, r=saethlinbors-7/+21
Use llvm.memset.p0i8.* to initialize all same-bytes arrays Similar to #43488 debug builds can now handle `0x0101_u16` and other multi-byte scalars that have all the same bytes (instead of special casing just `0`)
2025-01-11review comments and make test `run-rustfix`Esteban Küber-74/+64
2025-01-11On unused assign lint, detect `mut arg: &Ty` meant to be `arg: &mut Ty`Esteban Küber-5/+98
``` error: value assigned to `object` is never read --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:11:5 | LL | object = &object2; | ^^^^^^ | note: the lint level is defined here --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:1:9 | LL | #![deny(unused_assignments, unused_variables)] | ^^^^^^^^^^^^^^^^^^ help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding | LL ~ fn change_object2(object: &mut Object) { LL | let object2 = Object; LL ~ *object = object2; | ``` This might be the first thing someone tries to write to mutate the value *behind* an argument, trying to avoid an E0308.
2025-01-11On E0308, detect `mut arg: &Ty` meant to be `arg: &mut Ty`Esteban Küber-0/+105
``` error[E0308]: mismatched types --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:6:14 | LL | fn change_object(mut object: &Object) { | ------- expected due to this parameter type LL | let object2 = Object; LL | object = object2; | ^^^^^^^ expected `&Object`, found `Object` | help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding | LL ~ fn change_object(object: &mut Object) { LL | let object2 = Object; LL ~ *object = object2; | ``` This might be the first thing someone tries to write to mutate the value *behind* an argument. We avoid suggesting `object = &object2;`, as that is less likely to be what was intended.
2025-01-11review commentsEsteban Küber-57/+67
Replace tuple with struct and remove unnecessary early return.