Skip to content
Permalink
Browse files

Account for missing turbofish in paths too

  • Loading branch information...
estebank committed Sep 30, 2019
1 parent 6c9f298 commit d7dceaa0c57759d37a48b5a0aa1064b7c89f957b
Showing with 46 additions and 6 deletions.
  1. +43 −4 src/libsyntax/parse/diagnostics.rs
  2. +3 −2 src/test/ui/did_you_mean/issue-40396.stderr
@@ -585,12 +585,51 @@ impl<'a> Parser<'a> {
let early_return = vec![token::Eof];
self.consume_tts(1, &modifiers[..], &early_return[..]);

if self.token.kind != token::OpenDelim(token::Paren) {
// We don't have `foo< bar >(`, so we rewind the parser and bail out.
if !&[
token::OpenDelim(token::Paren),
token::ModSep,
].contains(&self.token.kind) {
// We don't have `foo< bar >(` or `foo< bar >::`, so we rewind the
// parser and bail out.
mem::replace(self, snapshot.clone());
}
}
if self.token.kind == token::OpenDelim(token::Paren) {
if token::ModSep == self.token.kind {
// We have some certainty that this was a bad turbofish at this point.
// `foo< bar >::`
err.span_suggestion(
op_span.shrink_to_lo(),
msg,
"::".to_string(),
Applicability::MaybeIncorrect,
);

let snapshot = self.clone();

self.bump(); // `::`
// Consume the rest of the likely `foo<bar>::new()` or return at `foo<bar>`.
match self.parse_expr() {
Ok(_) => {
// 99% certain that the suggestion is correct, continue parsing.
err.emit();
// FIXME: actually check that the two expressions in the binop are
// paths and resynthesize new fn call expression instead of using
// `ExprKind::Err` placeholder.
return Ok(Some(self.mk_expr(
lhs.span.to(self.prev_span),
ExprKind::Err,
ThinVec::new(),
)));
}
Err(mut err) => {
err.cancel();
// Not entirely sure now, but we bubble the error up with the
// suggestion.
mem::replace(self, snapshot);
return Err(err);
}
}
} else if token::OpenDelim(token::Paren) == self.token.kind {
// We have high certainty that this was a bad turbofish at this point.
// `foo< bar >(`
err.span_suggestion(
@@ -601,14 +640,14 @@ impl<'a> Parser<'a> {
);

let snapshot = self.clone();
self.bump(); // `(`

// Consume the fn call arguments.
let modifiers = vec![
(token::OpenDelim(token::Paren), 1),
(token::CloseDelim(token::Paren), -1),
];
let early_return = vec![token::Eof];
self.bump(); // `(`
self.consume_tts(1, &modifiers[..], &early_return[..]);

if self.token.kind == token::Eof {
@@ -13,9 +13,10 @@ error: chained comparison operators require parentheses
|
LL | Vec<i32>::new();
| ^^^^^
help: use `::<...>` instead of `<...>` if you meant to specify type arguments
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments
= help: or use `(...)` if you meant to specify fn arguments
LL | Vec::<i32>::new();
| ^^

error: chained comparison operators require parentheses
--> $DIR/issue-40396.rs:12:20

0 comments on commit d7dceaa

Please sign in to comment.
You can’t perform that action at this time.