Commit Graph

12152 Commits

Author SHA1 Message Date
Dylan DPC
6011fd4655
Rollup merge of #115477 - kellerkindt:stabilized_int_impl, r=dtolnay
Stabilize the `Saturating` type

Closes #87920
Closes #92354

Stabilization report https://github.com/rust-lang/rust/issues/87920#issuecomment-1652346124
FCP https://github.com/rust-lang/rust/issues/87920#issuecomment-1676438885
2023-09-17 11:23:24 +00:00
Dylan DPC
584eb696df
Rollup merge of #115434 - soqb:ascii-char-manual-debug, r=dtolnay
make `Debug` impl for `ascii::Char` match that of `char`

# Objective
use a more recognisable format for the `Debug` impl on `ascii::Char` than the derived one based off the enum variants. The alogorithm used is the following:
 - escape `ascii::Char::{Null, CharacterTabulation, CarraigeReturn, LineFeed, ReverseSolidus, Apostrophe}` to `'\0'`, `'\t'`, `'\r'`, `'\n'`, `'\\'` and `'\''` respectively. these are the same escape codes as `<char as Debug>::fmt` uses.
 - if `u8::is_ascii_control` is false, print the character wrapped in single quotes.
 - otherwise, print in the format `'\xAB'` where `A` and `B` are the hex nibbles of the byte. (`char` uses unicode escapes and this seems like the corresponding ascii format).

Tracking issue: https://github.com/rust-lang/rust/issues/110998
2023-09-17 11:23:24 +00:00
Dylan DPC
7cbe7fa6bf
Rollup merge of #114965 - benschulz:mpsc-drop, r=dtolnay
Remove Drop impl of mpsc Receiver and (Sync)Sender

This change removes the empty `Drop` implementations for `mpsc::Receiver`, `mpsc::Sender` and `mpsc::SyncSender`. These implementations do not specify `#[may_dangle]`, so by removing them we make `mpsc` types play nice with drop check.

