mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-15 14:49:36 +00:00
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:
1 parent
42dcfd234c
commit
07833c0a44
1 file changed
+2
-2
@@ -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>";
|
||||
|
||||
Reference in new issue
Block a user