Commit Graph

161446 Commits

Author SHA1 Message Date
Matthias Krüger
98cb33894c
Rollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se
Add MaybeUninit::(slice_)as_bytes(_mut)

This adds methods to convert between `MaybeUninit<T>` and a slice of `MaybeUninit<u8>`. This is safe since `MaybeUninit<u8>` can correctly handle padding bytes in any `T`.

These methods are added:
```rust
impl<T> MaybeUninit<T> {
	pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
	pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
	pub fn slice_as_bytes(this: &[MaybeUninit<T>]) -> &[MaybeUninit<u8>];
	pub fn slice_as_bytes_mut(this: &mut [MaybeUninit<T>]) -> &mut [MaybeUninit<u8>];
}
```
2022-01-20 17:10:30 +01:00
bors
74fbbefea8 Auto merge of #92138 - AngelicosPhosphoros:try_smarter_vec_from_iter_48994_2, r=Mark-Simulacrum
Improve capacity estimation in Vec::from_iter

Iterates on the attempt made in #53086.

Closes #48994
2022-01-20 06:50:14 +00:00
bors
237949b6c8 Auto merge of #93085 - matthiaskrgr:rollup-mgpu2ju, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #92316 (mangling_v0: Skip extern blocks during mangling)
 - #92630 (Change PhantomData type for `BuildHasherDefault` (and more))
 - #92800 (Add manifest docs fallback.)
 - #93005 (Move back templates into html folder)
 - #93065 (Pretty printer algorithm revamp step 2)
 - #93077 (remove `List::is_noop`)

Failed merges:

 - #93068 (Fix spacing for `·` between stability and source)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-19 22:34:55 +00:00
Amanieu d'Antras
5c96dcf961 Add MaybeUninit::as_bytes 2022-01-19 21:27:29 +00:00
Matthias Krüger
43d508bb78
Rollup merge of #93077 - lcnr:write_substs, r=oli-obk
remove `List::is_noop`

think that `is_noop` is actually less clear than just using `is_empty`
2022-01-19 19:19:52 +01:00
Matthias Krüger
fe93f08051
Rollup merge of #93065 - dtolnay:ringbuffer, r=lcnr
Pretty printer algorithm revamp step 2

This PR follows #92923 as a second chunk of modernizations backported from https://github.com/dtolnay/prettyplease into rustc_ast_pretty.

I've broken this up into atomic commits that hopefully are sensible in isolation. At every commit, the pretty printer is compilable and has runtime behavior that is identical to before and after the PR. None of the refactoring so far changes behavior.

The general theme of this chunk of commits is: the logic in the old pretty printer is doing some very basic things (pushing and popping tokens on a ring buffer) but expressed in a too-low-level way that I found makes it quite complicated/subtle to reason about. There are a number of obvious invariants that are "almost true" -- things like `self.left == self.buf.offset` and `self.right == self.buf.offset + self.buf.data.len()` and `self.right_total == self.left_total + self.buf.data.sum()`. The reason these things are "almost true" is the implementation tends to put updating one side of the invariant unreasonably far apart from updating the other side, leaving the invariant broken while unrelated stuff happens in between. The following code from master is an example of this:

e5e2b0be26/compiler/rustc_ast_pretty/src/pp.rs (L314-L317)

In this code the `advance_right` is reserving an entry into which to write a next token on the right side of the ring buffer, the `check_stack` is doing something totally unrelated to the right boundary of the ring buffer, and the `scan_push` is actually writing the token we previously reserved space for. Much of what this PR is doing is rearranging code to shrink the amount of stuff in between when an invariant is broken to when it is restored, until the whole thing can be factored out into one indivisible method call on the RingBuffer type.

The end state of the PR is that we can entirely eliminate `self.left` (because it's now just equal to `self.buf.offset` always) and `self.right` (because it's equal to `self.buf.offset + self.buf.data.len()` always) and the whole `Token::Eof` state which used to be the value of tokens that have been reserved space for but not yet written.

