diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2017-07-06 14:29:55 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2017-07-16 11:49:10 -0700 |
| commit | 7239d7717188f6dc2b380a40335a0c8571be6502 (patch) | |
| tree | 7c22fc3eeb42d3e9ba5427801ff31660834d70f2 /src/libsyntax/parse | |
| parent | 8f1339af2e5d1b33ec9ee3c8a3c531bcd61770fc (diff) | |
| download | rust-7239d7717188f6dc2b380a40335a0c8571be6502.tar.gz rust-7239d7717188f6dc2b380a40335a0c8571be6502.zip | |
Point at `:` when using it instead of `;`
When triggering type ascription in such a way that we can infer a statement end was intended, add a suggestion for the change. Always point out the reason for the expectation of a type is due to type ascription.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 74b2ea1df32..1b6c3cf94e4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2798,7 +2798,22 @@ impl<'a> Parser<'a> { lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Cast)?; continue } else if op == AssocOp::Colon { - lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?; + lhs = match self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type) { + Ok(lhs) => lhs, + Err(mut err) => { + err.span_label(self.span, + "expecting a type here because of type ascription"); + let cm = self.sess.codemap(); + let cur_pos = cm.lookup_char_pos(self.span.lo); + let op_pos = cm.lookup_char_pos(cur_op_span.hi); + if cur_pos.line != op_pos.line { + err.span_suggestion(cur_op_span, + "did you mean to end the statement here instead?", + ";".to_string()); + } + return Err(err); + } + }; continue } else if op == AssocOp::DotDot || op == AssocOp::DotDotDot { // If we didn’t have to handle `x..`/`x...`, it would be pretty easy to |
