@@ -97,8 +97,11 @@ impl<T> Parse<T> {
97
97
pub fn syntax_node ( & self ) -> SyntaxNode {
98
98
SyntaxNode :: new_root ( self . green . clone ( ) )
99
99
}
100
- pub fn errors ( & self ) -> & [ SyntaxError ] {
101
- self . errors . as_deref ( ) . unwrap_or_default ( )
100
+
101
+ pub fn errors ( & self ) -> Vec < SyntaxError > {
102
+ let mut errors = if let Some ( e) = self . errors . as_deref ( ) { e. to_vec ( ) } else { vec ! [ ] } ;
103
+ validation:: validate ( & self . syntax_node ( ) , & mut errors) ;
104
+ errors
102
105
}
103
106
}
104
107
@@ -111,10 +114,10 @@ impl<T: AstNode> Parse<T> {
111
114
T :: cast ( self . syntax_node ( ) ) . unwrap ( )
112
115
}
113
116
114
- pub fn ok ( self ) -> Result < T , Arc < [ SyntaxError ] > > {
115
- match self . errors {
116
- Some ( e ) => Err ( e ) ,
117
- None => Ok ( self . tree ( ) ) ,
117
+ pub fn ok ( self ) -> Result < T , Vec < SyntaxError > > {
118
+ match self . errors ( ) {
119
+ errors if !errors . is_empty ( ) => Err ( errors ) ,
120
+ _ => Ok ( self . tree ( ) ) ,
118
121
}
119
122
}
120
123
}
@@ -132,7 +135,7 @@ impl Parse<SyntaxNode> {
132
135
impl Parse < SourceFile > {
133
136
pub fn debug_dump ( & self ) -> String {
134
137
let mut buf = format ! ( "{:#?}" , self . tree( ) . syntax( ) ) ;
135
- for err in self . errors . as_deref ( ) . into_iter ( ) . flat_map ( < [ _ ] > :: iter ) {
138
+ for err in self . errors ( ) {
136
139
format_to ! ( buf, "error {:?}: {}\n " , err. range( ) , err) ;
137
140
}
138
141
buf
@@ -169,11 +172,9 @@ pub use crate::ast::SourceFile;
169
172
impl SourceFile {
170
173
pub fn parse ( text : & str ) -> Parse < SourceFile > {
171
174
let _p = tracing:: span!( tracing:: Level :: INFO , "SourceFile::parse" ) . entered ( ) ;
172
- let ( green, mut errors) = parsing:: parse_text ( text) ;
175
+ let ( green, errors) = parsing:: parse_text ( text) ;
173
176
let root = SyntaxNode :: new_root ( green. clone ( ) ) ;
174
177
175
- errors. extend ( validation:: validate ( & root) ) ;
176
-
177
178
assert_eq ! ( root. kind( ) , SyntaxKind :: SOURCE_FILE ) ;
178
179
Parse {
179
180
green,
0 commit comments