about summary refs log tree commit diff
path: root/compiler/rustc_parse_format
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-23 19:54:27 +0100
committerGitHub <noreply@github.com>2025-01-23 19:54:27 +0100
commitce2a316c937fa7985c06de6cb69f812740e539bd (patch)
treea5c6846461df7929adac1ee12ced513adf89115d /compiler/rustc_parse_format
parent36da4ecd833a6d883298d32106a90c25df0be2a0 (diff)
parent4c448d5163628b0aa5ff4c3bbdb8c6108c1119e9 (diff)
downloadrust-ce2a316c937fa7985c06de6cb69f812740e539bd.tar.gz
rust-ce2a316c937fa7985c06de6cb69f812740e539bd.zip
Rollup merge of #135911 - Zalathar:arena-cache-option, r=compiler-errors
Allow `arena_cache` queries to return `Option<&'tcx T>`

Currently, `arena_cache` queries always have to return `&'tcx T`[^deref]. This means that if an arena-cached query wants to return an optional value, it has to return `&'tcx Option<T>`, which has a few negative consequences:

- It goes against normal Rust style, where `Option<&T>` is preferred over `&Option<T>`.
- Callers that actually want an `Option<&T>` have to manually call `.as_ref()` on the query result.
- When the query result is `None`, a full-sized `Option<T>` still needs to be stored in the arena.

This PR solves that problem by introducing a helper trait `ArenaCached` that is implemented for both `&T` and `Option<&T>`, and takes care of bridging between the provided type, the arena-allocated type, and the declared query return type.

---

To demonstrate that this works, I have converted the two existing arena-cached queries that currently return `&Option<T>`: `mir_coroutine_witnesses` and `diagnostic_hir_wf_check`. Only the query declarations need to be modified; existing providers and callers continue to work with the new query return type.

(My real goal is to apply this to `coverage_ids_info`, which will return Option as of #135873, but that PR hasn't landed yet.)

[^deref]: Technically they could return other types that implement `Deref`, but it's hard to imagine this working well with anything other than `&T`.
Diffstat (limited to 'compiler/rustc_parse_format')
0 files changed, 0 insertions, 0 deletions