Commit Graph

8758 Commits

Author SHA1 Message Date
Josh Stone 013986be1b linux: Use `pthread_setname_np` instead of `prctl`
This function is available on Linux since glibc 2.12, musl 1.1.16, and
uClibc 1.0.20. The main advantage over `prctl` is that it properly
represents the pointer argument, rather than a multi-purpose `long`,
so we're better representing strict provenance (#95496).
2022-08-08 13:27:09 -07:00
Dan Vail cc8259e4b6 Adding more verbose documentation for `std::fmt::Write` 2022-08-07 21:02:04 -05:00
Matthias Krüger 07315fe970
Rollup merge of #100206 - RalfJung:miri-terminfo, r=thomcc
test: skip terminfo parsing in Miri

Terminfo parsing takes a significant amount of time in Miri, making libtest startup very slow. To work around that Miri in fact unsets the `TERM` variable. However, this means we don't get colors in `cargo miri test`.

So I propose we add some logic in libtest that skips parsing terminfo files under Miri, and just uses the regular basic coloring commands (taken from the `colored` crate).

As far as I can see, these two commands are all that libtest ever needs from terminfo, so Miri doesn't even lose any functionality through this. If you want I can entirely remove the terminfo parsing code and just use these commands instead.

Cc https://github.com/rust-lang/miri/issues/2292 `@saethlin`
2022-08-07 21:10:25 +02:00
Andrea Ciliberti 926f58745e Fix HorizonOS regression in FileTimes 2022-08-07 19:30:05 +02:00
Ralf Jung 5076c902a4 test: skip terminfo parsing in Miri 2022-08-07 11:56:12 -04:00
Matthias Krüger ee0b755fe6
Rollup merge of #100175 - fxn:patch-1, r=Mark-Simulacrum
ascii -> ASCII in code comment

Easy one I spotted while reading source code.
2022-08-07 01:19:35 +02:00
Matthias Krüger f0ff31fa09
Rollup merge of #100169 - WaffleLapkin:optimize_is_aligned_to, r=workingjubilee
Optimize `pointer::as_aligned_to`

This PR replaces `addr % align` with `addr & align - 1`, which is correct due to `align` being a power of two.

