Commit Graph

13230 Commits

Author SHA1 Message Date
Gray Olson
921d37dbd5 fix imports 2024-01-07 08:56:07 -08:00
Gray Olson
f2447a6a70 fix typos 2024-01-07 08:56:07 -08:00
Gray Olson
252a83b63f add section on manual owning ptr managed solution via @kpreid 2024-01-07 08:56:07 -08:00
Gray Olson
7c9c71260e improve structural Unpin + formatting 2024-01-07 08:56:06 -08:00
Gray Olson
e2e8746bb6 reword unpin auto impl section 2024-01-07 08:56:06 -08:00
Gray Olson
82a68171d3 fix link in footnote 2024-01-07 08:56:06 -08:00
Gray Olson
bebbe24a63 improve Pin struct docs and add examples 2024-01-07 08:56:05 -08:00
Gray Olson
6818d9278b improve intro and discussion of pinning as library contract 2024-01-07 08:56:05 -08:00
Gray Olson
db5b19e472 improve intro and Unpin-related discussion 2024-01-07 08:56:05 -08:00
Gray Olson
46f9d77bd1 update doubly linked list commentary and fix links 2024-01-07 08:56:04 -08:00
Gray Olson
ec8a01a479 fix one more broken link 2024-01-07 08:56:04 -08:00
Gray Olson
584f0986fc fix broken links 2024-01-07 08:56:04 -08:00
Gray Olson
ba3b9342cc Fix examples, finish polishing 2024-01-07 08:56:04 -08:00
Gray Olson
8241ca6056 mostly done 2024-01-07 08:56:03 -08:00
Miguel Young de la Sota
bfd63b20c8 Rewrite Pin<P> docs to clarify guarantees and uses
The documentation today does not give a complete treatment of pinning
from first principles, which appropriately describes how to design types
that use it, nor does it provide formal statements of the guarantees
users need to be aware of.

This rewrite attempts to address these in a way that makes the concept
more approachable while also making the documentation more normative.
2024-01-07 08:56:03 -08:00
Obei Sideg
a8aa6878f6 Update test for E0796 and static_mut_ref lint 2024-01-07 17:29:25 +03:00
bors
9522993b03 Auto merge of #114205 - the8472:vec-iter-nonnull, r=scottmcm
mark vec::IntoIter pointers as `!nonnull`

This applies the same NonNull optimizations to `vec::IntoIter` as  #113344 did for `slice::Iter`

