Commit graph

150004 commits

Author SHA1 Message Date
Mara Bos
a5dce6c99a
Rollup merge of #86357 - de-vri-es:simplify-repeated-cfg-ifs, r=m-ou-se
Rely on libc for correct integer types in os/unix/net/ancillary.rs.

This PR is a small maintainability improvement. It simplifies `unix/net/ancillary.rs` in `std` by removing the `cfg_ifs` for casting to the correct integer type, and just rely on libc to define the struct correctly.
2021-06-17 23:41:00 +02:00
Mara Bos
b7dd942e15
Rollup merge of #86202 - a1phyr:spec_io_bytes_size_hint, r=m-ou-se
Specialize `io::Bytes::size_hint` for more types

Improve the result of `<io::Bytes as Iterator>::size_hint` for some readers. I did not manage to specialize `SizeHint` for `io::Cursor`

Side question: would it be interesting for `io::Read` to have an optional `size_hint` method ?
2021-06-17 23:40:58 +02:00
Mara Bos
fcac478966
Rollup merge of #85925 - clarfonthey:lerp, r=m-ou-se
Linear interpolation

#71016 is a previous attempt at implementation that was closed by the author. I decided to reuse the feature request issue (#71015) as a tracking issue. A member of the rust-lang org will have to edit the original post to be formatted correctly as I am not the issue's original author.

The common name `lerp` is used because it is the term used by most code in a wide variety of contexts; it also happens to be the recently chosen name of the function that was added to C++20.

To ensure symmetry as a method, this breaks the usual ordering of the method from `lerp(a, b, t)` to `t.lerp(a, b)`. This makes the most sense to me personally, and there will definitely be discussion before stabilisation anyway.

Implementing lerp "correctly" is very dififcult even though it's a very common building-block used in all sorts of applications. A good prior reading is [this proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0811r2.html#linear-interpolation) for the C++20 lerp which talks about the various guarantees, which I've simplified down to:

1. Exactness: `(0.0).lerp(start, end) == start` and `(1.0).lerp(start, end) == end`
2. Consistency: `anything.lerp(x, x) == x`
3. Monotonicity: once you go up don't go down

Fun story: the version provided in that proposal, from what I understand, isn't actually monotonic.

I messed around with a *lot* of different lerp implementations because I kind of got a bit obsessed and I ultimately landed on one that uses the fused `mul_add` instruction. Floating-point lerp lore is hard to come by, so, just trust me when I say that this ticks all the boxes. I'm only 90% certain that it's monotonic, but I'm sure that people who care deeply about this will be there to discuss before stabilisation.

The main reason for using `mul_add` is that, in general, it ticks more boxes with fewer branches to be "correct." Although it will be slower on architectures without the fused `mul_add`, that's becoming more and more rare and I have a feeling that most people who will find themselves needing `lerp` will also have an efficient `mul_add` instruction available.
2021-06-17 23:40:57 +02:00
bors
e062e5d34e Auto merge of #83572 - pkubaj:patch-1, r=nagisa
Add support for powerpc64le-unknown-freebsd
2021-06-17 18:06:44 +00:00
bors
4d3ce2e7da Auto merge of #86399 - JohnTitor:rollup-qlm2dvz, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #85663 (Document Arc::from)
 - #85802 (Rename IoSlice(Mut)::advance to advance_slice and add IoSlice(Mut)::advance)
 - #85970 (Remove methods under Implementors on trait pages)
 - #86340 (Use better error message for hard errors in CTFE)
 - #86343 (Do not emit invalid suggestions on multiple mutable borrow errors)
 - #86355 (Remove invalid suggestions for assoc consts on placeholder type error)
 - #86389 (Make `sum()` and `product()` documentation hyperlinks refer to `Iterator` methods.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-06-17 15:12:56 +00:00
Maarten de Vries
259bf5f47a Rely on libc for correct integer types in os/unix/net/ancillary.rs. 2021-06-17 15:56:47 +02:00
Yuki Okushi
65d412b637
Rollup merge of #86389 - kpreid:sum, r=scottmcm
Make `sum()` and `product()` documentation hyperlinks refer to `Iterator` methods.

