feat(ast): tie debug_name return lifetime to the underlying AST node (#27295)

Return Cow<'a, str> instead of tying the result to the borrow of
the AstKind wrapper. This lets callers retain a debug name obtained
from a temporary AstKind while the underlying AST node remains alive.

The longer lifetime is sound: AstKind<'a> holds node references valid
for 'a, and every returned value is either an owned string, a static
string, or directive text borrowed from storage valid for 'a.

Co-authored-by: Cameron <cameron.clark@hey.com>
This commit is contained in:
sadanandCameron authored and GitHub committed 2026-10-04 10:28:40 +00:00
1 parent 42dcfd234c
commit 07833c0a44
1 file changed
+2 -2
+2 -2
View File
@@ -362,13 +362,13 @@ impl<'a> AstKind<'a> {
}
}
impl AstKind<'_> {
impl<'a> AstKind<'a> {
/// Get the AST kind name with minimal details. Particularly useful for
/// when debugging an iteration over an AST.
///
/// Note that this method does not exist in release builds. Do not include
/// usage of this method within your code.
pub fn debug_name(&self) -> std::borrow::Cow<'_, str> {
pub fn debug_name(&self) -> std::borrow::Cow<'a, str> {
use std::borrow::Cow;
const COMPUTED: &str = "<computed>";