Commit Graph

8590 Commits

Author SHA1 Message Date
Deadbeef
a6f9826979 Add Self: ~const Trait to traits with #[const_trait] 2022-07-26 14:14:21 +00: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
David Tolnay
63e74aba81
Expose size_hint() for TokenStream's iterator 2022-07-24 20:36:22 -07:00
bors
babff2211e Auto merge of #97581 - AngelicosPhosphoros:improve_calloc_check_in_vec_macro_for_tuples, r=Mark-Simulacrum
Support vec zero-alloc optimization for tuples and byte arrays

* Implement IsZero trait for tuples up to 8 IsZero elements;
* Implement IsZero for u8/i8, leading to implementation of it for arrays of them too;
* Add more codegen tests for this optimization.
* Lower size of array for IsZero trait because it fails to inline checks
2022-07-25 00:20:43 +00:00
Ralf Jung
58f2ede15f interpret, ptr_offset_from: refactor and test too-far-apart check 2022-07-24 19:35:40 -04:00
AngelicosPhosphoros
86d445eda8 Support vec zero-alloc optimization for tuples and byte arrays
* Implement IsZero trait for tuples up to 8 IsZero elements;
* Implement IsZero for u8/i8, leading to implementation of it for arrays of them too;
* Add more codegen tests for this optimization.
* Lower size of array for IsZero trait because it fails to inline checks
2022-07-24 15:56:39 -04:00
Ralf Jung
d10a7b1243 add miri-track-caller to some intrinsic-exposing methods 2022-07-24 14:49:33 -04:00
Ralf Jung
51b3d51cf4
Rollup merge of #99657 - Phosra:patch-1, r=Dylan-DPC
Docs - remove unnecessary `mut` that gives a warning

Fixes #99654.

A trivial linting fix for a Stdio example.

`@rustbot` label +T-lib
2022-07-24 14:04:27 -04:00
Deadbeef
65fca6db19 add const hack comment 2022-07-24 12:01:23 +00:00
Deadbeef
a89510e5f9 Add issue numbers 2022-07-24 12:01:22 +00:00
Deadbeef
9fc5463c18 Constify a few const (Partial)Ord impls 2022-07-24 12:01:22 +00:00
bors
35a0617248 Auto merge of #98674 - RalfJung:miri-stacktrace-pruning, r=Mark-Simulacrum
miri: prune some atomic operation and raw pointer details from stacktrace

Since Miri removes `track_caller` frames from the stacktrace, adding that attribute can help make backtraces more readable (similar to how it makes panic locations better). I made them only show up with `cfg(miri)` to make sure the extra arguments induced by `track_caller` do not cause any runtime performance trouble.

This is also testing the waters for whether the libs team is okay with having these attributes in their code, or whether you'd prefer if we find some other way to do this. If you are fine with this, we will probably want to add it to a lot more functions (all the other atomic operations, to start).

Before:
```
error: Undefined Behavior: Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at alloc1727 (current vector clock = VClock([9, 0, 6]), conflicting timestamp = VClock([0, 6]))
    --> /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:2594:23
     |
2594 |             SeqCst => intrinsics::atomic_load_seqcst(dst),
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at alloc1727 (current vector clock = VClock([9, 0, 6]), conflicting timestamp = VClock([0, 6]))
     |
     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
     = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

     = note: inside `std::sync::atomic::atomic_load::<usize>` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:2594:23
     = note: inside `std::sync::atomic::AtomicUsize::load` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:1719:26
note: inside closure at ../miri/tests/fail/data_race/atomic_read_na_write_race1.rs:22:13
    --> ../miri/tests/fail/data_race/atomic_read_na_write_race1.rs:22:13
     |
22   |             (&*c.0).load(Ordering::SeqCst)
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

After:
```
error: Undefined Behavior: Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at alloc1727 (current vector clock = VClock([9, 0, 6]), conflicting timestamp = VClock([0, 6]))
  --> tests/fail/data_race/atomic_read_na_write_race1.rs:22:13
   |
22 |             (&*c.0).load(Ordering::SeqCst)
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at alloc1727 (current vector clock = VClock([9, 0, 6]), conflicting timestamp = VClock([0, 6]))
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

   = note: inside closure at tests/fail/data_race/atomic_read_na_write_race1.rs:22:13
