Commit graph

1777 commits

Author SHA1 Message Date
Yuki Okushi 73d0340fd5
Rollup merge of #78554 - camelid:improve-drop_in_place-docs-wording, r=jyn514
Improve wording of `core::ptr::drop_in_place` docs

And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-30 18:00:58 +09:00
Yuki Okushi 02a4b58a3f
Rollup merge of #77921 - wcampbell0x2a:f64-collapsible-if, r=jyn514
f64: Refactor collapsible_if
2020-10-30 18:00:49 +09:00
Yuki Okushi 0723b274d2
Rollup merge of #77334 - pickfire:patch-4, r=jyn514
Reorder benches const variable

Move LEN so it is is read in order.
2020-10-30 18:00:41 +09:00
Camelid fee4f8feb0 Improve wording of core::ptr::drop_in_place docs
And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-29 20:09:29 -07:00
Jonas Schievink 48c4afbf9c
Rollup merge of #78499 - SkiFire13:fix-string-retain, r=m-ou-se
Prevent String::retain from creating non-utf8 strings when abusing panic

Fixes #78498

The idea is the same as `Vec::drain`, set the len to 0 so that nobody can observe the broken invariant if it escapes the function (in this case if `f` panics)
2020-10-29 17:05:28 +01:00
Jonas Schievink a384a5866b
Rollup merge of #76138 - camelid:rc-fully-qualified-syntax, r=steveklabnik
Explain fully qualified syntax for `Rc` and `Arc`

Also cleaned up some other small things.

@rustbot modify labels: T-doc
2020-10-29 17:05:08 +01:00
Jonas Schievink 2168210961
Rollup merge of #75078 - ijackson:slice-strip, r=steveklabnik
Improve documentation for slice strip_* functions

Prompted by the stabilisation tracking issue #73413 I looked at the docs for `strip_prefix` and `strip_suffix` for both `str` and `slice`, and I felt they could be slightly improved.

Thanks for your attention.
2020-10-29 17:05:00 +01:00
bors a53fb30e3b Auto merge of #78446 - RalfJung:box, r=Amanieu
fix Box::into_unique

https://github.com/rust-lang/rust/pull/77187/ broke Stacked Borrows pointer tagging around `Box::into_unique` (this is caused by `Box` being a special case in the type system, which box-internal code needs to account for). This PR fixes that.

r? `@Amanieu` Cc `@TimDiekmann`

Fixes https://github.com/rust-lang/rust/issues/78419.
2020-10-29 12:08:16 +00:00
Giacomo Stevanato 1f6f917f73 Added test for issue #78498 2020-10-29 12:25:02 +01:00
Giacomo Stevanato e83666f45e Prevent String::retain from creating non-utf8 strings when abusing panic 2020-10-29 11:58:12 +01:00
Yuki Okushi c7792230c0
Rollup merge of #78491 - petertodd:2020-inline-from-nonzero, r=sfackler
Inline NonZeroN::from(n)

Currently this results in the generated assembly having a function call for this trivial conversion.
2020-10-29 12:08:59 +09:00
Yuki Okushi 7eb7b5a4af
Rollup merge of #78470 - camelid:fixup-std-path-intra-doc, r=jyn514
Clean up intra-doc links in `std::path`
2020-10-29 12:08:53 +09:00
Camelid 4e30e10f25 Don't say you "should" use fully qualified syntax
That recommendation was removed last year; there isn't a particular
style that is officially recommended anymore.
2020-10-28 16:49:30 -07:00
Camelid e0eed3c558 Fix broken intra-doc link 2020-10-28 16:31:45 -07:00
Camelid bd7cbaecd3 Explain fully qualified syntax for Rc and Arc 2020-10-28 16:31:44 -07:00
Peter Todd 061715604a
Inline NonZeroN::from(n) 2020-10-28 13:26:44 -04:00
Camelid 0217edbd29
Clean up intra-doc links in std::path 2020-10-27 20:54:30 -07:00
bors db241bb0c8 Auto merge of #78458 - Dylan-DPC:rollup-tan044s, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #78152 (Separate unsized locals)
 - #78297 (Suggest calling await on method call and field access)
 - #78351 (Move "mutable thing in const" check from interning to validity)
 - #78365 (check object safety of generic constants)
 - #78379 (Tweak invalid `fn` header and body parsing)
 - #78391 (Add const_fn in generics test)
 - #78401 (resolve: private fields in tuple struct ctor diag)
 - #78408 (Remove tokens from foreign items in `TokenStripper`)
 - #78447 (Fix typo in  comment)
 - #78453 (Fix typo in comments)

Failed merges:

r? `@ghost`
2020-10-28 01:40:06 +00:00
Dylan DPC 346aeef496
Rollup merge of #78152 - spastorino:separate-unsized-locals, r=oli-obk
Separate unsized locals

Closes #71694

Takes over again #72029 and #74971

cc @RalfJung @oli-obk @pnkfelix @eddyb as they've participated in previous reviews of this PR.
2020-10-28 01:21:08 +01:00
bors 90e6d0d46b Auto merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obk
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc

The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc.
The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that.

(cc #53224).

r? `@oli-obk`
2020-10-27 22:59:13 +00:00
Santiago Pastorino ba59aa2b77
Do not depend on except for bootstrap 2020-10-27 14:45:36 -03:00
Santiago Pastorino 708fc3b1a2
Add unsized_fn_params feature 2020-10-27 14:45:02 -03:00
Ralf Jung ab374dc37c fix Box::into_unique 2020-10-27 17:02:42 +01:00
Ayrton 511fe048b4 Changed lint to check for std::fmt::Pointer and transmute
The lint checks arguments in calls to `transmute` or functions that have
`Pointer` as a trait bound and displays a warning if the argument is a function
reference. Also checks for `std::fmt::Pointer::fmt` to handle formatting macros
although it doesn't depend on the exact expansion of the macro or formatting
internals. `std::fmt::Pointer` and `std::fmt::Pointer::fmt` were also added as
diagnostic items and symbols.
2020-10-27 11:04:04 -04:00
bors 56d288fa46 Auto merge of #78227 - SergioBenitez:test-stdout-threading, r=m-ou-se
Capture output from threads spawned in tests

This is revival of #75172.

Original text:
> Fixes #42474.
>
> r? `@​dtolnay` since you expressed interest in this, but feel free to redirect if you aren't the right person anymore.

---

Closes #75172.
2020-10-27 11:43:18 +00:00
bors c9b606ed67 Auto merge of #78359 - ssomers:btree_cleanup_mem, r=Mark-Simulacrum
BTreeMap: move generic support functions out of navigate.rs

A preparatory step chipped off #78104, useful in general (if at all).

r? `@Mark-Simulacrum`
2020-10-27 04:01:52 +00:00
Nathan Whitaker 39941e6281 Fix bootstrap doctest failure 2020-10-26 22:09:47 -04:00
Yuki Okushi 4236d27c9b
Rollup merge of #78412 - camelid:cleanup-hash-docs, r=jonas-schievink
Improve formatting of hash collections docs
2020-10-27 08:45:30 +09:00
Yuki Okushi f6f8764b25
Rollup merge of #78394 - rubik:master, r=m-ou-se
fix(docs): typo in BufWriter documentation

This PR fixes a small typo in the BufWriter documentation. The current documentation looks like this:

![2020-10-26-111501_438x83_scrot](https://user-images.githubusercontent.com/238549/97160357-83d3a000-177c-11eb-8a35-3cdd3a7d89de.png)

The `<u8>` at the end is mangled by Markdown. This PR makes the `BufWriter` documentation like the `BufReader` one:

https://github.com/rust-lang/rust/blob/master/library/std/src/io/buffered/bufreader.rs#L16

I'm tagging Steve as per the Rustc dev guide.

r? @steveklabnik
2020-10-27 08:45:20 +09:00
Yuki Okushi 5a33fa5179
Rollup merge of #78375 - taiki-e:question-in-macros, r=kennytm
Use ? in core/std macros
2020-10-27 08:45:10 +09:00
Yuki Okushi 727e93dc74
Rollup merge of #78347 - Rustin-Liu:rustin-patch-doc, r=kennytm
Add lexicographical comparison doc

close https://github.com/rust-lang/rust/issues/72255
2020-10-27 08:45:01 +09:00
Yuki Okushi 2c307fab49
Rollup merge of #77703 - Keruspe:system-libunwind, r=Mark-Simulacrum
add system-llvm-libunwind config option

allows using the system-wide llvm-libunwind as the unwinder

Workaround for #76020
2020-10-27 08:44:44 +09:00
Yuki Okushi 13e88d6366
Rollup merge of #76635 - scottmcm:slice-as-chunks, r=LukasKalbertodt
Add [T]::as_chunks(_mut)

Allows getting the slices directly, rather than just through an iterator as in `array_chunks(_mut)`.  The constructors for those iterators are then written in terms of these methods, so the iterator constructors no longer have any `unsafe` of their own.

Unstable, of course. #74985
2020-10-27 08:44:41 +09:00
Nathan Whitaker cb8b9012db Address review comments 2020-10-26 19:19:06 -04:00
Nathan Whitaker 1bcd2452fe Address review comments 2020-10-26 18:19:48 -04:00
Nathan Whitaker 737bfeffd2 Change to warn by default / fix typo 2020-10-26 18:19:48 -04:00
Nathan Whitaker ce95122e95 Update doctest 2020-10-26 18:19:47 -04:00
bors fd542592f0 Auto merge of #77187 - TimDiekmann:box-alloc, r=Amanieu
Support custom allocators in `Box`

r? `@Amanieu`

This pull request requires a crater run.

### Prior work:
- #71873
- #58457
- [`alloc-wg`](https://github.com/TimDiekmann/alloc-wg)-crate

Currently blocked on:
- ~#77118~
- ~https://github.com/rust-lang/chalk/issues/615 (#77515)~
2020-10-26 21:16:33 +00:00
Camelid 59f108885e Improve formatting of hash collections docs 2020-10-26 14:05:06 -07:00
Rustin-Liu 42844ed2cf Add lexicographical comparison doc
Add links

Fix typo

Use `sequence`

Fix typo

Fix broken link

Fix broken link

Fix broken link

Fix broken links

Fix broken links
2020-10-26 22:39:43 +08:00
Michele Lacchia a4ba179bdd
fix(docs): typo in BufWriter documentation 2020-10-26 11:13:47 +01:00
Stein Somers 0da7941e1c BTreeMap: move generic functions out of navigate.rs 2020-10-26 09:31:36 +01:00
bors 69e68cf550 Auto merge of #75728 - nagisa:improve_align_offset_2, r=Mark-Simulacrum
Optimise align_offset for stride=1 further

`stride == 1` case can be computed more efficiently through `-p (mod
a)`. That, then translates to a nice and short sequence of LLVM
instructions:

    %address = ptrtoint i8* %p to i64
    %negptr = sub i64 0, %address
    %offset = and i64 %negptr, %a_minus_one

And produces pretty much ideal code-gen when this function is used in
isolation.

Typical use of this function will, however, involve use of
the result to offset a pointer, i.e.

    %aligned = getelementptr inbounds i8, i8* %p, i64 %offset

This still looks very good, but LLVM does not really translate that to
what would be considered ideal machine code (on any target). For example
that's the codegen we obtain for an unknown alignment:

    ; x86_64
    dec     rsi
    mov     rax, rdi
    neg     rax
    and     rax, rsi
    add     rax, rdi

In particular negating a pointer is not something that’s going to be
optimised for in the design of CISC architectures like x86_64. They
are much better at offsetting pointers. And so we’d love to utilize this
ability and produce code that's more like this:

    ; x86_64
    lea     rax, [rsi + rdi - 1]
    neg     rsi
    and     rax, rsi

To achieve this we need to give LLVM an opportunity to apply its
various peep-hole optimisations that it does during DAG selection. In
particular, the `and` instruction appears to be a major inhibitor here.
We cannot, sadly, get rid of this load-bearing operation, but we can
reorder operations such that LLVM has more to work with around this
instruction.

One such ordering is proposed in #75579 and results in LLVM IR that
looks broadly like this:

    ; using add enables `lea` and similar CISCisms
    %offset_ptr = add i64 %address, %a_minus_one
    %mask = sub i64 0, %a
    %masked = and i64 %offset_ptr, %mask
    ; can be folded with `gepi` that may follow
    %offset = sub i64 %masked, %address

…and generates the intended x86_64 machine code.
One might also wonder how the increased amount of code would impact a
RISC target. Turns out not much:

    ; aarch64 previous                 ; aarch64 new
    sub     x8, x1, #1                 add     x8, x1, x0
    neg     x9, x0                     sub     x8, x8, #1
    and     x8, x9, x8                 neg     x9, x1
    add     x0, x0, x8                 and     x0, x8, x9

    (and similarly for ppc, sparc, mips, riscv, etc)

The only target that seems to do worse is… wasm32.

Onto actual measurements – the best way to evaluate snipets like these
is to use llvm-mca. Much like Aarch64 assembly would allow to suspect,
there isn’t any performance difference to be found. Both snippets
execute in same number of cycles for the CPUs I tried. On x86_64,
we get throughput improvement of >50%!

Fixes #75579
2020-10-26 06:49:34 +00:00
Dylan DPC 147a001fd3
Rollup merge of #78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisa
Properly define va_arg and va_list for aarch64-apple-darwin

From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26 03:09:00 +01:00
Dylan DPC 9885232019
Rollup merge of #77836 - RalfJung:transmute_copy, r=Mark-Simulacrum
transmute_copy: explain that alignment is handled correctly

The doc comment currently is somewhat misleading because if it actually transmuted `&T` to `&U`, a higher-aligned `U` would be problematic.
2020-10-26 03:08:58 +01:00
Dylan DPC e0c08ae4e1
Rollup merge of #74477 - chansuke:sys-wasm-unsafe-op-in-unsafe-fn, r=Mark-Simulacrum
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm

This is part of #73904.

This encloses unsafe operations in unsafe fn in `libstd/sys/wasm`.

@rustbot modify labels: F-unsafe-block-in-unsafe-fn
2020-10-26 03:08:56 +01:00
Jake Goulding 0a91755ff4 Properly define va_arg and va_list for aarch64-apple-darwin
From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-25 21:37:01 -04:00
bors b6ac411f45 Auto merge of #78015 - ssomers:btree_merge_mergers, r=Mark-Simulacrum
btree: merge the implementations of MergeIter

Also remove the gratuitous Copy bounds. Same benchmark performance.

r? `@Mark-Simulacrum`
2020-10-25 22:29:02 +00:00
Taiki Endo 04c0018d1b Use ? in core/std macros 2020-10-26 07:15:37 +09:00
Tim Diekmann 06e4497a04 Merge remote-tracking branch 'upstream/master' into box-alloc 2020-10-25 16:32:28 +01:00