Implement advance_by, advance_back_by for iter::Chain
Part of #77404.
This PR does two things:
- implement `Chain::advance[_back]_by` in terms of `advance[_back]_by` on `self.a` and `advance[_back]_by` on `self.b`
- change `Chain::nth[_back]` to use `advance[_back]_by` on `self.a` and `nth[_back]` on `self.b`
This ensures that `Chain::nth` can take advantage of an efficient `nth` implementation on the second iterator, in case it doesn't implement `advance_by`.
cc `@scottmcm` in case you want to review this
Rollup of 13 pull requests
Successful merges:
- #76388 (Add a note about the panic behavior of math operations on time objects)
- #76855 (Revamp rustdoc docs about documentation using `cfg`)
- #76995 (Reduce boilerplate with the matches! macro)
- #77228 (Add missing examples for MaybeUninit)
- #77528 (Avoid unchecked casts in net parser)
- #77534 (Disallow overriding forbid in same scope)
- #77555 (Allow anyone to set regression labels)
- #77558 (Rename bootstrap/defaults/{config.toml.PROFILE => config.PROFILE.toml})
- #77559 (Fix rustdoc warnings about invalid Rust syntax)
- #77560 (Fix LitKind's byte buffer to use refcounted slice)
- #77573 (Hint doc use convert::identity relative link)
- #77587 (Fix span for unicode escape suggestion.)
- #77591 (Record `expansion_that_defined` into crate metadata)
Failed merges:
r? `@ghost`
Record `expansion_that_defined` into crate metadata
Fixes#77523
Now that hygiene serialization is implemented, we also need to record
`expansion_that_defined` so that we properly handle a foreign
`SyntaxContext`.
Fix span for unicode escape suggestion.
If a unicode escape is missing the curly braces, the suggested fix is to add the curly braces, but the span for the fix was incorrect. It was not covering the `\u`, but the suggested text includes the `\u`, causing the resulting fix to be `"\u\u{1234}"`. This changes it so that the span includes the `\u`. An alternate fix would be to remove `\u` from the suggested fix, but I think the error message reads better if the entire escape is included.
Fix LitKind's byte buffer to use refcounted slice
While working on adding a new lint for clippy (see https://github.com/rust-lang/rust-clippy/pull/6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type.
This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
Fix LitKind's byte buffer to use refcounted slice
While working on adding a new lint for clippy (see https://github.com/rust-lang/rust-clippy/pull/6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type.
This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
Rename bootstrap/defaults/{config.toml.PROFILE => config.PROFILE.toml}
This allows these files to have okay syntax highlighting in editors, and helps avoid nagging from editors which want to suggest that I install a plugin for `*.library` files to view the `config.toml.library` or whatever.
It's a very minor change.
r?@jyn514
Reduce boilerplate with the matches! macro
Replaces simple bool `match`es of the form
match $expr {
$pattern => true
_ => false
}
and their inverse with invocations of the matches! macro.
Limited to rustc_middle for now to get my feet wet.
Revamp rustdoc docs about documentation using `cfg`
- Move `cfg(doc)` out of `unstable-features`. It's not unstable.
- Remove outdated reference to `everybody_loops`.
- Improve wording in various places
- Give an example of code this allows (and does not allow)
- Link to `cfg(doc)` in `doc(cfg)` documentation. Since one is stable
and the other is not, don't combine them.
- Cleanup wording for `doc(cfg)`
- Incorporate changes from #76849
- Mention that `doc(cfg)` is also for features
Addresses https://github.com/rust-lang/rust/pull/76849#issuecomment-694516199.
Obsoletes https://github.com/rust-lang/rust/pull/76849 (I made sure to fix the weird dashes too).
r? @steveklabnik
unnecessary sort by: avoid dereferencing the suggested closure parameter
This change tries to simplify the solution for problematic cases but is less restrictive than #6006.
* We can't dereference shared references to non-Copy types, so the new suggestion does not do that. Note that this implies that the suggested closure parameter will be a reference.
* We can't take a reference to the closure parameter in the returned key, so we don't lint in those cases. This can happen either because the key borrows from the parameter (e.g. `|a| a.borrows()`), or because we suggest `|a| Reverse(a)`. If we did we would hit this error:
```
error: lifetime may not live long enough
--> /home/ebroto/src/ebroto-clippy/tests/ui/unnecessary_sort_by.fixed:19:25
|
19 | vec.sort_by_key(|b| Reverse(b));
| -- ^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is Reverse<&'2 isize>
| has type `&'1 isize`
error: aborting due to previous error
```
Note that Clippy does not currently have the (MIR-based) machinery necessary to check that what is borrowed is actually the closure parameter.
changelog: [`unnecessary_sort_by`]: avoid dereferencing the suggested closure parameter
Fixes#6001