Commit Graph

8733 Commits

Author SHA1 Message Date
Mark Rousskov
1c40ef70a1 Apply changes from rustfmt bump 2022-08-12 16:28:16 -04:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Dylan DPC
da3b89d0bf
Rollup merge of #100255 - thedanvail:issue-98861-fix, r=joshtriplett
Adding more verbose documentation for `std::fmt::Write`

Attempts to address #98861
2022-08-12 20:39:13 +05:30
Dylan DPC
51eed00ca9
Rollup merge of #100030 - WaffleLapkin:nice_pointer_sis, r=scottmcm
cleanup code w/ pointers in std a little

Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
2022-08-12 20:39:10 +05:30
Dylan DPC
a8c799a6a0
Rollup merge of #100022 - joboet:faster_threadid, r=joshtriplett
Optimize thread ID generation

By using atomics where available, thread IDs can be generated without locking while still enforcing uniqueness.
2022-08-12 20:39:09 +05:30
bors
569788e47e Auto merge of #99624 - vincenzopalazzo:macros/unix_error, r=Amanieu
promote debug_assert to assert when possible and useful

This PR fixed a very old issue https://github.com/rust-lang/rust/issues/94705 to clarify and improve the POSIX error checking, and some of the checks are skipped because can have no benefit, but I'm sure that this can open some interesting discussion.

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

cc: `@tavianator`
cc: `@cuviper`
2022-08-12 09:49:55 +00:00
Matthias Krüger
c7578b4e65
Rollup merge of #100418 - tbodt:stabilize-backtrace, r=dtolnay
Add stability attributes to BacktraceStatus variants

Fixes #100399
2022-08-11 22:53:10 +02:00
Matthias Krüger
bd64d67d11
Rollup merge of #100203 - compiler-errors:command-args-size-hint, r=m-ou-se
provide correct size hint for unsupported platform `CommandArgs`

Split from https://github.com/rust-lang/rust/pull/99880#discussion_r932994172
2022-08-11 22:53:04 +02:00
Matthias Krüger
275d4e779a
Rollup merge of #100112 - RalfJung:assert_send_and_sync, r=m-ou-se
Fix test: chunks_mut_are_send_and_sync

Follow-up to https://github.com/rust-lang/rust/pull/100023 to make the test actually effective
2022-08-11 22:53:03 +02:00
Matthias Krüger
37efd55210
Rollup merge of #99511 - RalfJung:raw_eq, r=wesleywiser
make raw_eq precondition more restrictive

Specifically, don't allow comparing pointers that way. Comparing pointers is subtle because you have to talk about what happens to the provenance.

This matches what [Miri already implements](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9eb1dfb8a61b5a2d4a7cee43df2717af), and all existing users are fine with this.

If raw_eq on pointers is ever desired, we can adjust the intrinsic spec and Miri implementation as needed, but for now that seems just unnecessary. Also, this is a const intrinsic, and in const, comparing pointers this way is *not possible* -- so if we allow the intrinsic to compare pointers in general, we need to impose an extra restrictions saying that in const-context, pointers are *not* okay.
2022-08-11 22:53:01 +02:00
Matthias Krüger
6737549aaf
Rollup merge of #99421 - Bryanskiy:android-crt-static, r=petrochenkov
add crt-static for android
2022-08-11 22:52:58 +02:00
Theodore Dubois
121fab0396 Add stability attributes to BacktraceStatus variants
Fixes #100399
2022-08-11 11:00:07 -07:00
Dylan DPC
a5b0f72e71
Rollup merge of #100287 - cuviper:no-linux-prctl, r=Mark-Simulacrum
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-11 22:47:02 +05:30
Dylan DPC
d749914f79
Rollup merge of #100184 - Kixunil:stabilize_ptr_const_cast, r=m-ou-se
Stabilize ptr_const_cast

