Commit Graph

11760 Commits

Author SHA1 Message Date
Matthias Krüger
8630b1b3f4
Rollup merge of #112950 - tshepang:patch-4, r=Mark-Simulacrum
DirEntry::file_name: improve explanation
2023-06-25 02:04:20 +02:00
Chris Denton
e2eff0d4ab
Remove unnecessary path attribute 2023-06-24 19:56:29 +01:00
Chris Denton
8a7399cd45
Move arm32 shim to c.rs 2023-06-24 17:30:27 +01:00
Michael Goulet
ee8b035fab
Rollup merge of #112763 - Patryk27:bump-compiler-builtins, r=Amanieu
Bump compiler_builtins

Actually closes https://github.com/rust-lang/rust/issues/108489.

Note that the example code given [in compiler_builtins](https://github.com/rust-lang/compiler-builtins/pull/527) doesn't compile on current rustc since we're still waiting for https://reviews.llvm.org/D153197 (aka `LLVM ERROR: Expected a constant shift amount!`), but it's a step forward anyway.
2023-06-23 19:47:20 -07:00
Michael Goulet
4a01a38466
Rollup merge of #111087 - ibraheemdev:patch-15, r=dtolnay
Implement `Sync` for `mpsc::Sender`

`mpsc::Sender` is currently `!Sync` because the previous implementation contained an optimization where the channel started out as single-producer and was dynamically upgraded on the first clone, which relied on a unique reference to the sender. This optimization is one of the main reasons the old implementation was so complex and was removed in #93563. `mpsc::Sender` can now soundly implement `Sync`.

Note for any potential confusion, this chance does *not* add MPMC behavior. This only affects the already `Send + Clone` *sender*, not *receiver*.

It's technically possible to rely on the `!Sync` behavior in the same way as a `PhantomData<*mut T>`, but that seems very unlikely in practice. Either way, this change is insta-stable and needs an FCP.

`@rustbot` label +T-libs-api -T-libs
2023-06-23 19:47:19 -07:00
Tobias Bucher
11fecf619a Add Read, Write and Seek impls for Arc<File> where appropriate
If `&T` implements these traits, `Arc<T>` has no reason not to do so
either. This is useful for operating system handles like `File` or
`TcpStream` which don't need a mutable reference to implement these
traits.

CC #53835.
CC #94744.
2023-06-23 14:55:43 +02:00
Tobias Bucher
9fc2da1b54 Forward io::{Read,Seek,Write} impls of File to &File
This reduces code duplication.
2023-06-23 14:54:24 +02:00
Matthias Krüger
8168915639
Rollup merge of #112704 - RalfJung:dont-wrap-slices, r=ChrisDenton
slice::from_raw_parts: mention no-wrap-around condition

Cc https://github.com/rust-lang/rust/issues/83996. This probably needs to be mentioned in more places, so I am not closing that issue, but this here should help at least.
2023-06-23 13:18:13 +02:00
Amanieu d'Antras
4a9f292e50 Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std
This was added in rust-lang/compiler-builtins#526 to force all
compiler-builtins intrinsics to use weak linkage.
2023-06-23 11:15:34 +01:00
Tshepang Mbambo
6f61f6ba11
DirEntry::file_name: improve explanation 2023-06-23 04:47:30 +02:00
The 8472
1bc095cd80 add inline annotation to concrete impls
otherwise they wouldn't be eligible for cross-crate inlining
2023-06-23 00:17:34 +02:00
The 8472
070ce235f2 Specialize StepBy<Range<{integer}>>
For ranges < usize we determine the number of items
StepBy would yield and then store that in the range.end
instead of the actual end. This significantly
simplifies calculation of the loop induction variable
especially in cases where StepBy::step (an usize)
could overflow the Range's item type
2023-06-23 00:17:34 +02:00
Thom Chiovoloni
5ef4d1fb2e
Actually save all the files 2023-06-21 14:59:40 -07:00
Thom Chiovoloni
37854aab76
Update tvOS support elsewhere in the stdlib 2023-06-21 14:59:40 -07:00
Thom Chiovoloni
49da0acb71
Avoid fork/exec spawning on tvOS/watchOS, as those functions are marked as prohibited 2023-06-21 14:59:40 -07:00
Thom Chiovoloni
f978d7ea42
Finish up preliminary tvos support in libstd 2023-06-21 14:59:39 -07:00
Thom Chiovoloni
bdc3db944c
wip: Support Apple tvOS in libstd 2023-06-21 14:59:37 -07:00
bors
006a26c0b5 Auto merge of #111684 - ChayimFriedman2:unused-offset-of, r=WaffleLapkin
Warn on unused `offset_of!()` result

The usage of `core::hint::must_use()` means that we don't get a specialized message. I figured out that since there are plenty of other methods that just have `#[must_use]` with no message it'll be fine, but it is a bit unfortunate that the error mentions `must_use` and not `offset_of!`.

Fixes #111669.
2023-06-21 16:40:54 +00:00
Guillaume Gomez
38916c71cb
Rollup merge of #112863 - clubby789:stderr-typo, r=albertlarsan68
Fix copy-paste typo in `eprint(ln)` docs

Fixes #112862
2023-06-21 15:45:17 +02:00
Guillaume Gomez
476798d4fd
Rollup merge of #99587 - ibraheemdev:park-orderings, r=m-ou-se
Document memory orderings of `thread::{park, unpark}`

Document `thread::park/unpark` as having acquire/release synchronization. Without that guarantee, even the example in the documentation can deadlock:

```rust
let flag = Arc::new(AtomicBool::new(false));

let t2 = thread::spawn(move || {
    while !flag.load(Ordering::Acquire) {
        thread::park();
    }
});

flag.store(true, Ordering::Release);
t2.thread().unpark();

// t1: flag.store(true)
// t1: thread.unpark()
// t2: flag.load() == false

// t2 now parks, is immediately unblocked but never
// acquires the flag, and thus spins forever
```

Multiple calls to `unpark` should also maintain a release sequence to make sure operations released by previous `unpark`s are not lost:

```rust
let a = Arc::new(AtomicBool::new(false));
let b = Arc::new(AtomicBool::new(false));

let t2 = thread::spawn(move || {
    while !a.load(Ordering::Acquire) || !b.load(Ordering::Acquire) {
        thread::park();
    }
});

thread::spawn(move || {
    a.store(true, Ordering::Release);
    t2.thread().unpark();
});

b.store(true, Ordering::Release);
t2.thread().unpark();

// t1: a.store(true)
// t1: t2.unpark()
// t3: b.store(true)
// t3: t2.unpark()

// t2 now parks, is immediately unblocked but never
// acquires the store of `a`, only the store of `b` which
// was released by the most recent unpark, and thus spins forever
```

This is of course a contrived example, but is reasonable to rely upon in real code.

Note that all implementations of park/unpark already comply with the rules, it's just undocumented.
2023-06-21 15:45:15 +02:00
Mara Bos
3acb1d2b9b
"Memory Orderings" -> "Memory Ordering"
Co-authored-by: yvt <i@yvt.jp>
2023-06-21 12:43:22 +02:00
Chayim Refael Friedman
592844cf88 Warn on unused offset_of!() result 2023-06-21 11:43:14 +03:00
bors
97bf23d26b Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstrieb
Rollup of 6 pull requests

Successful merges:

 - #112632 (Implement PartialOrd for `Vec`s over different allocators)
 - #112759 (Make closure_saved_names_of_captured_variables a query. )
 - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`)
 - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment))
 - #112830 (More codegen cleanups)
 - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-21 08:00:23 +00:00
Nilstrieb
78a90cb4ee
Rollup merge of #112632 - gootorov:vec_alloc_partialeq, r=dtolnay
Implement PartialOrd for `Vec`s over different allocators

It is already possible to `PartialEq` `Vec`s with different allocators, but that is not the case with `PartialOrd`.
2023-06-21 07:37:00 +02:00
bors
67da586efe Auto merge of #106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieu
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata

FCP completed in https://github.com/rust-lang/rust/issues/103763#issuecomment-1362267967

Closes #103763
2023-06-21 05:13:39 +00:00
clubby789
7201271fe8 Fix typo in eprintln docs 2023-06-21 01:08:10 +01:00
Ibraheem Ahmed
bf27f12d94 relaxed orderings in thread::park example 2023-06-20 20:05:31 -04:00
Jacob Pratt
abd0677d2f
Merge proc_macro_span_shrink and proc_macro_span 2023-06-20 19:40:26 -04:00
Jacob Pratt
a1cd8c3a28
Add Span::{line, column} 2023-06-20 19:40:25 -04:00
Jacob Pratt
87ec0738ab
Span::{before, after}Span::{start, end} 2023-06-20 19:40:25 -04:00
Jacob Pratt
dc76991d2f
Remove LineColumn, Span::start, Span::end 2023-06-20 19:40:24 -04:00
Guillaume Gomez
816b659157
Rollup merge of #112464 - eval-exec:exec/fix-connect_timeout-overflow, r=ChrisDenton
Fix windows `Socket::connect_timeout` overflow

This PR want to close #112405

- [x] add unit test
2023-06-20 14:23:39 +02:00
Eval EXEC
a0c757a13f
Remove useless unit tests 2023-06-20 18:47:31 +08:00
Eval EXEC
30e1c1a53c
Ignore connect_timeout unit test on SGX platform
Co-authored-by: Chris Denton <christophersdenton@gmail.com>
2023-06-20 18:43:12 +08:00
bors
6fc0273b5a Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnr
Add `implement_via_object` to `rustc_deny_explicit_impl` to control object candidate assembly

Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the `Unsize` trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually *instruct* the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code.

Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of `dyn Unsize<T>` does not mean that the compiler is able to unsize `Box<dyn Unsize<T>>` into `Box<T>`, since `Unsize` is a *witness* to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above.

The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits:
2f896da247/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs (L61-L132)

However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about: `rustc_deny_explicit_impl`. This PR adds `implement_via_object` as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well.

r? `@lcnr`
2023-06-20 08:42:37 +00:00
Michael Goulet
ca68cf0d46 Merge attrs, better validation 2023-06-20 04:38:55 +00:00
Michael Goulet
657d3f43a9 Add rustc_do_not_implement_via_object 2023-06-20 04:38:46 +00:00
bors
d7dcadc597 Auto merge of #112817 - compiler-errors:rollup-0eqomra, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #112232 (Better error for non const `PartialEq` call generated by `match`)
 - #112499 (Fix python linting errors)
 - #112596 (Suggest correct signature on missing fn returning RPITIT/AFIT)
 - #112606 (Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses)
 - #112781 (Don't consider TAIT normalizable to hidden ty if it would result in impossible item bounds)
 - #112787 (Add gha problem matcher)
 - #112799 (Clean up "doc(hidden)" check)
 - #112803 (Format the examples directory of cg_clif)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-20 02:58:53 +00:00
Michael Goulet
e24fe97bd9
Rollup merge of #112606 - clarfonthey:ip-display, r=thomcc
Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses

ACP: rust-lang/libs-team#239
2023-06-19 17:53:35 -07:00
Michael Goulet
935452b619
Rollup merge of #112499 - tgross35:py-ruff-fixes, r=Mark-Simulacrum
Fix python linting errors

These were flagged by `ruff`, run using the config in https://github.com/rust-lang/rust/pull/112482
2023-06-19 17:53:34 -07:00
bors
14803bda0e Auto merge of #111849 - eholk:uniquearc, r=Mark-Simulacrum
Add `alloc::rc::UniqueRc`

This PR implements `UniqueRc` as described in https://github.com/rust-lang/libs-team/issues/90.

I've tried to stick to the API proposed there, incorporating the feedback from the ACP review. For now I've just implemented `UniqueRc`, but we'll want `UniqueArc` as well. I wanted to get feedback on this implementation first since the `UniqueArc` version should be mostly a copy/paste/rename job.
2023-06-20 00:11:57 +00:00
Eric Holk
53003cdd86
Introduce alloc::::UniqueRc
This is an `Rc` that is guaranteed to only have one strong reference.
Because it is uniquely owned, it can safely implement `DerefMut`, which
allows programs to have an initialization phase where structures inside
the `Rc` can be mutated.

The `UniqueRc` can then be converted to a regular `Rc`, allowing sharing
and but read-only access.

During the "initialization phase," weak references can be created, but
attempting to upgrade these will fail until the `UniqueRc` has been
converted to a regular `Rc`. This feature can be useful to create
cyclic data structures.

This API is an implementation based on the feedback provided to the ACP
at https://github.com/rust-lang/libs-team/issues/90.
2023-06-19 12:24:06 -07:00
Matthias Krüger
7d072fa8fb
Rollup merge of #112757 - Danvil:patch-1, r=Mark-Simulacrum
Use BorrowFlag instead of explicit isize

The integer type tracking borrow count has a typedef called `BorrowFlag`. This type should be used instead of explicit `isize`.
2023-06-19 19:26:26 +02:00
Matthias Krüger
663fb5a0e9
Rollup merge of #109970 - danielhenrymantilla:add-poll-fn-pin-clarifications, r=thomcc
[doc] `poll_fn`: explain how to `pin` captured state safely

Usage of `Pin::new_unchecked(&mut …)` is dangerous with `poll_fn`, even though the `!Unpin`-infectiousness has made things smoother. Nonetheless, there are easy ways to avoid the need for any `unsafe` altogether, be it through `Box::pin`ning, or the `pin!` macro. Since the latter only works within an `async` context, showing an example artificially introducing one ought to help people navigate this subtlety with safety and confidence.

## Preview

https://user-images.githubusercontent.com/9920355/230092494-da22fdcb-0b8f-4ff4-a2ac-aa7d9ead077a.mov

```@rustbot``` label +A-docs
2023-06-19 19:26:25 +02:00
Vas
748e2c6df9 Document thread names for SGX compilation target 2023-06-19 10:25:25 +02:00
bors
8d1fa473dd Auto merge of #112724 - scottmcm:simpler-unchecked-shifts, r=Mark-Simulacrum
[libs] Simplify `unchecked_{shl,shr}`

There's no need for the `const_eval_select` dance here.  And while I originally wrote the `.try_into().unwrap_unchecked()` implementation here, it's kinda a mess in MIR -- this new one is substantially simpler, as shown by the old one being above the inlining threshold but the new one being below it in the `mir-opt/inline/unchecked_shifts` tests.

We don't need `u32::checked_shl` doing a dance through both `Result` *and* `Option` 🙃
2023-06-19 04:48:35 +00:00
Patryk Wychowaniec
70ce2139e8
Bump compiler_builtins 2023-06-18 13:29:36 +02:00
Daniel Henry-Mantilla
94f7a7931c [doc] poll_fn: explain how to pin captured state safely
Usage of `Pin::new_unchecked(&mut …)` is dangerous with `poll_fn`, even
though the `!Unpin`-infectiousness has made things smoother.
Nonetheless, there are easy ways to avoid the need for any `unsafe`
altogether, be it through `Box::pin`ning, or the `pin!` macro. Since the
latter only works within an `async` context, showing an example
artifically introducing one ought to help people navigate this subtlety
with safety and confidence.
2023-06-18 09:56:13 +00:00
David Weikersdorfer
09707ee12a
Same for BorrowRef 2023-06-18 01:14:45 -07:00
Eval EXEC
f65b5d0ddf
Add unit test to connect to an unreachable address
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-18 15:59:25 +08:00
David Weikersdorfer
c4c428b6da
Use BorrowFlag instead of explicit isize
The integer type tracking borrow count has a typedef called `BorrowFlag`. This type should be used instead of explicit `isize`.
2023-06-18 00:46:51 -07:00
Matthias Krüger
eb40590579
Rollup merge of #112685 - cuviper:wasm-dlmalloc, r=Mark-Simulacrum
std: only depend on dlmalloc for wasm*-unknown

It was already filtered out for emscripten, but wasi doesn't need dlmalloc
either since it reuses `unix/alloc.rs`.
2023-06-18 08:06:42 +02:00
Matthias Krüger
876f00a655
Rollup merge of #107200 - mina86:c, r=Amanieu
io: soften ‘at most one write attempt’ requirement in io::Write::write

At the moment, documentation of std::io::Write::write indicates that
call to it ‘represents at most one attempt to write to any wrapped
object’.  It seems that such wording was put there to contrast it with
pre-1.0 interface which attempted to write all the data (it has since
been changed in [RFC 517]).

However, the requirement puts unnecessary constraints and may
complicate adaptors which perform non-trivial transformations on the
data.  For example, they may maintain an internal buffer which needs
to be written out before the write method accepts more data.  It might
be natural to code the method such that it flushes the buffer and then
grabs another chunk of user data.  With the current wording in the
documentation, the adaptor would be forced to return Ok(0).

This commit softens the wording such that implementations can choose
code structure which makes most sense for their particular use case.

While at it, elaborate on the meaning of `Ok(0)` return pointing out
that the write_all methods interprets it as an error.

[RFC 517]: https://rust-lang.github.io/rfcs/0517-io-os-reform.html
2023-06-18 08:06:41 +02:00
Igor Gutorov
001b081cc1 alloc: Allow comparing Boxs over different allocators 2023-06-18 06:19:35 +03:00
Igor Gutorov
ed82c055c6 alloc: Implement PartialOrd for Vecs over different allocators 2023-06-18 06:09:09 +03:00
bors
0c2c243342 Auto merge of #112599 - saethlin:cleaner-panics, r=thomcc
Launch a non-unwinding panic for misaligned pointer deref

This panic already never unwinds, but that's only because it always hits the unwind guard that's created by our `UnwindAction::Terminate`. Hitting the unwind guard generates a huge double-panic backtrace. Now we generate a normal-looking panic message when this check is hit.

r? `@thomcc`
2023-06-18 01:58:51 +00:00
bors
ed7281e784 Auto merge of #112595 - hargoniX:l4re_fix, r=Mark-Simulacrum
fix: get the l4re target working again

This is based on work from https://github.com/rust-lang/rust/pull/103966, addressing the review comment by `@m-ou-se` at the time and "fixing" the (probably newly) missing read_buf.
2023-06-17 21:59:08 +00:00
bors
3b2073f076 Auto merge of #112746 - matthiaskrgr:rollup-se59bfd, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #110805 (Github action to periodically `cargo update` to keep dependencies current)
 - #112435 (Allow overwriting the sysroot compile flag via --rustc-args)
 - #112610 (Bump stdarch)
 - #112619 (Suggest bumping download-ci-llvm-stamp if the build config for llvm changes)
 - #112738 (make ice msg "Unknown runtime phase" a bit nicer)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-17 19:16:11 +00:00
Eval EXEC
fca9e6e706
Add unit test for TcpStream::connect_timeout
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-18 01:56:11 +08:00
Eval EXEC
22f62df337
Fix windows Socket::connect_timeout overflow
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-18 01:56:11 +08:00
Matthias Krüger
703b728ce2
Rollup merge of #112610 - scottmcm:update-stdarch, r=Amanieu
Bump stdarch

In particular to pick up the stabilization of the AVX512 types (but not intrinsics) that was FCPed in https://github.com/rust-lang/stdarch/pull/1436.
2023-06-17 18:27:31 +02:00
bors
a8a29070f0 Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obk
Remove `box_free` lang item

This PR removes the `box_free` lang item, replacing it with `Box`'s `Drop` impl. Box dropping is still slightly magic because the contained value is still dropped by the compiler.
2023-06-17 16:10:57 +00:00
bors
e1c29d137d Auto merge of #112739 - matthiaskrgr:rollup-8cfggml, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #112352 (Fix documentation build on FreeBSD)
 - #112644 (Correct types in method descriptions of `NonZero*` types)
 - #112683 (fix ICE on specific malformed asm clobber_abi)
 - #112707 ([rustdoc] Fix invalid handling of "going back in history" when "go to only search result" setting is enabled)
 - #112719 (Replace fvdl with ffx, allow test without install)
 - #112728 (Add `<meta charset="utf-8">` to `-Zdump-mir-spanview` output)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-17 13:19:29 +00:00
Matthias Krüger
ba3e535c07
Rollup merge of #112644 - zica87:nonZeroTypes, r=Mark-Simulacrum
Correct types in method descriptions of `NonZero*` types

- `$Int`: e.g. i32, usize
- `$Ty`: e.g. NonZeroI32, NonZeroUsize

|method|current description|after my changes|
|-|-|-|
|`saturating_add`|...Return `$Int`::MAX on overflow.|...Return `$Ty`::MAX on overflow.|
|`checked_abs`|...returns None if self == `$Int`::MIN.|...returns None if self == `$Ty`::MIN.|
|`checked_neg`|...returning None if self == i32::MIN.|...returning None if self == `$Ty`::MIN.|
|`saturating_neg`|...returning MAX if self == i32::MIN...|...returning `$Ty`::MAX if self == `$Ty`::MIN...|
|`saturating_mul`|...Return `$Int`::MAX...|...Return `$Ty`::MAX...|
|`saturating_pow`|...Return `$Int`::MIN or `$Int`::MAX...|...Return `$Ty`::MIN or `$Ty`::MAX...|

---

For example:

```rust
pub const fn saturating_neg(self) -> NonZeroI128
```

- current
  - Saturating negation. Computes `-self`, returning `MAX` if `self == i32::MIN` instead of overflowing.
- after my changes
  - Saturating negation. Computes `-self`, returning `NonZeroI128::MAX` if `self == NonZeroI128::MIN` instead of overflowing.
2023-06-17 12:43:30 +02:00
Matthias Krüger
d2120b7d42
Rollup merge of #112352 - dankm:fbsd_doc_fix, r=thomcc
Fix documentation build on FreeBSD

After the socket ancillary data implementation was introduced, the documentation build was broken on FreeBSD hosts, add the same workaround as for the existing implementations.

Fixes the doc build after #91793
2023-06-17 12:43:29 +02:00
The 8472
3738785735 Extend io::copy buffer reuse to BufReader too
previously it was only able to use BufWriter. This was due to a limitation in the
BufReader generics that prevented specialization. This change works around the issue
by using `where Self: Read` instead of `where I: Read`. This limits our options, e.g.
we can't access BufRead methods, but it happens to work out if we rely on some
implementation details.
2023-06-17 11:07:04 +02:00
Trevor Gross
22d00dcd47 Apply changes to fix python linting errors 2023-06-16 20:56:01 -04:00
Scott McMurray
3ec4eeddef [libs] Simplify unchecked_{shl,shr}
There's no need for the `const_eval_select` dance here.  And while I originally wrote the `.try_into().unwrap_unchecked()` implementation here, it's kinda a mess in MIR -- this new one is substantially simpler, as shown by the old one being above the inlining threshold but the new one being below it.
2023-06-16 16:03:19 -07:00
DrMeepster
a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Michael Goulet
38fc6be325
Rollup merge of #112662 - Vanille-N:symbol_unique, r=RalfJung
`#[lang_item]` for `core::ptr::Unique`

Tree Borrows is about to introduce experimental special handling of `core::ptr::Unique` in Miri to give it a semantics.
As of now there does not seem to be a clean way (i.e. other than `&format!("{adt:?}") == "std::ptr::Unique"`) to check if an `AdtDef` represents a `Unique`.

r? `@RalfJung`

Draft: making a lang item
2023-06-16 12:53:22 -07:00
Michael Goulet
4d5e7cdc03
Rollup merge of #112226 - devnexen:netbsd_affinity, r=cuviper
std: available_parallelism using native netbsd api first

before falling back to existing code paths like FreeBSD does.
2023-06-16 12:53:21 -07:00
Michael Goulet
c55af41e7a
Rollup merge of #111074 - WaffleLapkin:🌟unsizes_your_buf_reader🌟, r=Amanieu
Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`

TL;DR:
```diff,rust
-pub struct BufReader<R> { /* ... */ }
+pub struct BufReader<R: ?Sized> { /* ... */ }

-pub struct BufWriter<W: Write> { /* ... */ }
+pub struct BufWriter<W: ?Sized + Write> { /* ... */ }

-pub struct LineWriter<W: Write> { /* ... */ }
+pub struct LineWriter<W: ?Sized + Write> { /* ... */ }
```

This allows using `&mut BufReader<dyn Read>`, for example.

**This is an insta-stable change**.
2023-06-16 12:53:21 -07:00
Neven Villani
dc3e91c6c2
#[lang_item] for core::ptr::Unique 2023-06-16 15:22:18 +02:00
Ben Kimock
7a2490eba3 Launch a non-unwinding panic for misaligned pointer deref 2023-06-16 09:20:33 -04:00
Ralf Jung
18b86468b8 slice::from_raw_parts: mention no-wrap-around condition 2023-06-16 14:56:31 +02:00
Alex Macleod
b607a8a4af Remove #[cfg(all())] workarounds from c_char 2023-06-16 12:17:12 +00:00
Dylan DPC
48b645e0ea
Rollup merge of #112579 - MikaelUrankar:freebsd_docs, r=cuviper
Fix building libstd documentation on FreeBSD.

It fixes the following error:
```
error[E0412]: cannot find type `sockcred2` in module `libc`
   --> library/std/src/os/unix/net/ancillary.rs:211:29
    |
211 | pub struct SocketCred(libc::sockcred2);
    |                             ^^^^^^^^^ not found in `libc`
```
2023-06-16 14:46:16 +05:30
Dylan DPC
627f85cd5a
Rollup merge of #112535 - RalfJung:miri-test-libstd, r=cuviper
reorder attributes to make miri-test-libstd work again

Fixes fallout from https://github.com/rust-lang/rust/pull/110141
2023-06-16 14:46:15 +05:30
+merlan #flirora
c2e4e981b3 Add more comprehensive tests for is_sorted and friends
See #53485 and #55045.
2023-06-16 03:04:34 -04:00
Josh Stone
886085a4d5 std: only depend on dlmalloc for wasm*-unknown
It was already filtered out for emscripten, but wasi doesn't need dlmalloc
either since it reuses `unix/alloc.rs`.
2023-06-15 15:56:00 -07:00
Guillaume Gomez
d233522418
Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obk
Extend `unused_must_use` to cover block exprs

Given code like

```rust
#[must_use]
fn foo() -> i32 {
    42
}

fn warns() {
    {
        foo();
    }
}

fn does_not_warn() {
    {
        foo()
    };
}

fn main() {
    warns();
    does_not_warn();
}
```

### Before This PR

```
warning: unused return value of `foo` that must be used
 --> test.rs:8:9
  |
8 |         foo();
  |         ^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
8 |         let _ = foo();
  |         +++++++

warning: 1 warning emitted
```

### After This PR

```
warning: unused return value of `foo` that must be used
 --> test.rs:8:9
  |
8 |         foo();
  |         ^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
8 |         let _ = foo();
  |         +++++++

warning: unused return value of `foo` that must be used
  --> test.rs:14:9
   |
14 |         foo()
   |         ^^^^^
   |
help: use `let _ = ...` to ignore the resulting value
   |
14 |         let _ = foo();
   |         +++++++      +

warning: 2 warnings emitted
```

Fixes #104253.
2023-06-15 22:04:56 +02:00
The 8472
64ee0f74eb remove unused field
since DrainFilter no longer continues draining when it's dropped
the panic tracking is no longer needed.
2023-06-15 21:14:40 +02:00
Vadim Petrochenkov
95a24c6ed4 privacy: Do not mark items reachable farther than their nominal visibility
This commit reverts a change made in #111425.
It was believed that this change was necessary for implementing type privacy lints, but #111801 showed that it was not necessary.
Quite opposite, the revert fixes some issues.
2023-06-15 21:25:47 +03:00
Matthias Krüger
c4c5e0baee
Rollup merge of #112621 - GrigorenkoPV:env, r=jyn514
Mention `env!` in `option_env!`'s docs

`env!` mentions that there is an alternative that returns an `Option<...>` instead of emitting a compile error.

Now `option_env!` also mentions that there is an alternative that emits a compile error instead of returning an `Option<...>`.
2023-06-15 17:52:37 +02:00
许杰友 Jieyou Xu (Joe)
72b3b58efc
Extend unused_must_use to cover block exprs 2023-06-15 17:59:13 +08:00
bors
4996b56ba9 Auto merge of #106343 - the8472:slice-iter-fold, r=scottmcm
optimize slice::Iter::fold

Fixes 2 of 4 cases from #106288

```
OLD: test slice::fold_to_last                                           ... bench:         248 ns/iter (+/- 3)
NEW: test slice::fold_to_last                                           ... bench:           0 ns/iter (+/- 0)
```
2023-06-15 09:38:53 +00:00
zica
88b08582b2 Correct types in method descriptions of NonZero* types 2023-06-15 11:41:56 +08:00
bors
6ee4265ca6 Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieu
Don't drain-on-drop in DrainFilter impls of various collections.

This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](https://github.com/rust-lang/rust/issues/43244#issuecomment-641638196) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](https://github.com/rust-lang/rfcs/pull/3288).

closes #101122

[ACP](https://github.com/rust-lang/libs-team/issues/136)

affected tracking issues
* #43244
* #70530
* #59618

Related hashbrown update: https://github.com/rust-lang/hashbrown/pull/374
2023-06-15 00:03:10 +00:00
The 8472
d90508f761 use indexed loop instead of ptr bumping
this seems to produce less IR
2023-06-14 22:22:41 +02:00
bors
8c74a5d27c Auto merge of #112625 - matthiaskrgr:rollup-jcobj3g, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112584 (loongarch64-none*: Remove environment component from llvm target)
 - #112600 (Introduce a `Stable` trait to translate MIR to SMIR)
 - #112605 (Improve docs/clean up negative overlap functions)
 - #112611 (Error on unconstrained lifetime in RPITIT)
 - #112612 (Fix explicit-outlives-requirements lint span)
 - #112613 (Fix rustdoc-gui tests on Windows)
 - #112620 (Fix small typo)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-14 20:20:40 +00:00
ltdk
2dce58d0f6 Fix SocketAddrV6: Display tests 2023-06-14 15:21:15 -04:00
ltdk
2f2c3f55a9 Fix Ipv6Addr: Display tests 2023-06-14 14:25:25 -04:00
bors
0b475c705f Auto merge of #112624 - matthiaskrgr:rollup-db6ta1b, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #98202 (Implement `TryFrom<&OsStr>` for `&str`)
 - #107619 (Specify behavior of HashSet::insert)
 - #109814 (Stabilize String::leak)
 - #111974 (Update runtime guarantee for `select_nth_unstable`)
 - #112109 (Don't print unsupported split-debuginfo modes with `-Zunstable-options`)
 - #112506 (Properly check associated consts for infer placeholders)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-14 17:25:04 +00:00
Matthias Krüger
c451f7bedb
Rollup merge of #111974 - Sp00ph:update_guarantees, r=Amanieu
Update runtime guarantee for `select_nth_unstable`

#106933 changed the runtime guarantee for `select_nth_unstable` from O(n) to O(n log n), since the old guarantee wasn't actually met by the implementation at the time. Now with #107522, `select_nth_unstable` should be truly linear in runtime, so we can revert its runtime guarantee to O(n). Since #106933 was considered a bug fix, this will probably need an FCP because it counts as a new API guarantee.

r? `@Amanieu`
2023-06-14 18:10:29 +02:00
Matthias Krüger
b8f71eaf01
Rollup merge of #109814 - est31:stabilize_string_leak, r=Amanieu
Stabilize String::leak

Stabilizes the following API:

```Rust
impl String {
    pub fn leak(self) -> &'static mut str;
}
```

closes #102929

blocked by having an FCP for stabilization.
2023-06-14 18:10:28 +02:00
Matthias Krüger
d54bb505d0
Rollup merge of #107619 - stepancheg:hash-set-insert, r=Amanieu
Specify behavior of HashSet::insert

`HashSet::insert` does not replace the value with equal value.

Fixes #107581.
2023-06-14 18:10:28 +02:00
Matthias Krüger
4efdb5c001
Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=Amanieu
Implement `TryFrom<&OsStr>` for `&str`

Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing.

Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`.

As this is a trait implementation, it is insta-stable, if I'm not mistaken?
Either way this will need an FCP.
I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off.

`@rustbot` modify labels: +T-libs-api

API Change Proposal: rust-lang/rust#99031 (accepted)
2023-06-14 18:10:27 +02:00
Pavel Grigorenko
cfe2e4660d
Mention env! in option_env!'s docs 2023-06-14 18:29:08 +03:00
Antonios Barotsis
cb093fc648 Fix typo 2023-06-14 16:52:29 +02:00
bors
afa9fef709 Auto merge of #112418 - ferrocene:pa-mir-opt-panic, r=ozkanonur,saethlin
Add support for targets without unwinding in `mir-opt`, and improve `--bless` for it

The main goal of this PR is to add support for targets without unwinding support in the `mir-opt` test suite, by adding the `EMIT_MIR_FOR_EACH_PANIC_STRATEGY` comment. Similarly to 32bit vs 64bit, when that comment is present, blessed output files will have the `.panic-unwind` or `.panic-abort` suffix, and the right one will be chosen depending on the target's panic strategy.

The `EMIT_MIR_FOR_EACH_PANIC_STRATEGY` comment replaced all the `ignore-wasm32` comments in the `mir-opt` test suite, as those comments were added due to `wasm32` being a target without unwinding support. The comment was also added on other tests that were only executed on x86 but were still panic strategy dependent.

The `mir-opt` suite was then blessed, which caused a ton of churn as most of the existing output files had to be renamed and (mostly) duplicated with the abort strategy.

---

After [asking on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/mir-opt.20tests.20and.20panic.3Dabort), the main concern about this change is it'd make blessing the `mir-opt` suite even harder, as you'd need to both bless it with an unwinding target and an aborting target. This exacerbated the current situation, where you'd need to bless it with a 32bit and a 64bit target already.

Because of that, this PR also makes significant enhancements to `--bless` for the `mir-opt` suite, where it will automatically bless the suite four times with different targets, while requiring minimal cross-compilation.

To handle the 32bit vs 64bit blessing, there is now an hardcoded list of target mapping between 32bit and 64bit. The goal of the list is to find a related target that will *probably* work without requiring additional cross-compilation toolchains on the system. If a mapping is found, bootstrap will bless the suite with both targets, otherwise just with the current target.

To handle the panic strategy blessing (abort vs unwind), I had to resort to what I call "synthetic targets". For each of the target we're blessing (so either the current one, or a 32bit and a 64bit depending on the previous paragraph), bootstrap will extract the JSON spec of the target and change it to include `"panic-strategy": "abort"`. It will then build the standard library with this synthetic target, and bless the `mir-opt` suite with it.

As a result of these changes, blessing the `mir-opt` suite will actually bless it two or four times with different targets, ensuring all possible variants are actually blessed.

---

This PR is best reviewed commit-by-commit.

r? `@jyn514`
cc `@saethlin` `@oli-obk`
2023-06-14 14:20:59 +00:00
The 8472
479be6ac43 update hashbrown and replace Hash{Set,Map}::DrainFilter with ExtractIf 2023-06-14 09:28:56 +02:00
The 8472
114d5f221c s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList 2023-06-14 09:28:54 +02:00
The 8472
b7ce7edd87 remove drain-on-drop behavior from linked_list::DrainFilter and add #[must_use] 2023-06-14 09:24:51 +02:00
The 8472
b687e84aeb remove drain-on-drop behavior from BTree{Set,Map}::DrainFilter and add #[must_use] 2023-06-14 09:24:51 +02:00
The 8472
c0df1c8c43 remove drain-on-drop behavior from vec::DrainFilter and add #[must_use] 2023-06-14 09:24:51 +02:00
Scott McMurray
e94f26a40a Bump stdarch 2023-06-13 21:45:04 -07:00
ltdk
3a9a8d4abf Alter Display for Ipv6Addr for IPv4-compatible addresses 2023-06-13 22:30:38 -04:00
Henrik Böving
82466625b4 fix: get the l4re target working again 2023-06-13 20:41:33 +00:00
bors
371994e0d8 Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3
Ignore `core`, `alloc` and `test` tests that require unwinding on `-C panic=abort`

Some of the tests for `core` and `alloc` require unwinding through their use of `catch_unwind`. These tests fail when testing using `-C panic=abort` (in my case through a target without unwinding support, and `-Z panic-abort-tests`), while they should be ignored as they don't indicate a failure.

This PR marks all of these tests with this attribute:

```rust
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
```

I'm not aware of a way to test this on rust-lang/rust's CI, as we don't test any target with `-C panic=abort`, but I tested this locally on a Ferrocene target and it does indeed make the test suite pass.
2023-06-13 19:03:27 +00:00
Pietro Albini
44556eed36
ignore core, alloc and test tests that require unwinding on panic=abort 2023-06-13 15:53:24 +02:00
MikaelUrankar
513f28db0a Fix building the documentation on FreeBSD.
It fixes the following error:
error[E0412]: cannot find type `sockcred2` in module `libc`
   --> library/std/src/os/unix/net/ancillary.rs:211:29
    |
211 | pub struct SocketCred(libc::sockcred2);
    |                             ^^^^^^^^^ not found in `libc`
2023-06-13 13:14:06 +02:00
bors
caeea3f0a2 Auto merge of #112575 - matthiaskrgr:rollup-7a8d7tg, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #111885 (Don't ICE on unsized `extern "rust-call"` call)
 - #112558 (Fix typo in mod.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-13 06:13:43 +00:00
Matthias Krüger
aee8e10a26
Rollup merge of #112558 - eltociear:patch-21, r=thomcc
Fix typo in mod.rs

assoicated -> associated
2023-06-13 07:02:28 +02:00
bors
de1ff0a8b5 Auto merge of #99339 - yanchith:binary-heap-ta, r=Amanieu
Make BinaryHeap parametric over Allocator

Tracking issue: #32838
Related: https://github.com/rust-lang/wg-allocators/issues/7

This parametrizes `BinaryHeap` with `A`, similarly to how other collections are parametrized.

A couple things I left out:

```
BinaryHeap::append

    Currently requires both structures to have the same allocator type. Could
    change, but depends on Vec::append, which has the same constraints.

impl<T: Ord> Default for BinaryHeap<T>

    Not parametrized, because there's nowhere to conjure the allocator from.

impl<T: Ord> FromIterator<T> for BinaryHeap<T>

    Not parametrized, because there's nowhere to conjure the allocator from.

impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T>

    Not parametrized, because there's nowhere to conjure the allocator from.

unsafe impl<I> AsVecIntoIter for IntoIter<I>

    AsVecIntoIter is not allocator aware, and I didn't dare change it without guidance. Is this something important?
```

I've seen very few tests for allocator_api in general, but I'd like to at least test this on some usage code in my projects before moving forward.

EDIT: Updated the list of impls and functions that are not affected by this. `BinaryHeap` no longer has a `SpecExtend` impl, and prior work made implementing `Extend` possible.
2023-06-13 03:23:12 +00:00
Ikko Eltociear Ashimine
69de7ca199
Fix typo in mod.rs
assoicated -> associated
2023-06-13 00:09:13 +09:00
bdbai
df08f56b08 Add comment for arm_shim in generate-windows-sys 2023-06-12 22:40:30 +08:00
bdbai
f7f25b0e2f Add windows_sys typedef for Win ARM32 2023-06-12 22:40:30 +08:00
The 8472
d89e458159 optimize slice::Iter::fold 2023-06-12 13:03:29 +02:00
The 8472
cfb0f11a9f add benchmark 2023-06-12 13:03:29 +02:00
Guillaume Gomez
7c5e41631d Revert "Fix intra-doc links from pointer appearing in windows HANDLE type alias"
This reverts commit 2ce7cd906b.
2023-06-12 11:18:28 +02:00
aticu
e3a1a11ed2 Implement TryFrom<&OsStr> for &str 2023-06-12 10:46:49 +02:00
Pietro Albini
6fd0d1ba14
make sure the standard library compiles properly with synthetic targets
It might happen that a synthetic target name does not match one of the
hardcoded ones in std's build script, causing std to fail to build. This
commit changes the std build script avoid including the restricted-std
feature unconditionally when a synthetic target is being built.
2023-06-12 09:34:13 +02:00
yanchith
e0e355dd25 Impl allocator function for iterators 2023-06-11 22:56:16 +02:00
yanchith
d9b6181d2f Remove explicit lifetimes 2023-06-11 22:42:50 +02:00
Ralf Jung
3b9b4e5e3d reorder attributes to make miri-test-libstd work again 2023-06-11 22:15:46 +02:00
Matthias Krüger
0ff35f27b0
Rollup merge of #112497 - icecream17:patch-1, r=Mark-Simulacrum
abs_sub: fix typo 0[-:][+.]0
2023-06-11 01:57:28 +02:00
Matthias Krüger
e4f6b3d39e
Rollup merge of #112484 - bdbai:fix/uwpntdll, r=ChrisDenton
Fix ntdll linkage issues on Windows UWP platforms

See discussion: https://github.com/rust-lang/rust/issues/112265#issuecomment-1575479683

Static loading `ntdll` functions does not work for UWP programs, which will end up link errors complaining about missing symbols, or failure to pass the WACK tests. The breakage was introduced in #108262.

This PR basically reverts part of the changes in #108262 for UWP only, and fixes some lint suggestions.
2023-06-11 01:57:26 +02:00
Ibraheem Ahmed
5f56956b3c implement Sync for mpsc::Sender 2023-06-10 19:22:07 -04:00
icecream17
83d7826753
abs_sub: fix typo 0[-:][+.]0 2023-06-10 10:45:50 -05:00
bors
788c98df59 Auto merge of #111818 - Urgau:uplift_cmp_nan, r=cjgillot
Uplift `clippy::cmp_nan` lint

This PR aims at uplifting the `clippy::cmp_nan` lint into rustc.

## `invalid_nan_comparisons`

~~(deny-by-default)~~ (warn-by-default)

The `invalid_nan_comparisons` lint checks comparison with `f32::NAN` or `f64::NAN` as one of the operand.

### Example

```rust,compile_fail
let a = 2.3f32;
if a == f32::NAN {}
```

### Explanation

NaN does not compare meaningfully to anything – not even itself – so those comparisons are always false.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler
2023-06-10 12:47:51 +00:00
bdbai
cd523f2f18 Keep uwp specific code in sync with windows-sys 2023-06-10 20:47:10 +08:00
bdbai
48e410e317 Lazy load ntdll functions on UWP 2023-06-10 16:34:20 +08:00
Urgau
3681285df7 Add diagnostic items for f32::NAN and f64::NAN 2023-06-09 17:46:33 +02:00
bors
397641f3bd Auto merge of #112465 - GuillaumeGomez:rollup-gyh5buc, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #112260 (Improve document of `unsafe_code` lint)
 - #112429 ([rustdoc] List matching impls on type aliases)
 - #112442 (Deduplicate identical region constraints in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-09 15:37:22 +00:00
bors
d7ad9d9797 Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errors
Uplift `clippy::undropped_manually_drops` lint

This PR aims at uplifting the `clippy::undropped_manually_drops` lint.

## `undropped_manually_drops`

(warn-by-default)

The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop.

### Example

```rust
struct S;
drop(std::mem::ManuallyDrop::new(S));
```

### Explanation

`ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either.

-----

Mostly followed the instructions for uplifting an clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2023-06-09 12:44:23 +00:00
yanchith
4df4c0d00b Don't explicitly name Global 2023-06-09 12:19:17 +02:00
yanchith
767a7119a0 Pass tidy again 2023-06-09 12:02:25 +02:00
yanchith
208da513cc Add allocator function 2023-06-09 11:53:28 +02:00
yanchith
7a9f282528 Reallocatorize after merge 2023-06-09 11:48:11 +02:00
yanchith
cb5c011670 Merge branch 'master' into binary-heap-ta 2023-06-09 11:22:08 +02:00
Guillaume Gomez
2ce7cd906b Fix intra-doc links from pointer appearing in windows HANDLE type alias 2023-06-09 10:36:22 +02:00
Matthias Krüger
8747c0ebea
Rollup merge of #109953 - thomcc:thomcc/typeid128, r=WaffleLapkin
Use 128 bits for TypeId hash

Preliminary/Draft impl of https://github.com/rust-lang/compiler-team/issues/608

Prior art (probably incomplete list)
- https://github.com/rust-lang/rust/pull/75923
- https://github.com/rust-lang/rust/pull/95845
2023-06-08 12:36:17 +02:00
Urgau
d9d1c76ded Allow undropped_manually_drops for some tests 2023-06-08 11:41:34 +02:00
bors
80917360d3 Auto merge of #112292 - thomcc:tls-ohno, r=m-ou-se
Avoid unwind across `extern "C"` in `thread_local::fast_local`

This is a minimal fix for #112285, in case we want a simple patch that can be easily to backported if that's desirable.

*(Note: I have another broader cleanup which I've mostly omitted from here to avoid clutter, except for the `Cell` change, which isn't needed to fix UB, but simplifies safety comments).*

The only tier-1 target that this occurs on in a way that seems likely to cause problems in practice linux-gnu, although I believe some folks care about that platform somewhat 😉. I'm unsure how big of an issue this is. I've seen stuff like this behave quite badly, but there's a number of reasons to think this might actually be "fine in practice".

I've hedged my bets and assumed we'll backport this at least to beta but my feeling is that there's not enough evidence this is a problem worth backporting further than that.

### More details

This issue seems to have existed since `thread_local!`'s `const` init functionality was added. It occurs if you have a `const`-initialized thread local for a type that `needs_drop`, the drop panics, and you're on a target with support for static thread locals. In this case, we will end up defining an `extern "C"` function in the user crate rather than in libstd, and because the user crate will not have `#![feature(c_unwind)]` enabled, their panic will not be caught by an auto-inserted abort guard.

In practice, the actual situation where problems are likely[^ub] is somewhat narrower.

On most targets with static thread locals, we manage the TLS dtor list by hand (for reentrancy reasons among others). In these cases, while the users code may panic, we're calling it inside our own `extern "C"` (or `extern "system"`) function, which seems to (at least in practice) catch the panic and convert it to an abort.

However, on a few targets, most notably linux-gnu with recent glibc (but also fuchsia and redox), a tls dtor registration mechanism exists which we can actually use directly, [`__cxa_thread_atexit_impl`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/thread_local_dtor.rs#L26-L36).

This is the case that seems most likely to be a cause for concern, as now we're passing a function to the system library and panicking out of it in a case where there are may not be Rust frames above it on the call stack (since it's running thread shutdown), and even if there were, it may not be prepared to handle such unwinding. If that's the case, it'd be bad.

Is it? Dunno. The fact that it's a `__cxa_*` function makes me think they probably have considered that the callback could throw but I have no evidence here and it doesn't seem to be written down anywhere, so it's just a guess. (I would not be surprised if someone comes into this thread to tell me how definitely-bad-news it is).

That said, as I said, all this is actually UB! If this isn't a "technically UB but fine in practice", but all bets are off if this is the kind of thing we are telling LLVM about.

[^ub]: This is UB so take that with a grain of salt -- I'm absolutely making assumptions about how the UB will behave "in practice" here, which is almost certainly a mistake.
2023-06-08 04:44:08 +00:00
Thom Chiovoloni
b512004a4a
Fix typo
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2023-06-07 21:27:51 -07:00
bors
10b7e468f3 Auto merge of #96875 - SabrinaJewson:noop-waker, r=m-ou-se
Add `task::Waker::noop`

I have found myself reimplementing this function many times when I need a `Context` but don't have a runtime or `futures` to hand.

Prior art: [`futures::task::noop_waker`](https://docs.rs/futures/0.3/futures/task/fn.noop_waker.html) and [`futures::task::noop_waker_ref`](https://docs.rs/futures/0.3/futures/task/fn.noop_waker_ref.html)

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

Unresolved questions:
1. Should we also add `RawWaker::noop()`? (I don't think so, I can't think of a use case for it)
2. Should we also add `Context::noop()`? Depending on the future direction `Context` goes a "noop context" might not even make sense in future.
3. Should it be an associated constant instead? That would allow for `let cx = &mut Context::from_waker(&Waker::NOOP);` to work on one line which is pretty nice. I don't really know what the guideline is here.

r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs
2023-06-07 06:04:32 +00:00
bors
b3dd578767 Auto merge of #111819 - nikarh:vita-improved, r=Amanieu
Improved std support for ps vita target

Fixed a couple of things in std support for ps vita via Vita SDK newlib oss implementation:

- Added missing hardware features to target spec
- Compile in thumb by default (newlib is also compiled in thumb)
- Fixed fs calls. Vita newlib has a not-very-posix dirent. Also vita does not expose inodes, it's stubbed as 0 in stat, and I'm stubbing it here for dirent (because vita newlibs's dirent doesn't even have that field)
- Enabled signal handlers for panic unwinding
- Dropped static link requirement from the platform support md. Also, rearranged sections to better stick with the template.
2023-06-07 03:20:15 +00:00
Dan McGregor
e99f7ed071 Fix documentation build on FreeBSD
After the socket ancillary data implementation was introduced, the
build was broken on FreeBSD, add the same workaround as for the
existing implementations.
2023-06-06 10:28:10 -06:00
Nikolay Arhipov
032857e7e4 Bumped libc version 2023-06-06 16:09:05 +03:00
David Carlier
25b3751fd1 std: available_parallelism using native netbsd api first
before falling back to existing code paths like FreeBSD does.
2023-06-06 06:34:27 +01:00
Nikolay Arhipov
ac48d49ff8 Simplified bool to int conversion 2023-06-05 19:26:04 +03:00
Nikolay Arhipov
50117af409 Std support improvement for ps vita target 2023-06-05 19:14:09 +03:00
Guillaume Gomez
200d03acad
Rollup merge of #112263 - GrishaVar:remove-extend-element, r=scottmcm
Remove ExtendElement, ExtendWith, extend_with

Related to  #104624, broken up into two commits. The first removes wrapper trait ExtendWith and its only implementer struct ExtendElement. The second may have perf issues so may be reverted/removed if no alternate fix is found; it should be profiled.

r? `@scottmcm`
2023-06-05 17:02:51 +02:00
Thom Chiovoloni
70e1dc9967
Avoid unwind across extern "C" in thread_local::fast_local.rs 2023-06-04 14:54:28 -07:00
Thom Chiovoloni
9e5573a0d2
Use 128 bits for TypeId hash
- Switch TypeId to 128 bits
- Hack around the fact that tracing-subscriber dislikes how TypeId is hashed
- Remove lowering of type_id128 from rustc_codegen_llvm
- Remove unnecessary `type_id128` intrinsic (just change return type of `type_id`)
- Only hash the lower 64 bits of the TypeId
- Reword comment
2023-06-04 08:34:48 -07:00
Grisha Vartanyan
dd2bd03d0a Remove ExtendWith and ExtendElement 2023-06-04 15:55:34 +02:00
Matthias Krüger
cbc3e3f641
Rollup merge of #112172 - tshepang:patch-1, r=Mark-Simulacrum
doc: improve explanation
2023-06-04 13:21:27 +02:00
Matthias Krüger
7ee2505529
Rollup merge of #109093 - Dante-Broggi:patch-2, r=joshtriplett
add `#[doc(alias="flatmap")]` to `Option::and_then`

I keep forgetting that rust calls this `and_then` and trying to search for `flatmap`. `and_then`'s docs even mention "Some languages call this operation flatmap", but it doesn't show up as a result in the search at `https://doc.rust-lang.org/std/?search=flatmap`
2023-06-04 13:21:25 +02:00
Matthias Krüger
6e024ecab8
Rollup merge of #111702 - cgwalters:option-map-or-else-with-result, r=Mark-Simulacrum
Option::map_or_else: Show an example of integrating with Result

Moving this from https://github.com/rust-lang/libs-team/issues/59 where an API addition was rejected.  But I think it's valuable to add this example to the documentation at least.
2023-06-03 20:38:11 +02:00
bors
1e17cef9e2 Auto merge of #109432 - flba-eb:108594_forkspawn_exponential_backoff, r=workingjubilee
QNX Neutrino: exponential backoff when fork/spawn needs a retry

Fixes #108594: When retrying, sleep with an exponential duration. When sleep duration is lower than minimum possible sleeping time, yield instead (this will not be often due to the exponential increase of duration).

Minimum possible sleeping time is determined using `libc::clock_getres` but only when spawn/fork failed the first time in a request. This is cached using a LazyLock.

CC `@gh-tr`

r? `@workingjubilee`
`@rustbot` label +O-neutrino
2023-06-03 10:06:59 +00:00
Matthias Krüger
4435544c35
Rollup merge of #112206 - k0ur0x:typo, r=Nilstrieb
Fix typo in `std::cell` module docs
2023-06-02 18:12:47 +02:00
Matthias Krüger
a3b639ce43
Rollup merge of #111647 - klensy:cstr, r=oli-obk
use c literals in compiler and library

Use c literals #108801 in compiler and library

currently blocked on:
* <strike>rustfmt: don't know how to format c literals</strike> nope, nightly one works.
* <strike>bootstrap</strike>

r? `@ghost`
`@rustbot` blocked
2023-06-02 18:12:45 +02:00
Florian Bartels
716cc5ac93 Only determine clock res once; give up before sleeping more than 1 second 2023-06-02 17:52:14 +02:00
Florian Bartels
bdb475cf6c Retry to fork/spawn with exponential backoff 2023-06-02 16:12:21 +02:00
Kourosh
9df4572277
Fix typo in std::cell module docs 2023-06-02 15:30:40 +03:30
klensy
2f459f7f14 fix ptr cast 2023-06-02 11:26:34 +03:00
Michael Goulet
24404e6409
Rollup merge of #111670 - compiler-errors:const-param-ty, r=BoxyUwU
Require that const param tys implement `ConstParamTy`

1. Require that const param tys implement `ConstParamTy` instead of using `search_for_adt_const_param_violation`
2. Add `StructuralPartialEq` as a supertrait for `ConstParamTy`, since we need to make sure that we derive *both* `PartialEq` and `Eq`
3. Implement `ConstParamTy` for tuples up to 12 (or whatever the default for tuples is)
4. Add some custom diagnostics to `ConstParamTy` errors, to avoid regressions from (1.). It's still not as great as it could be -- will point out inline in comments.

r? `@BoxyUwU`
2023-06-01 23:07:36 -07:00
Trevor Gross
5cb701f379 Stabilize 'const_cstr_methods' 2023-06-01 17:39:18 -04:00
Matthias Krüger
a66ba9b10b
Rollup merge of #112154 - ShaneEverittM:zero-len-utf16, r=thomcc
Fix bug in utf16_to_utf8 for zero length strings

This fixes the behavior of sending EOF by pressing Ctrl+Z => Enter in a windows console.

Previously, that would trip the unpaired surrogate error, whereas now we correctly detect EOF.
2023-06-01 22:47:32 +02:00
Michael Goulet
a9fcb524ff Impl ConstParamTy for tuples, make PartialStructuralEq a supertrait too 2023-06-01 18:21:42 +00:00
Boxy
bbf41279fa Require that const param tys implement ConstParamTy 2023-06-01 18:03:59 +00:00
Tshepang Mbambo
793fa8d7c5
doc: improve explanation 2023-06-01 12:55:58 +02:00
Dylan DPC
129c559764
Rollup merge of #112141 - anna-singleton:issue-111655-fix, r=thomcc
remove reference to Into in ? operator core/std docs, fix #111655

remove the text stating that `?` uses `Into::into` and add text stating it uses `From::from` instead. This closes #111655.
2023-06-01 11:09:45 +05:30
bors
ba1690bedd Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naber
Uplift `clippy::cast_ref_to_mut` lint

This PR aims at uplifting the `clippy::cast_ref_to_mut` lint into rustc.

## `cast_ref_to_mut`

(deny-by-default)

The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T` without using interior mutability.

### Example

```rust,compile_fail
fn x(r: &i32) {
    unsafe {
        *(r as *const i32 as *mut i32) += 1;
    }
}
```

### Explanation

Casting `&T` to `&mut T` without interior mutability is undefined behavior, as it's a violation of Rust reference aliasing requirements.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::cast_ref_to_mut` into rustc
2023-06-01 01:27:32 +00:00
Shane Murphy
1293c17205 Fix bug in utf16_to_utf8 for zero length strings
This fixes the behavior of sending EOF by pressing Ctrl+Z => Enter in a
windows console.

Previously, that would trip the unpaired surrogate error, whereas now we
correctly detect EOF.
2023-05-31 17:25:53 -07:00
klensy
f212ba6d6d use c literals in library 2023-05-31 19:41:51 +03:00
anna-singleton
2eeb7693c5 remove reference to Into in ? operator core/std docs, fix 111655 2023-05-31 15:51:28 +01:00
bors
ad8304a0d5 Auto merge of #111076 - notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot
diagnostics: exclude indirect private deps from trait impl suggest

Fixes #88696
2023-05-31 13:47:36 +00:00
Urgau
a51ad131e6 Add diagnostic items for ptr::cast_mut and ptr::from_ref 2023-05-31 12:26:36 +02:00
Matthias Krüger
2054acb0a4
Rollup merge of #112103 - Mark-Simulacrum:bootstrap-update, r=clubby789
Bootstrap update to 1.71 beta

Best reviewed by-commit.
2023-05-31 11:19:09 +02:00
bors
617d3d6d72 Auto merge of #112127 - matthiaskrgr:rollup-77pt893, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112031 (Migrate  `item_proc_macro` to Askama)
 - #112053 (Remove `-Zcgu-partitioning-strategy`.)
 - #112069 (offset_of: don't require type to be `Sized`)
 - #112084 (enhancements on  build_helper utilization and rustdoc-gui-test)
 - #112096 (Remove array_zip)
 - #112108 (Fix re-export of doc hidden item inside private item not displayed)
 - #112113 (rustdoc: simplify `clean` by removing `FnRetTy`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-31 05:42:26 +00:00
Matthias Krüger
88160ab94c
Rollup merge of #112096 - workingjubilee:array-unzip, r=scottmcm
Remove array_zip

`[T; N]::zip` is "eager" but most zips are mapped. This causes poor optimization in generated code. This is a fundamental design issue and "zip" is "prime real estate" in terms of function names, so let's free it up again.

- FCP concluded in https://github.com/rust-lang/rust/issues/80094#issuecomment-1468300057
- Closes https://github.com/rust-lang/rust/issues/80094
- Closes https://github.com/rust-lang/rust/issues/103555

Could use review to make sure we aren't losing any essential codegen tests.
r? `@scottmcm`
2023-05-31 07:07:02 +02:00
bors
f51fca3af3 Auto merge of #112120 - weihanglo:update-cargo, r=ehuss
Update cargo

17 commits in 64fb38c97ac4d3a327fc9032c862dd28c8833b17..f7b95e31642e09c2b6eabb18ed75007dda6677a0
2023-05-23 18:53:23 +0000 to 2023-05-30 19:25:02 +0000
- chore: detect the channel a PR wants to merge into (rust-lang/cargo#12181)
- refactor: de-depulicate `make_dep_prefix` implementation (rust-lang/cargo#12203)
- Re-enable code_generation test on Windows (rust-lang/cargo#12199)
- docs: add doc comments for git source and friends (rust-lang/cargo#12192)
- test: set retry sleep to 1ms for all tests (rust-lang/cargo#12194)
- fix(add): Reduce the chance we re-format the user's `[features]` table (rust-lang/cargo#12191)
- test(add): Remove expensive test (rust-lang/cargo#12188)
- Add a description of `Cargo.lock` conflicts in the Cargo FAQ (rust-lang/cargo#12185)
- refactor(tests): Reduce cargo-add setup load (rust-lang/cargo#12189)
- Warn when an edition 2021 crate is in a virtual workspace with default resolver (rust-lang/cargo#10910)
- refactor(tests): Reduce cargo-remove setup load (rust-lang/cargo#12184)
- chore: Lexicographically order `-Z` flags (rust-lang/cargo#12182)
- chore(ci): remove temporary fix for rustup 1.24.1 (rust-lang/cargo#12180)
- fix: AIX searches dynamic libraries in `LIBPATH`. (rust-lang/cargo#11968)
- deps: remove unused features from windows-sys (rust-lang/cargo#12176)
- Automatically inherit workspace lints when running cargo new/init (rust-lang/cargo#12174)
- Test that the new `debuginfo` options match between cargo and rustc (rust-lang/cargo#12022)

r? `@ghost`
2023-05-31 03:03:10 +00:00
Weihang Lo
5abff3753a
Explicit set workspace.resolver = "1"
rust-lang/cargo#10910 starts emitting warning if resolver is not set
for 2021 edition package. We want to surpress the warning for now.
2023-05-31 00:08:11 +01:00
bors
9610dfe5a9 Auto merge of #109698 - epage:wtf, r=Amanieu
Allow limited access to `OsStr` bytes

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows.  Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544
2023-05-30 21:26:22 +00:00
Mark Rousskov
42e757192d Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
Mark Rousskov
4f9b394c8a Swap out CURRENT_RUSTC_VERSION to 1.71.0 2023-05-30 07:54:29 -04:00
Nilstrieb
7a4006cc52
Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkin
Uplift `clippy::invalid_utf8_in_unchecked` lint

This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints.

## `invalid_from_utf8_unchecked`

(deny-by-default)

The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal.

### Example

```rust
unsafe {
    std::str::from_utf8_unchecked(b"cl\x82ippy");
}
```

### Explanation

Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`.

## `invalid_from_utf8`

(warn-by-default)

The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal.

### Example

```rust
std::str::from_utf8(b"ru\x82st");
```

### Explanation

Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

````@rustbot```` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-30 12:57:38 +02:00
Nilstrieb
18c9baf4fe
Rollup merge of #107916 - reez12g:issue-107040, r=Amanieu
fix comment on Allocator trait

fixes https://github.com/rust-lang/rust/issues/107040
2023-05-30 12:57:38 +02:00
Jubilee Young
472230d192 Remove array_zip
`[T; N]::zip` is "eager" but most zips are mapped.
This causes poor optimization in generated code.
This is a fundamental design issue and "zip" is
"prime real estate" in terms of function names,
so let's free it up again.
2023-05-30 00:40:39 -07:00
reez12g
000cd9b5fb fix comment on Allocator trait 2023-05-30 13:56:57 +09:00
Scott McMurray
11fa1764ee Make TrustedStep require Copy
All the implementations of the trait already are `Copy`, and this seems to be enough to simplify the implementations enough to make the MIR inliner willing to inline basics like `Range::next`.
2023-05-29 13:19:47 -07:00
Matthias Krüger
e71b3b3cfa
Rollup merge of #112045 - Sp00ph:update_current_impl, r=Amanieu
Followup to #111973

I somehow forgot to update the comment on `select_nth_unstable_by_key` in #111973, so this PR fixes that.

r? `@Amanieu`
2023-05-29 04:03:03 +02:00
Markus Everling
448a388387 Update current impl comment for select_nth_unstable_by_key 2023-05-28 16:12:48 +00:00
Markus Everling
62ee9e1d0a Update runtime guarantee for select_nth_unstable 2023-05-28 16:09:55 +00:00
est31
3ab0d90b7e Stabilize String::leak 2023-05-28 12:26:30 +02:00
Matthias Krüger
5a4c04cc2c
Rollup merge of #111656 - finnbear:string_leak_unbounded_lifetime, r=Amanieu
Use an unbounded lifetime in `String::leak`.

Using `'a` instead of `'static` is predicted to make the process of making `String` generic over an allocator easier/less of a breaking change.

See:
- https://github.com/rust-lang/rust/pull/109814#issuecomment-1550164195
- https://github.com/rust-lang/rust/pull/109814#issuecomment-1550250163

ACP: https://github.com/rust-lang/libs-team/issues/109
2023-05-27 20:40:29 +02:00
Matthias Krüger
1d06bb9612
Rollup merge of #108630 - overlookmotel:realloc-docs-fix, r=Amanieu
Fix docs for `alloc::realloc`

Fixes #108546.

Corrects the docs for `alloc::realloc` to bring the safety constraints into line with `Layout::from_size_align_unchecked`'s constraints.
2023-05-27 20:40:27 +02:00
bors
f91b634643 Auto merge of #110975 - Amanieu:panic_count, r=joshtriplett
Rework handling of recursive panics

This PR makes 2 changes to how recursive panics works (a panic while handling a panic).

1. The panic count is no longer used to determine whether to force an immediate abort. This allows code like the following to work without aborting the process immediately:

```rust
struct Double;

impl Drop for Double {
    fn drop(&mut self) {
        // 2 panics are active at once, but this is fine since it is caught.
        std::panic::catch_unwind(|| panic!("twice"));
    }
}

let _d = Double;

panic!("once");
```

Rustc already generates appropriate code so that any exceptions escaping out of a `Drop` called in the unwind path will immediately abort the process.

2. Any panics while the panic hook is executing will force an immediate abort. This is necessary to avoid potential deadlocks like #110771 where a panic happens while holding the backtrace lock. We don't even try to print the panic message in this case since the panic may have been caused by `Display` impls.

Fixes #110771
2023-05-27 15:12:24 +00:00
Amanieu d'Antras
ef7f0e697b Rework handling of recursive panics 2023-05-27 16:35:16 +02:00