Commit Graph

9650 Commits

Author SHA1 Message Date
Ralf Jung
29d451ccb3 fmt 2022-11-07 15:24:49 +01:00
Ralf Jung
780952f922 run alloc benchmarks in Miri and fix UB 2022-11-07 10:34:04 +01:00
Yuki Okushi
7ca833efe0
Rollup merge of #104074 - yancyribbens:add-example-to-round, r=Mark-Simulacrum
rustdoc: Add an example for round that is different from truncate

The current examples for [round](https://github.com/rust-lang/rust/blob/master/library/std/src/f64.rs#L75) would have the same results as the example for [truncate](https://github.com/rust-lang/rust/blob/master/library/std/src/f64.rs#L95).  This PR adds one more example to `round` that will have a different result from `truncate`.
2022-11-07 09:46:29 +09:00
Yuki Okushi
57daec5989
Rollup merge of #104056 - ripytide:patch-1, r=Mark-Simulacrum
Vec: IntoIterator signature consistency

Also makes the code dryer.
2022-11-07 09:46:26 +09:00
yancy
a398e09e42 rustdoc: Add an example for round that is different from truncate 2022-11-06 23:05:16 +01:00
bors
7eef946fc0 Auto merge of #99943 - compiler-errors:tuple-trait, r=jackh726
Implement `std::marker::Tuple`, use it in `extern "rust-call"` and `Fn`-family traits

Implements rust-lang/compiler-team#537

I made a few opinionated decisions in this implementation, specifically:
1. Enforcing `extern "rust-call"` on fn items during wfcheck,
2. Enforcing this for all functions (not just ones that have bodies),
3. Gating this `Tuple` marker trait behind its own feature, instead of grouping it into (e.g.) `unboxed_closures`.

Still needing to be done:
1. Enforce that `extern "rust-call"` `fn`-ptrs are well-formed only if they have 1/2 args and the second one implements `Tuple`. (Doing this would fix ICE in #66696.)
2. Deny all explicit/user `impl`s of the `Tuple` trait, kinda like `Sized`.
3. Fixing `Tuple` trait built-in impl for chalk, so that chalkification tests are un-broken.

Open questions:
1. Does this need t-lang or t-libs signoff?

Fixes #99820
2022-11-06 17:48:33 +00:00
ripytide
743726e352
Vec: IntoIterator signature consistency
Also makes the code dryer.
2022-11-06 15:25:00 +00:00
Matthias Krüger
d93b5200d5
Rollup merge of #104002 - RalfJung:unsafecell-new, r=JohnTitor
fix a comment in UnsafeCell::new

There are several safe methods that access the inner value: `into_inner` has existed since forever and `get_mut` also exists since recently. So this comment seems just wrong. But `&self` methods return raw pointers and thus require unsafe code (though the methods themselves are still safe).
2022-11-06 08:35:27 +01:00
Michael Goulet
d9891563d3 Merge conflicts and rebase onto master 2022-11-05 18:05:44 +00:00
Michael Goulet
2786acce98 Enforce Tuple trait on Fn traits 2022-11-05 17:34:47 +00:00
Ralf Jung
dad327090a fix a comment in UnsafeCell::new 2022-11-05 12:27:43 +01:00
Dylan DPC
47e6304e32
Rollup merge of #103995 - SUPERCILEX:typos, r=Dylan-DPC
Small round of typo fixes
2022-11-05 11:31:30 +05:30
Alex Saveau
849d89b031
Small round of typo fixes
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-04 20:06:18 -07:00
Matthias Krüger
c38ee06b62
Rollup merge of #103681 - RalfJung:libtest-thread, r=thomcc
libtest: run all tests in their own thread, if supported by the host

This reverts the threading changes of https://github.com/rust-lang/rust/pull/56243, which made it so that with `-j1`, the test harness does not spawn any threads. Those changes were done to enable Miri to run the test harness, but Miri supports threads nowadays, so this is no longer needed. Using a thread for each test is useful because the thread's name can be set to the test's name which makes panic messages consistent between `-j1` and `-j2` runs and also a bit more readable.

I did not revert the HashMap changes of https://github.com/rust-lang/rust/pull/56243; using a deterministic map seems fine for the test harness and the more deterministic testing is the better.

Fixes https://github.com/rust-lang/rust/issues/59122
Fixes https://github.com/rust-lang/rust/issues/70492
2022-11-04 18:52:26 +01:00
Matthias Krüger
dabb6c6bd7
Rollup merge of #103367 - chbaker0:update-std-getrandom, r=thomcc
Remove std's transitive dependency on cfg-if 0.1

After https://github.com/rust-lang/rust/pull/101946 this completes the move to cfg-if 1.0 by:
* Updating getrandom 0.1.14->0.1.16
* Updating panic_abort's and unwind's dep to cfg-if 1.0

Fixes https://github.com/rust-lang/rust/issues/103365
2022-11-04 18:52:25 +01:00
Matthias Krüger
9398676635
Rollup merge of #103941 - douweschulte:patch-1, r=jyn514
Fixed typos

Fixed a typo that has been found on two locations in comments.
2022-11-04 12:18:02 +01:00
Matthias Krüger
428dd011ca
Rollup merge of #103680 - RalfJung:cstr-links, r=JohnTitor
CStr: add some doc links
2022-11-04 12:18:00 +01:00
Douwe Schulte
f65cb6868d
Fixed typos
Fixed a typo that has been found on two locations in comments.
2022-11-03 21:19:02 +00:00
Collin Baker
dfab01b6e0 Remove std's transitive dependency on cfg-if 0.1
After rust-lang/rust#101946 this completes the move to cfg-if 1.0 by:
* Updating getrandom 0.1.14->0.1.16
* Updating panic_abort, panic_unwind, and unwind to cfg-if 1.0
2022-11-02 18:01:20 -04:00
Dylan DPC
68db106366
Rollup merge of #103807 - H4x5:string-extend-from-within-tracking-issue, r=Dylan-DPC
Add tracking issue for `string_extend_from_within`

Tracking issue: #103806

The original PR didn't create a tracking issue.
2022-11-02 22:32:04 +05:30
Dylan DPC
bbd3a10663
Rollup merge of #103774 - compiler-errors:dyn-trait-in-type-name, r=eholk
Format `dyn Trait` better in `type_name` intrinsic

Noticed this in #103764 (though not related to that PR at all!)

```rust
trait Foo {
    type Bar;
}

fn main() {
    println!(
        "`dyn Fn(i32, i32) -> i32` => `{}`",
        std::any::type_name::<dyn Fn(i32, i32) -> i32>()
    );
    println!(
        "`dyn Foo<Bar = i32> + Send + Sync` => `{}`",
        std::any::type_name::<dyn Foo<Bar = i32> + Send + Sync>()
    );
}
```

```
`dyn Fn(i32, i32) -> i32` => `dyn core::ops::function::Fn<(i32, i32)>+Output = i32`
`dyn Foo<Bar = i32> + Send + Sync` => `dyn playground::Foo+Bar = i32+core::marker::Sync+core::marker::Send`
```

Just reuse `pretty_print_dyn_existential` which already makes an attempt to make its output stable.
2022-11-02 22:32:03 +05:30
Manish Goregaokar
65d63caf8d
Rollup merge of #103637 - ChrisDenton:stdio-uwp, r=thomcc
Use stdio in UWP apps

Fixes #103233

This has been supported since Windows 10.0.16299. See https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-console-l1-1-0dll
2022-11-01 20:00:38 -04:00
Manish Goregaokar
d4bd794f5e
Rollup merge of #103084 - inquisitivecrystal:control-flow, r=scottmcm
Derive `Eq` and `Hash` for `ControlFlow`

There's really no reason for `ControlFlow` not to derive these traits. This is the part of #96416 that no one objected to, but that PR seems stale. The `Eq` derive was also [requested](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60ControlFlow.3A.20Eq.60/near/303610659) by `@lcnr` on Zulip to allow for pattern matching.

This change requires an FCP because it's insta-stable.

Closes #96416.
2022-11-01 20:00:37 -04:00
Michael Goulet
e24df2778f Format dyn Trait better in type_name intrinsic 2022-11-01 20:41:47 +00:00
Dylan DPC
5d30bfc431
Rollup merge of #103809 - tyggja:patch-1, r=JohnTitor
Fix a typo in std::net mod doc comment

net-doc syntax
2022-11-01 14:12:27 +05:30
Dylan DPC
20528baac4
Rollup merge of #103729 - RalfJung:align-of-val-packed, r=oli-obk
interpret: fix align_of_val on packed types

Fixes https://github.com/rust-lang/miri/issues/2632

r? `@oli-obk`
2022-11-01 14:12:26 +05:30
Dylan DPC
43634675f6
Rollup merge of #103061 - Amanieu:rewrite_alloc_error_handler, r=bjorn3
Rewrite implementation of `#[alloc_error_handler]`

The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called.

This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-11-01 14:12:25 +05:30
bors
95a3a7277b Auto merge of #103795 - thomcc:untest, r=Mark-Simulacrum
Include both benchmarks and tests in the numbers given to `TeFiltered{,Out}`

Fixes #103794

`#[bench]` is broken on nightly without this, sadly. It apparently has no test coverage. In addition to manually testing, I've added a run-make smokecheck for this (which would have caught the issue), but it would be nice to have a better way to test, err, libtest. For now we should get this in ASAP IMO
2022-10-31 18:50:06 +00:00
Amanieu d'Antras
56074b5231 Rewrite implementation of #[alloc_error_handler]
The new implementation doesn't use weak lang items and instead changes
`#[alloc_error_handler]` to an attribute macro just like
`#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by
the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom`
function is defined in any crate then the compiler shim will call
`__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with
`default_alloc_error_handler`: `__rg_oom` was previously defined in the
alloc crate and would attempt to reference the `oom` lang item, even if
it didn't exist. This worked as long as `__rg_oom` was excluded from
linking since it was not called.

This is a prerequisite for the stabilization of
`default_alloc_error_handler` (#102318).
2022-10-31 16:32:57 +00:00
tyggja
7fe1622b71
Update mod.rs 2022-10-31 12:17:30 -04:00
Sky
3e23d60a32
Add tracking issue for string_extend_from_within 2022-10-31 12:01:20 -04:00
Dylan DPC
d80bcf8316
Rollup merge of #103766 - lukas-code:error-in-core, r=Dylan-DPC
Add tracking issue to `error_in_core`

This was merged in https://github.com/rust-lang/rust/pull/99917 without a tracking issue, so I'm creating one now: https://github.com/rust-lang/rust/issues/103765
2022-10-31 14:52:57 +05:30
Thom Chiovoloni
b56cb9e032
Include both benchmarks and tests in the numbers given to TeFiltered{,Out} 2022-10-31 00:42:10 -07:00
Lukas Markeffsky
f56d3c3140 Add tracking issue to error_in_core 2022-10-30 17:26:46 +01:00
Dylan DPC
176a89f496
Rollup merge of #103689 - saethlin:libtest-startup, r=thomcc
Do fewer passes and generally be more efficient when filtering tests

Follow-on of the work I started with this PR: https://github.com/rust-lang/rust/pull/99939

Basically, the startup code for libtest is really inefficient, but that's not usually a problem because it is distributed in release and workloads are small. But under Miri which can be 100x slower than a debug build, these inefficiencies explode.

Most of the diff here is making test filtering single-pass. There are a few other small optimizations as well, but they are more straightforward.

With this PR, the startup time of the `iced` tests with `--features=code_asm,mvex` drops from 17 to 2 minutes (I think Miri has gotten slower under this workload since #99939). The easiest way to try this out is to set `MIRI_LIB_SRC` to a checkout of this branch when running `cargo +nightly miri test --features=code_asm,mvex`.

r? `@thomcc`
2022-10-30 11:50:27 +05:30
Matthias Krüger
e4821d743b
Rollup merge of #103715 - tshepang:consistency, r=Dylan-DPC
use consistent terminology

I did not see other traits using the "interface" word
2022-10-30 00:09:25 +02:00
Matthias Krüger
22e320b2c9
Rollup merge of #100006 - jyn514:update-copy, r=dtolnay
Make `core::mem::copy` const

cc https://github.com/rust-lang/rust/issues/98262, https://github.com/rust-lang/libs-team/issues/78
2022-10-30 00:09:23 +02:00
Ralf Jung
d366471e58 interpret: fix align_of_val on packed types 2022-10-29 15:58:32 +02:00
Guillaume Gomez
6425764045
Rollup merge of #103719 - joseluis:fix-typos-try-reserve, r=the8472
fix typo in `try_reserve` method from `HashMap` and `HashSet`

Currently refers to the `reserve` method, instead of `try_reserve`. Other collections like [Vec](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.try_reserve) & [VecDeque](https://doc.rust-lang.org/std/collections/vec_deque/struct.VecDeque.html#method.try_reserve) shows it well.
2022-10-29 14:18:05 +02:00
Guillaume Gomez
6dd64d38a3
Rollup merge of #102721 - nbdd0121:panic, r=Amanieu
Prevent foreign Rust exceptions from being caught

Fix #102715

Use the address of a static variable (which is guaranteed to be unique per copy of std) to tell apart if a Rust exception comes from local or foreign Rust code, and abort for the latter.
2022-10-29 14:18:02 +02:00
joseLuís
4b353132f5 fix typo in hashmap and hashset try_reserve method 2022-10-29 11:01:06 +02:00
Tshepang Mbambo
a36a37e5a8 use consistent terminology
I did not see other traits using the "interface" word
2022-10-29 09:23:12 +02:00
Matthias Krüger
b3ca68f9e9
Rollup merge of #102961 - reitermarkus:const-cstr-from-ptr, r=oli-obk
Make `CStr::from_ptr` `const`.

Should be included in https://github.com/rust-lang/rust/issues/101719.

cc ``@WaffleLapkin``
2022-10-29 08:57:34 +02:00
bors
7174231ae6 Auto merge of #102737 - RalfJung:poll_fn_pin, r=Mark-Simulacrum
poll_fn and Unpin: fix pinning

See [IRLO](https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484) for details: currently `poll_fn` is very subtle to use, since it does not pin the closure, so creating a `Pin::get_unchcked(&mut capture)` inside the closure is unsound. This leads to actual miscompilations with `futures::join!`.

IMO the proper fix is to pin the closure when the future is pinned, which is achieved by changing the `Unpin` implementation. This is a breaking change though. 1.64.0 was *just* released, so maybe this is still okay?

The alternative would be to add some strong comments to the docs saying that closure captures are *not pinned* and doing `Pin::get_unchecked` on them is unsound.
2022-10-28 23:27:33 +00:00
Markus Reiter
b3f9277a17
Remove unneeded attribute. 2022-10-28 14:17:34 +02:00
Ralf Jung
3af058ec94 libtest: run all tests in their own thread, if supported by the host 2022-10-28 12:26:09 +02:00
Ralf Jung
a6c3f6ce1d CStr: add some doc links 2022-10-28 10:24:14 +02:00
Ben Kimock
17b86cb611 Do fewer passes and generally be more efficient when filtering tests 2022-10-27 21:34:56 -04:00
Chris Denton
5857c3045a
Use stdio in UWP apps
This has been supported since Windows 10.0.16299. See https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-console-l1-1-0dll
2022-10-27 17:21:30 +01:00
Matthias Krüger
c75e6f559f
Rollup merge of #103394 - Pointerbender:unsafecell-docs, r=Amanieu
Clarify documentation about the memory layout of `UnsafeCell`

This PR addresses a [comment](https://github.com/rust-lang/rust/pull/101717#issuecomment-1279908390) by `@RalfJung` in PR #101717 to further clarify the documentation of `UnsafeCell<T>`. The previous PR was merged already before we had a chance to correct this, hence this second PR :)

To goal of this PR is:

1. Split the paragraph about the memory layout of `UnsafeCell<T>` and the usage of `UnsafeCell::(raw_)get()` into two paragraphs, so that it is easier to digest for the reader.
2. Slightly simplify the previously added examples in order to reduce redundancy between the new examples and the examples that already [existed](ddd119b2fe/library/core/src/cell.rs (L1858-L1908)) before these 2 PRs (which remained untouched by both PRs).
2022-10-27 15:03:56 +02:00