Commit Graph

17247 Commits

Author SHA1 Message Date
Guillaume Gomez
65b0dad824
Rollup merge of #133701 - kornelski:c-str, r=workingjubilee
Use c"lit" for CStrings without unwrap

I've reviewed uses of `CString::new("lit")`.

Some could be changed to `c"lit"`. Some could be changed to `c"lit".to_owned()`, avoiding an `unwrap()`.

Many `CString` documentation examples could be simplified. I deliberately haven't changed all the examples to use the exact same expression, so that they can demonstrate many ways of creating `CString`s.

I've left UI tests mostly unchanged, because `c""` requires edition 2021, but most UI tests use 2015, and I didn't want to accidentally change what the tests are testing.
2024-12-02 23:08:55 +01:00
Guillaume Gomez
e56e68541b
Rollup merge of #131713 - tgross35:stabilize-const_maybe_uninit_write, r=RalfJung,dtolnay
Stabilize `const_maybe_uninit_write`

Mark the following API const stable:

```rust
impl<T> MaybeUninit<T> {
    pub const fn write(&mut self, val: T) -> &mut T;
}
```

This depends on `const_mut_refs` and [`const_maybe_uninit_assume_init`](https://github.com/rust-lang/rust/issues/86722), both of which have recently been stabilized.

Closes: <https://github.com/rust-lang/rust/issues/63567>
2024-12-02 23:08:52 +01:00
Trevor Gross
c5fedc2267 Stabilize const_maybe_uninit_write
Mark the following API const stable:

    impl<T> MaybeUninit<T> {
        pub const fn write(&mut self, val: T) -> &mut T;
    }

This depends on `const_mut_refs` and `const_maybe_uninit_assume_init`,
both of which have recently been stabilized.

Tracking issue: <https://github.com/rust-lang/rust/issues/63567>
2024-12-02 14:06:56 -05:00
Kornel
eadea7764e
Use c"lit" for CStrings without unwrap 2024-12-02 18:16:36 +00:00
Guillaume Gomez
1638a5514b
Rollup merge of #133743 - bjoernager:slice-as-array, r=joboet
Fix docs for `<[T]>::as_array`.

Tracking issue: #133508

This PR fixes a small typographical error in the docs entry for `<[T]>::as_array`.
2024-12-02 17:36:08 +01:00
bors
3bff51ea91 Auto merge of #133728 - jhpratt:rollup-k1i60pg, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - #133589 (Remove `hir::ArrayLen`)
 - #133672 (Remove a bunch of unnecessary const stability noise)
 - #133678 (Stabilize `ptr::fn_addr_eq`)
 - #133727 (Update mailmap)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-02 12:17:12 +00:00
Gabriel Bjørnager Jensen
b1ff3c8b92 Fix docs for '<[T]>::as_array'; 2024-12-02 10:38:40 +01:00
Jacob Pratt
10f3735a02
Rollup merge of #133678 - Urgau:stabilize-ptr_fn_addr_eq, r=jhpratt
Stabilize `ptr::fn_addr_eq`

This PR stabilize the `ptr::fn_addr_eq` function.

FCP completed in https://github.com/rust-lang/rust/issues/129322#issuecomment-2508304516
Closes https://github.com/rust-lang/rust/issues/129322
2024-12-01 22:10:24 -05:00
Jacob Pratt
8f7a10670f
Rollup merge of #133672 - RalfJung:const-stability-cleanup, r=jhpratt
Remove a bunch of unnecessary const stability noise
2024-12-01 22:10:23 -05:00
Jacob Pratt
1391039fa7
Rollup merge of #133711 - cod10129:master, r=Noratrieb
add isatty doc alias for `is_terminal`

(first Rust contribution!)

This adds `isatty` as a doc alias for [`std::io::IsTerminal::is_terminal`](https://doc.rust-lang.org/stable/std/io/trait.IsTerminal.html#tymethod.is_terminal).

I think this change does meet the [doc alias policy](https://std-dev-guide.rust-lang.org/policy/doc-alias.html). This would be especially useful because searching "rust isatty" gets you the `isatty` crate which is deprecated in favor of `atty`. `atty` is unmaintained and you might get to `is-terminal`, which will finally tell you that the function you're looking for has been in `std` all along.

The Windows implementation of `is_terminal()` doesn't use `isatty`, but that hasn't been a problem for the analogous cases of `create_dir()`'s alias `mkdir` or `remove_dir()`/`rmdir`.
2024-12-01 21:38:25 -05:00
Jacob Pratt
5880752b9a
Rollup merge of #131784 - Urgau:stabilize-midpoint, r=dtolnay
Stabilize unsigned and float variants of `num_midpoint` feature

This PR proposes that we stabilize the unsigned variants of the [`num_midpoint`](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) feature as well as the floats variants, since they are not subject to any unresolved questions, which is equivalent to doing `(a + b) / 2` (and `(a + b) >> 1`) in a sufficiently large number.

The stabilized API surface would be:

```rust
/// Calculates the middle point of `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a sufficiently-large unsigned integral type.
/// This implies that the result is always rounded towards negative infinity and that no overflow will ever occur.

impl u{8,16,32,64,128,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl NonZeroU{8,16,32,64,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl f{32,64} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}
```

The signed variants `u{8,16,32,64,128,size}` would remain gated, until a decision is made about the rounding mode, in other words that the [unresolved questions](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) are resolved.

cc `@rust-lang/libs-api`
cc `@scottmcm`
r? libs-api
2024-12-01 21:38:24 -05:00
Jacob Pratt
cb67512784
Rollup merge of #131416 - okaneco:const_copy, r=RalfJung
Mark `slice::copy_from_slice` unstably const

Tracking issue #131415

I used `const_eval_select` for runtime and const panic functions because const formatting isn't available yet.
2024-12-01 21:38:23 -05:00
okaneco
7f011a894f Mark slice::copy_from_slice unstably const 2024-12-01 16:39:56 -05:00
cod10129
77b2fe1944 add isatty alias for is_terminal 2024-12-01 13:54:04 -06:00
Matthias Krüger
2f00feb616
Rollup merge of #133674 - scottmcm:chain-carrying-add, r=Amanieu
Fix chaining `carrying_add`s

Something about the MIR lowering for `||` ended up breaking this, but it's fixed by changing the code to use `|` instead.

I also added an assembly test to ensure it *keeps* being [`adc`](https://www.felixcloutier.com/x86/adc).

cc https://github.com/rust-lang/rust/issues/85532#issuecomment-2495119815, which noticed this.
2024-12-01 14:30:11 +01:00
Matthias Krüger
3d18c3c414
Rollup merge of #133669 - RalfJung:const_swap_splitup, r=dtolnay
Move some functions out of const_swap feature gate

- `swap_unchecked` is still unstable as a regular fn, so that feature gate can also cover its constness.
- `swap_nonoverlapping` isn't ready to be stabilized yet, so make it a different feature gate.

Part of https://github.com/rust-lang/rust/issues/83163, https://github.com/rust-lang/rust/issues/88539, https://github.com/rust-lang/rust/issues/133668
2024-12-01 14:30:10 +01:00
Urgau
b88478f707 Stabilize unsigned num_midpoint feature 2024-12-01 11:28:53 +01:00
Matthias Krüger
3d365795fa
Rollup merge of #133686 - samueltardieu:push-xkxwxzxqokuu, r=compiler-errors
Add diagnostic item for `std::ops::ControlFlow`

This will be used in Clippy to detect useless conversions done through `ControlFlow::map_break()` and `ControlFlow::map_continue()`.
2024-12-01 08:15:25 +01:00
Matthias Krüger
5d87be3b3c
Rollup merge of #133622 - mkroening:exception-blog, r=cuviper
update link to "C++ Exceptions under the hood" blog

The link was introduced in 0ec321f7b5. For the old link, see https://web.archive.org/web/20170409223244/https://monoinfinito.wordpress.com/series/exception-handling-in-c/. The blog has migrated from WordPress to Blogger in 2021 and to GitHub pages in 2024.
2024-12-01 08:15:24 +01:00
Matthias Krüger
61d50fd0ac
Rollup merge of #133602 - SanchithHegde:fix-pathbuf-example-codeblocks, r=cuviper
fix: fix codeblocks in `PathBuf` example

This PR adds missing codeblocks around an example included in the `PathBuf` documentation.
2024-12-01 08:15:23 +01:00
Matthias Krüger
ec7caabe97
Rollup merge of #133515 - SteveLauC:fix/hurd, r=ChrisDenton
fix: hurd build, stat64.st_fsid was renamed to st_dev

On hurd, `stat64.st_fsid` was renamed to `st_dev` in https://github.com/rust-lang/libc/pull/3785, so if you have a new libc with this patch included, and you build std from source, you get this error:

```sh
error[E0609]: no field `st_fsid` on type `&stat64`
   --> /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/os/hurd/fs.rs:301:36
    |
301 |         self.as_inner().as_inner().st_fsid as u64
    |                                    ^^^^^^^ unknown field
    |
help: a field with a similar name exists
    |
301 |         self.as_inner().as_inner().st_uid as u64
    |                                    ~~~~~~
```

Full CI log: https://github.com/nix-rust/nix/actions/runs/12033180710/job/33546728266?pr=2544
2024-12-01 08:15:22 +01:00
Matthias Krüger
fe4c6e8657
Rollup merge of #128184 - joboet:refactor_pthread_sync, r=workingjubilee
std: refactor `pthread`-based synchronization

The non-trivial code for `pthread_condvar` is duplicated across the thread parking and the `Mutex`/`Condvar` implementations. This PR moves that code into `sys::pal`, which now exposes an `unsafe` wrapper type for `pthread_mutex_t` and `pthread_condvar_t`.
2024-12-01 08:15:21 +01:00
bors
7442931d49 Auto merge of #133684 - RalfJung:rollup-j2tmrg7, r=RalfJung
Rollup of 6 pull requests

Successful merges:

 - #131698 (use stores of the correct size to set discriminants)
 - #133571 (Mark visionOS as supporting `std`)
 - #133655 (Eliminate print_expr_maybe_paren function from pretty printers)
 - #133667 (Remove unused code)
 - #133670 (bump hashbrown version)
 - #133673 (replace hard coded error id with `ErrorKind::DirectoryNotEmpty`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-30 21:08:45 +00:00
Samuel Tardieu
484c561d78 Add diagnostic item for std::ops::ControlFlow
This will be used in Clippy to detect useless conversions done through
`ControlFlow::map_break()` and `ControlFlow::map_continue()`.
2024-11-30 19:53:36 +01:00
Ralf Jung
ec000a7e85
Rollup merge of #133670 - RalfJung:hashbrown, r=Amanieu
bump hashbrown version

This pulls in https://github.com/rust-lang/hashbrown/pull/586, in preparation for https://github.com/rust-lang/rust/issues/102575.

Cc ``@Amanieu``
2024-11-30 19:24:43 +01:00
bors
f981b2e27a Auto merge of #133659 - jieyouxu:rollup-576gh4p, r=jieyouxu
Rollup of 6 pull requests

Successful merges:

 - #131551 (Support input/output in vector registers of PowerPC inline assembly)
 - #132515 (Fix and undeprecate home_dir())
 - #132721 (CI: split x86_64-mingw job)
 - #133106 (changes old intrinsic declaration to new declaration)
 - #133496 (thread::available_parallelism for wasm32-wasip1-threads)
 - #133548 (Add `BTreeSet` entry APIs to match `HashSet`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-30 17:18:00 +00:00
joboet
8b2ff49ff9
std: clarify comments about initialization 2024-11-30 16:22:56 +01:00
Urgau
69c0326229 Stabilize ptr::fn_addr_eq 2024-11-30 16:15:47 +01:00
Steve Lau
43ae473520 fix: hurd build, stat64.st_fsid was renamed to st_dev 2024-11-30 19:04:58 +08:00
Ralf Jung
9182aa0bf7 rustc_allow_const_fn_unstable is not used in proc_macro 2024-11-30 11:55:58 +01:00
Ralf Jung
4ce2116aef get rid of a bunch of unnecessary rustc_const_unstable 2024-11-30 11:55:58 +01:00
Scott McMurray
9836196e3c Fix chaining carrying_adds
Something about the MIR lowering for `||` ended up breaking this, but it's fixed by changing the code to use `|` instead.

I also added an assembly test to ensure it *keeps* being `adc`.
2024-11-30 02:12:23 -08:00
Ralf Jung
2a05e5be4f add test for bytewise ptr::swap of a pointer 2024-11-30 10:42:17 +01:00
Ralf Jung
0dc94404ee remove a whole bunch of unnecessary const feature gates 2024-11-30 10:23:39 +01:00
Ralf Jung
ede5f0111d move swap_nonoverlapping constness to separate feature gate 2024-11-30 10:12:30 +01:00
Ralf Jung
67a29ac73d bump hashbrown version 2024-11-30 10:06:58 +01:00
Ralf Jung
23d9741be3 move slice::swap_unchecked constness to slice_swap_unchecked feature gate 2024-11-30 09:52:20 +01:00
许杰友 Jieyou Xu (Joe)
132fcd89b3
Rollup merge of #133548 - cuviper:btreeset-entry-api, r=Mark-Simulacrum
Add `BTreeSet` entry APIs to match `HashSet`

The following methods are added, along with the corresponding `Entry` implementation.

```rust
impl<T, A: Allocator + Clone> BTreeSet<T, A> {
    pub fn get_or_insert(&mut self, value: T) -> &T
    where
        T: Ord,
    {...}
    pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
    where
        T: Borrow<Q> + Ord,
        Q: Ord,
        F: FnOnce(&Q) -> T,
    {...}

    pub fn entry(&mut self, value: T) -> Entry<'_, T, A>
    where
        T: Ord,
    {...}
}
```

Tracking issue #133549
Closes https://github.com/rust-lang/rfcs/issues/1490
2024-11-30 12:57:35 +08:00
许杰友 Jieyou Xu (Joe)
70b107910b
Rollup merge of #133496 - rust-wasi-web:wasi-available-parallelism, r=Amanieu
thread::available_parallelism for wasm32-wasip1-threads

The target has limited POSIX support and provides the `libc::sysconf` function which allows querying the number of available CPUs.
2024-11-30 12:57:35 +08:00
许杰友 Jieyou Xu (Joe)
9e716c2788
Rollup merge of #133106 - BLANKatGITHUB:intrinsic, r=RalfJung
changes old intrinsic declaration to new declaration

This pr is for issue #132735

It changes old `extern "intrinsic"` code block with new declaration.

There are other blocks that use old declaration but as the changes needed in single block is quite large I do them in parts
2024-11-30 12:57:34 +08:00
许杰友 Jieyou Xu (Joe)
9eeae42de2
Rollup merge of #132515 - kornelski:home_fix, r=jhpratt
Fix and undeprecate home_dir()

`home_dir()` has been deprecated for 6 years due to using `HOME` env var on Windows.

It's been a long time, and having a perpetually buggy and deprecated function in the standard library is not useful. I propose fixing and undeprecating it.

6 years seems more than long enough to warn users against relying on this function. The change in behavior is minor, and it's more of a bug fix than breakage. The old behavior is unlikely to be useful, and even if anybody actually needed to specifically use the non-standard `HOME` on Windows, they can trivially mitigate this change by reading the env var themselves.

----

Use of `USERPROFILE` is in line with the `home` crate: 37bc5f0232/crates/home/src/windows.rs (L12)

The `home` crate uses `SHGetKnownFolderPath` instead of `GetUserProfileDirectoryW`. AFAIK it doesn't make any difference in practice, because `SHGetKnownFolderPath` merely adds support for more kinds of folders, including virtual (non-filesystem) folders identified by a GUID, but the specific case of [`FOLDERID_Profile`](https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid#FOLDERID_Profile) is documented as a FIXED folder (a regular filesystem path). Just in case, I've added a note to documentation that the use of `GetUserProfileDirectoryW` can change.

I've used `CURRENT_RUSTC_VERSION` in a doccomment. `replace-version-placeholder` tool seems to perform a simple string replacement, so hopefully it'll get updated.
2024-11-30 12:57:33 +08:00
许杰友 Jieyou Xu (Joe)
6512836be0
Rollup merge of #133625 - RalfJung:custom-mir-debug-info, r=compiler-errors
custom MIR: add doc comment for debuginfo

This is a revival of https://github.com/rust-lang/rust/pull/117015
2024-11-30 12:56:55 +08:00
许杰友 Jieyou Xu (Joe)
dd99f11ef8
Rollup merge of #116161 - Soveu:varargs2, r=cjgillot
Stabilize `extended_varargs_abi_support`

I think that is everything? If there is any documentation regarding `extern` and/or varargs to correct, let me know, some quick greps suggest that there might be none.

Tracking issue: https://github.com/rust-lang/rust/issues/100189
2024-11-30 12:56:50 +08:00
bors
1fc691e6dd Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrum
Bump boostrap compiler to new beta

Currently failing due to something about the const stability checks and `panic!`. I'm not sure why though since I wasn't able to see any PRs merged in the past few days that would result in a `cfg(bootstrap)` that shouldn't be removed. cc `@RalfJung` #131349
2024-11-29 22:39:10 +00:00
Ralf Jung
6e449e18ad refine mir debuginfo docs 2024-11-29 14:01:53 +01:00
Camille GILLOT
c76f1f0b9b Doc comment custom MIR debuginfo.
and add a test for the constant case
2024-11-29 12:32:55 +01:00
Martin Kröning
27c4c3a978
update link to "C++ Exceptions under the hood" blog
The link was introduced in 0ec321f7b5.
For the old link see https://web.archive.org/web/20170409223244/https://monoinfinito.wordpress.com/series/exception-handling-in-c/.
The blog has migrated from WordPress to Blogger in 2021 and to GitHub pages in 2024.
2024-11-29 11:46:34 +01:00
Matthias Krüger
8ca5a907a5
Rollup merge of #133530 - timvisee:master, r=jhpratt
Use consistent wording in docs, use is zero instead of is 0

In documentation, wording of _"`rhs` is zero"_ and _"`rhs` is 0"_ is intermixed. This is especially visible [here](https://doc.rust-lang.org/std/primitive.usize.html#method.div_ceil).

This changes all occurrences to _"`rhs` is zero"_ for better readability.
2024-11-29 10:18:58 +01:00
Matthias Krüger
370fc13298
Rollup merge of #133466 - aksh1618:patch-1, r=thomcc
Fix typos in pin.rs
2024-11-29 10:18:56 +01:00
Sanchith Hegde
d599d5a381
fix: fix codeblocks in PathBuf example 2024-11-29 03:50:26 +05:30