I came across an inconvenience when answering the following [Stack Overflow](https://stackoverflow.com/questions/67831170) question.
To get the remaining slice you have to call `buff.fill_buf().unwrap()`. Which in my opinion doesn't really tell you what is returned (in the context of Cursor). To improve readability and convenience when using Cursor i propose adding the method `remaining`.
The next thing i found inconvenient (unnecessary long) was detecting if the cursor reached the end. There are a few ways this can be achieved right now:
- `buff.fill_buf().unwrap().is_empty()`
- `buff.position() >= buff.get_ref().len()`
- `buff.bytes().next().is_none()`
Which all seem a bit unintuitive, hidden in trait documentations or just a bit long for such a simple task.
Therefor i propose another method called `is_empty`, maybe with another name, since this one may leave room for interpretation on what really is empty (the underlying slice, the remaining slice or maybe the position).
Since it seemed easier to create this PR instead of an RFC i did that, if an RFC is wanted, i can close this PR and write an RFC first.
Yuki Okushi [Mon, 21 Jun 2021 22:37:46 +0000 (07:37 +0900)]
Rollup merge of #85182 - CDirkx:available_concurrency, r=JohnTitor
Move `available_concurrency` implementation to `sys`
This splits out the platform-specific implementation of `available_concurrency` to the corresponding platforms under `sys`. No changes are made to the implementation.
Tidy didn't lint against this code being originally added outside of `sys` because of a bug (see #84677), this PR also reverts the exclusion that was introduced in that bugfix.
Yuki Okushi [Mon, 21 Jun 2021 15:00:45 +0000 (00:00 +0900)]
Rollup merge of #86503 - ehuss:rustc.css-fonts, r=jyn514,GuillaumeGomez
Fix rust.css fonts.
The `rust.css` file (used for all non-rustdoc and non-mdbook pages) has gotten out of sync with rustdoc's css. The two share the same fonts, so this updates them to match what rustdoc uses.
It would be ideal not to need this at all, but that's for another time.
Yuki Okushi [Mon, 21 Jun 2021 15:00:42 +0000 (00:00 +0900)]
Rollup merge of #86472 - Mark-Simulacrum:fix-ci-beta, r=pietroalbini
Fix CI to fetch master on beta channel
This forward-ports a fix from the beta channel (landing in #86413, hopefully) to master so that we don't need to apply it on each round of backports.
This bug also demonstrates that our channel-checking is a bit insufficient -- stable is checked, but beta has some of its own peculiarities currently and isn't checked. But this does not attempt to adjust for that; we likely can't afford to run both beta and stable channels by CI and the current state here seems OK for now.
Yuki Okushi [Mon, 21 Jun 2021 15:00:41 +0000 (00:00 +0900)]
Rollup merge of #86424 - calebcartwright:rustfmt-mod-resolution, r=Mark-Simulacrum
rustfmt: load nested out-of-line mods correctly
This should address https://github.com/rust-lang/rustfmt/issues/4874
r? `@Mark-Simulacrum`
Decided to make the change directly in tree here for expediency/to minimize any potential backporting issues, and because there's some subtree sync items I need to get resolved before pulling from r-l/rustfmt
Yuki Okushi [Mon, 21 Jun 2021 15:00:40 +0000 (00:00 +0900)]
Rollup merge of #86349 - yerke:add-test-for-issue-78632, r=Mark-Simulacrum
Add regression test for issue #78632
Add regression test for issue #78632
Closes #78632
Took this test from #78632 (what was committed to glacier in https://github.com/rust-lang/rust/issues/78632#issuecomment-731843345).
Tested that the we get ICE on 1.52.1 on the playground (https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b86d51fee4cded9d24b50d8ecbc48c6a).
bors [Mon, 21 Jun 2021 12:21:19 +0000 (12:21 +0000)]
Auto merge of #86210 - ehuss:rustfix-update, r=Mark-Simulacrum
Rustfix update
This updates to rustfix 0.6.0. One of the key changes here is https://github.com/rust-lang/rustfix/pull/195 which changes rustfix to apply multi-part suggestions. One of the tests needs to updated because there are some overlapping suggestions which rustfix cannot handle. The solution is to only apply the machine-applicable suggestions to avoid the overlapping issue.
This also includes a minor change to compiletest to provide better error messages with rustfix.
bors [Mon, 21 Jun 2021 09:40:34 +0000 (09:40 +0000)]
Auto merge of #86157 - jsha:tera, r=jyn514,GuillaumeGomez
Use Tera templates for rustdoc.
Replaces a format!() call in layout::render with a template
expansion. Introduces a `templates` field in SharedContext so parts
of rustdoc can share pre-rendered templates.
This currently builds in a copy of the single template available, like
with static files. However, future work can make this live-loadable with
a perma-unstable flag, to make rustdoc developers' work easier.
Part of #84419.
Demo at https://hoffman-andrews.com/rust/tera/std/string/struct.String.html.
bors [Mon, 21 Jun 2021 06:56:51 +0000 (06:56 +0000)]
Auto merge of #85775 - adamrk:warn-unused-target-fields, r=nagisa
Emit warnings for unused fields in custom targets.
Add a warning which lists any fields in a custom target `json` file that aren't used. Currently unrecognized fields are ignored so, for example, a typo in the `json` will silently produce a target which isn't the one intended.
Replaces a format!() call in layout::render with a template
expansion. Introduces a `templates` field in SharedContext so parts
of rustdoc can share pre-rendered templates.
This currently builds in a copy of the single template available, like
with static files. However, future work can make this live-loadable with
a perma-unstable flag, to make rustdoc developers' work easier.
bors [Mon, 21 Jun 2021 01:16:15 +0000 (01:16 +0000)]
Auto merge of #86502 - JohnTitor:rollup-wge0f3x, r=JohnTitor
Rollup of 8 pull requests
Successful merges:
- #83739 (Account for bad placeholder errors on consts/statics with trait objects)
- #85637 (document PartialEq, PartialOrd, Ord requirements more explicitly)
- #86152 (Lazify is_really_default condition in the RustdocGUI bootstrap step)
- #86156 (Fix a bug in the linkchecker)
- #86427 (Updated release note)
- #86452 (fix panic-safety in specialized Zip::next_back)
- #86484 (Do not set depth to 0 in fully_expand_fragment)
- #86491 (expand: Move some more derive logic to rustc_builtin_macros)
Yuki Okushi [Mon, 21 Jun 2021 00:42:17 +0000 (09:42 +0900)]
Rollup merge of #86452 - the8472:fix-zip-drop-safety, r=m-ou-se
fix panic-safety in specialized Zip::next_back
This was unsound since a panic in a.next_back() would result in the
length not being updated which would then lead to the same element
being revisited in the side-effect preserving code.
Yuki Okushi [Mon, 21 Jun 2021 00:42:15 +0000 (09:42 +0900)]
Rollup merge of #86156 - ehuss:linkchecker-fixes, r=Mark-Simulacrum
Fix a bug in the linkchecker
There was a small typo in the linkchecker (in #85652) that caused it to report a `#` fragment link error pointing to the wrong file (it was displaying the path to the source file, not the target of the link).
This also includes a few other changes:
- Fixes the tests due to some changes in the redirect handling in #84703.
- Adds the tests to rustbuild to run whenever the linkchecker itself is run.
- Updates the tests to validate more of the output (so that a mistake like this would have been caught).
Yuki Okushi [Mon, 21 Jun 2021 00:42:15 +0000 (09:42 +0900)]
Rollup merge of #86152 - the8472:lazify-npm-queries, r=Mark-Simulacrum
Lazify is_really_default condition in the RustdocGUI bootstrap step
The `RustdocGUI::should_run` condition spawns `npm list` several times which adds up to seconds of wall-time.
Evaluate the condition lazily to to keep `./x.py test tidy` and similar short-running tasks fast.
Yuki Okushi [Mon, 21 Jun 2021 00:42:13 +0000 (09:42 +0900)]
Rollup merge of #85637 - RalfJung:partial-ord, r=m-ou-se
document PartialEq, PartialOrd, Ord requirements more explicitly
This is the result of discussion in https://github.com/rust-lang/rust/issues/50230, in particular [this summary comment](https://github.com/rust-lang/rust/issues/50230#issuecomment-392819364).
bors [Sun, 20 Jun 2021 22:52:49 +0000 (22:52 +0000)]
Auto merge of #85980 - ssomers:btree_cleanup_LeafRange, r=Mark-Simulacrum
BTree: encapsulate LeafRange better & some debug asserts
Looking at iterators again, I think #81937 didn't house enough code in `LeafRange`. Moving the API boundary a little makes things more local in navigate.rs and less complicated in map.rs.
bors [Sun, 20 Jun 2021 20:07:13 +0000 (20:07 +0000)]
Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
Replace some `std::iter::repeat` with `str::repeat`
I noticed that there were some instances where `std::iter::repeat` would be used to repeat a string or a char to take a specific count of it and then collect it into a `String` when `str::repeat` is actually much faster and better for that.
See also: https://github.com/rust-lang/rust-clippy/issues/7260.
bors [Sun, 20 Jun 2021 16:42:13 +0000 (16:42 +0000)]
Auto merge of #84967 - CDirkx:os_str_ext, r=m-ou-se
Move `OsStringExt` and `OsStrExt` to `std::os`
Moves the `OsStringExt` and `OsStrExt` traits and implementations from `sys_common` to `os`. `sys_common` is for abstractions over `sys` and shouldn't really contain publicly exported items.
This does introduce some duplication: the traits and implementations are now duplicated in `unix`, `wasi`, `hermit`, and `sgx`. However, I would argue that this duplication is no different to how something like `MetadataExt` is duplicated in `linux`, `vxworkx`, `redox`, `solaris` etc. The duplication also matches the fact that the traits on different platforms are technically distinct types: any platform is free to add it's own extra methods to the extension trait.
bors [Sat, 19 Jun 2021 23:10:55 +0000 (23:10 +0000)]
Auto merge of #86433 - paolobarbolini:string-overlapping, r=m-ou-se
Use `copy_nonoverlapping` to copy `bytes` in `String::insert_bytes`
The second copy could be made using `ptr::copy_nonoverlapping` instead of `ptr::copy`, since aliasing won't allow `self` and `bytes` to overlap. LLVM even seems to recognize this, [replacing the second `memmove` with a `memcopy`](https://rust.godbolt.org/z/Yoaa6rrGn), so this makes it so it's always applied.
bors [Sat, 19 Jun 2021 17:05:08 +0000 (17:05 +0000)]
Auto merge of #86034 - nagisa:nagisa/rt-soundness, r=m-ou-se
Change entry point to π‘οΈ against π₯ π₯-payloads
Guard against panic payloads panicking within entrypoints, where it is
UB to do so.
Note that there are a number of tradeoffs to consider. For instance, I
considered guarding against accidental panics inside the `rt::init` and
`rt::cleanup` code as well, as it is not all that obvious these may not
panic, but doing so would mean that we initialize certain thread-local
slots unconditionally, which has its own problems.
Change entry point to π‘οΈ against π₯ π₯-payloads
Guard against panic payloads panicking within entrypoints, where it is
UB to do so.
Note that there are a number of implementation approaches to consider.
Some simpler, some more complicated. This particular solution is nice in
that it also guards against accidental implementation issues in
various pieces of runtime code, something we cannot prevent statically
right now.
bors [Sat, 19 Jun 2021 05:44:11 +0000 (05:44 +0000)]
Auto merge of #86378 - Smittyvb:thir-walker-pat, r=LeSeulArtichaut
Add pattern walking support to THIR walker
Suggested in https://github.com/rust-lang/rust/pull/85263#issuecomment-861906730, this splits off the support for pattern walking in THIR from #85263. This has no observable effect on THIR unsafety checking, since it is not currently possible to trigger unsafety from the THIR checker using the additional patterns or constants that are now walked. THIR patterns are walked in source code order.
Yuki Okushi [Sat, 19 Jun 2021 01:14:14 +0000 (10:14 +0900)]
Rollup merge of #86444 - FabianWolff:issue-83505, r=LeSeulArtichaut
Fix ICE with `#[repr(simd)]` on enum
This pull request fixes #83505. `#[repr(simd)]` may only be applied to structs, which correctly causes `E0517` for the example given in #83505, but the compiler attempts to recover from this error, which leads to an ICE later, when `.non_enum_variant()` is called on the `AdtDef`. I have added a check that prevents this from happening.
Yuki Okushi [Sat, 19 Jun 2021 01:14:10 +0000 (10:14 +0900)]
Rollup merge of #86397 - Eosis:alter-cell-docs, r=JohnTitor
Alter std::cell::Cell::get_mut documentation
I felt that there was some inconsistency between between Cell and RefCell with regards to their `get_mut` method documentation: `RefCell` flags this method as "unusual" in that it takes `&mut self`, while `Cell` does not. I attempted to flag this in `Cell`s documentation as well, and point to `RefCell`s method in the case where it is required.
Find relevant parts of docs and the new version below.
The current docs for `Cell::get_mut`:
> Returns a mutable reference to the underlying data.
This call borrows Cell mutably (at compile-time) which guarantees that we possess the only reference.
And `RefCell::get_mut`:
> Returns a mutable reference to the underlying data.
This call borrows `RefCell` mutably (at compile-time) so there is no need for dynamic checks.
However be cautious: this method expects self to be mutable, which is generally not the case when using a `RefCell`. Take a look at the `borrow_mut` method instead if self isnβt mutable.
Also, please be aware that this method is only for special circumstances and is usually not what you want. In case of doubt, use `borrow_mut` instead.
My attempt to make `Cell::get_mut` clearer:
> Returns a mutable reference to the underlying data.
This call borrows `Cell` mutably (at compile-time) which guaranteesthat we possess the only reference.
However be cautious: this method expects `self` to be mutable, which is generally not the case when using a `Cell`. If you require interior mutability by reference, consider using `RefCell` which provides run-time checked mutable borrows through its `borrow_mut` method.
Yuki Okushi [Sat, 19 Jun 2021 01:14:07 +0000 (10:14 +0900)]
Rollup merge of #86136 - m-ou-se:proc-macro-open-close-span, r=m-ou-se
Stabilize span_open() and span_close().
This proposes to stabilize `Group::span_open()` and `Group::span_close()`.
These are part of the `proc_macro_span` feature gate tracked in https://github.com/rust-lang/rust/issues/54725
Most of the features gated behind `proc_macro_span` are about source location information (file path, line and column information), expansion information (parent()), source_text(), etc. Those are not ready for stabilizaiton. However, getting the span of the `(` and `)` separately instead of only of the entire `(...)` can be very useful in proc macros, and doesn't seem blocked on anything that all the other parts of `proc_macro_span` are blocked on. So, this renames the feature gate for those two functions to `proc_macro_group_span` and stabilizes them.
The8472 [Sat, 19 Jun 2021 00:20:22 +0000 (02:20 +0200)]
fix panic-safety in specialized Zip::next_back
This was unsound since a panic in a.next_back() would result in the
length not being updated which would then lead to the same element
being revisited in the side-effect preserving code.
bors [Fri, 18 Jun 2021 23:17:40 +0000 (23:17 +0000)]
Auto merge of #86194 - RalfJung:const-ub-hard-error, r=oli-obk
make UB during CTFE a hard error
This is a next step for https://github.com/rust-lang/rust/issues/71800. `const_err` has been a future-incompatibility lint for 4 months now since https://github.com/rust-lang/rust/pull/80394 (and err-by-default for many years before that), so I think we could try making it a proper hard error at least in some situations.
I didn't yet adjust the tests, since I first want to gauge the fall-out via crater.
Cc `@rust-lang/wg-const-eval`
bors [Fri, 18 Jun 2021 20:11:51 +0000 (20:11 +0000)]
Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-se
Add has_data_left() to BufRead
This is a continuation of #40747 and also addresses #40745. The problem with the previous PR was that it had "eof" in its method name. This PR uses a more descriptive method name, but I'm open to changing it.