Commit Graph

17720 Commits

Author SHA1 Message Date
bors
b605c65b6e Auto merge of #135224 - wyfo:tls-panic-outline, r=cuviper
Outline panicking code for `LocalKey::with`

See https://github.com/rust-lang/rust/pull/115491 for prior related modifications.

https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
2025-01-21 02:23:15 +00:00
bors
a42d5ecf34 Auto merge of #134286 - Urgau:unreach_pub-std, r=ibraheemdev
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](https://github.com/rust-lang/compiler-team/issues/773#issue-2467219005) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
2025-01-20 23:34:04 +00:00
Matthias Krüger
8a7db695a6
Rollup merge of #135741 - bardiharborow:std/net/rfc9637, r=Amanieu
Recognise new IPv6 documentation range from IETF RFC 9637

This PR adds the `3fff::/20` range defined by [IETF RFC 9637](https://datatracker.ietf.org/doc/rfc9637/) to those ranges which `Ipv6Addr::is_documentation` recognises as a documentation IP.

See also: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
Unstable tracking issue: #27709
2025-01-20 20:58:36 +01:00
Matthias Krüger
bbec1510bb
Rollup merge of #133695 - x17jiri:hint_likely, r=Amanieu
Reexport likely/unlikely in std::hint

Since `likely`/`unlikely` should be working now, we could reexport them in `std::hint`. I'm not sure if this is already approved or if it requires approval

Tracking issue: #26179
2025-01-20 20:58:34 +01:00
Urgau
15f345b815 core: #[allow(unreachable_pub)] on unreachable pub use 2025-01-20 18:35:32 +01:00
Urgau
8e61502484 core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
Urgau
0f30662147 rtstartup: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
Urgau
477ef65121 panic_unwind: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
Jiri Bobek
cb2efaf5bc 1. Removed 'rustc_nounwind' 2. Rewording of comments 2025-01-20 16:16:46 +01:00
许杰友 Jieyou Xu (Joe)
ecfb55762c
Rollup merge of #135762 - TomFryersMidsummer:patch-1, r=joboet
Correct counting to four in cell module docs

It could also be argued that `OnceCell<T>` and `LazyCell<T>` don't really provide safe interior mutability in different ways. But it's a vague enough claim that I'm not sure it's worth being pedantic about.
2025-01-20 21:45:06 +08:00
许杰友 Jieyou Xu (Joe)
e7f53663de
Rollup merge of #135626 - clubby789:env-note, r=ibraheemdev
doc: Point to methods on `Command` as alternatives to `set/remove_var`

Make these methods more discoverable, as configuring a child process is a common reason for manipulating the environment.
2025-01-20 21:45:04 +08:00
Tom Fryers
8ba0d2db18
Correct counting to four in cell module docs 2025-01-20 10:16:27 +00:00
许杰友 Jieyou Xu (Joe)
e1e26f339d
Rollup merge of #135491 - RalfJung:remove-dead-rustc_allowed_through_unstable_modules, r=Mark-Simulacrum
Remove dead rustc_allowed_through_unstable_modules for std::os::fd contents

As far as I was able to reconstruct, the history here is roughly as follows:
- https://github.com/rust-lang/rust/pull/99723 added some `rustc_allowed_through_unstable_modules` to the types in `std::os::fd::raw` since they were accessible on stable via the unstable `std::os::wasi::io::AsRawFd` path. (This was needed to fix https://github.com/rust-lang/rust/issues/99502.)
- Shortly thereafter, https://github.com/rust-lang/rust/pull/98368 re-organized things so that instead of re-exporting from an internal  `std::os::wasi::io::raw`,   `std::os::wasi::io::AsRawFd` is now directly re-exported from `std::os::fd`. This also made `library/std/src/os/wasi/io/raw.rs` entirely dead code as far as I can tell, it's not imported by anything any more.
- Shortly thereafter, https://github.com/rust-lang/rust/pull/103308 stabilizes `std::os::wasi::io`, so `rustc_allowed_through_unstable_modules` is not needed any more to access `std::os::wasi::io::AsRawFd`. There is even a comment in `library/std/src/os/wasi/io/raw.rs` saying the attribute can be removed now, but that file is dead code so it is not touched as part of the stabilization.

I did a grep for `pub use crate::os::fd` and all the re-exports I could find are in stable modules. So given all that, we can remove the  `rustc_allowed_through_unstable_modules` (hoping they are not also re-exported somewhere else, it's really hard to be sure about this).

I have checked that std still builds after this PR on the wasm32-wasip2 target.
2025-01-20 12:38:32 +08:00
许杰友 Jieyou Xu (Joe)
e5b85035fe
Rollup merge of #135446 - klensy:panic_immediate_abort_ext, r=Mark-Simulacrum
further improve panic_immediate_abort by removing rtprintpanic! messages

Reduces binary size using `panic_immediate_abort` by removing strings used by `rtprintpanic!`.

for `main.rs`
```rust
fn main() {
    println!("Hello, world!");
}
```
with `Cargo.toml`
```toml
[package]
name = "tst"
version = "0.1.0"
edition = "2024"

[dependencies]

[profile.release]
lto = true
codegen-units = 1
panic = "abort"

```

and build with `RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" cargo +stage-1 b -r -Z build-std=std,panic_abort -Z build-std-features=optimize_for_size,panic_immediate_abort` for `x86_64-unknown-linux-gnu`

This reduces size:
| before |  after | type |
| - | - | - |
| 25256 | 21880 | unstripped |
| 18072 | 15288 | stripped |
2025-01-20 12:38:32 +08:00
Bardi Harborow
1f0e35eeca Recognise new IPv6 documentation range from RFC9637
This commit adds the 3fff::/20 range defined by RFC9637 to those ranges which Ipv6Addr::is_documentation recognises as a documentation IP.
2025-01-20 07:39:33 +11:00
bors
39dc268459 Auto merge of #135714 - rust-lang:cargo_update, r=clubby789
Weekly `cargo update`

Automation to keep dependencies in `Cargo.lock` current.

The following is the output from `cargo update`:

```txt

compiler & tools dependencies:
     Locking 13 packages to latest compatible versions
    Updating anstyle-wincon v3.0.6 -> v3.0.7
    Updating bitflags v2.7.0 -> v2.8.0
    Updating chrono-tz v0.10.0 -> v0.10.1
    Updating js-sys v0.3.76 -> v0.3.77
    Updating log v0.4.22 -> v0.4.25
    Updating miniz_oxide v0.8.2 -> v0.8.3
    Updating uuid v1.11.1 -> v1.12.0
    Updating valuable v0.1.0 -> v0.1.1
    Updating wasm-bindgen v0.2.99 -> v0.2.100
    Updating wasm-bindgen-backend v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro-support v0.2.99 -> v0.2.100
    Updating wasm-bindgen-shared v0.2.99 -> v0.2.100
note: pass `--verbose` to see 41 unchanged dependencies behind latest

library dependencies:
     Locking 1 package to latest compatible version
    Updating miniz_oxide v0.8.2 -> v0.8.3
note: pass `--verbose` to see 4 unchanged dependencies behind latest

rustbook dependencies:
     Locking 12 packages to latest compatible versions
    Updating anstyle-wincon v3.0.6 -> v3.0.7
    Updating bitflags v2.7.0 -> v2.8.0
    Updating cc v1.2.8 -> v1.2.10
    Updating js-sys v0.3.76 -> v0.3.77
    Updating log v0.4.22 -> v0.4.25
    Updating miniz_oxide v0.8.2 -> v0.8.3
      Adding rustversion v1.0.19
    Updating wasm-bindgen v0.2.99 -> v0.2.100
    Updating wasm-bindgen-backend v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro-support v0.2.99 -> v0.2.100
    Updating wasm-bindgen-shared v0.2.99 -> v0.2.100
```
2025-01-19 14:19:27 +00:00
bors
678e669cc4 Auto merge of #134976 - mgsloan:improve-select-nth-unstable-docs, r=ibraheemdev
Improve `select_nth_unstable` documentation clarity

* Instead uses `before` and `after` variable names in the example
where `greater` and `lesser` are flipped.

* Uses `<=` and `>=` instead of "less than or equal to" and "greater
than or equal to" to make the docs more concise.

* General attempt to remove unnecessary words and be more precise. For
example it seems slightly wrong to say "its final sorted position",
since this implies there is only one sorted position for this element.
2025-01-19 08:50:12 +00:00
bors
c62b732724 Auto merge of #135709 - lqd:bring-back-len, r=compiler-errors
Temporarily bring back `Rvalue::Len`

r? `@compiler-errors` as requested in https://github.com/rust-lang/rust/issues/135671#issuecomment-2599580364

> However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔

Agreed. To fix the IMO P-critical #135671 for which we somehow didn't have test coverage, this PR temporarily reverts:
- https://github.com/rust-lang/rust/pull/133734
- its bugfix https://github.com/rust-lang/rust/pull/134371
- https://github.com/rust-lang/rust/pull/134330

cc `@scottmcm`

I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](https://github.com/rust-lang/rust/issues/135671#issuecomment-2599714354).

Fixes #135671. And if we want to land this, it should also be nominated for beta backport.
2025-01-19 06:09:51 +00:00
Michael Sloan
3a6eea0c6a Rewrap following accepting review suggestions from @ibraheemdev 2025-01-18 18:40:16 -07:00
Michael Sloan
fd89cf9b8f
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:35:41 -07:00
Michael Sloan
6ac44fa5fa
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:35:22 -07:00
Michael Sloan
c0aa7b5cf0
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:35:12 -07:00
Michael Sloan
de7f1b670b
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:34:29 -07:00
Michael Sloan
a3c65805ad
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:34:21 -07:00
Michael Sloan
2eef440c22
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:42 -07:00
Michael Sloan
a506f9d210
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:33 -07:00
Michael Sloan
305bd856b2
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:23 -07:00
Michael Sloan
d39d0ecd57
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:02 -07:00
Michael Sloan
ecf68f3cd0
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:32:47 -07:00
github-actions
715c3d4fcf cargo update
compiler & tools dependencies:
     Locking 13 packages to latest compatible versions
    Updating anstyle-wincon v3.0.6 -> v3.0.7
    Updating bitflags v2.7.0 -> v2.8.0
    Updating chrono-tz v0.10.0 -> v0.10.1
    Updating js-sys v0.3.76 -> v0.3.77
    Updating log v0.4.22 -> v0.4.25
    Updating miniz_oxide v0.8.2 -> v0.8.3
    Updating uuid v1.11.1 -> v1.12.0
    Updating valuable v0.1.0 -> v0.1.1
    Updating wasm-bindgen v0.2.99 -> v0.2.100
    Updating wasm-bindgen-backend v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro-support v0.2.99 -> v0.2.100
    Updating wasm-bindgen-shared v0.2.99 -> v0.2.100
note: pass `--verbose` to see 41 unchanged dependencies behind latest

library dependencies:
     Locking 1 package to latest compatible version
    Updating miniz_oxide v0.8.2 -> v0.8.3
note: pass `--verbose` to see 4 unchanged dependencies behind latest

rustbook dependencies:
     Locking 12 packages to latest compatible versions
    Updating anstyle-wincon v3.0.6 -> v3.0.7
    Updating bitflags v2.7.0 -> v2.8.0
    Updating cc v1.2.8 -> v1.2.10
    Updating js-sys v0.3.76 -> v0.3.77
    Updating log v0.4.22 -> v0.4.25
    Updating miniz_oxide v0.8.2 -> v0.8.3
      Adding rustversion v1.0.19
    Updating wasm-bindgen v0.2.99 -> v0.2.100
    Updating wasm-bindgen-backend v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro v0.2.99 -> v0.2.100
    Updating wasm-bindgen-macro-support v0.2.99 -> v0.2.100
    Updating wasm-bindgen-shared v0.2.99 -> v0.2.100
2025-01-19 00:21:55 +00:00
Rémy Rakic
ca1c17c88d Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"
This reverts commit e108481f74, reversing
changes made to 303e8bd768.
2025-01-18 22:09:34 +00:00
Michael Sloan
0257cfb974 then be -> be based on feedback from @ibraheemdev 2025-01-18 14:52:16 -07:00
Matthias Krüger
23fb4f22b3
Rollup merge of #135661 - tgross35:stabilize-float_next_up_down, r=scottmcm
Stabilize `float_next_up_down`

FCP completed at [1].

For `f16` and `f128`, this just removes the gates in comments and doctests.

Closes https://github.com/rust-lang/rust/issues/91399

[1]: https://github.com/rust-lang/rust/issues/91399#issuecomment-2598734570
2025-01-18 13:58:06 +01:00
Matthias Krüger
508c72b81e
Rollup merge of #135583 - NobodyXu:move-pipe-to-io, r=joshtriplett
Move `std::pipe::*` into `std::io`

Resolve concern from final comment period https://github.com/rust-lang/rust/issues/127154#issuecomment-2590419895
2025-01-18 13:58:03 +01:00
Trevor Gross
809f61a783 Add references to the IEEE functions for float_next_up_down
Mention the IEEE function by name and create a doc alias of the same.
2025-01-17 23:01:23 +00:00
Trevor Gross
366cecacdd Stabilize float_next_up_down
FCP completed at [1].

Closes https://github.com/rust-lang/rust/issues/91399

[1]: https://github.com/rust-lang/rust/issues/91399#issuecomment-2598734570
2025-01-17 23:01:10 +00:00
Jiahao XU
81d70f92ab
Fix import of pipe in kernel_copy.rs
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-18 00:44:44 +11:00
clubby789
f7c2d1194d doc: Point to methods on Command as alternatives to set/remove_var 2025-01-17 12:53:58 +00:00
Matthias Krüger
dbbbed0579
Rollup merge of #135556 - AeonSolstice:patch-1, r=tgross35
Clarify note in `std::sync::LazyLock` example

I doubt most people know what it means, as I did not until a week ago. In the current form, it seems like a `TODO:`.
2025-01-16 17:00:47 +01:00
Matthias Krüger
87b3671ce9
Rollup merge of #134496 - DiuDiu777:fix-doc, r=ibraheemdev
Update documentation for Arc::from_raw, Arc::increment_strong_count, and Arc::decrement_strong_count to clarify allocator requirement

### Related Issue:
This update addresses parts of the issue raised in [#134242](https://github.com/rust-lang/rust/issues/134242), where Arc's documentation lacks `Global Allocator` safety descriptions for three APIs. And this was confirmed by ```@workingjubilee``` :
> Wait, nevermind. I apparently forgot the `increment_strong_count` is implicitly A = Global. Ugh. Another reason these things are hard to track, unfortunately.

### PR Description
This PR updates the document for the following APIs:
- `Arc::from_raw`
- `Arc::increment_strong_count`
- `Arc::decrement_strong_count`

These APIs currently lack an important piece of documentation: **the raw pointer must point to a block of memory allocated by the global allocator**. This crucial detail is specified in the source code but is not reflected in the documentation, which could lead to confusion or incorrect usage by users.

### Problem:
The following example demonstrates the potential confusion caused by the lack of documentation:

```rust
#![feature(allocator_api)]
use std::alloc::{Allocator,AllocError, Layout};
use std::ptr::NonNull;
use std::sync::Arc;

struct LocalAllocator {
    memory: NonNull<u8>,
    size: usize,
}

impl LocalAllocator {
    fn new(size: usize) -> Self {
        Self {
            memory: unsafe { NonNull::new_unchecked(&mut 0u8 as *mut u8) },
            size,
        }
    }
}

unsafe impl Allocator for LocalAllocator {
    fn allocate(&self, _layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        Ok(NonNull::slice_from_raw_parts(self.memory, self.size))
    }

    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
    }
}

fn main() {
    let allocator = LocalAllocator::new(64);
    let arc = Arc::new_in(5, &allocator); // Here, allocator could be any non-global allocator
    let ptr = Arc::into_raw(arc);

    unsafe {
        Arc::increment_strong_count(ptr);
        let arc = Arc::from_raw(ptr);
        assert_eq!(2, Arc::strong_count(&arc)); // Failed here!
    }
}
```
2025-01-16 17:00:45 +01:00
Matthias Krüger
fca148185e
Rollup merge of #133720 - c410-f3r:cfg-match-foo-bar-baz, r=joshtriplett
[cfg_match] Adjust syntax

A year has passed since the creation of #115585 and the feature, as expected, is not moving forward. Let's change that.

This PR proposes changing the arm's syntax from  `cfg(SOME_CONDITION) => { ... }` to `SOME_CODITION => {}`.

```rust
match_cfg! {
   unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}
```

Why? Because after several manual migrations in https://github.com/rust-lang/rust/pull/116342 it became clear,  at least for me, that `cfg` prefixes are unnecessary, verbose and redundant.

Again, everything is just a proposal to move things forward. If the shown syntax isn't ideal, feel free to close this PR or suggest other alternatives.
2025-01-16 17:00:44 +01:00
Jiahao XU
efe888871c
Move std::pipe::* into std::io
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-17 01:30:05 +11:00
ClearLove
48e671ec88
fix typo in library/alloc/src/sync.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-16 15:16:43 +08:00
Scott McMurray
c18718c9c2 Less unsafe in dangling/without_provenance 2025-01-15 22:17:57 -08:00
bors
6fc8a27931 Auto merge of #135555 - matthiaskrgr:rollup-jnqdbuu, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #135497 (fix typo in typenames of pin documentation)
 - #135522 (add incremental test for issue 135514)
 - #135523 (const traits: remove some known-bug that do not seem to make sense)
 - #135535 (Add GUI test for #135499)
 - #135541 (Methods of const traits are const)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-15 22:22:48 +00:00
Aeon
c4a5e12567
Clarify note in std::sync::LazyLock example 2025-01-15 16:08:22 -05:00
Matthias Krüger
85d2b2af15
Rollup merge of #135497 - DJMrTV:master, r=jhpratt
fix typo in typenames of pin documentation

I noticed this whilst reading the documentation for pin.

Basically there was just one to many closing angle brackets on the type parameters in the documentation where instead of being `Pin<&mut T>` it was `Pin<&mut T>>`
2025-01-15 22:06:11 +01:00
Jiri Bobek
c656f879c9 Export likely(), unlikely() and cold_path() in std::hint 2025-01-15 21:42:47 +01:00
DJMrTV
b535a1dd65 fix typo in typenames of pin documentation 2025-01-15 19:18:17 +01:00
Guillaume Gomez
369d135733
Rollup merge of #135003 - RalfJung:deprecate-allowed-through-unstable, r=davidtwco
deprecate `std::intrinsics::transmute` etc, use `std::mem::*` instead

The `rustc_allowed_through_unstable_modules` attribute lets users call `std::mem::transmute` as `std::intrinsics::transmute`. The former is a reexport of the latter, and for a long time we didn't properly check stability for reexports, so making this a hard error now would be a breaking change for little gain. But at the same time, `std::intrinsics::transmute` is not the intended path for this function, so I think it is a good idea to show a deprecation warning when that path is used. This PR implements that, for all the functions in `std::intrinsics` that carry the attribute.

I assume this will need ``@rust-lang/libs-api`` FCP.
2025-01-15 16:30:11 +01:00