diff --git a/crates/analyzer/src/traversal/types.rs b/crates/analyzer/src/traversal/types.rs index c37a28dad2..99274a494a 100644 --- a/crates/analyzer/src/traversal/types.rs +++ b/crates/analyzer/src/traversal/types.rs @@ -575,7 +575,6 @@ pub fn type_desc( if let Some(val) = self_type { Ok(Type::SelfType(val).id(context.db())) } else { - dbg!("Reporting error"); Err(TypeError::new(context.error( "`Self` can not be used here", desc.span, diff --git a/crates/parser2/src/parser/attr.rs b/crates/parser2/src/parser/attr.rs index 827d2fb073..883032283c 100644 --- a/crates/parser2/src/parser/attr.rs +++ b/crates/parser2/src/parser/attr.rs @@ -4,7 +4,7 @@ use crate::SyntaxKind; pub(super) fn parse_attr_list(parser: &mut Parser) -> Option { if let Some(SyntaxKind::DocComment) | Some(SyntaxKind::Pound) = parser.current_kind() { - Some(parser.parse(super::attr::AttrListScope::default(), None).1) + Some(parser.parse(AttrListScope::default(), None).1) } else { None } diff --git a/crates/parser2/src/parser/expr_atom.rs b/crates/parser2/src/parser/expr_atom.rs index 1e0cf5c9b0..9b759d3fae 100644 --- a/crates/parser2/src/parser/expr_atom.rs +++ b/crates/parser2/src/parser/expr_atom.rs @@ -105,21 +105,21 @@ impl super::Parse for IfExprScope { parser.parse(BlockExprScope::default(), None); if parser.current_kind() == Some(SyntaxKind::ElseKw) { - parser.with_next_expected_tokens( + parser.bump_expected(SyntaxKind::ElseKw); + + parser.with_recovery_tokens( |parser| { - parser.bump_expected(SyntaxKind::ElseKw); + if matches!( + parser.current_kind(), + Some(SyntaxKind::LBrace | SyntaxKind::IfKw) + ) { + parse_expr(parser); + } else { + parser.error_and_recover("expected `{` or `if` after `else`", None); + } }, &[SyntaxKind::LBrace, SyntaxKind::IfKw], ); - - if !matches!( - parser.current_kind(), - Some(SyntaxKind::LBrace | SyntaxKind::IfKw) - ) { - parser.error_and_recover("expected `{` or `if` after `else`", None); - return; - } - parse_expr(parser); } } } diff --git a/crates/parser2/src/parser/item.rs b/crates/parser2/src/parser/item.rs index 7c8f50c56b..cfbfef6b33 100644 --- a/crates/parser2/src/parser/item.rs +++ b/crates/parser2/src/parser/item.rs @@ -279,7 +279,7 @@ impl super::Parse for VariantDefListScope { if !parser.bump_if(SyntaxKind::Comma) && parser.current_kind() != Some(SyntaxKind::RBrace) { - parser.error_at_current_pos("expected comma after enum variant definition"); + parser.error("expected comma after enum variant definition"); } } @@ -453,22 +453,20 @@ impl super::Parse for ConstScope { parser.with_next_expected_tokens( |parser| { - parser.bump_or_recover( - SyntaxKind::Colon, - "expected type annotation for `const`", - None, - ); - parse_type(parser, None); + if parser.bump_if(SyntaxKind::Colon) { + parse_type(parser, None); + } else { + parser.error_and_recover("expected type annotation for `const`", None); + } }, &[SyntaxKind::Eq], ); - if !parser.bump_if(SyntaxKind::Eq) { + if parser.bump_if(SyntaxKind::Eq) { + parse_expr(parser); + } else { parser.error_and_recover("expected `=` for const value definition", None); - return; } - - parse_expr(parser); } } @@ -485,7 +483,7 @@ impl super::Parse for ExternScope { } } -define_scope! { ExternItemListScope, ExternItemList, Override(RBrace, FnKw) } +define_scope! { ExternItemListScope, ExternItemList, Override(RBrace, PubKw, UnsafeKw, FnKw) } impl super::Parse for ExternItemListScope { fn parse(&mut self, parser: &mut Parser) { parse_fn_item_block(parser, true, FuncDefScope::Extern); @@ -543,17 +541,21 @@ fn parse_fn_item_block( } let mut checkpoint = attr::parse_attr_list(parser); - let modifier_scope = ItemModifierScope::default(); - match parser.current_kind() { - Some(kind) if kind.is_modifier_head() && allow_modifier => { - if allow_modifier { - let (_, modifier_checkpoint) = parser.parse(modifier_scope, None); - checkpoint.get_or_insert(modifier_checkpoint); - } else { - parser.error_and_recover("modifier is not allowed in the block", checkpoint); + + loop { + match parser.current_kind() { + Some(kind) if kind.is_modifier_head() => { + if allow_modifier { + let (_, modifier_checkpoint) = + parser.parse(ItemModifierScope::default(), None); + checkpoint.get_or_insert(modifier_checkpoint); + } else { + parser + .unexpected_token_error("modifier is not allowed in this block", None); + } } + _ => break, } - _ => {} } match parser.current_kind() { @@ -561,7 +563,8 @@ fn parse_fn_item_block( parser.parse(FuncScope::new(fn_def_scope), checkpoint); } _ => { - parser.error_and_recover("only `fn` is allowed in the block", checkpoint); + parser.error_msg_on_current_token("only `fn` is allowed in this block"); + parser.recover(checkpoint); } } diff --git a/crates/parser2/src/parser/mod.rs b/crates/parser2/src/parser/mod.rs index f81a75aa4d..0940493b14 100644 --- a/crates/parser2/src/parser/mod.rs +++ b/crates/parser2/src/parser/mod.rs @@ -149,7 +149,7 @@ impl Parser { .iter() .all(|token| *token != self.current_kind().unwrap()) { - self.error_and_recover("unexpected token", None); + self.recover(None); } for token in expected_tokens { @@ -231,10 +231,8 @@ impl Parser { /// * If checkpoint is `None`, the current branch is wrapped up by an error /// node. pub fn error_and_recover(&mut self, msg: &str, checkpoint: Option) { - let err_scope = self.error(msg); - let checkpoint = self.enter(err_scope, checkpoint); - self.recover(); - self.leave(checkpoint); + self.error(msg); + self.recover(checkpoint); } /// Add `msg` as an error to the error list, then bumps consecutive tokens @@ -320,8 +318,9 @@ impl Parser { } } - /// Proceeds the parser to the recovery token of the current scope. - pub fn recover(&mut self) { + /// Consumes tokens until a recovery token is found, and reports an error on any + /// unexpexted tokens. + pub fn recover(&mut self, checkpoint: Option) { let mut recovery_set: FxHashSet = fxhash::FxHashSet::default(); let mut scope_index = self.parents.len() - 1; loop { @@ -346,8 +345,10 @@ impl Parser { } } - let is_newline_trivia = self.set_newline_as_trivia(false); - self.auxiliary_recovery_set.insert(SyntaxKind::Newline, 1); + if !self.is_newline_trivia { + self.add_recovery_token(SyntaxKind::Newline); + } + let mut unexpected = None; let mut open_brackets_in_error = FxHashMap::default(); while let Some(kind) = self.current_kind() { if kind.is_open_bracket_kind() { @@ -364,11 +365,35 @@ impl Parser { break; } } - + if unexpected.is_none() { + if !self.parents.is_empty() { + self.bump_trivias(); + } + unexpected = Some(( + self.current_pos, + checkpoint.unwrap_or_else(|| self.checkpoint()), + )); + } self.bump(); } - self.set_newline_as_trivia(is_newline_trivia); + if !self.is_newline_trivia { + self.remove_recovery_token(SyntaxKind::Newline); + } + + if let Some((start_pos, checkpoint)) = unexpected { + self.is_err = true; + if !self.is_dry_run() { + self.builder + .start_node_at(checkpoint, SyntaxKind::Error.into()); + self.builder.finish_node(); + + self.errors.push(ParseError { + range: TextRange::new(start_pos, self.current_pos), + msg: "unexpected syntax".to_string(), + }); + } + } } /// Bumps the current token if the current token is the `expected` kind. @@ -381,7 +406,8 @@ impl Parser { checkpoint: Option, ) { if !self.bump_if(expected) { - self.error_and_recover(msg, checkpoint); + self.error(msg); + self.recover(checkpoint); } } @@ -444,8 +470,20 @@ impl Parser { } } - /// Add the `msg` to the error list. + /// Add the `msg` to the error list, at `current_pos`. fn error(&mut self, msg: &str) -> ErrorScope { + self.is_err = true; + let pos = self.current_pos; + self.errors.push(ParseError { + range: TextRange::new(pos, pos), + msg: msg.to_string(), + }); + ErrorScope::default() + } + + /// Add the `msg` to the error list, on `current_token()`. + /// Bumps trivias. + fn error_msg_on_current_token(&mut self, msg: &str) { self.bump_trivias(); self.is_err = true; let start = self.current_pos; @@ -454,23 +492,26 @@ impl Parser { } else { start }; - let range = TextRange::new(start, end); self.errors.push(ParseError { - range, + range: TextRange::new(start, end), msg: msg.to_string(), }); - ErrorScope::default() } - fn error_at_current_pos(&mut self, msg: &str) -> ErrorScope { - let pos = self.current_pos; - let range = TextRange::new(pos, pos); + /// Wrap the current token in a `SyntaxKind::Error`, and add `msg` to the error list. + fn unexpected_token_error(&mut self, msg: &str, checkpoint: Option) { + let checkpoint = self.enter(ErrorScope::default(), checkpoint); + + self.is_err = true; + let start_pos = self.current_pos; + self.bump(); + self.errors.push(ParseError { - range, + range: TextRange::new(start_pos, self.current_pos), msg: msg.to_string(), }); - ErrorScope::default() + self.leave(checkpoint); } /// Returns `true` if the parser is in the dry run mode. diff --git a/crates/parser2/src/parser/stmt.rs b/crates/parser2/src/parser/stmt.rs index 8e53be1b7f..fe6927511a 100644 --- a/crates/parser2/src/parser/stmt.rs +++ b/crates/parser2/src/parser/stmt.rs @@ -61,11 +61,18 @@ impl super::Parse for ForStmtScope { fn parse(&mut self, parser: &mut Parser) { parser.bump_expected(SyntaxKind::ForKw); - parser.with_next_expected_tokens(parse_pat, &[SyntaxKind::InKw, SyntaxKind::LBrace]); + parser.with_recovery_tokens(parse_pat, &[SyntaxKind::InKw, SyntaxKind::LBrace]); - parser.bump_or_recover(SyntaxKind::InKw, "expected `in` keyword", None); + parser.with_next_expected_tokens( + |p| { + if !p.bump_if(SyntaxKind::InKw) { + p.error("expected `in` keyword"); + } - parser.with_next_expected_tokens(parse_expr_no_struct, &[SyntaxKind::LBrace]); + parse_expr_no_struct(p); + }, + &[SyntaxKind::LBrace], + ); if parser.current_kind() != Some(SyntaxKind::LBrace) { parser.error_and_recover("expected block", None); diff --git a/crates/parser2/src/parser/struct_.rs b/crates/parser2/src/parser/struct_.rs index 521da7cccc..3729f0dc1b 100644 --- a/crates/parser2/src/parser/struct_.rs +++ b/crates/parser2/src/parser/struct_.rs @@ -67,7 +67,7 @@ impl super::Parse for RecordFieldDefListScope { if !parser.bump_if(SyntaxKind::Comma) && parser.current_kind() != Some(SyntaxKind::RBrace) { - parser.error_at_current_pos("expected comma after field definition"); + parser.error("expected comma after field definition"); } } @@ -99,8 +99,8 @@ impl super::Parse for RecordFieldDefScope { // 2. We anticipate that this error would happen often in the transition period // to Fe-V2. if parser.current_kind() == Some(SyntaxKind::FnKw) { - let err_scope = parser.error("function definition in struct is not allowed"); - let checkpoint = parser.enter(err_scope, None); + parser.error_msg_on_current_token("function definition in struct is not allowed"); + let checkpoint = parser.enter(super::ErrorScope::new(), None); parser.parse(FuncScope::default(), None); parser.leave(checkpoint); return; diff --git a/crates/parser2/src/parser/type_.rs b/crates/parser2/src/parser/type_.rs index 0f28481644..a931d24a7c 100644 --- a/crates/parser2/src/parser/type_.rs +++ b/crates/parser2/src/parser/type_.rs @@ -89,7 +89,11 @@ impl super::Parse for TupleTypeScope { } if !parser.bump_if(SyntaxKind::RParen) { + // If the close paren is missing, we want to recover on a newline, + // so we have to explicitly set newlines to be non-trivia. + parser.set_newline_as_trivia(false); parser.error_and_recover("expected `)`", None); + parser.set_newline_as_trivia(true); parser.bump_if(SyntaxKind::RParen); } } diff --git a/crates/parser2/src/parser/use_tree.rs b/crates/parser2/src/parser/use_tree.rs index 0d5caf54fe..58c09c8e92 100644 --- a/crates/parser2/src/parser/use_tree.rs +++ b/crates/parser2/src/parser/use_tree.rs @@ -23,7 +23,7 @@ impl super::Parse for UseTreeScope { if parser.current_kind() == Some(SyntaxKind::AsKw) { if is_glob { - parser.error_and_recover("can't use `as` with `*`", None); + parser.error_msg_on_current_token("can't use `as` with `*`"); } if parser.current_kind() == Some(SyntaxKind::AsKw) { parser.parse(UseTreeAliasScope::default(), None); @@ -34,14 +34,12 @@ impl super::Parse for UseTreeScope { if !parser.bump_if(SyntaxKind::Colon2) { return; } - match parser.current_kind() { - Some(SyntaxKind::LBrace) if !is_glob => { - parser.parse(UseTreeListScope::default(), None); - } - _ => { - parser.error_and_recover("can't use `*` with `{}`", None); + if parser.current_kind() == Some(SyntaxKind::LBrace) { + if is_glob { + parser.error_msg_on_current_token("can't use `*` with `{}`"); } - }; + parser.parse(UseTreeListScope::default(), None); + } } } @@ -90,7 +88,7 @@ impl super::Parse for UsePathScope { }); if is_path_segment { if self.is_glob.get() { - parser.error_and_recover("can't specify path after `*`", None); + parser.error_msg_on_current_token("can't specify path after `*`"); } parser.bump_expected(SyntaxKind::Colon2); self.is_glob diff --git a/crates/parser2/test_files/error_recovery/exprs/array.snap b/crates/parser2/test_files/error_recovery/exprs/array.snap index fc44b5596d..f5531d8d5d 100644 --- a/crates/parser2/test_files/error_recovery/exprs/array.snap +++ b/crates/parser2/test_files/error_recovery/exprs/array.snap @@ -35,6 +35,5 @@ Root@0..19 Lit@16..17 Int@16..17 "2" Comma@17..18 "," - Error@18..18 RBracket@18..19 "]" diff --git a/crates/parser2/test_files/error_recovery/exprs/call.snap b/crates/parser2/test_files/error_recovery/exprs/call.snap index 1573ecfd13..f6369fd7a7 100644 --- a/crates/parser2/test_files/error_recovery/exprs/call.snap +++ b/crates/parser2/test_files/error_recovery/exprs/call.snap @@ -66,7 +66,6 @@ Root@0..40 PathType@32..32 Path@32..32 PathSegment@32..32 - Error@32..32 Gt@32..33 ">" CallArgList@33..39 LParen@33..34 "(" diff --git a/crates/parser2/test_files/error_recovery/exprs/if_.snap b/crates/parser2/test_files/error_recovery/exprs/if_.snap index 116fcd04b5..34feb493dc 100644 --- a/crates/parser2/test_files/error_recovery/exprs/if_.snap +++ b/crates/parser2/test_files/error_recovery/exprs/if_.snap @@ -20,7 +20,7 @@ Root@0..101 Newline@8..9 "\n" RBrace@9..10 "}" Newline@10..12 "\n\n" - IfExpr@12..31 + IfExpr@12..28 IfKw@12..14 "if" WhiteSpace@14..15 " " PathExpr@15..16 @@ -37,12 +37,12 @@ Root@0..101 WhiteSpace@26..27 " " Error@27..28 Ident@27..28 "x" - WhiteSpace@28..29 " " - BlockExpr@29..31 - LBrace@29..30 "{" - RBrace@30..31 "}" + WhiteSpace@28..29 " " + BlockExpr@29..31 + LBrace@29..30 "{" + RBrace@30..31 "}" Newline@31..33 "\n\n" - IfExpr@33..66 + IfExpr@33..48 IfKw@33..35 "if" WhiteSpace@35..36 " " PathExpr@36..37 @@ -59,28 +59,28 @@ Root@0..101 WhiteSpace@46..47 " " Error@47..48 Ident@47..48 "x" - WhiteSpace@48..49 " " - IfExpr@49..66 - IfKw@49..51 "if" - WhiteSpace@51..52 " " - PathExpr@52..53 - Path@52..53 - PathSegment@52..53 - Ident@52..53 "x" - WhiteSpace@53..54 " " - BlockExpr@54..57 - LBrace@54..55 "{" - WhiteSpace@55..56 " " - RBrace@56..57 "}" - WhiteSpace@57..58 " " - ElseKw@58..62 "else" - WhiteSpace@62..63 " " - BlockExpr@63..66 - LBrace@63..64 "{" - WhiteSpace@64..65 " " - RBrace@65..66 "}" + WhiteSpace@48..49 " " + IfExpr@49..66 + IfKw@49..51 "if" + WhiteSpace@51..52 " " + PathExpr@52..53 + Path@52..53 + PathSegment@52..53 + Ident@52..53 "x" + WhiteSpace@53..54 " " + BlockExpr@54..57 + LBrace@54..55 "{" + WhiteSpace@55..56 " " + RBrace@56..57 "}" + WhiteSpace@57..58 " " + ElseKw@58..62 "else" + WhiteSpace@62..63 " " + BlockExpr@63..66 + LBrace@63..64 "{" + WhiteSpace@64..65 " " + RBrace@65..66 "}" Newline@66..68 "\n\n" - IfExpr@68..100 + IfExpr@68..101 IfKw@68..70 "if" WhiteSpace@70..71 " " PathExpr@71..72 @@ -88,7 +88,7 @@ Root@0..101 PathSegment@71..72 Ident@71..72 "x" WhiteSpace@72..73 " " - BlockExpr@73..100 + BlockExpr@73..101 LBrace@73..74 "{" Newline@74..75 "\n" WhiteSpace@75..79 " " @@ -98,18 +98,16 @@ Root@0..101 Int@79..81 "10" WhiteSpace@81..85 " " Newline@85..86 "\n" - ExprStmt@86..92 - Error@86..92 + ExprStmt@86..100 + Error@86..100 ElseKw@86..90 "else" WhiteSpace@90..91 " " LBrace@91..92 "{" - Newline@92..93 "\n" - WhiteSpace@93..97 " " - ExprStmt@97..98 - LitExpr@97..98 - Lit@97..98 - Int@97..98 "1" - Newline@98..99 "\n" - RBrace@99..100 "}" - Newline@100..101 "\n" + Newline@92..93 "\n" + WhiteSpace@93..97 " " + Int@97..98 "1" + Newline@98..99 "\n" + RBrace@99..100 "}" + Newline@100..101 "\n" + Error@101..101 diff --git a/crates/parser2/test_files/error_recovery/exprs/index.snap b/crates/parser2/test_files/error_recovery/exprs/index.snap index cd5a52c44d..aa3cbcdcae 100644 --- a/crates/parser2/test_files/error_recovery/exprs/index.snap +++ b/crates/parser2/test_files/error_recovery/exprs/index.snap @@ -34,8 +34,6 @@ Root@0..20 LitExpr@13..14 Lit@13..14 Int@13..14 "3" - Error@14..14 - Error@14..14 Newline@14..15 "\n" IndexExpr@15..20 PathExpr@15..16 diff --git a/crates/parser2/test_files/error_recovery/exprs/match_.snap b/crates/parser2/test_files/error_recovery/exprs/match_.snap index 39f6b55436..89d7442001 100644 --- a/crates/parser2/test_files/error_recovery/exprs/match_.snap +++ b/crates/parser2/test_files/error_recovery/exprs/match_.snap @@ -41,9 +41,6 @@ Root@0..94 Path@35..38 PathSegment@35..38 Ident@35..38 "Bar" - Error@38..38 - Error@38..38 - Error@38..38 Newline@38..39 "\n" RBrace@39..40 "}" WhiteSpace@40..41 " " @@ -83,9 +80,6 @@ Root@0..94 PathPat@70..70 Path@70..70 PathSegment@70..70 - Error@70..70 - Error@70..70 - Error@70..70 FatArrow@70..72 "=>" WhiteSpace@72..73 " " LitExpr@73..77 diff --git a/crates/parser2/test_files/error_recovery/exprs/method.snap b/crates/parser2/test_files/error_recovery/exprs/method.snap index 98ad9e7542..c102ef6f2b 100644 --- a/crates/parser2/test_files/error_recovery/exprs/method.snap +++ b/crates/parser2/test_files/error_recovery/exprs/method.snap @@ -36,7 +36,6 @@ Root@0..78 PathType@24..24 Path@24..24 PathSegment@24..24 - Error@24..24 Gt@24..25 ">" CallArgList@25..31 LParen@25..26 "(" @@ -79,7 +78,6 @@ Root@0..78 Ident@49..50 "E" Comma@50..51 "," CallArg@51..51 - Error@51..51 RParen@51..52 ")" Newline@52..54 "\n\n" MethodCallExpr@54..78 diff --git a/crates/parser2/test_files/error_recovery/items/const_.snap b/crates/parser2/test_files/error_recovery/items/const_.snap index 582943fa80..6790a63299 100644 --- a/crates/parser2/test_files/error_recovery/items/const_.snap +++ b/crates/parser2/test_files/error_recovery/items/const_.snap @@ -11,11 +11,6 @@ Root@0..44 WhiteSpace@5..6 " " Ident@6..7 "X" WhiteSpace@7..8 " " - Error@8..8 - PathType@8..8 - Path@8..8 - PathSegment@8..8 - Error@8..8 Eq@8..9 "=" WhiteSpace@9..10 " " LitExpr@10..12 @@ -23,7 +18,7 @@ Root@0..44 Int@10..12 "10" Newline@12..14 "\n\n" Item@14..29 - Const@14..27 + Const@14..26 ConstKw@14..19 "const" WhiteSpace@19..20 " " Ident@20..21 "X" @@ -33,9 +28,7 @@ Root@0..44 Path@23..26 PathSegment@23..26 Ident@23..26 "i32" - WhiteSpace@26..27 " " - Error@27..27 - Error@27..27 + WhiteSpace@26..27 " " Newline@27..29 "\n\n" Item@29..44 Const@29..44 diff --git a/crates/parser2/test_files/error_recovery/items/enum_.snap b/crates/parser2/test_files/error_recovery/items/enum_.snap index 0b90dbc1e4..a931adb74d 100644 --- a/crates/parser2/test_files/error_recovery/items/enum_.snap +++ b/crates/parser2/test_files/error_recovery/items/enum_.snap @@ -23,9 +23,9 @@ Root@0..151 LBrace@19..20 "{" Newline@20..21 "\n" WhiteSpace@21..25 " " - VariantDef@25..39 + VariantDef@25..33 Ident@25..26 "X" - TupleType@26..39 + TupleType@26..33 LParen@26..27 "(" PathType@27..30 Path@27..30 @@ -37,10 +37,10 @@ Root@0..151 Path@32..33 PathSegment@32..33 Ident@32..33 "T" - Newline@33..34 "\n" - WhiteSpace@34..38 " " - Error@38..39 - Ident@38..39 "A" + Newline@33..34 "\n" + WhiteSpace@34..38 " " + VariantDef@38..39 + Ident@38..39 "A" Newline@39..40 "\n" WhiteSpace@40..44 " " VariantDef@44..53 @@ -115,7 +115,6 @@ Root@0..151 WhiteSpace@112..113 " " KindBoundMono@113..114 Star@113..114 "*" - Error@114..114 Newline@114..115 "\n" WhiteSpace@115..119 " " WherePredicate@119..129 diff --git a/crates/parser2/test_files/error_recovery/items/func.snap b/crates/parser2/test_files/error_recovery/items/func.snap index efd0618d1e..9c9c2cd676 100644 --- a/crates/parser2/test_files/error_recovery/items/func.snap +++ b/crates/parser2/test_files/error_recovery/items/func.snap @@ -112,8 +112,6 @@ Root@0..133 WhiteSpace@91..92 " " Ident@92..97 "Trait" Gt@97..98 ">" - Error@98..98 - Error@98..98 FuncParamList@98..106 LParen@98..99 "(" FnParam@99..105 diff --git a/crates/parser2/test_files/error_recovery/items/impl_.snap b/crates/parser2/test_files/error_recovery/items/impl_.snap index cc199736ec..be69f26108 100644 --- a/crates/parser2/test_files/error_recovery/items/impl_.snap +++ b/crates/parser2/test_files/error_recovery/items/impl_.snap @@ -28,9 +28,6 @@ Root@0..56 PathType@17..17 Path@17..17 PathSegment@17..17 - Error@17..17 - Error@17..17 - Error@17..17 WhereClause@17..34 WhereKw@17..22 "where" WhiteSpace@22..23 " " @@ -74,7 +71,6 @@ Root@0..56 PathType@51..51 Path@51..51 PathSegment@51..51 - Error@51..51 Gt@51..52 ">" Newline@52..53 "\n" ImplItemList@53..56 diff --git a/crates/parser2/test_files/error_recovery/items/impl_trait.snap b/crates/parser2/test_files/error_recovery/items/impl_trait.snap index d5e0333cd0..e85dcdad90 100644 --- a/crates/parser2/test_files/error_recovery/items/impl_trait.snap +++ b/crates/parser2/test_files/error_recovery/items/impl_trait.snap @@ -34,24 +34,22 @@ Root@0..90 WhiteSpace@14..15 " " ForKw@15..18 "for" WhiteSpace@18..19 " " - PathType@19..23 + PathType@19..22 Path@19..20 PathSegment@19..20 Ident@19..20 "Y" - GenericArgList@20..23 + GenericArgList@20..22 Lt@20..21 "<" - TypeGenericArg@21..23 + TypeGenericArg@21..22 PathType@21..22 Path@21..22 PathSegment@21..22 Ident@21..22 "T" - WhiteSpace@22..23 " " - Error@23..23 - Error@23..23 - WhereClause@23..34 + WhiteSpace@22..23 " " + WhereClause@23..33 WhereKw@23..28 "where" WhiteSpace@28..29 " " - WherePredicate@29..34 + WherePredicate@29..33 PathType@29..30 Path@29..30 PathSegment@29..30 @@ -64,8 +62,7 @@ Root@0..90 Path@32..33 PathSegment@32..33 Ident@32..33 "X" - WhiteSpace@33..34 " " - Error@34..34 + WhiteSpace@33..34 " " ImplTraitItemList@34..36 LBrace@34..35 "{" RBrace@35..36 "}" @@ -74,11 +71,11 @@ Root@0..90 ImplTrait@38..71 ImplKw@38..42 "impl" WhiteSpace@42..43 " " - TraitRef@43..50 + TraitRef@43..49 Path@43..44 PathSegment@43..44 Ident@43..44 "X" - GenericArgList@44..50 + GenericArgList@44..49 Lt@44..45 "<" TypeGenericArg@45..46 PathType@45..46 @@ -87,34 +84,30 @@ Root@0..90 Ident@45..46 "T" Comma@46..47 "," WhiteSpace@47..48 " " - TypeGenericArg@48..50 + TypeGenericArg@48..49 PathType@48..49 Path@48..49 PathSegment@48..49 Ident@48..49 "u" - WhiteSpace@49..50 " " - Error@50..50 - Error@50..50 + WhiteSpace@49..50 " " ForKw@50..53 "for" WhiteSpace@53..54 " " - PathType@54..58 + PathType@54..57 Path@54..55 PathSegment@54..55 Ident@54..55 "Y" - GenericArgList@55..58 + GenericArgList@55..57 Lt@55..56 "<" - TypeGenericArg@56..58 + TypeGenericArg@56..57 PathType@56..57 Path@56..57 PathSegment@56..57 Ident@56..57 "T" - WhiteSpace@57..58 " " - Error@58..58 - Error@58..58 - WhereClause@58..69 + WhiteSpace@57..58 " " + WhereClause@58..68 WhereKw@58..63 "where" WhiteSpace@63..64 " " - WherePredicate@64..69 + WherePredicate@64..68 PathType@64..65 Path@64..65 PathSegment@64..65 @@ -127,8 +120,7 @@ Root@0..90 Path@67..68 PathSegment@67..68 Ident@67..68 "X" - WhiteSpace@68..69 " " - Error@69..69 + WhiteSpace@68..69 " " ImplTraitItemList@69..71 LBrace@69..70 "{" RBrace@70..71 "}" diff --git a/crates/parser2/test_files/error_recovery/items/struct_.snap b/crates/parser2/test_files/error_recovery/items/struct_.snap index 84290b8a94..c1e8787114 100644 --- a/crates/parser2/test_files/error_recovery/items/struct_.snap +++ b/crates/parser2/test_files/error_recovery/items/struct_.snap @@ -11,28 +11,24 @@ Root@0..160 PubKw@0..3 "pub" WhiteSpace@3..4 " " StructKw@4..10 "struct" - Error@10..10 - GenericParamList@10..16 + GenericParamList@10..15 Lt@10..11 "<" TypeGenericParam@11..12 Ident@11..12 "T" Comma@12..13 "," WhiteSpace@13..14 " " - TypeGenericParam@14..16 + TypeGenericParam@14..15 Ident@14..15 "U" - Newline@15..16 "\n" - Error@16..16 - Error@16..16 + Newline@15..16 "\n" WhereClause@16..40 WhereKw@16..21 "where" WhiteSpace@21..22 " " - WherePredicate@22..24 + WherePredicate@22..23 PathType@22..23 Path@22..23 PathSegment@22..23 Ident@22..23 "T" - WhiteSpace@23..24 " " - Error@24..24 + WhiteSpace@23..24 " " Newline@24..25 "\n" WhiteSpace@25..31 " " WherePredicate@31..40 @@ -57,8 +53,6 @@ Root@0..160 WhiteSpace@47..51 " " RecordFieldDef@51..54 Ident@51..54 "foo" - Error@54..54 - Error@54..54 Newline@54..55 "\n" WhiteSpace@55..59 " " RecordFieldDef@59..72 diff --git a/crates/parser2/test_files/error_recovery/items/trait_.snap b/crates/parser2/test_files/error_recovery/items/trait_.snap index 74f5cac32f..453cb4fd1c 100644 --- a/crates/parser2/test_files/error_recovery/items/trait_.snap +++ b/crates/parser2/test_files/error_recovery/items/trait_.snap @@ -20,7 +20,6 @@ Root@0..133 Ident@13..14 "Y" Comma@14..15 "," TypeGenericParam@15..15 - Error@15..15 Gt@15..16 ">" TraitItemList@16..18 LBrace@16..17 "{" @@ -38,15 +37,12 @@ Root@0..133 Comma@31..32 "," WhiteSpace@32..33 " " TypeGenericParam@33..33 - Error@33..33 - Error@33..33 - Error@33..33 TraitItemList@33..35 LBrace@33..34 "{" RBrace@34..35 "}" Newline@35..37 "\n\n" Item@37..53 - Trait@37..53 + Trait@37..51 TraitKw@37..42 "trait" WhiteSpace@42..43 " " Ident@43..46 "Bar" @@ -57,13 +53,8 @@ Root@0..133 Comma@48..49 "," WhiteSpace@49..50 " " TypeGenericParam@50..50 - Error@50..50 Gt@50..51 ">" - Newline@51..53 "\n\n" - Error@53..53 - Error@53..53 - Error@53..53 - Error@53..53 + Newline@51..53 "\n\n" Item@53..87 Trait@53..85 TraitKw@53..58 "trait" @@ -79,13 +70,12 @@ Root@0..133 Ident@66..67 "T" Comma@67..68 "," TypeGenericParam@68..68 - Error@68..68 Gt@68..69 ">" WhiteSpace@69..70 " " - WhereClause@70..83 + WhereClause@70..82 WhereKw@70..75 "where" WhiteSpace@75..76 " " - WherePredicate@76..83 + WherePredicate@76..82 PathType@76..77 Path@76..77 PathSegment@76..77 @@ -98,8 +88,7 @@ Root@0..133 Path@79..82 PathSegment@79..82 Ident@79..82 "Add" - WhiteSpace@82..83 " " - Error@83..83 + WhiteSpace@82..83 " " TraitItemList@83..85 LBrace@83..84 "{" RBrace@84..85 "}" diff --git a/crates/parser2/test_files/error_recovery/items/type_.snap b/crates/parser2/test_files/error_recovery/items/type_.snap index 38febb6a43..2b16a62168 100644 --- a/crates/parser2/test_files/error_recovery/items/type_.snap +++ b/crates/parser2/test_files/error_recovery/items/type_.snap @@ -17,9 +17,6 @@ Root@0..72 Comma@13..14 "," WhiteSpace@14..15 " " TypeGenericParam@15..15 - Error@15..15 - Error@15..15 - Error@15..15 Eq@15..16 "=" WhiteSpace@16..17 " " PathType@17..29 diff --git a/crates/parser2/test_files/error_recovery/items/use_.snap b/crates/parser2/test_files/error_recovery/items/use_.snap index e9f2c8d85a..120cd71b40 100644 --- a/crates/parser2/test_files/error_recovery/items/use_.snap +++ b/crates/parser2/test_files/error_recovery/items/use_.snap @@ -19,7 +19,6 @@ Root@0..63 Colon2@12..14 "::" UsePathSegment@14..15 Star@14..15 "*" - Error@15..15 Colon2@15..17 "::" UsePathSegment@17..18 Ident@17..18 "A" @@ -39,12 +38,18 @@ Root@0..63 UsePathSegment@33..34 Star@33..34 "*" Colon2@34..36 "::" - Error@36..42 + UseTreeList@36..42 LBrace@36..37 "{" - Ident@37..38 "A" + UseTree@37..38 + UsePath@37..38 + UsePathSegment@37..38 + Ident@37..38 "A" Comma@38..39 "," WhiteSpace@39..40 " " - Ident@40..41 "B" + UseTree@40..41 + UsePath@40..41 + UsePathSegment@40..41 + Ident@40..41 "B" RBrace@41..42 "}" Newline@42..43 "\n" Item@43..63 @@ -62,7 +67,7 @@ Root@0..63 UsePathSegment@57..58 Star@57..58 "*" WhiteSpace@58..59 " " - Error@59..63 + UseTreeRename@59..63 AsKw@59..61 "as" WhiteSpace@61..62 " " Ident@62..63 "B" diff --git a/crates/parser2/test_files/error_recovery/stmts/for_.fe b/crates/parser2/test_files/error_recovery/stmts/for_.fe index 764b7df3ee..38a3af19f2 100644 --- a/crates/parser2/test_files/error_recovery/stmts/for_.fe +++ b/crates/parser2/test_files/error_recovery/stmts/for_.fe @@ -1,7 +1,9 @@ +{ for i arr { } for in arr { } for @ in arr {} -for @ in arr x y {} \ No newline at end of file +for @ in arr x y {} +} \ No newline at end of file diff --git a/crates/parser2/test_files/error_recovery/stmts/for_.snap b/crates/parser2/test_files/error_recovery/stmts/for_.snap index 1d0c95cb47..f143788693 100644 --- a/crates/parser2/test_files/error_recovery/stmts/for_.snap +++ b/crates/parser2/test_files/error_recovery/stmts/for_.snap @@ -3,77 +3,91 @@ source: crates/parser2/tests/error_recovery.rs expression: node input_file: crates/parser2/test_files/error_recovery/stmts/for_.fe --- -Root@0..67 - ForStmt@0..29 - ForKw@0..3 "for" - WhiteSpace@3..4 " " - PathPat@4..5 - Path@4..5 - PathSegment@4..5 - Ident@4..5 "i" - WhiteSpace@5..6 " " - Error@6..9 - Ident@6..9 "arr" - WhiteSpace@9..10 " " - Error@10..13 - LBrace@10..11 "{" - WhiteSpace@11..12 " " - RBrace@12..13 "}" - Newline@13..15 "\n\n" - Error@15..25 - ForKw@15..18 "for" - WhiteSpace@18..19 " " - InKw@19..21 "in" - WhiteSpace@21..22 " " - Ident@22..25 "arr" - WhiteSpace@25..26 " " - BlockExpr@26..29 - LBrace@26..27 "{" - WhiteSpace@27..28 " " - RBrace@28..29 "}" - Newline@29..31 "\n\n" - ForStmt@31..46 - ForKw@31..34 "for" - WhiteSpace@34..35 " " - PathPat@35..36 - Path@35..36 - PathSegment@35..36 - Error@35..36 - InvalidToken@35..36 "@" - WhiteSpace@36..37 " " - InKw@37..39 "in" - WhiteSpace@39..40 " " - PathExpr@40..43 - Path@40..43 - PathSegment@40..43 - Ident@40..43 "arr" - WhiteSpace@43..44 " " - BlockExpr@44..46 - LBrace@44..45 "{" - RBrace@45..46 "}" - Newline@46..48 "\n\n" - ForStmt@48..67 - ForKw@48..51 "for" - WhiteSpace@51..52 " " - PathPat@52..53 - Path@52..53 - PathSegment@52..53 - Error@52..53 - InvalidToken@52..53 "@" - WhiteSpace@53..54 " " - InKw@54..56 "in" - WhiteSpace@56..57 " " - PathExpr@57..60 - Path@57..60 - PathSegment@57..60 - Ident@57..60 "arr" - WhiteSpace@60..61 " " - Error@61..64 - Ident@61..62 "x" - WhiteSpace@62..63 " " - Ident@63..64 "y" - WhiteSpace@64..65 " " - BlockExpr@65..67 - LBrace@65..66 "{" - RBrace@66..67 "}" +Root@0..71 + ExprStmt@0..71 + BlockExpr@0..71 + LBrace@0..1 "{" + Newline@1..2 "\n" + ForStmt@2..15 + ForKw@2..5 "for" + WhiteSpace@5..6 " " + PathPat@6..7 + Path@6..7 + PathSegment@6..7 + Ident@6..7 "i" + WhiteSpace@7..8 " " + PathExpr@8..11 + Path@8..11 + PathSegment@8..11 + Ident@8..11 "arr" + WhiteSpace@11..12 " " + BlockExpr@12..15 + LBrace@12..13 "{" + WhiteSpace@13..14 " " + RBrace@14..15 "}" + Newline@15..17 "\n\n" + ForStmt@17..31 + ForKw@17..20 "for" + WhiteSpace@20..21 " " + PathPat@21..21 + Path@21..21 + PathSegment@21..21 + InKw@21..23 "in" + WhiteSpace@23..24 " " + PathExpr@24..27 + Path@24..27 + PathSegment@24..27 + Ident@24..27 "arr" + WhiteSpace@27..28 " " + BlockExpr@28..31 + LBrace@28..29 "{" + WhiteSpace@29..30 " " + RBrace@30..31 "}" + Newline@31..33 "\n\n" + ForStmt@33..48 + ForKw@33..36 "for" + WhiteSpace@36..37 " " + PathPat@37..38 + Path@37..38 + PathSegment@37..38 + Error@37..38 + InvalidToken@37..38 "@" + WhiteSpace@38..39 " " + InKw@39..41 "in" + WhiteSpace@41..42 " " + PathExpr@42..45 + Path@42..45 + PathSegment@42..45 + Ident@42..45 "arr" + WhiteSpace@45..46 " " + BlockExpr@46..48 + LBrace@46..47 "{" + RBrace@47..48 "}" + Newline@48..50 "\n\n" + ForStmt@50..69 + ForKw@50..53 "for" + WhiteSpace@53..54 " " + PathPat@54..55 + Path@54..55 + PathSegment@54..55 + Error@54..55 + InvalidToken@54..55 "@" + WhiteSpace@55..56 " " + InKw@56..58 "in" + WhiteSpace@58..59 " " + PathExpr@59..62 + Path@59..62 + PathSegment@59..62 + Ident@59..62 "arr" + WhiteSpace@62..63 " " + Error@63..66 + Ident@63..64 "x" + WhiteSpace@64..65 " " + Ident@65..66 "y" + WhiteSpace@66..67 " " + BlockExpr@67..69 + LBrace@67..68 "{" + RBrace@68..69 "}" + Newline@69..70 "\n" + RBrace@70..71 "}" diff --git a/crates/parser2/test_files/error_recovery/stmts/while_.snap b/crates/parser2/test_files/error_recovery/stmts/while_.snap index 262ba63de1..80e8dcfd4a 100644 --- a/crates/parser2/test_files/error_recovery/stmts/while_.snap +++ b/crates/parser2/test_files/error_recovery/stmts/while_.snap @@ -39,20 +39,16 @@ Root@0..56 Int@33..34 "1" Newline@34..35 "\n" RBrace@35..36 "}" - ExprStmt@36..37 - Error@36..37 + ExprStmt@36..56 + Error@36..56 RBrace@36..37 "}" - Newline@37..38 "\n" - WhiteSpace@38..42 " " - Newline@42..43 "\n" - WhileStmt@43..56 - WhileKw@43..48 "while" - WhiteSpace@48..49 " " - LitExpr@49..53 - Lit@49..53 - TrueKw@49..53 "true" - WhiteSpace@53..54 " " - BlockExpr@54..56 + Newline@37..38 "\n" + WhiteSpace@38..42 " " + Newline@42..43 "\n" + WhileKw@43..48 "while" + WhiteSpace@48..49 " " + TrueKw@49..53 "true" + WhiteSpace@53..54 " " LBrace@54..55 "{" RBrace@55..56 "}" diff --git a/crates/uitest/fixtures/parser/array.fe b/crates/uitest/fixtures/parser/array.fe new file mode 100644 index 0000000000..05e71bdd22 --- /dev/null +++ b/crates/uitest/fixtures/parser/array.fe @@ -0,0 +1,4 @@ +fn f() { +[1, 2 a, 3] +[1, 2,] +} \ No newline at end of file diff --git a/crates/uitest/fixtures/parser/array.snap b/crates/uitest/fixtures/parser/array.snap new file mode 100644 index 0000000000..ded5f3a520 --- /dev/null +++ b/crates/uitest/fixtures/parser/array.snap @@ -0,0 +1,18 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/array.fe +--- +error[1-0001]: unexpected syntax + ┌─ array.fe:2:7 + │ +2 │ [1, 2 a, 3] + │ ^ unexpected syntax + +error[1-0001]: expected expression + ┌─ array.fe:3:7 + │ +3 │ [1, 2,] + │ ^ expected expression + + diff --git a/crates/uitest/fixtures/parser/block.fe b/crates/uitest/fixtures/parser/block.fe new file mode 100644 index 0000000000..ffdee30cae --- /dev/null +++ b/crates/uitest/fixtures/parser/block.fe @@ -0,0 +1,7 @@ +fn f() { +{ + let x: i32 u32 = 10 + let y = 10 + +} +} \ No newline at end of file diff --git a/crates/uitest/fixtures/parser/block.snap b/crates/uitest/fixtures/parser/block.snap new file mode 100644 index 0000000000..f9c92cf9dd --- /dev/null +++ b/crates/uitest/fixtures/parser/block.snap @@ -0,0 +1,18 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/block.fe +--- +error[1-0001]: expected newline after statement + ┌─ block.fe:3:15 + │ +3 │ let x: i32 u32 = 10 + │ ^ expected newline after statement + +error[1-0001]: unexpected syntax + ┌─ block.fe:3:16 + │ +3 │ let x: i32 u32 = 10 + │ ^^^^^^^^ unexpected syntax + + diff --git a/crates/uitest/fixtures/parser/call.fe b/crates/uitest/fixtures/parser/call.fe new file mode 100644 index 0000000000..8db93b0f78 --- /dev/null +++ b/crates/uitest/fixtures/parser/call.fe @@ -0,0 +1,5 @@ +fn f() { +foo(x, y a, z ;) + +foo(x, y) +} \ No newline at end of file diff --git a/crates/uitest/fixtures/parser/call.snap b/crates/uitest/fixtures/parser/call.snap new file mode 100644 index 0000000000..b723e6fad7 --- /dev/null +++ b/crates/uitest/fixtures/parser/call.snap @@ -0,0 +1,30 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/call.fe +--- +error[1-0001]: unexpected syntax + ┌─ call.fe:2:10 + │ +2 │ foo(x, y a, z ;) + │ ^ unexpected syntax + +error[1-0001]: unexpected syntax + ┌─ call.fe:2:15 + │ +2 │ foo(x, y a, z ;) + │ ^ unexpected syntax + +error[1-0001]: unexpected syntax + ┌─ call.fe:4:12 + │ +4 │ foo(x, y) + │ ^ unexpected syntax + +error[1-0001]: expected path segment + ┌─ call.fe:4:15 + │ +4 │ foo(x, y) + │ ^ expected path segment + + diff --git a/crates/uitest/fixtures/parser/const_.snap b/crates/uitest/fixtures/parser/const_.snap index a5d66b7bad..b20e4b9d4f 100644 --- a/crates/uitest/fixtures/parser/const_.snap +++ b/crates/uitest/fixtures/parser/const_.snap @@ -4,34 +4,16 @@ expression: diags input_file: crates/uitest/fixtures/parser/const_.fe --- error[1-0001]: expected type annotation for `const` - ┌─ const_.fe:1:9 + ┌─ const_.fe:1:8 │ 1 │ const X = 10 - │ ^ expected type annotation for `const` - -error[1-0001]: expected path segment - ┌─ const_.fe:1:9 - │ -1 │ const X = 10 - │ ^ expected path segment - -error[1-0001]: unexpected token - ┌─ const_.fe:3:14 - │ -3 │ const X: i32 - │ ╭─────────────^ -4 │ │ -5 │ │ const X: ]@ = 1 - │ ╰^ unexpected token + │ ^ expected type annotation for `const` error[1-0001]: expected `=` for const value definition - ┌─ const_.fe:3:14 - │ -3 │ const X: i32 - │ ╭─────────────^ -4 │ │ -5 │ │ const X: ]@ = 1 - │ ╰^ expected `=` for const value definition + ┌─ const_.fe:3:13 + │ +3 │ const X: i32 + │ ^ expected `=` for const value definition error[1-0001]: expected path segment ┌─ const_.fe:5:10 @@ -39,4 +21,10 @@ error[1-0001]: expected path segment 5 │ const X: ]@ = 1 │ ^ expected path segment +error[1-0001]: unexpected syntax + ┌─ const_.fe:5:10 + │ +5 │ const X: ]@ = 1 + │ ^^ unexpected syntax + diff --git a/crates/uitest/fixtures/parser/enum_.snap b/crates/uitest/fixtures/parser/enum_.snap index 22aec3fe41..a0515384a5 100644 --- a/crates/uitest/fixtures/parser/enum_.snap +++ b/crates/uitest/fixtures/parser/enum_.snap @@ -4,10 +4,16 @@ expression: diags input_file: crates/uitest/fixtures/parser/enum_.fe --- error[1-0001]: expected `)` - ┌─ enum_.fe:3:5 + ┌─ enum_.fe:2:13 │ -3 │ A - │ ^ expected `)` +2 │ X(u32, T + │ ^ expected `)` + +error[1-0001]: expected comma after enum variant definition + ┌─ enum_.fe:2:13 + │ +2 │ X(u32, T + │ ^ expected comma after enum variant definition error[1-0001]: expected comma after enum variant definition ┌─ enum_.fe:3:6 diff --git a/crates/uitest/fixtures/parser/extern_.snap b/crates/uitest/fixtures/parser/extern_.snap index 8b31e1f87b..ea4ed0fec5 100644 --- a/crates/uitest/fixtures/parser/extern_.snap +++ b/crates/uitest/fixtures/parser/extern_.snap @@ -3,10 +3,16 @@ source: crates/uitest/tests/parser.rs expression: diags input_file: crates/uitest/fixtures/parser/extern_.fe --- -error[1-0001]: only `fn` is allowed in the block +error[1-0001]: only `fn` is allowed in this block ┌─ extern_.fe:4:5 │ 4 │ struct Foo { - │ ^^^^^^ only `fn` is allowed in the block + │ ^^^^^^ only `fn` is allowed in this block + +error[1-0001]: unexpected syntax + ┌─ extern_.fe:4:5 + │ +4 │ struct Foo { + │ ^^^^^^^^^^^^ unexpected syntax diff --git a/crates/uitest/fixtures/parser/fn_missing_body.snap b/crates/uitest/fixtures/parser/fn_missing_body.snap index c3e90c894e..835c7fdcda 100644 --- a/crates/uitest/fixtures/parser/fn_missing_body.snap +++ b/crates/uitest/fixtures/parser/fn_missing_body.snap @@ -3,58 +3,22 @@ source: crates/uitest/tests/parser.rs expression: diags input_file: crates/uitest/fixtures/parser/fn_missing_body.fe --- -error[1-0001]: unexpected token - ┌─ fn_missing_body.fe:3:1 - │ -3 │ fn bar() asdf - │ ^^ unexpected token - -error[1-0001]: unexpected token - ┌─ fn_missing_body.fe:3:1 - │ -3 │ fn bar() asdf - │ ^^ unexpected token - error[1-0001]: function body is required - ┌─ fn_missing_body.fe:3:1 + ┌─ fn_missing_body.fe:1:28 │ -3 │ fn bar() asdf - │ ^^ function body is required +1 │ fn foo(x: u8, y: u64) -> u8 + │ ^ function body is required -error[1-0001]: expected newline after item definition - ┌─ fn_missing_body.fe:3:1 - │ -3 │ fn bar() asdf - │ ^^ expected newline after item definition - -error[1-0001]: unexpected token +error[1-0001]: unexpected syntax ┌─ fn_missing_body.fe:3:13 │ 3 │ fn bar() asdf - │ ^^^^ unexpected token - -error[1-0001]: unexpected token - ┌─ fn_missing_body.fe:5:1 - │ -5 │ fn baz(x: u8) -> u8 { - │ ^^ unexpected token - -error[1-0001]: unexpected token - ┌─ fn_missing_body.fe:5:1 - │ -5 │ fn baz(x: u8) -> u8 { - │ ^^ unexpected token + │ ^^^^ unexpected syntax error[1-0001]: function body is required - ┌─ fn_missing_body.fe:5:1 - │ -5 │ fn baz(x: u8) -> u8 { - │ ^^ function body is required - -error[1-0001]: expected newline after item definition - ┌─ fn_missing_body.fe:5:1 + ┌─ fn_missing_body.fe:3:17 │ -5 │ fn baz(x: u8) -> u8 { - │ ^^ expected newline after item definition +3 │ fn bar() asdf + │ ^ function body is required diff --git a/crates/uitest/fixtures/parser/fn_missing_parameters.snap b/crates/uitest/fixtures/parser/fn_missing_parameters.snap index baf36bce1d..581a2f8ff8 100644 --- a/crates/uitest/fixtures/parser/fn_missing_parameters.snap +++ b/crates/uitest/fixtures/parser/fn_missing_parameters.snap @@ -4,33 +4,33 @@ expression: diags input_file: crates/uitest/fixtures/parser/fn_missing_parameters.fe --- error[1-0001]: expected `(` for the function arguments - ┌─ fn_missing_parameters.fe:1:8 + ┌─ fn_missing_parameters.fe:1:7 │ 1 │ fn foo -> u8 {} - │ ^^ expected `(` for the function arguments + │ ^ expected `(` for the function arguments error[1-0001]: expected `(` for the function arguments - ┌─ fn_missing_parameters.fe:3:8 + ┌─ fn_missing_parameters.fe:3:7 │ 3 │ fn bar { - │ ^ expected `(` for the function arguments + │ ^ expected `(` for the function arguments error[1-0001]: expected `(` for the function arguments - ┌─ fn_missing_parameters.fe:6:8 + ┌─ fn_missing_parameters.fe:6:7 │ 6 │ fn baz -> u8 {} - │ ^^ expected `(` for the function arguments + │ ^ expected `(` for the function arguments error[1-0001]: expected `(` for the function arguments - ┌─ fn_missing_parameters.fe:8:9 + ┌─ fn_missing_parameters.fe:8:8 │ 8 │ fn f where T: U {} - │ ^^^^^ expected `(` for the function arguments + │ ^ expected `(` for the function arguments error[1-0001]: expected newline after type bounds - ┌─ fn_missing_parameters.fe:8:20 + ┌─ fn_missing_parameters.fe:8:19 │ 8 │ fn f where T: U {} - │ ^ expected newline after type bounds + │ ^ expected newline after type bounds diff --git a/crates/uitest/fixtures/parser/for_.fe b/crates/uitest/fixtures/parser/for_.fe new file mode 100644 index 0000000000..5c6229c883 --- /dev/null +++ b/crates/uitest/fixtures/parser/for_.fe @@ -0,0 +1,9 @@ +fn f() { +for i arr { } + +for in arr { } + +for @ in arr {} + +for @ in arr x y {} +} diff --git a/crates/uitest/fixtures/parser/for_.snap b/crates/uitest/fixtures/parser/for_.snap new file mode 100644 index 0000000000..7ab22c5374 --- /dev/null +++ b/crates/uitest/fixtures/parser/for_.snap @@ -0,0 +1,48 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/for_.fe +--- +error[1-0001]: expected `in` keyword + ┌─ for_.fe:2:6 + │ +2 │ for i arr { } + │ ^ expected `in` keyword + +error[1-0001]: expected path segment + ┌─ for_.fe:4:5 + │ +4 │ for in arr { } + │ ^ expected path segment + +error[1-0001]: expected path segment + ┌─ for_.fe:6:5 + │ +6 │ for @ in arr {} + │ ^ expected path segment + +error[1-0001]: unexpected syntax + ┌─ for_.fe:6:5 + │ +6 │ for @ in arr {} + │ ^ unexpected syntax + +error[1-0001]: expected path segment + ┌─ for_.fe:8:5 + │ +8 │ for @ in arr x y {} + │ ^ expected path segment + +error[1-0001]: unexpected syntax + ┌─ for_.fe:8:5 + │ +8 │ for @ in arr x y {} + │ ^ unexpected syntax + +error[1-0001]: unexpected syntax + ┌─ for_.fe:8:14 + │ +8 │ for @ in arr x y {} + │ ^^^ unexpected syntax + + diff --git a/crates/uitest/fixtures/parser/func.snap b/crates/uitest/fixtures/parser/func.snap index 8801ce5453..871bfeb3fb 100644 --- a/crates/uitest/fixtures/parser/func.snap +++ b/crates/uitest/fixtures/parser/func.snap @@ -3,23 +3,23 @@ source: crates/uitest/tests/parser.rs expression: diags input_file: crates/uitest/fixtures/parser/func.fe --- -error[1-0001]: unexpected token +error[1-0001]: unexpected syntax ┌─ func.fe:1:17 │ 1 │ fn foo>(x: i32, _ mut y: u32, z: u32) -> T, u where T: Trait2 - │ ^ unexpected token + │ ^ unexpected syntax -error[1-0001]: unexpected token +error[1-0001]: unexpected syntax ┌─ func.fe:1:29 │ 1 │ fn foo>(x: i32, _ mut y: u32, z: u32) -> T, u where T: Trait2 - │ ^^^ unexpected token + │ ^^^^^ unexpected syntax -error[1-0001]: unexpected token +error[1-0001]: unexpected syntax ┌─ func.fe:1:54 │ 1 │ fn foo>(x: i32, _ mut y: u32, z: u32) -> T, u where T: Trait2 - │ ^ unexpected token + │ ^^^ unexpected syntax error[1-0001]: expected type parameter ┌─ func.fe:6:8 @@ -27,11 +27,11 @@ error[1-0001]: expected type parameter 6 │ fn foo<<(x: i32) │ ^ expected type parameter -error[1-0001]: unexpected token - ┌─ func.fe:6:19 +error[1-0001]: unexpected syntax + ┌─ func.fe:6:8 │ 6 │ fn foo<<(x: i32) - │ ^ unexpected token + │ ^^^^^^^^^^^ unexpected syntax error[1-0001]: expected closing `>` ┌─ func.fe:6:19 diff --git a/crates/uitest/fixtures/parser/if_.fe b/crates/uitest/fixtures/parser/if_.fe new file mode 100644 index 0000000000..948c00bcdb --- /dev/null +++ b/crates/uitest/fixtures/parser/if_.fe @@ -0,0 +1,18 @@ +fn f() { + +if x y { +} + +if x { + +} else x {} + +if x { } else x if x { } else { } + +if x { + 10 +else { + 1 +} + +} \ No newline at end of file diff --git a/crates/uitest/fixtures/parser/if_.snap b/crates/uitest/fixtures/parser/if_.snap new file mode 100644 index 0000000000..2d56b32f3b --- /dev/null +++ b/crates/uitest/fixtures/parser/if_.snap @@ -0,0 +1,86 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/if_.fe +--- +error[1-0001]: unexpected syntax + ┌─ if_.fe:3:6 + │ +3 │ if x y { + │ ^ unexpected syntax + +error[1-0001]: expected `{` or `if` after `else` + ┌─ if_.fe:8:7 + │ +8 │ } else x {} + │ ^ expected `{` or `if` after `else` + +error[1-0001]: unexpected syntax + ┌─ if_.fe:8:8 + │ +8 │ } else x {} + │ ^ unexpected syntax + +error[1-0001]: expected newline after statement + ┌─ if_.fe:8:9 + │ +8 │ } else x {} + │ ^ expected newline after statement + +error[1-0001]: unexpected syntax + ┌─ if_.fe:8:10 + │ +8 │ } else x {} + │ ^^ unexpected syntax + +error[1-0001]: expected `{` or `if` after `else` + ┌─ if_.fe:10:14 + │ +10 │ if x { } else x if x { } else { } + │ ^ expected `{` or `if` after `else` + +error[1-0001]: unexpected syntax + ┌─ if_.fe:10:15 + │ +10 │ if x { } else x if x { } else { } + │ ^ unexpected syntax + +error[1-0001]: expected newline after statement + ┌─ if_.fe:10:16 + │ +10 │ if x { } else x if x { } else { } + │ ^ expected newline after statement + +error[1-0001]: unexpected syntax + ┌─ if_.fe:10:17 + │ +10 │ if x { } else x if x { } else { } + │ ^^^^^^^^^^^^^^^^^ unexpected syntax + +error[1-0001]: expected expression + ┌─ if_.fe:14:1 + │ +14 │ else { + │ ^ expected expression + +error[1-0001]: unexpected syntax + ┌─ if_.fe:14:1 + │ +14 │ ╭ else { +15 │ │ 1 +16 │ │ } + │ ╰─^ unexpected syntax + +error[1-0001]: expected newline after statement + ┌─ if_.fe:18:2 + │ +18 │ } + │ ^ expected newline after statement + +error[1-0001]: expected `}` + ┌─ if_.fe:18:2 + │ +18 │ } + │ ^ expected `}` + + diff --git a/crates/uitest/fixtures/parser/impl_.snap b/crates/uitest/fixtures/parser/impl_.snap index 151d23dee6..98820d8cf7 100644 --- a/crates/uitest/fixtures/parser/impl_.snap +++ b/crates/uitest/fixtures/parser/impl_.snap @@ -7,19 +7,13 @@ error[1-0001]: expected path segment ┌─ impl_.fe:2:5 │ 2 │ where T: Integer - │ ^^^^^ expected path segment - -error[1-0001]: unexpected token - ┌─ impl_.fe:2:5 - │ -2 │ where T: Integer - │ ^^^^^ unexpected token + │ ^ expected path segment error[1-0001]: expected closing `>` ┌─ impl_.fe:2:5 │ 2 │ where T: Integer - │ ^^^^^ expected closing `>` + │ ^ expected closing `>` error[1-0001]: expected path segment ┌─ impl_.fe:5:13 diff --git a/crates/uitest/fixtures/parser/impl_trait.snap b/crates/uitest/fixtures/parser/impl_trait.snap index 2b854339c5..1093794360 100644 --- a/crates/uitest/fixtures/parser/impl_trait.snap +++ b/crates/uitest/fixtures/parser/impl_trait.snap @@ -3,64 +3,46 @@ source: crates/uitest/tests/parser.rs expression: diags input_file: crates/uitest/fixtures/parser/impl_trait.fe --- -error[1-0001]: unexpected token +error[1-0001]: unexpected syntax ┌─ impl_trait.fe:1:12 │ 1 │ impl X for Y for Y` - ┌─ impl_trait.fe:1:24 + ┌─ impl_trait.fe:1:23 │ 1 │ impl X for Y` + │ ^ expected closing `>` error[1-0001]: expected newline after type bounds - ┌─ impl_trait.fe:1:35 + ┌─ impl_trait.fe:1:34 │ 1 │ impl X for Y` - ┌─ impl_trait.fe:3:13 - │ -3 │ impl X` - -error[1-0001]: unexpected token - ┌─ impl_trait.fe:3:21 + ┌─ impl_trait.fe:3:12 │ 3 │ impl X` error[1-0001]: expected closing `>` - ┌─ impl_trait.fe:3:21 + ┌─ impl_trait.fe:3:20 │ 3 │ impl X` + │ ^ expected closing `>` error[1-0001]: expected newline after type bounds - ┌─ impl_trait.fe:3:32 + ┌─ impl_trait.fe:3:31 │ 3 │ impl X { + Foo() => true + Bar +} + +match X { + Foo(i, j, => true x + Bar => x +} +} \ No newline at end of file diff --git a/crates/uitest/fixtures/parser/match_.snap b/crates/uitest/fixtures/parser/match_.snap new file mode 100644 index 0000000000..d22fb5865e --- /dev/null +++ b/crates/uitest/fixtures/parser/match_.snap @@ -0,0 +1,42 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/match_.fe +--- +error[1-0001]: unexpected syntax + ┌─ match_.fe:2:10 + │ +2 │ match X => { + │ ^^ unexpected syntax + +error[1-0001]: expected `=>` + ┌─ match_.fe:4:7 + │ +4 │ Bar + │ ^ expected `=>` + +error[1-0001]: expected expression + ┌─ match_.fe:4:7 + │ +4 │ Bar + │ ^ expected expression + +error[1-0001]: expected path segment + ┌─ match_.fe:8:16 + │ +8 │ Foo(i, j, => true x + │ ^ expected path segment + +error[1-0001]: expected `)` + ┌─ match_.fe:8:16 + │ +8 │ Foo(i, j, => true x + │ ^ expected `)` + +error[1-0001]: unexpected syntax + ┌─ match_.fe:8:24 + │ +8 │ Foo(i, j, => true x + │ ^ unexpected syntax + + diff --git a/crates/uitest/fixtures/parser/method.fe b/crates/uitest/fixtures/parser/method.fe new file mode 100644 index 0000000000..60ec01baf8 --- /dev/null +++ b/crates/uitest/fixtures/parser/method.fe @@ -0,0 +1,7 @@ +fn f() { +foo::bar.baz(1, 2) + +foo::bar.x(1, 2 E,) + +foo::bar.baz() +} \ No newline at end of file diff --git a/crates/uitest/fixtures/parser/method.snap b/crates/uitest/fixtures/parser/method.snap new file mode 100644 index 0000000000..b1097ffbb7 --- /dev/null +++ b/crates/uitest/fixtures/parser/method.snap @@ -0,0 +1,30 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/method.fe +--- +error[1-0001]: unexpected syntax + ┌─ method.fe:2:23 + │ +2 │ foo::bar.baz(1, 2) + │ ^ unexpected syntax + +error[1-0001]: expected path segment + ┌─ method.fe:2:25 + │ +2 │ foo::bar.baz(1, 2) + │ ^ expected path segment + +error[1-0001]: unexpected syntax + ┌─ method.fe:4:17 + │ +4 │ foo::bar.x(1, 2 E,) + │ ^ unexpected syntax + +error[1-0001]: expected expression + ┌─ method.fe:4:19 + │ +4 │ foo::bar.x(1, 2 E,) + │ ^ expected expression + + diff --git a/crates/uitest/fixtures/parser/struct_.snap b/crates/uitest/fixtures/parser/struct_.snap index cff9f38415..505701d973 100644 --- a/crates/uitest/fixtures/parser/struct_.snap +++ b/crates/uitest/fixtures/parser/struct_.snap @@ -9,41 +9,23 @@ error[1-0001]: expected ident for the struct name 1 │ pub struct` - ┌─ struct_.fe:2:1 + ┌─ struct_.fe:1:16 │ -2 │ where T - │ ^^^^^ expected closing `>` +1 │ pub struct` error[1-0001]: expected `:` for type bounds - ┌─ struct_.fe:2:9 - │ -2 │ where T - │ ╭────────^ -3 │ │ U: Trait - │ ╰^ expected `:` for type bounds - -error[1-0001]: unexpected token - ┌─ struct_.fe:6:8 - │ -6 │ foo - │ ╭───────^ -7 │ │ bar: i32::foo - │ ╰^ unexpected token + ┌─ struct_.fe:2:8 + │ +2 │ where T + │ ^ expected `:` for type bounds error[1-0001]: expected `name: type` for the field definition ┌─ struct_.fe:6:8 - │ -6 │ foo - │ ╭───────^ -7 │ │ bar: i32::foo - │ ╰^ expected `name: type` for the field definition + │ +6 │ foo + │ ^ expected `name: type` for the field definition error[1-0001]: expected comma after field definition ┌─ struct_.fe:6:8 diff --git a/crates/uitest/fixtures/parser/struct_missing_body.snap b/crates/uitest/fixtures/parser/struct_missing_body.snap index b5dba50e95..30983f0e10 100644 --- a/crates/uitest/fixtures/parser/struct_missing_body.snap +++ b/crates/uitest/fixtures/parser/struct_missing_body.snap @@ -3,58 +3,16 @@ source: crates/uitest/tests/parser.rs expression: diags input_file: crates/uitest/fixtures/parser/struct_missing_body.fe --- -error[1-0001]: unexpected token - ┌─ struct_missing_body.fe:4:1 - │ -4 │ struct T - │ ^^^^^^ unexpected token - -error[1-0001]: unexpected token - ┌─ struct_missing_body.fe:4:1 - │ -4 │ struct T - │ ^^^^^^ unexpected token - -error[1-0001]: unexpected token - ┌─ struct_missing_body.fe:4:1 - │ -4 │ struct T - │ ^^^^^^ unexpected token - error[1-0001]: expected struct field definition - ┌─ struct_missing_body.fe:4:1 - │ -4 │ struct T - │ ^^^^^^ expected struct field definition - -error[1-0001]: expected newline after item definition - ┌─ struct_missing_body.fe:4:1 - │ -4 │ struct T - │ ^^^^^^ expected newline after item definition - -error[1-0001]: unexpected token - ┌─ struct_missing_body.fe:6:1 + ┌─ struct_missing_body.fe:2:9 │ -6 │ struct Foo {} - │ ^^^^^^ unexpected token - -error[1-0001]: unexpected token - ┌─ struct_missing_body.fe:6:1 - │ -6 │ struct Foo {} - │ ^^^^^^ unexpected token +2 │ struct S + │ ^ expected struct field definition error[1-0001]: expected struct field definition - ┌─ struct_missing_body.fe:6:1 + ┌─ struct_missing_body.fe:4:12 │ -6 │ struct Foo {} - │ ^^^^^^ expected struct field definition - -error[1-0001]: expected newline after item definition - ┌─ struct_missing_body.fe:6:1 - │ -6 │ struct Foo {} - │ ^^^^^^ expected newline after item definition +4 │ struct T + │ ^ expected struct field definition diff --git a/crates/uitest/fixtures/parser/trait_.snap b/crates/uitest/fixtures/parser/trait_.snap index fc142eced2..72e8a4d13b 100644 --- a/crates/uitest/fixtures/parser/trait_.snap +++ b/crates/uitest/fixtures/parser/trait_.snap @@ -15,12 +15,6 @@ error[1-0001]: expected type parameter 3 │ trait Bar` ┌─ trait_.fe:3:14 │ @@ -33,29 +27,11 @@ error[1-0001]: expected type parameter 5 │ trait Bar │ ^ expected type parameter -error[1-0001]: unexpected token - ┌─ trait_.fe:7:1 - │ -7 │ trait Bar where T: Add {} - │ ^^^^^ unexpected token - -error[1-0001]: unexpected token - ┌─ trait_.fe:7:1 - │ -7 │ trait Bar where T: Add {} - │ ^^^^^ unexpected token - error[1-0001]: expected trait body - ┌─ trait_.fe:7:1 + ┌─ trait_.fe:5:15 │ -7 │ trait Bar where T: Add {} - │ ^^^^^ expected trait body - -error[1-0001]: expected newline after item definition - ┌─ trait_.fe:7:1 - │ -7 │ trait Bar where T: Add {} - │ ^^^^^ expected newline after item definition +5 │ trait Bar + │ ^ expected trait body error[1-0001]: expected type parameter ┌─ trait_.fe:7:16 @@ -64,10 +40,10 @@ error[1-0001]: expected type parameter │ ^ expected type parameter error[1-0001]: expected newline after type bounds - ┌─ trait_.fe:7:31 + ┌─ trait_.fe:7:30 │ 7 │ trait Bar where T: Add {} - │ ^ expected newline after type bounds + │ ^ expected newline after type bounds error[1-0001]: expected type parameter ┌─ trait_.fe:9:11 @@ -75,4 +51,10 @@ error[1-0001]: expected type parameter 9 │ trait Bar< │ ^ expected type parameter +error[1-0001]: unexpected syntax + ┌─ trait_.fe:9:11 + │ +9 │ trait Bar< + │ ^^ unexpected syntax + diff --git a/crates/uitest/fixtures/parser/trait_pub_fn.snap b/crates/uitest/fixtures/parser/trait_pub_fn.snap index d5f1f6a8b8..16075bfc96 100644 --- a/crates/uitest/fixtures/parser/trait_pub_fn.snap +++ b/crates/uitest/fixtures/parser/trait_pub_fn.snap @@ -3,28 +3,22 @@ source: crates/uitest/tests/parser.rs expression: diags input_file: crates/uitest/fixtures/parser/trait_pub_fn.fe --- -error[1-0001]: only `fn` is allowed in the block +error[1-0001]: modifier is not allowed in this block ┌─ trait_pub_fn.fe:2:5 │ 2 │ pub fn foo(mut self) - │ ^^^ only `fn` is allowed in the block + │ ^^^ modifier is not allowed in this block -error[1-0001]: expected newline after item definition - ┌─ trait_pub_fn.fe:2:9 - │ -2 │ pub fn foo(mut self) - │ ^^ expected newline after item definition - -error[1-0001]: only `fn` is allowed in the block +error[1-0001]: modifier is not allowed in this block ┌─ trait_pub_fn.fe:3:5 │ 3 │ pub unsafe fn bar(self) - │ ^^^ only `fn` is allowed in the block + │ ^^^ modifier is not allowed in this block -error[1-0001]: expected newline after item definition - ┌─ trait_pub_fn.fe:3:16 +error[1-0001]: modifier is not allowed in this block + ┌─ trait_pub_fn.fe:3:9 │ 3 │ pub unsafe fn bar(self) - │ ^^ expected newline after item definition + │ ^^^^^^ modifier is not allowed in this block diff --git a/crates/uitest/fixtures/parser/type_.snap b/crates/uitest/fixtures/parser/type_.snap index a8af0faeeb..adbfa1c23d 100644 --- a/crates/uitest/fixtures/parser/type_.snap +++ b/crates/uitest/fixtures/parser/type_.snap @@ -9,12 +9,6 @@ error[1-0001]: expected type parameter 1 │ type Result │ ^ expected type parameter -error[1-0001]: unexpected token - ┌─ type_.fe:1:16 - │ -1 │ type Result - │ ^ unexpected token - error[1-0001]: expected closing `>` ┌─ type_.fe:1:16 │ diff --git a/crates/uitest/fixtures/parser/while_.fe b/crates/uitest/fixtures/parser/while_.fe new file mode 100644 index 0000000000..b247fcac3a --- /dev/null +++ b/crates/uitest/fixtures/parser/while_.fe @@ -0,0 +1,9 @@ +fn f() { +while @ {} + +while true { + x + 1 +}} + +while true {} +} diff --git a/crates/uitest/fixtures/parser/while_.snap b/crates/uitest/fixtures/parser/while_.snap new file mode 100644 index 0000000000..3da7cf9756 --- /dev/null +++ b/crates/uitest/fixtures/parser/while_.snap @@ -0,0 +1,31 @@ +--- +source: crates/uitest/tests/parser.rs +expression: diags +input_file: crates/uitest/fixtures/parser/while_.fe +--- +error[1-0001]: expected expression + ┌─ while_.fe:2:6 + │ +2 │ while @ {} + │ ^ expected expression + +error[1-0001]: unexpected syntax + ┌─ while_.fe:2:7 + │ +2 │ while @ {} + │ ^ unexpected syntax + +error[1-0001]: expected item: but got Some(WhileKw) + ┌─ while_.fe:8:1 + │ +8 │ while true {} + │ ^ expected item: but got Some(WhileKw) + +error[1-0001]: unexpected syntax + ┌─ while_.fe:8:1 + │ +8 │ ╭ while true {} +9 │ │ } + │ ╰─^ unexpected syntax + +