Commit Graph

7712 Commits

Author SHA1 Message Date
Matthias Krüger
9630242e5e
Rollup merge of #137439 - clarfonthey:c-str-module, r=tgross35
Stabilise `std::ffi::c_str`

This finished FCP in #112134 but never actually got a stabilisation PR. Since the FCP in #120048 recently passed to add the `os_str` module, it would be nice to also merge this too, to ensure that both get added in the next version.

Note: The added stability attributes which *somehow* were able to be omitted before (rustc bug?) were added based on the fact that they were added in 302551388b, which ended up in 1.85.0.

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

r? libs-api
2025-04-27 11:54:56 +02:00
Matthias Krüger
153eeb0e24
Rollup merge of #140325 - ethanwu10:ethanwu10/grammar-fixes-for-bufread-has-data-left-docs, r=jhpratt
Grammar fixes for BufRead::has_data_left docs

Fix some grammar in the documentation for `BufRead::has_data_left`
2025-04-26 16:12:34 +02:00
Ethan Wu
0084862cd3 Grammar fixes for BufRead::has_data_left docs 2025-04-25 22:21:40 -07:00
Matthias Krüger
806260e973
Rollup merge of #140216 - t5kd:master, r=tgross35
Document that "extern blocks must be unsafe" in Rust 2024

The [documentation on `extern`](https://doc.rust-lang.org/std/keyword.extern.html) contains the following code sample:
```rust
#[link(name = "my_c_library")]
extern "C" {
    fn my_c_function(x: i32) -> bool;
}
```

Due to #123743, attempting to compile such code with the 2024 edition of Rust fails:
```
error: extern blocks must be unsafe
```

This PR extends the `extern` documentation with a brief explanation of the new requirement. It also adds the missing `unsafe` keyword to the code sample, which should be compatible with rustc since v1.82.

**Related docs:**
- https://doc.rust-lang.org/reference/items/external-blocks.html
- https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html
2025-04-26 07:13:07 +02:00
Tobias
1862feb0e7 Update extern docs for Rust 2024 and add safety remarks 2025-04-25 23:23:02 +02:00
bors
b4c8b0c3f0 Auto merge of #140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137683 (Add a tidy check for GCC submodule version)
 - #138968 (Update the index of Result to make the summary more comprehensive)
 - #139572 (docs(std): mention const blocks in const keyword doc page)
 - #140152 (Unify the format of rustc cli flags)
 - #140193 (fix ICE in `#[naked]` attribute validation)
 - #140205 (Tidying up UI tests [2/N])
 - #140284 (remove expect() in `unnecessary_transmutes`)
 - #140290 (rustdoc: fix typo change from equivelent to equivalent)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 18:51:15 +00:00
Matthias Krüger
394cdca40f
Rollup merge of #139572 - ismailarilik:docs/std/mention-const-blocks-in-const-keyword-doc-page, r=tgross35
docs(std): mention const blocks in const keyword doc page

Aims to close #139549
2025-04-25 17:31:47 +02:00
bors
8f43b85954 Auto merge of #140282 - matthiaskrgr:rollup-g6ze4jj, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137653 (Deprecate the unstable `concat_idents!`)
 - #138957 (Update the index of Option to make the summary more comprehensive)
 - #140006 (ensure compiler existance of tools on the dist step)
 - #140143 (Move `sys::pal::os::Env` into `sys::env`)
 - #140202 (Make #![feature(let_chains)] bootstrap conditional in compiler/)
 - #140236 (norm nested aliases before evaluating the parent goal)
 - #140257 (Some drive-by housecleaning in `rustc_borrowck`)
 - #140278 (Don't use item name to look up associated item from trait item)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 12:27:16 +00:00
bors
5c54aa781f Auto merge of #140273 - matthiaskrgr:rollup-rxmuvkg, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137096 (Stabilize flags for doctest cross compilation)
 - #140148 (CI: use aws codebuild for job dist-arm-linux)
 - #140187 ([AIX] Handle AIX dynamic library extensions within c-link-to-rust-dylib run-make test)
 - #140196 (Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`))
 - #140210 (Work around cygwin issue on condvar timeout)
 - #140213 (mention about `x.py setup` in `INSTALL.md`)
 - #140229 (`DelimArgs` tweaks)
 - #140248 (Fix impl block items indent)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 09:09:27 +00:00
ismailarilik
49cb451b5d docs(std): mention const blocks in const keyword doc page 2025-04-25 10:17:27 +03:00
Matthias Krüger
f3641df491
Rollup merge of #140143 - thaliaarchi:move-env-pal, r=joboet
Move `sys::pal::os::Env` into `sys::env`

Although `Env` (as `Vars`), `Args`, path functions, and OS constants are publicly exposed via `std::env`, their implementations are each self-contained. Keep them separate in `std::sys` and make a new module, `sys::env`, for `Env`.

Also fix `unsafe_op_in_unsafe_fn` for Unix and update the `!DynSend` and `!DynSync` impls which had grown out of sync with the platforms (see #48005 for discussion on that).

r? joboet

Tracked in #117276.
2025-04-25 07:50:25 +02:00
Matthias Krüger
84a921d957
Rollup merge of #137653 - tgross35:deprecate-concat_idents, r=workingjubilee
Deprecate the unstable `concat_idents!`

`concat_idents` has been around unstably for a long time, but there is now a better (but still unstable) way to join identifiers using `${concat(...)}` syntax with `macro_metavar_expr_concat`. This resolves a lot of the problems with `concat_idents` and is on a better track toward stabilization, so there is no need to keep both versions around. `concat_idents!` still has a lot of use in the ecosystem so deprecate it before removing, as discussed in [1].

Link: https://github.com/rust-lang/rust/issues/124225

[1]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Removing.20.60concat_idents.60
2025-04-25 07:50:23 +02:00
Matthias Krüger
11fbbc54ba
Rollup merge of #140210 - Berrysoft:cygwin-timedwait, r=joboet
Work around cygwin issue on condvar timeout

This workaround *just works*... Actually I don't quite understand why does it work in such way. With a simple test on Cygwin, it seems that the maximum value of `tv_sec` could be 12899331056917, while the maximum value of `tv_nsec` should be a value floating around 464600000. A larger `timespec` could block the syscall forever.

r? `@joboet`
2025-04-25 00:54:00 +02:00
Trevor Gross
75a9be609e Deprecate the unstable concat_idents!
`concat_idents` has been around unstably for a long time, but there is
now a better (but still unstable) way to join identifiers using
`${concat(...)}` syntax with `macro_metavar_expr_concat`. This resolves
a lot of the problems with `concat_idents` and is on a better track
toward stabilization, so there is no need to keep both versions around.
`concat_idents!` still has a lot of use in the ecosystem so deprecate it
before removing, as discussed in [1].

Link: https://github.com/rust-lang/rust/issues/124225
[1]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Removing.20.60concat_idents.60
2025-04-24 22:14:23 +00:00
Matthias Krüger
9dcb367838
Rollup merge of #140141 - thaliaarchi:env-consts/zkvm, r=joboet
Move zkVM constants into `sys::env_consts`

I missed this in #139868. Its `mod` declaration was removed, but the contents were not moved.

r? joboet
2025-04-24 17:19:45 +02:00
Matthias Krüger
10732e14f4
Rollup merge of #139450 - NobodyXu:new-api/make-fifo, r=tgross35
Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo`

Tracking issue #139324
2025-04-24 08:12:57 +02:00
Matthias Krüger
cb3c5d773c
Rollup merge of #139307 - xizheyin:issue-139296, r=joboet
std: Add performance warnings to HashMap::get_disjoint_mut

Closes #139296

The `get_disjoint_mut` in `HashMap` also performs a complexity O(n^2) check. So we need to be reminded of that as well.

b5b0655a37/src/raw/mod.rs (L1216-L1220)
2025-04-24 08:12:56 +02:00
王宇逸
d2120e653e Work around cygwin issue on timeout 2025-04-24 01:25:46 +08:00
bors
553600e0f5 Auto merge of #140180 - ChrisDenton:rollup-5pvs08u, r=ChrisDenton
Rollup of 7 pull requests

Successful merges:

 - #140142 (Some more graphviz tweaks)
 - #140146 (Update `compiler_builtins` to 0.1.156)
 - #140147 (Clean: rename `open_braces` to `open_delimiters` in lexer and move `make_unclosed_delims_error` into `diagnostics.rs`.)
 - #140160 (Use `is_lang_item` and `as_lang_item` instead of handrolling their logic)
 - #140163 (Validate extension in `PathBuf::add_extension`)
 - #140173 (Ping Mara when touching format_args!() internals.)
 - #140175 (`rc""` more clear error message)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-23 15:12:33 +00:00
Jiahao XU
780f95dd18
Impl new API std::os::unix::fs::mkfifo under feature unix_fifo
Tracking issue #139324

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-04-23 23:02:52 +10:00
Chris Denton
ed4e167c4a
Rollup merge of #140163 - thaliaarchi:pathbuf-validate-extension, r=ChrisDenton
Validate extension in `PathBuf::add_extension`

The extension is validated in `PathBuf::set_extension`, but not `add_extension`. Fix that. Check for both `/` and `\` path separators on Windows, even when the path is verbatim, since this is logically like `PathBuf::push` which normalizes separators (i.e., keeping the current behavior).

`PathBuf::add_extension` is tracked in #127292.

r? `@ChrisDenton`
2025-04-23 00:43:07 +00:00
Chris Denton
538ae9979b
Rollup merge of #140146 - tgross35:update-builtins, r=tgross35
Update `compiler_builtins` to 0.1.156

Includes the following changes:

* Provide `abort` on AVR [1]

[1]: https://github.com/rust-lang/compiler-builtins/pull/830
2025-04-23 00:43:05 +00:00
Chris Denton
2d8264fb08
Rollup merge of #140149 - RalfJung:test_nan, r=tgross35
test_nan: ensure the NAN contant is quiet

Follow-up to https://github.com/rust-lang/rust/pull/139483

r? ``@tgross35``
2025-04-22 15:24:09 +00:00
Chris Denton
1586660fb2
Rollup merge of #139617 - Berrysoft:cygwin-posix-spawn, r=joboet
Use posix_spawn on cygwin

r? ``@joboet``

Depends on:
- [x] https://github.com/rust-lang/libc/pull/4387
- [x] https://github.com/rust-lang/rust/pull/140081
2025-04-22 15:24:05 +00:00
Thalia Archibald
006b7e3a2b Validate extension in PathBuf::add_extension
The extension is validated in `PathBuf::set_extension`, but not
`add_extension`. Fix that. Check for both / and \ path separators on
Windows, even when the path is verbatim, since this is logically like
`PathBuf::push` which normalizes separators (i.e., keeping the current
behavior).
2025-04-22 05:34:25 -07:00
Ralf Jung
e7a865448a test_nan: ensure the NAN contant is quiet 2025-04-22 09:06:43 +02:00
Trevor Gross
e800bf7df4 Update compiler_builtins to 0.1.156
Includes the following changes:

* Provide `abort` on AVR [1]

[1]: https://github.com/rust-lang/compiler-builtins/pull/830
2025-04-22 05:46:51 +00:00
Thalia Archibald
01485c9fe9 Unify owned Env types between platforms
Also, update the same pattern of reuse in `sys::args` to match.
2025-04-21 22:38:22 -07:00
Thalia Archibald
4695212566 Deduplicate unsupported env items 2025-04-21 21:58:58 -07:00
Thalia Archibald
6518bcb967 Fix unsafe_op_in_unsafe_fn for Unix env 2025-04-21 21:17:16 -07:00
Thalia Archibald
dfc8f02279 Move zkVM constants into sys::env_consts
I missed this in #139868. Its `mod` declaration was removed, but the
contents were not moved.
2025-04-21 21:05:04 -07:00
Thalia Archibald
90fe2805df Move sys::pal::os::Env into sys::env
Although `Env` (as `Vars`), `Args`, path functions, and OS constants are
publicly exposed via `std::env`, their implementations are each
self-contained. Keep them separate in `std::sys` and make a new module,
`sys::env`, for `Env`.
2025-04-21 20:56:43 -07:00
Chris Denton
07a28ec2fb
Rollup merge of #140081 - Berrysoft:update-libc-172, r=tgross35
Update `libc` to 0.2.172

r? ````@joboet````
2025-04-22 01:22:13 +00:00
bors
d6c1e454aa Auto merge of #140127 - ChrisDenton:rollup-2kye32h, r=ChrisDenton
Rollup of 11 pull requests

Successful merges:

 - #134213 (Stabilize `naked_functions`)
 - #139711 (Hermit: Unify `std::env::args` with Unix)
 - #139795 (Clarify why SGX code specifies linkage/symbol names for certain statics)
 - #140036 (Advent of `tests/ui` (misc cleanups and improvements) [4/N])
 - #140047 (remove a couple clones)
 - #140052 (Fix error when an intra doc link is trying to resolve an empty associated item)
 - #140074 (rustdoc-json: Improve test for auto-trait impls)
 - #140076 (jsondocck: Require command is at start of line)
 - #140107 (rustc-dev-guide subtree update)
 - #140111 (cleanup redundant pattern instances)
 - #140118 ({B,C}Str: minor cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-21 19:28:16 +00:00
Chris Denton
8ecaf148e7
Rollup merge of #140111 - jogru0:redundant_pattern, r=compiler-errors
cleanup redundant pattern instances

Just two small code cleanups.
2025-04-21 18:53:20 +00:00
Chris Denton
cac8bc3d1f
Rollup merge of #139795 - jethrogb:jb/sgx-linkage-comments, r=joboet
Clarify why SGX code specifies linkage/symbol names for certain statics

Specifying linkage/symbol name is solely to ensure a single instance between the `std` crate and its unit tests.

Also update the symbol names as items have moved around a bit. The actual name isn't that important, it just needs to be unique. But for debugging it can be useful for it to point to the right place.
2025-04-21 18:53:16 +00:00
Chris Denton
5779843eda
Rollup merge of #139711 - thaliaarchi:hermit-args, r=jhpratt
Hermit: Unify `std::env::args` with Unix

The only differences between these implementations of `std::env::args` are that Unix uses relaxed ordering, but Hermit uses acquire/release, and Unix truncates `argv` at the first null pointer, but Hermit doesn't. Since Hermit aims for Unix compatibility, unify it with Unix.

The atomic orderings were established in https://github.com/rust-lang/rust/pull/74006 (cc `@euclio)` for Unix and https://github.com/rust-lang/rust/pull/100579 (cc `@joboet)` for Hermit and, before those, they used mutexes and non-atomic statics. I think the difference in orderings is simply from them being changed at different times. The commented explanation for using acquire/release for Hermit is “to broadcast writes by the OS”. I'm not experienced enough with atomics to accurately judge, but I think acquire/release is stronger than needed. Either way, they should match.

Truncating at the first null pointer seems desirable, though I don't know whether it is necessary in practice on Hermit.

cc `@mkroening` `@stlankes` for Hermit
2025-04-21 18:53:16 +00:00
Chris Denton
24bd5649b1
Rollup merge of #140009 - ShE3py:tls-abort, r=thomcc
docs(LocalKey<T>): clarify that T's Drop shouldn't panic

Clarify that should a TLS destructor panics, the process will abort.

Also, an abort may be obfuscated as the process can be terminated with `SIGSEGV` or [`STATUS_STACK_BUFFER_OVERRUN`](https://devblogs.microsoft.com/oldnewthing/20190108-00/?p=100655) (i.e., `SIGABRT` is not guaranteed), so explicitly prints that the process was aborted.

Context:
https://users.rust-lang.org/t/status-stack-buffer-overrun-on-windows-without-any-usage-of-unsafe/128417

``@rustbot`` label -T-compiler
2025-04-21 15:55:57 +00:00
Chris Denton
10e17dc3a4
Rollup merge of #139982 - coolreader18:time-doc-tweak, r=jhpratt
SystemTime doc tweaks

* Change the `UNIX_EPOCH` link in the `SystemTime` docs to point to the associated constant, not the module level constant. The former seems to be the recommended way to access it, since aiui the only reason the module constant exists in the first place is that associated constants weren't stable yet at the time.
* Reword the comment in the `SystemTime` example - "an error occurred!" is a tad misleading; I feel like it implies a system error out of our control while `SystemTimeError` is more of a logic error.

I was originally just gonna do the first thing but I noticed the second and figured I may as well.

I'm also somewhat surprised that there aren't more in-depth module level docs for `std::time`; they don't even mention `SystemTime` at all. I might make another PR for that but mainly just wanted to flag it.
2025-04-21 15:55:57 +00:00
Jonathan Gruner
2039b36f90 cleanup redundant pattern instances 2025-04-21 14:15:32 +02:00
xizheyin
16381b3133
Use currently for futher improvement
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2025-04-20 21:20:29 +08:00
王宇逸
6ea0fe5fc4 Update libc to 0.2.172 for std 2025-04-20 21:19:52 +08:00
bors
49e5e4e3a5 Auto merge of #140043 - ChrisDenton:rollup-vwf0s9j, r=ChrisDenton
Rollup of 8 pull requests

Successful merges:

 - #138934 (support config extensions)
 - #139091 (Rewrite on_unimplemented format string parser.)
 - #139753 (Make `#[naked]` an unsafe attribute)
 - #139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - #139834 (Don't canonicalize crate paths)
 - #139868 (Move `pal::env` to `std::sys::env_consts`)
 - #139978 (Add citool command for generating a test dashboard)
 - #139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-20 02:08:02 +00:00
Chris Denton
709f4fee50
Rollup merge of #139868 - thaliaarchi:move-env-consts-pal, r=joboet
Move `pal::env` to `std::sys::env_consts`

Combine the `std::env::consts` platform implementations as a single file. Use the Unix file as the base, since it has 28 entries, and fold the 8 singleton platforms into it. The Unix file was roughly grouped into Linux, Apple, BSD, and everything else, roughly in alphabetical order. Alphabetically order them to make it easier to maintain and discard the Unix-specific groups to generalize it to all platforms.

I'd prefer to have no fallback implementation, as I consider it a bug; however TEEOS, Trusty, and Xous have no definitions here. Since they otherwise have `pal` abstractions, that indicates that there are several platforms without `pal` abstractions which are also missing here. To support unsupported, create a little macro to handle the fallback case and not introduce ordering between the `cfg`s like `cfg_if!`.

I've named the module `std::sys::env_consts`, because they are used in `std::env::consts` and I intend to use the name `std::sys::env` for the combination of `Args` and `Vars`.

cc `@joboet` `@ChrisDenton`

Tracked in #117276.
2025-04-19 15:09:35 +00:00
Thalia Archibald
670ff84d1c Handle unsupported fallback 2025-04-18 19:49:23 -07:00
Thalia Archibald
37712cc016 Combine env consts into std::sys::env_consts 2025-04-18 19:17:08 -07:00
Thalia Archibald
e0d9244472 Sort Unix env constants alphabetically by target_os
They were roughly grouped into Linux, Apple, BSD, and everything else,
roughly in alphabetical order. Alphabetically order them to make it
easier to maintain and discard the Unix-specific groups to generalize it
to all platforms.
2025-04-18 16:35:26 -07:00
Patrick Mooney
fb3cae08ab std: Use fstatat() on illumos 2025-04-18 14:44:19 -05:00
bors
191df20fca Auto merge of #139996 - matthiaskrgr:rollup-0nka2hw, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138528 (deref patterns: implement implicit deref patterns)
 - #139393 (rustdoc-json: Output target feature information)
 - #139553 (sync::mpsc: prevent double free on `Drop`)
 - #139615 (Remove `name_or_empty`)
 - #139853 (Disable combining LLD with external llvm-config)
 - #139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions))
 - #139942 (Ignore aix for tests/ui/erros/pic-linker.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-18 13:49:17 +00:00
Lieselotte
17b7d63fd7
rtprintpanic: clarify that the error is aborting the process 2025-04-18 15:02:22 +02:00