Commit graph

5909 commits

Author SHA1 Message Date
Ed Morley
b41b2e5a5c
Document unreachable!() custom panic message
The `unreachable!` docs previously did not mention that there was a second
form, `unreachable!("message")` that could be used to specify a custom panic
message,

The docs now mention this in the same style as currently used for `unimplemented!`:
https://doc.rust-lang.org/core/macro.unimplemented.html#panics
2021-11-11 13:41:21 +00:00
bors
d71ba74f0d Auto merge of #88798 - sunfishcode:sunfishcode/windows-null-handles, r=joshtriplett
Fix assertion failures in `OwnedHandle` with `windows_subsystem`.

As discussed in #88576, raw handle values in Windows can be null, such
as in `windows_subsystem` mode, or when consoles are detached from a
process. So, don't use `NonNull` to hold them, don't assert that they're
not null, and remove `OwnedHandle`'s `repr(transparent)`. Introduce a
new `HandleOrNull` type, similar to `HandleOrInvalid`, to cover the FFI
use case.

r? `@joshtriplett`
2021-11-11 12:07:53 +00:00
bors
62efba8a05 Auto merge of #90755 - scottmcm:spec-array-clone, r=jackh726
Specialize array cloning for Copy types

Because after PR 86041, the optimizer no longer load-merges at the LLVM IR level, which might be part of the perf loss.  (I'll run perf and see if this makes a difference.)

Also I added a codegen test so this hopefully won't regress in future -- it passes on stable and with my change here, but not on the 2021-11-09 nightly.

Example on current nightly: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=1f52d46fb8fc3ca3ac9f097390085ffa>
```rust
type T = u8;
const N: usize = 3;

pub fn demo_clone(x: &[T; N]) -> [T; N] {
    x.clone()
}

pub fn demo_copy(x: &[T; N]) -> [T; N] {
    *x
}
```
```llvm-ir
; playground::demo_clone
; Function Attrs: mustprogress nofree nosync nounwind nonlazybind uwtable willreturn
define i24 `@_ZN10playground10demo_clone17h98a4f11453d1a753E([3` x i8]* noalias nocapture readonly align 1 dereferenceable(3) %x) unnamed_addr #0 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* `@rust_eh_personality` {
start:
  %0 = getelementptr [3 x i8], [3 x i8]* %x, i64 0, i64 0
  %1 = getelementptr inbounds [3 x i8], [3 x i8]* %x, i64 0, i64 1
  %.val.i.i.i.i.i.i.i.i.i = load i8, i8* %0, align 1, !alias.scope !2, !noalias !9
  %2 = getelementptr inbounds [3 x i8], [3 x i8]* %x, i64 0, i64 2
  %.val.i.i.i.i.i.1.i.i.i.i = load i8, i8* %1, align 1, !alias.scope !2, !noalias !20
  %.val.i.i.i.i.i.2.i.i.i.i = load i8, i8* %2, align 1, !alias.scope !2, !noalias !23
  %array.sroa.6.0.insert.ext.i.i.i.i = zext i8 %.val.i.i.i.i.i.2.i.i.i.i to i32
  %array.sroa.6.0.insert.shift.i.i.i.i = shl nuw nsw i32 %array.sroa.6.0.insert.ext.i.i.i.i, 16
  %array.sroa.5.0.insert.ext.i.i.i.i = zext i8 %.val.i.i.i.i.i.1.i.i.i.i to i32
  %array.sroa.5.0.insert.shift.i.i.i.i = shl nuw nsw i32 %array.sroa.5.0.insert.ext.i.i.i.i, 8
  %array.sroa.0.0.insert.ext.i.i.i.i = zext i8 %.val.i.i.i.i.i.i.i.i.i to i32
  %array.sroa.5.0.insert.insert.i.i.i.i = or i32 %array.sroa.5.0.insert.shift.i.i.i.i, %array.sroa.0.0.insert.ext.i.i.i.i
  %array.sroa.0.0.insert.insert.i.i.i.i = or i32 %array.sroa.5.0.insert.insert.i.i.i.i, %array.sroa.6.0.insert.shift.i.i.i.i
  %.sroa.4.0.extract.trunc.i.i.i.i = trunc i32 %array.sroa.0.0.insert.insert.i.i.i.i to i24
  ret i24 %.sroa.4.0.extract.trunc.i.i.i.i
}

; playground::demo_copy
; Function Attrs: mustprogress nofree norecurse nosync nounwind nonlazybind readonly uwtable willreturn
define i24 `@_ZN10playground9demo_copy17h7817453f9291d746E([3` x i8]* noalias nocapture readonly align 1 dereferenceable(3) %x) unnamed_addr #1 {
start:
  %.sroa.0.0..sroa_cast = bitcast [3 x i8]* %x to i24*
  %.sroa.0.0.copyload = load i24, i24* %.sroa.0.0..sroa_cast, align 1
  ret i24 %.sroa.0.0.copyload
}
```
2021-11-11 09:13:22 +00:00
tamaron
181716a16c compare between Path instead of str 2021-11-11 11:40:34 +09:00
bors
8e0293137f Auto merge of #90784 - matthiaskrgr:rollup-car8g12, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #89930 (Only use `clone3` when needed for pidfd)
 - #90736 (adjust documented inline-asm register constraints)
 - #90783 (Update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-10 23:13:06 +00:00
Matthias Krüger
a09115f3b4
Rollup merge of #89930 - cuviper:avoid-clone3, r=joshtriplett
Only use `clone3` when needed for pidfd

In #89522 we learned that `clone3` is interacting poorly with Gentoo's
`sandbox` tool. We only need that for the unstable pidfd extensions, so
otherwise avoid that and use a normal `fork`.

This is a re-application of beta #89924, now that we're aware that we need
more than just a temporary release fix. I also reverted 12fbabd27f, as
that was just fallout from using `clone3` instead of `fork`.

r? `@Mark-Simulacrum`
cc `@joshtriplett`
2021-11-10 23:04:25 +01:00
Scott McMurray
5b115fcb68 Moar #[inline] 2021-11-10 11:57:14 -08:00
Alex Crichton
1ac5d7dcde std: Tweak expansion of thread-local const
This commit tweaks the expansion of `thread_local!` when combined with a
`const { ... }` value to help ensure that the rules which apply to
`const { ... }` blocks will be the same as when they're stabilized.
Previously with this invocation:

    thread_local!(static NAME: Type = const { init_expr });

this would generate (on supporting platforms):

    #[thread_local]
    static NAME: Type = init_expr;

instead the macro now expands to:

    const INIT_EXPR: Type = init_expr;
    #[thread_local]
    static NAME: Type = INIT_EXPR;

with the hope that because `init_expr` is defined as a `const` item then
it's not accidentally allowing more behavior than if it were put into a
`static`. For example on the stabilization issue [this example][ex] now
gives the same error both ways.

[ex]: https://github.com/rust-lang/rust/issues/84223#issuecomment-953384298
2021-11-10 11:07:43 -08:00
Alex Crichton
e4b3496618 Update stdarch/dlmalloc
Ensure that they compile with the now-a-feature-is-required logic.
2021-11-10 08:35:43 -08:00
Alex Crichton
b5c3f4c5d8 Update dlmalloc for libstd
This pulls in a fix for wasm64 to work correctly with this dlmalloc
2021-11-10 08:35:43 -08:00
Alex Crichton
88f1bf73ee Update stdarch/compiler_builtins
Brings in some fixes and better support for the wasm64 target.
2021-11-10 08:35:42 -08:00
Alex Crichton
d2a3c24a95 Update more rustc/libtest things for wasm64
* Add wasm64 variants for inline assembly along the same lines as wasm32
* Update a few directives in libtest to check for `target_family`
  instead of `target_arch`
* Update some rustc codegen and typechecks specialized for wasm32 to
  also work for wasm64.
2021-11-10 08:35:42 -08:00
Alex Crichton
caa9e4a2d0 Review comments 2021-11-10 08:35:42 -08:00
Alex Crichton
971638824f Use target_family = "wasm" 2021-11-10 08:35:42 -08:00
Alex Crichton
7f3ffbc8c2 std: Get the standard library compiling for wasm64
This commit goes through and updates various `#[cfg]` as appropriate to
get the wasm64-unknown-unknown target behaving similarly to the
wasm32-unknown-unknown target. Most of this is just updating various
conditions for `target_arch = "wasm32"` to also account for `target_arch
= "wasm64"` where appropriate. This commit also lists `wasm64` as an
allow-listed architecture to not have the `restricted_std` feature
enabled, enabling experimentation with `-Z build-std` externally.

The main goal of this commit is to enable playing around with
`wasm64-unknown-unknown` externally via `-Z build-std` in a way that's
similar to the `wasm32-unknown-unknown` target. These targets are
effectively the same and only differ in their pointer size, but wasm64
is much newer and has much less ecosystem/library support so it'll still
take time to get wasm64 fully-fledged.
2021-11-10 08:35:42 -08:00
Joseph Roitman
7b40448a6f Fix collection entry API documentation. 2021-11-10 12:37:18 +02:00
Scott McMurray
cc7d8014d7 Specialize array cloning for Copy types
Because after PR 86041, the optimizer no longer load-merges at the LLVM IR level, which might be part of the perf loss.  (I'll run perf and see if this makes a difference.)

Also I added a codegen test so this hopefully won't regress in future -- it passes on stable and with my change here, but not on the 2021-11-09 nightly.
2021-11-09 21:43:20 -08:00
Matthias Krüger
e7375016eb
Rollup merge of #90751 - ehuss:update-books, r=ehuss
Update books

## nomicon

1 commits in 358e6a61d5f4f0496d0a81e70cdcd25d05307342..c6b4bf831e9a40aec34f53067d20634839a6778b
2021-10-20 11:23:12 -0700 to 2021-11-09 02:30:56 +0900
- Replace some use of variant with covariant (rust-lang/nomicon#322)

## book

11 commits in fd9299792852c9a368cb236748781852f75cdac6..5c5dbc5b196c9564422b3193264f3288d2a051ce
2021-10-22 21:59:46 -0400 to 2021-11-09 19:30:43 -0500
- Fix constants link.
- Fix updated anchor
- Propagate edits to chapter 2 back
- Edits to nostarch's chapter 3 edits
- ch 3 from nostarch
- Fix Cargo.toml snippet about custom derive macros
- Snapshot of chapter 9 for nostarch
- Create tmp/src for converting quotes, not sure why this broke but ok
- Update question mark to better explain where it can be used
- Clarify sentence about Results in functions that don't return Result. Fixes rust-lang/book#2912.
- Merge pull request rust-lang/book#2913 from covariant/patch-1

## rust-by-example

2 commits in 27f1ff5e440ef78828b68ab882b98e1b10d9af32..e9d45342d7a6c1def4731f1782d87ea317ba30c3
2021-10-13 08:04:40 -0300 to 2021-11-02 13:33:03 -0500
- Enums: Linked-List Needs Re-Wording (rust-lang/rust-by-example#1469)
- fix: Use the point as top left corner for `square` (rust-lang/rust-by-example#1471)

## rustc-dev-guide

13 commits in b06008731af0f7d07cd0614e820c8276dfed1c18..196ef69aa68f2cef44f37566ee7db37daf00301b
2021-10-21 15:13:09 -0500 to 2021-11-07 07:48:47 -0600
- Fix typo: [upv.rs_mentioned] -&gt; [upvars_mentioned]
- Add note to emphasize replacing TARGET_TRIPLE (rust-lang/rustc-dev-guide#1250)
- Remove some legacy test suites.
- tiny capitalization fix
- Fix date
- Update some date-check comments
- Ensure date-check cron job is using latest stable Rust
- enhance subtree docs, link to clippy docs
- Edit introduction to bootstrapping
- Some minor adjustments to the diagnostic documentation
- Edit "About this guide" for semantic line feeds
- Fix `rustc_mir` related links (rust-lang/rustc-dev-guide#1228)
- Add documentation for LLVM CFI support

## edition-guide

3 commits in 7c0088ca744d293a5f4b1e2ac378e7c23d30fe55..27f4a84d3852e9416cae5861254fa53a825c56bd
2021-10-05 13:28:05 +0200 to 2021-11-08 10:13:20 -0500
- Add a missing period (rust-lang/edition-guide#271)
- Fix syntax error in code example (rust-lang/edition-guide#270)
- Fixed an example error of prelude.md (rust-lang/edition-guide#269)
2021-11-10 06:02:56 +01:00
Matthias Krüger
ebd15290a2
Rollup merge of #90748 - cuviper:track-setgroups, r=dtolnay
Add a real tracking issue for `CommandExt::groups`

The `unstable` attribute referenced the closed RFE #38527, so I filed tracking issue #90747.
2021-11-10 06:02:55 +01:00
Matthias Krüger
5bc09362dc
Rollup merge of #90690 - solid-rs:fix-kmc-solid-asm-const, r=Mark-Simulacrum
kmc-solid: Avoid the use of `asm_const`

This PR removes the use of [the now-separated-out `asm_const` compiler feature][1] in `std::sys::solid` to fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

[1]: https://github.com/rust-lang/rust/pull/90348
2021-11-10 06:02:54 +01:00
Eric Huss
9be22db5e1 Update books 2021-11-09 19:11:01 -08:00
Josh Stone
c0fbadaba3 Add a real tracking issue for CommandExt::groups 2021-11-09 17:28:56 -08:00
bors
8b09ba6a5d Auto merge of #90734 - matthiaskrgr:rollup-e1euotp, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #89561 (Type inference for inline consts)
 - #90035 (implement rfc-2528 type_changing-struct-update)
 - #90613 (Allow to run a specific rustdoc-js* test)
 - #90683 (Make `compiler-docs` only control the default instead of being a hard off-switch)
 - #90685 (x.py: remove fixme by deleting code)
 - #90701 (Record more artifact sizes during self-profiling.)
 - #90723 (Better document `Box` and `alloc::alloc::box_free` connection)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-09 20:09:53 +00:00
The8472
a6e0aa20d9 remove redundant .iter() call since zip() takes an IntoIterator argument 2021-11-09 20:54:42 +01:00
The8472
7f6e080120 add fast path on Path::eq for exact equality 2021-11-09 20:54:42 +01:00
The8472
a083dd653a optimize Hash for Path
Hashing does not have to use the whole Components parsing machinery because we only need it to match the
normalizations that Components does.

* stripping redundant separators -> skipping separators
* stripping redundant '.' directories -> skipping '.' following after a separator

That's all it takes.

And instead of hashing individual slices for each component we feed the bytes directly into the hasher which avoids
hashing the length of each component in addition to its contents.
2021-11-09 20:54:42 +01:00
The8472
82b4544ddc add benchmarks and tests for Hash and Eq impls on Path
The tests check for consistency between Ord, Eq and Hash
2021-11-09 20:54:00 +01:00
est31
eeaa2f16aa Extend the const_swap feature
This makes the inherent method ptr::swap unstably
const, as well as slice::swap{,_unchecked}.
2021-11-09 20:09:56 +01:00
Jubilee Young
caf206b820 Stabilize File::options()
Renames File::with_options to File::options, per consensus in
rust-lang/rust#65439, and stabilizes it.
2021-11-09 10:22:28 -08:00
Matthias Krüger
9c1aa12ff1
Rollup merge of #90723 - asquared31415:box_docs, r=jyn514
Better document `Box` and `alloc::alloc::box_free` connection

The internal `alloc::alloc::box_free` function requires that its signature matches the `owned_box` struct's declaration, but previously that connection was only documented on the `box_free` function.

This PR makes the documentation two-way to help anyone making theoretical changes to `Box` to see the connection, since changes are more likely to originate from `Box`.
2021-11-09 19:00:46 +01:00
bors
d6082292a6 Auto merge of #86041 - bstrie:unmagic-array-copy, r=jackh726
Replace Copy/Clone compiler magic on arrays with library impls

With const generics the compiler no longer needs to fake these impls.
2021-11-09 17:13:44 +00:00
Yuki Okushi
d638c1d13c
Rollup merge of #87530 - bstrie:commentsync, r=bstrie
Add comments regarding superfluous `!Sync` impls
2021-11-09 22:02:21 +09:00
asquared31415
db4e60b29f document Box and box_free connection 2021-11-09 07:13:53 -05:00
Julian Frimmel
60a9d5a5a9 Re-enable copy[_nonoverlapping]() runtime checks
This commit re-enables the debug checks for valid usages of the two
functions `copy()` and `copy_nonoverlapping()`. Those checks were com-
mented out in #79684 in order to make the functions const. All that's
been left was a FIXME, that could not be resolved until there is was way
to only do the checks at runtime.
Since #89247 there is such a way: `const_eval_select()`. This commit
uses that new intrinsic in order to either do nothing (at compile time)
or to do the old checks (at runtime).

The change itself is rather small: in order to make the checks usable
with `const_eval_select`, they are moved into a local function (one for
`copy` and one for `copy_nonoverlapping` to keep symmetry).

The change does not break referential transparency, as there is nothing
you can do at compile time, which you cannot do on runtime without get-
ting undefined behavior. The CTFE-engine won't allow missuses. The other
way round is also fine.
2021-11-09 10:02:09 +01:00
Jacob Pratt
6d2f8af1db
Permit const assertions in stdlib 2021-11-08 17:06:00 -05:00
bstrie
61b1394ac7 Attempt to address perf regressions with #[inline] 2021-11-08 15:51:56 -05:00
bstrie
3024efff59 Update Copy/Clone documentation WRT arrays 2021-11-08 13:11:59 -05:00
bstrie
ce1143e94d impl Copy/Clone for arrays in std, not in compiler 2021-11-08 13:11:58 -05:00
bstrie
86c0ef8adc Add comments regarding superfluous !Sync impls 2021-11-08 13:07:20 -05:00
Guillaume Gomez
f07f800364
Rollup merge of #90494 - Meziu:armv6k-3ds-target, r=sanxiyn
ARMv6K Horizon OS panic change

After a small change to `backtrace-rs` ([#448](https://github.com/rust-lang/backtrace-rs/pull/448)), `PanicStrategy::Unwind` is now fully supported.
2021-11-08 15:15:22 +01:00
Tomoaki Kawada
f17077002b kmc-solid: Avoid the use of asm_const 2021-11-08 19:13:31 +09:00
bors
fecfc0e6cc Auto merge of #89310 - joshtriplett:available-concurrency-affinity, r=m-ou-se
Make `std:🧵:available_concurrency` support process-limited number of CPUs

Use `libc::sched_getaffinity` and count the number of CPUs in the returned mask. This handles cases where the process doesn't have access to all CPUs, such as when limited via `taskset` or similar.

This also covers cgroup cpusets.
2021-11-07 11:53:25 +00:00
bors
90a273b785 Auto merge of #90348 - Amanieu:asm_feature_gates, r=joshtriplett
Add features gates for experimental asm features

This PR splits off parts of `asm!` into separate features because they are not ready for stabilization.

Specifically this adds:
- `asm_const` for `const` operands.
- `asm_sym` for `sym` operands.
- `asm_experimental_arch` for architectures other than x86, x86_64, arm, aarch64 and riscv.

r? `@nagisa`
2021-11-07 04:59:42 +00:00
Amanieu d'Antras
eb32c00216 Add features gates for experimental asm features 2021-11-07 01:23:53 +00:00
Jacob Pratt
0cdbeaa2a3
Stabilize const_raw_ptr_deref for *const T
This stabilizes dereferencing immutable raw pointers in const contexts.
It does not stabilize `*mut T` dereferencing. This is placed behind the
`const_raw_mut_ptr_deref` feature gate.
2021-11-06 17:05:15 -04:00
Matthias Krüger
0a5640b55f use matches!() macro in more places 2021-11-06 16:13:14 +01:00
bors
7276a6a117 Auto merge of #90297 - dtolnay:dotzero, r=petrochenkov
Append .0 to unsuffixed float if it would otherwise become int token

Previously the unsuffixed f32/f64 constructors of `proc_macro::Literal` would create literal tokens that are definitely not a float:

```rust
Literal::f32_unsuffixed(10.0)  // 10
Literal::f32_suffixed(10.0)    // 10f32
Literal::f64_unsuffixed(10.0)  // 10
Literal::f64_suffixed(10.0)    // 10f64
```

Notice that the `10` are actually integer tokens if you were to reparse them, not float tokens.

This diff updates `Literal::f32_unsuffixed` and `Literal::f64_unsuffixed` to produce tokens that unambiguously parse as a float. This matches longstanding behavior of the proc-macro2 crate's implementation of these APIs dating back at least 3.5 years, so it's likely an unobjectionable behavior.

```rust
Literal::f32_unsuffixed(10.0)  // 10.0
Literal::f32_suffixed(10.0)    // 10f32
Literal::f64_unsuffixed(10.0)  // 10.0
Literal::f64_suffixed(10.0)    // 10f64
```

Fixes https://github.com/dtolnay/syn/issues/1085.
2021-11-06 07:15:05 +00:00
Josh Stone
6edaaa6db8 Also note tool expectations of fork vs clone3
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-11-05 14:49:24 -07:00
Josh Stone
fa2eee7bf2 Update another comment on fork vs. clone3 2021-11-05 14:48:52 -07:00
Josh Stone
85b55ce00d Only use clone3 when needed for pidfd
In #89522 we learned that `clone3` is interacting poorly with Gentoo's
`sandbox` tool. We only need that for the unstable pidfd extensions, so
otherwise avoid that and use a normal `fork`.
2021-11-05 14:48:41 -07:00
Yuki Okushi
0b3a002805
Reorder widening_impls to make the doc clearer 2021-11-05 11:55:51 -07:00
bors
d22dd65835 Auto merge of #90604 - mbartlett21:iterator-reexports, r=kennytm
Re-export some iterators from `core` in `std`

These iterators seem to have been forgotten to be re-exported from `std` (through `alloc`)

These are stable:

`core::slice::{SplitInclusive, SplitInclusiveMut}`

This one is still unstable:

`core::slice::EscapeAscii` (cc #77174)
2021-11-05 12:22:13 +00:00
bors
489ec310d2 Auto merge of #90577 - matthiaskrgr:clippy_perf_nov, r=petrochenkov
clippy::perf fixes
2021-11-05 09:17:39 +00:00
mbartlett21
ed63c71d61
Fix str::SplitInclusive stabilisation date 2021-11-05 17:46:58 +10:00
mbartlett21
d606dbe256
Add feature to alloc so we can re-export. 2021-11-05 17:35:07 +10:00
mbartlett21
9ae92ad19a
Re-export core::slice::EscapeAscii 2021-11-05 17:14:57 +10:00
mbartlett21
03d1f24db8
Re-export core::slice::SplitInclusive[Mut] 2021-11-05 15:44:43 +10:00
Yuki Okushi
5aa6eaf4c0
Rollup merge of #90556 - scottmcm:carrying_comments, r=joshtriplett
Add more text and examples to `carrying_{add|mul}`

`feature(bigint_helper_methods)` tracking issue https://github.com/rust-lang/rust/issues/85532

cc `````@clarfonthey`````
2021-11-05 10:32:46 +09:00
Matthias Krüger
28ef4169cc clippy::perf fixes 2021-11-04 21:07:56 +01:00
Scott McMurray
dc2c2603c6 Add more text and examples to `carrying_{add|mul}" 2021-11-04 00:51:45 -07:00
bors
4061c04079 Auto merge of #87467 - inquisitivecrystal:ref-unwind, r=dtolnay
Implement `RefUnwindSafe` for `Rc<T>`

This PR implements `RefUnwindSafe` for `Rc<T>`, where `T: RefUnwindSafe`.

This impl was omitted by an apparent oversight. `Rc<T>` already implements `UnwindSafe`. `Arc<T>` implements both `UnwindSafe` and `RefUnwindSafe`. There is no reason why an `&Rc<T>` is any less unwind safe than a `Rc<T>` or an `&Arc<T>`, so this should be safe to add.

Resolves #45924.
2021-11-04 06:54:21 +00:00
bors
0b4ac62dda Auto merge of #90392 - solid-rs:fix-solid-support, r=Mark-Simulacrum
kmc-solid: Fix SOLID target

This PR is a follow-up for #86191 and necessary to make the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets actually usable.

 - Bumps `libc` to 0.2.106, which includes <https://github.com/rust-lang/libc/pull/2227>.
 - Applies the change made by #89324 to this target's target-specific code.
2021-11-04 03:48:43 +00:00
The8472
7afe6f52e4 Make RawVec private to alloc
RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a935

Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since
it is no longer used outside alloc itself it can be made private again.

Also remove some functions that are dead due to lack of internal users.
2021-11-03 20:52:16 +01:00
bors
87ec5680c9 Auto merge of #90421 - thomcc:friendship-ended-with-ssize_t-now-ptrdiff_t-is-my-best-friend, r=joshtriplett
Replace `std::os::raw::c_ssize_t` with `std::os::raw::c_ptrdiff_t`

The discussions in #88345 brought up that `ssize_t` is not actually the signed index type defined in stddef.h, but instead it's `ptrdiff_t`. It seems pretty clear that the use of `ssize_t` here was a mistake on my part, and that if we're going to bother having a isize-alike for FFI in `std::os::raw`, it should be `ptrdiff_t` and not `ssize_t`.

Anyway, both this and `c_size_t` are dubious in the face of the discussion in https://internals.rust-lang.org/t/pre-rfc-usize-is-not-size-t/15369, and any RFC/project-group/etc that handles those issues there should contend with these types in some manner, but that doesn't mean we shouldn't fix something wrong like this, even if it is unstable.

All that said, `size_t` is *vastly* more common in function signatures than either `ssize_t` or `ptrdiff_t`, so I'm going to update the tracking issue's list of unresolved questions to note that perhaps we only want `c_size_t` — I mostly added the signed version for symmetry, rather than to meet a need. (Given this, I'm also fine with modifying this patch to instead remove `c_ssize_t` without a replacement)

CC `@magicant` (who brought the issue up)
CC `@chorman0773` (who has a significantly firmer grasp on the minutae of the C standard than I do)

r? `@joshtriplett` (original reviewer, active in the discussions around this)
2021-11-03 05:36:30 +00:00
inquisitivecrystal
bd194da4c2 Implement RefUnwindSafe for Rc<T> 2021-11-02 16:30:55 -07:00
bors
c3190c1eb4 Auto merge of #90442 - ChrisDenton:win-tls-dtor, r=alexcrichton
Windows thread-local keyless drop

`#[thread_local]` allows us to maintain a per-thread list of destructors. This also avoids the need to synchronize global data (which is particularly tricky within the TLS callback function).

r? `@alexcrichton`
2021-11-02 12:15:08 +00:00
Meziu
d379147219 Updated backtrace submodule 2021-11-02 12:31:34 +01:00
bors
6384dca100 Auto merge of #90439 - m-ou-se:thread-is-running, r=Mark-Simulacrum
Add JoinHandle::is_running.

This adds:
```rust
impl<T> JoinHandle<T> {
    /// Checks if the the associated thread is still running its main function.
    ///
    /// This might return `false` for a brief moment after the thread's main
    /// function has returned, but before the thread itself has stopped running.
    pub fn is_running(&self) -> bool;
}
```
The usual way to check if a background thread is still running is to set some atomic flag at the end of its main function. We already do that, in the form of dropping an Arc which will reduce the reference counter. So we might as well expose that information.

This is useful in applications with a main loop (e.g. a game, gui, control system, ..) where you spawn some background task, and check every frame/iteration whether the background task is finished to .join() it in that frame/iteration while keeping the program responsive.
2021-11-02 08:11:57 +00:00
r00ster91
5f6cfd211a mention remove in swap_remove 2021-11-01 18:52:26 +01:00
Chris Denton
1048651fa3
Run destructors from existing tls callback 2021-11-01 15:19:49 +00:00
Mara Bos
978ebd9c8c Add tracking issue for thread_is_running. 2021-11-01 15:04:24 +01:00
Tomoaki Kawada
26a6cc4515 itron: Rename itron:🧵:{available_conccurrency -> available_parallelism}
Catching up with commit b4615b5bf9
2021-11-01 10:45:51 +09:00
Tomoaki Kawada
15af06795c Bump libc dependency of std to 0.2.106 2021-11-01 10:45:49 +09:00
Thom Chiovoloni
8d19819781
Re-add std::os::raw::c_ssize_t, with more accurate documentation 2021-10-31 13:01:57 -07:00
Chris Denton
9212f4070e
Windows thread-local keyless drop
`#[thread_local]` allows us to maintain a per-thread list of destructors. This also avoids the need to synchronize global data (which is particularly tricky within the TLS callback function).
2021-10-31 16:09:35 +00:00
bors
c7e4740ec1 Auto merge of #86336 - camsteffen:char-array-pattern, r=joshtriplett
impl Pattern for char array

Closes #39511
Closes #86329
2021-10-31 15:45:39 +00:00
Mara Bos
67362b301b Add test for JoinHandle::is_running. 2021-10-31 15:23:36 +01:00
Mara Bos
d718b1a795 Add JoinHandle::is_running. 2021-10-31 15:09:36 +01:00
Matthias Krüger
455a79acab
Rollup merge of #90431 - jkugelman:must-use-std-o-through-z, r=joshtriplett
Add #[must_use] to remaining std functions (O-Z)

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from O-Z.

`panicking::take_hook` has a side effect: it unregisters the current panic hook, returning it. I almost ignored it, but the documentation example shows `let _ = panic::take_hook();`, so following suit I went ahead and added a `#[must_use]`.

```rust
std::panicking   fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>;
```

I added these functions that clippy did not flag:

```rust
std::path::Path   fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool;
std::path::Path   fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool;
std::path::Path   fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf;
std::path::Path   fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf;
```

Parent issue: #89692

r? `@joshtriplett`
2021-10-31 13:20:07 +01:00
Matthias Krüger
26f505c433
Rollup merge of #90430 - jkugelman:must-use-std-a-through-n, r=joshtriplett
Add #[must_use] to remaining std functions (A-N)

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from A-N.

I added these functions myself. Clippy predictably ignored the `mut` ones, but I don't know why the rest weren't flagged. Check them closely, please? Maybe I overlooked good reasons.

```rust
std::backtrace::Backtrace                                   const fn disabled() -> Backtrace;
std::backtrace::Backtrace<'a>                               fn frames(&'a self) -> &'a [BacktraceFrame];
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn key_mut(&mut self) -> &mut K;
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn get_mut(&mut self) -> &mut V;
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn get_key_value(&mut self) -> (&K, &V);
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn get_key_value_mut(&mut self) -> (&mut K, &mut V);
std::env                                                    fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString>;
std::env                                                    fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_>;
std::io::Error                                              fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)>;
```

Parent issue: #89692

r? `@joshtriplett`
2021-10-31 13:20:06 +01:00
Matthias Krüger
88e5ae2dd3
Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplett
Add #[must_use] to len and is_empty

Parent issue: #89692

r? `@joshtriplett`
2021-10-31 13:20:05 +01:00
Matthias Krüger
6c5aa765fb
Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplett
Restructure std::rt (part 2)

A couple more cleanups on top of https://github.com/rust-lang/rust/pull/89011

Blocked on #89011
2021-10-31 13:20:04 +01:00
Matthias Krüger
ff6d8ecd64
Rollup merge of #90427 - jkugelman:must-use-alloc-leak, r=joshtriplett
Add #[must_use] to alloc functions that would leak memory

As [requested](https://github.com/rust-lang/rust/pull/89899#issuecomment-955600779) by `@joshtriplett.`

> Please do go ahead and add the ones whose only legitimate use for ignoring the return value is leaking memory. (In a separate PR please.) I think it's sufficiently error-prone to call something like alloc and ignore the result that it's legitimate to require `let _ =` for that.

I added `realloc` myself. Clippy ignored it because of its `mut` argument.

```rust
alloc/src/alloc.rs:123:1   alloc   unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8;
```

Parent issue: #89692

r? `@joshtriplett`
2021-10-31 09:20:27 +01:00
Matthias Krüger
d4bdcdb1ec
Rollup merge of #89951 - ojeda:stable-unwrap_unchecked, r=dtolnay
Stabilize `option_result_unwrap_unchecked`

Closes https://github.com/rust-lang/rust/issues/81383.

Stabilization report: https://github.com/rust-lang/rust/issues/81383#issuecomment-944498212.

```@rustbot``` label +A-option-result +T-libs-api
2021-10-31 09:20:27 +01:00
Matthias Krüger
95750ae439
Rollup merge of #89897 - jkugelman:must-use-core, r=joshtriplett
Add #[must_use] to remaining core functions

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `core` crate.

Ignored by clippy for reasons unknown:

```rust
core::alloc::Layout   unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self;
core::any             const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str;
```

Ignored by clippy because of `mut`:

```rust
str   fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
```

<del>
Ignored by clippy presumably because a caller might want `f` called for side effects. That seems like a bad usage of `map` to me.

```rust
core::cell::Ref<'b, T>   fn map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Ref<'b, T>;
core::cell::Ref<'b, T>   fn map_split<U: ?Sized, V: ?Sized, F>(orig: Ref<'b, T>, f: F) -> (Ref<'b, U>, Ref<'b, V>);
```
</del>

Parent issue: #89692

r? ```@joshtriplett```
2021-10-31 09:20:26 +01:00
Matthias Krüger
e79e9f5e2a
Rollup merge of #89839 - jkugelman:must-use-mem-ptr-functions, r=joshtriplett
Add #[must_use] to mem/ptr functions

There's a lot of low-level / unsafe stuff here. Are there legit use cases for ignoring any of these return values?

* No regressions in `./x.py test --stage 1 library/std src/tools/clippy`.
* One regression in `./x.py test --stage 1 src/test/ui`. Fixed.
* I am unable to run `./x.py doc` on my machine so I'll need to wait for the CI to verify doctests pass. I eyeballed all the adjacent tests and they all look okay.

Parent issue: #89692

r? ```@joshtriplett```
2021-10-31 09:20:25 +01:00
Matthias Krüger
a26b1d2259
Rollup merge of #89835 - jkugelman:must-use-expensive-computations, r=joshtriplett
Add #[must_use] to expensive computations

The unifying theme for this commit is weak, admittedly. I put together a list of "expensive" functions when I originally proposed this whole effort, but nobody's cared about that criterion. Still, it's a decent way to bite off a not-too-big chunk of work.

Given the grab bag nature of this commit, the messages I used vary quite a bit. I'm open to wording changes.

For some reason clippy flagged four `BTreeSet` methods but didn't say boo about equivalent ones on `HashSet`. I stared at them for a while but I can't figure out the difference so I added the `HashSet` ones in.

```rust
// Flagged by clippy.
alloc::collections::btree_set::BTreeSet<T>   fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T>;
alloc::collections::btree_set::BTreeSet<T>   fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>) -> SymmetricDifference<'a, T>
alloc::collections::btree_set::BTreeSet<T>   fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T>;
alloc::collections::btree_set::BTreeSet<T>   fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T>;

// Ignored by clippy, but not by me.
std::collections::HashSet<T, S>              fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S>;
std::collections::HashSet<T, S>              fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>) -> SymmetricDifference<'a, T, S>
std::collections::HashSet<T, S>              fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S>;
std::collections::HashSet<T, S>              fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S>;
```

Parent issue: #89692

r? ```@joshtriplett```
2021-10-31 09:20:24 +01:00
Matthias Krüger
3cf3910c15
Rollup merge of #89833 - jkugelman:must-use-rc-downgrade, r=joshtriplett
Add #[must_use] to Rc::downgrade

Missed this in previous PR https://github.com/rust-lang/rust/pull/89796#issuecomment-941456006

Parent issue: #89692

r? ```@joshtriplett```
2021-10-31 09:20:23 +01:00
Matthias Krüger
15a0cddff3
Rollup merge of #89677 - maxwase:is-symlink-stabilization, r=joshtriplett
Stabilize `is_symlink()` for `Metadata` and `Path`

I'm not fully sure about `since` version, correct me if I'm wrong

Needs update after stabilization: [cargo-test-support](8063672238/crates/cargo-test-support/src/paths.rs (L202))

Linked issue: #85748
2021-10-31 09:20:22 +01:00
Matthias Krüger
e7be8a2c07
Rollup merge of #89446 - chrismit3s:issue-88715-fix, r=joshtriplett
Add paragraph to ControlFlow docs to menion it works with the ? operator (#88715)

fixes #88715

r? ```@steveklabnik```
2021-10-31 09:20:21 +01:00
John Kugelman
e129d49f88 Add #[must_use] to remaining std functions (A-N) 2021-10-30 23:44:02 -04:00
John Kugelman
a81d4b18ea Add #[must_use] to remaining std functions (O-Z) 2021-10-30 23:37:32 -04:00
John Kugelman
42e0282d52 Add #[must_use] to alloc functions that would leak memory 2021-10-30 22:19:07 -04:00
bors
0a09858b05 Auto merge of #90306 - kornelski:slicecloneasset, r=joshtriplett
track_caller for slice length assertions

`clone_from_slice` was missing `#[track_caller]`, and its assert did not report a useful location.

These are small generic methods, so hopefully track_caller gets inlined into nothingness, but it may be worth running a benchmark on this.
2021-10-31 01:56:40 +00:00
Josh Triplett
7c9611d124 Make std:🧵:available_concurrency support process-limited number of CPUs
Use libc::sched_getaffinity and count the number of CPUs in the returned
mask. This handles cases where the process doesn't have access to all
CPUs, such as when limited via taskset or similar.
2021-10-31 01:38:14 +02:00
Josh Triplett
23be29aace Update libc to 0.2.106 to get definitions for CPU_* 2021-10-31 01:38:05 +02:00
John Kugelman
6745e8da06 Add #[must_use] to len and is_empty 2021-10-30 19:25:12 -04:00
John Kugelman
887503ad14 Add #[must_use] to mem/ptr functions 2021-10-30 18:54:48 -04:00
Matthias Krüger
0da75bcc9c
Rollup merge of #90401 - mkroening:hermit-condvar, r=joshtriplett
hermit: Implement Condvar::wait_timeout

This implements `Condvar::wait_timeout` for the `hermit` target.

See
* https://github.com/hermitcore/rust/pull/2
* https://github.com/hermitcore/rust/pull/5

CC: `@stlankes`
2021-10-31 00:33:25 +02:00
Matthias Krüger
1adb664392
Rollup merge of #89899 - jkugelman:must-use-alloc, r=joshtriplett
Add #[must_use] to remaining alloc functions

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `alloc` crate.

I ignored these because they might be used to purposefully leak memory... or other allocator shenanigans? I dunno. I'll add them if y'all tell me to.

```rust
alloc::alloc          unsafe fn alloc(layout: Layout) -> *mut u8;
alloc::alloc          unsafe fn alloc_zeroed(layout: Layout) -> *mut u8;
alloc::sync::Arc<T>   fn into_raw(this: Self) -> *const T;
```

I don't know why clippy ignored these. I added them myself:

```rust
alloc::collections::btree_map::BTreeMap<K, V>   fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>;
alloc::collections::btree_set::BTreeSet<T>      fn range<K: ?Sized, R>(&self, range: R) -> Range<'_, T>;
```

I added these non-mutating `mut` functions:

```rust
alloc::collections::btree_map::BTreeMap<K, V>     fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>;
alloc::collections::btree_map::BTreeMap<K, V>     fn iter_mut(&mut self) -> IterMut<'_, K, V>;
alloc::collections::btree_map::BTreeMap<K, V>     fn values_mut(&mut self) -> ValuesMut<'_, K, V>;
alloc::collections::linked_list::LinkedList<T>    fn iter_mut(&mut self) -> IterMut<'_, T>;
alloc::collections::linked_list::LinkedList<T>    fn cursor_front_mut(&mut self) -> CursorMut<'_, T>;
alloc::collections::linked_list::LinkedList<T>    fn cursor_back_mut(&mut self) -> CursorMut<'_, T>;
alloc::collections::linked_list::LinkedList<T>    fn front_mut(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::LinkedList<T>    fn back_mut(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn current(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn peek_next(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn peek_prev(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn front_mut(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn back_mut(&mut self) -> Option<&mut T>;
```

I moved a few existing `#[must_use]`s from functions onto the iterator types they return: `IntoIterSorted`, `IntoKeys`, `IntoValues`.

Parent issue: #89692

r? `@joshtriplett`
2021-10-31 00:33:24 +02:00