Commit Graph

14422 Commits

Author SHA1 Message Date
Jiahao XU
05366ee270
Update doc for std::io::Error::downcast 2024-04-15 21:58:36 +10:00
Jiahao XU
4a6b1562b5
Update document for std::io::Error::downcast 2024-04-12 23:03:36 +10:00
bors
6bc9dcd7ec Auto merge of #123490 - niluxv:strict_prov_unwind_seh, r=Amanieu
Refactor `panic_unwind/seh.rs` pointer use

* `x86` now conforms to strict-provenance
* `x86_64` now uses the expose API (instead of `as` casts)
* changed `ptr_t` from a type alias to a `repr(transparent)` struct for some extra type-safety
* replaced the `ptr!` macro by methods on `ptr_t`, as there is now no reason (as far as I can see) anymore to use a macro

On `x86_64` pointers in SEH are represented by 32-bit offsets from `__ImageBase`, so we can't use a pointer type. It might be possible to leak the provenance into the FFI by using a `MaybeUninit<u32>` instead of a `u32`, but that is a bit more involved than using expose, and I'm not sure that would be worth it.
2024-04-12 06:38:26 +00:00
Matthias Krüger
3758e2ffa5
Rollup merge of #123826 - kornelski:one-in-a-quintillion, r=Amanieu
Move rare overflow error to a cold function

`scoped.spawn()` generates unnecessary inlined panic-formatting code for a branch that will never be taken.
2024-04-12 04:38:22 +02:00
bors
46961d2407 Auto merge of #120092 - zetanumbers:pin_in_static_allocator, r=Amanieu
Add `A: 'static` bound for `Arc/Rc::pin_in`

Analogous to https://github.com/rust-lang/rust/pull/79327
Needed to preserve pin's [drop guarantee](https://doc.rust-lang.org/std/pin/index.html#drop-guarantee)
2024-04-12 00:03:43 +00:00
bors
a07f3eb43a Auto merge of #123823 - matthiaskrgr:rollup-8zdtggx, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #122882 (Avoid a panic in `set_output_capture` in the default panic handler)
 - #123523 (Account for trait/impl difference when suggesting changing argument from ref to mut ref)
 - #123744 (Silence `unused_imports` for redundant imports)
 - #123784 (Replace `document.write` with `document.head.insertAdjacent`)
 - #123798 (Avoid invalid socket address in length calculation)
 - #123804 (Stop using `HirId` for fn-like parents since closures are not `OwnerNode`s)
 - #123806 (Panic on overflow in `BorrowedCursor::advance`)
 - #123820 (Add my former address to .mailmap)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-11 21:56:11 +00:00
Kornel
1170d73007 Move rare overflow error to a cold function 2024-04-11 22:23:49 +01:00
Matthias Krüger
d8ae975c02
Rollup merge of #123806 - joboet:advanced_overflow, r=Amanieu
Panic on overflow in `BorrowedCursor::advance`

Passing `usize::MAX` to `advance` clearly isn't correct, but the current assertion fails to detect this when overflow checks are disabled. This isn't unsound, but should probably be fixed regardless.
2024-04-11 22:38:56 +02:00
Matthias Krüger
f361026ebd
Rollup merge of #123798 - tniessen:patch-1, r=workingjubilee
Avoid invalid socket address in length calculation

This has no effect on the lengths of these constants, but since the IP address portion of the socket addresses was intentionally chosen to be the largest valid value, it seems appropriate to also use the largest valid value for the other components (as opposed to invalid values exceeding the possible ranges).
2024-04-11 22:38:55 +02:00
Matthias Krüger
1e99af514b
Rollup merge of #122882 - Zoxc:panic-output-panic, r=Amanieu
Avoid a panic in `set_output_capture` in the default panic handler

This avoid a panic in the default panic handler by not using `set_output_capture` as `OUTPUT_CAPTURE.with` may panic once `OUTPUT_CAPTURE` is dropped.

A new non-panicking `try_set_output_capture` variant of `set_output_capture` is added for use in the default panic handler.
2024-04-11 22:38:53 +02:00
bors
616a8f85f1 Auto merge of #123814 - matthiaskrgr:rollup-lxn0t4t, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #123459 (Correctly handle inlining of doc hidden foreign items)
 - #123740 (Reduce Size of `ModifierInfo`)
 - #123770 (Correct broken link in core::pin doc)
 - #123777 (Deduplicate some function implementations between the parser and AST/HIR)
 - #123808 (codegen tests: Tolerate `nuw` `nsw` on `trunc`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-11 19:52:22 +00:00
niluxv
f63d5d1dcd
Refactor panic_unwind/seh.rs pointer use; x86 now conforms to strict-provenance 2024-04-11 20:47:52 +02:00
bors
aa6a697a1c Auto merge of #123732 - a1phyr:io_error_factor, r=cuviper
Factor some common `io::Error` constants
2024-04-11 17:49:04 +00:00
joboet
91fe6f9343
core: panic on overflow in BorrowedCursor 2024-04-11 18:33:46 +02:00
Tobias Nießen
e1972c0061
Avoid invalid socket address in length calculation 2024-04-11 17:27:23 +02:00
Benoît du Garreau
9c64068ddb Factor some common io::Error constants 2024-04-11 09:55:15 +02:00
Tomoki Nakagawa
68914f2095 Correct broken link in core::pin doc 2024-04-11 15:02:49 +09:00
León Orell Valerian Liehr
b24d2ad300
Rollup merge of #123756 - lukas-code:file-sync, r=jhpratt
clean up docs for `File::sync_*`

* Clarify that `sync_all` also writes data and not just metadata.
* Clarify that dropping a file is not equivalent to calling `sync_all` and ignoring the result. `sync_all` the still the recommended way to detect errors before closing, because we don't have a dedicated method for that.
* Add a link from `sync_all` to `sync_data`, because that's what the user might want to use instead.
* Add doc aliases for `fsync` -> `sync_all` and `fdatasync` -> `sync_data`. Those are the POSIX standard names for these functions. I was trying to find out what we call `fsync` in Rust and had to search through the source code to find it, so this alias should help with that in the future.
2024-04-11 01:56:26 +02:00
León Orell Valerian Liehr
d7d5be0c40
Rollup merge of #123661 - tgross35:stabilize-cstr_count_bytes, r=dtolnay
Stabilize `cstr_count_bytes`

Newly stable API:

```rust
impl CStr {
    pub fn count_bytes(&self) -> usize;
}
```

Const stabilization has not yet been decided, so that will continue to be gated under <https://github.com/rust-lang/rust/issues/113219>.

FCP finished at https://github.com/rust-lang/rust/issues/114441#issuecomment-2016942573.

Fixes: <https://github.com/rust-lang/rust/issues/114441>
2024-04-11 01:56:25 +02:00
León Orell Valerian Liehr
084d27b120
Rollup merge of #123360 - adamgemmell:dev/adagem01/restricted-std, r=ehuss
Document restricted_std

This PR aims to pin down exactly what restricted_std is meant to achieve and what it isn't.