Here is a proof that this makes things better: [[godbolt]](https://godbolt.org/z/Wbq3hx6YG).

This PR also removes `assume(align != 0)`, with the new impl it does not improve anything anymore ([[godbolt]](https://rust.godbolt.org/z/zcnrG4777), [[original concern]](https://github.com/rust-lang/rust/pull/95643#discussion_r843326903)).
2022-08-07 01:19:34 +02:00
Matthias Krüger 879c17f3f9
Rollup merge of #100127 - ChrisDenton:remove-init, r=thomcc
Remove Windows function preloading

After `@Mark-Simulacrum` asked me to provide guidance for when optionally imported functions should be preloaded, I realised my justifications were now quite weak. I think the strongest argument that can be made is that it avoids some degree of nondeterminism when calling these functions (in as far as system API calls can be said to be deterministic). However, I don't think that's particularly convincing unless there's a real world use case where it matters. Further discussion with `@thomcc` has strengthened my feeling that preloading isn't really needed.

Note that `WaitOnAddress` needed some adjustment to work without preloading. I opted not to use a macro for this special case as it seemed silly to do so for just one thing (and I don't like macros tbh).
2022-08-07 01:19:32 +02:00
Michael Goulet 725da87876 provide correct size hint for unsupported platform CommandArgs 2022-08-06 17:33:49 +00:00
Xavier Noria 64d1c91a31
ascii -> ASCII in code comment 2022-08-05 18:45:42 +02:00
Maybe Waffle c195f7c0a4 Optimize `pointer::as_aligned_to` 2022-08-05 17:14:32 +04:00
Maybe Waffle a7c45ec867 improve documentation of `pointer::align_offset` 2022-08-05 16:47:49 +04:00
Maybe Waffle 127b6c4c18 cleanup code w/ pointers in std a little 2022-08-05 16:47:49 +04:00
Chris Denton a0e4c16958
Update after code review 2022-08-04 12:26:40 +01:00
Tomoaki Kawada 0af4a28894 kmc-solid: Add a stub implementation of `File::set_times` 2022-08-04 19:12:30 +09:00
Chris Denton c985648593
Remove Windows function preloading 2022-08-04 01:46:14 +01:00
Chris Denton aac82a9e18
Add visibility modifier to compat macro 2022-08-04 00:20:06 +01:00
Ivan Markov e86c128aa3 FilesTimes support does not build for ESP-IDF 2022-08-03 19:30:23 +00:00
Ralf Jung a61c841385 actually call assert_send_and_sync 2022-08-03 12:44:21 -04:00
bors 04f72f9538 Auto merge of #100023 - saethlin:send-sync-chunksmut, r=m-ou-se
Add back Send and Sync impls on ChunksMut iterators

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

These were accidentally removed in #94247 because the representation was changed from `&mut [T]` to `*mut T`, which has `!Send + !Sync`.
2022-08-03 13:17:58 +00:00
Dylan DPC 8d465cc551
Rollup merge of #99800 - sandydoo:bugfix/wasm-futex, r=m-ou-se
Fix futex module imports on wasm+atomics

The futex modules were rearranged a bit in #98707, which meant that wasm+atomics would no longer compile on nightly. I don’t believe any other targets were impacted by this.
2022-08-03 13:45:52 +05:30
Dylan DPC cb9932ea64
Rollup merge of #99614 - RalfJung:transmute-is-not-memcpy, r=thomcc
do not claim that transmute is like memcpy

Saying transmute is like memcpy is not a well-formed statement, since memcpy is by-ref whereas transmute is by-val. The by-val nature of transmute inherently means that padding is lost along the way. (This is not specific to transmute, this is how all by-value operations work.) So adjust the docs to clarify this aspect.

Cc `@workingjubilee`
2022-08-03 13:45:50 +05:30
Dylan DPC 5730f12b37
Rollup merge of #99371 - ChrisDenton:simplify-gen-random-keys, r=thomcc
Remove synchronization from Windows `hashmap_random_keys`

Unfortunately using synchronization when generating hashmap keys can prevent it being used in `DllMain`.

~~Fixes #99341~~
2022-08-03 13:45:49 +05:30
Ralf Jung da3e11fc42 wordsmithing 2022-08-02 20:43:48 -04:00
Theodore Dubois 53a870c506 Stabilize backtrace 2022-08-02 16:21:20 -07:00
bors e4417cf020 Auto merge of #92268 - jswrenn:transmute, r=oli-obk
Initial implementation of transmutability trait.

*T'was the night before Christmas and all through the codebase, not a miri was stirring — no hint of `unsafe`!*

This PR provides an initial, **incomplete** implementation of *[MCP 411: Lang Item for Transmutability](https://github.com/rust-lang/compiler-team/issues/411)*. The `core::mem::BikeshedIntrinsicFrom` trait provided by this PR is implemented on-the-fly by the compiler for types `Src` and `Dst` when the bits of all possible values of type `Src` are safely reinterpretable as a value of type `Dst`.

What this PR provides is:
- [x] [support for transmutations involving primitives](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/primitives)
- [x] [support for transmutations involving arrays](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/arrays)
- [x] [support for transmutations involving structs](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/structs)
- [x] [support for transmutations involving enums](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/enums)
- [x] [support for transmutations involving unions](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/unions)
- [x] [support for weaker validity checks](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/unions/should_permit_intersecting_if_validity_is_assumed.rs) (i.e., `Assume::VALIDITY`)
- [x] visibility checking

What isn't yet implemented:
- [ ] transmutability options passed using the `Assume` struct
- [ ] [support for references](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/references.rs)
- [ ] smarter error messages

These features will be implemented in future PRs.
2022-08-02 21:17:31 +00:00
bors 792bc5a010 Auto merge of #99977 - BlackHoleFox:cfte-cstr, r=thomcc
Add validation to const fn CStr creation

Improves upon the existing validation that only worked when building the stdlib from source. `CStr::from_bytes_with_nul_unchecked` now utilizes `const_eval_select` to validate the safety requirements of the function when used as `const FOO: &CStr = CStr::from_bytes_with_nul_unchecked(b"Foobar\0");`.

This can help catch erroneous code written by accident and, assuming a new enough `rustc` in use, remove the need for boilerplate safety comments for this function in `const` contexts.

~~I think this might need a UI test, but I don't know where to put it. If this is a worth change, a perf run would be nice to make sure the `O(n)` validation isn't too bad. I didn't notice a difference building the stdlib tests locally.~~
2022-08-02 09:07:31 +00:00
Maybe Waffle 756bd6e3a3 Use `next_chunk` in `ArrayChunks` impl 2022-08-02 10:46:43 +04:00
bors ca37a45232 Auto merge of #100048 - matthiaskrgr:rollup-agimvm6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #99156 (`codegen_fulfill_obligation` expect erased regions)
 - #99293 (only run --all-targets in stage0 for Std)
 - #99779 (Fix item info pos and height)
 - #99994 (Remove `guess_head_span`)
 - #100011 (Use Parser's `restrictions` instead of `let_expr_allowed`)
 - #100017 (kmc-solid: Update `Socket::connect_timeout` to be in line with #78802)
 - #100037 (Update rustc man page to match `rustc --help`)
 - #100042 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-02 06:09:22 +00:00
Matthias Krüger 042bba799b
Rollup merge of #100017 - solid-rs:patch/kmc-solid/adapt-to-78802, r=thomcc
kmc-solid: Update `Socket::connect_timeout` to be in line with #78802

Fixes the build failure of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets after #78802.

```
error[E0308]: mismatched types
   --> library\std\src\sys\solid\net.rs:234:45
    |
234 |             cvt(netc::connect(self.0.raw(), addrp, len))
    |                 -------------               ^^^^^ expected *-ptr, found union `SocketAddrCRepr`
    |                 |
    |                 arguments to this function are incorrect
    |
    = note: expected raw pointer `*const sockets::sockaddr`
                     found union `SocketAddrCRepr`
note: function defined here
   --> library\std\src\sys\solid\abi\sockets.rs:173:12
    |
    173 |     pub fn connect(s: c_int, name: *const sockaddr, namelen: socklen_t) -> c_int;
    |            ^^^^^^^
```
2022-08-02 07:30:45 +02:00
Jane Losare-Lusby b2bbca3933 remove fn backtrace 2022-08-01 20:10:40 +00:00
Maybe Waffle 475e4ba747 Simplify `ArrayChunks::{,r}fold` impls 2022-08-01 19:17:01 +04:00
Maybe Waffle 4c0292cff5 Simplify `ArrayChunks::is_empty` 2022-08-01 19:17:01 +04:00
Maybe Waffle 37dfb04317 Remove `Fuse` from `ArrayChunks` implementation
It doesn't seem to be used at all.
2022-08-01 19:16:56 +04:00
Maybe Waffle 3102b39daa Use `#[track_caller]` to make panic in `Iterator::array_chunks` nicer 2022-08-01 19:16:36 +04:00
Maybe Waffle 4db628a801 Remove incorrect impl `TrustedLen` for `ArrayChunks`
As explained in the review of the previous attempt to add `ArrayChunks`,
adapters that shrink the length can't implement `TrustedLen`.
2022-08-01 19:16:24 +04:00
Ben Kimock 22dfbdd707 Add back Send and Sync impls on ChunksMut iterators
These were accidentally removed in #94247 because the representation was
changed from &mut [T] to *mut T, which has !Send + !Sync.
2022-08-01 10:32:45 -04:00
Maybe Waffle b8b14864c0 Forward `ArrayChunks::next{,_back}` to `try_{for_each,rfold}`
(suggested in the review of the previous attempt to add `ArrayChunks`)
2022-08-01 18:26:18 +04:00
Maybe Waffle ef72349e38 Remove `array::IntoIter::with_partial` -- an artifact of the past, once used to create an `IntoIter` from its parts 2022-08-01 17:00:51 +04:00
Ross MacArthur f5485181ca Use `array::IntoIter` for the `ArrayChunks` remainder 2022-08-01 16:39:30 +04:00
Ross MacArthur ca3d1010bb Add `Iterator::array_chunks()` 2022-08-01 16:39:27 +04:00
Tomoaki Kawada bfbda81107 kmc-solid: Adapt to a recent change in the `IntoInner` impl of `SocketAddr`
`(x: SocketAddr).into_inner()` evaluates to `(SocketAddrCRepr,
socklen_t)` instead of `(*const sockaddr, socklen_t)` as of
commit 55e23db13.
2022-08-01 16:08:24 +09:00
bors 1f5d8d49eb Auto merge of #98246 - joshtriplett:times, r=m-ou-se
Support setting file accessed/modified timestamps

Add `struct FileTimes` to contain the relevant file timestamps, since
most platforms require setting all of them at once. (This also allows
for future platform-specific extensions such as setting creation time.)

Add `File::set_file_time` to set the timestamps for a `File`.

Implement the `sys` backends for UNIX, macOS (which needs to fall back
to `futimes` before macOS 10.13 because it lacks `futimens`), Windows,
and WASI.
2022-08-01 06:44:43 +00:00
Chris Denton 847f4613e0
Never inline Windows dtor access 2022-08-01 03:53:16 +01:00
Matthias Krüger e4fcee579e
Rollup merge of #99984 - ChrisDenton:fix-miri, r=Mark-Simulacrum
Fix compat.rs for `cfg(miri)`

Fixes #99982
2022-07-31 23:39:44 +02:00
Matthias Krüger c98e893bad
Rollup merge of #99932 - madsmtm:fix-unwinding-debug-assertions, r=Amanieu
Fix unwinding on certain platforms when debug assertions are enabled

This came up on `armv7-apple-ios` when using `-Zbuild-std`.

Looks like this is a leftover from a [conversion from C to Rust](051c2d14fb), where integer wrapping is implicit.

Not at all sure how the unwinding code works!
2022-07-31 23:39:41 +02:00
BlackHoleFox 0e54d71e15 Add validation to const fn CStr creation 2022-07-31 13:14:18 -05:00
Chris Denton bf0b18e910
Make sure `symbol_name` is const evaluated 2022-07-31 17:41:07 +01:00
bors 3405e402fa Auto merge of #78802 - faern:simplify-socketaddr, r=joshtriplett
Implement network primitives with ideal Rust layout, not C system layout

This PR is the result of this internals forum thread: https://internals.rust-lang.org/t/why-are-socketaddrv4-socketaddrv6-based-on-low-level-sockaddr-in-6/13321.

Instead of basing `std:::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}` on system (C) structs, they are encoded in a more optimal and idiomatic Rust way.

This changes the public API of std by introducing structural equality impls for all four types here, which means that `match ipv4addr { SOME_CONSTANT => ... }` will now compile, whereas previously this was an error. No other intentional changes are introduced to public API.

It's possible to observe the current layout of these types (e.g., by pointer casting); most but not all libraries which were found by Crater to do this have had updates issued and affected versions yanked. See report below.

### Benefits of this change

- It will become possible to move these fundamental network types from `std` into `core` ([RFC](https://github.com/rust-lang/rfcs/pull/2832)).
- Some methods that can't be made `const fn`s today can be made `const fn`s with this change.
- `SocketAddrV4` only occupies 6 bytes instead of 16 bytes.
- These simple primitives become easier to read and uses less `unsafe`.
- Makes these types support structural equality, which means you can now (for instance) match an `Ipv4Addr` against a constant

### ~Remaining~ Previous problems

This change obviously changes the memory layout of the types. And it turns out some libraries invalidly assumes the memory layout and does very dangerous pointer casts to convert them. These libraries will have undefined behaviour and perform invalid memory access until patched.

- [x] - `mio` - Issue: https://github.com/tokio-rs/mio/issues/1386.
  - [x] `0.7` branch https://github.com/tokio-rs/mio/pull/1388
  - [x] `0.7.6` published https://github.com/tokio-rs/mio/pull/1398
  - [x] Yank all `0.7` versions older than `0.7.6`
  - [x] Report `<0.7.6` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0081.html
- [x] - `socket2` - Issue: https://github.com/rust-lang/socket2-rs/issues/119.
  - [x] `0.3.x` branch https://github.com/rust-lang/socket2-rs/pull/120
  - [x] `0.3.16` published
  - [x] `master` branch https://github.com/rust-lang/socket2-rs/pull/122
  - [x] Yank all `0.3` versions older than `0.3.16`
  - [x] Report `<0.3.16` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0079.html
- [x] - `net2` - Issue: https://github.com/deprecrated/net2-rs/issues/105
  - [x] https://github.com/deprecrated/net2-rs/pull/106
  - [x] `0.2.36` published
  - [x] Yank all `0.2` versions older than `0.2.36`
  - [x] Report `<0.2.36` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0078.html
- [x] - `miow` - Issue: https://github.com/yoshuawuyts/miow/issues/38
  - [x] `0.3.x` - https://github.com/yoshuawuyts/miow/pull/39
  - [x] `0.3.6` published
  - [x] `0.2.x` - https://github.com/yoshuawuyts/miow/pull/40
  - [x] `0.2.2` published
  - [x] Yanked all `0.2` versions older than `0.2.2`
  - [x] Yanked all `0.3` versions older than `0.3.6`
  - [x] Report `<0.2.2` and `<0.3.6` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0080.html
- [x] - `quinn master` (aka what became 0.7) - https://github.com/quinn-rs/quinn/issues/968 https://github.com/quinn-rs/quinn/pull/987
  - [x] - `quinn 0.6` - https://github.com/quinn-rs/quinn/pull/1045
  - [x] - `quinn 0.5` - https://github.com/quinn-rs/quinn/pull/1046
  - [x] - Release `0.7.0`, `0.6.2` and `0.5.4`
- [x] - `nb-connect` - https://github.com/smol-rs/nb-connect/issues/1
  - [x] - Release `1.0.3`
  - [x] - Yank all versions older than `1.0.3`
- [x] - `shadowsocks-rust` - https://github.com/shadowsocks/shadowsocks-rust/issues/462
- [ ] - `rio` - https://github.com/spacejam/rio/issues/44
- [ ] - `seaslug` - https://github.com/spacejam/seaslug/issues/1

#### Fixed crate versions

All crates I have found that assumed the memory layout have been fixed and published. The crates and versions that will continue working even as/if this PR is merged is (please upgrade these to help unblock this PR):

* `net2 0.2.36`
* `socket2 0.3.16`
* `miow 0.2.2`
* `miow 0.3.6`
* `mio 0.7.6`
* `mio 0.6.23` - Never had the invalid assumption itself, but has now been bumped to only allow fixed dependencies (`net2` + `miow`)
* `nb-connect 1.0.3`
* `quinn 0.5.4`
* `quinn 0.6.2`

### Release notes draft

This release changes the memory layout of `Ipv4Addr`, `Ipv6Addr`, `SocketAddrV4` and `SocketAddrV6`. The standard library no longer implements these as the corresponding `libc` structs (`sockaddr_in`, `sockaddr_in6` etc.). This internal representation was never exposed, but some crates relied on it anyway by unsafely transmuting. This change will cause those crates to make invalid memory accesses. Notably `net2 <0.2.36`, `socket2 <0.3.16`, `mio <0.7.6`, `miow <0.3.6` and a few other crates are affected. All known affected crates have been patched and have had fixed versions published over a year ago. If any affected crate is still in your dependency tree, you need to upgrade them before using this version of Rust.
2022-07-31 15:56:28 +00:00
Chris Denton 7f3d11e1d8
Fix compat.rs for `cfg(miri)` 2022-07-31 14:45:26 +01:00
Ralf Jung c4aca2bc88
typo
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2022-07-31 09:00:49 -04:00
bors 76822a2878 Auto merge of #99553 - ChrisDenton:lazy-compat-fn, r=Mark-Simulacrum
Rewrite Windows `compat_fn` macro

This allows using most delay loaded functions before the init code initializes them. It also only preloads a select few functions, rather than all functions.

This is optimized for the common case where a function is used after already being loaded (or failed to load). The only change in codegen at the call site is to use an atomic load instead of a plain load, which should have negligible or no impact.

I've split the old `compat_fn` macro in two so as not to mix two different use cases. If/when Windows 7 support is dropped `compat_fn_optional` can be removed entirely.

r? rust-lang/libs
2022-07-31 10:44:11 +00:00
Matthias Krüger 656cd3a48f
Rollup merge of #99937 - ChrisDenton:fix-remove-dir-all-win-7, r=joshtriplett
Reset directory iteration in remove_dir_all

Fixes #99934
2022-07-30 22:51:00 +02:00
Josh Triplett f8061ddb03 Fix warnings in stubbed out set_times 2022-07-30 13:28:17 -07:00
Chris Denton aac8a0a518
Reset directory iteration in remove_dir_all 2022-07-30 05:28:38 +01:00
Mads Marquart 15b7a08747 Fix unwinding when debug assertions are enabled
This came up on armv7-apple-ios when using -Zbuild-std
2022-07-30 05:14:54 +02:00
Linus Färnstrand 73bb371ad3 Remove socklen_t from platforms where it's no longer used 2022-07-30 02:42:02 +02:00
Nika Layzell 6d1650fe45 proc_macro: use crossbeam channels for the proc_macro cross-thread bridge
This is done by having the crossbeam dependency inserted into the
proc_macro server code from the server side, to avoid adding a
dependency to proc_macro.

In addition, this introduces a -Z command-line option which will switch
rustc to run proc-macros using this cross-thread executor. With the
changes to the bridge in #98186, #98187, #98188 and #98189, the
performance of the executor should be much closer to same-thread
execution.

In local testing, the crossbeam executor was substantially more
performant than either of the two existing CrossThread strategies, so
they have been removed to keep things simple.
2022-07-29 17:38:12 -04:00
Yuki Okushi 9b3f49f1bd
Rollup merge of #99781 - workingjubilee:demo-string-from-cstr, r=thomcc
Use String::from_utf8_lossy in CStr demo

Fixes rust-lang/rust#99755.
2022-07-29 15:40:00 +09:00
Dylan DPC 48efd30c9d
Rollup merge of #99689 - dtolnay:write, r=Mark-Simulacrum
Revert `write!` and `writeln!` to late drop temporaries

Closes (on master, but not on beta) #99684 by reverting the `write!` and `writeln!` parts of #96455.

argument position | before<br>#94868 | after<br>#94868 | after<br>#96455 | after<br>this PR | desired<br>(unimplementable)
--- |:---:|:---:|:---:|:---:|:---:
`write!($tmp, "…", …)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | **⸺late**
`write!(…, "…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | *early⸺*
`writeln!($tmp, "…", …)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | **⸺late**
`writeln!(…, "…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | *early⸺*
`print!("…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | *early⸺* | *early⸺*
`println!("…", $tmp)` | *early⸺* | **⸺late** | *early⸺* | *early⸺* | *early⸺*
`eprint!("…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | *early⸺* | *early⸺*
`eprintln!("…", $tmp)` | *early⸺* | **⸺late**| *early⸺* | *early⸺* | *early⸺*
`panic!("…", $tmp)` | *early⸺* | *early⸺* | *early⸺* | *early⸺* | *early⸺*

"Late drop" refers to dropping temporaries at the nearest semicolon **outside** of the macro invocation.

"Early drop" refers to dropping temporaries inside of the macro invocation.
2022-07-28 22:14:46 +05:30
Dylan DPC a479cab09a
Rollup merge of #99628 - vincenzopalazzo:macros/is_number_doc, r=joshtriplett
add more docs regarding ideographic numbers

This was discussed in the last lib meeting and I try to avoid forgetting to open a PR because I think having some docs can help people.

However, I think we need to discuss a little bit if this is enough or if we need to add more clarification? Maybe an example?

Inspiration Source: https://github.com/rust-lang/rust/issues/84056#issuecomment-1184725924

Including suggestion https://github.com/rust-lang/rust/pull/99626#issuecomment-1192983043 my bad command git close the PR
2022-07-28 22:14:46 +05:30
Vincenzo Palazzo 47a0a56c1d add more docs regarding ideographic numbers
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-07-28 15:52:18 +00:00
Dylan DPC f3266923fe
Rollup merge of #99723 - bstrie:wasifd, r=yaahc
Allow using stable os::fd::raw items through unstable os::wasi module

This fixes a regression from stable to nightly.

Closes #99502.
2022-07-28 16:38:31 +05:30
bors 48316dfea1 Auto merge of #99182 - RalfJung:mitigate-uninit, r=scottmcm
mem::uninitialized: mitigate many incorrect uses of this function

Alternative to https://github.com/rust-lang/rust/pull/98966: fill memory with `0x01` rather than leaving it uninit. This is definitely bitewise valid for all `bool` and nonnull types, and also those `Option<&T>` that we started putting `noundef` on. However it is still invalid for `char` and some enums, and on references the `dereferenceable` attribute is still violated, so the generated LLVM IR still has UB -- but in fewer cases, and `dereferenceable` is hopefully less likely to cause problems than clearly incorrect range annotations.

This can make using `mem::uninitialized` a lot slower, but that function has been deprecated for years and we keep telling everyone to move to `MaybeUninit` because it is basically impossible to use `mem::uninitialized` correctly. For the cases where that hasn't helped (and all the old code out there that nobody will ever update), we can at least mitigate the effect of using this API. Note that this is *not* in any way a stable guarantee -- it is still UB to call `mem::uninitialized::<bool>()`, and Miri will call it out as such.

This is somewhat similar to https://github.com/rust-lang/rust/pull/87032, which proposed to make `uninitialized` return a buffer filled with 0x00. However
- That PR also proposed to reduce the situations in which we panic, which I don't think we should do at this time.
- The 0x01 bit pattern means that nonnull requirements are satisfied, which (due to references) is the most common validity invariant.

`@5225225` I hope I am using `cfg(sanitize)` the right way; I was not sure for which ones to test here.
Cc https://github.com/rust-lang/rust/issues/66151
Fixes https://github.com/rust-lang/rust/issues/87675
2022-07-28 01:11:10 +00:00
Jack Wrenn b78c3daad0 safe transmute: reference tracking issue
ref: https://github.com/rust-lang/rust/pull/92268#discussion_r925266769
2022-07-27 17:33:57 +00:00
Jack Wrenn 21d1ab4877 safe transmute: add `rustc_on_unimplemented` to `BikeshedIntrinsicFrom`
ref: https://github.com/rust-lang/rust/pull/92268#discussion_r925266583
2022-07-27 17:33:57 +00:00
Jack Wrenn bc4a1dea41 Initial (incomplete) implementation of transmutability trait.
This initial implementation handles transmutations between types with specified layouts, except when references are involved.

Co-authored-by: Igor null <m1el.2027@gmail.com>
2022-07-27 17:33:56 +00:00
Guillaume Gomez ef81fca760
Rollup merge of #94247 - saethlin:chunksmut-aliasing, r=the8472
Fix slice::ChunksMut aliasing

Fixes https://github.com/rust-lang/rust/issues/94231, details in that issue.
cc `@RalfJung`

This isn't done just yet, all the safety comments are placeholders. But otherwise, it seems to work.

I don't really like this approach though. There's a lot of unsafe code where there wasn't before, but as far as I can tell the only other way to uphold the aliasing requirement imposed by `__iterator_get_unchecked` is to use raw slices, which I think require the same amount of unsafe code. All that would do is tie the `len` and `ptr` fields together.

Oh I just looked and I'm pretty sure that `ChunksExactMut`, `RChunksMut`, and `RChunksExactMut` also need to be patched. Even more reason to put up a draft.
2022-07-27 17:55:01 +02:00
bstrie 0eb28abcc9 Allow using stable os::fd::raw items through unstable os::wasi module
This fixes a regression from stable to nightly.

Closes #99502.
2022-07-27 10:25:13 -04:00
bors 2a220937c2 Auto merge of #99802 - JohnTitor:rollup-uaklql1, r=JohnTitor
Rollup of 5 pull requests

Successful merges:

 - #99079 (Check that RPITs constrained by a recursive call in a closure are compatible)
 - #99704 (Add `Self: ~const Trait` to traits with `#[const_trait]`)
 - #99769 (Sync rustc_codegen_cranelift)
 - #99783 (rustdoc: remove Clean trait impls for more items)
 - #99789 (Refactor: use `pluralize!`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-27 12:32:54 +00:00
Yuki Okushi 28b44ff5d4
Rollup merge of #99704 - fee1-dead-contrib:add_self_tilde_const_trait, r=oli-obk
Add `Self: ~const Trait` to traits with `#[const_trait]`

r? `@oli-obk`
2022-07-27 19:05:33 +09:00
bors 50166d5e5e Auto merge of #98748 - saethlin:optimize-bufreader, r=Mark-Simulacrum
Remove some redundant checks from BufReader

The implementation of BufReader contains a lot of redundant checks. While any one of these checks is not particularly expensive to execute, especially when taken together they dramatically inhibit LLVM's ability to make subsequent optimizations by confusing data flow increasing the code size of anything that uses BufReader.

In particular, these changes have a ~2x increase on the benchmark that this adds a `black_box` to. I'm adding that `black_box` here just in case LLVM gets clever enough to remove the reads entirely. Right now it can't, but these optimizations are really setting it up to do so.

We get this optimization by factoring all the actual buffer management and bounds-checking logic into a new module inside `bufreader` with a new `Buffer` type. This makes it much easier to ensure that we have correctly encapsulated the management of the region of the buffer that we have read bytes into, and it lets us provide a new faster way to do small reads. `Buffer::consume_with` lets a caller do a read from the buffer with a single bounds check, instead of the double-check that's required to use `buffer` + `consume`.

Unfortunately I'm not aware of a lot of open-source usage of `BufReader` in perf-critical environments. Some time ago I tweaked this code because I saw `BufReader` in a profile at work, and I contributed some benchmarks to the `bincode` crate which exercise `BufReader::buffer`. These changes appear to help those benchmarks at little, but all these sorts of benchmarks are kind of fragile so I'm wary of quoting anything specific.
2022-07-27 09:49:06 +00:00
sandydoo e3afce8c70
Fix futex module imports on wasm+atomics 2022-07-27 12:44:32 +04:00
bors e33cc71a61 Auto merge of #99792 - JohnTitor:rollup-20i7ewx, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #98583 (Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`)
 - #99698 (Prefer visibility map parents that are not `doc(hidden)` first)
 - #99700 (Add a clickable link to the layout section)
 - #99712 (passes: port more of `check_attr` module)
 - #99759 (Remove dead code from cg_llvm)
 - #99765 (Don't build std for *-uefi targets)
 - #99771 (Update pulldown-cmark version to 0.9.2 (fixes url encoding for some chars))
 - #99775 (rustdoc: do not allocate String when writing path full name)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-27 04:18:49 +00:00
Yuki Okushi 1ff84f09b2
Rollup merge of #98583 - joshtriplett:stabilize-windows-symlink-types, r=thomcc
Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`

These calls allow detecting whether a symlink is a file or a directory,
a distinction Windows maintains, and one important to software that
wants to do further operations on the symlink (e.g. removing it).
2022-07-27 11:52:52 +09:00
Ben Kimock 746afe8952 Clarify safety comments 2022-07-26 21:25:56 -04:00
bors b573e10d21 Auto merge of #98553 - the8472:next_chunk_opt, r=Mark-Simulacrum
Optimized vec::IntoIter::next_chunk impl

```
x86_64v1, default
test vec::bench_next_chunk                               ... bench:         696 ns/iter (+/- 22)
x86_64v1, pr
test vec::bench_next_chunk                               ... bench:         309 ns/iter (+/- 4)

znver2, default
test vec::bench_next_chunk                               ... bench:      17,272 ns/iter (+/- 117)
znver2, pr
test vec::bench_next_chunk                               ... bench:         211 ns/iter (+/- 3)
```

On znver2 the default impl seems to be slow due to different inlining decisions. It goes through `core::array::iter_next_chunk`
which has a deep call tree.
2022-07-27 01:12:30 +00:00
Ben Kimock 5fa1926634 Add Buffer::consume_with to enable direct buffer access with one check 2022-07-26 20:16:55 -04:00
Ben Kimock e2e3a88771 Explain how *mut [T] helps, and how we rely on the check in split_at_mut 2022-07-26 18:37:00 -04:00
Jubilee Young d48a869b9d Force the Cow into a String 2022-07-26 14:45:28 -07:00
Jubilee Young 79e0543060 Use String::from_utf8_lossy in CStr demo 2022-07-26 13:26:05 -07:00
The 8472 4ba7cac359 add test for vec::IntoIter::next_chunk() impl
an adaption of the default impl's doctest
2022-07-26 21:43:25 +02:00
bors 4d6d601c8a Auto merge of #99574 - durin42:allocator-patch-redux, r=nikic
codegen: use new {re,de,}allocator annotations in llvm

This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

r? `@nikic`
2022-07-26 19:35:57 +00:00
The 8472 2f9f2e507e Optimized vec::IntoIter::next_chunk impl
```
test vec::bench_next_chunk                               ... bench:         696 ns/iter (+/- 22)
x86_64v1, pr
test vec::bench_next_chunk                               ... bench:         309 ns/iter (+/- 4)

znver2, default
test vec::bench_next_chunk                               ... bench:      17,272 ns/iter (+/- 117)
znver2, pr
test vec::bench_next_chunk                               ... bench:         211 ns/iter (+/- 3)
```

The znver2 default impl seems to be slow due to inlining decisions. It goes through `core::array::iter_next_chunk`
which has a deeper call tree.
2022-07-26 20:31:43 +02:00
Matthias Krüger a739e28aea
Rollup merge of #99757 - asquared31415:patch-1, r=Dylan-DPC
Make `transmute_copy` docs read better
2022-07-26 16:57:52 +02:00
Matthias Krüger ea299e8f31
Rollup merge of #99716 - sourcelliu:iomut, r=Mark-Simulacrum
remove useless mut from examples

remove useless mut from examples
2022-07-26 16:57:48 +02:00
Deadbeef a6f9826979 Add `Self: ~const Trait` to traits with `#[const_trait]` 2022-07-26 14:14:21 +00:00
Augie Fackler 130a1df71e codegen: use new {re,de,}allocator annotations in llvm
This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

While we're here, we also emit allocator attributes on
__rust_alloc_zeroed. This should allow LLVM to perform more
optimizations for zeroed blocks, and probably fixes #90032. [This
comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157)
mentions "weird UB-like behaviour with bitvec iterators in
rustc_data_structures" so we may need to back this change out if things
go wrong.

The new test cases require LLVM 15, so we copy them into LLVM
14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26 09:43:28 -04:00
Chris Denton 698d4a86c6
Rewrite Windows `compat_fn` macro
This allows using most delay loaded functions before the init code initializes them. It also only preloads a select few functions, rather than all functions.

Co-Authored-By: Mark Rousskov <mark.simulacrum@gmail.com>
2022-07-26 14:16:35 +01:00
asquared31415 e241d5a093
Make `transmute_copy` docs read better 2022-07-26 05:59:44 -04:00
Dylan DPC deab13c681
Rollup merge of #99692 - RalfJung:too-far, r=oli-obk
interpret, ptr_offset_from: refactor and test too-far-apart check

We didn't have any tests for the "too far apart" message, and indeed that check mostly relied on the in-bounds check and was otherwise probably not entirely correct... so I rewrote that check, and it is before the in-bounds check so we can test it separately.
2022-07-26 14:26:58 +05:30
Yuki Okushi d3acd0069d
Rollup merge of #98211 - devnexen:get_path_freebsd, r=Mark-Simulacrum
Implement `fs::get_path` for FreeBSD.

Using `F_KINFO` fcntl flag, the kf_structsize field
needs to be set beforehand for that effect.
2022-07-26 13:12:18 +09:00
David CARLIER e39b44a076 Implement `fs::get_path` for FreeBSD.
Using `F_KINFO` fcntl flag, the kf_structsize field
needs to be set beforehand for that effect.
2022-07-25 23:25:15 +01:00
Yuki Okushi 5bbdf65996
Rollup merge of #99703 - dtolnay:tokenstreamsizehint, r=petrochenkov
Expose size_hint() for TokenStream's iterator

The iterator for `proc_macro::TokenStream` is a wrapper around a `Vec` iterator:

babff2211e/library/proc_macro/src/lib.rs (L363-L371)

so it can cheaply provide a perfectly precise size hint, with just a pointer subtraction:

babff2211e/library/alloc/src/vec/into_iter.rs (L170-L177)

I need the size hint in syn (https://github.com/dtolnay/syn/blob/1.0.98/src/buffer.rs) to reduce allocations when converting TokenStream into syn's internal TokenBuffer representation.

Aside from `size_hint`, the other non-default methods in `std::vec::IntoIter`'s `Iterator` impl are `advance_by`, `count`, and `__iterator_get_unchecked`. I've included `count` in this PR since it is trivial. I did not include `__iterator_get_unchecked` because it is spoopy and I did not feel like dealing with that. Lastly, I did not include `advance_by` because that requires `feature(iter_advance_by)` (https://github.com/rust-lang/rust/issues/77404) and I noticed this comment at the top of libproc_macro:

babff2211e/library/proc_macro/src/lib.rs (L20-L22)
2022-07-26 07:14:50 +09:00
Yuki Okushi aeca079d7e
Rollup merge of #99084 - RalfJung:write_bytes, r=thomcc
clarify how write_bytes can lead to UB due to invalid values

Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/330

Cc ``@5225225``
2022-07-26 07:14:46 +09:00
Yuki Okushi b8aab9781a
Rollup merge of #98710 - mojave2:string, r=JohnTitor
correct the output of a `capacity` method example

The output of this example in std::alloc is different from which shown in the comment. I have tested it on both Linux and Windows.
2022-07-26 07:14:45 +09:00
Yuki Okushi c1647e10ad
Rollup merge of #92390 - fee1-dead-contrib:const_cmp, r=oli-obk
Constify a few `(Partial)Ord` impls

Only a few `impl`s are constified for now, as #92257 has not landed in the bootstrap compiler yet and quite a few impls would need that fix.

This unblocks #92228, which unblocks marking iterator methods as `default_method_body_is_const`.
2022-07-26 07:14:43 +09:00
Yuki Okushi d1e4342d11
Rollup merge of #99690 - RalfJung:miri-track-caller, r=Mark-Simulacrum
add miri-track-caller to more intrinsic-exposing methods

Follow-up to https://github.com/rust-lang/rust/pull/98674: I went through the Miri test suite to find more functions that would benefit from Miri backtrace pruning, and this is what I found.

Basically anything that just exposes a potentially-UB intrinsic to the user should get this treatment.
2022-07-25 18:46:55 +09:00
Yuki Okushi e726af8dd4
Rollup merge of #95916 - solid-rs:feat-kmc-solid-abort, r=Mark-Simulacrum
kmc-solid: Use `libc::abort` to abort a program

This PR updates the target-specific abort subroutine for the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

The current implementation uses a `hlt` instruction, which is the most direct way to notify a connected debugger but is not the most flexible way. This PR changes it to call the `abort` libc function, making it possible for a system designer to override its behavior as they see fit.
2022-07-25 18:46:48 +09:00
Yuki Okushi 0ecbcbb0ac
Rollup merge of #95040 - frank-king:fix/94981, r=Mark-Simulacrum
protect `std::io::Take::limit` from overflow in `read`

Resolves #94981
2022-07-25 18:46:47 +09:00