I found without these changes the pretty printer implementation to be hard to reason about and I wasn't able to confidently introduce improvements like trailing commas in `prettyplease` until after this refactor. The logic here is 43 years old at this point (Graydon translated it as directly as possible from the 1979 pretty printing paper) and while there are advantages to following the paper as closely as possible, in `prettyplease` I decided if we're going to adapt the algorithm to work better for Rust syntax, it was worthwhile making it easier to follow than the original.
2022-01-19 19:19:51 +01:00
Matthias Krüger
623791df24
Rollup merge of #93005 - GuillaumeGomez:templates-in-html, r=notriddle
Move back templates into html folder

Follow-up of https://github.com/rust-lang/rust/pull/92526.

r? `@notriddle`
2022-01-19 19:19:49 +01:00
Matthias Krüger
bcb093efcd
Rollup merge of #92800 - ehuss:docs-fallback, r=Mark-Simulacrum
Add manifest docs fallback.

This adds a fallback so that the rustup manifest will contain the rust-docs component for all hosts. There is a mapping so that the docs that get downloaded are roughly close to the actual host. There inevitably will be things that don't match. Ideally the standard library docs would be the same for every platform (`cfg(doc)` goes a long way towards this), but there are still lots of minor differences.

Closes #69525
2022-01-19 19:19:48 +01:00
Matthias Krüger
dfbb6b246d
Rollup merge of #92630 - steffahn:lift_bounds_on_BuildHasherDefault, r=yaahc
Change PhantomData type for `BuildHasherDefault` (and more)

