mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Validate string literals
This commit is contained in:
parent
5a9150df9b
commit
3b4c02c19e
9 changed files with 621 additions and 274 deletions
|
@ -3236,6 +3236,43 @@ impl<'a> AstNode<'a> for Stmt<'a> {
|
|||
|
||||
impl<'a> Stmt<'a> {}
|
||||
|
||||
// String
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> {
|
||||
pub(crate) syntax: SyntaxNode<R>,
|
||||
}
|
||||
pub type String<'a> = StringNode<RefRoot<'a>>;
|
||||
|
||||
impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StringNode<R1>> for StringNode<R2> {
|
||||
fn eq(&self, other: &StringNode<R1>) -> bool { self.syntax == other.syntax }
|
||||
}
|
||||
impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {}
|
||||
impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for String<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
STRING => Some(String { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot<RaTypes>> StringNode<R> {
|
||||
pub fn borrowed(&self) -> String {
|
||||
StringNode { syntax: self.syntax.borrowed() }
|
||||
}
|
||||
pub fn owned(&self) -> StringNode {
|
||||
StringNode { syntax: self.syntax.owned() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> String<'a> {}
|
||||
|
||||
// StructDef
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
mod generated;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::string::String as RustString;
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
|
@ -76,7 +77,7 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> {
|
|||
|
||||
/// Returns the textual content of a doc comment block as a single string.
|
||||
/// That is, strips leading `///` and joins lines
|
||||
fn doc_comment_text(self) -> String {
|
||||
fn doc_comment_text(self) -> RustString {
|
||||
self.doc_comments()
|
||||
.map(|comment| {
|
||||
let prefix = comment.prefix();
|
||||
|
@ -133,6 +134,12 @@ impl<'a> Char<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> String<'a> {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
&self.syntax().leaf_text().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Comment<'a> {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
self.syntax().leaf_text().unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue