Fix invalid suggestion for mismatched types in closure arguments
This PR fixes the invalid suggestion for mismatched types in closure arguments.
The invalid suggestion came from a wrongly created span in the parser for closure arguments that don't have a type specified. Specifically, the span in this case was the last token span, but in the case of tuples, the span represented the last parenthesis instead of the whole tuple, which is fixed by taking the more accurate span of the pattern.
There is one unfortunate downside of this fix, it worsens even more the diagnostic for mismatched types in closure args without an explicit type. This happens because there is no correct span for implied inferred type. I tried also fixing this but it's a rabbit hole.
Fixes https://github.com/rust-lang/rust/issues/114180
`const`-stablilize `NonNull::as_ref`
A bunch of pointer to reference methods have been made unstably const some time ago in #91823 under the feature gate `const_ptr_as_ref`.
Out of these, `NonNull::as_ref` can be implemented as a `const fn` in stable rust today, so i hereby propose to const stabilize this function only.
Tracking issue: #91822
``@rustbot`` label +T-libs-api -T-libs
merge functionality of `io::Sink` into `io::Empty`
Many times, there is a need for a simple dummy `io::Read`er + `io::Write`r, but currently the only options are `io::Empty` and `io::Sink` respectively. Having both of their functionality together requires writing your own boilerplate for something that makes sense to have in the standard library. This PR adds the functionality of `io::Sink` to `io::Empty`, making `io::Empty` be able to perform the tasks of both of the previous structs. (This idea was first mentioned in #24235)
Note: I also updated some doc comments in `io::utils` in this pull request to fix inconsistencies between `io::Sink` and `io::Empty`.
API Change Proposal: https://github.com/rust-lang/libs-team/issues/49
[rustdoc] Remove unneeded `clone()` calls for `derive_id`
I realized we were cloning values before passing them to `derive_id` where they are cloned again, which isn't great. Since they'll be cloned anyway, let's allow to pass both by reference and by value.
r? `@notriddle`
- Make the levels of headings consistent in this whole document
- Fix some headings
- Remove redundant empty lines
- Follow the markdown linter advices to use the same symbol for different level of unordered list entries
The invalid suggestion came from a wrongly created span in `rustc_parse'
for closure arguments that didn't have a type specified. Specifically,
the span in this case was the last token span, but in the case of
tuples, the span represented the last parenthesis instead of the whole
tuple, which is fixed by taking the more accurate span of the pattern.
Rollup of 6 pull requests
Successful merges:
- #110056 (Fix the example in document for WaitTimeoutResult::timed_out)
- #112655 (Mark `map_or` as `#[must_use]`)
- #114018 (Make `--error-format human-annotate-rs` handle multiple files)
- #114068 (inline format!() args up to and including rustc_middle (2))
- #114223 (Documentation: Fix Stilted Language in Vec->Indexing)
- #114227 (Add tidy check for stray rustfix files)
r? `@ghost`
`@rustbot` modify labels: rollup
Documentation: Fix Stilted Language in Vec->Indexing
Problem
Language in the Vec->Indexing documentation sounds stilted due to incorrect word ordering: "... type allows to access values by index."
Solution
Reorder words in the Vec->Indexing documentation to flow better: "... type allows access to values by index." The phrase "allows access to" also matches other existing documentation.
Updated lines doc to include trailing carriage return note
Updated `str::lines` doc to include explicit info about (trailing) carriage returns.
Reference: #100311
Clarify behavior of inclusive bounds in BTreeMap::{lower,upper}_bound
It wasn’t quite clear to me how these methods would interpret inclusive bounds so I added examples for those.
Remove redundant example of `BTreeSet::iter`
The usage and that `Values returned by the iterator are returned in ascending order` are already demonstrated by the other example and the description, so I removed the useless one.
`redundant_closure` fixes
fixes#8548
A good chunk of the code is fixing false negatives. The old code banned any non late-bound regions from appearing in the callee's signature. The new version checks when the late-bound region is actually required.
changelog: Better track when a early-bound region appears when a late-bound region is required in `redundant_closure`.
changelog: Don't lint `redundant_closure` when the closure gives explicit types.
[rustc][data_structures] Simplify binary_search_slice.
Instead of using `binary_search_by_key`, it's possible to use `partition_point` to find the lower bound. This avoids the need to locate the leftmost matching entry separately.
It's also possible to use `partition_point` to find the upper bound, so I plan to send a separate PR for your consideration.
Rustdoc small cleanups
Each commit does some little cleanups:
* We had some `Res` comparisons in multiple places (and still do, but unless we use a macro, it's not possible to "merge" any further) so I moved it into a function.
* It was weird to have some utils function used everywhere in `visit_ast` so I instead moved it into `clean/utils.rs`.
* In HTML rendering, we had some write "issues":
* Multiple calls that could be merged into one.
* Some `write!` that could be `write_str`.
* We didn't use the new `format!` args much.
r? `@notriddle`
Make RPITITs inherit the `assumed_wf_types` of their parent method
... and then move the RPITIT well-formedness check to just use the regular logic of wfchecking an associated type.
---
We need to inherit the `assumed_wf_types` of the RPITIT's parent function in order for the given code to be considered well-formed:
```rust
trait Foo {
fn bar<'a, T>(_: &'a T) -> impl Iterator<Output = &'a T>;
}
```
Since for `&'a T` to be WF, we need `T: 'a`.
In order for this to work for late-bound lifetimes, we need to do some additional mapping of any late-bound lifetimes captured by these assumed wf types. This is because within the body of the function (and thus in the `assumed_wf_types`), they're represented as `ReFree` variants of the original late-bound lifetimes declared in the function's generics, but in the RPITIT's GAT, they're represented as "reified" `ReEarlyBound` vars (duplicated during opaque type lowering). Luckily, the mapping between these two is already [stored in the opaque](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html#structfield.lifetime_mapping).
Fixes#113796