Commit Graph

265713 Commits

Author SHA1 Message Date
Chris Denton
7223fd8085
Add system libs when cross compiling for Windows 2024-09-15 12:38:55 +00:00
bors
1ae268816c Auto merge of #130148 - RalfJung:interpret-get_ptr_alloc_mut, r=saethlin
interpret: get_ptr_alloc_mut: lookup allocation only once

I don't think this will make a big perf difference, but it makes this function symmetric with `get_ptr_alloc` -- and it's always nice to successfully solve a borrow checker puzzle like this. ;)
2024-09-15 08:59:26 +00:00
Ralf Jung
f16f09db63 interpret: get_ptr_alloc_mut: lookup allocation only once 2024-09-15 10:21:19 +02:00
bors
bc486f31a6 Auto merge of #130379 - Zalathar:rollup-wpmcnql, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - #130042 (properly handle EOF in BufReader::peek)
 - #130061 (Add `NonNull` convenience methods to `Box` and `Vec`)
 - #130202 (set `download-ci-llvm = true` by default on "library" and "tools" profiles)
 - #130214 (MaybeUninit::zeroed: mention that padding is not zeroed)
 - #130353 (Make some lint doctests compatible with `--stage=0`)
 - #130370 (unstable-book: `trait_upcasting` example should not have `#![allow(incomplete_features)]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-15 05:15:25 +00:00
Stuart Cook
4b6f838e56
Rollup merge of #130370 - kpreid:patch-2, r=compiler-errors
unstable-book: `trait_upcasting` example should not have `#![allow(incomplete_features)]`

Tracking issue: #65991

`trait_upcasting` is not currently an incomplete feature; therefore examples of its use do not require `#![allow(incomplete_features)]`.
2024-09-15 12:14:58 +10:00
Stuart Cook
12fb8e45c2
Rollup merge of #130353 - Zalathar:lint-zero, r=jieyouxu
Make some lint doctests compatible with `--stage=0`

Currently, running `x test compiler --stage=0` (with `rust.parallel-compiler=false` to avoid other problems) results in two failures, because these lint doctests aren't compatible with the current stage0 compiler.

In theory, the more “correct” solution would be to wrap the opening triple-backtick line in  `#[cfg_attr(not(bootstrap), doc = "..."]`. However, that causes a few practical problems:
- `tidy` doesn't understand that syntax, and miscounts the number of backticks in the comment block.
- `lint-docs` doesn't understand that syntax, and thinks it's trying to declare the lint name.
- Working around the above problems would cause more work and more confusion for whoever does the next bootstrap beta bump.

So instead this PR adds some bootstrap gates inside the individual doctests, which end up producing the desired behaviour, and are straightforward to remove.
2024-09-15 12:14:57 +10:00
Stuart Cook
0648987532
Rollup merge of #130214 - RalfJung:zeroed, r=Mark-Simulacrum
MaybeUninit::zeroed: mention that padding is not zeroed

That should clarify cases like [this](https://github.com/rust-lang/rust/pull/129778#issuecomment-2342542847).
2024-09-15 12:14:56 +10:00
Stuart Cook
36ee8520e8
Rollup merge of #130202 - onur-ozkan:force-ci-llvm-on-default-profiles, r=Mark-Simulacrum
set `download-ci-llvm = true` by default on "library" and "tools" profiles

It's very rare for developers to need to modify LLVM, so "if-unchanged" isn't a good default for "tools" and "library" profiles since it fetches the LLVM submodule to track changes.
2024-09-15 12:14:56 +10:00
Stuart Cook
c11505f218
Rollup merge of #130061 - theemathas:box_vec_non_null, r=MarkSimulacrum,workingjubilee
Add `NonNull` convenience methods to `Box` and `Vec`

Implements the ACP: https://github.com/rust-lang/libs-team/issues/418.

The docs for the added methods are mostly copied from the existing methods that use raw pointers instead of `NonNull`.

I'm new to this "contributing to rustc" thing, so I'm sorry if I did something wrong. In particular, I don't know what the process is for creating a new unstable feature. Please advise me if I should do something. Thank you.
2024-09-15 12:14:55 +10:00
Stuart Cook
e02e6bf0e9
Rollup merge of #130042 - lolbinarycat:bufreaker_peek_eof, r=Amanieu
properly handle EOF in BufReader::peek

previously this would cause an infinite loop due to it being unable to read `n` bytes.
2024-09-15 12:14:55 +10:00
bors
4f1be92153 Auto merge of #129753 - folkertdev:stabilize-const-extern-fn, r=RalfJung
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-14 23:47:59 +00:00
Kevin Reid
29ccc0d325
trait_upcasting is not currently an incomplete feature. 2024-09-14 14:46:29 -07:00
bors
9b72238eb8 Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-dead
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-14 21:11:04 +00:00
bors
5e3ede22ef Auto merge of #129974 - cuviper:ci-llvm-19, r=Mark-Simulacrum
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-14 18:44:23 +00:00
Tim (Theemathas) Chirananthavat
811ee38ff0 Add tracking issue number for box_vec_non_null 2024-09-15 01:11:18 +07:00
bors
5fe0e40e05 Auto merge of #130357 - fmease:rollup-j3ej4q0, r=fmease
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-14 16:18:12 +00:00
León Orell Valerian Liehr
2b40fdbb28
Rollup merge of #130349 - ShE3py:break_up_float, r=fmease
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-14 18:12:14 +02:00
León Orell Valerian Liehr
d1701a5334
Rollup merge of #130343 - Fayti1703:patch-correct-async-block-lint-doc, 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-14 18:12:13 +02:00
León Orell Valerian Liehr
03e8b6bbfa
Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnr
Lifetime cleanups

The last commit is very opinionated, let's see how we go.

r? `@oli-obk`
2024-09-14 18:12:13 +02:00
León Orell Valerian Liehr
f873367243
Rollup merge of #130290 - passcod:stabilise-entry-insert, r=ChrisDenton
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-14 18:12:12 +02:00
León Orell Valerian Liehr
a9dcd7f25d
Rollup merge of #130268 - RalfJung:simd-shuffle-idx-vector, r=compiler-errors
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-14 18:12:10 +02:00
León Orell Valerian Liehr
2b12b574ef
Rollup merge of #130017 - Zalathar:executor, r=Mark-Simulacrum
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-14 18:12:10 +02:00
Folkert de Vries
a528f4ecd9 stabilize const_extern_fn 2024-09-14 18:07:06 +02:00
bors
e7386b361d Auto merge of #128299 - DianQK:clone-copy, r=cjgillot
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-14 13:30:30 +00:00
Zalathar
14ed979cdf Make some lint doctests compatible with --stage=0 2024-09-14 23:18:49 +10:00
Ralf Jung
60ee1b7ac6 simd_shuffle: require index argument to be a vector 2024-09-14 14:43:24 +02:00
Lieselotte
4cb5849f01
Refactor Parser::break_up_float 2024-09-14 13:17:16 +02:00
bors
02b1be16c6 Auto merge of #130348 - Zalathar:rollup-5d0b7a9, r=Zalathar
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-14 11:01:13 +00:00
Lieselotte
3d20c810b0
Fix Parser::break_up_float's right span 2024-09-14 12:41:25 +02:00
Stuart Cook
73f684f3c5
Rollup merge of #130334 - madsmtm:macos-sdkroot-ignore, r=jieyouxu
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-14 20:22:41 +10:00
Stuart Cook
517e7ce37f
Rollup merge of #130311 - heiseish:issue-70849-fix, r=fmease
(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-14 20:22:41 +10:00
Stuart Cook
e2f17e66ed
Rollup merge of #130267 - TimNN:patch-2, r=nikic
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-14 20:22:40 +10:00
Stuart Cook
c992f97cb1
Rollup merge of #130053 - glowcoil:next_if-docs, r=jhpratt
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-14 20:22:40 +10:00
Lieselotte
003da02352
Add ErrorGuaranteed to DestructuredFloat::Error 2024-09-14 12:16:23 +02:00
Fayti1703
14285e9804
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.
2024-09-14 10:43:26 +02:00
bors
f9567d0f2b Auto merge of #128991 - Nadrieril:rustfix-unreachable-pattern, r=compiler-errors
Add a machine-applicable suggestion to "unreachable pattern"
2024-09-14 07:04:57 +00:00
DianQK
25d434b254
Update try_question_mark_nop.rs test 2024-09-14 13:30:36 +08:00
DianQK
c16c22cc9c
Simplify the canonical clone method to copy
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-14 13:30:35 +08:00
bors
4a47e8e449 Auto merge of #130332 - Zalathar:rollup-eq0qvvy, r=Zalathar
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-14 04:37:41 +00:00
Mads Marquart
56844c797a Fix SDKROOT ignore on macOS 2024-09-14 04:28:38 +02:00
Stuart Cook
89dd3f91a8
Rollup merge of #130317 - compiler-errors:no-ord, r=jackh726
`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-14 11:53:13 +10:00
Stuart Cook
59698a711f
Rollup merge of #130306 - onur-ozkan:avoid-submodule-updates-in-tests, r=Kobzol
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-14 11:53:13 +10:00
Stuart Cook
97475df89d
Rollup merge of #130302 - onur-ozkan:130040-with-fixes, r=Kobzol
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-14 11:53:12 +10:00
Stuart Cook
04e744e77d
Rollup merge of #130199 - compiler-errors:by-move, r=cjgillot
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-14 11:53:12 +10:00
Stuart Cook
2bf0dd2735
Rollup merge of #130138 - Zalathar:initial-libdir, r=albertlarsan68
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 11:53:11 +10:00
Giang Dao
b0db3a7bed (fix) conflicting negative impl marker and add tests 2024-09-14 09:25:06 +08:00
bors
23b04c0513 Auto merge of #125419 - GuillaumeGomez:add-gcc-to-dist, r=Kobzol
[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-14 00:26:04 +00:00
bors
507c05bead Auto merge of #130121 - lolbinarycat:bootstrap-warn-old-upstream-worktree, r=albertlarsan68
bootstrap: handle worktrees in warn_old_master_branch

fixes #130111
2024-09-13 22:02:35 +00:00
bors
0609062a91 Auto merge of #130312 - matthiaskrgr:rollup-ihwsc91, r=matthiaskrgr
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-13 19:21:37 +00:00
Nadrieril
1f69638400 Add a machine-applicable suggestion to "unreachable pattern" 2024-09-13 21:01:29 +02:00