Region naming refactoring [6/N]
Followup to #67474
EDIT: this PR is probably best read commit-by-commit...
The major changes in this PR include:
- moving many functions around to modules that better suit them. In particular, a lot of methods were moved from `borrow_check::diagnostics::region_errors` to `borrow_check::region_infer`, and `report_region_errors` was moved from `borrow_check` to `borrow_check::diagnostics::region_errors`.
- `borrow_check::diagnostics::{region_errors, region_name}` are now most comprised of methods on `MirBorrowckCtxt` instead of `RegionInferenceContext`, allowing us to get rid of the annoying `pub(in crate::borrow_check)` on most of the fields of the latter, along with a number of method arguments on many methods.
- I renamed `MirBorrowckCtxt.nonlexical_regioncx` to just `regioncx` because their is no lexical lifetimes any more, and the old name was annoyingly verbose, causing many lines to wrap unnecessarily.
- I got rid of `ErrorRegionNamingContext`. Region naming is implemented as inherent methods on `MirBorrowckCtxt`, so we just move the naming stuff into that struct.
The PR is rather large, but the commits are fairly self-contained (though they don't all compile). There was one minor output change to one test with `compare-mode=nll`, which I think is acceptable.
Between this PR and the last one, a net of 200 lines are removed, most of which was function parameters and context structs 🎉
Some samples:
```diff
- self.nonlexical_regioncx.free_region_constraint_info(
- &self.body,
- &self.local_names,
- &self.upvars,
- self.mir_def_id,
- self.infcx,
- borrow_region_vid,
- region,
- );
+ self.free_region_constraint_info(borrow_region_vid, region);
```
```diff
- .or_else(|| {
- self.give_name_if_anonymous_region_appears_in_yield_ty(
- infcx,
- body,
- *mir_def_id,
- fr,
- renctx,
- )
- });
+ .or_else(|| self.give_name_if_anonymous_region_appears_in_arguments(fr))
```
r? @matthewjasper
cc @eddyb
[self-profiler] Add example to `-Z help` to turn on query key recording
Also add the `default` option so that it's easy to add query key
recording to the default.
r? @michaelwoerister
Rollup of 6 pull requests
Successful merges:
- #67956 (Detail transitive containment in E0588 diagnostic)
- #68153 (resolve: Point at the private item definitions in privacy errors)
- #68195 (Account for common `impl Trait`/`dyn Trait` return type errors)
- #68288 (Fix some of the rustfmt fallout in Miri)
- #68292 (don't clone types that are copy)
- #68301 (Don't propagate __RUST_TEST_INVOKE to subprocess)
Failed merges:
r? @ghost
Don't propagate __RUST_TEST_INVOKE to subprocess
When -Z panic_abort_tests is enabled, we use an environment variable to
tell the subprocess which test to invoke. If that subprocess then
invokes another Rust test binary, chaos ensues.
r? @alexcrichton
Account for common `impl Trait`/`dyn Trait` return type errors
- When all return paths have the same type, suggest `impl Trait`.
- When all return paths implement the expected `trait`, suggest `Box<dyn Trait>` and mention using an `enum`.
- When multiple different types are returned and `impl Trait` is expected, extend the explanation.
- When return type is `impl Trait` and the return paths do not implement `Trait`, point at the returned values.
- Split `src/librustc/traits/error_reporting.rs` into multiple files to keep size under control.
Fix#68110, cc #66523.
When -Z panic_abort_tests is enabled, we use an environment variable to
tell the subprocess which test to invoke. If that subprocess then
invokes another Rust test binary, chaos ensues.
Implement `DebugStruct::non_exhaustive`.
This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using `DebugStruct`.
## Example
```rust
#![feature(debug_non_exhaustive)]
use std::fmt;
struct Bar {
bar: i32,
hidden: f32,
}
impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Bar")
.field("bar", &self.bar)
.non_exhaustive(true) // Show that some other field(s) exist.
.finish()
}
}
assert_eq!(
format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
"Bar { bar: 10, .. }",
);
```