Commit graph

149 commits

Author SHA1 Message Date
Camelid
5a307cf4bb
Fix intra-doc links
One of the original links was linking to the wrong thing as well.

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-20 12:39:12 -07:00
Camelid
22c02bfdb1
Revert to old link since intra-doc link is broken
Can't link from `core` to `std` yet.
2020-08-19 18:17:55 -07:00
Camelid
e0430a8aa2 Switch to intra-doc links in core::result 2020-08-19 14:02:34 -07:00
Tyler Mandry
4123237fa1
Rollup merge of #75648 - matklad:lazy-dropck, r=KodrAus
Make OnceCell<T> transparent to dropck

See the failed build in

https://github.com/rust-lang/rust/pull/75555#issuecomment-675016718

for an example where we need this in real life

r? @ghost
2020-08-19 11:12:20 -07:00
bors
11a44adc6f Auto merge of #75600 - nagisa:improve_align_offset, r=KodrAus
Improve codegen for `align_offset`

In this PR the `align_offset` implementation is changed/improved to produce better code in certain scenarios such as when pointer type is has a stride of 1 or when building for low optimisation levels.

While these changes do not achieve the "ideal" codegen referenced in #75579, it gets significantly closer to it. I’m not actually sure if the codegen can actually be much better with this function returning the offset, rather than the aligned pointer.

See the descriptions for separate commits for further information.
2020-08-19 10:54:44 +00:00
Yuki Okushi
ac264b53d1
Rollup merge of #75499 - jack-champagne:jack-champagne/issue-75412, r=Dylan-DPC
Fix documentation error

This should fix #75412. Just a quick >= to > sign replacement.
2020-08-19 15:54:28 +09:00
Yuki Okushi
1f4f31785e
Rollup merge of #75049 - janriemer:patch-1, r=poliorcetics
docs(marker/copy): provide example for `&T` being `Copy`

### Edited 2020-08-16 (most recent)
In the current documentation about the `Copy` marker trait, there is a section
with examples of structs that can implement `Copy`. Currently there is no example for
showing that shared references (`&T`) are also `Copy`.
It is worth to have a dedicated example for `&T` being `Copy`, because shared
references are an integral part of the language and it being `Copy` is not as
intuitive as other types that share this behaviour like `i32` or `bool`.

The example picks up on the previous non-`Copy` struct and shows that
structs can be `Copy`, even when they hold a shared reference to a non-`Copy` type.

-----------------------------------------
### Edited 2020-08-02, 3:28 p.m.
I've just realized that it says "in addition to the **implementors listed below**", which makes this PR kind of "wrong", because `&T` is indeed in the "implementors listed below".
Maybe we can instead show an example with `&T` in the [When can my type be Copy](https://doc.rust-lang.org/std/marker/trait.Copy.html#when-can-my-type-be-copy) section.

What I really want to achieve is that it becomes more obvious that `&T` is also `Copy`, because, I think, it is very valuable to know and it wasn't obvious for me, until I read something about it in a forum post.

What do you think? I would create another PR for that.
**Please feel free to close this PR.**

-----------------------------------
### Original post
In the current documentation about the `Copy` marker trait, there is a section
about "additional implementors", which list additional implementors of the `Copy` trait.
The fact that shared references are also `Copy` is mixed with another point,
which makes it hard to recognize and make it seem not as important.

This clarifies the fact that shared references are also `Copy`, by mentioning it as a
separate item in the list of "additional implementors".
2020-08-19 15:54:26 +09:00
Yuki Okushi
17d3ce457f
Rollup merge of #75038 - rust-lang:Havvy-patch-1, r=steveklabnik
See also X-Link mem::{swap, take, replace}

Since it's easy to end up at one of these functions when you really wanted the other one, cross link them with descriptions of why you'd want to use them.
2020-08-19 15:54:24 +09:00
Jan Riemer
522d177f34 docs: add another derive for Copyable struct
This adds another `derive` for a `Copy`able struct, so that we are
consistent with `derive` annotations.
2020-08-18 18:40:19 +02:00
Tim Diekmann
a9fe0ca47a Clean up AllocRef implementation and documentation 2020-08-18 09:53:22 +02:00
bors
515c9fa505 Auto merge of #75621 - TimDiekmann:no-fast-realloc, r=Amanieu
Remove fast path in reallocation for same layout sizes

r? @Amanieu

Before merging a perf-run should be done.

Closes https://github.com/rust-lang/wg-allocators/issues/70
2020-08-18 05:42:05 +00:00
Yuki Okushi
5498367faf
Rollup merge of #75392 - TimDiekmann:non-null-uninit-slice, r=RalfJung
Add `as_uninit`-like methods to pointer types and unify documentation of `as_ref` methods

This adds a convenient method to retrieve a `&(mut) [MaybeUninit<T>]` from slice pointers (`*const [T]`, `*mut [T]`, `NonNull<[T]>`). See also https://github.com/rust-lang/wg-allocators/issues/66#issuecomment-671789105.

~I'll add a tracking issue as soon as it's reviewed and CI passed.~
Tracking Issue: #75402

r? @RalfJung
2020-08-18 09:27:42 +09:00
Aleksey Kladov
695d86f584 Make OnceCell<T> transparent to dropck
See the failed build in

https://github.com/rust-lang/rust/pull/75555#issuecomment-675016718

for an example where we need this in real life
2020-08-18 00:34:54 +02:00
bors
792c645ca7 Auto merge of #75145 - davidtwco:issue-60607-preallocate-defid-for-lang-items, r=petrochenkov
Reference lang items during AST lowering

Fixes #60607 and fixes #61019.

This PR introduces `QPath::LangItem` to the HIR and uses it in AST lowering instead of constructing a `hir::Path` from a slice of symbols:

- Credit for much of this work goes to @matthewjasper, I basically just [rebased their earlier work](a227c706b7 (diff-c0f791ead38d2d02916faaad0f56f41d)).
- ~~Changes to Clippy might not be correct, they compile but attempting to run tests through `./x.py` produced failures which appeared spurious, so I didn't run any clippy tests.~~
- Changes to save analysis might not be correct - tests pass but I don't have a lot of confidence in those changes being correct.
- I've used `GenericBounds::LangItemTrait` rather than changing `PolyTraitRef`, as suggested by @matthewjasper [in this comment](a227c706b7 (r40107992)) but I'd prefer that be left for a follow-up.
- I've split things into smaller commits fairly arbitrarily to make the diff easier to review, each commit should compile but might not pass tests until the final commit.

r? @oli-obk
cc @matthewjasper
2020-08-17 20:51:59 +00:00
bors
e8df0b8932 Auto merge of #74940 - oli-obk:const_is_null, r=RalfJung
Make `<*const T>::is_null` const fn

r? @RalfJung

cc @rust-lang/wg-const-eval

tracking issue: #74939
2020-08-17 14:13:13 +00:00
Tim Diekmann
93e074bc8a Add as_uninit-like methods to pointer types and unify documentation of as_ref methods
Fix example in `NonNull::as_uninit_slice`


Rename feature gate to "ptr_as_uninit"


Make methods more consistent with already stable methods


Make `pointer::as_uninit_slice` return an `Option`


Fix placement for `// SAFETY` section


Add `as_uninit_ref` and `as_uninit_mut` to pointers


Fix doctest


Update tracking issue


Fix doc links


Apply suggestions from review


Make wording about counterparts consistent


Fix doc links


Improve documentation

Fix doc-tests


Fix doc links ... again


Apply suggestions from review


Apply suggestions from Review


Apply suggestion from review to all affected files


Add missing words in safety sections in `as_uninit_slice_mut`


Fix safety-comment in `NonNull::as_uninit_slice_mut`
2020-08-17 14:23:14 +02:00
Tim Diekmann
c619b36975 Remove fast path in reallocation for same layout sizes 2020-08-17 13:23:38 +02:00
bors
67e7b9b8cf Auto merge of #75535 - denisvasilik:intra-doc-links-any, r=jyn514
Move to intra-doc links for /library/core/src/any.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links, T-rustdoc

Known issues:

* Links from `core` to `std` (#74481):
    * `[Box]: ../../std/boxed/struct.Box.html`
2020-08-17 08:00:45 +00:00
bors
4bb4b96ee7 Auto merge of #74562 - pickfire:is_ascii_branchless, r=nagisa
Remove branch in optimized is_ascii

Performs slightly better in short or medium bytes by eliminating
the last branch check on `byte_pos == len` and always check the
last byte as it is always at most one `usize`.

Benchmark, before `libcore`, after `libcore_new`. It improves
medium and short by 1ns but regresses unaligned_tail by 2ns,
either way we can get unaligned_tail have a tiny chance of 1/8
on a 64 bit machine. I don't think we should bet on that, the
probability is worse than dice.

```
test long::case00_libcore                     ... bench:          38 ns/iter (+/- 1) = 183947 MB/s
test long::case00_libcore_new                 ... bench:          38 ns/iter (+/- 1) = 183947 MB/s
test long::case01_iter_all                    ... bench:         227 ns/iter (+/- 6) = 30792 MB/s
test long::case02_align_to                    ... bench:          40 ns/iter (+/- 1) = 174750 MB/s
test long::case03_align_to_unrolled           ... bench:          19 ns/iter (+/- 1) = 367894 MB/s
test medium::case00_libcore                   ... bench:           5 ns/iter (+/- 0) = 6400 MB/s
test medium::case00_libcore_new               ... bench:           4 ns/iter (+/- 0) = 8000 MB/s
test medium::case01_iter_all                  ... bench:          20 ns/iter (+/- 1) = 1600 MB/s
test medium::case02_align_to                  ... bench:           6 ns/iter (+/- 0) = 5333 MB/s
test medium::case03_align_to_unrolled         ... bench:           5 ns/iter (+/- 0) = 6400 MB/s
test short::case00_libcore                    ... bench:           7 ns/iter (+/- 0) = 1000 MB/s
test short::case00_libcore_new                ... bench:           6 ns/iter (+/- 0) = 1166 MB/s
test short::case01_iter_all                   ... bench:           5 ns/iter (+/- 0) = 1400 MB/s
test short::case02_align_to                   ... bench:           5 ns/iter (+/- 0) = 1400 MB/s
test short::case03_align_to_unrolled          ... bench:           5 ns/iter (+/- 1) = 1400 MB/s
test unaligned_both::case00_libcore           ... bench:           4 ns/iter (+/- 0) = 7500 MB/s
test unaligned_both::case00_libcore_new       ... bench:           4 ns/iter (+/- 0) = 7500 MB/s
test unaligned_both::case01_iter_all          ... bench:          26 ns/iter (+/- 0) = 1153 MB/s
test unaligned_both::case02_align_to          ... bench:          13 ns/iter (+/- 2) = 2307 MB/s
test unaligned_both::case03_align_to_unrolled ... bench:          11 ns/iter (+/- 0) = 2727 MB/s
test unaligned_head::case00_libcore           ... bench:           5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_head::case00_libcore_new       ... bench:           5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_head::case01_iter_all          ... bench:          19 ns/iter (+/- 1) = 1631 MB/s
test unaligned_head::case02_align_to          ... bench:          10 ns/iter (+/- 0) = 3100 MB/s
test unaligned_head::case03_align_to_unrolled ... bench:          14 ns/iter (+/- 0) = 2214 MB/s
test unaligned_tail::case00_libcore           ... bench:           3 ns/iter (+/- 0) = 10333 MB/s
test unaligned_tail::case00_libcore_new       ... bench:           5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_tail::case01_iter_all          ... bench:          19 ns/iter (+/- 0) = 1631 MB/s
test unaligned_tail::case02_align_to          ... bench:          10 ns/iter (+/- 0) = 3100 MB/s
test unaligned_tail::case03_align_to_unrolled ... bench:          13 ns/iter (+/- 0) = 2384 MB/s
```

Rough (unfair) maths on improvements for fun: 1ns * 7/8 - 2ns * 1/8 = 0.625ns

Inspired by fish and zsh clever trick to highlight missing linefeeds (⏎)
and branchless implementation of binary_search in rust.

cc @thomcc https://github.com/rust-lang/rust/pull/74066
r? @nagisa
2020-08-16 23:52:32 +00:00
Tyler Mandry
8ba56afcc6
Rollup merge of #75485 - RalfJung:pin, r=nagisa
pin docs: add some forward references

@nagisa had some questions about pinning that were answered in the docs, which they did not realize because that discussion is below the examples. I still think it makes sense to introduce the examples before that discussion, since it give the discussion something concrete to refer to, but this PR adds some forward references so people don't think the examples conclude the docs.

@nagisa do you think this would have helped?
2020-08-16 14:59:32 -07:00
Tyler Mandry
18e3799dc8
Rollup merge of #75423 - denisvasilik:intra-doc-links-core-hint, r=dtolnay
Move to intra-doc links for /library/core/src/hint.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links, T-rustdoc
2020-08-16 14:59:30 -07:00
Jan Riemer
56daf63d10
docs: add derive for struct
Code blocks in doc comments are compiled and run, so we show `Copy` works in this example.

Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2020-08-16 22:25:59 +02:00
Jan Riemer
9061da2e14
add empty line above code block
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2020-08-16 22:15:59 +02:00
Jan Riemer
dce864454c add back emojis that have been removed accidentally
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-16 20:48:44 +02:00
Simonas Kazlauskas
5d22b18bf2 Improve codegen of align_offset when stride == 1
Previously checking for `pmoda == 0` would get LLVM to generate branchy
code, when, for `stride = 1` the offset can be computed without such a
branch by doing effectively a `-p % a`.

For well-known (constant) alignments, with the new ordering of these
conditionals, we end up generating 2 to 3 cheap instructions on x86_64:

    movq    %rdi, %rax
    negl    %eax
    andl    $7, %eax

instead of 5+ as previously.

For unknown alignments the new code also generates just 3 instructions:

    negq    %rdi
    leaq    -1(%rsi), %rax
    andq    %rdi, %rax
2020-08-16 21:31:48 +03:00
Simonas Kazlauskas
e7271da69a Improve align_offset at opt-level <= 1
At opt-level <= 1, the methods such as `wrapping_mul` are not being
inlined, causing significant bloating and slowdowns of the
implementation at these optimisation levels.

With use of these intrinsics, the codegen of this function at
-Copt_level=1 is the same as it is at -Copt_level=3.
2020-08-16 21:31:48 +03:00
Jan Riemer
43dec0e171
rephrase: struct -> type
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-16 20:17:28 +02:00
Jan Riemer
a876b3d8aa
docs(marker/copy): provide example for &T being Copy
In the current documentation about the `Copy` marker trait, there is a section
with examples of structs that can implement `Copy`. Currently there is no example for
showing that shared references (`&T`) are also `Copy`.
It is worth to have a dedicated example for `&T` being `Copy`, because shared
references are an integral part of the language and it being `Copy` is not as
intuitive as other types that share this behaviour like `i32` or `bool`.

The example picks up on the previous non-`Copy` struct and shows that
structs can be `Copy`, even when they hold a shared reference to a non-`Copy` type.
2020-08-16 20:03:34 +02:00
David Wood
7dee5f824d
hir: introduce lang items for AST lowering
This commit adds new lang items which will be used in AST lowering once
`QPath::LangItem` is introduced.

Co-authored-by: Matthew Jasper <mjjasper1@gmail.com>
Signed-off-by: David Wood <david@davidtw.co>
2020-08-16 15:42:23 +01:00
bors
243c725c24 Auto merge of #75561 - kornelski:stringcol, r=Dylan-DPC
Doc: String isn't a collection

On forums one user was confused by this text, interpreting it as saying that `String` is a `Vec<char>` literally, rather than figuratively for the purpose of collect. I've reworded that paragraph.
2020-08-16 06:26:38 +00:00
bors
9d38dc22e5 Auto merge of #75553 - denisvasilik:intra-doc-links-convert, r=jyn514
Move to intra-doc links for /library/core/src/char/convert.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links, T-rustdoc
2020-08-16 04:31:05 +00:00
bors
86bccb684d Auto merge of #75541 - camelid:intra-doc-links-for-core-option, r=jyn514
Switch to intra-doc links in `core::option`

Part of #75080.

I didn't change some of the links since they link into `std` and you can't link from `core` to `std` (#74481).

Also, at least one other link can't be switched to an intra-doc link because it's not supported yet (#74489).
2020-08-16 02:39:21 +00:00
Denis Vasilik
14b50ede7d Link to primitive instead of module 2020-08-15 19:27:34 +02:00
Kornel Lesiński
d5cb5eb08b Doc: String isn't a collection 2020-08-15 17:55:10 +01:00
Camelid
8227b3b0b2
Remove unnecessary intra-doc link
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-15 09:52:35 -07:00
Camelid
b02c4049cb
Fix link
Intra-doc links don't work yet in this case: #74489
2020-08-15 09:31:14 -07:00
Denis Vasilik
ebcb99ef8f Use intra-doc links 2020-08-15 01:12:47 +02:00
Camelid
b1c05c5c2b Switch to intra-doc links in core::option 2020-08-14 16:11:43 -07:00
Tyler Mandry
ad8c5e1480
Rollup merge of #75214 - chansuke:fix-intra-doc-links, r=jyn514
Use intra-doc links in `mem::manually_drop` & `mem::maybe_uninit`

This is partial fixes for https://github.com/rust-lang/rust/issues/75080.
2020-08-14 14:46:47 -07:00
Denis Vasilik
75c1e2dfbb Use intra-doc links 2020-08-14 20:50:38 +02:00
chansuke
61866bc60c Use intra-doc links in mem::manually_drop & mem::maybe_uninit 2020-08-15 02:33:39 +09:00
bors
55b9adfafa Auto merge of #75157 - rodrimati1992:patch-1, r=oli-obk
Constified str::from_utf8_unchecked

This would be useful for const code to use an array to construct a string using guaranteed utf8 inputs, and then create a `&str` from it.
2020-08-14 14:08:05 +00:00
Jack Champagne
9b0f3d1266 Fix documentation error 2020-08-13 16:58:50 -04:00
rodrimati1992
18377082f1
Fixed transmute argument 2020-08-13 16:08:22 -03:00
rodrimati1992
1767c8bdf0
Replaced union with transmute 2020-08-13 15:56:23 -03:00
Ralf Jung
7aac3e0400 pin docs: add some forward references 2020-08-13 14:41:04 +02:00
kadmin
af32db21c8 Add drop check test & MaybeUninit::first_ptr_mut
Also in drop check test add hacky workaround for platforms that don't support
panic=unwind
2020-08-13 03:51:08 +00:00
kadmin
412417d807 Rm hiding feature gate & add 1 more example
Update order docs for `map`
2020-08-13 03:51:05 +00:00
kadmin
54b821ebc0 Add tracking issue #75243
Add note & example about iter order

Add doc changes

Update doc comments
2020-08-13 03:51:01 +00:00
kadmin
56a651ca15 Add recommend changes to array
Switch from indexing to zip, and also use `write` on `MaybeUninit`.

Add array_map feature to core/src/lib

Attempt to fix issue of no such feature

Update w/ pickfire's review

This changes a couple of names around, adds another small test of variable size,
and hides the rustdoc #![feature(..)].

Fmt doctest

Add suggestions from lcnr
2020-08-13 03:50:59 +00:00