Commit graph

1829 commits

Author SHA1 Message Date
Guillaume Gomez
f4d3f32f45
Rollup merge of #85826 - jsha:npo, r=joshtriplett
Mention "null pointer optimization" in option docs.

I had seen people discuss "null pointer optimization," but when I tried to find official documentation (using Google), the `std::option` page didn't show up, because it doesn't use that term. Hopefully adding the term will help others find it in the future.
2021-06-01 11:29:44 +02:00
est31
a0228d9b87 Intra doc link-ify a reference to a function 2021-06-01 05:04:48 +02:00
bors
bff138dbd9 Auto merge of #85754 - the8472:revert-83770, r=Mark-Simulacrum
Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"

Due to a performance regression that didn't show up in the original perf run
this reverts commit 9111b8ae97 (#83770), reversing
changes made to 9a700d2947.

Since since is expected to have the inverse impact it should probably be rollup=never.

r? `@Mark-Simulacrum`
2021-05-30 04:12:44 +00:00
bors
9a72afa7dd Auto merge of #83772 - jhpratt:revamp-step-trait, r=Mark-Simulacrum
Make `Step` trait safe to implement

This PR makes a few modifications to the `Step` trait that I believe better position it for stabilization in the short term. In particular,

1. `unsafe trait TrustedStep` is introduced, indicating that the implementation of `Step` for a given type upholds all stated invariants (which have remained unchanged). This is gated behind a new `trusted_step` feature, as stabilization is realistically blocked on min_specialization.
2. The `Step` trait is internally specialized on the `TrustedStep` trait, which avoids a serious performance regression.
3. `TrustedLen` is implemented for `T: TrustedStep` as the latter's invariants subsume the former's.
4. The `Step` trait is no longer `unsafe`, as the invariants must not be relied upon by unsafe code (unless the type implements `TrustedStep`).
5. `TrustedStep` is implemented for all types that implement `Step` in the standard library and compiler.
6. The `step_trait_ext` feature is merged into the `step_trait` feature. I was unable to find any reasoning for the features being split; the `_unchecked` methods need not necessarily be stabilized at the same time, but I think it is useful to have them under the same feature flag.

All existing implementations of `Step` will be broken, as it is not possible to `unsafe impl` a safe trait. Given this trait only exists on nightly, I feel this breakage is acceptable. The blanket `impl<T: Step> TrustedLen for T` will likely cause some minor breakage, but this should be covered by the equivalent impl for `TrustedStep`.

Hopefully these changes are sufficient to place `Step` in decent position for stabilization, which would allow user-defined types to be used with `a..b` syntax.
2021-05-30 01:21:39 +00:00
Jacob Hoffman-Andrews
79575a1a8e Mention "null pointer optimization" in option docs. 2021-05-29 09:57:12 -07:00
ltdk
2a40f2423a Add inherent unchecked_shl, unchecked_shr to integers 2021-05-28 22:54:39 -04:00
Guillaume Gomez
e30192ac5c
Rollup merge of #85730 - Smittyvb:iter-min-max-floats, r=m-ou-se
Mention workaround for floats in Iterator::{min, max}

`Iterator::{min, max}` can't be used with iterators of floats due to NaN issues. This suggests a workaround in the documentation of those functions.
2021-05-27 20:08:21 +02:00
Peter Todd
5b2076ff01
Revert #85176 addition of clone_from for ManuallyDrop
Forwarding `clone_from` to the inner value changes the observable
behavior, as previously the inner value would *not* be dropped by the
default implementation.
2021-05-27 14:01:16 -04:00
The8472
f72c60a39a Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"
Due to a performance regression that didn't show up in the original perf run
this reverts commit 9111b8ae97, reversing
changes made to 9a700d2947.
2021-05-27 18:17:09 +02:00
Ralf Jung
a7abd13092 make Ord doc style consistent with the other two; explain which properties are ensured by default impls 2021-05-27 12:01:49 +02:00
Dylan DPC
de1d7dbd0f
Rollup merge of #85689 - m-ou-se:array-intoiter-3, r=estebank
Remove Iterator #[rustc_on_unimplemented]s that no longer apply.

Now that `IntoIterator` is implemented for arrays, all the `rustc_on_unimplemented` for arrays of ranges (e.g. `for _ in [1..3] {}`) no longer apply, since they are now valid Rust.

Separated these from #85670, because we should discuss a potential new (clippy?) lint for these.

Until Rust 1.52, `for _ in [1..3] {}` produced:

```
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
 --> src/main.rs:2:14
  |
2 |     for _ in [1..3] {}
  |              ^^^^^^ if you meant to iterate between two values, remove the square brackets
  |
  = help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 1]`
  = note: `[start..end]` is an array of one `Range`; you might have meant to have a `Range` without the brackets: `start..end`
  = note: required by `std::iter::IntoIterator::into_iter`
```

But in Rust 1.53 and later, it compiles fine. It iterates over the array by value, for one iteration with the element `1..3`.

This is probably a mistake, which is no longer caught. Should we have a lint for it? Should Clippy have a lint for it?

cc ```@estebank``` ```@flip1995```

cc https://github.com/rust-lang/rust/issues/84513
2021-05-27 03:02:10 +02:00
Smittyvb
b00f6fc8a1
don't use unneeded closure
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
2021-05-26 20:38:50 -04:00
Smittyvb
7146a05a43
don't use unneeded closure
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
2021-05-26 20:38:43 -04:00
Jacob Pratt
35ce36812a
Unify feature flags as step_trait
While stdlib implementations of the unchecked methods require unchecked
math, there is no reason to gate it behind this for external users. The
reasoning for a separate `step_trait_ext` feature is unclear, and as
such has been merged as well.
2021-05-26 18:07:10 -04:00
Jacob Pratt
bc2f0fb5a9
Specialize implementations
Implementations in stdlib are now optimized as they were before.
2021-05-26 18:07:09 -04:00
Smitty
e7a3ada210 Mention float workaround in Iterator::{min,max} 2021-05-26 17:15:54 -04:00
bors
9111b8ae97 Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum
Add `TrustedRandomAccess` specialization for `Vec::extend()`

This should do roughly the same as the `TrustedLen` specialization but result in less IR by using `__iterator_get_unchecked`
instead of `Iterator::for_each`

Conflicting specializations are manually prioritized by grouping them under yet another helper trait.
2021-05-26 19:22:31 +00:00
Dylan DPC
9ee87c7e00
Rollup merge of #85712 - BlackHoleFox:fix-iter-typo, r=jyn514
Fix typo in core::array::IntoIter comment

Saw a small typo reading some internal comments and decided to just throw this up to fix it for future readers.
2021-05-26 13:32:12 +02:00
Dylan DPC
f3b10dd709
Rollup merge of #85679 - hch12907:master, r=Mark-Simulacrum
Remove num_as_ne_bytes feature

From the discussion in #76976, it is determined that eventual results of the safe transmute work as a more general mechanism will let these conversions happen in safe code without needing specialized methods.

Merging this PR closes #76976 and resolves #64464. Several T-libs members have raised their opinion that it doesn't pull its weight as a standalone method, and so we should not track it as a specific thing to add.
2021-05-26 13:32:11 +02:00
Dylan DPC
3c2a709620
Rollup merge of #85678 - lukas-code:matches2021, r=dtolnay
fix `matches!` and `assert_matches!` on edition 2021

Previously this code failed to compile on edition 2021. [(Playground)](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=53960f2f051f641777b9e458da747707)
```rust
fn main() {
    matches!((), ());
}
```
```
   Compiling playground v0.0.1 (/playground)
error: `$pattern:pat` may be followed by `|`, which is not allowed for `pat` fragments
    |
    = note: allowed there are: `=>`, `,`, `=`, `if` or `in`

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.
```
2021-05-26 13:32:10 +02:00
Dylan DPC
12ab323d0e
Rollup merge of #85670 - m-ou-se:array-intoiter-1, r=scottmcm
Remove arrays/IntoIterator message from Iterator trait.

Arrays implement IntoIterator since 1.53.

cc https://github.com/rust-lang/rust/issues/84513
2021-05-26 13:32:09 +02:00
BlackHoleFox
d1b69cf89b Fix typo in core::array::IntoIter comment 2021-05-26 02:37:39 -05:00
Yuki Okushi
587de8e5f9
Rollup merge of #85645 - scottmcm:demote-from-into-try, r=yaahc
Demote `ControlFlow::{from|into}_try` to `pub(crate)`

They have mediocre names and non-obvious semantics, so personally I don't think they're worth trying to stabilize, and thus might as well just be internal (they're used for convenience in iterator adapters), not something shown in the rustdocs.

I don't think anyone actually wanted to use them outside `core` -- they just got made public-but-unstable along with the whole type in https://github.com/rust-lang/rust/pull/76204 that promoted `LoopState` from an internal type to the exposed `ControlFlow` type.

cc https://github.com/rust-lang/rust/issues/75744, the tracking issue they mention.
cc https://github.com/rust-lang/rust/pull/85608, the PR where I'm proposing stabilizing the type.
2021-05-26 13:31:02 +09:00
Yuki Okushi
b7b9ce3df8
Rollup merge of #85610 - SkiFire13:fix-copy-within-provenance, r=oli-obk
Fix pointer provenance in <[T]>::copy_within

Previously the `self.as_mut_ptr()` invalidated the pointer created by the first `self.as_ptr()`. This also triggered miri when run with `-Zmiri-track-raw-pointers`
2021-05-26 13:31:00 +09:00
Jacob Pratt
a875876027
Make Range implementation safe 2021-05-26 00:12:06 -04:00
Jacob Pratt
641c8cd875
Limit TrustedLen impls to core types 2021-05-26 00:12:06 -04:00
Mara Bos
caf6faf951 Remove Iterator #[rustc_on_unimplemented]s that no longer apply. 2021-05-25 20:20:05 +02:00
Mara Bos
04a4a8225b Add new traits to 2021 prelude. 2021-05-25 19:58:50 +02:00
Mara Bos
e37ef7a842 Add tracking issue for edition-specific preludes. 2021-05-25 19:58:39 +02:00
Hoe Hao Cheng
0baf89810f Remove num_as_ne_bytes feature 2021-05-25 22:48:08 +08:00
Lukas Markeffsky
3ed90e2424 fix matches! and assert_matches! on edition 2021 2021-05-25 16:44:20 +02:00
Mara Bos
8d954fa589 Remove arrays/IntoIterator message from Iterator trait. 2021-05-25 15:48:14 +02:00
Guillaume Gomez
46615598a9
Rollup merge of #85644 - tialaramex:master, r=dtolnay
Better English for documenting when to use unimplemented!()

I don't think "plan of using" is correct here. I considered "plan on using" but eventually decided "plan to use" is better.
2021-05-25 13:05:15 +02:00
bors
a7890c7952 Auto merge of #84985 - pietroalbini:bootstrap-1.54, r=Mark-Simulacrum
Bump bootstrap compiler to beta 1.53.0

This PR bumps the bootstrap compiler to version 1.53.0 beta, as part of our usual release process (this was supposed to be Wednesday's step, but creating the beta release took longer than expected).

The PR also includes the "Bootstrap: skip rustdoc fingerprint for building docs" commit, see the reasoning [on Zulip](https://zulip-archive.rust-lang.org/241545trelease/88450153betabootstrap.html).

r? `@Mark-Simulacrum`
2021-05-25 05:48:00 +00:00
Scott McMurray
b63f7f9965 Demote ControlFlow::{from|into}_try to pub(crate) 2021-05-24 14:29:44 -07:00
Nick Lamb
54ccf95af2 Better English for documenting when to use unimplemented!() 2021-05-24 22:21:05 +01:00
Ralf Jung
1cfc1874b5 document PartialEq, PartialOrd, Ord requirements more explicitly 2021-05-24 18:18:32 +02:00
bors
ef0ec303fa Auto merge of #85596 - scottmcm:more-on-unimplemented, r=estebank
Extend `rustc_on_implemented` to improve more `?` error messages

`_Self` could match the generic definition; this adds that functionality for matching the generic definition of type parameters too.

Your advice welcome on the wording of all these messages, and which things belong in the message/label/note.

r? `@estebank`
2021-05-24 15:24:38 +00:00
Pietro Albini
9e22b844dd remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
bors
6f6919231e Auto merge of #85601 - klensy:padint-example-fix, r=dtolnay
fix pad_integral example

pad_integral's parameter `is_nonnegative - whether the original integer was either positive or zero`, but in example it checked as `self.nb > 0`, so it previously printed `-0` for `format!("{}", Foo::new(0)`, what is wrong.
2021-05-24 10:02:55 +00:00
Scott McMurray
65a0a8b386 Stabilize ops::ControlFlow (just the type) 2021-05-23 13:20:05 -07:00
Giacomo Stevanato
d7341f3c4b Don't reborrow self when computing the dest pointer in <[T]>::copy_within 2021-05-23 22:00:32 +02:00
bstrie
ed75d62fd5
Update std::array module doc header
Extremely outdated; not only are traits implemented on arrays of arbitrary length, those implementations are documented on the primitive type, not in this module.
2021-05-23 15:55:27 -04:00
Scott McMurray
8be67998a1 Extend rustc_on_implemented to improve a ?-on-ControlFlow error message 2021-05-23 07:18:02 -07:00
klensy
7c0db6f0f1 fix pad_integral example 2021-05-23 14:48:16 +03:00
bors
af2ed1b518 Auto merge of #85482 - scottmcm:more-try-bootstrap, r=yaahc
`#[cfg(bootstrap)]` out `NoneError` and other v1 try_trait stuff

Closes #46871

r? `@yaahc`
2021-05-21 13:46:04 +00:00
bors
35bab923c8 Auto merge of #85486 - RalfJung:rollup-4ibcxuu, r=RalfJung
Rollup of 8 pull requests

Successful merges:

 - #84717 (impl FromStr for proc_macro::Literal)
 - #85169 (Add method-toggle to <details> for methods)
 - #85287 (Expose `Concurrent` (private type in public i'face))
 - #85315 (adding time complexity for partition_in_place iter method)
 - #85439 (Add diagnostic item to `CStr`)
 - #85464 (Fix UB in documented example for `ptr::swap`)
 - #85470 (Fix invalid CSS rules for a:hover)
 - #85472 (CTFE Machine: do not expose Allocation)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-20 07:39:24 +00:00
bors
a426fc37f2 Auto merge of #85391 - Mark-Simulacrum:opt-tostring, r=scottmcm
Avoid zero-length memcpy in formatting

This has two separate and somewhat orthogonal commits. The first change adjusts the ToString general impl for all types that implement Display; it no longer uses the full format machinery, rather directly falling onto a `std::fmt::Display::fmt` call. The second change directly adjusts the general core::fmt::write function which handles the production of format_args! to avoid zero-length push_str calls.

Both changes target the fact that push_str will still call memmove internally (or a similar function), as it doesn't know the length of the passed string. For zero-length strings in particular, this is quite expensive, and even for very short (several bytes long) strings, this is also expensive. Future work in this area may wish to have us fallback to write_char or similar, which may be cheaper on the (typically) short strings between the interpolated pieces in format_args!.
2021-05-20 00:55:27 +00:00
Ralf Jung
2065c4b096
Rollup merge of #85464 - steffahn:fix_ub_in_ptr_swap_docs, r=dtolnay
Fix UB in documented example for `ptr::swap`

Compare [this (short) discussion on zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Pointers.20to.20overlapping.20arrays) (or [in the archive](https://zulip-archive.rust-lang.org/122651general/92017Pointerstooverlappingarrays.html), if you don’t have an account).

``@rustbot`` label T-doc T-libs
2021-05-20 00:19:08 +02:00
Ralf Jung
c1c4cd57b3
Rollup merge of #85315 - satylogin:master, r=yaahc
adding time complexity for partition_in_place iter method

I feel that one thing missing from rust docs compared to cpp references is existence of time complexity for all methods and functions. While it would be humongous task to include it for everything in single go, it is still doable if we as community keep on adding it in relevant places as and when we find them.

This PR adds the time complexity for partition_in_place method in iter.
2021-05-20 00:19:02 +02:00
bors
df70463ea5 Auto merge of #85340 - the8472:no-inplaceiterable-on-peekable, r=yaahc
remove InPlaceIterable marker from Peekable due to unsoundness

The unsoundness is not in Peekable per se, it rather is due to the
interaction between Peekable being able to hold an extra item
and vec::IntoIter's clone implementation shortening the allocation.

An alternative solution would be to change IntoIter's clone implementation
to keep enough spare capacity available.

fixes #85322
2021-05-19 21:50:45 +00:00
Scott McMurray
58a85d55e8 #[cfg(bootstrap)] out the v1 try_trait stuff 2021-05-19 13:32:15 -07:00
Frank Steffahn
f9752b4930 Fix UB in documented example for ptr::swap 2021-05-19 14:09:23 +02:00
bors
9f8012e3aa Auto merge of #85458 - jackh726:rollup-zvvybmt, r=jackh726
Rollup of 8 pull requests

Successful merges:

 - #83366 (Stabilize extended_key_value_attributes)
 - #83767 (Fix v0 symbol mangling bug)
 - #84883 (compiletest: "fix" FileCheck with --allow-unused-prefixes)
 - #85274 (Only pass --[no-]gc-sections if linker is GNU ld.)
 - #85297 (bootstrap: build cargo only if requested in tools)
 - #85396 (rustdoc: restore header sizes)
 - #85425 (Fix must_use on `Option::is_none`)
 - #85438 (Fix escape handling)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-19 04:44:09 +00:00
Jack Huey
e113a4f77b
Rollup merge of #85425 - mbartlett21:patch-1, r=scottmcm
Fix must_use on `Option::is_none`

This fixes the `#[must_use = ...]` on `Option::is_none` to have a working suggestion.
2021-05-18 22:36:18 -04:00
Jack Huey
3c99dcd82d
Rollup merge of #83366 - jyn514:stabilize-key-value-attrs, r=petrochenkov
Stabilize extended_key_value_attributes

Closes https://github.com/rust-lang/rust/issues/44732. Closes https://github.com/rust-lang/rust/issues/78835. Closes https://github.com/rust-lang/rust/issues/82768 (by making it irrelevant).

 # Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more and no less?")

This has been available on nightly since 1.50 with no major issues.

## Notes

### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized
(https://github.com/rust-lang/rust/pull/82539). The `forward_inner_docs`
workaround will still compile without warnings, but I expect it to be
used less once it's no longer necessary.
2021-05-18 22:35:54 -04:00
bors
3d31363338 Auto merge of #85176 - a1phyr:impl_clone_from, r=yaahc
Override `clone_from` for some types

Override `clone_from` method of the `Clone` trait for:
- `cell::RefCell`
- `cmp::Reverse`
- `io::Cursor`
- `mem::ManuallyDrop`

This can bring performance improvements.
2021-05-19 02:17:41 +00:00
The8472
60a900ee10 remove InPlaceIterable marker from Peekable due to unsoundness
The unsoundness is not in Peekable per se, it rather is due to the
interaction between Peekable being able to hold an extra item
and vec::IntoIter's clone implementation shortening the allocation.

An alternative solution would be to change IntoIter's clone implementation
to keep enough spare capacity available.
2021-05-19 01:41:09 +02:00
bors
4e3e6db011 Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr
Implement the new desugaring from `try_trait_v2`

~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix.

`try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277

Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them.  (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits.

r? `@ghost`

~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-18 20:50:01 +00:00
Guillaume Gomez
a181806b8c
Rollup merge of #85338 - lopopolo:core-iter-repeat-gh-81292, r=joshtriplett
Implement more Iterator methods on core::iter::Repeat

`core::iter::Repeat` always returns the same element, which means we can
do better than implementing most `Iterator` methods in terms of
`Iterator::next`.

Fixes #81292.

#81292 raises the question of whether these changes violate the contract of `core::iter::Repeat`, but as far as I can tell `core::iter::repeat` doesn't make any guarantees around how it calls `Clone::clone`.
2021-05-18 14:08:46 +02:00
Joshua Nelson
e48b6b4599 Stabilize extended_key_value_attributes
# Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See the changes to the reference for details on what macros are allowed;
see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more
and no less?")

This has been available on nightly since 1.50 with no major issues.

 ## Notes

 ### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

 ### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

 ## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

 ## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

 ## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized. The
`forward_inner_docs` workaround will still compile without warnings, but
I expect it to be used less once it's no longer necessary.
2021-05-18 01:01:36 -04:00
mbartlett21
18b0e7bf2c
Fix must_use on Option::is_none
This fixes the `#[must_use = ...]` on `Option::is_none` to have a working suggestion.
2021-05-18 13:40:26 +10:00
Satyarth Agrahari
85e4177184 adding algorithm explanation for partition_in_place iter method and bounding complexity to current implementation 2021-05-18 07:59:16 +05:30
Mark Rousskov
c7c9336469 Avoid zero-length write_str in fmt::write 2021-05-17 09:30:58 -04:00
Mark Rousskov
80ac15f667 Optimize default ToString impl
This avoids a zero-length write_str call, which boils down to a zero-length
memmove and ultimately costs quite a few instructions on some workloads.

This is approximately a 0.33% instruction count win on diesel-check.
2021-05-17 09:29:02 -04:00
VillSnow
5db13c529c Make partition_point to forward to binary_search_by 2021-05-17 19:13:41 +09:00
The8472
39e492a2be mark internal inplace_iteration traits as hidden 2021-05-16 19:36:21 +02:00
Ryan Lopopolo
963bd3b643
Implement more Iterator methods on core::iter::Repeat
`core::iter::Repeat` always returns the same element, which means we can
do better than implementing most `Iterator` methods in terms of
`Iterator::next`.

Fixes #81292.
2021-05-15 10:37:05 -07:00
Guillaume Gomez
62b834fb9f
Rollup merge of #84751 - Soveu:is_char_boundary_opt, r=Amanieu
str::is_char_boundary - slight optimization

Current `str::is_char_boundary` implementation emits slightly more instructions, because it includes an additional branch for `index == s.len()`
```rust
pub fn is_char_boundary(s: &str, index: usize) -> bool {
    if index == 0 || index == s.len() {
        return true;
    }
    match s.as_bytes().get(index) {
        None => false,
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
Just changing the place of `index == s.len()` merges it with `index < s.len()` from `s.as_bytes().get(index)`
```rust
pub fn is_char_boundary2(s: &str, index: usize) -> bool {
    if index == 0 {
        return true;
    }

    match s.as_bytes().get(index) {
        // For some reason, LLVM likes this comparison here more
        None => index == s.len(),
        // This is bit magic equivalent to: b < 128 || b >= 192
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
This one has better codegen on every platform, except powerpc
<details><summary>x86 codegen</summary>
<p>

```nasm
example::is_char_boundary:
        mov     al, 1
        test    rdx, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        jbe     .LBB0_3
        cmp     byte ptr [rdi + rdx], -65
        setg    al
.LBB0_5:
        ret
.LBB0_3:
        xor     eax, eax
        ret

example::is_char_boundary2:
        test    rdx, rdx
        je      .LBB1_1
        cmp     rsi, rdx
        jbe     .LBB1_4
        cmp     byte ptr [rdi + rdx], -65
        setg    al
        ret
.LBB1_1:  ; technically this branch is the same as LBB1_4
        mov     al, 1
        ret
.LBB1_4:
        sete    al
        ret
 ```
</p>
</details>

<details><summary>aarch64 codegen</summary>
<p>

```as
example::is_char_boundary:
        mov     x8, x0
        mov     w0, #1
        cbz     x2, .LBB0_4
        cmp     x1, x2
        b.eq    .LBB0_4
        b.ls    .LBB0_5
        ldrsb   w8, [x8, x2]
        cmn     w8, #65
        cset    w0, gt
.LBB0_4:
        ret
.LBB0_5:
        mov     w0, wzr
        ret

example::is_char_boundary2:
        cbz     x2, .LBB1_3
        cmp     x1, x2
        b.ls    .LBB1_4
        ldrsb   w8, [x0, x2]
        cmn     w8, #65
        cset    w0, gt
        ret
.LBB1_3:
        mov     w0, #1
        ret
.LBB1_4:
        cset    w0, eq
        ret
```

</p>
</details>

<details><summary>riscv64gc codegen</summary>
<p>

example::is_char_boundary:
        seqz    a3, a2
        xor     a4, a1, a2
        seqz    a4, a4
        or      a4, a4, a3
        addi    a3, zero, 1
        bnez    a4, .LBB0_3
        bgeu    a2, a1, .LBB0_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a3, a1, a0
.LBB0_3:
        mv      a0, a3
        ret
.LBB0_4:
        mv      a0, zero
        ret

example::is_char_boundary2:
        beqz    a2, .LBB1_3
        bgeu    a2, a1, .LBB1_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a0, a1, a0
        ret
.LBB1_3:
        addi    a0, zero, 1
        ret
.LBB1_4:
        xor     a0, a1, a2
        seqz    a0, a0
        ret

</p>
</details>

[Link to godbolt](https://godbolt.org/z/K8avEz8Gr)

`@rustbot` label: A-codegen
2021-05-15 17:56:47 +02:00
Satyarth Agrahari
196050305c adding time complexity for partition_in_place iter method 2021-05-15 10:50:02 +05:30
Amanieu d'Antras
5918ee4317 Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
2021-05-13 22:31:57 +01:00
Guillaume Gomez
16c825485f
Rollup merge of #85177 - tspiteri:wrapping-bits, r=joshtriplett
add BITS associated constant to core::num::Wrapping

This keeps `Wrapping` synchronized with the primitives it wraps as for the #32463 `wrapping_int_impl` feature.
2021-05-13 15:54:13 +02:00
bors
31bd868c39 Auto merge of #85218 - kornelski:pointerinline, r=scottmcm
#[inline(always)] on basic pointer methods

Retryng #85201 with only inlining pointer methods. The goal is to make pointers behave just like pointers in O0, mainly to reduce overhead in debug builds.

cc `@scottmcm`
2021-05-12 21:50:27 +00:00
bors
28e2b29b89 Auto merge of #84730 - sexxi-goose:rox-auto-trait, r=nikomatsakis
Add auto traits and clone trait migrations for RFC2229

This PR
- renames the existent RFC2229 migration `disjoint_capture_drop_reorder` to `disjoint_capture_migration`
- add additional migrations for auto traits and clone trait

Closes rust-lang/project-rfc-2229#29
Closes rust-lang/project-rfc-2229#28

r? `@nikomatsakis`
2021-05-12 13:33:32 +00:00
Kornel
3773740719 #[inline(always)] on basic pointer methods 2021-05-12 10:10:28 +01:00
Trevor Spiteri
a381e29117 add BITS associated constant to core::num::Wrapping
This keeps `Wrapping` synchronized with the primitives it wraps as for
the #32463 `wrapping_int_impl` feature.
2021-05-11 13:36:43 +02:00
Benoît du Garreau
9332ac3bfc Override clone_from for some types 2021-05-11 13:00:34 +02:00
Dylan DPC
7107c89970
Rollup merge of #85096 - clarfonthey:const_unchecked, r=oli-obk
Make unchecked_{add,sub,mul} inherent methods unstably const

The intrinsics are marked as being stably const (even though they're not stable by nature of being intrinsics), but the currently-unstable inherent versions are not marked as const. This fixes this inconsistency. Split out of #85017,

r? `@oli-obk`
2021-05-10 16:15:02 +02:00
Scott McMurray
bf0e34c001 PR feedback 2021-05-09 22:05:02 -07:00
ltdk
e6b12c8e4f Fix Step feature flag, make tidy lint more useful to find things like this 2021-05-09 17:15:54 -04:00
ltdk
380bbe8d47 Make unchecked_{add,sub,mul} inherent methods unstably const 2021-05-09 16:29:40 -04:00
Dylan DPC
aaf23892ab
Rollup merge of #84871 - richkadel:no-coverage-unstable-only, r=nagisa
Disallows `#![feature(no_coverage)]` on stable and beta (using standard crate-level gating)

Fixes: #84836

Removes the function-level feature gating solution originally implemented, and solves the same problem using `allow_internal_unstable`, so normal crate-level feature gating mechanism can still be used (which disallows the feature on stable and beta).

I tested this, building the compiler with and without `CFG_DISABLE_UNSTABLE_FEATURES=1`

With unstable features disabled, I get the expected result as shown here:

```shell
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc     src/test/run-make-fulldeps/coverage/no_cov_crate.rs
error[E0554]: `#![feature]` may not be used on the dev release channel
 --> src/test/run-make-fulldeps/coverage/no_cov_crate.rs:2:1
  |
2 | #![feature(no_coverage)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
```

r? ````@Mark-Simulacrum````
cc: ````@tmandry```` ````@wesleywiser````
2021-05-07 00:38:40 +02:00
Dylan DPC
7835c7802d
Rollup merge of #84755 - jyn514:core-links, r=kennytm
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with https://github.com/rust-lang/rust/issues/73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
2021-05-07 00:38:38 +02:00
Scott McMurray
b7a6c4a905 Perf Experiment: Wait, what if I just skip the trait alias 2021-05-06 11:37:46 -07:00
Scott McMurray
3d9660111c Fix rustdoc::private-intra-doc-links errors in the docs 2021-05-06 11:37:46 -07:00
Scott McMurray
4a7ceea930 Better rustc_on_unimplemented, and UI test fixes 2021-05-06 11:37:45 -07:00
Scott McMurray
266a72637a Simple library test updates 2021-05-06 11:37:45 -07:00
Scott McMurray
ca92b5a23a Actually implement the feature in the compiler
Including all the bootstrapping tweaks in the library.
2021-05-06 11:37:45 -07:00
Scott McMurray
c10eec3a1c Bootstrapping preparation for the library
Since just `ops::Try` will need to change meaning.
2021-05-06 11:37:44 -07:00
Roxane
9afea614bf Add additional migrations to handle auto-traits and clone traits
Combine all 2229 migrations under one flag name
2021-05-06 14:17:59 -04:00
Dylan DPC
ccf0e3e068
Rollup merge of #84949 - sdroege:maybe-unint-typo, r=m-ou-se
Fix typo in `MaybeUninit::array_assume_init` safety comment

And also add backticks around `MaybeUninit`.
2021-05-06 13:31:00 +02:00
Ralf Jung
92f3f0830f
Rollup merge of #84878 - jimblandy:contains-doc-fix, r=joshtriplett
Clarify documentation for `[T]::contains`

Change the documentation to correctly characterize when the suggested alternative to `contains` applies, and correctly explain why it works.

Fixes #84877
2021-05-05 17:52:26 +02:00
Ralf Jung
9ffba0917b
Rollup merge of #84843 - wcampbell0x2a:use-else-if-let, r=dtolnay
use else if in std library

Decreases indentation and improves readability
2021-05-05 17:52:24 +02:00
Ralf Jung
722bebf163
Rollup merge of #83553 - jfrimmel:addr-of, r=m-ou-se
Update `ptr` docs with regards to `ptr::addr_of!`

This updates the documentation since `ptr::addr_of!` and `ptr::addr_of_mut!` are now stable. One might remove the distinction between the sections `# On packed structs` and `# Examples`, as the old section on packed structs was primarily to prevent users of doing undefined behavior, which is not necessary anymore.

Technically there is now wrong/outdated documentation on stable, but I don't think this is worth a point release 😉

Fixes #83509.

``````````@rustbot`````````` modify labels: T-doc
2021-05-05 17:52:18 +02:00
Rich Kadel
3584c1dd0c Disallows #![feature(no_coverage)] on stable and beta
using allow_internal_unstable (as recommended)

Fixes: #84836

```shell
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc     src/test/run-make-fulldeps/coverage/no_cov_crate.rs
error[E0554]: `#![feature]` may not be used on the dev release channel
 --> src/test/run-make-fulldeps/coverage/no_cov_crate.rs:2:1
  |
2 | #![feature(no_coverage)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
```
2021-05-05 07:52:26 -07:00
Sebastian Dröge
42405b4fa8 Fix typo in MaybeUninit::array_assume_init safety comment
And also add backticks around `MaybeUninit`.
2021-05-05 12:31:38 +03:00
Julian Frimmel
389333a21c Update ptr docs with regards to ptr::addr_of!
This updates the documentation since `ptr::addr_of!` and
`ptr::addr_of_mut!` are now stable. One might remove the distinction
between the sections `# On packed structs` and `# Examples`, as the old
section on packed structs was primarily to prevent users of doing unde-
fined behavior, which is not necessary anymore.
There is also a new section in "how to obtain a pointer", which referen-
ces the `ptr::addr_of!` macros.

This commit contains squashed commits from code review.

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
Co-authored-by: Soveu <marx.tomasz@gmail.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-05-03 23:14:17 +02:00
Jim Blandy
d53469c1d3 Clarify documentation for [T]::contains. Fixes #84877. 2021-05-03 12:01:16 -07:00
wcampbell
2e559c8e10
use else if in std library
Clippy: Decreases indentation and improves readability

Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2021-05-03 07:05:08 -04:00
bors
e327a823d8 Auto merge of #84845 - wcampbell0x2a:clippy-redundant-field-names, r=joshtriplett
[clippy] remove redundant field names
2021-05-03 08:05:12 +00:00
wcampbell
962c3416ca
[clippy] remove redundant field names
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2021-05-02 20:24:17 -04:00
Brent Kerby
6679f5ceb1 Change 'NULL' to 'null' 2021-05-02 17:46:00 -06:00
bors
e244e840f2 Auto merge of #84725 - sebpop:arm64-isb, r=joshtriplett
[Arm64] use isb instruction instead of yield in spin loops

On arm64 we have seen on several databases that ISB (instruction synchronization
barrier) is better to use than yield in a spin loop.  The yield instruction is a
nop.  The isb instruction puts the processor to sleep for some short time.  isb
is a good equivalent to the pause instruction on x86.

Below is an experiment that shows the effects of yield and isb on Arm64 and the
time of a pause instruction on x86 Intel processors.  The micro-benchmarks use
https://github.com/google/benchmark.git

```
$ cat a.cc
static void BM_scalar_increment(benchmark::State& state) {
  int i = 0;
  for (auto _ : state)
    benchmark::DoNotOptimize(i++);
}
BENCHMARK(BM_scalar_increment);
static void BM_yield(benchmark::State& state) {
  for (auto _ : state)
    asm volatile("yield"::);
}
BENCHMARK(BM_yield);
static void BM_isb(benchmark::State& state) {
  for (auto _ : state)
    asm volatile("isb"::);
}
BENCHMARK(BM_isb);
BENCHMARK_MAIN();

$ g++ -o run a.cc -O2 -lbenchmark -lpthread
$ ./run

--------------------------------------------------------------
Benchmark                    Time             CPU   Iterations
--------------------------------------------------------------

AWS Graviton2 (Neoverse-N1) processor:
BM_scalar_increment      0.485 ns        0.485 ns   1000000000
BM_yield                 0.400 ns        0.400 ns   1000000000
BM_isb                    13.2 ns         13.2 ns     52993304

AWS Graviton (A-72) processor:
BM_scalar_increment      0.897 ns        0.874 ns    801558633
BM_yield                 0.877 ns        0.875 ns    800002377
BM_isb                    13.0 ns         12.7 ns     55169412

Apple Arm64 M1 processor:
BM_scalar_increment      0.315 ns        0.315 ns   1000000000
BM_yield                 0.313 ns        0.313 ns   1000000000
BM_isb                    9.06 ns         9.06 ns     77259282
```

```
static void BM_pause(benchmark::State& state) {
  for (auto _ : state)
    asm volatile("pause"::);
}
BENCHMARK(BM_pause);

Intel Skylake processor:
BM_scalar_increment      0.295 ns        0.295 ns   1000000000
BM_pause                  41.7 ns         41.7 ns     16780553
```

Tested on Graviton2 aarch64-linux with `./x.py test`.
2021-05-02 04:54:31 +00:00
Soveu
7bd9d9f1e9 str::is_char_boundary - few comments 2021-04-30 20:51:30 +02:00
Joshua Nelson
4a63e1e991 Allow using core:: in intra-doc links within core itself
I came up with this idea ages ago, but rustdoc used to ICE on it. Now it
doesn't.
2021-04-30 14:57:07 +00:00
Soveu
2ea0410f09 str::is_char_boundary - slight optimization 2021-04-30 16:13:00 +02:00
Sebastian Pop
c064b6560b [Arm64] use isb instruction instead of yield in spin loops
On arm64 we have seen on several databases that ISB (instruction synchronization
barrier) is better to use than yield in a spin loop.  The yield instruction is a
nop.  The isb instruction puts the processor to sleep for some short time.  isb
is a good equivalent to the pause instruction on x86.

Below is an experiment that shows the effects of yield and isb on Arm64 and the
time of a pause instruction on x86 Intel processors.  The micro-benchmarks use
https://github.com/google/benchmark.git

$ cat a.cc
static void BM_scalar_increment(benchmark::State& state) {
  int i = 0;
  for (auto _ : state)
    benchmark::DoNotOptimize(i++);
}
BENCHMARK(BM_scalar_increment);
static void BM_yield(benchmark::State& state) {
  for (auto _ : state)
    asm volatile("yield"::);
}
BENCHMARK(BM_yield);
static void BM_isb(benchmark::State& state) {
  for (auto _ : state)
    asm volatile("isb"::);
}
BENCHMARK(BM_isb);
BENCHMARK_MAIN();

$ g++ -o run a.cc -O2 -lbenchmark -lpthread
$ ./run

--------------------------------------------------------------
Benchmark                    Time             CPU   Iterations
--------------------------------------------------------------

AWS Graviton2 (Neoverse-N1) processor:
BM_scalar_increment      0.485 ns        0.485 ns   1000000000
BM_yield                 0.400 ns        0.400 ns   1000000000
BM_isb                    13.2 ns         13.2 ns     52993304

AWS Graviton (A-72) processor:
BM_scalar_increment      0.897 ns        0.874 ns    801558633
BM_yield                 0.877 ns        0.875 ns    800002377
BM_isb                    13.0 ns         12.7 ns     55169412

Apple Arm64 M1 processor:
BM_scalar_increment      0.315 ns        0.315 ns   1000000000
BM_yield                 0.313 ns        0.313 ns   1000000000
BM_isb                    9.06 ns         9.06 ns     77259282

static void BM_pause(benchmark::State& state) {
  for (auto _ : state)
    asm volatile("pause"::);
}
BENCHMARK(BM_pause);

Intel Skylake processor:
BM_scalar_increment      0.295 ns        0.295 ns   1000000000
BM_pause                  41.7 ns         41.7 ns     16780553

Tested on Graviton2 aarch64-linux with `./x.py test`.
2021-04-29 23:05:40 +00:00
Josh Triplett
20b569f579 Drop alias reduce for fold - we have a reduce function
Searching for "reduce" currently puts the `reduce` alias for `fold`
above the actual `reduce` function. The `reduce` function already has a
cross-reference for `fold`, and vice versa.
2021-04-29 12:05:08 -07:00
Rich Kadel
3a5df48021 adds feature gating of no_coverage at either crate- or function-level 2021-04-27 17:12:51 -07:00
Rich Kadel
888d0b4c96 Derived Eq no longer shows uncovered
The Eq trait has a special hidden function. MIR `InstrumentCoverage`
would add this function to the coverage map, but it is never called, so
the `Eq` trait would always appear uncovered.

Fixes: #83601

The fix required creating a new function attribute `no_coverage` to mark
functions that should be ignored by `InstrumentCoverage` and the
coverage `mapgen` (during codegen).

While testing, I also noticed two other issues:

* spanview debug file output ICEd on a function with no body. The
workaround for this is included in this PR.
* `assert_*!()` macro coverage can appear covered if followed by another
`assert_*!()` macro. Normally they appear uncovered. I submitted a new
Issue #84561, and added a coverage test to demonstrate this issue.
2021-04-27 11:11:56 -07:00
Dan Zwell
6c22b39187 Reorder the parameter descriptions of map_or and map_or_else
They were described backwards. #84608
2021-04-27 18:00:30 +08:00
bors
61e171566a Auto merge of #84092 - scottmcm:try_trait_initial, r=yaahc,m-ou-se
Add the `try_trait_v2` library basics

No compiler changes as part of this -- just new unstable traits and impls thereof.

The goal here is to add the things that aren't going to break anything, to keep the feature implementation simpler in the next PR.

(Draft since the FCP won't end until Saturday, but I was feeling optimistic today -- and had forgotten that FCP was 10 days, not 7 days.)
2021-04-26 23:17:31 +00:00
Mara Bos
9758d532f0
Rollup merge of #84523 - m-ou-se:stabilize-ordering-helpers, r=m-ou-se
Stabilize ordering_helpers.

Tracking issue: https://github.com/rust-lang/rust/issues/79885

Closes https://github.com/rust-lang/rust/issues/79885
2021-04-26 21:06:47 +02:00
Mara Bos
fb1502d570
Rollup merge of #84120 - workingjubilee:stabilize-duration-max, r=m-ou-se
Stabilize Duration::MAX

Following the suggested direction from https://github.com/rust-lang/rust/issues/76416#issuecomment-817278338, this PR proposes that `Duration::MAX` should have been part of the `duration_saturating_ops` feature flag all along, having been

0. heavily referenced by that feature flag
1. an odd duck next to most of `duration_constants`, as I expressed in https://github.com/rust-lang/rust/issues/57391#issuecomment-717681193
2. introduced in #76114 which added `duration_saturating_ops`

and accordingly should be folded into `duration_saturating_ops` and therefore stabilized.

r? `@m-ou-se`
2021-04-26 21:06:46 +02:00
bors
7bd62a8f5a Auto merge of #83390 - clarfonthey:hasher_docs, r=Amanieu
Document Hasher spec decision from #42951

Since that ticket was closed without the decision actually being documented.

Fixes #42951.
2021-04-26 08:21:55 +00:00
bors
4f0b24fd73 Auto merge of #84543 - paolobarbolini:reverse_bits-const-since, r=m-ou-se
Fix 'const-stable since' of reverse_bits

This fixes the const_stable `since` of `reverse_bits` for the signed and unsigned integer types. The previous value was incorrect, as it pointed to an older version where `reverse_bits` hadn't been stabilized yet.

`reverse_bits` was const-stable from the start, as can be seen from:

https://doc.rust-lang.org/1.37.0/std/primitive.u32.html#method.reverse_bits
https://doc.rust-lang.org/1.37.0/std/primitive.i32.html#method.reverse_bits
2021-04-26 05:41:04 +00:00
ltdk
920de7dd94 Document Hasher spec decision from #42951 2021-04-26 01:11:46 -04:00
Jubilee Young
8278380047 Update to reflect feedback on the constraints 2021-04-25 10:28:23 -07:00
Scott McMurray
5671647902 Documentation improvements (hopefully) 2021-04-25 10:04:23 -07:00
bors
06f0adb345 Auto merge of #84216 - RalfJung:black-box, r=Mark-Simulacrum
move core::hint::black_box under its own feature gate

The `black_box` function had its own RFC and is tracked separately from the `test` feature at https://github.com/rust-lang/rust/issues/64102. Let's reflect this in the feature gate.

To avoid breaking all the benchmarks, libtest's `test::black_box` is a wrapping definition, not a reexport -- this means it is still under the `test` feature gate.
2021-04-25 10:35:24 +00:00
Paolo Barbolini
34e51279ab Fix 'const-stable since' of reverse_bits 2021-04-25 11:58:59 +02:00
Ralf Jung
23d54ad96f move core::hint::black_box under its own feature gate 2021-04-25 11:08:12 +02:00
bors
13a2615883 Auto merge of #84147 - cuviper:array-method-dispatch, r=nikomatsakis,m-ou-se
Cautiously add IntoIterator for arrays by value

Add the attribute described in #84133, `#[rustc_skip_array_during_method_dispatch]`, which effectively hides a trait from method dispatch when the receiver type is an array.

Then cherry-pick `IntoIterator for [T; N]` from #65819 and gate it with that attribute. Arrays can now be used as `IntoIterator` normally, but `array.into_iter()` has edition-dependent behavior, returning `slice::Iter` for 2015 and 2018 editions, or `array::IntoIter` for 2021 and later.

r? `@nikomatsakis`
cc `@LukasKalbertodt` `@rust-lang/libs`
2021-04-25 07:26:49 +00:00
Jubilee Young
a80dbea918 Clarify Duration::MAX depends on Instant
Duration is used in std to represent a difference between two Instants.
As such, it has to at least contain that span of time in it. However,
Instant can vary by platform. Thus, we should explain the impl of
Duration::MAX is sensitive to these vagaries of the platform.
2021-04-24 16:57:58 -07:00
bors
b56b175c6c Auto merge of #84310 - RalfJung:const-fn-feature-flags, r=oli-obk
further split up const_fn feature flag

This continues the work on splitting up `const_fn` into separate feature flags:
* `const_fn_trait_bound` for `const fn` with trait bounds
* `const_fn_unsize` for unsizing coercions in `const fn` (looks like only `dyn` unsizing is still guarded here)

I don't know if there are even any things left that `const_fn` guards... at least libcore and liballoc do not need it any more.

`@oli-obk` are you currently able to do reviews?
2021-04-24 23:16:03 +00:00
Yuki Okushi
46b67ab0f9
Rollup merge of #84105 - WaffleLapkin:stabilize_array_from_ref, r=m-ou-se
stabilize `core::array::{from_ref,from_mut}` in `1.53.0`

I didn't get any response in https://github.com/rust-lang/rust/issues/77101#issuecomment-761831104, so I figured out I can try opening stabilization pr.

---

This PR stabilizes following functions:
```rust
// core::array
pub fn from_ref<T>(s: &T) -> &[T; 1];
pub fn from_mut<T>(s: &mut T) -> &mut [T; 1];
```

Functions are similar to already stabilized `core::slice::{`[`from_ref`](https://doc.rust-lang.org/std/slice/fn.from_ref.html),[`from_mut`](https://doc.rust-lang.org/std/slice/fn.from_mut.html)`}` and were unstable without any problems/questions for a while now.

---

resolves #77101

``@rustbot`` modify labels: +T-libs
2021-04-25 01:53:10 +09:00
Mara Bos
d86835281b Stabilize ordering_helpers. 2021-04-24 18:45:20 +02:00
Yuki Okushi
ed991a36b0
Rollup merge of #84489 - amorison:issue-83969-fix, r=yaahc
Mention FusedIterator case in Iterator::fuse doc

Using `fuse` on an iterator that incorrectly implements
`FusedIterator` does not fuse the iterator. This commit adds a
note about this in the documentation of this method to increase
awareness about this potential issue (esp. when relying on fuse
in unsafe code).

Closes #83969
2021-04-24 12:17:09 +09:00
Yuki Okushi
c00439f682
Rollup merge of #83990 - the8472:take-trusted-len, r=dtolnay
implement `TrustedRandomAccess` for `Take` iterator adapter

`TrustedRandomAccess` requires the iterator length to fit within `usize`. `take(n)` only constrains the upper bound of an iterator. So if the inner is `TrustedRandomAccess` (which already implies a finite length) then so can be `Take`.

```````@rustbot``````` label T-libs-impl
2021-04-24 12:17:01 +09:00
Yuki Okushi
9ada731c65
Rollup merge of #84444 - notriddle:num-docs-from-undocumented-items-toggle, r=yaahc
doc: Get rid of "[+] show undocumented items" toggle on numeric From impls

On most From implementations, the docstring is attached to the function. This is also how people have been [recommended] to do it.

Screenshots:

* [before](https://user-images.githubusercontent.com/1593513/115767662-323c5480-a35e-11eb-9918-98aba83e9183.png)
* [after](https://user-images.githubusercontent.com/1593513/115767675-35374500-a35e-11eb-964f-c28eeb6c807a.png)

[recommended]: https://github.com/rust-lang/rust/issues/51430#issuecomment-398322434
2021-04-24 03:44:12 +09:00
Yuki Okushi
dcb4083ed9
Rollup merge of #80805 - camelid:iter-by_ref-example, r=steveklabnik
Improve `Iterator::by_ref` example

I split the example into two: one that fails to compile, and one that
works. I also made them identical except for the addition of `by_ref`
so we don't confuse readers with random differences.

cc `@steveklabnik,` who is the one that added the previous version of this example
2021-04-24 03:44:02 +09:00
Adrien Morison
21b3b27fe4 Mention FusedIterator case in Iterator::fuse doc
Using `fuse` on an iterator that incorrectly implements
`FusedIterator` does not fuse the iterator. This commit adds a
note about this in the documentation of this method to increase
awareness about this potential issue (esp. when relying on fuse
in unsafe code).
2021-04-23 19:13:27 +01:00
bors
cb81dc535c Auto merge of #82585 - TrolledWoods:master, r=dtolnay
Added CharIndices::offset function

The CharIndices iterator has a field internally called front_offset, that I think would be very useful to have access to.

You can already do something like ``char_indices.next().map(|(offset, _)| offset)``, but that is wordy, in addition to not handling the case where the iterator has ended, where you'd want the offset to be equal to the length.

I'm very new to the open source world and the rust repository, so I'm sorry if I missed a step or did something weird.
2021-04-23 02:48:13 +00:00
Michael Howell
c247055032 Get rid of "[+] show undocumented items" toggle on numeric From impls
On most From implementations, the docstring is attached to the
function. This is also how people have been [recommended] to do it.

Screenshots:

* [before](https://user-images.githubusercontent.com/1593513/115767662-323c5480-a35e-11eb-9918-98aba83e9183.png)
* [after](https://user-images.githubusercontent.com/1593513/115767675-35374500-a35e-11eb-964f-c28eeb6c807a.png)

[recommended]: https://github.com/rust-lang/rust/issues/51430#issuecomment-398322434
2021-04-22 11:51:05 -07:00
bors
ccf171242b Auto merge of #77704 - AnthonyMikh:slice_index_with_ops_bound_pair, r=m-ou-se
Implement indexing slices with pairs of core::ops::Bound<usize>

Closes #49976.

I am not sure about code duplication between `check_range` and `into_maybe_range`. Should be former implemented in terms of the latter? Also this PR doesn't address code duplication between `impl SliceIndex for Range*`.
2021-04-22 15:36:27 +00:00
Mara Bos
268d29d75d
Rollup merge of #84406 - m-ou-se:drop-delete-alias, r=dtolnay
Remove `delete` alias from `mem::drop`.

See https://github.com/rust-lang/rust/pull/81988#issuecomment-824168459 and https://github.com/rust-lang/rust/pull/81988#issuecomment-824213843
2021-04-21 23:06:24 +02:00
Mara Bos
49a5c80a3b
Rollup merge of #84390 - m-ou-se:make-debug-non-exhaustive-without-fields-a-little-bit-less-verbose, r=kennytm
Format `Struct { .. }` on one line even with `{:#?}`.

The result of `debug_struct("A").finish_non_exhaustive()` before this change:
```
A {
    ..
}
```
And after this change:
```
A { .. }
```

If there's any fields, the result stays unchanged:
```
A {
    field: value,
    ..
}
2021-04-21 23:06:21 +02:00
Mara Bos
d341851f94
Rollup merge of #84301 - r00ster91:patch-1, r=kennytm
Document that `index` and `index_mut` can panic

I thought this was noteworthy and I think a bit more explicitness does no harm.
2021-04-21 23:06:16 +02:00
Mara Bos
47886ead1f
Rollup merge of #84251 - RalfJung:non-zero-const-since, r=kennytm
fix 'const-stable since' for NonZeroU*::new_unchecked

For the unsigned `NonZero` types, `new_unchecked` was const-stable from the start with https://github.com/rust-lang/rust/pull/50808. Fix the docs to accurately reflect that.

I think this `since` is also incorrect:
```rust
            #[stable(feature = "from_nonzero", since = "1.31.0")]
            impl From<$Ty> for $Int {
```
The signed nonzero types were only stabilized in 1.34, so that `From` impl certainly didn't exist before. But I had enough of digging through git histories after I figured out when `new_unchecked` became const-stable...^^
2021-04-21 23:06:15 +02:00
Mara Bos
a7a7737114
Rollup merge of #84013 - CDirkx:fmt, r=m-ou-se
Replace all `fmt.pad` with `debug_struct`

This replaces any occurrence of:
- `f.pad("X")` with `f.debug_struct("X").finish()`
- `f.pad("X { .. }")` with `f.debug_struct("X").finish_non_exhaustive()`

This is in line with existing formatting code such as
1255053067/library/std/src/sync/mpsc/mod.rs (L1470-L1475)
2021-04-21 23:06:11 +02:00
Mara Bos
6763a40eff
Bump slice_index_with_ops_bound_pair to 1.53.0 2021-04-21 22:40:19 +02:00
Mara Bos
f1f3069a98 Remove delete alias from mem::drop. 2021-04-21 21:54:39 +02:00
Christiaan Dirkx
fdae75738b Change the Debug impl of Any and UnsafeCell to use finish_non_exhaustive 2021-04-21 14:51:04 +02:00
Christiaan Dirkx
1fb3256fcb Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
Mara Bos
82dc73b1ae Format Struct { .. } on one line even with {:#?}. 2021-04-21 13:50:56 +02:00
Aleksey Kladov
de16951dad Clarify the difference between insert and get_or_insert 2021-04-19 18:17:45 +03:00
Ralf Jung
fbfaab2cb7 separate feature flag for unsizing casts in const fn 2021-04-18 19:11:29 +02:00
Ralf Jung
fdad6ab3a3 move 'trait bounds on const fn' to separate feature gate 2021-04-18 18:36:41 +02:00
r00ster
c86ffe9e89
Say that it "may panic" 2021-04-18 18:16:10 +02:00
r00ster
df01b3a67b
Document that index and index_mut can panic 2021-04-18 15:51:16 +02:00