[Godbolt](https://rust.godbolt.org/z/n1cTea718) showing the test IR on current nightly, note the absence of `!nonnull` on the loads.

r? `@scottmcm`
2024-01-07 09:13:32 +00:00
Michael Goulet
5117dc7a5b
Rollup merge of #119657 - cls:slice_split_once-typo, r=ChrisDenton
Fix typo in docs for slice::split_once, slice::rsplit_once

This fixes a typo in the doc comments for these methods, which I tripped over while reading the docs: "If any matching elements are **resent** in the slice [...]", which is presumably meant to read **present**.

I mentioned this in #112811, the tracking issue for `slice_split_once`, and was encouraged to open a PR.
2024-01-06 21:51:46 -05:00
Michael Goulet
e63a32e622
Rollup merge of #119656 - RalfJung:round-docs, r=Mark-Simulacrum
document rounding behavior of rint/nearbyint for ties

It's not possible to change the rounding mode in Rust, so these intrinsics will always behave like `roundeven`.
2024-01-06 21:51:45 -05:00
The 8472
93b34a5ffa mark vec::IntoIter pointers as !nonnull 2024-01-07 03:44:04 +01:00
The 8472
fd8ba7bc3c typo fix 2024-01-07 03:42:45 +01:00
bors
fde0e98247 Auto merge of #119599 - marthadev:position, r=the8472
Rewrite Iterator::position default impl

Storing the accumulating value outside the fold in an attempt to improve code generation has shown speedups on various handwritten benchmarks, see discussion at #119551.
2024-01-06 22:34:53 +00:00
Matthias Krüger
1d6ab69ab1
Rollup merge of #119624 - petrochenkov:dialoc4, r=compiler-errors
rustc_span: More consistent span combination operations

Also add more tests for using `tt` in addition to `ident`, and some other minor tweaks, see individual commits.

This is a part of https://github.com/rust-lang/rust/pull/119412 that doesn't yet add side tables for metavariable spans.
2024-01-06 16:07:48 +01:00
Matthias Krüger
cda0d08388
Rollup merge of #119595 - mbbill:patch-1, r=Mark-Simulacrum
Fixed ambiguity in hint.rs

Needle and haystack are actually not the same, they remain constant.
2024-01-06 16:07:48 +01:00
Matthias Krüger
923578e6f9
Rollup merge of #118781 - RalfJung:core-panic-feature, r=the8472
merge core_panic feature into panic_internals

I don't know why those are two separate features, but it does not seem intentional. This merge is useful because with https://github.com/rust-lang/rust/pull/118123, panic_internals is recognized as an internal feature, but core_panic is not -- but core_panic definitely should be internal.
2024-01-06 16:07:46 +01:00
AngelicosPhosphoros
8f432d4ae6 Add assume into NonZeroIntX::get
LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments.

Related to https://github.com/rust-lang/rust/issues/119422
Related to https://github.com/llvm/llvm-project/issues/76628
Related to https://github.com/rust-lang/rust/issues/49572
2024-01-06 14:26:37 +01:00
Ralf Jung
96acaff359 document rounding behavior of rint/nearbyint for ties 2024-01-06 12:58:15 +01:00
Connor Lane Smith
099b15f4fc Fix typo in docs for slice::split_once, slice::rsplit_once 2024-01-06 11:51:39 +00:00
Michael Goulet
71610e2eb6
Rollup merge of #119642 - petrochenkov:winstdtest, r=ChrisDenton
library: Fix a symlink test failing on Windows
2024-01-05 23:41:44 -05:00
Michael Goulet
a98993c2ea
Rollup merge of #119640 - petrochenkov:rtstartup, r=Mark-Simulacrum
library: Fix warnings in rtstartup

Not sure why global `deny(warnings)` in bootstrap doesn't apply to this code, it did in the past.
2024-01-05 23:41:44 -05:00
Michael Goulet
d90c702566
Rollup merge of #119216 - weiznich:use_diagnostic_namespace_in_stdlib, r=compiler-errors
Use diagnostic namespace in stdlib

This required a minor fix to have the diagnostics shown in third party crates when the `diagnostic_namespace` feature is not enabled. See 5d63f5d8d1 for details. I've opted for having a single PR for both changes as it's really not that much code. If it is required it should be easy to split up the change into several PR's.

r? `@compiler-errors`
2024-01-05 23:41:41 -05:00
Vadim Petrochenkov
0d70e588e6 library: Fix a symlink test failing on Windows 2024-01-06 01:40:56 +03:00
Vadim Petrochenkov
0489fd05d8 library: Fix warnings in rtstartup 2024-01-06 01:32:03 +03:00
ivmarkov
a10b3cd60f Fix broken build for ESP IDF due to #119026 2024-01-05 19:20:56 +00:00
Vadim Petrochenkov
deecbd80cd library: Add allow(unused_assignments) to custom MIR doctest
The lint is not yet reported due to span issues, but will be reported later.
2024-01-05 19:13:51 +03:00
Michael Goulet
8bea1df254
Rollup merge of #119583 - AngelicosPhosphoros:const_assume, r=RalfJung
Make `intrinsics::assume` const stable

Closes https://github.com/rust-lang/rust/issues/76972
Blocks https://github.com/rust-lang/rust/pull/119452

Approved in https://github.com/rust-lang/rust/pull/119452#issuecomment-1875741678

r? `@RalfJung`
2024-01-05 10:57:23 -05:00
martha
0e9c3d9533 Fix #119551: Rewrite Iterator::position default impl, storing the accumulating value outside of the fold in an attempt to improve code generation
Squashed with: Add inheriting overflow checks back
2024-01-05 16:35:44 +01:00
Georg Semmler
2c3aeea1ba
Replace some usage of #[rustc_on_unimplemented] with
`#[diagnostic::on_unimplemented]`

This commit replaces those `#[rustc_on_unimplemented]` attributes with
their equivalent `#[diagnostic::on_unimplemented]` where this is
supported (So no filter or any extended option)
2024-01-05 15:23:09 +01:00
bors
5113ed28ea Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkin
Merge `unused_tuple_struct_fields` into `dead_code`

This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.

[Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-05 04:51:55 +00:00
Laura Demkowicz-Duffy
648c70ef58 Fix a typo in core::ops::Deref's doc 2024-01-05 02:36:01 +00:00
Ming, Bai
fdf93830c9
Fixed ambiguity in hint.rs
Needle and haystack are actually not the same, they remain constant.
2024-01-04 15:48:22 -08:00
bors
f688dd684f Auto merge of #119569 - matthiaskrgr:rollup-4packja, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag)
 - #119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.)
 - #119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args)
 - #119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans)
 - #119362 (Make `derive(Trait)` suggestion more accurate)
 - #119397 (Recover parentheses in range patterns)
 - #119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`)
 - #119539 (Fix typos)
 - #119540 (Don't synthesize host effect args inside trait object types)
 - #119555 (Add codegen test for RVO on MaybeUninit)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-04 21:44:14 +00:00
AngelicosPhosphoros
59c76fb21b Make intrinsics::assume const stable
Closes https://github.com/rust-lang/rust/issues/76972
Blocks https://github.com/rust-lang/rust/pull/119452

Approved in https://github.com/rust-lang/rust/pull/119452#issuecomment-1875741678
2024-01-04 19:14:31 +01:00
Matthias Krüger
e306cfb115
Rollup merge of #119532 - GKFX:offset-of-parse-expr, r=est31
Make offset_of field parsing use metavariable which handles any spacing

As discussed at and around comments https://github.com/rust-lang/rust/issues/106655#issuecomment-1793485081 and https://github.com/rust-lang/rust/issues/106655#issuecomment-1793774183, the current arguments to offset_of do not accept all the whitespace combinations: `0. 1.1.1` and `0.1.1. 1` are currently treated specially in `tests/ui/offset-of/offset-of-tuple-nested.rs`.

They also do not allow [forwarding individual fields as in](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=444cdf0ec02b99e8fd5fd8d8ecb312ca)
```rust
macro_rules! off {
    ($a:expr) => {
        offset_of!(m::S, 0. $a)
    }
}
```

This PR replaces the macro arguments with `($Container:ty, $($fields:expr)+ $(,)?)` which does allow any arrangement of whitespace that I could come up with and the forwarding of fields example above.

This also allows for array indexing in the future, which I think is the last future extension to the syntax suggested in the offset_of RFC.

Tracking issue for offset_of: #106655
``@rustbot`` label F-offset_of

``@est31``
2024-01-04 15:34:00 +01:00
Matthias Krüger
99a8c339f0
Rollup merge of #119475 - saethlin:remove-libtest-dylib, r=cuviper
Remove libtest's dylib

libtest.so is only used by rustdoc, and tests seem to pass locally with this change. I suppose if this is broken, the only way to find out is to make a PR.
2024-01-04 15:34:00 +01:00
Matthias Krüger
a919d97aaa
Rollup merge of #119325 - RalfJung:custom-mir, r=compiler-errors
custom mir: make it clear what the return block is

Custom MIR recently got support for specifying the "unwind action", so now there's two things coming after the actual call part of `Call` terminators. That's not very self-explaining so I propose we change the syntax to imitate keyword arguments:
```
Call(popped = Vec::pop(v), ReturnTo(drop), UnwindContinue())
```

Also fix some outdated docs and add some docs to `Call` and `Drop`.
2024-01-04 15:33:58 +01:00
Matthias Krüger
d134a4fe60
Rollup merge of #119026 - devnexen:listener_upd, r=Mark-Simulacrum
std::net::bind using -1 for openbsd which in turn sets it to somaxconn.

trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
2024-01-04 08:33:22 +01:00
León Orell Valerian Liehr
a79fccc288
Rollup merge of #119534 - tgross35:thread-local-example-updates, r=JohnTitor
Update `thread_local` examples to use `local_key_cell_methods`

`local_key_cell_methods` has been stable for a while and provides a much less clunky way to interface with thread-local

Additionaly add context to the documentation about why types with interior mutability are needed.

r? libs
2024-01-03 16:08:33 +01:00
León Orell Valerian Liehr
34ef194859
Rollup merge of #119434 - taiki-e:rc-is-dangling, r=Mark-Simulacrum
rc: Take *const T in is_dangling

It is not important which one is used since `is_dangling` does not access memory, but `*const` removes the needs of `*const T` -> `*mut T` casts in `from_raw_in`.
2024-01-03 16:08:25 +01:00
León Orell Valerian Liehr
4e265d9fe0
Rollup merge of #119319 - chfogelman:buffered-file-doc, r=the8472
Document that File does not buffer reads/writes

...and refer to `BufReader`/`BufWriter`.

This is a common source of efficiency issues in Rust programs written naively. Including this information with the `File` docs, and adding a link to the wrapper types, will help discoverability.
2024-01-03 16:08:25 +01:00
Trevor Gross
6f49080fa8 Update thread_local examples to use local_key_cell_methods
`local_key_cell_methods` has been stable for a while and provides a much less
clunky way to interface with thread-local variables.

Additionaly add context to the documentation about why types with interior
mutability are needed.
2024-01-02 22:24:26 -06:00
George Bateman
09bb07e38f
Make offset_of field parsing use metavariable which handles any spacing 2024-01-02 22:18:35 +00:00
Jake Goulding
5772818dc8 Adjust library tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Carter Hunt Fogelman
5cbe41ae9e Document that File does not buffer reads/writes, refer to BufReader/BufWriter 2023-12-31 16:33:46 -08:00
Ben Kimock
c0fa85e9e1 Remove libtest's dylib 2023-12-31 11:18:25 -05:00
bors
a2541e861e Auto merge of #119436 - semarie:openbsd-available_parallelism, r=Mark-Simulacrum
openbsd: available_parallelism: use the right API

use the standard `sysconf(_SC_NPROCESSORS_ONLN)` way to get the number of  available processors (capable of running processes), and fallback to `sysctl([CTL_HW, HW_NCPU])` (number of CPUs configured) only on error.

it permits to differenciate CPUs online (capable of running processes) vs CPUs configured (not necessary  capable of running processes).

while here, use the common code path for BSDs for doing that, and avoid code  duplication.

Problem initially reported to me by Jiri Navratil.
2023-12-30 15:37:26 +00:00
Matthias Krüger
19580d56c2
Rollup merge of #119424 - ojeda:send-sync, r=est31
Primitive docs: fix confusing `Send` in `&T`'s list

The two lists in this document describe what traits are implemented on references when their underlying `T` also implements them. However, while it is true that `T: Send + Sync` implies `&T: Send` (which is what the sentence is trying to explain), it is confusing to have `Send` in the list because `T: Send` is not needed for that. In particular, the "also require" part may be interpreted as "both `T: Send` and `T: Sync` are required".

Instead, move `Send` back to where it was before commit 7a477869b7 ("Makes docs for references a little less confusing"), i.e. to the `&mut` list (where no extra nota is needed, i.e. it fits naturally) and move the `Sync` definition/note to the bottom as something independent.
2023-12-30 11:42:04 +01:00
Matthias Krüger
b594dfa456
Rollup merge of #119386 - Emilgardis:typo-ipaddr-canonical-doc, r=est31
fix typo in `IpAddr::to_canonical`
2023-12-30 11:42:03 +01:00
Matthias Krüger
c67ab2e0b4
Rollup merge of #119158 - JohnTheCoolingFan:arc-weak-clone-pretty, r=cuviper
Clean up alloc::sync::Weak Clone implementation

Since both return points (tail and early return) return the same expression and the only difference is whether inner is available, the code that does the atomic operations and checks on inner was moved into the if body and the only return is at the tail. Original comments preserved.
2023-12-30 11:42:02 +01:00
Sebastien Marie
3633f8ba1c openbsd: available_parallelism: use the right API
use the standard sysconf(_SC_NPROCESSORS_ONLN) way to get the number of 
available processors (capable of running processes), and fallback to 
sysctl([CTL_HW, HW_NCPU]) (number of CPUs configured) only on error.

it permits to differenciate CPUs online vs CPUs configured (and not necessary 
capable of running processes).

while here, use the common code path for BSDs for doing that, and avoid code 
duplication.

Problem initially reported to me by Jiri Navratil.
2023-12-30 09:34:02 +00:00
Taiki Endo
2c23c06c32 rc: Take *const T in is_dangling
It is not important which one is used since `is_dangling` does not access
memory, but `*const` removes the needs of `*const T` -> `*mut T` casts
in `from_raw_in`.
2023-12-30 16:28:00 +09:00
Miguel Ojeda
dd928c8f75 Primitive docs: fix confusing Send in &T's list
The two lists in this document describe what traits are implemented on
references when their underlying `T` also implements them. However,
while it is true that `T: Send + Sync` implies `&T: Send` (which is
what the sentence is trying to explain), it is confusing to have `Send`
in the list because `T: Send` is not needed for that. In particular,
the "also require" part may be interpreted as "both `T: Send` and
`T: Sync` are required".

Instead, move `Send` back to where it was before commit 7a477869b7
("Makes docs for references a little less confusing"), i.e. to the `&mut`
list (where no extra nota is needed, i.e. it fits naturally) and move the
`Sync` definition/note to the bottom as something independent.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-12-29 22:26:23 +01:00
Gurinder Singh
e3aca01343 Italicise "bytes" in the docs of some Vec methods
because on a cursory read it's easy to miss that the limit is
in terms of bytes not no. of elements. The italics should help
with that.
2023-12-29 09:53:29 +05:30
Emil Gardström
12dd5d1d0d
fix typo 2023-12-28 19:05:13 +01:00
Ralf Jung
4bf2794e59 custom mir: better type-checking 2023-12-26 20:15:35 +01:00
Ralf Jung
0f9baa8a31 custom mir: make it clear what the return block is 2023-12-26 20:15:26 +01:00
Michael Goulet
50e380c8f3
Rollup merge of #119235 - Urgau:missing-feature-gate-sanitizer-cfi-cfgs, r=Nilstrieb
Add missing feature gate for sanitizer CFI cfgs

Found during the review of https://github.com/rust-lang/rust/pull/118494 in https://github.com/rust-lang/rust/pull/118494#discussion_r1416079288.

cc `@rcvalle`
2023-12-26 13:29:13 -05:00
bors
e1fadb2c35 Auto merge of #119133 - scottmcm:assert-unchecked, r=thomcc
Add `hint::assert_unchecked`

Libs-API expressed interest, modulo bikeshedding, in https://github.com/rust-lang/libs-team/issues/315#issuecomment-1863159430

I think that means this is good for nightly, since we can always rename it before stabilization.

Tracking issue: https://github.com/rust-lang/rust/issues/119131
2023-12-26 15:31:44 +00:00
bors
a815c3b69c Auto merge of #119313 - matthiaskrgr:rollup-41x48j6, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #119287 (Fix doc typo for read_exact_at)
 - #119294 (fix `./configure --set change-id`)
 - #119303 (Update sysinfo)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-26 08:22:57 +00:00
AlexBuz
3896f0bb9b
Fix doc typo for read_exact_at 2023-12-24 19:28:03 -06:00
lch361
c082c1c4c3 Documented unsafe blocks 2023-12-25 01:59:37 +03:00
lch361
b15e13760a Removed redundant bounds checking at Split's next and next_mut methods 2023-12-25 01:34:07 +03:00
Linus Färnstrand
98899b7131 Stabilize ip_in_core feature 2023-12-24 12:23:50 +01:00
David Carlier
ce5af1c9bc std::net::bind using -1 for openbsd which in turn sets it to somaxconn.
trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
2023-12-24 10:56:22 +00:00
Matthias Krüger
89c3236789
Rollup merge of #119205 - mumbleskates:vecdeque-comment-fix, r=Mark-Simulacrum
fix minor mistake in comments describing VecDeque resizing

Avoiding confusion where one of the items in the deque seems to disappear in two of the three cases
2023-12-24 01:08:09 +01:00
Matthias Krüger
b136919ca6
Rollup merge of #119153 - rursprung:stabilize-file_create_new, r=dtolnay
stabilize `file_create_new`

closes #105135
2023-12-23 20:02:28 +01:00
Michael Goulet
eef023c806
Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-errors,dtolnay
Add `IntoAsyncIterator`

This introduces the `IntoAsyncIterator` trait and uses it in the desugaring of the unstable `for await` loop syntax. This is mostly added for symmetry with `Iterator` and `IntoIterator`.

r? `@compiler-errors`

cc `@rust-lang/libs-api,` `@rust-lang/wg-async`
2023-12-22 21:41:04 -05:00
bors
495203bf61 Auto merge of #119211 - rust-lang:pa-master-1.77, r=Mark-Simulacrum
Bump stage0 to 1.76 beta

r? `@Mark-Simulacrum`
2023-12-23 00:26:47 +00:00
Urgau
c88b021782 Adjust the std library for sanitizer_cfi cfgs changes 2023-12-23 01:01:09 +01:00
Eric Holk
acb6f17adf
Use IntoAsyncIterator in for await loop desugaring 2023-12-22 11:01:06 -08:00
Eric Holk
8e34391d6a
Add IntoAsyncIterator 2023-12-22 11:01:05 -08:00
bors
208dd2032b Auto merge of #118847 - eholk:for-await, r=compiler-errors
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue.

r? `@compiler-errors`
2023-12-22 14:17:10 +00:00
Pietro Albini
f9f5840eb4
update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
Pietro Albini
c00486c9bb
update version placeholders 2023-12-22 11:01:42 +01:00
Kent Ross
f2e711e4c2 fix minor mistake in comments describing VecDeque resizing 2023-12-21 15:20:14 -08:00
bors
5ac4c8a63e Auto merge of #119037 - RalfJung:repr-c-abi-mismatch, r=scottmcm
do not allow ABI mismatches inside repr(C) types

In https://github.com/rust-lang/rust/pull/115476 we allowed ABI mismatches inside `repr(C)` types. This wasn't really discussed much; I added it because from how I understand calling conventions, this should actually be safe in practice. However I entirely forgot to actually allow this in Miri, and in the mean time I have learned that too much ABI compatibility can be a problem for CFI (it can reject fewer calls so that gives an attacker more room to play with).

So I propose we take back that part about ABI compatibility in `repr(C)`. It is anyway something that C and C++ do not allow, as far as I understand.

In the future we might want to introduce a class of ABI compatibilities where we say "this is a bug and it may lead to aborting the process, but it won't lead to arbitrary misbehavior -- worst case it'll just transmute the arguments from the caller type to the callee type". That would give CFI leeway to reject such calls without introducing the risk of arbitrary UB. (The UB can still happen if the transmute leads to bad results, of course, but it wouldn't be due to ABI weirdness.)

#115476 hasn't reached beta yet so if we land this before Dec 22nd we can just pretend this all never happened. ;)  Otherwise we should do a beta backport (of the docs change at least).

Cc `@rust-lang/opsem` `@rust-lang/types`
2023-12-20 18:04:40 +00:00
JohnTheCoolingFan
0453d5fe6f
Cleaned up alloc::sync::Weak Clone implementation
Since both return points (tail and early return) return the same
expression and the only difference is whether inner is available, the
code that does the atomic operations and checks on inner was moved into
the if body and the only return is at the tail. Original comments
preserved.
2023-12-20 12:13:34 +03:00
Ralph Ursprung
62d53211b0
stabilize file_create_new
closes #105135
2023-12-20 08:45:46 +01:00
bors
51c0db6a91 Auto merge of #106790 - the8472:rawvec-niche, r=scottmcm
add more niches to rawvec

Previously RawVec only had a single niche in its `NonNull` pointer. With this change it now has `isize::MAX` niches since half the value-space of the capacity field is never needed, we can't have a capacity larger than isize::MAX.
2023-12-20 02:19:10 +00:00
Scott McMurray
7556d6f61b Add hint::assert_unchecked 2023-12-19 13:56:50 -08:00
AngelicosPhosphoros
1c5b2ce67c Docs: Use non-SeqCst in module example of atomics
I done this for this reasons:
1. The example now shows that there is more Orderings than just SeqCst.
2. People who would copy from example would now have more suitable orderings for the job.
3. SeqCst is both much harder to reason about and not needed in most situations.

IMHO, we should encourage people to think and use memory orderings that is suitable to task instead of blindly defaulting to SeqCst.
2023-12-19 22:19:03 +01:00
Eric Holk
97df0d3657
Desugar for await loops 2023-12-19 12:26:27 -08:00
bors
558ac1cfb7 Auto merge of #118853 - calebzulawski:simd-intrinsics, r=RalfJung
Add core::intrinsics::simd

Intended to close rust-lang/portable-simd#381.

r? ralfjung
2023-12-19 12:42:33 +00:00
Caleb Zulawski
e61aaf91c8 Disable new intrinsics for bootstrap 2023-12-18 21:41:50 -05:00
Christiaan Dirkx
605504c5bf Add Ipv6Addr::is_ipv4_mapped
This change consists of cherry-picking the content from the original
PR[1], which got closed due to inactivity, and applying the following
changes:

* Resolving merge conflicts (obviously)
* Linked to to_ipv4_mapped instead of to_ipv4 in the documentation (seems
  more appropriate)
* Added the must_use and rustc_const_unstable attributes the original
  didn't have

I think it's a reasonably useful method.

[1] https://github.com/rust-lang/rust/pull/86490
2023-12-18 13:54:26 +01:00
Matthias Krüger
10ad10ee2a
Rollup merge of #119051 - ChrisDenton:wine, r=workingjubilee
Replace `FileAllocationInfo` with `FileEndOfFileInfo`

This fixes WINE support
2023-12-18 08:08:24 +01:00
Caleb Zulawski
d655dd6dca Add new intrinsics 2023-12-17 23:00:29 -05:00
Caleb Zulawski
4767aaf826 Further explain semantics 2023-12-17 21:17:00 -05:00
Caleb Zulawski
e245bafa9c Apply suggestions from code review
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-12-17 21:17:00 -05:00
Caleb Zulawski
71a5698989 Improve simd_bitmask documentation and other minor fixes 2023-12-17 21:17:00 -05:00
Caleb Zulawski
560ac23b70 State type requirements first 2023-12-17 21:17:00 -05:00
Caleb Zulawski
1fd7de062e Clarify UB and improve grammar
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-12-17 21:17:00 -05:00
Caleb Zulawski
ef4cf01542 Add core::intrinsics::simd 2023-12-17 21:16:59 -05:00
bors
43dcc9b786 Auto merge of #114962 - darklyspaced:debug, r=est31
adds a column number to `dbg!()`

this would be very nice to have for a few reasons:
1. the rfc, when deciding not to add column numbers to macro, failed to acknowledge any potential ambiguous cases -- such as the one provided in #114910 -- which do exist
2. would be able to consistently and easily jump directly to the `dbg!()` regardless of the sutation
3. takes up, at a maximum, 3 characters of _horizontal_ screen space

fixes #114910
2023-12-17 23:01:18 +00:00
Chris Denton
e585b0ed58
Use FileEndOfFileInfo, not FileAllocationInfo
This fixes WINE support
2023-12-17 17:57:33 +00:00
Ralf Jung
c7e3b3f84c do not allow ABI mismatches inside repr(C) types 2023-12-17 09:34:25 +01:00
bors
5e7025419d Auto merge of #118830 - GuillaumeGomez:env-tracked_env, r=Nilstrieb
Add support for `--env` on `tracked_env::var`

Follow-up of https://github.com/rust-lang/rust/pull/118368.
Part of Part of https://github.com/rust-lang/rust/issues/80792.

It adds support of the `--env` option for proc-macros through `tracked_env::var`.

r? `@Nilstrieb`
2023-12-17 04:23:08 +00:00
Jubilee
6c2f00fbd7
Rollup merge of #118851 - bzEq:std-xcoff, r=Mark-Simulacrum
[std] Add xcoff in object's feature list

object-0.32.0 has supported XCOFF format. And backtrace in submodule has been updated to support XCOFF and AIX. Add `xcoff` to supported feature list to make backtrace built on AIX.
2023-12-15 21:32:58 -08:00
Jubilee
15e84ebc7b
Rollup merge of #118523 - okaneco:trim_ascii, r=Mark-Simulacrum
Add ASCII whitespace trimming functions to `&str`

- Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to `&str` for trimming ASCII whitespace
- Add `#[inline]` to `[u8]` `trim_ascii` functions

These functions are feature-gated by `#![feature(byte_slice_trim_ascii)]` #94035
2023-12-15 21:32:57 -08:00
Jubilee
4b447b8bb7
Rollup merge of #118998 - jstasiak:improve-doc, r=workingjubilee
Link to is_benchmark from the Ipv6Addr::is_global documentation

All other relevant is_* methods are mentioned in the list of addresses here, is_benchmarking has been the only one missing.
2023-12-15 14:08:18 -08:00
Jubilee
5e85fece3a
Rollup merge of #118956 - danielhuang:patch-2, r=workingjubilee
Make CStr documentation consistent ("nul" instead of "null")

"nul" is used in method names and appears more often in the documentation than "null", so make all instances "nul" to keep it consistent.
2023-12-15 14:08:16 -08:00
Jubilee
1d54949765
Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillot
Collect lang items from AST, get rid of `GenericBound::LangItemTrait`

r? `@cjgillot`
cc #115178

Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change:
1. A lot of `rustc_ast_lowering` for things like expr `..`
2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently.
3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem`

Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15 14:08:15 -08:00
Jakub Stasiak
47282799da Add link to is_benchmark from the Ipv6Addr::is_global documentation
All other relevant is_* methods are mentioned in the list of addresses
here, is_benchmarking has been the only one missing.
2023-12-15 20:53:54 +01:00
Matthias Krüger
ea6daca3cb
Rollup merge of #118234 - tgross35:type_name_of_value, r=dtolnay
Stabilize `type_name_of_val`

Make the following API stable:

```rust
// in core::any
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str
```

This is a convenience method to get the type name of a value, as opposed to `type_name` that takes a type as a generic.

Const stability is not added because this relies on `type_name` which is also not const. That has a blocking issue https://github.com/rust-lang/rust/issues/97156.

Wording was also changed to direct most of the details to `type_name` so we don't have as much duplicated documentation.

Fixes tracking issue #66359.

There were two main concerns in the tracking issue:

1. Naming: `type_name_of` and `type_name_of_val` seem like the only mentioned options. Differences in opinion here come from `std::mem::{size_of, align_of, size_of_val, align_of_val}`. This PR leaves the name as `type_name_of_val`, but I can change if desired since it is pretty verbose.
2. What this displays for `&dyn`: I don't think that having `type_name_of_val` function resolve those is worth the headache it would be, see https://github.com/rust-lang/rust/issues/66359#issuecomment-1718480774 for some workarounds. I also amended the docs wording to leave it open-ended, in case we have means to change that behavior in the future.

``@rustbot`` label -T-libs +T-libs-api +needs-fcp
r? libs-api
2023-12-15 20:19:53 +01:00
Maybe Waffle
b863e9ba57
Stabilize ptr::{from_ref, from_mut} 2023-12-15 08:34:59 -08:00
Cameron Steffen
04fafd69de Cfg remove lang items in doctest 2023-12-15 16:17:28 +00:00
Chris Denton
ab716d0635
Use assert_unsafe_precondition for char::from_u32_unchecked
Co-Authored-By: joboet <jonasboettiger@icloud.com>
2023-12-15 15:15:24 +00:00
bors
cca2bda07e Auto merge of #118966 - matthiaskrgr:rollup-sdvjwy6, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #116888 (Add discussion that concurrent access to the environment is unsafe)
 - #118888 (Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir`)
 - #118929 (coverage: Tidy up early parts of the instrumentor pass)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-15 06:52:44 +00:00
Matthias Krüger
44fd74aede
Rollup merge of #116888 - tbu-:pr_unsafe_env, r=Amanieu
Add discussion that concurrent access to the environment is unsafe

The bug report #27970 has existed for 8 years, the actual bug dates back to Rust pre-1.0. I documented it since it's in the interest of the user to be aware of it. The note can be removed once #27970 is fixed.
2023-12-15 06:50:17 +01:00
bors
1559dd2dbf Auto merge of #118770 - saethlin:fix-inline-never-uses, r=nnethercote
Fix cases where std accidentally relied on inline(never)

This PR increases the power of `-Zcross-crate-inline-threshold=always` so that it applies through `#[inline(never)]`. Note that though this is called "cross-crate-inlining" in this case especially it is _just_ lazy per-CGU codegen. The MIR inliner and LLVM still respect the attribute as much as they ever have.

Trying to bootstrap with the new `-Zcross-crate-inline-threshold=always` change revealed two bugs:

We have special intrinsics `assert_inhabited`, `assert_zero_valid`, and `assert_mem_uniniitalized_valid` which codegen backends will lower to nothing or a call to `panic_nounwind`.  Since we may not have any call to `panic_nounwind` in MIR but emit one anyway, we need to specially tell `MirUsedCollector` about this situation.

`#[lang = "start"]` is special-cased already so that `MirUsedCollector` will collect it, but then when we make it cross-crate-inlinable it is only assigned to a CGU based on whether `MirUsedCollector` saw a call to it, which of course we didn't.

---

I started looking into this because https://github.com/rust-lang/rust/pull/118683 revealed a case where we were accidentally relying on a function being `#[inline(never)]`, and cranking up cross-crate-inlinability seems like a way to find other situations like that.

r? `@nnethercote` because I don't like what I'm doing to the CGU partitioning code here but I can't come up with something much better
2023-12-15 04:54:14 +00:00
Daniel Huang
f2f9b1d82a
Update c_str.rs 2023-12-14 19:08:36 -05:00
Daniel Huang
d031795c81
Update c_str.rs 2023-12-14 19:05:03 -05:00
Urgau
3ea1331f51 Fix target_feature config in portable-simd 2023-12-14 14:50:32 +01:00
Ben Kimock
e559172249 Fix cases where std accidentally relied on inline(never) 2023-12-14 08:30:36 -05:00
bors
1aa6aefdc9 Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkin
use c literals in compiler and library

Relands refreshed https://github.com/rust-lang/rust/pull/111647
2023-12-14 11:14:03 +00:00
Tobias Bucher
2093d0c58e Reformulate std::env::{set,remove}_env as safety note 2023-12-13 12:49:38 +01:00
bors
f651b436ce Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkov
[`RFC 3086`] Attempt to try to resolve blocking concerns

Implements what is described at https://github.com/rust-lang/rust/issues/83527#issuecomment-1744822345 to hopefully make some progress.

It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities.

`@rustbot` labels +I-compiler-nominated
2023-12-13 06:37:08 +00:00
bors
9f1bfe53b6 Auto merge of #118900 - workingjubilee:rollup-wkv9hq1, r=workingjubilee
Rollup of 10 pull requests

Successful merges:

 - #118858 (Remove dead codes in core)
 - #118864 (Fix alignment passed down to LLVM for simd_masked_load)
 - #118872 (Add rustX check to codeblock attributes lint)
 - #118873 (fix `waker_getters` tracking issue number)
 - #118884 (NFC: simplify merging of two vecs)
 - #118885 (clippy::complexity fixes)
 - #118886 (Clean up variables in `search.js`)
 - #118887 (Typo)
 - #118889 (more clippy::complexity fixes)
 - #118891 (Actually parse async gen blocks correctly)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-13 04:38:30 +00:00
Jubilee
18e0966f39
Rollup merge of #118873 - lukas-code:fix_waker_getter_tracking_issue_number, r=workingjubilee
fix `waker_getters` tracking issue number

The feature currently links to the closed issue https://github.com/rust-lang/rust/issues/87021. Make it link to the tracking issue https://github.com/rust-lang/rust/issues/96992 instead.
2023-12-12 18:48:52 -08:00
Jubilee
2d1d443d7f
Rollup merge of #118858 - mu001999:dead_code/clean, r=cuviper
Remove dead codes in core

Detected by #118257
2023-12-12 18:48:50 -08:00
bors
77d1699756 Auto merge of #116438 - ChrisDenton:truncate, r=thomcc
Windows: Allow `File::create` to work on hidden files

This makes `OpenOptions::new().write(true).create(true).truncate(true).open(&path)` work if the path exists and is a hidden file. Previously it would fail with access denied.

This makes it consistent with `OpenOptions::new().write(true).truncate(true).open(&path)` (note the lack of `create`) which does not have this restriction. It's also more consistent with other platforms.

Fixes #115745 (see that issue for more details).
2023-12-13 02:27:12 +00:00
Kai Luo
9f64023096 Use different cfg for AIX 2023-12-13 10:15:27 +08:00
okaneco
e4808afe8e Add ASCII whitespace trimming functions to &str
Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to
`&str` for trimming ASCII whitespace under the `byte_slice_trim_ascii`
feature gate.
Add `inline` to `[u8]` `trim_ascii` functions
2023-12-12 12:53:59 -05:00
Lukas Markeffsky
04f3adb4a7 fix waker_getters tracking issue number 2023-12-12 14:38:13 +01:00
darklyspaced
cbb36d808b added column number to dbg!() 2023-12-12 18:12:23 +08:00
r01and
6c0dbb8cc6
Remove dead codes in core 2023-12-12 07:03:37 +00:00
Kai Luo
d2402e3f0d Add xcoff support 2023-12-12 10:20:06 +08:00
The 8472
6a2f44e9d8 add comment to RawVec::cap field 2023-12-11 23:38:48 +01:00
The 8472
502df1b7d4 add more niches to rawvec 2023-12-11 23:38:48 +01:00
Guillaume Gomez
6ce2fefea6 Add support for --env on tracked_env::var 2023-12-11 16:44:33 +01:00
bors
8a3765582c Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
bors
ff2c56344c Auto merge of #118823 - GuillaumeGomez:rollup-6v51gxv, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #118802 (Remove edition umbrella features.)
 - #118807 (Remove an allocation in min_stack)
 - #118812 (rustdoc-search: do not treat associated type names as types)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-11 12:33:04 +00:00
Guillaume Gomez
f712d73108
Rollup merge of #118807 - SUPERCILEX:allo, r=the8472
Remove an allocation in min_stack
2023-12-11 11:40:37 +01:00
bors
6f40082313 Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, r=compiler-errors
Restore `const PartialEq`

And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now.

r? `@compiler-errors`
2023-12-11 10:34:51 +00:00
bors
e299752868 Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrum
guarantee that char and u32 are ABI-compatible

In https://github.com/rust-lang/rust/pull/116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent.

This is a new stable guarantee, so it will need t-lang approval.
2023-12-11 04:13:19 +00:00
Nicholas Nethercote
925f7fad57 Improve print_tts by changing tokenstream::Spacing.
`tokenstream::Spacing` appears on all `TokenTree::Token` instances,
both punct and non-punct. Its current usage:
- `Joint` means "can join with the next token *and* that token is a
  punct".
- `Alone` means "cannot join with the next token *or* can join with the
  next token but that token is not a punct".

The fact that `Alone` is used for two different cases is awkward.
This commit augments `tokenstream::Spacing` with a new variant
`JointHidden`, resulting in:
- `Joint` means "can join with the next token *and* that token is a
  punct".
- `JointHidden` means "can join with the next token *and* that token is a
  not a punct".
- `Alone` means "cannot join with the next token".

This *drastically* improves the output of `print_tts`. For example,
this:
```
stringify!(let a: Vec<u32> = vec![];)
```
currently produces this string:
```
let a : Vec < u32 > = vec! [] ;
```
With this PR, it now produces this string:
```
let a: Vec<u32> = vec![] ;
```
(The space after the `]` is because `TokenTree::Delimited` currently
doesn't have spacing information. The subsequent commit fixes this.)

The new `print_tts` doesn't replicate original code perfectly. E.g.
multiple space characters will be condensed into a single space
character. But it's much improved.

`print_tts` still produces the old, uglier output for code produced by
proc macros. Because we have to translate the generated code from
`proc_macro::Spacing` to the more expressive `token::Spacing`, which
results in too much `proc_macro::Along` usage and no
`proc_macro::JointHidden` usage. So `space_between` still exists and
is used by `print_tts` in conjunction with the `Spacing` field.

This change will also help with the removal of `Token::Interpolated`.
Currently interpolated tokens are pretty-printed nicely via AST pretty
printing. `Token::Interpolated` removal will mean they get printed with
`print_tts`. Without this change, that would result in much uglier
output for code produced by decl macro expansions. With this change, AST
pretty printing and `print_tts` produce similar results.

The commit also tweaks the comments on `proc_macro::Spacing`. In
particular, it refers to "compound tokens" rather than "multi-char
operators" because lifetimes aren't operators.
2023-12-11 09:19:09 +11:00
Alex Saveau
af8dfde7f9
Remove an allocation in min_stack
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-12-10 13:28:59 -08:00
bors
84f6130fe3 Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkov
remove redundant imports

detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.

r? `@petrochenkov`
2023-12-10 11:55:48 +00:00
David Thomas
17edbe7cad Use AtomicU8 instead of AtomicUsize in backtrace.rs 2023-12-10 11:36:56 +00:00
Deadbeef
f635cd2e82 Restore const PartialEq 2023-12-10 09:30:07 +00:00
bors
c1a3919378 Auto merge of #118792 - naglis:fix-mutex-doc-typo, r=workingjubilee
Fix typo in `std::sync::Mutex` example
2023-12-10 09:02:29 +00:00
bors
61afc9c928 Auto merge of #116949 - hamza1311:stablize-arc_unwrap_or_clone, r=dtolnay
Stablize arc_unwrap_or_clone

Fixes: #93610

This likely needs FCP. I created this PR as it's stabilization is trivial and FCP can be just conducted here. Not sure how to ping the libs API team (last attempt didn't work apparently according to GH UI)
2023-12-10 05:01:00 +00:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
naglis
7d50a39763 Fix typo in std::sync::Mutex example 2023-12-10 02:21:53 +02:00
Ralf Jung
af4913fcf4 merge core_panic feature into panic_internals 2023-12-09 14:49:00 +01:00
bors
608f32435a Auto merge of #117873 - quininer:android-emutls, r=Amanieu
Add emulated TLS support

This is a reopen of https://github.com/rust-lang/rust/pull/96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful.

Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.

r? `@Amanieu`
2023-12-09 05:32:35 +00:00
bors
1a3aa4ad14 Auto merge of #114136 - TennyZhuang:linked-list-retain, r=thomcc
add LinkedList::{retain,retain_mut}

Implement #114135

The API is consistent with other collections.
2023-12-09 02:38:45 +00:00
Michael Goulet
96bb542a31 Implement async gen blocks 2023-12-08 17:23:25 +00:00
David Carlier
bc6a5c71b6 std: getrandom simplification for freebsd.
it is in the libcs' crate too now.
2023-12-08 15:26:16 +00:00
Matthias Krüger
982a238ac9
Rollup merge of #118581 - ianrrees:add-drop-note-to-once_lock, r=workingjubilee
OnceLock: Add note about drop and statics

Hi!  Just a minor documentation addition, I've attempted to build docs locally but ran in to issues, so am not 100% sure this change will render correctly.
2023-12-08 06:44:41 +01:00
Matthias Krüger
992f7ee5fd
Rollup merge of #118505 - CLEckhardt:update_ip_addr_bits_docs, r=cuviper
Elaborate on ip_addr bit conversion endianness

Adds explanation of how endianness is handled when converting `Ipv4Addr` and `Ipv6Addr` to and from bits. This is intended to unblock stabilization of the affected methods.

Addresses #113744
2023-12-08 06:44:41 +01:00
Ian Rees
88fccc465f OnceLock: Rework example, statics aren't dropped 2023-12-08 09:49:54 +13:00
Martin Nordholts
12e6bcfcab libtest: Fix padding of benchmarks run as tests
Before this fix we applied padding before manually doing what
`convert_benchmarks_to_tests()` does. Instead use
`convert_benchmarks_to_tests()` if applicable and then apply padding
afterwards so it becomes correct. (Benches should only be padded when
run as benches to make it easy to compare the benchmark numbers.)
2023-12-07 19:24:58 +01:00
Chris Eckhardt
c3bb1b50a5 Elaborate on ip_addr bit conversion endianness
Adds explanation of how endianness is handled when converting `Ipv4Addr`
and `Ipv6Addr` to and from bits.

Addresses #113744
2023-12-07 09:16:03 -06:00
bors
568f6a8641 Auto merge of #116565 - Sword-Destiny:master, r=Amanieu
add teeos std impl

add teeos std library implement.

this MR is draft untill the libc update to 0.2.150

this MR is the final step for suppot rust in teeos.
first step(add target): https://github.com/rust-lang/rust/pull/113480
second step(add teeos libc): https://github.com/rust-lang/libc/pull/3333
2023-12-07 05:22:21 +00:00
袁浩
e353eb91fb add teeos std impl
Signed-off-by: 袁浩 <yuanhao34@huawei.com>
2023-12-07 10:33:03 +08:00
bors
c9d85d67c4 Auto merge of #117960 - zhiqiangxu:dry, r=workingjubilee
chore: avoid duplicate code in `Weak::inner`
2023-12-07 02:27:41 +00:00
Matthias Krüger
2f71a448c0
Rollup merge of #118669 - klensy:comment-fix, r=workingjubilee
library: fix comment about const assert in win api

Resolves [comment ](https://github.com/rust-lang/rust/pull/116816#discussion_r1415869524)

r? `@workingjubilee`
2023-12-06 17:22:00 +01:00
Matthias Krüger
49d6594278
Rollup merge of #117563 - 0xalpharush:docs/into-raw, r=workingjubilee
docs: clarify explicitly freeing heap allocated memory

The documentation for `Box::into_raw` didn't mention `drop` and wondered if I was doing something wrong. Based off [this](https://stackoverflow.com/questions/75441199/rust-how-do-i-correctly-free-heap-allocated-memory), I think it's helpful to include the more concise yet explicit way to free heap allocated memory. This is my first rust PR and I went through https://std-dev-guide.rust-lang.org/development/, but let me know if I missed something :)
2023-12-06 17:21:57 +01:00
quininer
e5b76892cc Add emulated TLS support
Currently LLVM uses emutls by default
for some targets (such as android, openbsd),
but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify
    that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names
    to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated`
    to explicitly specify whether to generate emutls.
2023-12-07 00:21:32 +08:00
klensy
7ff9648808 library: fix comment about const assert in win api 2023-12-06 13:52:30 +03:00
bors
15bb3e204a Auto merge of #118460 - the8472:fix-vec-realloc, r=saethlin
Fix in-place collect not reallocating when necessary

Regression introduced in https://github.com/rust-lang/rust/pull/110353.
This was [caught by miri](https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Cron.20Job.20Failure.20.28miri-test-libstd.2C.202023-11.29/near/404764617)

r? `@saethlin`
2023-12-06 08:45:11 +00:00
Urgau
5e1bfb538f Adjust tests for newly added ambiguous_wide_pointer_comparisons lint 2023-12-06 09:03:48 +01:00
Urgau
30c7b18d25 Allow ambiguous_wide_pointer_comparisons lint for std methods 2023-12-06 09:03:48 +01:00
bors
1dd4db5062 Auto merge of #118655 - compiler-errors:rollup-vrngyzn, r=compiler-errors
Rollup of 9 pull requests

Successful merges:

 - #117793 (Update variable name to fix `unused_variables` warning)
 - #118123 (Add support for making lib features internal)
 - #118268 (Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always)
 - #118346 (Add `deeply_normalize_for_diagnostics`, use it in coherence)
 - #118350 (Simplify Default for tuples)
 - #118450 (Use OnceCell in cell module documentation)
 - #118585 (Fix parser ICE when recovering `dyn`/`impl` after `for<...>`)
 - #118587 (Cleanup error handlers some more)
 - #118642 (bootstrap(builder.rs): Don't explicitly warn against `semicolon_in_expressions_from_macros`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-06 04:20:51 +00:00
bors
84a554cda9 Auto merge of #117072 - betrusted-io:unwinding-crate-support, r=cuviper
Use `unwinding` crate for unwinding on Xous platform

This patch adds support for using [unwinding](https://github.com/nbdd0121/unwinding) on platforms where libunwinding isn't viable. An example of such a platform is `riscv32imac-unknown-xous-elf`.

### Background

The Rust project maintains a fork of llvm at [llvm-project](https://github.com/rust-lang/llvm-project/) where it applies patches on top of the llvm project. This mostly seems to be to get unwinding support for the SGX project, and there may be other patches that I'm unaware of.

There is a lot of machinery in the build system to support compiling `libunwind` on other platforms, and I needed to add additional patches to llvm in order to add support for Xous.

Rather than continuing down this path, it seemed much easier to use a Rust-based library. The `unwinding` crate by `@nbdd0121` fits this description perfectly.

### Future work

This could potentially replace the custom patches for `libunwind` on other platforms such as SGX, and could enable unwinding support on many more exotic platforms.

### Anti-goals

This is not designed to replace `libunwind` on tier-one platforms or those where unwinding support already exists. There is already a well-established approach for unwinding there. Instead, this aims to enable unwinding on new platforms where C++ code may be difficult to compile.
2023-12-06 02:23:01 +00:00
Sean Cross
a6b8de68a6 std: xous: take eh_frame address from main args
The main() function takes an argument that contains the eh_frame
address. Implement `unwinding` support by looking for unwinding data at
this address.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-06 09:07:07 +08:00
zhiqiangxu
75d76c8ffe Don't repeat yourself 2023-12-06 09:02:19 +08:00
bors
28968414c5 Auto merge of #118547 - alexcrichton:invert-common-net-inclusion, r=workingjubilee
std: Invert logic for inclusion of `sys_common::net`

The `library/std/src/sys_common/net.rs` module is intended to define common implementations of networking-related APIs across a variety of platforms that share similar APIs (e.g. Berkeley-style sockets and all). This module is not included for more fringe targets however such as UEFI or "unknown" targets to libstd (those classified as `restricted-std`). Previously the `sys_common/net.rs` file was set up such that an allow-list indicated it shouldn't be used. This commit inverts the logic to have an allow-list of when it should be used instead.

The goal of this commit is to make it a bit easier to experiment with a new Rust target. Currently more esoteric targets are required to get an exception in this `cfg_if` block to use `crate::sys::net` such as for unsupported targets. With this inversion of logic only targets which actually support networking will be listed, where most of those are lumped under `cfg(unix)`.

Given that this change is likely to cause some breakage for some target by accident I've attempted to be somewhat robust with this by following these steps to defining the new predicate for inverted logic.

1. Take all supported targets and filter out all `cfg(unix)` ones as these should all support `sys_common/net.rs`.
2. Take remaining targets and filter out `cfg(windows)` ones.
3. The remaining dozen-or-so targets were all audited by hand. Mostly this included `target_os = "hermit"` and `target_os = "solid_asp3"` which required an allow-list entry, but remaining targets were all already excluded (didn't use `sys_common/net.rs` so they were left out.

If this causes breakage it should be relatively easy to fix and I'd be happy to follow-up with any PRs necessary.
2023-12-06 00:04:28 +00:00
bors
e9013ac0e4 Auto merge of #118273 - AngelicosPhosphoros:dedup_2_loops_version_77772_2, r=the8472
Split `Vec::dedup_by` into 2 cycles

First cycle runs until we found 2 same elements, second runs after if there any found in the first one. This allows to avoid any memory writes until we found an item which we want to remove.

This leads to significant performance gains if all `Vec` items are kept: -40% on my benchmark with unique integers.

Results of benchmarks before implementation (including new benchmark where nothing needs to be removed):
 *   vec::bench_dedup_all_100                 74.00ns/iter  +/- 13.00ns
 *   vec::bench_dedup_all_1000               572.00ns/iter +/- 272.00ns
 *   vec::bench_dedup_all_100000              64.42µs/iter  +/- 19.47µs
 *   __vec::bench_dedup_none_100                67.00ns/iter  +/- 17.00ns__
 *   __vec::bench_dedup_none_1000              662.00ns/iter  +/- 86.00ns__
 *   __vec::bench_dedup_none_10000               9.16µs/iter   +/- 2.71µs__
 *   __vec::bench_dedup_none_100000             91.25µs/iter   +/- 1.82µs__
 *   vec::bench_dedup_random_100             105.00ns/iter  +/- 11.00ns
 *   vec::bench_dedup_random_1000            781.00ns/iter  +/- 10.00ns
 *   vec::bench_dedup_random_10000             9.00µs/iter   +/- 5.62µs
 *   vec::bench_dedup_random_100000          449.81µs/iter  +/- 74.99µs
 *   vec::bench_dedup_slice_truncate_100     105.00ns/iter  +/- 16.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.65µs/iter +/- 481.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.33µs/iter   +/- 5.23µs
 *   vec::bench_dedup_slice_truncate_100000  501.12µs/iter  +/- 46.97µs

Results after implementation:
 *   vec::bench_dedup_all_100                 75.00ns/iter   +/- 9.00ns
 *   vec::bench_dedup_all_1000               494.00ns/iter +/- 117.00ns
 *   vec::bench_dedup_all_100000              58.13µs/iter   +/- 8.78µs
 *   __vec::bench_dedup_none_100                52.00ns/iter  +/- 22.00ns__
 *   __vec::bench_dedup_none_1000              417.00ns/iter +/- 116.00ns__
 *   __vec::bench_dedup_none_10000               4.11µs/iter +/- 546.00ns__
 *   __vec::bench_dedup_none_100000             40.47µs/iter   +/- 5.36µs__
 *   vec::bench_dedup_random_100              77.00ns/iter  +/- 15.00ns
 *   vec::bench_dedup_random_1000            681.00ns/iter  +/- 86.00ns
 *   vec::bench_dedup_random_10000            11.66µs/iter   +/- 2.22µs
 *   vec::bench_dedup_random_100000          469.35µs/iter  +/- 20.53µs
 *   vec::bench_dedup_slice_truncate_100     100.00ns/iter   +/- 5.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.55µs/iter +/- 224.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.95µs/iter   +/- 2.59µs
 *   vec::bench_dedup_slice_truncate_100000  492.85µs/iter  +/- 72.84µs

Resolves #77772

P.S. Note that this is same PR as #92104 I just missed review then forgot about it.
Also, I cannot reopen that pull request so I am creating a new one.
I responded to remaining questions directly by adding commentaries to my code.
2023-12-05 21:40:02 +00:00
AngelicosPhosphoros
964df019d2 Split Vec::dedup_by into 2 cycles
First cycle runs until we found 2 same elements, second runs after if there any found in the first one. This allows to avoid any memory writes until we found an item which we want to remove.

This leads to significant performance gains if all `Vec` items are kept: -40% on my benchmark with unique integers.

Results of benchmarks before implementation (including new benchmark where nothing needs to be removed):
 *   vec::bench_dedup_all_100                 74.00ns/iter  +/- 13.00ns
 *   vec::bench_dedup_all_1000               572.00ns/iter +/- 272.00ns
 *   vec::bench_dedup_all_100000              64.42µs/iter  +/- 19.47µs
 *   __vec::bench_dedup_none_100                67.00ns/iter  +/- 17.00ns__
 *   __vec::bench_dedup_none_1000              662.00ns/iter  +/- 86.00ns__
 *   __vec::bench_dedup_none_10000               9.16µs/iter   +/- 2.71µs__
 *   __vec::bench_dedup_none_100000             91.25µs/iter   +/- 1.82µs__
 *   vec::bench_dedup_random_100             105.00ns/iter  +/- 11.00ns
 *   vec::bench_dedup_random_1000            781.00ns/iter  +/- 10.00ns
 *   vec::bench_dedup_random_10000             9.00µs/iter   +/- 5.62µs
 *   vec::bench_dedup_random_100000          449.81µs/iter  +/- 74.99µs
 *   vec::bench_dedup_slice_truncate_100     105.00ns/iter  +/- 16.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.65µs/iter +/- 481.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.33µs/iter   +/- 5.23µs
 *   vec::bench_dedup_slice_truncate_100000  501.12µs/iter  +/- 46.97µs

Results after implementation:
 *   vec::bench_dedup_all_100                 75.00ns/iter   +/- 9.00ns
 *   vec::bench_dedup_all_1000               494.00ns/iter +/- 117.00ns
 *   vec::bench_dedup_all_100000              58.13µs/iter   +/- 8.78µs
 *   __vec::bench_dedup_none_100                52.00ns/iter  +/- 22.00ns__
 *   __vec::bench_dedup_none_1000              417.00ns/iter +/- 116.00ns__
 *   __vec::bench_dedup_none_10000               4.11µs/iter +/- 546.00ns__
 *   __vec::bench_dedup_none_100000             40.47µs/iter   +/- 5.36µs__
 *   vec::bench_dedup_random_100              77.00ns/iter  +/- 15.00ns
 *   vec::bench_dedup_random_1000            681.00ns/iter  +/- 86.00ns
 *   vec::bench_dedup_random_10000            11.66µs/iter   +/- 2.22µs
 *   vec::bench_dedup_random_100000          469.35µs/iter  +/- 20.53µs
 *   vec::bench_dedup_slice_truncate_100     100.00ns/iter   +/- 5.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.55µs/iter +/- 224.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.95µs/iter   +/- 2.59µs
 *   vec::bench_dedup_slice_truncate_100000  492.85µs/iter  +/- 72.84µs

Resolves #77772
2023-12-05 21:01:00 +01:00
Michael Goulet
6fa93e83c9
Rollup merge of #118450 - marcin-serwin:master, r=workingjubilee
Use OnceCell in cell module documentation

The spanning tree example in the std cell module implementation was created before `OnceCell` was added to Rust so it uses `RefCell`. However, in this case using `OnceCell` seems more appropriate and produces simpler code. As a bonus, this also means that all three cell types are presented in the examples of std cell module.
2023-12-05 14:52:43 -05:00
Michael Goulet
aa5f25174d
Rollup merge of #118350 - DaniPopes:tuple-default, r=workingjubilee
Simplify Default for tuples

Doesn't need a separate block for each element
2023-12-05 14:52:43 -05:00
Michael Goulet
19bf749560
Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errors
Add support for making lib features internal

We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug.

This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal.

Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-12-05 14:52:41 -05:00
Michael Goulet
2d2a76d411
Rollup merge of #117793 - wdunicornpro:patch-1, r=workingjubilee
Update variable name to fix `unused_variables` warning

This PR fixes an `unused_variables` warning within `os.rs` when targeting `espidf`.
2023-12-05 14:52:40 -05:00
Trevor Gross
b225aab5ef Stabilize type_name_of_val
Make the following API stable:

    // in core::any
    pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str

Const stability is not added because this relies on `type_name` which is also
not const. That has a blocking issue.

Fixes #66359
2023-12-05 14:49:09 -05:00
The 8472
13a843ebcb Fix in-place collect not reallocating when necessary 2023-12-05 20:09:22 +01:00
Patryk Wychowaniec
a2b79cd92f
chore: Bump compiler_builtins
Actually closes https://github.com/rust-lang/rust/issues/118079.
2023-12-05 15:58:07 +01:00
bors
154f645d76 Auto merge of #118362 - RalfJung:panic_nounwind, r=thomcc
make sure panic_nounwind_fmt can still be fully inlined (e.g. for panic_immediate_abort)

Follow-up to https://github.com/rust-lang/rust/pull/110303.
2023-12-05 12:05:22 +00:00
Guillaume Gomez
89ed7fc040
Rollup merge of #118591 - RalfJung:portable-simd-build-fix, r=workingjubilee,calebzulawski
portable-simd: fix test suite build

``@workingjubilee`` ``@calebzulawski`` don't we run these portable-simd tests on rustc CI? Currently they don't even build here.
2023-12-04 20:46:10 +01:00
Benoît du Garreau
7d369f9830 Specialize count too 2023-12-04 19:48:20 +01:00
Benoît du Garreau
6318cbbe49 HashMap/HashSet: forward fold implementations of iterators 2023-12-04 19:48:20 +01:00
Ralf Jung
bcfeaabaf3 portable-simd: add missing feature gate 2023-12-04 08:16:03 +01:00
Gurinder Singh
423481ba54 Improve example in slice::windows() doc
Now using a window of 3 instead 2 because it removes any
confusion about exactly how consecutive windows overlap
2023-12-04 11:17:42 +05:30
bors
85a4bd8f58 Auto merge of #116915 - bend-n:unwet, r=saethlin
Add an assume that the index is inbounds to slice::get_unchecked

Fixes #116878
2023-12-04 03:09:45 +00:00
bendn
73afc00cf9
use assume(idx < self.len()) in [T]::get_unchecked 2023-12-04 06:00:12 +07:00
Ralf Jung
2a3fcc0a57 move calling miri_promise_symbolic_alignment to a shared helper 2023-12-03 21:51:14 +01:00
Ralf Jung
bebba4f6e0 miri: support 'promising' alignment for symbolic alignment check 2023-12-03 21:51:14 +01:00
klensy
c0134887d2 library: use c string literals 2023-12-03 14:54:09 +03:00
bors
71940e0a8a Auto merge of #118487 - RalfJung:exposed-provenance, r=thomcc
move exposed-provenance APIs into separate feature gate

We have already stated explicitly for all the 'exposed' functions that

> Using this method means that code is *not* following strict provenance rules.

However, they were part of the same feature gate and still described as part of the strict provenance experiment. Unfortunately, their semantics are much less clear and certainly nowhere near stabilization, so in preparation for an attempt to stabilize the strict provenance APIs, I suggest we split the things related to "exposed" into their own feature gate. I also used this opportunity to better explain how Exposed Provenance fits into the larger plan here: this is *one possible candidate* for `as` semantics, but we don't know if it is actually viable, so we can't really promise that it is equivalent to `as`. If it works out we probably want to make `as` equivalent to the 'exposed' APIs; if it doesn't, we will remove them again and try to find some other semantics for `as`.
2023-12-03 07:04:12 +00:00