```
2022-07-24 06:46:46 +00:00
Phosra
4855392111
Remove mut 2022-07-23 21:22:43 -07:00
Guillaume Gomez
74c3da39f0
Rollup merge of #99627 - saethlin:lock-once, r=eddyb
Lock stdout once when listing tests

This is a marginal optimization for normal operation, but for `cargo miri nextest list` (which is invoked by `cargo miri nextest run`) this knocks the startup time on `regex` down from 87 seconds to 17 seconds. Still slow, but a nice 5x improvement.
2022-07-23 23:34:31 +02:00
bors
e55c53c57e Auto merge of #97925 - the8472:cgroupv1, r=joshtriplett
Add cgroupv1 support to available_parallelism

Fixes #97549

My dev machine uses cgroup v2 so I was only able to test that code path. So the v1 code path is written only based on documentation. I could use some help testing that it works on a machine with cgroups v1:

```
$ x.py build --stage 1

# quota.rs
fn main() {
    println!("{:?}", std:🧵:available_parallelism());
}

# assuming stage1 is linked in rustup
$ rust +stage1 quota.rs

# spawn a new cgroup scope for the current user
$ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS

# should print Ok(3)
$ ./quota
```

If it doesn't work as expected an strace, the contents of `/proc/self/cgroups` and the structure of `/sys/fs/cgroups` would help.
2022-07-23 13:33:56 +00:00
bors
ed793d86da Auto merge of #93397 - joshtriplett:sort-floats, r=Amanieu
Add `[f32]::sort_floats` and `[f64]::sort_floats`

It's inconvenient to sort a slice or Vec of floats, compared to sorting integers. To simplify numeric code, add a convenience method to `[f32]` and `[f64]` to sort them using `sort_unstable_by` with `total_cmp`.
2022-07-23 02:47:54 +00:00
Ben Kimock
90dc0b02ae Lock stdout once when listing tests 2022-07-22 18:39:26 -04:00
the8472
2e33c812e8
[review] mention that runtime may scale with # of mountpoints
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-07-22 22:18:07 +02:00
Ralf Jung
35c6dec921 adjust UnsafeCell documentation 2022-07-22 14:25:41 -04:00
bors
41419e7036 Auto merge of #99491 - workingjubilee:sync-psimd, r=workingjubilee
Sync in portable-simd subtree

r? `@ghost`
2022-07-22 09:48:00 +00:00
Dylan DPC
5df3b98321
Rollup merge of #99579 - CleanCut:expect-warning, r=joshtriplett
Add same warning to Result::expect as Result::unwrap

I was reading a recent blog post by Jimmy Hartzell and [he noted](https://www.thecodedmessage.com/posts/2022-07-14-programming-unwrap/#context):

> I will however note that the documentation of `unwrap` comes with [a warning not to use it](https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap). The warning is framed in terms of the fact that `unwrap` may panic, but the [documentation of `expect`](https://doc.rust-lang.org/std/result/enum.Result.html#method.expect), where this is equally true, does not come with such a warning.

It _is_ equally true. Let's add the same warning to `expect`. This PR is a copy-and-paste of the warning text from the docstring for `unwrap`.
2022-07-22 11:53:43 +05:30
Dylan DPC
ad31d5c6a5
Rollup merge of #98174 - Kixunil:rename_ptr_as_mut_const_to_cast, r=scottmcm
Rename `<*{mut,const} T>::as_{const,mut}` to `cast_`

This renames the methods to use the `cast_` prefix instead of `as_` to
make it more readable and avoid confusion with `<*mut T>::as_mut()`
which is `unsafe` and returns a reference.

Sorry, didn't notice ACP process exists, opened https://github.com/rust-lang/libs-team/issues/51

See #92675
2022-07-22 11:53:39 +05:30
bors
aa01891700 Auto merge of #99420 - RalfJung:vtable, r=oli-obk
make vtable pointers entirely opaque

This implements the scheme discussed in https://github.com/rust-lang/unsafe-code-guidelines/issues/338: vtable pointers should be considered entirely opaque and not even readable by Rust code, similar to function pointers.

- We have a new kind of `GlobalAlloc` that symbolically refers to a vtable.
- Miri uses that kind of allocation when generating a vtable.
- The codegen backends, upon encountering such an allocation, call `vtable_allocation` to obtain an actually dataful allocation for this vtable.
- We need new intrinsics to obtain the size and align from a vtable (for some `ptr::metadata` APIs), since direct accesses are UB now.

I had to touch quite a bit of code that I am not very familiar with, so some of this might not make much sense...
r? `@oli-obk`
2022-07-22 01:33:49 +00:00
Nathan Stocks
7ba0be832a add same warning to Result::expect as Result::unwrap 2022-07-21 18:15:24 -06:00
Matthias Krüger
84a7b23fd7
Rollup merge of #99523 - cuviper:asfd_ptrs-1.64, r=jyn514
Fix the stable version of `AsFd for Arc<T>` and `Box<T>`

These merged in #97437 for 1.64.0, apart from the main `io_safety`
feature that stabilized in 1.63.0.
2022-07-21 18:42:05 +02:00
Matthias Krüger
9610c71b1e
Rollup merge of #99454 - benluelo:control-flow/continue-combinators, r=scottmcm
Add map_continue and continue_value combinators to ControlFlow

As suggested in this comment: https://github.com/rust-lang/rust/issues/75744#issuecomment-1188549494

Related tracking issue: https://github.com/rust-lang/rust/issues/75744

r? ``````@scottmcm``````
2022-07-21 18:42:04 +02:00
Matthias Krüger
43783b80ee
Rollup merge of #99413 - steffahn:btree_dropck, r=m-ou-se
Add `PhantomData` marker for dropck to `BTreeMap`

closes #99408
2022-07-21 18:42:02 +02:00
Matthias Krüger
c5df2f02d3
Rollup merge of #98707 - joboet:fuchsia_locks, r=m-ou-se
std: use futex-based locks on Fuchsia

This switches `Condvar` and `RwLock` to the futex-based implementation currently used on Linux and some BSDs. Additionally, `Mutex` now has its own, priority-inheriting implementation based on the mutex in Fuchsia's `libsync`. It differs from the original in that it panics instead of aborting when reentrant locking is detected.

````@rustbot```` ping fuchsia
r? ````@m-ou-se````
2022-07-21 18:42:02 +02:00
Martin Habovstiak
eb5acc9b9b Rename <*{mut,const} T>::as_{const,mut} to cast_
This renames the methods to use the `cast_` prefix instead of `as_` to
make it more readable and avoid confusion with `<*mut T>::as_mut()`
which is `unsafe` and returns a reference.

See #92675
2022-07-21 18:30:05 +02:00
joboet
8ba02f18b8
remove unused import 2022-07-21 11:51:26 +02:00
Jubilee Young
f8aa494c69 Introduce core::simd trait imports in tests 2022-07-20 18:08:20 -07:00
Jubilee Young
a14404a028 Sync core::simd up to rust-lang/portable-simd@2e081db92a 2022-07-20 17:57:56 -07:00
Ralf Jung
0318f07bdd various nits from review 2022-07-20 17:12:08 -04:00
Ralf Jung
114da84996 use extern type for extra opaqueness 2022-07-20 17:12:07 -04:00
Ralf Jung
5e840c5c8c incorporate some review feedback 2022-07-20 17:12:07 -04:00
Ralf Jung
8affef2ccb add intrinsic to access vtable size and align 2022-07-20 17:12:07 -04:00
Ralf Jung
13877a965d prune raw pointer read and write methods from Miri backtraces 2022-07-20 16:42:20 -04:00
Ralf Jung
2b269cad43 miri: prune some atomic operation details from stacktrace 2022-07-20 16:34:24 -04:00
benluelo
1993a5f7a8
Add map_continue and continue_value combinators to ControlFlow
Fix type error

Fix continue_value doc comment
2022-07-20 16:32:09 -04:00
Josh Stone
bd0474d24a Fix the stable version of AsFd for Arc<T> and Box<T>
These merged in #97437 for 1.64.0, apart from the main `io_safety`
feature that stabilized in 1.63.0.
2022-07-20 12:09:49 -07:00
Matthias Krüger
a5a681100c
Rollup merge of #99516 - m-ou-se:proc-macro-tracked-tracking-issue, r=Mark-Simulacrum
Use new tracking issue for proc_macro::tracked_*.
2022-07-20 18:58:22 +02:00