Commit Graph

3377 Commits

Author SHA1 Message Date
Maybe Waffle
03d4569939 Fill-in tracking issues for features pointer_byte_offsets, const_pointer_byte_offsets and pointer_is_aligned 2022-05-12 12:54:21 +04:00
Maybe Waffle
5a5d62aeb2 Optimize ptr.is_aligned_to()
Apparently LLVM is unable to understand that if count_ones() == 1 then self != 0.
Adding `assume(align != 0)` helps generating better asm:
https://rust.godbolt.org/z/ja18YKq91
2022-05-12 12:54:21 +04:00
Maybe Waffle
6c1ebff59e Implement ptr.is_aligned() in terms of .is_aligned_to() 2022-05-12 12:54:21 +04:00
Maybe Waffle
a908eec438 Lift the Sized requirement from convenience ptr fns
Since they work on byte pointers (by `.cast::<u8>()`ing them), there is
no need to know the size of `T` and so there is no need for `T: Sized`.

The `is_aligned_to` is similar, though it doesn't need the _alignment_
of `T`.
2022-05-12 12:54:21 +04:00
Maybe Waffle
c8c91f757a Add convenience functions to pointers
The functions added:
- {*const T,*mut T}::{wrapping_,}byte_{offset,add,sub}
- {*const T,*mut T}::{byte_offset_from,is_aligned,is_aligned_to}
2022-05-12 12:54:16 +04:00
Scott McMurray
003b954a43 Apply CR suggestions; add real tracking issue 2022-05-11 17:16:25 -07:00
Scott McMurray
4bb15b3797 Add a debug check for ordering, and check for isize overflow in CTFE 2022-05-11 17:16:25 -07:00
Scott McMurray
e76b3f3b5b Rename unsigned_offset_from to sub_ptr 2022-05-11 17:16:25 -07:00
Scott McMurray
89a18cb600 Add unsigned_offset_from on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`.  Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`.

As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives.  That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.

This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE.  It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-11 17:16:25 -07:00
Dylan DPC
c5c273b30e
Rollup merge of #96674 - bstrie:vardoc, r=thomcc
docs: add link explaining variance to NonNull docs
2022-05-10 08:24:02 +02:00
Matthias Krüger
6c8001b85c
Rollup merge of #96008 - fmease:warn-on-useless-doc-hidden-on-assoc-impl-items, r=lcnr
Warn on unused `#[doc(hidden)]` attributes on trait impl items

[Zulip conversation](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.E2.9C.94.20Validy.20checks.20for.20.60.23.5Bdoc.28hidden.29.5D.60).

Whether an associated item in a trait impl is shown or hidden in the documentation entirely depends on the corresponding item in the trait declaration. Rustdoc completely ignores `#[doc(hidden)]` attributes on impl items. No error or warning is emitted:

```rust
pub trait Tr { fn f(); }
pub struct Ty;
impl Tr for Ty { #[doc(hidden)] fn f() {} }
//               ^^^^^^^^^^^^^^ ignored by rustdoc and currently
//                              no error or warning issued
```

This may lead users to the wrong belief that the attribute has an effect. In fact, several such cases are found in the standard library (I've removed all of them in this PR).
There does not seem to exist any incentive to allow this in the future either: Impl'ing a trait for a type means the type *fully* conforms to its API. Users can add `#[doc(hidden)]` to the whole impl if they want to hide the implementation or add the attribute to the corresponding associated item in the trait declaration to hide the specific item. Hiding an implementation of an associated item does not make much sense: The associated item can still be found on the trait page.

This PR emits the warn-by-default lint `unused_attribute` for this case with a future-incompat warning.

`@rustbot` label T-compiler T-rustdoc A-lint
2022-05-09 18:45:36 +02:00
Matthias Krüger
28d800ce1c
Rollup merge of #95483 - golddranks:improve_float_docs, r=joshtriplett
Improve floating point documentation

This is my attempt to improve/solve https://github.com/rust-lang/rust/issues/95468 and https://github.com/rust-lang/rust/issues/73328 .

Added/refined explanations:
- Refine the "NaN as a special value" top level explanation of f32
- Refine `const NAN` docstring: add an explanation about there being multitude of NaN bitpatterns and disclaimer about the portability/stability guarantees.
- Refine `fn is_sign_positive` and `fn is_sign_negative` docstrings: add disclaimer about the sign bit of NaNs.
- Refine `fn min` and `fn max` docstrings: explain the semantics and their relationship to the standard and libm better.
- Refine `fn trunc` docstrings: explain the semantics slightly more.
- Refine `fn powi` docstrings: add disclaimer that the rounding behaviour might be different from `powf`.
- Refine `fn copysign` docstrings: add disclaimer about payloads of NaNs.
- Refine `minimum` and `maximum`: add disclaimer that "propagating NaN" doesn't mean that propagating the NaN bit patterns is guaranteed.
- Refine `max` and `min` docstrings: add "ignoring NaN" to bring the one-row explanation to parity with `minimum` and `maximum`.

Cosmetic changes:
- Reword `NaN` and `NAN` as plain "NaN", unless they refer to the specific `const NAN`.
- Reword "a number" to `self` in function docstrings to clarify.
- Remove "Returns NAN if the number is NAN" from `abs`, as this is told to be the default behavior in the top explanation.
2022-05-09 18:45:35 +02:00
bors
8a2fe75d0e Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errors
Remove `#[rustc_deprecated]`

This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`.

I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-05-09 04:47:30 +00:00
bors
cb12198715 Auto merge of #96846 - matthiaskrgr:rollup-yxu9ot9, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #96617 (Fix incorrect syntax suggestion with `pub async fn`)
 - #96828 (Further elaborate the lack of guarantees from `Hasher`)
 - #96829 (Fix the `x.py clippy` command)
 - #96830 (Add and tweak const-generics tests)
 - #96835 (Add more eslint rules)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-08 21:37:26 +00:00
León Orell Valerian Liehr
9d157ada35 Warn on unused doc(hidden) on trait impl items 2022-05-08 22:53:14 +02:00
Matthias Krüger
2c4d7a5463
Rollup merge of #96828 - scottmcm:clarify-hasher-write, r=Amanieu
Further elaborate the lack of guarantees from `Hasher`

I realized that I got too excited in #94598 by adding new methods, and forgot to do the documentation to really answer the core question in #94026.

This PR just has that doc update.

r? `@Amanieu`
2022-05-08 21:31:17 +02:00
bors
68461648bf Auto merge of #96302 - Serial-ATA:more-diagnostic-items, r=manishearth
Add more diagnostic items

This just adds a handful diagnostic items I noticed were missing.

Would it be worth doing this for all of the remaining types? I'm willing to do it if it'd be helpful.
2022-05-08 19:08:34 +00:00
Scott McMurray
83f785bff9 Further elaborate the lack of guarantees from Hasher 2022-05-07 17:44:30 -07:00
Matthias Krüger
1386a02dc1
Rollup merge of #96336 - Nilstrieb:link-to-correct-as_mut-in-ptr-as_ref, r=JohnTitor
Link to correct `as_mut` in docs for `pointer::as_ref`

It previously linked to the unstable const-mut-cast method instead of
the `mut` counterpart for `as_ref`.

Closes #96327
2022-05-07 22:44:36 +02:00
Nikolaos Chatzikonstantinou
7c1d241f2b
Fix a minor typo in the description of Formatter 2022-05-07 19:32:54 +09:00
bors
8c4fc9d9a4 Auto merge of #94598 - scottmcm:prefix-free-hasher-methods, r=Amanieu
Add a dedicated length-prefixing method to `Hasher`

This accomplishes two main goals:
- Make it clear who is responsible for prefix-freedom, including how they should do it
- Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths

This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.

Fixes #94026

r? rust-lang/libs

---

The core of this change is the following two new methods on `Hasher`:

```rust
pub trait Hasher {
    /// Writes a length prefix into this hasher, as part of being prefix-free.
    ///
    /// If you're implementing [`Hash`] for a custom collection, call this before
    /// writing its contents to this `Hasher`.  That way
    /// `(collection![1, 2, 3], collection![4, 5])` and
    /// `(collection![1, 2], collection![3, 4, 5])` will provide different
    /// sequences of values to the `Hasher`
    ///
    /// The `impl<T> Hash for [T]` includes a call to this method, so if you're
    /// hashing a slice (or array or vector) via its `Hash::hash` method,
    /// you should **not** call this yourself.
    ///
    /// This method is only for providing domain separation.  If you want to
    /// hash a `usize` that represents part of the *data*, then it's important
    /// that you pass it to [`Hasher::write_usize`] instead of to this method.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(hasher_prefixfree_extras)]
    /// # // Stubs to make the `impl` below pass the compiler
    /// # struct MyCollection<T>(Option<T>);
    /// # impl<T> MyCollection<T> {
    /// #     fn len(&self) -> usize { todo!() }
    /// # }
    /// # impl<'a, T> IntoIterator for &'a MyCollection<T> {
    /// #     type Item = T;
    /// #     type IntoIter = std::iter::Empty<T>;
    /// #     fn into_iter(self) -> Self::IntoIter { todo!() }
    /// # }
    ///
    /// use std:#️⃣:{Hash, Hasher};
    /// impl<T: Hash> Hash for MyCollection<T> {
    ///     fn hash<H: Hasher>(&self, state: &mut H) {
    ///         state.write_length_prefix(self.len());
    ///         for elt in self {
    ///             elt.hash(state);
    ///         }
    ///     }
    /// }
    /// ```
    ///
    /// # Note to Implementers
    ///
    /// If you've decided that your `Hasher` is willing to be susceptible to
    /// Hash-DoS attacks, then you might consider skipping hashing some or all
    /// of the `len` provided in the name of increased performance.
    #[inline]
    #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")]
    fn write_length_prefix(&mut self, len: usize) {
        self.write_usize(len);
    }

    /// Writes a single `str` into this hasher.
    ///
    /// If you're implementing [`Hash`], you generally do not need to call this,
    /// as the `impl Hash for str` does, so you can just use that.
    ///
    /// This includes the domain separator for prefix-freedom, so you should
    /// **not** call `Self::write_length_prefix` before calling this.
    ///
    /// # Note to Implementers
    ///
    /// The default implementation of this method includes a call to
    /// [`Self::write_length_prefix`], so if your implementation of `Hasher`
    /// doesn't care about prefix-freedom and you've thus overridden
    /// that method to do nothing, there's no need to override this one.
    ///
    /// This method is available to be overridden separately from the others
    /// as `str` being UTF-8 means that it never contains `0xFF` bytes, which
    /// can be used to provide prefix-freedom cheaper than hashing a length.
    ///
    /// For example, if your `Hasher` works byte-by-byte (perhaps by accumulating
    /// them into a buffer), then you can hash the bytes of the `str` followed
    /// by a single `0xFF` byte.
    ///
    /// If your `Hasher` works in chunks, you can also do this by being careful
    /// about how you pad partial chunks.  If the chunks are padded with `0x00`
    /// bytes then just hashing an extra `0xFF` byte doesn't necessarily
    /// provide prefix-freedom, as `"ab"` and `"ab\u{0}"` would likely hash
    /// the same sequence of chunks.  But if you pad with `0xFF` bytes instead,
    /// ensuring at least one padding byte, then it can often provide
    /// prefix-freedom cheaper than hashing the length would.
    #[inline]
    #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")]
    fn write_str(&mut self, s: &str) {
        self.write_length_prefix(s.len());
        self.write(s.as_bytes());
    }
}
```

With updates to the `Hash` implementations for slices and containers to call `write_length_prefix` instead of `write_usize`.

`write_str` defaults to using `write_length_prefix` since, as was pointed out in the issue, the `write_u8(0xFF)` approach is insufficient for hashers that work in chunks, as those would hash `"a\u{0}"` and `"a"` to the same thing.  But since `SipHash` works byte-wise (there's an internal buffer to accumulate bytes until a full chunk is available) it overrides `write_str` to continue to use the add-non-UTF-8-byte approach.

---

Compatibility:

Because the default implementation of `write_length_prefix` calls `write_usize`, the changed hash implementation for slices will do the same thing the old one did on existing `Hasher`s.
2022-05-06 09:43:57 +00:00
Lukas Lueg
cd1746b2b4 Clarify unreachable_unchecked docs 2022-05-06 09:34:41 +02:00
Scott McMurray
ebdcb08abf For now, don't change the details of hashing a str
We might want to change the default before stabilizing (or maybe even after), but for getting in the new unstable methods, leave it as-is for now.  That way it won't break cargo and such.
2022-05-06 00:14:44 -07:00
Scott McMurray
98054377ee Add a dedicated length-prefixing method to Hasher
This accomplishes two main goals:
- Make it clear who is responsible for prefix-freedom, including how they should do it
- Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths

This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.
2022-05-06 00:03:38 -07:00
Michael Goulet
ef949daf03
Rollup merge of #96639 - adpaco-aws:fix-offset-from-typo, r=scottmcm
Fix typo in `offset_from` documentation

Small fix for what I think is a typo in the `offset_from` documentation.

Someone reading this may understand that the distance in bytes is obtained by dividing the distance by `mem::size_of::<T>()`, but here we just want to define "units of T" in terms of bytes (i.e., units of T == bytes / `mem::size_of::<T>()`).
2022-05-05 19:34:23 -07:00
Michael Goulet
87ad928c15
Rollup merge of #96174 - RalfJung:no-run-transmute, r=scottmcm
mark ptr-int-transmute test as no_run

This causes [CI failures in Miri](https://github.com/rust-lang/miri-test-libstd/runs/6062500259?check_suite_focus=true) since ptr-int-transmutes are rejected there (when strict provenance is enabled).
2022-05-05 19:34:22 -07:00
bors
74cea9fdb9 Auto merge of #96520 - lcnr:general-incoherent-impls, r=petrochenkov
generalize "incoherent impls" impl for user defined types

To allow the move of `trait Error` into core.

continues the work from #94963, finishes https://github.com/rust-lang/compiler-team/issues/487

r? `@petrochenkov` cc `@yaahc`
2022-05-05 23:24:36 +00:00
Matthias Krüger
47801413d9
Rollup merge of #95359 - jhpratt:int_roundings, r=joshtriplett
Update `int_roundings` methods from feedback

This updates `#![feature(int_roundings)]` (#88581) from feedback. All methods now take `NonZeroX`. The documentation makes clear that they panic in debug mode and wrap in release mode.

r? `@joshtriplett`

`@rustbot` label +T-libs +T-libs-api +S-waiting-on-review
2022-05-05 15:43:00 +02:00
lcnr
209dd2cb0a generalize "incoherent impls" impl for custom types 2022-05-05 10:53:00 +02:00
bors
3d18f945ca Auto merge of #96630 - m-ysk:fix/issue-88038, r=notriddle
Include nonexported macro_rules! macros in the doctest target

Fixes #88038

This PR aims to include nonexported `macro_rules!` macros in the doctest target. For more details, please see the above issue.
2022-05-05 07:25:18 +00:00
bors
12d3f107c1 Auto merge of #96626 - thomcc:rand-bump, r=m-ou-se
Avoid using `rand::thread_rng` in the stdlib benchmarks.

This is kind of an anti-pattern because it introduces extra nondeterminism for no real reason. In thread_rng's case this comes both from the random seed and also from the reseeding operations it does, which occasionally does syscalls (which adds additional nondeterminism). The impact of this would be pretty small in most cases, but it's a good practice to avoid (particularly because avoiding it was not hard).

Anyway, several of our benchmarks already did the right thing here anyway, so the change was pretty easy and mostly just applying it more universally. That said, the stdlib benchmarks aren't particularly stable (nor is our benchmark framework particularly great), so arguably this doesn't matter that much in practice.

~~Anyway, this also bumps the `rand` dev-dependency to 0.8, since it had fallen somewhat out of date.~~ Nevermind, too much of a headache.
2022-05-05 05:08:44 +00:00
Jacob Pratt
dde590d180
Update int_roundings methods from feedback 2022-05-04 23:20:29 -04:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
Roland Kuhn
3d808d52de
add caveat discussed in #74335 2022-05-04 10:58:23 +02:00
bors
086bf7a8ff Auto merge of #96280 - lygstate:ffi-fixes, r=joshtriplett
library/core: Fixes implement of c_uint, c_long, c_ulong

Fixes: aa67016624 ("make memcmp return a value of c_int_width instead of i32")
Introduce c_num_definition to getting the cfg_if logic easier to maintain
Add newlines for easier code reading

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
2022-05-03 17:22:58 +00:00
bstrie
6096cfbfff docs: add link explaining variance to NonNull docs 2022-05-03 11:57:24 -04:00
Yoshiki Matsuda
3d12fd0faf ignore a doctest for the non-exported macro 2022-05-03 18:33:56 +09:00
Yonggang Luo
2e69549043
Update library/core/src/ffi/mod.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-05-03 10:42:46 +08:00
The 8472
a68a5d219d This aligns the inline attributes of existing __iterator_get_unchecked with those of next() on adapters that have both.
It improves the performance of iterators using unchecked access when building in incremental mode
(due to the larger CGU count?). It might negatively affect incremental compile times for better runtime results,
but considering that the equivalent `next()` implementations also are `#[inline]` and usually are more complex this
should be ok.

```
./x.py bench library/core -i --stage 0 --test-args bench_trusted_random_access

OLD: 119,172 ns/iter
NEW:  17,714 ns/iter
```
2022-05-02 20:54:46 +02:00
The 8472
e3db41bf97 add benchmark 2022-05-02 20:54:46 +02:00
Adrian Palacios
9b36a47831 Fix typo in offset_from documentation 2022-05-02 14:41:21 +00:00
Pyry Kontio
dea776512b Fix nits 2022-05-02 23:29:02 +09:00
Thom Chiovoloni
0812759840
Avoid use of rand::thread_rng in stdlib benchmarks 2022-05-02 00:08:21 -07:00
Yuki Okushi
f58135449e
Rollup merge of #96567 - alex-semenyuk:fix_docs_for_logs_func, r=Mark-Simulacrum
Fix docs for u32 and i32 logs func

Closes #96545
2022-05-02 10:41:57 +09:00
bors
4dd8b420c0 Auto merge of #96521 - petrochenkov:docrules, r=notriddle,GuillaumeGomez
rustdoc: Resolve doc links referring to `macro_rules` items

cc https://github.com/rust-lang/rust/issues/81633

UPD: the fallback to considering *all* `macro_rules` in the crate for unresolved names is not removed in this PR, it will be removed separately and will be run through crater.
2022-05-01 20:28:10 +00:00
Scott McMurray
e094ee5f10 Add do yeet expressions to allow experimentation in nightly
Using an obviously-placeholder syntax.  An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point.

But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-30 17:40:27 -07:00
Vadim Petrochenkov
6083db7c4e Fix some links in the standard library 2022-05-01 00:02:34 +03:00
bors
579d26876d Auto merge of #96348 - overdrivenpotato:inline-location, r=the8472
Inline core::panic::Location methods

This avoids the overhead of a function call when used.
2022-04-30 16:33:12 +00:00
alexey semenyuk
6ee70bc6b3
Fix documentation for log functions int 2022-04-29 23:21:50 +00:00
alexey semenyuk
ec90f9dd33
Fix documentation for log functions unsigned int 2022-04-29 23:16:53 +00:00
Serial
09b0b8b6e2 Add more diagnostic items 2022-04-28 16:42:20 -04:00
Dylan DPC
2c1d58b8cc
Rollup merge of #96480 - user-simon:patch-1, r=Dylan-DPC
Fixed grammatical error in example comment

Added missing "we" in sentence.
2022-04-28 20:13:03 +02:00
Simon
332f326334
Fixed grammatical error in example comment 2022-04-27 17:27:02 +02:00
Michael Goulet
83d701e569 Better error messages when collecting into [T; n] 2022-04-26 21:37:10 -07:00
Guillaume Gomez
2b8bf0d530
Rollup merge of #95949 - SoniEx2:patch-5, r=m-ou-se
Implement Default for AssertUnwindSafe

Trait impls are still insta-stable yeah...?
2022-04-26 13:22:27 +02:00
Dylan DPC
93db30aa7f
Rollup merge of #96149 - est31:remove_unused_macro_matchers, r=petrochenkov
Remove unused macro rules

Removes rules of internal macros that weren't triggered.
2022-04-26 01:21:20 +02:00
Dylan DPC
51b86848ff
Rollup merge of #90312 - r00ster91:search, r=Dylan-DPC
Fix some confusing wording and improve slice-search-related docs

This adds more links between `contains` and `binary_search` because I do think they have some relevant connections. If your (big) slice happens to be sorted and you know it, surely you should be using `[3; 100].binary_search(&5).is_ok()` over `[3; 100].contains(&5)`?
This also fixes the confusing "searches this sorted X" wording which just sounds really weird because it doesn't know whether it's actually sorted. It should be but it may not be. The new wording should make it clearer that you will probably want to sort it and in the same sentence it also mentions the related function `contains`.
Similarly, this mentions `binary_search` on `contains`' docs.
This also fixes some other minor stuff and inconsistencies.
2022-04-26 01:21:20 +02:00
Marko Mijalkovic
92a584177d Inline core::panic::Location methods 2022-04-23 14:41:47 -04:00
bors
6b4563bf93 Auto merge of #90602 - mbartlett21:const-intoiterator, r=oli-obk
Unstably constify `impl<I: Iterator> IntoIterator for I`

This constifies the default `IntoIterator` implementation under the `const_intoiterator_identity` feature.

Tracking Issue: #90603
2022-04-23 15:41:45 +00:00
bors
1e9aa8a96b Auto merge of #95971 - workingjubilee:no-weird-fp-in-const, r=oli-obk
No "weird" floats in const fn {from,to}_bits

I suspect this code is subtly incorrect and that we don't even e.g. use x87-style floats in CTFE, so I don't have to guard against that case. A future PR will be hopefully removing them from concern entirely, anyways. But at the moment I wanted to get this rolling because small questions like that one seem best answered by review.

r? `@oli-obk`
cc `@eddyb` `@thomcc`
2022-04-23 13:00:54 +00:00
Nilstrieb
521bb810be Link to correct as_mut in docs for pointer::as_ref
It previously linked to the unstable const-mut-cast method instead of
the `mut` counterpart for `as_ref`.
2022-04-23 13:42:26 +02:00
Jubilee Young
4da8682523 Remove unnecessary const-time x87-related checks 2022-04-22 19:34:33 -07:00
Jubilee Young
bb555b828c Fix comments for float classify 2022-04-22 18:34:34 -07:00
Yonggang Luo
1d5948f473 library/core: Fixes implement of c_uint, c_long, c_ulong
Fixes: aa67016624 ("make memcmp return a value of c_int_width instead of i32")
Introduce c_num_definition to getting the cfg_if logic easier to maintain
Add newlines for easier code reading

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
2022-04-21 17:18:32 +08:00
mbartlett21
4879875c76
Change file locations to be links to GitHub 2022-04-20 13:14:32 +10:00
mbartlett21
671a8723c6
Fix locations for intrinsics impls 2022-04-20 09:28:07 +10:00
bors
d5ae66c12c Auto merge of #92287 - JulianKnodt:slice_remainder, r=yaahc
Add slice::remainder

This adds a remainder function to the Slice iterator, so that a caller can access unused
elements if iteration stops.

Addresses #91733
2022-04-18 23:34:24 +00:00
est31
3c1e1661e7 Remove unused macro rules 2022-04-18 23:28:06 +02:00
Dylan DPC
55e399771e
Rollup merge of #96156 - est31:use_from_le_bytes, r=Dylan-DPC
Replace u8to64_le macro with u64::from_le_bytes

The macro was a reimplementation of the function.
2022-04-18 18:22:07 +02:00
Dylan DPC
a6ad1394f3
Rollup merge of #96136 - thomcc:lifetime-wording, r=RalfJung
Reword clarification on lifetime for ptr->ref safety docs

I believe the current wording of the safety comment is somewhat misleading, and that this is more accurate. Suggested by `@CAD97` in this thread on the topic https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Lifetime.20of.20reference.20pointer.20docs.20issue

Just to check that this is correct, CC `@RalfJung.`

I suppose it's open for interpretation as to whether or not this is more clear. I think it is.
2022-04-18 18:22:04 +02:00
Ralf Jung
74d77d058b mark ptr-int-transmute test as no_run 2022-04-18 10:04:31 -04:00
est31
9e7a319f01 Replace u8to64_le macro with u64::from_le_bytes
The macro was a reimplementation of the function.
2022-04-17 22:55:33 +02:00
Lukas Lueg
3615cb476b Expand core::hint::unreachable_unchecked() docs
Fixes #95865
2022-04-17 20:58:36 +02:00
kadmin
494901ced6 Add slice::remainder
This adds a remainder function to the Slice iterator, so that a caller can access unused
elements if iteration stops.
2022-04-17 17:19:45 +00:00
bors
ac8b11810f Auto merge of #96010 - eduardosm:Unique-on-top-of-NonNull, r=m-ou-se,tmiasko
Implement `core::ptr::Unique` on top of `NonNull`

Removes the use `rustc_layout_scalar_valid_range_start` and some `unsafe` blocks.
2022-04-17 05:26:08 +00:00
Thom Chiovoloni
be30e40440
Reword clarification on lifetime for ptr->ref safety docs 2022-04-16 21:39:43 -07:00
Matthew Woodcraft
16c81fa9a6 Document the numeric value returned by string parsing for floats 2022-04-16 22:03:24 +01:00
Matthew Woodcraft
6fa061c5f9 Document rounding for floating-point primitive operations
State that the four primitive operations honour IEEE 754 roundTiesToEven.

Documenting under "Primitive Type f32"; f64 refers to that.
2022-04-16 21:58:36 +01:00
Giles Cope
bf02d1ea5f
No need to check the assert all the time. 2022-04-16 19:30:23 +01:00
Dylan DPC
4ed7627117
Rollup merge of #96081 - eduardosm:masks_usize_size_agnostic, r=yaahc
Make some `usize`-typed masks definitions agnostic to the size of `usize`

Some masks where defined as
```rust
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
```
where it was assumed that `usize` is never wider than 64, which is currently true.

To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way
```rust
const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]);
```

There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
2022-04-16 14:26:01 +02:00
Dylan DPC
bd007ba928
Rollup merge of #96038 - beyarkay:patch-1, r=m-ou-se
docs: add link from zip to unzip

The docs for `Iterator::unzip` explain that it is kind of an inverse operation to `Iterator::zip` and guide the reader to the `zip` docs, but the `zip` docs don't let the user know that they can undo the `zip` operation with `unzip`. This change modifies the docs to help the user find `unzip`.
2022-04-16 14:25:58 +02:00
Raekye
d5f96e6ade Change as_uninit_* methods on NonNull from taking self by
reference to taking `self` by value. This is consistent with the methods
of the same names on primitive pointers. The returned lifetime was
already previously unbounded.
2022-04-15 21:21:02 -04:00
ltdk
63a8652961 MaybeUninit array cleanup
* Links MaybeUninit::uninit_array to meta-tracking issue
* Links MaybeUninit::array_assume_init to meta-tracking issue
* Unstably constifies MaybeUninit::array_assume_init
2022-04-15 20:53:50 -04:00
Dylan DPC
20bf34f8c5
Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelix
Create (unstable) 2024 edition

[On Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Deprecating.20macro.20scoping.20shenanigans/near/272860652), there was a small aside regarding creating the 2024 edition now as opposed to later. There was a reasonable amount of support and no stated opposition.

This change creates the 2024 edition in the compiler and creates a prelude for the 2024 edition. There is no current difference between the 2021 and 2024 editions. Cargo and other tools will need to be updated separately, as it's not in the same repository. This change permits the vast majority of work towards the next edition to proceed _now_ instead of waiting until 2024.

For sanity purposes, I've merged the "hello" UI tests into a single file with multiple revisions. Otherwise we'd end up with a file per edition, despite them being essentially identical.

````@rustbot```` label +T-lang +S-waiting-on-review

Not sure on the relevant team, to be honest.
2022-04-15 20:50:43 +02:00
Dylan DPC
27e2d811e6
Rollup merge of #94457 - jhpratt:stabilize-derive_default_enum, r=davidtwco
Stabilize `derive_default_enum`

This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](https://github.com/rust-lang/rfcs/pull/3107) and tracked in #87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility).

```````@rustbot``````` label +S-waiting-on-review +T-lang
2022-04-15 20:50:43 +02:00
Eduardo Sánchez Muñoz
93ae6f80e3 Make some usize-typed masks definition agnostic to the size of usize
Some masks where defined as
```rust
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
```
where it was assumed that `usize` is never wider than 64, which is currently true.

To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way
```rust
const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]);
```

There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
2022-04-15 17:04:59 +02:00
Vadim Petrochenkov
7f3cc2fbbf library: Use type aliases to make CStr(ing) in libcore/liballoc unstable 2022-04-14 21:53:11 +03:00
Vadim Petrochenkov
5bee741a08 library: Move CStr to libcore, and CString to liballoc 2022-04-14 21:53:11 +03:00
Eduardo Sánchez Muñoz
2a91eeac1a Implement core::ptr::Unique on top of NonNull
Removes the use `rustc_layout_scalar_valid_range_start` and some `unsafe` blocks.
2022-04-14 19:35:40 +02:00
Boyd Kane
d73e32867f
Remove trailing whitespace
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-04-14 11:19:49 +02:00
Boyd Kane
f6d957701f
docs: add link from zip to unzip
The docs for `Iterator::unzip` explain that it is kind of an inverse operation to `Iterator::zip` and guide the reader to the `zip` docs, but the `zip` docs don't let the user know that they can undo the `zip` operation with `unzip`. This change modifies the docs to help the user find `unzip`.
2022-04-14 09:51:47 +02:00
Jacob Pratt
4fbe73e0b7
Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
Dylan DPC
e95f2db98f
Rollup merge of #96006 - hkBst:patch-2, r=Dylan-DPC
Add a missing article

Add a missing article
2022-04-13 17:35:37 +02:00
Marijn Schouten
c008d45187
Add a missing article
Add a missing article
2022-04-13 13:33:09 +02:00
Marijn Schouten
212e98bc3e
Add missing article to fix "few" to "a few".
Add missing article to fix "few" (not many) to "a few" (some).
2022-04-13 13:24:28 +02:00
Dylan DPC
633c391225
Rollup merge of #95984 - wcampbell0x2a:fix-spelling, r=thomcc
Fix spelling in docs for `can_not_overflow`

Introduced in https://github.com/rust-lang/rust/pull/95399
2022-04-13 05:54:13 +02:00
Dylan DPC
6aa875aa96
Rollup merge of #95914 - c410-f3r:meta-vars, r=petrochenkov
Implement tuples using recursion

Because it is c00l3r™, requires less repetition and can be used as a reference for external people.

This change is non-essential and I am not sure about potential performance impacts so feel free to close this PR if desired.

r? `@petrochenkov`
2022-04-12 23:16:58 +02:00
Caio
23bf977758 Implement tuples using recursion 2022-04-12 16:23:36 -03:00
wcampbell
9ea89e1d3d Fix spelling in docs for can_not_overflow 2022-04-12 13:29:56 -04:00
Jubilee Young
83581796b2 Ban subnormals and NaNs in const {from,to}_bits 2022-04-12 02:27:25 -07:00