mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
make ast object safe
This commit is contained in:
parent
e055cfacdf
commit
bbcca4f735
2 changed files with 15 additions and 4 deletions
|
@ -25,15 +25,23 @@ pub use self::{
|
|||
/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
|
||||
/// the same representation: a pointer to the tree root and a pointer to the
|
||||
/// node itself.
|
||||
pub trait AstNode: Clone {
|
||||
fn can_cast(kind: SyntaxKind) -> bool;
|
||||
pub trait AstNode {
|
||||
fn can_cast(kind: SyntaxKind) -> bool
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
fn syntax(&self) -> &SyntaxNode;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assert_ast_is_object_safe() {
|
||||
fn _f(_: &dyn AstNode, _: &dyn NameOwner) {}
|
||||
}
|
||||
|
||||
/// Like `AstNode`, but wraps tokens rather than interior nodes.
|
||||
pub trait AstToken {
|
||||
fn cast(token: SyntaxToken) -> Option<Self>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue