Commit Graph

9118 Commits

Author SHA1 Message Date
Nick Cameron
9372c4f6ac error::Error: remove some comments
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-25 07:42:07 +01:00
Deadbeef
69ad634808 Do not include const_ptr_sub_ptr in this stabilization 2022-08-25 06:03:28 +00:00
Deadbeef
ad93272627 Stabilize const_ptr_offset_from.
Stabilization has been completed [here](https://github.com/rust-lang/rust/issues/92980#issuecomment-1065644848)
with a FCP.
2022-08-25 06:03:28 +00:00
Yuki Okushi
df354f5cf6
Rollup merge of #100921 - ChayimFriedman2:and-eager-eval, r=JohnTitor
Add a warning about `Option/Result::and()` being eagerly evaluated

Copied from `or()`.

Inspired by [this StackOverflow question](https://stackoverflow.com/questions/73461846/why-is-in-rust-the-expression-in-option-and-evaluated-if-option-is-none).

[The PR for `or()`](https://github.com/rust-lang/rust/pull/46548) mentions the Clippy lint `or_fun_call` which doesn't exist for `and()` (although there is `unnecessary_lazy_evaluations`). I still think this warning is also good for `and()`. Feel free to close if you disagree.
2022-08-25 08:50:59 +09:00
Yuki Okushi
f4550a6edf
Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov
Stabilize `#![feature(label_break_value)]`

See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313.
2022-08-25 08:50:54 +09:00
Josh Triplett
ae937cc347 Clarify comment to fit as _ better 2022-08-25 00:22:40 +02:00
Matthias Krüger
fe1f1f1282
Rollup merge of #100922 - GuillaumeGomez:rewrite-error-index, r=notriddle
Rewrite error index generator to greatly reduce the size of the pages

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

Instead of having all error codes in a same page (making the DOM way too big), I split the output into multiple files and generated a list of links (if there is an explanation) to the error codes' explanation into the already existing file.

I also used this opportunity to greatly simplify the code. Instead of needing a `build.rs`, I simply imported the file we want and wrote the macro which generates a function containing everything we need. We just need to call it to get the error codes and their explanation (if any). Also, considering the implementations between markdown and HTML formats differed even further, the `Formatter` trait was becoming too problematic so I removed it too.

You can test it [here](https://rustdoc.crud.net/imperio/rewrite-error-index/error-index.html).

cc ``@jsha``
r? ``@notriddle``
2022-08-24 18:20:16 +02:00
Matthias Krüger
e802df9e8b
Rollup merge of #100855 - IsaacCloos:master, r=joshtriplett
Extra documentation for new formatting feature

Documentation of this feature was added in #90473 and released in Rust 1.58. However, high traffic macros did not receive new examples. Namely `println!()` and `format!()`.

The doc comments included in Rust are super important to the community- especially newcomers. I have met several other newbies like myself who are unaware of this recent (well about 7 months old now) update to the language allowing for convenient intra-string identifiers.

Bringing small examples of this feature to the doc comments of `println!()` and `format!()` would be helpful to everyone learning the language.

[Blog Post Announcing Feature](https://blog.rust-lang.org/2022/01/13/Rust-1.58.0.html)
[Feature PR](https://github.com/rust-lang/rust/pull/90473) - includes several instances of documentation of the feature- minus the macros in question for this PR

*This is my first time contributing to a project this large. Feedback would mean the world to me 😄*

---

*Recreated; I violated the [No-Merge Policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy)*
2022-08-24 18:20:10 +02:00
Matthias Krüger
6deca5f067
Rollup merge of #100220 - scottmcm:fix-by-ref-sized, r=joshtriplett
Properly forward `ByRefSized::fold` to the inner iterator

cc ``@timvermeulen,`` who noticed this mistake in https://github.com/rust-lang/rust/pull/100214#issuecomment-1207317625
2022-08-24 18:20:08 +02:00
Nick Cameron
b556a5be5a error::Error: rename the Demand arguments from req to demand
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-24 15:35:51 +01:00
Nick Cameron
80442f375a error::Error: rename the chain method to sources
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-24 15:35:51 +01:00
Josh Triplett
589db1f73a Expand example to show how to implement qualified trait names 2022-08-24 15:38:21 +02:00
Josh Triplett
3c8618fd82 Update write! docs: can now import traits as _ to avoid conflicts 2022-08-24 14:42:25 +02:00
Josh Triplett
a7886506ad Remove some documentation duplicated between writeln! and write!
`writeln!` already includes a reference to `write!` for more
information, so remove duplicated information.
2022-08-24 14:41:22 +02:00
Joshua Nelson
31e39446ec Stabilize #![feature(label_break_value)]
# Stabilization proposal

The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.

There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630

Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006

Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249

nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs,
and the design space seems rather speculative.

joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804

withoutboats has regrettably left the language team.

joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353

[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+

 ## Report

+ Feature gate:
    - d695a497bb/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
    - 6b2d3d5f3c/compiler/rustc_parse/src/parser/diagnostics.rs (L2629)
    - f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L749)
    - f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L1001)
    - 111df9e6ed/compiler/rustc_passes/src/loops.rs (L254)
    - d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L2079)
    - d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L1569)
+ Tests:
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs

 ## Interactions with other features

Labels follow the hygiene of local variables.

label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
    'foo: {
        Err(())?;
        break 'foo;
    }
};
```

label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
    || break 'a
    //~^ ERROR use of unreachable label `'a`
    //~| ERROR `break` inside of a closure
}
```

label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
    match false 'b: { //~ ERROR block label not supported here
        _ => {}
    }
}

macro_rules! m {
    ($b:block) => {
        'lab: $b; //~ ERROR cannot use a `block` macro fragment here
        unsafe $b; //~ ERROR cannot use a `block` macro fragment here
        |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
    }
}

fn foo() {
    m!({});
}
```

