mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Validate byte string literals
This commit is contained in:
parent
c258b4fdb0
commit
30cd4d5acb
8 changed files with 305 additions and 24 deletions
|
@ -409,6 +409,43 @@ impl<R: TreeRoot<RaTypes>> ByteNode<R> {
|
|||
|
||||
impl<'a> Byte<'a> {}
|
||||
|
||||
// ByteString
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> {
|
||||
pub(crate) syntax: SyntaxNode<R>,
|
||||
}
|
||||
pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>;
|
||||
|
||||
impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> {
|
||||
fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax }
|
||||
}
|
||||
impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {}
|
||||
impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for ByteString<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
BYTE_STRING => Some(ByteString { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot<RaTypes>> ByteStringNode<R> {
|
||||
pub fn borrowed(&self) -> ByteString {
|
||||
ByteStringNode { syntax: self.syntax.borrowed() }
|
||||
}
|
||||
pub fn owned(&self) -> ByteStringNode {
|
||||
ByteStringNode { syntax: self.syntax.owned() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> ByteString<'a> {}
|
||||
|
||||
// CallExpr
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue