Auto merge of #45503 - thombles:tk/i44339-v5, r=petrochenkov

Improve diagnostics when list of tokens has incorrect separators

Make `parse_seq_to_before_tokens` more resilient to error conditions. Where possible it is better if it can consume up to the final bracket before returning. This change improves the diagnostics in a couple of situations:

```
struct S(pub () ()); // omitted separator
use std::{foo. bar}; // used a similar but wrong separator
```

Fixes #44339
r? @petrochenkov
This commit is contained in:
bors
2017-10-28 03:02:17 +00:00
7 changed files with 55 additions and 4 deletions

View File

@@ -1033,7 +1033,23 @@ impl<'a> Parser<'a> {
} else {
if let Err(e) = self.expect(t) {
fe(e);
break;
// Attempt to keep parsing if it was a similar separator
if let Some(ref tokens) = t.similar_tokens() {
if tokens.contains(&self.token) {
self.bump();
}
}
// Attempt to keep parsing if it was an omitted separator
match f(self) {
Ok(t) => {
v.push(t);
continue;
},
Err(mut e) => {
e.cancel();
break;
}
}
}
}
}