The previous linking seemed confusing: within "the sum() method on iterators", "sum()" was linked to `Sum::sum`, not `Iterator::sum`, even though the sentence is talking about the latter. I have rewritten the sentence to be, I believe, clearer, as well as changing the link destinations; applying the same change to the `Product` documentation as well as `Sum`.

I reviewed other traits in the same module and did not see similar issues, and previewed the results using `./x.py doc library/std`.
2021-06-17 21:56:46 +09:00
Yuki Okushi
aff7994740
Rollup merge of #86355 - JohnTitor:issue-82158, r=estebank
Remove invalid suggestions for assoc consts on placeholder type error

Fixes #82158
This also moves some tests to typeck.
r? ``@estebank``
2021-06-17 21:56:45 +09:00
Yuki Okushi
afe70ee440
Rollup merge of #86343 - JohnTitor:issue-85581, r=estebank
Do not emit invalid suggestions on multiple mutable borrow errors

Fixes #85581
2021-06-17 21:56:44 +09:00
Yuki Okushi
c062f3dddd
Rollup merge of #86340 - Smittyvb:ctfe-hard-error-message, r=RalfJung
Use better error message for hard errors in CTFE

I noticed this while working on #86255: currently the same message is used for hard errors and soft errors in CTFE. This changes the error messages to make hard errors use a message that indicates the reality of the situation correctly, since usage of the constant is never allowed when there was a hard error evaluating it. This doesn't affect the behaviour of these error messages, only the content.

This changes the error logic to check if the error should be hard or soft where it is generated, instead of where it is emitted, to allow this distinction in error messages.
2021-06-17 21:56:43 +09:00
Yuki Okushi
9521da7179
Rollup merge of #85970 - jsha:remove-methods-implementors, r=GuillaumeGomez
Remove methods under Implementors on trait pages

As discussed at https://github.com/rust-lang/rust/issues/84326#issuecomment-842652412.

On a trait page, the "Implementors" section currently lists all methods of each implementor. That duplicates the method definitions on the trait itself, and is usually not very useful. So the implementors are collapsed by default. This PR changes rustdoc to just not render them at all. Any documentation specific to an implementor can be found by clicking through to the implementor's page.

