mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-30 23:27:24 +00:00
syntax: return owned string instead of leaking string
This commit is contained in:
parent
4ecaad98e0
commit
5ff3299dd6
16 changed files with 27 additions and 27 deletions
|
@ -12,19 +12,19 @@ use crate::{
|
|||
};
|
||||
|
||||
impl ast::Lifetime {
|
||||
pub fn text(&self) -> &str {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
text_of_first_token(self.syntax())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Name {
|
||||
pub fn text(&self) -> &str {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
text_of_first_token(self.syntax())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::NameRef {
|
||||
pub fn text(&self) -> &str {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
text_of_first_token(self.syntax())
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,8 @@ impl ast::NameRef {
|
|||
}
|
||||
}
|
||||
|
||||
fn text_of_first_token(node: &SyntaxNode) -> &str {
|
||||
let t =
|
||||
node.green().children().next().and_then(|it| it.into_token()).unwrap().text().to_string();
|
||||
Box::leak(Box::new(t))
|
||||
fn text_of_first_token(node: &SyntaxNode) -> SmolStr {
|
||||
node.green().children().next().and_then(|it| it.into_token()).unwrap().text().into()
|
||||
}
|
||||
|
||||
pub enum Macro {
|
||||
|
@ -378,7 +376,7 @@ impl fmt::Display for NameOrNameRef {
|
|||
}
|
||||
|
||||
impl NameOrNameRef {
|
||||
pub fn text(&self) -> &str {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
match self {
|
||||
NameOrNameRef::Name(name) => name.text(),
|
||||
NameOrNameRef::NameRef(name_ref) => name_ref.text(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue