From 9149fd2c0ca3d23719082852a2cddd8ba5804ce6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Aug 2018 18:23:14 +0300 Subject: Fix some parser bugs --- crates/libsyntax2/src/grammar/paths.rs | 2 +- crates/libsyntax2/src/grammar/patterns.rs | 6 +++++- crates/libsyntax2/src/grammar/type_params.rs | 7 ++++++- crates/libsyntax2/src/grammar/types.rs | 7 +++++-- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'crates/libsyntax2/src') diff --git a/crates/libsyntax2/src/grammar/paths.rs b/crates/libsyntax2/src/grammar/paths.rs index c277e2a6b..aa5ecf4b8 100644 --- a/crates/libsyntax2/src/grammar/paths.rs +++ b/crates/libsyntax2/src/grammar/paths.rs @@ -62,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { } SELF_KW | SUPER_KW => p.bump(), _ => { - p.error("expected identifier"); + p.err_and_bump("expected identifier"); } }; segment.complete(p, PATH_SEGMENT); diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs index 436f3b26d..220f36db7 100644 --- a/crates/libsyntax2/src/grammar/patterns.rs +++ b/crates/libsyntax2/src/grammar/patterns.rs @@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser) -> Option { // let Bar(..) = (); // } fn path_pat(p: &mut Parser) -> CompletedMarker { + assert!(paths::is_path_start(p)); let m = p.start(); paths::expr_path(p); let kind = match p.current() { @@ -116,8 +117,11 @@ fn struct_pat_fields(p: &mut Parser) { p.bump(); pattern(p); } - _ => { + REF_KW | MUT_KW | IDENT => { bind_pat(p, false); + }, + _ => { + p.err_and_bump("expected ident"); } } if !p.at(R_CURLY) { diff --git a/crates/libsyntax2/src/grammar/type_params.rs b/crates/libsyntax2/src/grammar/type_params.rs index 0a3e8fd07..32b69dc5b 100644 --- a/crates/libsyntax2/src/grammar/type_params.rs +++ b/crates/libsyntax2/src/grammar/type_params.rs @@ -121,7 +121,12 @@ fn where_predicate(p: &mut Parser) { lifetime_bounds(p) } else { types::path_type(p); - bounds(p); + if p.at(COLON) { + bounds(p); + } else { + p.error("expected colon") + } + } m.complete(p, WHERE_PRED); } diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs index 5ba3fcca0..88631fefe 100644 --- a/crates/libsyntax2/src/grammar/types.rs +++ b/crates/libsyntax2/src/grammar/types.rs @@ -166,8 +166,11 @@ fn fn_pointer_type(p: &mut Parser) { p.error("expected `fn`"); return; } - - params::param_list_opt_patterns(p); + if p.at(L_PAREN) { + params::param_list_opt_patterns(p); + } else { + p.error("expected parameters") + } // test fn_pointer_type_with_ret // type F = fn() -> (); fn_ret_type(p); -- cgit v1.2.3