This moves the "portability" info inside the `<summary>` tags so it is still visible on trait pages (as originally implemented in #79201). That also means it will be visible on struct/enum pages when methods are collapsed.

Add `#[doc(hidden)]` to all implementations of `Iterator::__iterator_get_unchecked` that didn't already have it. Otherwise, due to #86145, the structs/enums with those implementations would generate documentation for them, and that documentation would have a broken link into the Iterator page. Those links were already "broken" but not detected by the link-checker, because they pointed to one of the Implementors on the Iterator page, which happened to have the right anchor name.

This reduces the Read trait's page size from 128kB to 68kB (uncompressed) and from 12,125 bytes to 9,989 bytes (gzipped
Demo:

https://hoffman-andrews.com/rust/remove-methods-implementors/std/string/struct.String.html#trait-implementations
https://hoffman-andrews.com/rust/remove-methods-implementors/std/io/trait.Read.html#implementors

r? `@GuillaumeGomez`
2021-06-17 21:56:42 +09:00
Yuki Okushi
31ee68067e
Rollup merge of #85802 - Thomasdezeeuw:ioslice-advance, r=m-ou-se
Rename IoSlice(Mut)::advance to advance_slice and add IoSlice(Mut)::advance

Also changes the signature of `advance_slice` to accept a `&mut &mut [IoSlice]`, not returning anything. This will better match the `IoSlice::advance` function.

Updates https://github.com/rust-lang/rust/issues/62726.
2021-06-17 21:56:41 +09:00
Yuki Okushi
36b9a6ee73
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
Document Arc::from
2021-06-17 21:56:39 +09:00
bors
0ef2b4a29b Auto merge of #85755 - b-naber:unexpected_concrete_region, r=nikomatsakis
Replace parent substs of associated types with inference vars in borrow checker

Fixes https://github.com/rust-lang/rust/issues/83190
Fixes https://github.com/rust-lang/rust/issues/78450

When we normalize an associated type that refers to an opaque type, it can happen that the substs of the associated type do not occur in the projection (they are parent substs). We previously didn't replace those substs with inference vars, which left a concrete region after all regions should have already been replaced with inference vars and triggered a `delay_span_bug`. After we normalize the opaque type, we now try to replace any remaining concrete regions with inference vars.
2021-06-17 12:31:56 +00:00
Mara Bos
5e7a8c6eb1
Fix typos in code examples. 2021-06-17 12:13:06 +02:00
Niko Matsakis
09eed2889a use to_region_vid in opaque type code
Normalization can pull in named regions from the parameter
environment. We need to be prepared for that in the opaque
types code.
2021-06-17 05:22:04 -04:00
bors
b17d9c1332 Auto merge of #85834 - cjgillot:save-sbi, r=michaelwoerister
Encode CrateNum using the StableCrateId for incr. comp.
2021-06-17 09:03:58 +00:00
bors
cb3c4ee718 Auto merge of #86164 - FabianWolff:issue-86053, r=davidtwco
Handle C-variadic arguments properly when reporting region errors

This pull request fixes #86053. The issue is that for a C-variadic function
```rust
#![feature(c_variadic)]
unsafe extern "C" fn foo(_: (), ...) {}
```
`foo`'s signature will contain only the first parameter (and have `c_variadic` set to `true`), whereas its body has a second argument (a `hir::Pat` for the `...`).

The code for reporting region errors iterates over the body's parameters and tries to fetch the corresponding parameter from the signature; this causes an out-of-bounds ICE for the `...` (though not in the example above, because there are no region errors to report).

I have simply restricted the iteration over the body parameters to exclude `...`, which is fine because `...` cannot cause a region error.
2021-06-17 06:34:12 +00:00
Jacob Hoffman-Andrews
bf81e139af Restore details for Impls on Foreign Types
These were previously removed along with the details in the
"Implementors" section of trait pages. But for "Implementations on
Foreign Types," we need to include the details because they will not be
documented anywhere else.
2021-06-16 22:48:31 -07:00
Jacob Hoffman-Andrews
2ac5c1721a Fix target highlighting in rustdoc.
Also factor out outer_version and const_outer_version into
render_rightside.
2021-06-16 22:48:23 -07:00
Jacob Hoffman-Andrews
c4fa6d5827 Move anchor earlier in the DOM for easier layout 2021-06-16 22:47:46 -07:00
Jacob Hoffman-Andrews
5de1391b88 Factor out render_rightside
This covers rendering of stability_since and the srclink across methods
and trait implementations, so their DOM representation is consistent.
2021-06-16 22:46:53 -07:00
Jacob Hoffman-Andrews
593d6d1cb1 Make portability part of the summary.
That means it will be visible under "Implementors" on trait pages, and
under "Implementations" on struct/enum pages, even when all methods are
collapsed.

Switch to a float layout for rightside elements.
2021-06-16 22:20:25 -07:00
Jacob Hoffman-Andrews
910c7fa767 Add doc(hidden) to all __iterator_get_unchecked
This method on the Iterator trait is doc(hidden), and about half of
implementations were doc(hidden). This adds the attribute to the
remaining implementations.
2021-06-16 22:08:44 -07:00
Jacob Hoffman-Andrews
bff4f073c8 Use render_impl_summary when rendering traits. 2021-06-16 22:08:44 -07:00
Jacob Hoffman-Andrews
ce6472987d Remove methods under Implementors on trait pages
These were hidden by default, and duplicated information already on the
page anyhow.

Also remove the "Auto-hide trait implementors of a trait" setting,
which is not needed anymore.
2021-06-16 22:08:36 -07:00
bors
50a407200b Auto merge of #86380 - cuviper:1.53-compat-bits, r=Mark-Simulacrum
Add a compatibility note for BITS in 1.53

Closes #85667
r? `@Mark-Simulacrum`
2021-06-17 01:12:30 +00:00
Kevin Reid
cb2f8d9b02 Make sum() and product() hyperlinks refer to Iterator methods.
The previous linking seemed confusing: within "the sum() method on
iterators", "sum()" was linked to `Sum::sum`, not `Iterator::sum`, even
though the sentence is talking about the latter.

I have rewritten the sentence to be, I believe, clearer, as well as
changing the link destinations; applying the same change to the
`Product` documentation as well as `Sum`.
2021-06-16 17:52:33 -07:00
bors
444a85ac38 Auto merge of #86379 - JohnTitor:rollup-mkz9x36, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #85870 (Allow whitespace in dump_mir filter)
 - #86104 (Fix span calculation in format strings)
 - #86140 (Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`)
 - #86141 (Link reference in `dyn` keyword documentation)
 - #86260 (Open trait implementations' toggles by default.)
 - #86339 (Mention #79078 on compatibility notes of 1.52)
 - #86341 (Stop returning a value from `report_assert_as_lint`)
 - #86353 (Remove `projection_ty_from_predicates`)
 - #86361 (Add missing backslashes to prevent unwanted newlines in rustdoc HTML)
 - #86372 (Typo correction: s/is/its)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-06-16 22:48:31 +00:00
Smitty
044b3620e7 Move some hard error logic to InterpError 2021-06-16 18:23:34 -04:00
Josh Stone
fded947257 Add a compatibility note for BITS in 1.53 2021-06-16 14:04:33 -07:00
Yuki Okushi
27d5426bcf
Rollup merge of #86372 - snoyberg:patch-1, r=jonas-schievink
Typo correction: s/is/its
2021-06-17 05:55:02 +09:00
Yuki Okushi
129723553b
Rollup merge of #86361 - GuillaumeGomez:missing-backslashes, r=jsha
Add missing backslashes to prevent unwanted newlines in rustdoc HTML

Just adding some forgotten backslashes.

r? `@jsha`
2021-06-17 05:55:01 +09:00
Yuki Okushi
05ba958fe8
Rollup merge of #86353 - JohnTitor:remove-projection_ty_from_predicates, r=oli-obk
Remove `projection_ty_from_predicates`

Fixes #86350
r? ``@oli-obk``
2021-06-17 05:54:59 +09:00
Yuki Okushi
36bf808aa1
Rollup merge of #86341 - LingMan:ret_val, r=davidtwco
Stop returning a value from `report_assert_as_lint`

This function only ever returns `None`. Make that explicity by not returning a value at all.

`@rustbot` modify labels +C-cleanup +T-compiler
2021-06-17 05:54:58 +09:00
Yuki Okushi
4e9dc76d36
Rollup merge of #86339 - JohnTitor:note-derive-on-proc-macros, r=petrochenkov
Mention #79078 on compatibility notes of 1.52

Closes #85854
r? ``@petrochenkov``
2021-06-17 05:54:57 +09:00
Yuki Okushi
b5c3ef66e6
Rollup merge of #86260 - jsha:expand-methods, r=GuillaumeGomez
Open trait implementations' toggles by default.

This makes it possible to use Ctrl-F to find methods defined in traits.

As discussed in #85923. This modifies the approach suggested in #40363, but still achieves the goal of skimmability. For new users who aren't familiar with all the traits, their methods are readily visible and searchable. For experienced users who prefer to skim the list of all traits, there are two options: the "collapse all" shortcut, and the "auto hide trait implementations" setting.

Demo https://hoffman-andrews.com/rust/expand-methods/std/string/struct.String.html#trait-implementations

r? `@GuillaumeGomez`
2021-06-17 05:54:56 +09:00
Yuki Okushi
0d14acad7e
Rollup merge of #86141 - amorison:link-ref-in-doc-dyn-keyword, r=kennytm
Link reference in `dyn` keyword documentation

The "read more" sentence formatted "object safety" as inline code
instead of providing a link to more information.  This PR adds a link
to the Reference about this matter, as well as the page regarding trait
objects.

---

We could also put these links in the very first line (instead of the link to the
Book) and in the first paragraph which mentions the "object safe" requirement.
Personally, I think it's good to keep the link to the Book up-front as it's more
accessible than the Reference.
2021-06-17 05:54:55 +09:00
Yuki Okushi
b1fb32d165
Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytm
Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`

To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.
2021-06-17 05:54:54 +09:00
Yuki Okushi
4ff55ecf04
Rollup merge of #86104 - FabianWolff:issue-86085, r=davidtwco
Fix span calculation in format strings

This pull request fixes #86085. The ICE described there is due to an error in the span calculation inside format strings, if the format string is the result of a macro invocation:
```rust
fn main() {
    format!(concat!("abc}"));
}
```
currently produces:
```
error: invalid format string: unmatched `}` found
 --> test.rs:2:17
  |
2 |     format!(concat!("abc}"));
  |                 ^ unmatched `}` in format string
```
which is obviously incorrect. This happens because the span of the entire `concat!()` is combined with the _relative_ location of the unmatched `` `}` `` in the _result_ of the macro invocation (i.e. 4).

In #86085, this has led to a span that starts or ends in the middle of a multibyte character, but the root cause was the same. This pull request fixes the problem.
2021-06-17 05:54:52 +09:00
Yuki Okushi
7030efbb77
Rollup merge of #85870 - ptrojahn:mir_dump_whitespace, r=davidtwco
Allow whitespace in dump_mir filter

At least on my system this is necessary to get more complex filters with spaces like in https://rustc-dev-guide.rust-lang.org/mir/debugging.html working.
2021-06-17 05:54:46 +09:00
bors
a85f584aeb Auto merge of #86266 - LeSeulArtichaut:box-thir-adt, r=davidtwco
Box `thir::ExprKind::Adt` for performance

`Adt` is the biggest variant in the enum and probably isn't used very often compared to the other expr kinds, so boxing it should be beneficial for performance. We need a perf test to be sure.
2021-06-16 20:00:17 +00:00
Jacob Hoffman-Andrews
62658bfc22 Open trait implementations' toggles by default.
This makes it possible to use Ctrl-F to find methods defined in traits.
2021-06-16 10:24:59 -07:00
Michael Snoyman
770e8cc01e
Typo correction: s/is/its 2021-06-16 19:20:15 +03:00
bors
9fef8d91b4 Auto merge of #86179 - the8472:revere-path-cmp, r=kennytm
optimize Eq implementation for paths

Filesystems generally have a tree-ish structure which means paths are more likely to share a prefix than a suffix. Absolute paths are especially prone to share long prefixes.

quick benchmark consisting of a search through through a vec containing the absolute paths of all (1850) files in `compiler/`:

```
# old
test path::tests::bench_path_cmp                                  ... bench:     227,407 ns/iter (+/- 2,162)

# new
test path::tests::bench_path_cmp                                  ... bench:      64,976 ns/iter (+/- 1,142)
```
2021-06-16 15:18:19 +00:00
Guillaume Gomez
a2a006d1cc Add missing backslashes to prevent unwanted backlines in rustdoc HTML 2021-06-16 14:39:51 +02:00
bors
8daad743c4 Auto merge of #86332 - rylev:fix-ice-docalias, r=GuillaumeGomez
Fix ICE when doc aliases were put on function params

Fixes #86239

r? `@GuillaumeGomez`
2021-06-16 10:01:20 +00:00
Yuki Okushi
fb06d9e0cd
Move some typeck-related tests to the typeck dir 2021-06-16 19:01:05 +09:00
Yuki Okushi
d828eadd7a
Remove invalid suggestions for assoc consts on placeholder type error 2021-06-16 18:57:53 +09:00
Yuki Okushi
280d19395d
Remove projection_ty_from_predicates 2021-06-16 16:33:03 +09:00