Commit graph

136457 commits

Author SHA1 Message Date
Mara Bos
3fe37c3830
Rollup merge of #80973 - ehuss:update-books, r=ehuss
Update books

## nomicon

2 commits in a5a48441d411f61556b57d762b03d6874afe575d..a8584998eacdea7106a1dfafcbf6c1c06fcdf925
2020-12-06 10:39:41 +0900 to 2021-01-06 12:49:49 -0500
- Update vector code examples
- Remove outdated information about `jemalloc`

## reference

13 commits in b278478b766178491a8b6f67afa4bcd6b64d977a..50af691f838937c300b47812d0507c6d88c14f97
2020-12-21 18:18:03 -0800 to 2021-01-12 21:19:20 -0800
- Update grammar for parser unification. (rust-lang/reference#927)
- Define constraining an implementation (rust-lang/reference#928)
- Document extra behavior of #[no_mangle] (rust-lang/reference#930)
- Add a float examle without a `.`. (rust-lang/reference#929)
- Add more details about const generics. (rust-lang/reference#921)
- Fix footnotes. (rust-lang/reference#926)
- Add "Logic errors" as behavior not considered unsafe (rust-lang/reference#919)
- Update grammar for order of parameters/arguments. (rust-lang/reference#920)
- Fix formatting in the tuple section (rust-lang/reference#923)
- document const generics (rust-lang/reference#901)
- Update mdbook (rust-lang/reference#918)
- linkage.md: update link to FFI section of the Book. (rust-lang/reference#917)
- Document array expression with a const. (rust-lang/reference#914)

## book

8 commits in 5bb44f8b5b0aa105c8b22602e9b18800484afa21..ac57a0ddd23d173b26731ccf939f3ba729753275
2020-12-18 20:07:31 -0500 to 2021-01-09 14:18:45 -0500
- Update version of mdbook we're testing with to 0.4.5 (rust-lang/book#2561)
- Fix grammar in ch13-01-closures.md (rust-lang/book#2534)
- Merge remote-tracking branch 'origin/pr/2527'
- Clarify code example ch6.3 (rust-lang/book#2485)
- Fix link added in rust-lang/book#2495 to be relative and at the bottom
- Merge remote-tracking branch 'origin/pr/2495'
- Update output to match the updated poem punctuation
- Fix rust-lang/book#2539 - Remove fancy apostrophes from poem for Windows

## rust-by-example

3 commits in 1cce0737d6a7d3ceafb139b4a206861fb1dcb2ab..03e23af01f0b4f83a3a513da280e1ca92587f2ec
2020-12-21 17:36:29 -0300 to 2021-01-09 10:20:28 -0300
- Replace for loop with iteration (rust-lang/rust-by-example#1404)
- Update mdbook (rust-lang/rust-by-example#1402)
- Add note for match guards to include catch-all (rust-lang/rust-by-example#1401)

## embedded-book

1 commits in ba34b8a968f9531d38c4dc4411d5568b7c076bfe..ceec19e873be87c6ee5666b030c6bb612f889a96
2020-11-17 00:20:43 +0000 to 2021-01-03 13:13:10 +0000
- book.toml: add link to GitHub repo  (rust-embedded/book#276)
2021-01-14 18:00:20 +00:00
Mara Bos
9bfe6f1b2c
Rollup merge of #80972 - KodrAus:deprecate/remove_item, r=nagisa
Remove unstable deprecated Vec::remove_item

Closes #40062

The `Vec::remove_item` method was deprecated in `1.46.0` (in August of 2020). This PR now removes that unstable method entirely.
2021-01-14 18:00:18 +00:00
Mara Bos
90cc815829
Rollup merge of #80969 - camelid:monomorph-ice-msg, r=nagisa
Use better ICE message when no MIR is available

The ICE message is somewhat confusing and overly specific - the issue is
that there's no MIR available.

This should make debugging these ICEs easier since the error tells you
what's actually wrong, not what it was trying to do when it failed.

cc https://github.com/rust-lang/rust/pull/80952#issuecomment-759198841
cc `````@jyn514`````
2021-01-14 18:00:16 +00:00
Mara Bos
7855a730b9
Rollup merge of #80966 - KodrAus:deprecate/spin_loop_hint, r=m-ou-se
Deprecate atomic::spin_loop_hint in favour of hint::spin_loop

For https://github.com/rust-lang/rust/issues/55002

We wanted to leave `atomic::spin_loop_hint` alone when stabilizing `hint::spin_loop` so folks had some time to migrate. This now deprecates `atomic_spin_loop_hint`.
2021-01-14 18:00:14 +00:00
Mara Bos
ce48709405
Rollup merge of #80895 - sfackler:read-to-end-ub, r=m-ou-se
Fix handling of malicious Readers in read_to_end

A malicious `Read` impl could return overly large values from `read`, which would result in the guard's drop impl setting the buffer's length to greater than its capacity! ~~To fix this, the drop impl now uses the safe `truncate` function instead of `set_len` which ensures that this will not happen. The result of calling the function will be nonsensical, but that's fine given the contract violation of the `Read` impl.~~

~~The `Guard` type is also used by `append_to_string` which does not pass untrusted values into the length field, so I've copied the guard type into each function and only modified the one used by `read_to_end`. We could just keep a single one and modify it, but it seems a bit cleaner to keep the guard code close to the functions and related specifically to them.~~

To fix this, we now assert that the returned length is not larger than the buffer passed to the method.

For reference, this bug has been present for ~2.5 years since 1.20: ecbb896b9e.

Closes #80894.
2021-01-14 18:00:11 +00:00
Mara Bos
9e9aba87af
Rollup merge of #80829 - jyn514:dep-constructor, r=michaelwoerister
Get rid of `DepConstructor`

This removes fully 235 unused functions.

Follow-up to https://github.com/rust-lang/rust/pull/80325#discussion_r548491999.

r? ``@michaelwoerister``
cc ``@cjgillot``
2021-01-14 18:00:09 +00:00
Mara Bos
446ed77124
Rollup merge of #80567 - lukaslueg:intersperse_with, r=m-ou-se
Add Iterator::intersperse_with

This is a follow-up to #79479, tracking in #79524, as discussed https://github.com/rust-lang/rust/pull/79479#issuecomment-752671731.

~~Note that I had to manually implement `Clone` and `Debug` because `derive` insists on placing a `Clone`-bound on the struct-definition, which is too narrow. There is a long-standing issue # for this somewhere around here :-)~~

Also, note that I refactored the guts of `Intersperse` into private functions and re-used them in `IntersperseWith`, so I also went light on duplicating all the tests.

If this is suitable to be merged, the tracking issue should be updated, since it only mentions `intersperse`.

Happy New Year!

r? ``@m-ou-se``
2021-01-14 18:00:06 +00:00
Mara Bos
3308b43ba1
Rollup merge of #80444 - glittershark:bound-as-ref, r=dtolnay
Add as_ref and as_mut methods for Bound

Add as_ref and as_mut method for std::ops::range::Bound, patterned off
of the methods of the same name on Option.

I'm not quite sure what the process is for introducing new feature gates (this is my first contribution) so I've left these ungated, but happy to do whatever is necessary to gate them.
2021-01-14 18:00:02 +00:00
Mara Bos
9fc298ca89
Rollup merge of #80217 - camelid:io-read_to_string, r=m-ou-se
Add a `std::io::read_to_string` function

I recognize that you're usually supposed to open an issue first, but the
implementation is very small so it's okay if this is closed and it was 'wasted
work' :)

-----

The equivalent of `std::fs::read_to_string`, but generalized to all
`Read` impls.

As the documentation on `std::io::read_to_string` says, the advantage of
this function is that it means you don't have to create a variable first
and it provides more type safety since you can only get the buffer out
if there were no errors. If you use `Read::read_to_string`, you have to
remember to check whether the read succeeded because otherwise your
buffer will be empty.

It's friendlier to newcomers and better in most cases to use an explicit
return value instead of an out parameter.
2021-01-14 18:00:00 +00:00
Mara Bos
930371b3ae
Rollup merge of #80169 - frewsxcv:frewsxcv-docs-fix, r=jyn514
Recommend panic::resume_unwind instead of panicking.

Fixes https://github.com/rust-lang/rust/issues/79950.
2021-01-14 17:59:57 +00:00
Mara Bos
d3b31065e3
Rollup merge of #80017 - camelid:sugg-rest-pattern, r=estebank
Suggest `_` and `..` if a pattern has too few fields

Fixes #80010.
2021-01-14 17:59:55 +00:00
Mara Bos
8ac21fb201
Rollup merge of #79982 - ijackson:exit-status, r=dtolnay
Add missing methods to unix ExitStatusExt

These are the methods corresponding to the remaining exit status examination macros from `wait.h`.  `WCOREDUMP` isn't in SuS but is it is very standard.  I have not done portability testing to see if this builds everywhere, so I may need to Do Something if it doesn't.

There is also a bugfix and doc improvement to `.signal()`, and an `.into_raw()` accessor.

This would fix #73128 and fix #73129.  Please let me know if you like this direction, and if so I will open the tracking issue and so on.

If this MR goes well, I may tackle #73125 next - I have an idea for how to do it.
2021-01-14 17:59:53 +00:00
bors
4275ef6c9d Auto merge of #79689 - Vooblin:patch1, r=tmandry
Update tests of "unused_lifetimes" lint for async functions and corresponding source code

Before this PR the following code would cause an error:
```
#![deny(unused_lifetimes)]
async fn f<'a>(_: &'a i32) {}
fn main() {}
```
It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused.

Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now.

This PR connected to issues #78522, #77217
2021-01-14 17:27:15 +00:00
bors
d03fe84169 Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
Reintroduce hir::ExprKind::If

Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications.

The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome.

- [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051)
- [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d)
- [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5)
- [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691)
- [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95)
- [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-14 14:41:58 +00:00
Tomasz Miąsko
5ea1d0e865 Don't ICE when computing a layout of a generator tainted by errors 2021-01-14 13:13:13 +01:00
bors
7bb163095d Auto merge of #81003 - tmiasko:generator-layout, r=oli-obk
Encode optimized MIR of generators when emitting metadata
2021-01-14 11:58:17 +00:00
bors
a4f022e109 Auto merge of #78259 - plaflamme:fix-49660, r=KodrAus
Fix #49660 - Adds checks to ensure existence of arithmetic trait implementations

The first 2 commits fix an issue with the existing `wrapping.rs` tests. It wasn't referred to from the module, so the file was being ignored. This is fixed in 872dc60ed2 This surfaced a bug in its macro which is fixed in 8ddad18283

Lastly, commit 64d695b753 is the actual tests for fixing #49660

The following checks are done:

* `Add`, `Sub`, `Mul`, `Div`, `Rem`
  * `T op T`, `T op &T`, `&T op T` and `&T op &T`
  * for all integer and floating point types
* `AddAssign`, `SubAssign`, `MulAssign`, `DivAssign`, `RemAssign`
  * `&mut T op T` and `&mut T op &T`
  * for all integer and floating point types
* `Neg`
  * `op T` and `op &T`
  * for all signed integer and floating point types
* `Not`
  * `op T` and `op &T`
  * for `bool`
* `BitAnd`, `BitOr`, `BitXor`
  * `T op T`, `T op &T`, `&T op T` and `&T op &T`
  * for all integer types and bool
* `BitAndAssign`, `BitOrAssign`, `BitXorAssign`
  * `&mut T op T` and `&mut T op &T`
  * for all integer types and bool
* `Shl`, `Shr`
  * `L op R`, `L op &R`, `&L op R` and `&L op &R`
  * for all pairs of integer types
* `ShlAssign`, `ShrAssign`
  * `&mut L op R`, `&mut L op &R`
  * for all pairs of integer types

NOTE: I'd like some feedback on improving the macros. I'm not familiar with the idioms and patterns there and composing them has been a challenge for me.

[EDIT]: updated links to commits after rebase.
2021-01-14 08:46:55 +00:00
David Tolnay
a8d0161960
Fix typos in Fuchsia unix_process_wait_more 2021-01-13 22:13:45 -08:00
Philippe Laflamme
64d695b753
Adds tests to ensure some base op traits exist.
These tests invoke the various op traits using all accepted types they
are implemented for as well as for references to those types.

This fixes #49660 and ensures the following implementations exist:

* `Add`, `Sub`, `Mul`, `Div`, `Rem`
  * `T op T`, `T op &T`, `&T op T` and `&T op &T`
  * for all integer and floating point types
* `AddAssign`, `SubAssign`, `MulAssign`, `DivAssign`, `RemAssign`
  * `&mut T op T` and `&mut T op &T`
  * for all integer and floating point types
* `Neg`
  * `op T` and `op &T`
  * for all signed integer and floating point types
* `Not`
  * `op T` and `op &T`
  * for `bool`
* `BitAnd`, `BitOr`, `BitXor`
  * `T op T`, `T op &T`, `&T op T` and `&T op &T`
  * for all integer types and bool
* `BitAndAssign`, `BitOrAssign`, `BitXorAssign`
  * `&mut T op T` and `&mut T op &T`
  * for all integer types and bool
* `Shl`, `Shr`
  * `L op R`, `L op &R`, `&L op R` and `&L op &R`
  * for all pairs of integer types
* `ShlAssign`, `ShrAssign`
  * `&mut L op R`, `&mut L op &R`
  * for all pairs of integer types
2021-01-13 23:14:00 -05:00
Philippe Laflamme
8ddad18283
Avoid ident concatenation in macro.
AFAIK it isn't currently possible to do this. It is also more in line with other tests in the surrounding modules.
2021-01-13 23:13:55 -05:00
Philippe Laflamme
872dc60ed2
Fix missing mod declaration for Wrapping tests. 2021-01-13 23:13:49 -05:00
Aaron Hill
a961e6785c
Set tokens on AST node in collect_tokens
A new `HasTokens` trait is introduced, which is used to move logic from
the callers of `collect_tokens` into the body of `collect_tokens`.

In addition to reducing duplication, this paves the way for PR #80689,
which needs to perform additional logic during token collection.
2021-01-13 22:10:36 -05:00
bors
c7b0ddbffe Auto merge of #80802 - jyn514:box-attributes, r=nnethercote
Box Item::Attributes

This reduces the size of Item from 128 to 40 bytes. I think this is as small as it needs to get 🎉

Builds on https://github.com/rust-lang/rust/pull/80339 and should not be merged before.

r? `@GuillaumeGomez`
2021-01-14 02:26:46 +00:00
Griffin Smith
eb72dc5d40 Add as_ref and as_mut methods for Bound
Add as_ref and as_mut method for std::ops::range::Bound, patterned off
of the methods of the same name on Option.
2021-01-13 21:16:26 -05:00
Tomasz Miąsko
ea4cbff264 Encode optimized MIR of generators when emitting metadata 2021-01-14 00:00:00 +00:00
bors
180fdffa17 Auto merge of #80654 - Aaron1011:fix/dummy-span-ctxt, r=wesleywiser
Properly handle `SyntaxContext` of dummy spans in incr comp

Fixes #80336

Due to macro expansion, we may end up with spans with an invalid
location and non-root `SyntaxContext`. This commits preserves the
`SyntaxContext` of such spans in the incremental cache, and ensures
that we always hash the `SyntaxContext` when computing the `Fingerprint`
of a `Span`

Previously, we would discard the `SyntaxContext` during serialization to
the incremental cache, causing the span's `Fingerprint` to change across
compilation sessions.
2021-01-13 23:24:31 +00:00
bors
a62a76047e Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-13 20:35:58 +00:00
Aaron Hill
482a67d20f
Properly handle SyntaxContext of dummy spans in incr comp
Fixes #80336

Due to macro expansion, we may end up with spans with an invalid
location and non-root `SyntaxContext`. This commits preserves the
`SyntaxContext` of such spans in the incremental cache, and ensures
that we always hash the `SyntaxContext` when computing the `Fingerprint`
of a `Span`

Previously, we would discard the `SyntaxContext` during serialization to
the incremental cache, causing the span's `Fingerprint` to change across
compilation sessions.
2021-01-13 15:20:29 -05:00
Lukas Lueg
9b2f085110 Improve Iterator::intersperse_ docs 2021-01-13 21:07:59 +01:00
Caleb Sander
391b4cc378 Fix formatting specifiers doc link
Was incorrectly linked to `core::fmt`, which is empty, in d36e3e23a8
Some of the links were fixed already in 3baf6a4a74
2021-01-13 15:05:39 -05:00
Josh Stone
0342fd16ff Remove the unused context from CreateDebugLocation
This went unused in commit 88d874de63, part of #68965.
2021-01-13 11:55:49 -08:00
Lukas Lueg
95289889fe Add doc intralinks 2021-01-13 19:47:41 +01:00
bors
9bc8b00b4a Auto merge of #80718 - tmiasko:skip-opt-mir, r=oli-obk
Consistently avoid constructing optimized MIR when not doing codegen

The optimized MIR for closures is being encoded unconditionally, while
being unnecessary for cargo check. This turns out to be especially
costly with MIR inlining enabled, since it triggers computation of
optimized MIR for all callees that are being examined for inlining
purposes https://github.com/rust-lang/rust/pull/77307#issuecomment-751915450.

Skip encoding of optimized MIR for closures, enum constructors, struct
constructors, and trait fns when not doing codegen, like it is already
done for other items since 49433.
2021-01-13 17:48:41 +00:00
Ian Jackson
b59fa3d634 Fix stabilisation version of slice_strip
See https://github.com/rust-lang/rust/pull/77853#pullrequestreview-564921079

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 14:21:18 +00:00
bors
fd2df74902 Auto merge of #76219 - Mark-Simulacrum:extern-require-abi, r=estebank
Add allow-by-default lint on implicit ABI in extern function pointers and items

This adds a new lint, missing_abi, which lints on omitted ABIs on extern blocks, function declarations, and function pointers.

It is currently not emitting the best possible diagnostics -- we need to track the span of "extern" at least or do some heuristic searching based on the available spans -- but seems good enough for an initial pass than can be expanded in future PRs.

This is a pretty large PR, but mostly due to updating a large number of tests to include ABIs; I can split that into a separate PR if it would be helpful, but test updates are already in dedicated commits.
2021-01-13 13:56:15 +00:00
Ian Jackson
05a88aabc1 ExitStatusExt: Fix build on Fuchsia
This is not particularly pretty but the current situation is a mess
and I don't think I'm making it significantly worse.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 13:27:30 +00:00
David Tolnay
efddf5949f Fix typo saeled -> sealed 2021-01-13 12:50:29 +00:00
Ian Jackson
f3e7199a79 ExitStatusExt windows: Retrospectively seal this trait
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
70121941ff ExitStatusExt unix: Retrospectively seal this trait
As discussed in #79982.

I think the "new interfaces", ie the new trait and impl, must be
insta-stable.  This seems OK because we are, in fact, adding a new
restriction to the stable API.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
fa68567a1f unix ExitStatus: Add tracking issue to new methods
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
06a405c49c Replace Ie with In other words
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13 12:50:29 +00:00
Ian Jackson
29c851aef6 Replace Ie with In other words
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13 12:50:29 +00:00
Ian Jackson
42ea8f6434 unix ExitStatus: Provide .continued()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
f060b9e0d9 unix ExitStatus: Provide .stopped_signal()
Necessary to handle WIFSTOPPED.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
3f05051d6b unix ExitStatus: Provide .core_dumped
This is essential for proper reporting of child process status on Unix.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
530270f94a unix ExitStatus: Provide .into_raw()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
12d62aa436 unix ExitStatus: Clarify docs for .signal()
We need to be clear that this never returns WSTOPSIG.  That is, if
WIFSTOPPED, the return value is None.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson
5b1316f781 unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED
A unix wait status can contain, at least, exit statuses, termination
signals, and stop signals.

WTERMSIG is only valid if WIFSIGNALED.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

It will not be easy to experience this bug with `Command`, because
that doesn't pass WUNTRACED.  But you could make an ExitStatus
containing, say, a WIFSTOPPED, from a call to one of the libc wait
functions.

(In the WIFSTOPPED case, there is WSTOPSIG.  But a stop signal is
encoded differently to a termination signal, so WTERMSIG and WSTOPSIG
are by no means the same.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Mark Rousskov
4614671cae Update code to account for extern ABI requirement 2021-01-13 07:49:45 -05:00
Mark Rousskov
920b5ee722 Lint on extern in item declaration position 2021-01-13 07:49:16 -05:00