aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-19 21:20:43 +0000
committerGitHub <[email protected]>2021-03-19 21:20:43 +0000
commit8b16af590dd3d241bec07f69f4d4dadae9a4b523 (patch)
tree79729a2efc6d2cdb2557cd313ee79a25245983d3 /crates/syntax/src/ast
parentfc21640a65b5caef8dbbc9e85e9616b843847fb4 (diff)
parent636de3c709a7c86a1d3a870dc5dc3566310e9d92 (diff)
Merge #8112
8112: Revamp `hir_def` attribute API r=Veykril a=jonas-schievink This adds `AttrsWithOwner`, which can construct an accurate `AttrSourceMap` without requiring additional information from the caller. r? @Veykril Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r--crates/syntax/src/ast/node_ext.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 5a9834cbb..01f580a40 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -90,6 +90,36 @@ impl NameOwner for Macro {
90 90
91impl AttrsOwner for Macro {} 91impl AttrsOwner for Macro {}
92 92
93/// Basically an owned `dyn AttrsOwner` without extra boxing.
94pub struct AttrsOwnerNode {
95 node: SyntaxNode,
96}
97
98impl AttrsOwnerNode {
99 pub fn new<N: AttrsOwner>(node: N) -> Self {
100 AttrsOwnerNode { node: node.syntax().clone() }
101 }
102}
103
104impl AttrsOwner for AttrsOwnerNode {}
105impl 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
93#[derive(Debug, Clone, PartialEq, Eq)] 123#[derive(Debug, Clone, PartialEq, Eq)]
94pub enum AttrKind { 124pub enum AttrKind {
95 Inner, 125 Inner,