This commit fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/87 by explaining why the error appears and what the choices the user has. The error describes how std cannot function without knowing about some form of OS/platform support. Any features of std that work without an OS should be moved to core/alloc (see https://github.com/rust-lang/rust/issues/27242 https://github.com/rust-lang/rust/issues/103765).

Note that the message says "platform" and "environment" because, since https://github.com/rust-lang/rust/pull/120232, libstd can be built for some JSON targets. This is still unsupported (all JSON targets probably should be unstable https://github.com/rust-lang/wg-cargo-std-aware/issues/90), but a JSON target with the right configuration should hopefully have some partial libstd support.

I propose closing https://github.com/rust-lang/wg-cargo-std-aware/issues/69 as "Won't fix" since any support of std without properly configured os, vendor or env fields is very fragile considering future upgrades of Rust or dependencies. In addition there's no likely path to it being fixed long term (making std buildable for all targets being the only solution). This is distinct from tier 3 platforms with limited std support implemented (and as such aren't restricted_std) because these platforms can conceptually work in the future and std support should mainly improve over time.

The alternative to closing https://github.com/rust-lang/wg-cargo-std-aware/issues/69 is a new crate feature for std which escapes the restricted_std mechanism in build.rs. It could be used with the -Zbuild-std-features flag if we keep it permanently unstable, which I hope we can do anyway. A minor side-effect in this scenario is that std wouldn't be marked as unstable if documentation for it were generated with build-std.

cc ```@ehuss```
2024-04-11 01:56:25 +02:00
León Orell Valerian Liehr
aac3f24054
Rollup merge of #122470 - tgross35:f16-f128-step4-libs-min, r=Amanieu
`f16` and `f128` step 4: basic library support

This is the next step after https://github.com/rust-lang/rust/pull/121926, another portion of https://github.com/rust-lang/rust/pull/114607

Tracking issue: https://github.com/rust-lang/rust/issues/116909

This PR adds the most basic operations to `f16` and `f128` that get lowered as LLVM intrinsics. This is a very small step but it seemed reasonable enough to add unopinionated basic operations before the larger modules that are built on top of them.

r? ```@Amanieu``` since you were pretty involved in the RFC
cc ```@compiler-errors```
```@rustbot``` label +T-libs-api +S-blocked +F-f16_and_f128
2024-04-11 01:56:23 +02:00
Lukas Markeffsky
f0fd5ad5d7 clean up docs for File::sync_* 2024-04-10 23:02:12 +02:00
Trevor Gross
311ad55c32 Add primitive documentation for f16 and f128 2024-04-10 13:50:27 -04:00
Trevor Gross
143ecc3202 Add basic f16 and f128 modules
Create empty modules so `rustdoc` has someplace to link to for these
types.
2024-04-10 13:50:27 -04:00
Trevor Gross
454de78ea3 Add basic library support for f16 and f128
Implement basic operation traits that get lowered to intrinsics. This
includes codegen tests for implemented operations.
2024-04-10 13:50:27 -04:00
Trevor Gross
88bcc79f31 Revert "Put basic impls for f16 and f128 behind cfg(not(bootstrap))"
This reverts commit 049a917535.

The resolution to <https://github.com/rust-lang/rust/issues/123282> is
that the `f16`/`f128` regression in the beta compiler was fixable
without a revert, so the commit adding `#[cfg(not(bootstrap))]` is no
longer useful (added in
<https://github.com/rust-lang/rust/pull/123390>).

Revert this commit because not having these basic impls bootstrap-gated
simplifies everything else that uses them.
2024-04-10 13:50:27 -04:00
bors
5974fe87c4 Auto merge of #123725 - GuillaumeGomez:rollup-gk2bbrg, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #118391 (Add `REDUNDANT_LIFETIMES` lint to detect lifetimes which are semantically redundant)
 - #123534 (Windows: set main thread name without re-encoding)
 - #123659 (Add support to intrinsics fallback body)
 - #123689 (Add const generics support for pattern types)
 - #123701 (Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place)
 - #123702 (Further cleanup cfgs in the UI test suite)
 - #123706 (rustdoc: reduce per-page HTML overhead)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-10 14:28:52 +00:00
Guillaume Gomez
38af5f9ee8
Rollup merge of #123534 - ChrisDenton:name, r=workingjubilee
Windows: set main thread name without re-encoding

As a minor optimization, we can skip the runtime UTF-8 to UTF-16 conversion.
2024-04-10 16:15:23 +02:00
bors
e908cfd125 Auto merge of #122393 - a1phyr:specialize_read_buf_exact, r=joboet
Specialize many implementations of `Read::read_buf_exact`

This makes all implementations of `Read` that have a specialized `read_exact` implementation also have one for `read_buf_exact`.
2024-04-10 11:38:15 +00:00
bors
b14d8b2ef2 Auto merge of #122812 - dtolnay:mode, r=workingjubilee
Show mode_t as octal in std::fs Debug impls

Example:

```rust
fn main() {
    println!("{:?}", std::fs::metadata("Cargo.toml").unwrap().permissions());
}
```

- Before: `Permissions(FilePermissions { mode: 33204 })`

- ~~After: `Permissions(FilePermissions { mode: 0o100664 })`~~

- After: `Permissions(FilePermissions { mode: 0o100664 (-rw-rw-r--) })`

~~I thought about using the format from `ls -l` (`-rw-rw-r--`, `drwxrwxr-x`) but I am not sure how transferable the meaning of the higher bits between different unix systems, and anyway starting the value with a leading negative-sign seems objectionable.~~
2024-04-10 04:47:56 +00:00
Matthias Krüger
a3f10a47d9
Rollup merge of #123633 - bjorn3:unsupported_command_data, r=jhpratt
Store all args in the unsupported Command implementation

This allows printing them in the Debug impl as well as getting them again using the get_args() method. This allows programs that would normally spawn another process to more easily show which program they would have spawned if not for the fact that the target doesn't support spawning child processes without requiring intrusive changes to keep the args. For example rustc compiled to wasi will show the full linker invocation that would have been done.
2024-04-10 04:27:40 +02:00
David Tolnay
caf3766eaf
Show mode_t as octal in std::fs Debug impls 2024-04-09 18:12:41 -07:00
Chris Denton
19f04a7d68
Add comment on UTF-16 surrogates 2024-04-09 20:20:32 +00:00
Chris Denton
952d432666
Windows: set main thread name without reencoding 2024-04-09 20:20:31 +00:00
Chris Denton
b48e7e5496
Add const UTF-8 to UTF-16 conversion macros
`wide_str!` creates a null terminated UTF-16 string whereas `utf16!` just creates a UTF-16 string without adding a null.
2024-04-09 20:20:19 +00:00
bors
8b2459c1f2 Auto merge of #123683 - pietroalbini:pa-cve-2024-24576-nightly, r=pietroalbini
Backport fix of CVE-2024-24576

See https://blog.rust-lang.org/2024/04/09/cve-2024-24576.html

r? `@ghost`
2024-04-09 19:56:18 +00:00
bors
033becf83c Auto merge of #123485 - madsmtm:use-libc-copyfile, r=joboet
macOS: Use `libc` definitions for copyfile

`COPYFILE_ALL` is not yet exposed in `libc`, but the rest of what we need is, so use those definitions instead of manually defining them.

The definitions were added in https://github.com/rust-lang/libc/pull/2667 and https://github.com/rust-lang/libc/pull/3346.
2024-04-09 14:15:09 +00:00
bjorn3
b4a395bcce Fix dead code warning 2024-04-09 13:44:53 +00:00
Guillaume Gomez
4f563a16f2
Rollup merge of #123665 - Jules-Bertholet:patch-1, r=lqd
Fix typo in `Future::poll()` docs

``@rustbot`` label A-docs
2024-04-09 13:39:24 +02:00
Guillaume Gomez
1c5db28ec3
Rollup merge of #123254 - stepancheg:thin-box-0-const-alloc, r=oli-obk
Do not allocate for ZST ThinBox (attempt 2 using const_allocate)

There's PR https://github.com/rust-lang/rust/pull/123184 which avoids allocation for ZST ThinBox.

That PR has an issue with unsoundness with padding in `MaybeUninit` (see comments in that PR). Also that PR relies on `Freeze` trait.

This PR is much simpler implementation which does not have this problem, but it uses `const_allocate` feature.

`@oli-obk` suggested that `const_allocate` should not be used for that feature. But I like how easy it to do this feature with `const_allocate`. Maybe it's OK to use `const_allocate` while `ThinBox` is unstable? Or, well, we can abandon this PR.

r? `@oli-obk`
2024-04-09 13:39:21 +02:00
Jules Bertholet
c9be7b8db6
Fix typo in Future::poll() docs 2024-04-09 01:40:03 -04:00
Trevor Gross
0ef49fe35d Stabilize cstr_count_bytes
Newly stable API:

```rust
impl CStr {
    pub fn count_bytes(&self) -> usize;
}
```

Const stabilization has not yet been decided, so that will continue to be
gated under <https://github.com/rust-lang/rust/issues/113219>.

Fixes: <https://github.com/rust-lang/rust/issues/114441>
2024-04-08 22:38:59 -04:00
Chris Denton
ceedae178e
Document Windows argument splitting 2024-04-09 01:19:33 +02:00
Chris Denton
f66a096607
Disallow or quote all specials in bat args 2024-04-09 01:19:08 +02:00
Matthias Krüger
9570ac4d28
Rollup merge of #123564 - scottmcm:step-by-div-zero, r=joboet
Don't emit divide-by-zero panic paths in `StepBy::len`

I happened to notice today that there's actually two such calls emitted in the assembly: <https://rust.godbolt.org/z/1Wbbd3Ts6>

Since they're impossible, hopefully telling LLVM that will also help optimizations elsewhere.
2024-04-08 22:06:22 +02:00
bors
537aab7a2e Auto merge of #120131 - oli-obk:pattern_types_syntax, r=compiler-errors
Implement minimal, internal-only pattern types in the type system

rebase of https://github.com/rust-lang/rust/pull/107606

You can create pattern types with `std::pat::pattern_type!(ty is pat)`. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via `transmute`.

This PR's implementation differs from the MCP's text. Specifically

> This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.

is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type `std::time::Nanoseconds` struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.

Waiting on:

* [x] move all unrelated commits into their own PRs.
* [x] fix niche computation (see 2db07f94f44f078daffe5823680d07d4fded883f)
* [x] add lots more tests
* [x] T-types MCP https://github.com/rust-lang/types-team/issues/126 to finish
* [x] some commit cleanup
* [x] full self-review
* [x] remove 61bd325da19a918cc3e02bbbdce97281a389c648, it's not necessary anymore I think.
* [ ] ~~make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)~~ we don't even do this for the new float primitives
* [x] get approval that [the scope expansion to trait impls](https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/Pattern.20types.20types-team.23126/near/427670099) is ok

r? `@BoxyUwU`
2024-04-08 16:25:23 +00:00
bjorn3
bbd82ff44e Store all args in the unsupported Command implementation
This allows printing them in the Debug impl as well as getting them
again using the get_args() method. This allows programs that would
normally spawn another process to more easily show which program they
would have spawned if not for the fact that the target doesn't support
spawning child processes without requiring intrusive changes to keep the
args. For example rustc compiled to wasi will show the full linker
invocation that would have been done.
2024-04-08 16:21:07 +00:00
Matthias Krüger
5c3559df63
Rollup merge of #123595 - balaganesh102004:master, r=joboet
Documentation fix

Changed "It must not be an identical residual when interconversion is involved" to "The residual is not mandated to be identical when interconversion is involved." as the previous parenthetical appears to state that the residual is not permitted to be identical when interconversion is involved. However the intention of the original wording was to convey that the residual is not required to be identical when interconversion is involved, which makes more sense contextually.
2024-04-08 14:31:11 +02:00
Matthias Krüger
17c94b5f12
Rollup merge of #123089 - Philippe-Cholet:vecdeque_pop_assume_cap, r=Nilstrieb
Add invariant to VecDeque::pop_* that len < cap if pop successful

Similar to #114370 for VecDeque instead of Vec.

I initially come from https://github.com/rust-itertools/itertools/pull/899 where we noticed that `pop_front;push_back;` was slower than expected so `@scottmcm` suggested I file an issue which lead to https://internals.rust-lang.org/t/vecdeque-pop-front-push-back/20483 where **kornel** mentionned #114334 (fixed by #114370).

This is my first time with codegen tests, I based the test on what was done for Vec.
2024-04-08 14:31:11 +02:00
Matthias Krüger
beaca9ce08
Rollup merge of #115984 - hermit-os:fuse, r=m-ou-se
extending filesystem support for Hermit

Extending `std` to create, change and read a directory for Hermit.

Hermit is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-04-08 14:31:09 +02:00