This was previously attempted in [#105243](https://github.com/rust-lang/rust/pull/105243#issuecomment-1337188646) but then [abandoned due to a test failure](https://github.com/rust-lang/rust/pull/105243#issuecomment-1337227970). I've aligned the test with those for `Mutex` and `RwLock`.
2023-09-17 11:23:23 +00:00
bors
3ecc563628 Auto merge of #113748 - clarfonthey:ip-step, r=dtolnay
impl Step for IP addresses

ACP: rust-lang/libs-team#235

Note: since this is insta-stable, it requires an FCP.

Separating out from the bit operations PR since it feels logically disjoint, and so their FCPs can be separate.
2023-09-17 06:27:09 +00:00
bors
a09c1f85f1 Auto merge of #115782 - a1phyr:improve_pad_adapter, r=dtolnay
Improve `PadAdapter::write_char`

Split from #108043
2023-09-17 01:47:49 +00:00
bors
d7229c479c Auto merge of #113753 - dvdsk:master, r=dtolnay
Add implementation for thread::sleep_until

- Feature gate is `thread::sleep_until`
- Tracking issue is: #113752
- APC: https://github.com/rust-lang/libs-team/issues/237
2023-09-17 00:02:45 +00:00
Matthias Krüger
e2ea347517
Rollup merge of #115895 - 52:patch-docs-vec-truncate, r=dtolnay
Improve Vec(Deque)::truncate documentation

Fixes #115784
2023-09-16 23:20:43 +02:00
Matthias Krüger
633f143921
Rollup merge of #115560 - ShE3py:format-results, r=dtolnay
Update doc for `alloc::format!` and `core::concat!`

Closes #115551.

Used comments instead of `assert!`s as [`std::fmt`](https://doc.rust-lang.org/std/fmt/index.html#usage) uses comments.

Should all the str-related macros (`format!`, `format_args!`, `concat!`, `stringify!`, `println!`, `writeln!`, etc.) references each others? For instance, [`concat!`](https://doc.rust-lang.org/core/macro.concat.html) mentions that integers are stringified, but don't link to `stringify!`.

`@rustbot` label +A-docs +A-fmt
2023-09-16 23:20:41 +02:00
Matthias Krüger
b8c4b78a79
Rollup merge of #115487 - ModProg:patch-1, r=dtolnay
Improve documentation on when signes are printed by default

I found the original formulation a bit irritating, but not sure if I really improved it.
2023-09-16 23:20:40 +02:00
Matthias Krüger
edfe8b4434
Rollup merge of #115329 - xzmeng:fix-std-doc, r=dtolnay
fix std::primitive doc: homogenous -> homogeneous

replace "homogenous" with the more commonly used "homogeneous".
2023-09-16 23:20:39 +02:00
Matthias Krüger
cf9ce96a5b
Rollup merge of #115247 - the8472:life-before-main, r=dtolnay
Document std limitations before/after main

Solves #110708
2023-09-16 23:20:39 +02:00
bors
4514fb98d5 Auto merge of #112229 - clarfonthey:range-iter-count, r=dtolnay
Specialize count for range iterators

Since `size_hint` is already specialized, it feels apt to specialize `count` as well. Without any specialized version of `ExactSizeIterator::len` or `Step::steps_between`, this feels like a more reliable way of accessing this without having to rely on knowing that `size_hint` is correct.

In my case, this is particularly useful to access the `steps_between` implementation for `char` from the standard library without having to compute it manually.

I didn't think it was worth modifying the `Step` trait to add a version of `steps_between` that used native overflow checks since this is just doing one subtraction in most cases anyway, and so I decided to make the inclusive version use `checked_add` so it didn't have this lopsided overflow-checks-but-only-sometimes logic.
2023-09-16 16:43:31 +00:00
mxnkarou
1c7a77a638
edit std::collections::VecDeque docs 2023-09-16 15:52:34 +02:00
mxnkarou
d1ff5e174b
edit std::vec::Vec::truncate docs 2023-09-16 15:46:31 +02:00
Matthias Krüger
c2f228f654
Rollup merge of #115607 - RalfJung:safe-traits-unsafe-code, r=dtolnay
clarify that unsafe code must not rely on our safe traits

This adds a disclaimer to PartialEq, Eq, PartialOrd, Ord, Hash, Deref, DerefMut.

We already have a similar disclaimer in ExactSizeIterator (worded a bit differently):
```
/// Note that this trait is a safe trait and as such does *not* and *cannot*
/// guarantee that the returned length is correct. This means that `unsafe`
/// code **must not** rely on the correctness of [`Iterator::size_hint`]. The
/// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives
/// this additional guarantee.
```
If there are any other traits that should carry such a disclaimer, please let me know.

Fixes https://github.com/rust-lang/rust/issues/73682
2023-09-16 11:48:18 +02:00
ltdk
08aa6c9b65 Specialize count for range iterators 2023-09-16 01:33:56 -04:00
ltdk
8184c9c50d impl Step for IP addresses 2023-09-16 01:28:13 -04:00
bors
635c4a5e61 Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726
Make useless_ptr_null_checks smarter about some std functions

This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc.

This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`).

Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null.

Follow-up of PR #113657

Fixes #114442
2023-09-16 03:40:20 +00:00
bors
e81f85fe9e Auto merge of #115520 - Finomnis:const_transmute_copy, r=dtolnay
Stabilize const_transmute_copy

Closes #83165
2023-09-16 01:51:55 +00:00
bors
c728bf3963 Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obk
Rework `no_coverage` to `coverage(off)`

As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation.

Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-14 01:05:18 +00:00
Nikolay Arhipov
41ee874fa9 Disabled socketpair for Vita 2023-09-13 16:41:38 +03:00
Benoît du Garreau
814f4f6f52 Improve PadAdapter::write_char 2023-09-12 15:57:36 +02:00
bors
9d311f9e2d Auto merge of #114967 - japaric:ja-gh114966, r=Mark-Simulacrum
QNX: pass a truncated thread name to the OS

The maximum length the thread name can have is `_NTO_THREAD_NAME_MAX`

fixes #114966
2023-09-10 23:55:38 +00:00
bors
559421e8e3 Auto merge of #114590 - ijackson:stdio-stdio-2, r=dtolnay
Allow redirecting subprocess stdout to our stderr etc. (redux)

This is the code from #88561, tidied up, including review suggestions, and with the for-testing-only CI commit removed.  FCP for the API completed in #88561.

I have made a new MR to facilitate review.  The discussion there is very cluttered and the branch is full of changes (in many cases as a result of changes to other Rust stdlib APIs since then).  Assuming this MR is approvedl we should close that one.

### Reviewer doing a de novo review

Just code review these four commits..  FCP discussion starts here: https://github.com/rust-lang/rust/pull/88561#issuecomment-1640527595

Portability tests: you can see that this branch works on Windows too by looking at the CI results in #88561, which has the same code changes as this branch but with an additional "DO NOT MERGE" commit to make the Windows tests run.

### Reviewer doing an incremental review from some version of #88561

Review the new commits since your last review.  I haven't force pushed the branch there.

git diff the two branches (eg `git diff 176886197d6..0842b69c219`).  You'll see that the only difference is in gitlab CI files.  You can also see that *this* MR doesn't touch those files.
2023-09-09 19:56:51 +00:00
Ian Jackson
436fe01895
std::process (unsupported): Implement From<io::Stdout> etc. for imp::Stdio
This implementation is wrong.  Like the impl for From<File>, it is
forced to panic because process::Stdio in unsupported/process.rs
doesn't have a suitable variant.

The root cause of the problem is that process::Stdio in
unsupported/process.rs has any information in it at all.

I'm pretty sure that it should just be a unit struct.  However,
making that build on all platforms is going to be a lot of work,
iterating through CI and/or wrestling Docker.

I don't think this extra panic is making things significantly worse.
For now I have added some TODOs.
2023-09-09 11:24:53 +01:00
Guillaume Gomez
1fb672c738
Rollup merge of #115201 - notriddle:notriddle/type-alias-impl-list, r=GuillaumeGomez
rustdoc: list matching impls on type aliases

Fixes https://github.com/rust-lang/rust/issues/32077

Fixes #99952

Remake of https://github.com/rust-lang/rust/pull/112429

Partially reverts https://github.com/rust-lang/rust/pull/112543, but keeps the test case.

This version of the PR avoids the infinite loop by structurally matching types instead of using full unification. This version does not support type alias trait bounds, but the compiler does not enforce those anyway (https://github.com/rust-lang/rust/issues/21903).

r? `@GuillaumeGomez`

CC `@lcnr`
2023-09-08 14:10:51 +02:00
Guillaume Gomez
2cceedd0ef
Rollup merge of #104299 - mkrasnitski:discriminant-transmute-docs, r=oli-obk
Clarify stability guarantee for lifetimes in enum discriminants

Since `std::mem::Discriminant` erases lifetimes, it should be clarified that changing the concrete value of a lifetime parameter does not change the value of an enum discriminant for a given variant. This is useful as it guarantees that it is safe to transmute `Discriminant<Foo<'a>>` to `Discriminant<Foo<'b>>` for any combination of `'a` and `'b`. This also holds for type-generics as long as the type parameters do not change, e.g. `Discriminant<Foo<T, 'a>>` can be transmuted to `Discriminant<Foo<T, 'b>>`.

Side note: Is what I've written actually enough to imply soundness (or rather codify it), or should it specifically be spelled out that it's OK to transmute in the above way?
2023-09-08 14:10:49 +02:00
Andy Caldwell
679267f2ac
Rename the feature, but not the attribute, to coverage_attribute 2023-09-08 12:46:09 +01:00
Andy Caldwell
8e03371fc3
Rework no_coverage to coverage(off) 2023-09-08 12:46:06 +01:00
bors
feb06732c0 Auto merge of #114299 - clarfonthey:char-min, r=dtolnay,BurntSushi
Add char::MIN

ACP: rust-lang/libs-team#252
Tracking issue: #114298

r? `@rust-lang/libs-api`
2023-09-08 00:02:48 +00:00
bors
4e5b31c2b0 Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, r=est31
Lint on invalid usage of `UnsafeCell::raw_get` in reference casting

This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint.

The goal of this is to catch those kind of invalid reference casting:
```rust
fn as_mut<T>(x: &T) -> &mut T {
    unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
    //~^ ERROR casting `&T` to `&mut T` is undefined behavior
}
```

r? `@est31`
2023-09-07 00:24:45 +00:00
bors
b0d45536ac Auto merge of #115580 - eduardosm:stdarch-intrinsics, r=davidtwco,bjorn3
Update stdarch submodule and remove special handling in cranelift codegen for some AVX and SSE2 LLVM intrinsics

https://github.com/rust-lang/stdarch/pull/1463 reimplemented some x86 intrinsics to avoid using some x86-specific LLVM intrinsics:

* Store unaligned (`_mm*_storeu_*`) use `<*mut _>::write_unaligned` instead of `llvm.x86.*.storeu.*`.
* Shift by immediate (`_mm*_s{ll,rl,ra}i_epi*`) use `if` (srl, sll) or `min` (sra) to simulate the behaviour when the RHS is out of range. RHS is constant, so the `if`/`min` will be optimized away.

This PR updates the stdarch submodule to pull these changes and removes special handling for those LLVM intrinsics from cranelift codegen. I left gcc codegen untouched because there are some autogenerated lists.
2023-09-06 22:26:37 +00:00
Darius Wiles
408dca7241
Fix minor grammar typo 2023-09-06 09:47:22 -07:00
Ralf Jung
62111145b7 clarify that unsafe code must not rely on our safe traits 2023-09-06 16:12:39 +02:00
ShE3py
94e651b9b2
Update doc for alloc::format! and core::concat! 2023-09-06 15:11:21 +02:00
bors
24bece8420 Auto merge of #115453 - ibraheemdev:patch-16, r=joshtriplett
Stabilize `io_error_other` feature

Per the FCP for https://github.com/rust-lang/rust/issues/91946.
2023-09-06 08:00:25 +00:00
Matthias Krüger
14c57f1adb
Rollup merge of #114794 - RalfJung:swap-safety, r=m-ou-se
clarify safety documentation of ptr::swap and ptr::copy

Closes https://github.com/rust-lang/rust/issues/81005
2023-09-05 20:15:01 +02:00
Eduardo Sánchez Muñoz
537edd0be4 Bump stdarch submodule 2023-09-05 19:56:20 +02:00
Ralf Jung
4684ffaf2a
if -> when 2023-09-05 17:20:31 +02:00
Matthias Krüger
9381e5bf58
Rollup merge of #115540 - cjgillot:custom-debuginfo, r=oli-obk
Support debuginfo for custom MIR.
2023-09-05 15:16:51 +02:00
Matthias Krüger
781253bc32
Rollup merge of #114813 - RalfJung:fpu-control, r=Amanieu
explain why we can mutate the FPU control word

This is usually not allowed (see https://github.com/rust-lang/stdarch/pull/1454), but here we have a special case.
2023-09-05 15:16:48 +02:00
Matthias Krüger
cbab5adf8a
Rollup merge of #114412 - RalfJung:libc-symbols, r=pnkfelix
document our assumptions about symbols provided by the libc

LLVM makes assumptions about `memcmp`, `memmove`, and `memset` that go beyond what the C standard guarantees -- see https://reviews.llvm.org/D86993. Since we use LLVM, we are inheriting these assumptions.

With https://github.com/rust-lang/rust/pull/114382 we are also making a similar assumption about `memcmp`, so I added that to the list.

Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/426.
2023-09-05 15:16:47 +02:00
Matthias Krüger
a23f216136
Rollup merge of #113510 - ink-feather-org:const_ptr_transmute_docs, r=RalfJung
Document soundness of Integer -> Pointer -> Integer conversions in `const` contexts.

see this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Soundness.20of.20Integer.20-.3E.20Pointer.20-.3E.20Integer.20conversions)

r? `@RalfJung`

With this slice `Iterator`'s should be able to be made const once the const Trait reimplementation is done.
2023-09-05 15:16:47 +02:00
bors
ce798a52c3 Auto merge of #115493 - Ayush1325:raw-os-error, r=workingjubilee
Move RawOsError defination to sys

This was originally a part of https://github.com/rust-lang/rust/pull/105861, but I feel it should be its own PR since the raw os error is still unstable.
2023-09-04 08:04:00 +00:00
bors
abfc6c4438 Auto merge of #115491 - Zoxc:refcell-tweak, r=Mark-Simulacrum
Outline panicking code for `RefCell::borrow` and `RefCell::borrow_mut`

This outlines panicking code for `RefCell::borrow` and `RefCell::borrow_mut` to reduce code size.
2023-09-03 23:03:03 +00:00
Finomnis
0bb54814e1 Stabilize const_transmute_copy 2023-09-03 23:20:31 +02:00
Matthias Krüger
487fe2e5ad
Rollup merge of #115512 - Fulgen301:startupinfow, r=ChrisDenton
Command::spawn: Fix STARTUPINFOW.cb being initialized with the address of size_of

Fixes #115511.
2023-09-03 21:38:43 +02:00
Matthias Krüger
33e2e71502
Rollup merge of #115489 - saethlin:is-interrupted, r=thomcc
Use std::io::Error::is_interrupted everywhere

In https://github.com/rust-lang/rust/pull/115228 I introduced this helper and started using it, this PR uses it to replace all applicable uses of `std::io::Error::kind`. The justification is the same; for whatever reason LLVM totally flops optimizing `Error::kind` so it's nice to use it less.

FYI ``@mkroening`` I swear the hermit changes look good, but I was so sure about the previous PR.
2023-09-03 21:38:43 +02:00
Matthias Krüger
50aea927f5
Rollup merge of #115279 - schuelermine:patch/doc/RangeFull/remote-parens, r=Mark-Simulacrum
RangeFull: Remove parens around .. in documentation snippet

I’ve removed unnecessary parentheses in a documentation snippet documenting `RangeFull`. It could’ve lead people to believe the parentheses were necessary.
2023-09-03 21:38:41 +02:00
Fulgen301
a8b0e44e86
Command::spawn: Fix STARTUPINFOW.cb being initialized with the address of size_of 2023-09-03 17:04:42 +02:00