aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-13 16:30:56 +0100
committerAleksey Kladov <[email protected]>2018-08-13 16:30:56 +0100
commit51f7f937a569680ddb0b2bbca2a74f861802898b (patch)
tree16844f4f6216587f87add068cffc7d1ad0461be0 /crates/libsyntax2
parentc1a7b72fb7c9b69779e490e1d692ddfccec8b57a (diff)
Safer errors
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/grammar/mod.rs4
-rw-r--r--crates/libsyntax2/src/grammar/patterns.rs5
-rw-r--r--crates/libsyntax2/tests/data/parser/ok/0030_traits.txt34
3 files changed, 22 insertions, 21 deletions
diff --git a/crates/libsyntax2/src/grammar/mod.rs b/crates/libsyntax2/src/grammar/mod.rs
index e1329044d..d9443f24f 100644
--- a/crates/libsyntax2/src/grammar/mod.rs
+++ b/crates/libsyntax2/src/grammar/mod.rs
@@ -129,7 +129,7 @@ fn name(p: &mut Parser) {
129 p.bump(); 129 p.bump();
130 m.complete(p, NAME); 130 m.complete(p, NAME);
131 } else { 131 } else {
132 p.error("expected a name"); 132 p.err_and_bump("expected a name");
133 } 133 }
134} 134}
135 135
@@ -139,7 +139,7 @@ fn name_ref(p: &mut Parser) {
139 p.bump(); 139 p.bump();
140 m.complete(p, NAME_REF); 140 m.complete(p, NAME_REF);
141 } else { 141 } else {
142 p.error("expected identifier"); 142 p.err_and_bump("expected identifier");
143 } 143 }
144} 144}
145 145
diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs
index 220f36db7..71a1d5445 100644
--- a/crates/libsyntax2/src/grammar/patterns.rs
+++ b/crates/libsyntax2/src/grammar/patterns.rs
@@ -117,11 +117,8 @@ fn struct_pat_fields(p: &mut Parser) {
117 p.bump(); 117 p.bump();
118 pattern(p); 118 pattern(p);
119 } 119 }
120 REF_KW | MUT_KW | IDENT => {
121 bind_pat(p, false);
122 },
123 _ => { 120 _ => {
124 p.err_and_bump("expected ident"); 121 bind_pat(p, false);
125 } 122 }
126 } 123 }
127 if !p.at(R_CURLY) { 124 if !p.at(R_CURLY) {
diff --git a/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt b/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt
index d50295134..5adab705b 100644
--- a/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt
+++ b/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt
@@ -97,19 +97,21 @@ FILE@[0; 164)
97 WHITESPACE@[125; 126) 97 WHITESPACE@[125; 126)
98 L_CURLY@[126; 127) 98 L_CURLY@[126; 127)
99 WHITESPACE@[127; 132) 99 WHITESPACE@[127; 132)
100 err: `expected ident` 100 err: `expected a name`
101 ERROR@[132; 134) 101 BIND_PAT@[132; 134)
102 FN_KW@[132; 134) 102 ERROR@[132; 134)
103 err: `expected COMMA` 103 FN_KW@[132; 134)
104 err: `expected COMMA`
104 WHITESPACE@[134; 135) 105 WHITESPACE@[134; 135)
105 BIND_PAT@[135; 147) 106 BIND_PAT@[135; 147)
106 NAME@[135; 147) 107 NAME@[135; 147)
107 IDENT@[135; 147) "fn_with_expr" 108 IDENT@[135; 147) "fn_with_expr"
108 err: `expected COMMA` 109 err: `expected COMMA`
109 err: `expected ident` 110 err: `expected a name`
110 ERROR@[147; 148) 111 BIND_PAT@[147; 148)
111 L_PAREN@[147; 148) 112 ERROR@[147; 148)
112 err: `expected COMMA` 113 L_PAREN@[147; 148)
114 err: `expected COMMA`
113 IDENT@[148; 149) "x" 115 IDENT@[148; 149) "x"
114 COLON@[149; 150) 116 COLON@[149; 150)
115 WHITESPACE@[150; 151) 117 WHITESPACE@[150; 151)
@@ -128,13 +130,15 @@ FILE@[0; 164)
128 INT_NUMBER@[157; 158) "1" 130 INT_NUMBER@[157; 158) "1"
129 R_BRACK@[158; 159) 131 R_BRACK@[158; 159)
130 err: `expected COMMA` 132 err: `expected COMMA`
131 err: `expected ident` 133 err: `expected a name`
132 ERROR@[159; 160) 134 BIND_PAT@[159; 160)
133 R_PAREN@[159; 160) 135 ERROR@[159; 160)
134 err: `expected COMMA` 136 R_PAREN@[159; 160)
135 err: `expected ident` 137 err: `expected COMMA`
136 ERROR@[160; 161) 138 err: `expected a name`
137 SEMI@[160; 161) 139 BIND_PAT@[160; 161)
140 ERROR@[160; 161)
141 SEMI@[160; 161)
138 WHITESPACE@[161; 162) 142 WHITESPACE@[161; 162)
139 R_CURLY@[162; 163) 143 R_CURLY@[162; 163)
140 err: `expected COLON` 144 err: `expected COLON`