@@ -97,8 +97,11 @@ impl<T> Parse<T> {
9797 pub fn syntax_node ( & self ) -> SyntaxNode {
9898 SyntaxNode :: new_root ( self . green . clone ( ) )
9999 }
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
102105 }
103106}
104107
@@ -111,10 +114,10 @@ impl<T: AstNode> Parse<T> {
111114 T :: cast ( self . syntax_node ( ) ) . unwrap ( )
112115 }
113116
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 ( ) ) ,
118121 }
119122 }
120123}
@@ -132,7 +135,7 @@ impl Parse<SyntaxNode> {
132135impl Parse < SourceFile > {
133136 pub fn debug_dump ( & self ) -> String {
134137 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 ( ) {
136139 format_to ! ( buf, "error {:?}: {}\n " , err. range( ) , err) ;
137140 }
138141 buf
@@ -169,11 +172,9 @@ pub use crate::ast::SourceFile;
169172impl SourceFile {
170173 pub fn parse ( text : & str ) -> Parse < SourceFile > {
171174 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) ;
173176 let root = SyntaxNode :: new_root ( green. clone ( ) ) ;
174177
175- errors. extend ( validation:: validate ( & root) ) ;
176-
177178 assert_eq ! ( root. kind( ) , SyntaxKind :: SOURCE_FILE ) ;
178179 Parse {
179180 green,
0 commit comments