[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23 21:14:12 -05:00
bors
25ea5a36c6 Auto merge of #96869 - sunfishcode:main, r=joshtriplett
Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8.

Add a `is_known_utf8` flag to `Wtf8Buf`, which tracks whether the
string is known to contain UTF-8. This is efficiently computed in many
common situations, such as when a `Wtf8Buf` is constructed from a `String`
or `&str`, or with `Wtf8Buf::from_wide` which is already doing UTF-16
decoding and already checking for surrogates.

This makes `OsString::into_string` O(1) rather than O(N) on Windows in
common cases.

And, it eliminates the need to scan through the string for surrogates in
`Args::next` and `Vars::next`, because the strings are already being
translated with `Wtf8Buf::from_wide`.

Many things on Windows construct `OsString`s with `Wtf8Buf::from_wide`,
such as `DirEntry::file_name` and `fs::read_link`, so with this patch,
users of those functions can subsequently call `.into_string()` without
paying for an extra scan through the string for surrogates.

r? `@ghost`
2022-08-24 01:17:52 +00:00
Benoît du Garreau
3aa6fe376d Remove a packing branch from fmt::builders::PadAdapter 2022-08-24 01:21:40 +02:00
Benoît du Garreau
289d7cca1d Reduce code size of assert_matches_failed 2022-08-24 00:56:04 +02:00
bors
060e47f74a Auto merge of #99917 - yaahc:error-in-core-move, r=thomcc
Move Error trait into core

This PR moves the error trait from the standard library into a new unstable `error` module within the core library. The goal of this PR is to help unify error reporting across the std and no_std ecosystems, as well as open the door to integrating the error trait into the panic reporting system when reporting panics whose source is an errors (such as via `expect`).

This PR is a rewrite of https://github.com/rust-lang/rust/pull/90328 using new compiler features that have been added to support error in core.
2022-08-23 19:48:55 +00:00
Guillaume Gomez
4398d9229a Fix links to error codes 2022-08-23 21:47:31 +02:00
Chayim Refael Friedman
eb2fdd917e Add a warning about Option/Result::and() being eagerly evaluated
Copied from `or()`.
2022-08-23 16:15:09 +00:00
Maybe Waffle
53565b23ac Make use of [wrapping_]byte_{add,sub}
...replacing `.cast().wrapping_offset().cast()` & similar code.
2022-08-23 19:32:37 +04:00
Dylan DPC
a163659b1b
Rollup merge of #100835 - devnexen:listener_followups, r=devnexen
net listen backlog update, follow-up from #97963.

FreeBSD and using system limit instead for others.
2022-08-23 20:40:05 +05:30
Jake Goulding
260ec93478 Add Provider::{would_be_satisfied_by_value_of,would_be_satisfied_by_ref_of}
While the `provide_*` methods already short-circuit when a value has
been provided, there are times where an expensive computation is
needed to determine if the `provide_*` method can even be called.
2022-08-23 10:48:59 -04:00
Tomasz Miąsko
5f4d23dd14 Remove aliases for old atomic intrinsics names 2022-08-23 16:24:59 +02:00
Tomasz Miąsko
f5db0c7110 Use renamed atomic intrinsics in panic_unwind 2022-08-23 16:24:59 +02:00
Tomasz Miąsko
3bc5e322cf Update stdarch submodule 2022-08-23 16:24:59 +02:00
Jake Goulding
38de102cff Support eager and lazy methods for providing references and values
There are times where computing a value may be cheap, or where
computing a reference may be expensive, so this fills out the
possibilities.
2022-08-23 09:58:50 -04:00
Amanieu d'Antras
a54ddd494f Update comment about personalities in panic_abort 2022-08-23 16:12:58 +08:00
Amanieu d'Antras
c110329f25 Remove custom frame info registration on i686-pc-windows-gnu
The indirection is no longer needed since we always link to libgcc
even when the panic_abort runtime is used. Instead we can just call
the libgcc functions directly.
2022-08-23 16:12:58 +08:00
Amanieu d'Antras
5ff0876694 Move personality functions to std
These were previously in the panic_unwind crate with dummy stubs in the
panic_abort crate. However it turns out that this is insufficient: we
still need a proper personality function even with -C panic=abort to
handle the following cases:

1) `extern "C-unwind"` still needs to catch foreign exceptions with -C
panic=abort to turn them into aborts. This requires landing pads and a
personality function.

2) ARM EHABI uses the personality function when creating backtraces.
The dummy personality function in panic_abort was causing backtrace
generation to get stuck in a loop since the personality function is
responsible for advancing the unwind state to the next frame.
2022-08-23 16:12:58 +08:00
bors
1cff564203 Auto merge of #100782 - thomcc:fix-android-sigaddset, r=Mark-Simulacrum
Align android `sigaddset` impl with the reference impl from Bionic

In https://github.com/rust-lang/rust/pull/100737 I noticed we were treating the sigset_t as an array of bytes, while referencing code from android (ad8dcd6023/libc/include/android/legacy_signal_inlines.h) which treats it as an array of unsigned long.

That said, the behavior difference is so subtle here that it's not hard to see why nobody noticed. This fixes the implementation to be equivalent to the one in bionic.
2022-08-23 08:09:19 +00:00
Amanieu d'Antras
db94dbc597 Fix comment on the SEH personality function 2022-08-23 11:14:40 +08:00
Thiago Trannin
3d2b61c1af Remove out-of-context comment in mem::MaybeUninit documentation 2022-08-22 20:03:53 -03:00
Dan Gohman
2efe6b0d3d Add AsFd implementations for stdio types on WASI.
This mirrors the implementations on Unix platforms, and also mirrors the
existing `AsRawFd` impls.
2022-08-22 15:46:41 -07:00
Jane Losare-Lusby
bf7611d55e Move error trait into core 2022-08-22 13:28:25 -07:00
Jack Wrenn
f46fffc276 safe transmute: use Assume struct to provide analysis options
This was left as a TODO in #92268, and brings the trait more in
line with what was defined in MCP411.

`Assume::visibility` has been renamed to `Assume::safety`, as
library safety is what's actually being assumed; visibility is
just the mechanism by which it is currently checked (this may
change).

ref: https://github.com/rust-lang/compiler-team/issues/411
ref: https://github.com/rust-lang/rust/issues/99571
2022-08-22 18:37:54 +00:00
Mohsen Zohrevandi
85b3df2630 Export Cancel from std::os::fortanix_sgx::usercalls::raw
This was missed in https://github.com/rust-lang/rust/pull/100642
2022-08-22 08:54:50 -07:00
David CARLIER
15c8e55601 net listen backlog update, follow-up from #97963.
FreeBSD and using system limit instead for others.
2022-08-22 16:27:37 +01:00
Dylan DPC
4ed8fa4759
Rollup merge of #100872 - JanBeh:PR_vec_default_alloc_doc, r=fee1-dead
Add guarantee that Vec::default() does not alloc

Currently `Vec::new()` is guaranteed to not allocate until elements are pushed onto the `Vec`, but such a guarantee is missing for `Vec`'s implementation of `Default::default`.

This adds such a guarantee for `Vec::default()` to the API reference.

See also [this discussion on URLO](https://users.rust-lang.org/t/guarantee-that-vec-default-does-not-allocate/79903).
2022-08-22 20:34:16 +05:30
Dylan DPC
58d23737a6
Rollup merge of #100820 - WaffleLapkin:use_ptr_is_aligned_methods, r=scottmcm
Use pointer `is_aligned*` methods

This PR replaces some manual alignment checks with calls to `pointer::{is_aligned, is_aligned_to}` and removes a useless pointer cast.

r? `@scottmcm`

_split off from #100746_
2022-08-22 20:34:15 +05:30
Dylan DPC
382ba73062
Rollup merge of #100331 - lo48576:try-reserve-preserve-on-failure, r=thomcc
Guarantee `try_reserve` preserves the contents on error

Update doc comments to make the guarantee explicit. However, some
implementations does not have the statement though.

* `HashMap`, `HashSet`: require guarantees on hashbrown side.
* `PathBuf`: simply redirecting to `OsString`.

Fixes #99606.
2022-08-22 20:34:12 +05:30
Dylan DPC
c1a5ec7faf
Rollup merge of #99957 - chotchki:ip-globally-reachable_rebase, r=Mark-Simulacrum
Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase

Rebasing of pull request #86634 off of master to try and get the feature "ip" stabilized.

I also found a test failure in the rebase that is_global was considering the benchmark space to be globally reachable.

This is related to my other rebasing pull request #99947
2022-08-22 20:34:10 +05:30
Ralf Jung
d13699d0be update and extend some comments, and cfg-out some unused code 2022-08-22 09:14:33 -04:00
Ralf Jung
138375a74c std: use realstd fast key when building tests 2022-08-22 09:14:33 -04:00
Jan Behrens
0227b71865 Add guarantee that Vec::default() does not alloc
Currently `Vec::new()` is guaranteed to not allocate until elements are
pushed onto the `Vec`, but such a guarantee is missing for `Vec`'s
implementation of `Default::default`. This adds such a guarantee for
`Vec::default()` to the API reference.
2022-08-22 12:36:44 +02:00
Dylan DPC
33b5ce6433
Rollup merge of #99386 - AngelicosPhosphoros:add_retain_test_maybeuninit, r=JohnTitor
Add tests that check `Vec::retain` predicate execution order.

This behaviour is documented for `Vec::retain` which means that there is code that rely on that but there weren't tests about that.
2022-08-22 11:45:41 +05:30
Dylan DPC
a4950ef7eb
Rollup merge of #93162 - camsteffen:std-prim-docs, r=Mark-Simulacrum
Std module docs improvements

My primary goal is to create a cleaner separation between primitive types and primitive type helper modules (fixes #92777). I also changed a few header lines in other top-level std modules (seen at https://doc.rust-lang.org/std/) for consistency.

Some conventions used/established:

 * "The \`Box\<T>` type for heap allocation." - if a module mainly provides a single type, name it and summarize its purpose in the module header
 * "Utilities for the _ primitive type." - this wording is used for the header of helper modules
 * Documentation for primitive types themselves are removed from helper modules
 * provided-by-core functionality of primitive types is documented in the primitive type instead of the helper module (such as the "Iteration" section in the slice docs)

I wonder if some content in `std::ptr` should be in `pointer` but I did not address this.
2022-08-22 11:45:40 +05:30
Isaac Cloos
acca4b8f86 Extra documentation for new formatting feature
High traffic macros should detail this helpful addition.
2022-08-21 15:28:27 -04:00
Matthias Krüger
5e761f3f03
Rollup merge of #100839 - nelsonjchen:consistent_child_stdin_field_desc, r=thomcc
Make doc for stdin field of process consistent

The other fields use this format and example.
2022-08-21 16:54:08 +02:00
Matthias Krüger
a45f69f27d
Rollup merge of #100822 - WaffleLapkin:no_offset_question_mark, r=scottmcm
Replace most uses of `pointer::offset` with `add` and `sub`

As PR title says, it replaces `pointer::offset` in compiler and standard library with `pointer::add` and `pointer::sub`. This generally makes code cleaner, easier to grasp and removes (or, well, hides) integer casts.

This is generally trivially correct, `.offset(-constant)` is just `.sub(constant)`, `.offset(usized as isize)` is just `.add(usized)`, etc. However in some cases we need to be careful with signs of things.

r? ````@scottmcm````

_split off from #100746_
2022-08-21 16:54:07 +02:00
Matthias Krüger
fd403f5d17
Rollup merge of #100821 - WaffleLapkin:ptr_add_docs, r=scottmcm
Make some docs nicer wrt pointer offsets

This PR replaces `pointer::offset` with `pointer::add` and similarly `.cast().wrapping_add().cast()` with `.wrapping_byte_add()` **in docs**.

r? ``````@scottmcm``````

_split off from #100746_
2022-08-21 16:54:06 +02:00
Matthias Krüger
1cdcf508bb
Rollup merge of #100663 - clarfonthey:const-reverse, r=scottmcm
Make slice::reverse const

I remember this not being doable for some reason before, but decided to try it again and everything worked out in the tests.
2022-08-21 16:54:01 +02:00
Matthias Krüger
a5c16a5381
Rollup merge of #100556 - Alex-Velez:patch-1, r=scottmcm
Clamp Function for f32 and f64

I thought the clamp function could use a little improvement for readability purposes. The function now returns early in order to skip the extra bound checks.

If there was a reason for binding `self` to `x` or if this code is incorrect, please correct me :)
2022-08-21 16:54:01 +02:00
Maybe Waffle
efef211876 Make use of pointer::is_aligned[_to] 2022-08-21 15:46:03 +04:00
Nelson Chen
7abbfa8c41 Make doc for stdin field of process consistent
The other fields use this format and example.
2022-08-21 01:56:26 -07:00
Thom Chiovoloni
4ecf87619c
Fix redundant comparison 2022-08-21 01:08:33 -07:00
Maybe Waffle
b2625e24b9 fix nitpicks from review 2022-08-21 06:36:11 +04:00
Maybe Waffle
168a837975 fill in tracking issue for feature(ptr_mask) 2022-08-21 05:27:14 +04:00
Maybe Waffle
10270f4b44 Add pointer masking convenience functions
This commit adds the following functions all of which have a signature
`pointer, usize -> pointer`:
- `<*mut T>::mask`
- `<*const T>::mask`
- `intrinsics::ptr_mask`

These functions are equivalent to `.map_addr(|a| a & mask)` but they
utilize `llvm.ptrmask` llvm intrinsic.

*masks your pointers*
2022-08-21 05:27:14 +04:00
Maybe Waffle
3ba393465f Make some docs nicer wrt pointer offsets 2022-08-21 02:22:20 +04:00
Maybe Waffle
e4720e1cf2 Replace most uses of pointer::offset with add and sub 2022-08-21 02:21:41 +04:00
Cameron Steffen
17ddcb434b Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
Maybe Waffle
ed084ba292 Remove useless pointer cast 2022-08-21 01:32:40 +04:00
bors
878aef79dc Auto merge of #100810 - matthiaskrgr:rollup-xep778s, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #97963 (net listen backlog set to negative on Linux.)
 - #99935 (Reenable disabled early syntax gates as future-incompatibility lints)
 - #100129 (add miri-test-libstd support to libstd)
 - #100500 (Ban references to `Self` in trait object substs for projection predicates too.)
 - #100636 (Revert "Revert "Allow dynamic linking for iOS/tvOS targets."")
 - #100718 ([rustdoc] Fix item info display)
 - #100769 (Suggest adding a reference to a trait assoc item)
 - #100777 (elaborate how revisions work with FileCheck stuff in src/test/codegen)
 - #100796 (Refactor: remove unnecessary string searchings)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-20 20:08:26 +00:00
Matthias Krüger
e93edf3335
Rollup merge of #100129 - RalfJung:miri-test-libstd, r=thomcc
add miri-test-libstd support to libstd

- The first commit mirrors what we already have in liballoc.
- The second commit adds some regression tests that only really make sense to be run in Miri, since they rely on Miri's extra checks to detect anything.
- The third commit makes the MPSC tests work in reasonable time in Miri by reducing iteration counts.
- The fourth commit silences some warnings due to code being disabled with `cfg(miri)`
2022-08-20 19:45:11 +02:00
Matthias Krüger
d9789b6903
Rollup merge of #97963 - devnexen:net_listener_neg, r=the8472
net listen backlog set to negative on Linux.

it will be 4076 (from 5.4) or 128.
2022-08-20 19:45:09 +02:00
Matthias Krüger
77db317eed
Rollup merge of #100710 - ChrisDenton:load-library, r=thomcc
Windows: Load synch functions together

Attempt to load all the required sync functions and fail if any one of them fails.

This fixes a FIXME by going back to optional loading of `WakeByAddressSingle`.

Also reintroduces a macro for optional loading of functions but keeps it separate from the fallback macro rather than having that do two different jobs.

r? `@thomcc`
2022-08-20 19:32:13 +02:00
Matthias Krüger
c4fa35bb41
Rollup merge of #100642 - mzohreva:mz/update-sgx-abi-cancel-queue, r=Mark-Simulacrum
Update fortanix-sgx-abi and export some useful SGX usercall traits

Update `fortanix-sgx-abi` to 0.5.0 to add support for cancel queue (see https://github.com/fortanix/rust-sgx/pull/405 and https://github.com/fortanix/rust-sgx/pull/404).

Export some useful traits for processing SGX usercall. This is needed for https://github.com/fortanix/rust-sgx/pull/404 to avoid duplication.

cc `@raoulstrackx` and `@jethrogb`
2022-08-20 19:32:10 +02:00
Matthias Krüger
bd4a63cda2
Rollup merge of #100585 - wooorm:patch-1, r=Mark-Simulacrum
Fix trailing space showing up in example

The current text is rendered as: U+005B ..= U+0060 ``[ \ ] ^ _ ` ``, or (**note the final space!**)
This patch changes that to render as: U+005B ..= U+0060 `` [ \ ] ^ _ ` ``, or (**note no final space!**)

The reason for that, is that CommonMark has a solution for starting or ending inline code with a backtick/grave accent: padding both sides with a space, makes that padding disappear.
2022-08-20 19:32:08 +02:00
Matthias Krüger
d49906519b
Rollup merge of #99544 - dylni:expose-utf8lossy, r=Mark-Simulacrum
Expose `Utf8Lossy` as `Utf8Chunks`

This PR changes the feature for `Utf8Lossy` from `str_internals` to `utf8_lossy` and improves the API. This is done to eventually expose the API as stable.

Proposal: rust-lang/libs-team#54
Tracking Issue: #99543
2022-08-20 19:32:07 +02:00
dylni
e8ee0b7b2b Expose Utf8Lossy as Utf8Chunks 2022-08-20 12:49:20 -04:00
Matthias Krüger
1e47e8a9ee
Rollup merge of #100729 - thomcc:less-initialized, r=ChrisDenton
Avoid zeroing a 1kb stack buffer on every call to `std::sys::windows::fill_utf16_buf`

I've also tried to be slightly more careful about integer overflows, although in practice this is likely still not handled ideally.

r? `@ChrisDenton`
2022-08-20 07:09:04 +02:00
Matthias Krüger
368f08a65f
Rollup merge of #100383 - fortanix:raoul/aepic_leak_mitigation, r=cuviper
Mitigate stale data reads on SGX platform

Intel disclosed the Stale Data Read vulnerability yesterday. In order to mitigate this issue completely, reading userspace from an SGX enclave must be aligned and in 8-bytes chunks. This PR implements this mitigation

References:
 - https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00657.html
 - https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/stale-data-read-from-xapic.html

cc: ``@jethrogb``
2022-08-20 07:08:58 +02:00
Chris Denton
625e7e9579
Use const instead of static 2022-08-20 04:15:47 +01:00
Chris Denton
efd305e0ec
Simplify load/store 2022-08-20 04:15:46 +01:00
ltdk
ae2b1dbc89 Tracking issue for const_reverse 2022-08-19 20:38:32 -04:00
Thom Chiovoloni
f506656876
Align android sigaddset impl with the reference impl from Bionic 2022-08-19 16:02:48 -07:00
KaDiWa
a297631bdc
use <[u8]>::escape_ascii instead of core::ascii::escape_default 2022-08-19 19:00:37 +02:00
Thom Chiovoloni
d4cba61099
Fix comment typo 2022-08-19 08:45:21 -07:00
bors
6c943bad02 Auto merge of #99541 - timvermeulen:flatten_cleanup, r=the8472
Refactor iteration logic in the `Flatten` and `FlatMap` iterators

The `Flatten` and `FlatMap` iterators both delegate to `FlattenCompat`:
```rust
struct FlattenCompat<I, U> {
    iter: Fuse<I>,
    frontiter: Option<U>,
    backiter: Option<U>,
}
```
Every individual iterator method that `FlattenCompat` implements needs to carefully manage this state, checking whether the `frontiter` and `backiter` are present, and storing the current iterator appropriately if iteration is aborted. This has led to methods such as `next`, `advance_by`, and `try_fold` all having similar code for managing the iterator's state.

I have extracted this common logic of iterating the inner iterators with the option to exit early into a `iter_try_fold` method:
```rust
impl<I, U> FlattenCompat<I, U>
where
    I: Iterator<Item: IntoIterator<IntoIter = U>>,
{
    fn iter_try_fold<Acc, Fold, R>(&mut self, acc: Acc, fold: Fold) -> R
    where
        Fold: FnMut(Acc, &mut U) -> R,
        R: Try<Output = Acc>,
    { ... }
}
```
It passes each of the inner iterators to the given function as long as it keep succeeding. It takes care of managing `FlattenCompat`'s state, so that the actual `Iterator` methods don't need to. The resulting code that makes use of this abstraction is much more straightforward:
```rust
fn next(&mut self) -> Option<U::Item> {
    #[inline]
    fn next<U: Iterator>((): (), iter: &mut U) -> ControlFlow<U::Item> {
        match iter.next() {
            None => ControlFlow::CONTINUE,
            Some(x) => ControlFlow::Break(x),
        }
    }

    self.iter_try_fold((), next).break_value()
}
```
Note that despite being implemented in terms of `iter_try_fold`, `next` is still able to benefit from `U`'s `next` method. It therefore does not take the performance hit that implementing `next` directly in terms of `Self::try_fold` causes (in some benchmarks).

This PR also adds `iter_try_rfold` which captures the shared logic of `try_rfold` and `advance_back_by`, as well as `iter_fold` and `iter_rfold` for folding without early exits (used by `fold`, `rfold`, `count`, and `last`).

Benchmark results:
```
                                             before                after
bench_flat_map_sum                       423,255 ns/iter      414,338 ns/iter
bench_flat_map_ref_sum                 1,942,139 ns/iter    2,216,643 ns/iter
bench_flat_map_chain_sum               1,616,840 ns/iter    1,246,445 ns/iter
bench_flat_map_chain_ref_sum           4,348,110 ns/iter    3,574,775 ns/iter
bench_flat_map_chain_option_sum          780,037 ns/iter      780,679 ns/iter
bench_flat_map_chain_option_ref_sum    2,056,458 ns/iter      834,932 ns/iter
```

I added the last two benchmarks specifically to demonstrate an extreme case where `FlatMap::next` can benefit from custom internal iteration of the outer iterator, so take it with a grain of salt. We should probably do a perf run to see if the changes to `next` are worth it in practice.
2022-08-19 02:34:30 +00:00
Scott McMurray
8118a31e86 Inline <T as From<T>>::from
I noticed in the MIR for <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=67097e0494363ee27421a4e3bdfaf513> that it's inlined most stuff
```
scope 5 (inlined <Result<i32, u32> as Try>::branch)
```
```
scope 8 (inlined <Result<i32, u32> as Try>::from_output)
```

But yet the do-nothing `from` call was still there:
```
_17 = <u32 as From<u32>>::from(move _18) -> bb9;
```

So let's give this a try and see what perf has to say.
2022-08-18 16:04:00 -07:00
Ralf Jung
fbcdf2a383 clarify lib.rs attribute structure 2022-08-18 18:07:39 -04:00
Ralf Jung
438e49c1cb silence some unused-fn warnings in miri std builds 2022-08-18 18:07:39 -04:00
Ralf Jung
8c8dc125b1 make many std tests work in Miri 2022-08-18 18:07:39 -04:00
Ralf Jung
27b0444333 add some Miri-only tests 2022-08-18 18:07:39 -04:00
Ralf Jung
ac66baad1a add miri-test-libstd support to libstd 2022-08-18 18:07:39 -04:00
Thom Chiovoloni
f50f8782fe
Avoid zeroing a 1kb stack buffer on every call to std::sys::windows::fill_utf16_buf 2022-08-18 15:04:28 -07:00
bors
361c599fee Auto merge of #98655 - nnethercote:dont-derive-PartialEq-ne, r=dtolnay
Don't derive `PartialEq::ne`.

Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums
and empty structs, thus reyling on the default `ne`. This behaviour is
unnecessarily conservative, because the `PartialEq` docs say this:

> Implementations must ensure that eq and ne are consistent with each other:
>
> `a != b` if and only if `!(a == b)` (ensured by the default
> implementation).

This means that the default implementation (`!(a == b)`) is always good
enough. So this commit changes things such that `ne` is never derived.

The motivation for this change is that not deriving `ne` reduces compile
times and binary sizes.

Observable behaviour may change if a user has defined a type `A` with an
inconsistent `PartialEq` and then defines a type `B` that contains an
`A` and also derives `PartialEq`. Such code is already buggy and
preserving bug-for-bug compatibility isn't necessary.

Two side-effects of the change:
- There is only one error message produced for types where `PartialEq`
  cannot be derived, instead of two.
- For coverage reports, some warnings about generated `ne` methods not
  being executed have disappeared.

Both side-effects seem fine, and possibly preferable.
2022-08-18 10:11:11 +00:00
Nick Cameron
ac70aea985 Address reviewer comments
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-18 10:34:40 +01:00
Chris Denton
b631ca0c2f
Windows: Load synch functions together
Attempt to load all the required sync functions and fail if any one of them fails.

This reintroduces a macro for optional loading of functions but keeps it separate from the fallback macro rather than having that do two different jobs.
2022-08-18 07:39:14 +01:00
David Tolnay
83f081fc01
Remove unstable Result::into_ok_or_err 2022-08-17 17:20:42 -07:00
Matthias Krüger
1199dbdcf5
Rollup merge of #100661 - PunkyMunky64:patch-1, r=thomcc
Fixed a few documentation errors

Quick pull request; IEEE-754, not IEEE-745. May save someone a quick second some time.
2022-08-17 12:33:02 +02:00
Matthias Krüger
bd8aa6dffe
Rollup merge of #100660 - PunkyMunky64:patch-2, r=thomcc
Fixed a few documentation errors

Quick pull request; IEEE-754, not IEEE-745. May save someone a quick second some time.
2022-08-17 12:33:01 +02:00
Matthias Krüger
56b02b2137
Rollup merge of #100532 - RalfJung:unwind-miri, r=Mark-Simulacrum
unwind: don't build dependency when building for Miri

This is basically re-submitting https://github.com/rust-lang/rust/pull/94813.

In that PR there was a suggestion to instead have bootstrap set a `RUST_CHECK` env var and use that rather than doing something Miri-specific. However, such an env var would mean that when switching between `./x.py check` and `./x.py build`, the build script gets re-run each time, which doesn't seem good. So I think for now checking for Miri probably causes fewer problems.

r? ````@Mark-Simulacrum````
2022-08-17 12:32:53 +02:00
Raoul Strackx
2a23d08aae Mitigate Stale Data Read for xAPIC vulnerability
In order to mitigate the Stale Data Read for xAPIC vulnerability completely, reading userspace from an SGX enclave must be aligned and in 8-bytes chunks.

References:

 - https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00657.html
 - https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/stale-data-read-from-xapic.html
2022-08-17 09:51:03 +02:00
ltdk
5e1730fd17 Make slice::reverse const 2022-08-17 02:01:32 -04:00
PunkyMunky64
683b3f4e6e
Fixed a few documentation errors
Quick pull request; IEEE-754, not IEEE-745. May save someone a quick second some time.
2022-08-16 22:29:14 -07:00
PunkyMunky64
89d9a35b3e
Fixed a few documentation errors
IEEE-754, not IEEE-745. May save someone a second sometime
2022-08-16 22:28:11 -07:00
Alex
0ff8f0b578 Update src/test/assembly/x86_64-floating-point-clamp.rs
Simple Clamp Function

I thought this was more robust and easier to read. I also allowed this function to return early in order to skip the extra bound check (I'm sure the difference is negligible). I'm not sure if there was a reason for binding `self` to `x`; if so, please correct me.

Simple Clamp Function for f64

I thought this was more robust and easier to read. I also allowed this function to return early in order to skip the extra bound check (I'm sure the difference is negligible). I'm not sure if there was a reason for binding `self` to `x`; if so, please correct me.

Floating point clamp test

f32 clamp using mut self

f64 clamp using mut self

Update library/core/src/num/f32.rs

Update f64.rs

Update x86_64-floating-point-clamp.rs

Update src/test/assembly/x86_64-floating-point-clamp.rs

Update x86_64-floating-point-clamp.rs

Co-Authored-By: scottmcm <scottmcm@users.noreply.github.com>
2022-08-16 19:45:44 -04:00
Mohsen Zohrevandi
70dd980c8d Update fortanix-sgx-abi and export some useful SGX usercall traits
Update fortanix-sgx-abi to 0.5.0 to add support for cancel queue (see
https://github.com/fortanix/rust-sgx/pull/405 and
https://github.com/fortanix/rust-sgx/pull/404).

Export some useful traits for processing SGX usercall. This is needed
for https://github.com/fortanix/rust-sgx/pull/404 to avoid duplication.
2022-08-16 11:01:53 -07:00
Markus Reiter
44d62425b9
Simplify IpDisplayBuffer API. 2022-08-16 19:32:00 +02:00
Markus Reiter
31540f5e15
Use MaybeUninit<u8> for IpDisplayBuffer. 2022-08-16 18:12:06 +02:00
Markus Reiter
033e9d66ff
Move IpDisplayBuffer into submodule. 2022-08-16 17:57:46 +02:00
Markus Reiter
5a11b814d4
Add IpDisplayBuffer helper struct. 2022-08-16 17:54:55 +02:00
Raoul Strackx
25de53f768 Refactor copying data to userspace 2022-08-16 15:01:18 +02:00
Matthias Krüger
0b19a185db
Rollup merge of #100460 - cuviper:drop-llvm-12, r=nagisa
Update the minimum external LLVM to 13

With this change, we'll have stable support for LLVM 13 through 15 (pending release).
For reference, the previous increase to LLVM 12 was #90175.

r? `@nagisa`
2022-08-16 06:05:57 +02:00
bors
3694b7d307 Auto merge of #100007 - ChrisDenton:dtor-inline-never, r=michaelwoerister
Never inline Windows dtor access

Inlining can cause problem If used in a Rust dylib. See #44391.

r? `@Mark-Simulacrum`
2022-08-15 23:57:44 +00:00
Ralf Jung
63113c8b0c unwind: don't build dependency when building for Miri 2022-08-15 12:54:12 -04:00
Titus
8e80c39d2d
Fix trailing space showing up in example
The current text is rendered as: U+005B ..= U+0060 ``[ \ ] ^ _ ` ``, or.
This patch changes that to render as: U+005B ..= U+0060 `` [ \ ] ^ _ ` ``, or

The reason for that, is that CommonMark has a solution for starting or ending inline code with a backtick/grave accent: padding both sides with a space, makes that padding disappear.
2022-08-15 16:18:00 +02:00
Urgau
3f10e6c86d Say that the identity holds only for all finite numbers (aka not NaN) 2022-08-15 12:47:05 +02:00
Orson Peters
a1e251024d Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
Orson Peters
85d5171dea Float biteq macros can be unused if test is skipped. 2022-08-15 12:33:00 +02:00
Orson Peters
18d61bfbf4 Skip next_up/down tests entirely on x87. 2022-08-15 12:33:00 +02:00
Orson Peters
fbe215af53 Conditionally do not compile NaN roundtrip tests on x87 fp. 2022-08-15 12:33:00 +02:00
Orson Peters
712bf2a07a Added tracking issue numbers for float_next_up_down. 2022-08-15 12:33:00 +02:00
Orson Peters
de757e8a98 Ensure NaN references values go through function boundary for next_up/down. 2022-08-15 12:33:00 +02:00
Orson Peters
3241bbcbc7 Fixed float next_up/down 32-bit x87 float NaN roundtrip test case. 2022-08-15 12:33:00 +02:00
Orson Peters
04681898f0 Added next_up and next_down for f32/f64. 2022-08-15 12:32:53 +02:00
Scott McMurray
7680c8b690 Properly forward ByRefSized::fold to the inner iterator 2022-08-14 22:55:30 -07:00
bors
80ed61fbd6 Auto merge of #96350 - austinabell:skip_optimization, r=Mark-Simulacrum
fix(iter::skip): Optimize `next` and `nth` implementations of `Skip`

This avoids calling nth/next or nth/nth to first skip elements and then get the next one (unless necessary due to usize overflow).
2022-08-15 03:09:20 +00:00
Josh Stone
2970ad8aee Update the minimum external LLVM to 13 2022-08-14 13:46:51 -07:00
Matthias Krüger
b8b3ead67a
Rollup merge of #100249 - Meziu:master, r=joshtriplett
Fix HorizonOS regression in FileTimes

The changes in #98246 caused a regression for multiple Newlib-based systems. This is just a fix including HorizonOS to the list of  targets which require a workaround.

``@AzureMarker`` ``@ian-h-chamberlain``
r? ``@nagisa``
2022-08-14 20:16:00 +02:00
austinabell
00bc9e8ac4
fix(iter::skip): Optimize next and nth implementations of Skip 2022-08-14 13:25:13 -04:00
Dylan DPC
482a6eaf10
Rollup merge of #100026 - WaffleLapkin:array-chunks, r=scottmcm
Add `Iterator::array_chunks` (take N+1)

A revival of https://github.com/rust-lang/rust/pull/92393.

r? `@Mark-Simulacrum`
cc `@rossmacarthur` `@scottmcm` `@the8472`

I've tried to address most of the review comments on the previous attempt. The only thing I didn't address is `try_fold` implementation, I've left the "custom" one for now, not sure what exactly should it use.
2022-08-14 17:09:14 +05:30
Jakub Dąbek
8509936e8f
Add mention of BufReader in Read::bytes docs 2022-08-14 11:01:04 +02:00
Michael Goulet
f8bdd9c680
Rollup merge of #100501 - RalfJung:miri-from-exposed-addr, r=Mark-Simulacrum
nicer Miri backtraces for from_exposed_addr

Miri by default warns about using from_exposed_addr; this makes the span for that a bit nicer.
2022-08-13 14:10:14 -07:00
Michael Goulet
ea42f3cfd7
Rollup merge of #100407 - RalfJung:no-int2ptr, r=Mark-Simulacrum
avoid some int2ptr casts in thread_local_key tests
2022-08-13 14:10:05 -07:00
Ralf Jung
2dc9bf0fa0 nicer Miri backtraces for from_exposed_addr 2022-08-13 12:55:43 -04:00
Berend-Jan Lange
786e8755e7 created tcpstream quickack trait
for linux and android
2022-08-13 17:38:01 +02:00
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
Maybe Waffle
5fbcde1b55 fill-in tracking issue for feature(iter_array_chunks) 2022-08-12 15:04:29 +04:00
Maybe Waffle
eb6b729545 address review comments 2022-08-12 14:57:15 +04:00
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
b5786dcae6 avoid some int2ptr casts in thread_local_key tests 2022-08-11 09:39:25 -04:00
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
YOSHIOKA Takuma
2bb7e1e6ed
Guarantee try_reserve preserves the contents on error
Update doc comments to make the guarantee explicit. However, some
implementations does not have the statement though.

* `HashMap`, `HashSet`: require guarantees on hashbrown side.
* `PathBuf`: simply redirecting to `OsString`.

Fixes #99606.
2022-08-10 01:51:38 +09: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
BlackHoleFox
08c97323de Add standard C error function aliases
Aids the discoverability of `io::Error::last_os_error()` by linking to
commonly used error number functions from C/C++.
2022-08-08 17:56:21 -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
Michael Goulet
6b2eab2310 Add Tuple marker trait 2022-08-07 16:28:24 -07: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
Nika Layzell
1c7c792dda proc_macro/bridge: send diagnostics over the bridge as a struct
This removes some RPC when creating and emitting diagnostics, and
simplifies the bridge slightly.

After this change, there are no remaining methods which take advantage
of the support for `&mut` references to objects in the store as
arguments, meaning that support for them could technically be removed if
we wanted. The only remaining uses of immutable references into the
store are `TokenStream` and `SourceFile`.
2022-08-06 15:49:43 -04: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
Nick Cameron
1a2122fff0 non-linux platforms
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-05 17:18:51 +01: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
Tim Vermeulen
38bb0b173e Move rfold logic into iter_rfold 2022-08-05 03:43:39 +02:00
Tim Vermeulen
3f7004920c Move fold logic to iter_fold method and reuse it in count and last 2022-08-05 03:43:39 +02:00
Tim Vermeulen
cbc5f62782 Move shared logic of try_rfold and advance_back_by into iter_try_rfold 2022-08-05 03:43:39 +02:00
Tim Vermeulen
8ff8d05279 Move shared logic of try_fold and advance_by into iter_try_fold 2022-08-05 03:43:39 +02:00
Nick Cameron
b56cf67ce1 Add some docs for BorrowBuf
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-04 15:29:32 +01:00
Nick Cameron
c1aae4d279 std::io: migrate ReadBuf to BorrowBuf/BorrowCursor
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-04 15:29:32 +01: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
Kevin Reid
d4bcc4ae6d Remove self-referential intra-doc links. 2022-08-03 22:07:50 -07:00
Kevin Reid
1b87306b98 Document that RawWakerVTable functions must be thread-safe.
Also add some intra-doc links and more high-level explanation of how
`Waker` is used, while I'm here.

Context:
https://internals.rust-lang.org/t/thread-safety-of-rawwakervtables/17126
2022-08-03 19:14:31 -07: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
Trevor Spiteri
97c963d081 make slice::{split_at,split_at_unchecked} const functions 2022-08-02 22:22:16 +02: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
Nicholas Nethercote
d4a5b034b7 Don't derive PartialEq::ne.
Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums
and empty structs, thus reyling on the default `ne`. This behaviour is
unnecessarily conservative, because the `PartialEq` docs say this:

> Implementations must ensure that eq and ne are consistent with each other:
>
> `a != b` if and only if `!(a == b)` (ensured by the default
> implementation).

This means that the default implementation (`!(a == b)`) is always good
enough. So this commit changes things such that `ne` is never derived.

The motivation for this change is that not deriving `ne` reduces compile
times and binary sizes.

Observable behaviour may change if a user has defined a type `A` with an
inconsistent `PartialEq` and then defines a type `B` that contains an
`A` and also derives `PartialEq`. Such code is already buggy and
preserving bug-for-bug compatibility isn't necessary.

Two side-effects of the change:
- There is only one error message produced for types where `PartialEq`
  cannot be derived, instead of two.
- For coverage reports, some warnings about generated `ne` methods not
  being executed have disappeared.

Both side-effects seem fine, and possibly preferable.
2022-08-01 08:01:58 +10: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
Christopher Hotchkiss
f6590887df Original branch seems to have missed excluding the benchmark range from the globally reachable change 2022-07-30 13:05:33 -04:00
Christopher Hotchkiss
3365b0631d Reincorporated changes from #87689 2022-07-30 11:37:16 -04:00
Christiaan Dirkx
f2990648db Change Ipv4Addr::is_global to be in line with Ipv6Addr::is_global
Rebasing off master
2022-07-30 11:29:06 -04:00
Christiaan Dirkx
f7d8805a47 Fix Ipv6Addr::is_global to check for global reachability rather than global scope 2022-07-30 11:25:03 -04: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