Skip to content

Commit fc5f73d

Browse files
Move AttrsOwnerNode to syntax and make it public
1 parent fc21640 commit fc5f73d

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

crates/ide/src/syntax_highlighting/inject.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use either::Either;
66
use hir::{HasAttrs, InFile, Semantics};
77
use ide_db::{call_info::ActiveParameter, defs::Definition, SymbolKind};
88
use syntax::{
9-
ast::{self, AstNode, AttrsOwner, DocCommentsOwner},
9+
ast::{self, AstNode, AttrsOwner, AttrsOwnerNode, DocCommentsOwner},
1010
match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize,
1111
};
1212

@@ -89,36 +89,6 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
8989
"edition2021",
9090
];
9191

92-
// Basically an owned dyn AttrsOwner without extra Boxing
93-
struct AttrsOwnerNode {
94-
node: SyntaxNode,
95-
}
96-
97-
impl AttrsOwnerNode {
98-
fn new<N: DocCommentsOwner>(node: N) -> Self {
99-
AttrsOwnerNode { node: node.syntax().clone() }
100-
}
101-
}
102-
103-
impl AttrsOwner for AttrsOwnerNode {}
104-
impl AstNode for AttrsOwnerNode {
105-
fn can_cast(_: syntax::SyntaxKind) -> bool
106-
where
107-
Self: Sized,
108-
{
109-
false
110-
}
111-
fn cast(_: SyntaxNode) -> Option<Self>
112-
where
113-
Self: Sized,
114-
{
115-
None
116-
}
117-
fn syntax(&self) -> &SyntaxNode {
118-
&self.node
119-
}
120-
}
121-
12292
fn doc_attributes<'node>(
12393
sema: &Semantics<RootDatabase>,
12494
node: &'node SyntaxNode,

crates/syntax/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub use self::{
2020
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
2121
generated::{nodes::*, tokens::*},
2222
node_ext::{
23-
AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind,
24-
SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
23+
AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind,
24+
SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
2525
},
2626
token_ext::*,
2727
traits::*,

crates/syntax/src/ast/node_ext.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ impl NameOwner for Macro {
9090

9191
impl AttrsOwner for Macro {}
9292

93+
/// Basically an owned `dyn AttrsOwner` without extra boxing.
94+
pub struct AttrsOwnerNode {
95+
node: SyntaxNode,
96+
}
97+
98+
impl AttrsOwnerNode {
99+
pub fn new<N: AttrsOwner>(node: N) -> Self {
100+
AttrsOwnerNode { node: node.syntax().clone() }
101+
}
102+
}
103+
104+
impl AttrsOwner for AttrsOwnerNode {}
105+
impl AstNode for AttrsOwnerNode {
106+
fn can_cast(_: SyntaxKind) -> bool
107+
where
108+
Self: Sized,
109+
{
110+
false
111+
}
112+
fn cast(_: SyntaxNode) -> Option<Self>
113+
where
114+
Self: Sized,
115+
{
116+
None
117+
}
118+
fn syntax(&self) -> &SyntaxNode {
119+
&self.node
120+
}
121+
}
122+
93123
#[derive(Debug, Clone, PartialEq, Eq)]
94124
pub enum AttrKind {
95125
Inner,

0 commit comments

Comments
 (0)