Simplify dead code lint
This PR scratches a few itches I had when looking at that code.
The perf improvement comes from keeping the `scanned` set through several marking phases. This pretty much divides by 2 the number of HIR traversals.
`Printer` cleanups
The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up.
r? ``@davidtwco``
Return a struct with named fields from `hash_owner_nodes`
While looking through this code for other reasons, I noticed a nice opportunity to return a struct with named fields instead of a tuple. The first patch also introduces an early-return to flatten the rest of `hash_owner_nodes`.
There are further changes that could potentially be made here (renaming things, `Option<Hashes>` instead of optional fields), but I'm not deeply familiar with this code so I didn't want to disturb the calling code too much.
It's a cryptic macro that makes some things slightly more concise in
`PrettyPrinter`. E.g. if you declare `define_scope_printer!(p)` in a
scope you can then call `p! to get these transformations:
```
p!("foo"); --> write!(p, "foo")?;
p!(print(ty)); --> ty.print(p)?;
p!(method(args)); --> p.method(args)?;
```
You can also chain calls, e.g.:
```
p!("foo", print(ty)); --> write!(p, "foo")?; ty.print(p)?;
```
Ultimately this doesn't seem worth it. The macro definition is hard to
read, the call sites are hard to read, `define_scope_printer!` is pretty
gross, and the code size reductions are small. Tellingly, many normal
`write!` and `print` calls are sprinkled throughout the code, probably
because people have made modifications and didn't want to use or
understand how to use `p!`.
This commit removes it.
Currently they are mostly named `cx`, which is a terrible name for a
type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with
other types like `TyCtxt`. This commit changes them to `p`. A couple of
existing `p` variables had to be renamed to make way.
Improve formatting of doc code blocks
We don't currently apply automatic formatting to doc comment code blocks. As a
result, it has built up various idiosyncracies, which make such automatic
formatting difficult. Some of those idiosyncracies also make things harder for
human readers or other tools.
This PR makes a few improvements to doc code formatting, in the hopes of making
future automatic formatting easier, as well as in many cases providing net
readability improvements.
I would suggest reading each commit separately, as each commit contains one
class of changes.
Remove the witness type from coroutine *args* (without actually removing the type)
This does as much of rust-lang/rust#144157 as we can without having to break rust-lang/rust#143545 and/or introduce some better way of handling higher ranked assumptions.
Namely, it:
* Stalls coroutines based off of the *coroutine* type rather than the witness type.
* Reworks the dtorck constraint hack to not rely on the witness type.
* Removes the witness type from the args of the coroutine, eagerly creating the type for nested obligations when needed (auto/clone impls).
I'll experiment with actually removing the witness type in a follow-up.
r? lcnr
Deduplicate `IntTy`/`UintTy`/`FloatTy`.
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed.
r? `@fmease`
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This
commit removes them and places a single definition in `rustc_ast_ir`.
This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but
means a bunch of silly conversion functions can be removed.
The one annoying wrinkle is that the old version had differences in
their `Debug` impls, e.g. one printed `u32` while the other printed
`U32`. Some compiler error messages rely on the former (yuk), and some
clippy output depends on the latter. So the commit also changes clippy
to not rely on `Debug` and just implement what it needs itself.
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`,
and `Const` and... `BoundVar`. An annoying inconsistency.
This commit repurposes the existing `BoundConst`, which was barely used,
so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks
a `kind` field but it's still nice to have because it makes the const
code more similar to the ty/region code everywhere.
The commit also removes `impl From<BoundVar> for BoundTy`, which has a
single use and doesn't seem worth it.
These changes fix the "FIXME: We really should have a separate
`BoundConst` for consts".
Type folders can only modify a few "types of interest": `Binder`, `Ty`,
`Predicate`, `Clauses`, `Region`, `Const`. Likewise for type visitors,
but they can also visit errors (via `ErrorGuaranteed`).
Currently the impls of `try_super_fold_with`, `super_fold_with`, and
`super_visit_with` do more than they need to -- they fold/visit values
that cannot contain any types of interest.
This commit removes those unnecessary fold/visit operations, which makes
these impls more similar to the impls for `Ty`. It also removes the
now-unnecessary derived impls for the no-longer-visited types.
Rollup of 3 pull requests
Successful merges:
- rust-lang/rust#144657 (fix: Only "close the window" when its the last annotated file)
- rust-lang/rust#144665 (Re-block SRoA on SIMD types)
- rust-lang/rust#144713 (`rustc_middle::ty` cleanups)
r? `@ghost`
`@rustbot` modify labels: rollup
Remove eval_always from check_private_in_public.
This PR attempts to avoid re-computing `check_private_in_public` query. First by marking the query as non-`eval_always`, and by reducing the amount of accesses to HIR as much as possible.
Latest perf https://github.com/rust-lang/rust/pull/116316#issuecomment-3094672105 shows that we manage it. The cost is extra dep-graph bookkeeping.