Changes `PhantomData<H>` to `PhantomData<fn() -> H>` for `BuildHasherDefault`. This preserves the covariance of `H`, while it lifts the currently inferred unnecessary bounds like [`H: Send` for `BuildHasherDefault<H>: Send`](https://doc.rust-lang.org/1.57.0/std/hash/struct.BuildHasherDefault.html#impl-Send), etc.

_Edit:_ Also does a similar change for `iter::Empty` and `future::Pending`.
2022-01-19 19:19:47 +01:00
Matthias Krüger
715cda2e81
Rollup merge of #92316 - petrochenkov:extmangle, r=wesleywiser
mangling_v0: Skip extern blocks during mangling

There's no need to include the dummy `Nt` into the symbol name, items in extern blocks belong to their parent modules for all purposes except for inheriting the ABI and attributes.

Follow up to https://github.com/rust-lang/rust/pull/92032

(There's also a drive-by fix to the `rust-demangler` tool's tests, which don't run on CI, I initially attempted using them for testing this PR.)
2022-01-19 19:19:45 +01:00
Eric Huss
c8e6889e08 Add assert that fallback targets must be available. 2022-01-19 09:41:04 -08:00
bors
5e57faa78a Auto merge of #93069 - matthiaskrgr:rollup-gx1vkp7, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #88642 (Formally implement let chains)
 - #89621 (doc: guarantee call order for sort_by_cached_key)
 - #91278 (Use iterator instead of recursion in `codegen_place`)
 - #92124 (Little improves in CString `new` when creating from slice)
 - #92783 (Annotate dead code lint with notes about ignored derived impls)
 - #92797 (Remove horizontal lines at top of page)
 - #92920 (Move expr- and item-related pretty printing functions to modules)
 - #93041 (Remove some unused ordering derivations based on `DefId`)
 - #93051 (Add Option::is_some_with and Result::is_{ok,err}_with)
 - #93062 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-19 15:01:10 +00:00
AngelicosPhosphoros
ea570c689c Improve estimation of capacity in Vec::from_iter
Closes #48994
2022-01-19 09:47:49 -05:00
lcnr
4bd571c4ff remove is_noop 2022-01-19 13:58:29 +01:00
Guillaume Gomez
48f5dcad10 Move back templates into html folder 2022-01-19 11:13:24 +01:00
Matthias Krüger
ea1275a62c
Rollup merge of #93062 - ehuss:update-books, r=ehuss
Update books

## nomicon

1 commits in c05c452b36358821bf4122f9c418674edd1d713d..66d097d3d80e8f88c288c6879c7c2b909ecf8ad4
2021-12-13 15:23:48 +0900 to 2022-01-05 05:45:21 +0900
- Fix typo / type error in FFI code example (rust-lang/nomicon#327)

## reference

8 commits in f8ba2f12df60ee19b96de24ae5b73af3de8a446b..4dee6eb63d728ffb9e7a2ed443e9ada9275c69d2
2022-01-03 11:02:08 -0800 to 2022-01-18 09:26:33 -0800
- (minor) Remove Expression Path sub-types splits in Pattern specs (rust-lang/reference#1138)
- Document destructuring assignment (rust-lang/reference#1116)
- Document the 2021 edition changes to macros-by-example `pat` metavariables (rust-lang/reference#1135)
- Improve the documentation of macros-by-example metavariable names (rust-lang/reference#1130)
- trait-bounds.md: add pronoun 'that' (rust-lang/reference#1131)
- Say that macros-by-example `ident` metavariables can match raw identifiers (rust-lang/reference#1133)
- State in the UAX31 profile description that a lone `_` is not an identifier (rust-lang/reference#1129)
- Document syntax reserved in Rust 2021 (rust-lang/reference#1128)

## book

17 commits in d3740fb7aad0ea4a80ae20f64dee3a8cfc0c5c3c..f17df27fc14696912c48b8b7a7a8fa49e648088d
2022-01-03 21:46:04 -0500 to 2022-01-18 17:46:28 -0500
- Add a notice to the top of all nostarch snapshots
- Fix quotes
- Grammar (minor): 'or' → 'and' for enum variants
- Propagate edits of chapter 8 to src
- Replies to nostarch edits
- more edits
- ch8 from nostarch
- Fix grammar and line wrapping
- Merge remote-tracking branch 'origin/pr/2880'
- Remove wikipedia link
- Merge remote-tracking branch 'origin/pr/2927'
- Snapshot of ch14 for nostarch
- Backport fixes to chapter 14 noticed while doing nostarch snapshot
- Fix usage of find piped into xargs
- Adjust some more line numbers of Cargo.toml includes
- Merge branch '2909'
- Merge remote-tracking branch 'parkerziegler/fix/ch14-add-one-naming'

## rustc-dev-guide

7 commits in 875464457c4104686faf667f47848aa7b0f0a744..78dd6a4684cf8d6b72275fab6d0429ea40b66338
2021-12-28 22:17:49 -0600 to 2022-01-18 14:44:26 -0300
- Reorganize and expand the testing chapters. (rust-lang/rustc-dev-guide#1281)
- Add inline assembly internals (rust-lang/rustc-dev-guide#1266)
- Spelling: Rename `rust` to `Rust` (rust-lang/rustc-dev-guide#1288)
- Clean up section about FCPs (rust-lang/rustc-dev-guide#1287)
- Address more review comments in rust-lang/rustc-dev-guide#1286.
- Address review comments in rust-lang/rustc-dev-guide#1286.
- Streamline "Getting Started" some more.
2022-01-19 10:42:21 +01:00
Matthias Krüger
d5bc168d65
Rollup merge of #93051 - m-ou-se:is-some-with, r=yaahc
Add Option::is_some_with and Result::is_{ok,err}_with

See https://github.com/rust-lang/rust/issues/62358#issuecomment-1015827777
2022-01-19 10:42:20 +01:00
Matthias Krüger
0b9056c38a
Rollup merge of #93041 - pierwill:rm-unused-defid-ords, r=cjgillot
Remove some unused ordering derivations based on `DefId`

Like #93018, this removes some unused/unneeded ordering derivations as part of ongoing work on #90317. Here, these changes are aimed at making https://github.com/rust-lang/rust/pull/90749 easier to review, test, and merge.

r? `@cjgillot`
2022-01-19 10:42:19 +01:00
Matthias Krüger
420ada6f8a
Rollup merge of #92920 - dtolnay:printtidy, r=cjgillot
Move expr- and item-related pretty printing functions to modules

Currently *compiler/rustc_ast_pretty/src/pprust/state.rs* is 2976 lines on master. The `tidy` limit is 3000, which is blocking #92243.

This PR adds a `mod expr;` and `mod item;` to move logic related to those AST nodes out of the single huge file.
2022-01-19 10:42:18 +01:00
Matthias Krüger
7f2dbcba38
Rollup merge of #92797 - jsha:fewer-lines, r=GuillaumeGomez
Remove horizontal lines at top of page

They are not needed to separate the search bar and the title, which are visually distinct on their own.

Part of #59840

Demo: https://rustdoc.crud.net/jsha/fewer-lines/std/string/struct.String.html

r? `@GuillaumeGomez`
2022-01-19 10:42:17 +01:00
Matthias Krüger
9a82f74cdf
Rollup merge of #92783 - FabianWolff:issue-92726, r=nikomatsakis
Annotate dead code lint with notes about ignored derived impls

Fixes #92726. CC `@pmetzger,` is this what you had in mind?

r? `@nikomatsakis`
2022-01-19 10:42:16 +01:00
Matthias Krüger
3148a322d8
Rollup merge of #92124 - AngelicosPhosphoros:remove_extra_alloc_in_cstring_new_35838, r=Mark-Simulacrum
Little improves in CString `new` when creating from slice

Old code already contain optimization for cases with `&str` and `&[u8]` args. This commit adds a specialization for `&mut[u8]` too.

Also, I added usage of old slice in search for zero bytes instead of new buffer because it produce better code for constant inputs on Windows LTO builds. For other platforms, this wouldn't cause any difference because it calls `libc` anyway.

Inlined `_new` method into spec trait to reduce amount of code generated to `CString::new` callers.
2022-01-19 10:42:15 +01:00
Matthias Krüger
3a1db90efb
Rollup merge of #91278 - SparrowLii:place, r=spastorino
Use iterator instead of recursion in `codegen_place`

This PR fixes the FIXME in `codegen_place` about using iterator instead of recursion when processing the `projection` field in `mir::PlaceRef`. At the same time, it also reduces the right drift.
2022-01-19 10:42:14 +01:00
Matthias Krüger
2a4381d8ea
Rollup merge of #89621 - digama0:patch-2, r=yaahc
doc: guarantee call order for sort_by_cached_key

`slice::sort_by_cached_key` takes a caching function `f: impl FnMut(&T) -> K`, which means that the order that calls to the caching function are made is user-visible. This adds a clause to the documentation to promise the current behavior, which is that `f` is called on all elements of the slice from left to right, unless the slice has len < 2 in which case `f` is not called.

For example, this can be used to ensure that the following code is a correct way to involve the index of the element in the sort key:
```rust
let mut index = 0;
slice.sort_by_cached_key(|x| (my_key(index, x), index += 1).0);
```
2022-01-19 10:42:13 +01:00
Matthias Krüger
5d2928f7b9
Rollup merge of #88642 - c410-f3r:let_chains_2, r=matthewjasper
Formally implement let chains

## Let chains

My longest and hardest contribution since #64010.

Thanks to `@Centril` for creating the RFC and special thanks to `@matthewjasper` for helping me since the beginning of this journey. In fact, `@matthewjasper` did much of the complicated MIR stuff so it's true to say that this feature wouldn't be possible without him. Thanks again `@matthewjasper!`

With the changes proposed in this PR, it will be possible to chain let expressions along side local variable declarations or ordinary conditional expressions. In other words, do much of what the `if_chain` crate already does.

## Other considerations

* `if let guard` and `let ... else` features need special care and should be handled in a following PR.

* Irrefutable patterns are allowed within a let chain context

* ~~Three Clippy lints were already converted to start dogfooding and help detect possible corner cases~~

cc #53667
2022-01-19 10:42:12 +01:00
bors
2f004d2d40 Auto merge of #93063 - ehuss:update-cargo, r=ehuss
Update cargo

16 commits in 358e79fe56fe374649275ca7aebaafd57ade0e8d..95bb3c92bf516017e812e7f1c14c2dea3845b30e
2022-01-04 18:39:45 +0000 to 2022-01-18 17:39:35 +0000
- Error when setting crate type of both dylib and cdylib in library (rust-lang/cargo#10243)
- Include `help` in `--list` (rust-lang/cargo#10300)
- Add report subcommand to bash completion. (rust-lang/cargo#10295)
- Downgrade some log messages. (rust-lang/cargo#10296)
- Enable shortcut for triage bot (rust-lang/cargo#10298)
- Bump to 0.61.0, update changelog (rust-lang/cargo#10294)
- use new cargo fmt option (rust-lang/cargo#10291)
- Add `run-fail` to semver-check for docs (rust-lang/cargo#10287)
- Use `is_symlink()` method (rust-lang/cargo#10290)
- Stabilize namespaced and weak dependency features. (rust-lang/cargo#10269)
- Port cargo to clap3 (rust-lang/cargo#10265)
- feat: support rustflags per profile (rust-lang/cargo#10217)
- Make bors ignore the PR template so it doesn't end up in merge messages (rust-lang/cargo#10267)
- Be resilient to most IO error and filesystem loop while walking dirs (rust-lang/cargo#10214)
- Remove the option to disable pipelining (rust-lang/cargo#10258)
- Always ask rustc for messages about artifacts, and always process them (rust-lang/cargo#10255)
2022-01-19 06:17:07 +00:00
David Tolnay
4d3faae5cd
Eliminate left and right cursors in favor of ring buffer 2022-01-18 20:19:44 -08:00
David Tolnay
cc66a7ff20
Eliminate eof token state 2022-01-18 20:08:52 -08:00
David Tolnay
6e8b06015e
Simplify the buffer push done by scan_break 2022-01-18 19:35:43 -08:00
Eric Huss
84e0d9db6c Update books 2022-01-18 19:23:45 -08:00
David Tolnay
fe5c4eab2d
Eliminate a check_stack call on an empty scan stack 2022-01-18 19:23:22 -08:00
David Tolnay
377c9dbabf
Index a single time in check_stack 2022-01-18 19:21:18 -08:00
David Tolnay
a37d272892
Implement check_stack nonrecursively 2022-01-18 19:20:33 -08:00
David Tolnay
0490e43422
Implement check_stream nonrecursively 2022-01-18 19:19:18 -08:00
David Tolnay
947a09a4a8
Replace if + unwrap with if let in check_stack 2022-01-18 19:18:47 -08:00
David Tolnay
80139a0f02
Ensure Printer buf is always indexed using self.left or self.right 2022-01-18 19:18:04 -08:00
David Tolnay
ae28ec5a9c
Inline Printer's scan_pop_bottom method 2022-01-18 19:16:33 -08:00
David Tolnay
2a14275500
Inline Printer's scan_top method 2022-01-18 19:16:32 -08:00
David Tolnay
e20d5abdfb
Inline Printer's scan_pop method 2022-01-18 19:16:32 -08:00
Eric Huss
bfacc5cc73 Update cargo 2022-01-18 19:14:33 -08:00
David Tolnay
50d722a691
Simplify ring buffer pushes 2022-01-18 19:07:12 -08:00
David Tolnay
e219b2b5f9
Inline Printer's scan_push method 2022-01-18 19:04:12 -08:00
David Tolnay
fdb95f54e8
Inline Printer's advance_right method 2022-01-18 19:02:49 -08:00
Jacob Hoffman-Andrews
fa9a8430ea Remove horizontal lines at top of page
They are not needed to separate the search bar and the title, which are
visually distinct on their own.
2022-01-18 18:45:43 -08:00
Mara Bos
5fee3e7a9c Fix is_some_with tests. 2022-01-19 00:12:35 +01:00
bors
e5e2b0be26 Auto merge of #93048 - matthiaskrgr:rollup-cz5ma34, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #90782 (Implement raw-dylib support for windows-gnu)
 - #91150 (Let qpath contain NtTy: `<$:ty as $:ty>::…`)
 - #92425 (Improve SIMD casts)
 - #92692 (Simplify and unify rustdoc sidebar styles)
 - #92780 (Directly use ConstValue for single literals in blocks)
 - #92924 (Delete pretty printer tracing)
 - #93018 (Remove some unused `Ord` derives based on `Span`)
 - #93026 (fix typo in `max` description for f32/f64)
 - #93035 (Fix stdarch submodule pointing to commit outside tree)

Failed merges:

 - #92861 (Rustdoc mobile: put out-of-band info on its own line)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-18 22:46:47 +00:00
Caio
5f74ef4fb1 Formally implement let chains 2022-01-18 19:38:17 -03:00
Mara Bos
45dee47fec Improve is_err_with example. 2022-01-18 22:53:43 +01:00
Mara Bos
148234ff73 Add is_some_with tracking issue number. 2022-01-18 22:18:16 +01:00
Mara Bos
aaebae973f Add Result::{is_ok_with, is_err_with}. 2022-01-18 22:17:44 +01:00