This stabilizes `ptr_const_cast` feature as was decided in a recent
[FCP](https://github.com/rust-lang/rust/issues/92675#issuecomment-1190660233)

Closes #92675
2022-08-11 22:46:58 +05:30
Ralf Jung
338d7c2fb0
more typos
Co-authored-by: Nicholas Nethercote <n.nethercote@gmail.com>
2022-08-11 07:37:22 -04:00
bors
187654481f Auto merge of #100298 - BlackHoleFox:hashmap_keygen_cleanup, r=Mark-Simulacrum
Replace pointer casting in hashmap_random_keys with safe code

The old code was unnecessarily unsafe and relied on the layout of tuples always being the same as an array of the same size (which might be bad with `-Z randomize-layout`)?

The replacement has [identical codegen](https://rust.godbolt.org/z/qxsvdb8nx), so it seems like a reasonable change.
2022-08-11 02:46:32 +00:00
Vincenzo Palazzo
d91dff3c1b promote debug_assert to assert
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-08-11 01:18:45 +00:00
bors
908fc5b26d Auto merge of #99174 - scottmcm:reoptimize-layout-array, r=joshtriplett
Reoptimize layout array

This way it's one check instead of two, so hopefully (cc #99117) it'll be simpler for rustc perf too 🤞

Quick demonstration:
```rust
pub fn demo(n: usize) -> Option<Layout> {
    Layout::array::<i32>(n).ok()
}
```

Nightly: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e97bf33508aa03f38968101cdeb5322d>
```nasm
	mov	rax, rdi
	mov	ecx, 4
	mul	rcx
	seto	cl
	movabs	rdx, 9223372036854775805
	xor	esi, esi
	cmp	rax, rdx
	setb	sil
	shl	rsi, 2
	xor	edx, edx
	test	cl, cl
	cmove	rdx, rsi
	ret
```

This PR (note no `mul`, in addition to being much shorter):
```nasm
	xor	edx, edx
	lea	rax, [4*rcx]
	shr	rcx, 61
	sete	dl
	shl	rdx, 2
	ret
```

This is built atop `@CAD97` 's #99136; the new changes are cb8aba66ef6a0e17f08a0574e4820653e31b45a0.

I added a bunch more tests for `Layout::from_size_align` and `Layout::array` too.
2022-08-10 23:50:18 +00:00
Ralf Jung
d1cace5a97
grammar
Co-authored-by: Frank Steffahn <fdsteffahn@gmail.com>
2022-08-10 16:15:21 -04:00
Bryanskiy
874ee5bede add crt-static for android 2022-08-10 19:42:24 +03:00
Michael Goulet
eff71b9927
Rollup merge of #100371 - xfix:inline-from-bytes-with-nul-unchecked-rt-impl, r=scottmcm
Inline CStr::from_bytes_with_nul_unchecked::rt_impl

Currently `CStr::from_bytes_with_nul_unchecked::rt_impl` is not being inlined. The following function:

```rust
pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) {
    CStr::from_bytes_with_nul_unchecked(bytes);
}
```

Outputs the following assembly on current nightly

```asm
example::from_bytes_with_nul_unchecked:
        jmp     qword ptr [rip + _ZN4core3ffi5c_str4CStr29from_bytes_with_nul_unchecked7rt_impl17h026f29f3d6a41333E@GOTPCREL]
```

Meanwhile on beta this provides the following assembly:

```asm
example::from_bytes_with_nul_unchecked:
        ret
```

This pull request adds `#[inline]` annotation to`rt_impl` to fix a code generation regression for `CStr::from_bytes_with_nul_unchecked`.
2022-08-10 09:28:25 -07:00
Michael Goulet
efa182f3db
Rollup merge of #100353 - theli-ua:master, r=joshtriplett
Fix doc links in core::time::Duration::as_secs
2022-08-10 09:28:23 -07:00
Martin Habovstiak
2a3ce7890c Stabilize ptr_const_cast
This stabilizes `ptr_const_cast` feature as was decided in a recent
[FCP](https://github.com/rust-lang/rust/issues/92675#issuecomment-1190660233)

Closes #92675
2022-08-10 17:22:58 +02:00
joboet
3d21c371ef
std: optimize thread ID generation 2022-08-10 16:56:09 +02:00
Konrad Borowski
de95117ea8 Inline CStr::from_bytes_with_nul_unchecked::rt_impl 2022-08-10 12:21:17 +00:00
Matthias Krüger
3b97de6b1b
Rollup merge of #100345 - vincenzopalazzo:macros/is_number_doc, r=joshtriplett
docs: remove repetition in `is_numeric` function docs

In https://github.com/rust-lang/rust/pull/99628 we introduce new docs for the `is_numeric` function, and this is a follow-up PR that removes some unnecessary repetition that may be introduced by some rebasing.

`@rustbot` r? `@joshtriplett`
2022-08-10 07:21:39 +02:00
Matthias Krüger
0cbecda7fe
Rollup merge of #100332 - eholk:stabilize-ilog, r=scottmcm
Rename integer log* methods to ilog*

This reflects the concensus from the libs team as reported at https://github.com/rust-lang/rust/issues/70887#issuecomment-1209513261.

Joint work with `@yoshuawuyts.`
2022-08-10 07:21:36 +02:00
Matthias Krüger
e10f924e27
Rollup merge of #99573 - tbodt:stabilize-backtrace, r=yaahc
Stabilize backtrace

This PR stabilizes the std::backtrace module. As of #99431, the std::Error::backtrace item has been removed, and so the rest of the backtrace feature is set to be stabilized.

Previous discussion can be found in #72981, #3156.

Stabilized API summary:
```rust
pub mod std {
    pub mod backtrace {
        pub struct Backtrace { }
        pub enum BacktraceStatus {
            Unsupported,
            Disabled,
            Captured,
        }
        impl fmt::Debug for Backtrace {}
        impl Backtrace {
            pub fn capture() -> Backtrace;
            pub fn force_capture() -> Backtrace;
            pub const fn disabled() -> Backtrace;
            pub fn status(&self) -> BacktraceStatus;
        }
        impl fmt::Display for Backtrace {}
    }
}
```

`@yaahc`
2022-08-10 07:21:33 +02:00
Anton Romanov
4a71447d38 Fix doc links in core::time::Duration::as_secs 2022-08-09 21:15:06 -07:00
Jane Losare-Lusby
21396828e4
Apply suggestions from code review 2022-08-09 15:59:53 -07:00
Vincenzo Palazzo
23bd7cbcb1 docs: remove repetition
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-08-09 21:54:05 +00:00
Dan Vail
ee8a01f596 Switching documentation to be more clear about potential errors 2022-08-09 12:57:19 -05:00
Dan Vail
0436067210
Merge branch 'rust-lang:master' into issue-98861-fix 2022-08-09 12:52:11 -05:00
Eric Holk
c18f22058b Rename integer log* methods to ilog*
This reflects the concensus from the libs team as reported at
https://github.com/rust-lang/rust/issues/70887#issuecomment-1209513261

Co-authored-by: Yosh Wuyts <github@yosh.is>
2022-08-09 10:20:49 -07:00
Waffle Maybe
d52ed8234e
move an assert! to the right place 2022-08-09 21:19:19 +04:00
BlackHoleFox
0cf9503751 Replace pointer casting in hashmap_random_keys with safe code
The old code was unnecessarily unsafe and relied on the layout
of tuples always being the same as an array of the same size.
2022-08-08 18:49:17 -07:00
Anton Romanov
63be9a95b6 Update Duration::as_secs doc to point to as_secs_f64/32 for including fractional part
Rather than suggesting to calculate manually
2022-08-08 18:32:16 -07:00
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
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