about summary refs log tree commit diff
AgeCommit message (Collapse)AuthorLines
2024-09-14compiler: Document AbiAndPrefAlignJubilee Young-0/+8
2024-09-14Auto merge of #129753 - folkertdev:stabilize-const-extern-fn, r=RalfJungbors-235/+186
stabilize `const_extern_fn` closes https://github.com/rust-lang/rust/issues/64926 tracking issue: https://github.com/rust-lang/rust/issues/64926 reference PR: https://github.com/rust-lang/reference/pull/1596 ## Stabilizaton Report ### Summary Using `const extern "Rust"` and `const extern "C"` was already stabilized (since version 1.62.0, see https://github.com/rust-lang/rust/pull/95346). This PR stabilizes the other calling conventions: it is now possible to write `const unsafe extern "calling-convention" fn` and `const extern "calling-convention" fn` for any supported calling convention: ```rust const extern "C-unwind" fn foo1(val: u8) -> u8 { val + 1} const extern "stdcall" fn foo2(val: u8) -> u8 { val + 1} const unsafe extern "C-unwind" fn bar1(val: bool) -> bool { !val } const unsafe extern "stdcall" fn bar2(val: bool) -> bool { !val } ``` This can be used to const-ify an `extern fn`, or conversely, to make a `const fn` callable from external code. r? T-lang cc `@RalfJung`
2024-09-14Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-deadbors-578/+225
const-eval interning: accept interior mutable pointers in final value …but keep rejecting mutable references This fixes https://github.com/rust-lang/rust/issues/121610 by no longer firing the lint when there is a pointer with interior mutability in the final value of the constant. On stable, such pointers can be created with code like: ```rust pub enum JsValue { Undefined, Object(Cell<bool>), } impl Drop for JsValue { fn drop(&mut self) {} } // This does *not* get promoted since `JsValue` has a destructor. // However, the outer scope rule applies, still giving this 'static lifetime. const UNDEFINED: &JsValue = &JsValue::Undefined; ``` It's not great to accept such values since people *might* think that it is legal to mutate them with unsafe code. (This is related to how "infectious" `UnsafeCell` is, which is a [wide open question](https://github.com/rust-lang/unsafe-code-guidelines/issues/236).) However, we [explicitly document](https://doc.rust-lang.org/reference/behavior-considered-undefined.html) that things created by `const` are immutable. Furthermore, we also accept the following even more questionable code without any lint today: ```rust let x: &'static Option<Cell<i32>> = &None; ``` This is even more questionable since it does *not* involve a `const`, and yet still puts the data into immutable memory. We could view this as promotion [potentially introducing UB](https://github.com/rust-lang/unsafe-code-guidelines/issues/493). However, we've accepted this since ~forever and it's [too late to reject this now](https://github.com/rust-lang/rust/pull/122789); the pattern is just too useful. So basically, if you think that `UnsafeCell` should be tracked fully precisely, then you should want the lint we currently emit to be removed, which this PR does. If you think `UnsafeCell` should "infect" surrounding `enum`s, the big problem is really https://github.com/rust-lang/unsafe-code-guidelines/issues/493 which does not trigger the lint -- the cases the lint triggers on are actually the "harmless" ones as there is an explicit surrounding `const` explaining why things end up being immutable. What all this goes to show is that the hard error added in https://github.com/rust-lang/rust/pull/118324 (later turned into the future-compat lint that I am now suggesting we remove) was based on some wrong assumptions, at least insofar as it concerns shared references. Furthermore, that lint does not help at all for the most problematic case here where the potential UB is completely implicit. (In fact, the lint is actively in the way of [my preferred long-term strategy](https://github.com/rust-lang/unsafe-code-guidelines/issues/493#issuecomment-2028674105) for dealing with this UB.) So I think we should go back to square one and remove that error/lint for shared references. For mutable references, it does seem to work as intended, so we can keep it. Here it serves as a safety net in case the static checks that try to contain mutable references to the inside of a const initializer are not working as intended; I therefore made the check ICE to encourage users to tell us if that safety net is triggered. Closes https://github.com/rust-lang/rust/issues/122153 by removing the lint. Cc `@rust-lang/opsem` `@rust-lang/lang`
2024-09-14Auto merge of #129974 - cuviper:ci-llvm-19, r=Mark-Simulacrumbors-0/+67
ci: add a runner for vanilla LLVM 19 Ubuntu 24.10 has `llvm-19` packages that we can start testing with. The `Dockerfile` is otherwise the same as the `llvm-18` runner.
2024-09-14Auto merge of #130357 - fmease:rollup-j3ej4q0, r=fmeasebors-874/+645
Rollup of 6 pull requests Successful merges: - #130017 (coverage: Extract `executor::block_on` from several async coverage tests) - #130268 (simd_shuffle: require index argument to be a vector) - #130290 (Stabilize entry_insert) - #130294 (Lifetime cleanups) - #130343 (docs: Enable required feature for 'closure_returning_async_block' lint) - #130349 (Fix `Parser::break_up_float`'s right span) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-14Rollup merge of #130349 - ShE3py:break_up_float, r=fmeaseLeón Orell Valerian Liehr-58/+56
Fix `Parser::break_up_float`'s right span ```rs use std::mem::offset_of; fn main() { offset_of!((u8,), 0.0); } ``` Before: ``` error[E0609]: no field `0` on type `u8` --> ./main.rs:4:25 | 4 | offset_of!((u8,), 0.0); | _____--------------------^- | | | | | in this macro invocation 5 | | } ... | | = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error ``` After: ``` error[E0609]: no field `0` on type `u8` --> ./main.rs:4:25 | 4 | offset_of!((u8,), 0.0); | ^ error: aborting due to 1 previous error ``` --- `@rustbot` label +A-parser +D-imprecise-spans
2024-09-14Rollup merge of #130343 - Fayti1703:patch-correct-async-block-lint-doc, ↵León Orell Valerian Liehr-0/+1
r=compiler-errors docs: Enable required feature for 'closure_returning_async_block' lint Failing to do this results in the lint example output complaining about the lint not existing instead of the thing the lint is supposed to be complaining about. See <https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#closure-returning-async-block>: ![image](https://github.com/user-attachments/assets/78bae16f-3fb6-4d6d-b8aa-768b477cd187)
2024-09-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-231/+224
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
2024-09-14Rollup merge of #130290 - passcod:stabilise-entry-insert, r=ChrisDentonLeón Orell Valerian Liehr-4/+2
Stabilize entry_insert This stabilises `HashMap::Entry::insert_entry`, following the FCP in tracking issue #65225. This was implemented in #64656 five years ago.
2024-09-14Rollup merge of #130268 - RalfJung:simd-shuffle-idx-vector, r=compiler-errorsLeón Orell Valerian Liehr-304/+220
simd_shuffle: require index argument to be a vector Remove some codegen hacks by forcing the SIMD shuffle `index` argument to be a vector, which means (thanks to https://github.com/rust-lang/rust/pull/128537) that it will automatically be passed as an immediate in LLVM. The only special-casing we still have is for the extra sanity-checks we add that ensure that the indices are all in-bounds. (And the GCC backend needs to do a bunch of work since the Rust intrinsic is modeled after what LLVM expects, which seems to be quite different from what GCC expects.) Fixes https://github.com/rust-lang/rust/issues/128738, see that issue for more context.
2024-09-14Rollup merge of #130017 - Zalathar:executor, r=Mark-SimulacrumLeón Orell Valerian Liehr-277/+142
coverage: Extract `executor::block_on` from several async coverage tests By moving `block_on` to an auxiliary crate, we avoid having to keep a separate copy of it in every async test.
2024-09-14stabilize `const_extern_fn`Folkert de Vries-235/+186
2024-09-14Auto merge of #128299 - DianQK:clone-copy, r=cjgillotbors-53/+1648
Simplify the canonical clone method and the copy-like forms to copy Fixes #128081. The optimized clone method ends up as the following MIR: ``` _2 = copy ((*_1).0: i32); _3 = copy ((*_1).1: u64); _4 = copy ((*_1).2: [i8; 3]); _0 = Foo { a: move _2, b: move _3, c: move _4 }; ``` We can transform this to: ``` _0 = copy (*_1); ``` r? `@cjgillot`
2024-09-14simd_shuffle: require index argument to be a vectorRalf Jung-304/+220
2024-09-14Refactor `Parser::break_up_float`Lieselotte-27/+25
2024-09-14Auto merge of #130348 - Zalathar:rollup-5d0b7a9, r=Zalatharbors-6/+41
Rollup of 4 pull requests Successful merges: - #130053 (fix doc comments for Peekable::next_if(_eq)) - #130267 (small_data_threshold.rs: Adapt to LLVM head changes) - #130311 ((fix) conflicting negative impl marker) - #130334 (Fix `SDKROOT` ignore on macOS) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-14Fix `Parser::break_up_float`'s right spanLieselotte-25/+25
2024-09-14Rollup merge of #130334 - madsmtm:macos-sdkroot-ignore, r=jieyouxuStuart Cook-1/+1
Fix `SDKROOT` ignore on macOS `rustc` has code to detect when `SDKROOT` is obviously set for the wrong platform, so that it can choose to ignore it. This is a pretty important feature for Cargo build scripts and proc macros, since you will often have `SDKROOT` set to an iOS platform there. However, the code was checking for an old SDK version name `"macosx10.15"` that was previously configured by `add_apple_sdk`, but nowadays configured to the correct `"macosx"`. I think this error was introduced in part https://github.com/rust-lang/rust/pull/77202 and in https://github.com/rust-lang/rust/pull/100286. Fixes part of https://github.com/rust-lang/rust/issues/80817 (linking with `-Clinker=ld` now works), though more work is still needed in this area, see also https://github.com/rust-lang/rust/issues/129432. ``@rustbot`` label O-macos A-cross
2024-09-14Rollup merge of #130311 - heiseish:issue-70849-fix, r=fmeaseStuart Cook-1/+36
(fix) conflicting negative impl marker ## Context This MR fixes the error message for conflicting negative trait impls by adding the corresponding the polarity marker to the trait name. ## Issues - closes #70849 r​? `@fmease`
2024-09-14Rollup merge of #130267 - TimNN:patch-2, r=nikicStuart Cook-2/+2
small_data_threshold.rs: Adapt to LLVM head changes When compiled against LLVM head, `small_data_threshold.rs` [fails with](https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/31051#0191e508-f11d-437b-a4a0-5e18247debc9): ``` /.../small_data_threshold.rs:61:12: error: RISCV: expected string not found in input --   | //@ RISCV: .section .sdata,   | ^   | /.../small_data_threshold.s:1:1: note: scanning from here   | .text   | ^   | /.../small_data_threshold.s:6:2: note: possible intended match here   | .section .sdata.U,"aw",`@progbits`   | ^ ``` I don't know how exactly the current output looks like, or if there was a specific reason for including the trailing comma on the first line. I only saw a failure for RISCV, but it seemed sensible to adjust MIPS as well. CI passes with this patch applied: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/31053 `@rustbot` label: +llvm-main cc `@paulmenage`
2024-09-14Rollup merge of #130053 - glowcoil:next_if-docs, r=jhprattStuart Cook-2/+2
fix doc comments for Peekable::next_if(_eq) Fix references to a nonexistent `consume` function in the doc comments for `Peekable::next_if` and `Peekable::next_if_eq`.
2024-09-14Add `ErrorGuaranteed` to `DestructuredFloat::Error`Lieselotte-7/+7
2024-09-14docs: Enable required feature for 'closure_returning_async_block' lintFayti1703-0/+1
Failing to do this results in the lint example output complaining about the lint not existing instead of the thing the lint is supposed to be complaining about.
2024-09-14Auto merge of #128991 - Nadrieril:rustfix-unreachable-pattern, r=compiler-errorsbors-98/+502
Add a machine-applicable suggestion to "unreachable pattern"
2024-09-14Update try_question_mark_nop.rs testDianQK-1/+6
2024-09-14Simplify the canonical clone method to copyDianQK-52/+1642
The optimized clone method ends up as the following MIR: ``` _2 = copy ((*_1).0: i32); _3 = copy ((*_1).1: u64); _4 = copy ((*_1).2: [i8; 3]); _0 = Foo { a: move _2, b: move _3, c: move _4 }; ``` We can transform this to: ``` _0 = copy (*_1); ```
2024-09-14Auto merge of #130332 - Zalathar:rollup-eq0qvvy, r=Zalatharbors-54/+84
Rollup of 5 pull requests Successful merges: - #130138 (bootstrap: Print more debug info when `find_initial_libdir` fails) - #130199 (Don't call closure_by_move_body_def_id on FnOnce async closures in MIR validation) - #130302 (add llvm-bitcode-linker and llvm-tools bins to ci-rustc's sysroot) - #130306 (avoid updating LLVM submodule during bootstrap unit tests) - #130317 (`ProjectionElem` and `UnOp`/`BinOp` dont need to be `PartialOrd`/`Ord`) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-14Fix SDKROOT ignore on macOSMads Marquart-1/+1
2024-09-14Rollup merge of #130317 - compiler-errors:no-ord, r=jackh726Stuart Cook-3/+3
`ProjectionElem` and `UnOp`/`BinOp` dont need to be `PartialOrd`/`Ord` These types don't really admit a natural ordering and no code seems to rely on it, so let's remove it.
2024-09-14Rollup merge of #130306 - onur-ozkan:avoid-submodule-updates-in-tests, r=KobzolStuart Cook-0/+2
avoid updating LLVM submodule during bootstrap unit tests To test this, make sure you don't have `src/llvm-project` fetched and then set `llvm.download-ci-llvm=true` and run `x test bootstrap`.
2024-09-14Rollup merge of #130302 - onur-ozkan:130040-with-fixes, r=KobzolStuart Cook-39/+47
add llvm-bitcode-linker and llvm-tools bins to ci-rustc's sysroot https://github.com/rust-lang/rust/pull/130040 is [reverted](https://github.com/rust-lang/rust/pull/130292) because adding component binaries directly to the dist tarball of the compiler caused conflicts (see https://github.com/rust-lang/rust/issues/130291 and https://github.com/rust-lang/rustup/issues/4019). This PR solves the original problem without touching the dist tarball. r? Kobzol
2024-09-14Rollup merge of #130199 - compiler-errors:by-move, r=cjgillotStuart Cook-8/+24
Don't call closure_by_move_body_def_id on FnOnce async closures in MIR validation Refactors the check in #129847 to not unncessarily call the `closure_by_move_body_def_id` query for async closures that don't *need* a by-move body. Fixes #130167
2024-09-14Rollup merge of #130138 - Zalathar:initial-libdir, r=albertlarsan68Stuart Cook-4/+8
bootstrap: Print more debug info when `find_initial_libdir` fails From looking at the failure messages printed by #129775, my hypothesis is that `rustc --print=sysroot` sometimes prints the wrong path when the rustc executable is hardlinked in multiple places, at least on my macOS system. However, currently I don't have any concrete evidence of this actually happening. This PR therefore expands on #129775 by printing even more information on failure (including the actual rustc path), in the hope that when the failure next occurs we can confirm or reject the hypothesis that `rustc --print=sysroot` is printing the wrong path.
2024-09-14(fix) conflicting negative impl marker and add testsGiang Dao-1/+36
2024-09-14Auto merge of #125419 - GuillaumeGomez:add-gcc-to-dist, r=Kobzolbors-42/+603
[bootstrap] Add support for building gcc and libgccjit As `@eholk` summarized below: > From my understanding, this change would add libgccjit as an optional component to the Rust distribution. This library is licensed under GPLv2 and currently we do not have any other components under that license so it would be a new license, and one that is generally more restrictive than the other licenses we use. It'll greatly improve the experience for anyone wanting to work on the GCC backend from the compiler. Should help with https://github.com/rust-lang/rust/issues/124172. Will unblock #124353. r? `@Kobzol`
2024-09-13Auto merge of #130121 - lolbinarycat:bootstrap-warn-old-upstream-worktree, ↵bors-25/+47
r=albertlarsan68 bootstrap: handle worktrees in warn_old_master_branch fixes #130111
2024-09-13Auto merge of #130312 - matthiaskrgr:rollup-ihwsc91, r=matthiaskrgrbors-467/+609
Rollup of 6 pull requests Successful merges: - #129320 (Fix crash when labeling arguments for call_once and friends) - #130266 (target: default to the medium code model on LoongArch targets) - #130297 (Dataflow cleanups) - #130299 (Add set_dcx to ParseSess) - #130301 (some fixes for clashing_extern_declarations lint) - #130305 (Clippy: consider msrv for const context for const_float_bits_conv) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-13Add a machine-applicable suggestion to "unreachable pattern"Nadrieril-98/+502
2024-09-13ProjectionElem and UnOp/BinOp dont need to be PartialOrd/OrdMichael Goulet-3/+3
2024-09-13Rollup merge of #130305 - tspiteri:clippy-msrv-for-const_float_bits_conv, ↵Matthias Krüger-6/+21
r=flip1995 Clippy: consider msrv for const context for const_float_bits_conv When `const_float_bits_conv` was stabilized for 1.83.0, clippy lints started to be triggered in const context ignoring MSRV. This PR makes the lints trigger in const context only when the MSRV meets 1.83.0. Fixes https://github.com/rust-lang/rust-clippy/issues/13383.
2024-09-13Rollup merge of #130301 - RalfJung:clashing_extern_declarations, ↵Matthias Krüger-89/+172
r=compiler-errors some fixes for clashing_extern_declarations lint There were two issues with the clashing_extern_declarations lint: - It would accept non-`repr(C)` structs as compatible with each other by comparing their fields in declaration order, but the fields could have different memory order (and with `-Zrandomize-layout`, this can really happen). - It would accept two types as compatible if `compare_layouts` returns `true`, but that function actually just compared the *ABI*, not the fully layout -- and all sized structs with more than 2 fields have the same ABI (`Abi::Aggregate`), so this missed a *lot* of cases. We don't currently have a clear spec for what we *want* to consider "clashing" and what is fine, so I otherwise kept the original logic. I hope to have a t-lang discussion about this at some point. But meanwhile, these changes seem like clear bugfixes.
2024-09-13Rollup merge of #130299 - vetleras:add_set_dcx, r=compiler-errorsMatthias Krüger-0/+4
Add set_dcx to ParseSess After [this](https://github.com/rust-lang/rust/pull/126623) PR was merged, it is no longer possible to inject one's own `Emitter` in the way [described in the Compiler Development Guide](https://rustc-dev-guide.rust-lang.org/rustc-driver-getting-diagnostics.html). The reason is that the `dcx` field in `ParseSess` is no longer public, so it is not possible to update the `dcx` field with a `DiagCtxt` that contains one's own `Emitter` in the `psess_created` callback in `rustc_interface::Config`. The only way I have found to insert my own `DiagCtxt` is by creating an entirely new `ParseSess` and replacing the old one. This is not a good solution as the original `ParseSess` contains fields I would like to keep. (In my case the problem is that I lose the `cfg` and `check-cfg` fields of the original.) The solution proposed in this PR is to add a `set_dcx` method to `ParseSess`. Per my limited understanding of the rustc codebase this should be fine as `set_dcx` requires a mutable reference to `ParseSess`, which is as far as I know only available in the `psess_created` callback (outside of `rustc_interface::run_compiler`). If this PR is accepted, I will create a new PR to update the aforementioned example in the Compiler Development Guide.
2024-09-13Rollup merge of #130297 - nnethercote:dataflow-cleanups, r=cjgillotMatthias Krüger-167/+161
Dataflow cleanups r? `@cjgillot`
2024-09-13Rollup merge of #130266 - heiher:loong-medium-cmodel, r=compiler-errorsMatthias Krüger-4/+6
target: default to the medium code model on LoongArch targets The Rust LoongArch targets have been using the default LLVM code model so far, which is "small" in LLVM-speak and "normal" in LoongArch-speak. As described in the "Code Model" section of LoongArch ELF psABI spec v20231219 [1], one can only make function calls as far as ±128MiB with the "normal" code model; this is insufficient for very large software containing Rust components that needs to be linked into the big text section, such as Chromium. Because: * we do not want to ask users to recompile std if they are to build such software, * objects compiled with larger code models can be linked with those with smaller code models without problems, and * the "medium" code model is comparable to the "small"/"normal" one performance-wise (same data access pattern; each function call becomes 2-insn long and indirect, but this may be relaxed back into the direct 1-insn form in a future LLVM version), but is able to perform function calls within ±128GiB, it is better to just switch the targets to the "medium" code model, which is also "medium" in LLVM-speak. Relands [2]: #120661 [1]: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#code-models [2]: https://github.com/rust-lang/rust/issues/121289#issuecomment-2333687396
2024-09-13Rollup merge of #129320 - jder:issue-128848, r=compiler-errorsMatthias Krüger-201/+245
Fix crash when labeling arguments for call_once and friends When calling a method on Fn* traits explicitly, argument diagnostics should point at the called method (eg Fn::call_once), not the underlying callee. This PR makes 3 main changes: * It uses TupleArguments to detect if the user called a Fn* method directly (`my_fn.call_once(…)`) or implicitly (`my_fn(…)`). If it was explicit, argument diagnostics should point at the call_once method, not the underlying callable. * The previous state was causing confusion between the two arguments lists (which could be different lengths), causing an out-of-bounds slice indexing in #128848. I added a length assert to capture the requirement in case this regresses or happens in another case. * Unfortunately, this assert tripped when the required arguments information was not available (`self.get_hir_params_with_generics` was returning an empty Vec), so I've updated that to return None when that information is not available. (cc `@strottos` if you have any comments, since you added this function in #121595) Sorry this causes a bunch of indentation changes, recommend reviewing [ignoring whitespace](https://github.com/rust-lang/rust/pull/129320/files?w=1).) This is my first rustc PR, so please call out if you'd like this split into more commits (or PRs), style nits, etc. I will add a few comments/questions inline. Thank you! Fixes #128848
2024-09-13avoid updating LLVM submodule during bootstrap unit testsonur-ozkan-0/+2
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-13Remove gcc changes for dist buildGuillaume Gomez-12/+0
2024-09-13Auto merge of #130215 - RalfJung:interpret-simd, r=compiler-errorsbors-199/+190
interpret: simplify SIMD type handling This is possible as a follow-up to https://github.com/rust-lang/rust/pull/129403
2024-09-13When calling a method on Fn* traits explicitly, argument diagnostics shouldJesse Rusak-201/+245
point at the called method (eg Fn::call_once), not the underlying callee. Fixes 128848
2024-09-13interpret: simplify SIMD type handlingRalf Jung-199/+190