Account for typo in turbofish and suggest ::
This commit is contained in:
parent
3bbfc7320b
commit
a8ccbf5f2f
2 changed files with 11 additions and 5 deletions
|
@ -358,7 +358,7 @@ impl<'a> Parser<'a> {
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut DiagnosticBuilder<'_>,
|
||||||
maybe_expected_semicolon: bool,
|
maybe_expected_semicolon: bool,
|
||||||
) {
|
) {
|
||||||
if let Some((sp, likely_path)) = self.last_type_ascription {
|
if let Some((sp, likely_path)) = self.last_type_ascription.take() {
|
||||||
let sm = self.sess.source_map();
|
let sm = self.sess.source_map();
|
||||||
let next_pos = sm.lookup_char_pos(self.token.span.lo());
|
let next_pos = sm.lookup_char_pos(self.token.span.lo());
|
||||||
let op_pos = sm.lookup_char_pos(sp.hi());
|
let op_pos = sm.lookup_char_pos(sp.hi());
|
||||||
|
@ -395,7 +395,6 @@ impl<'a> Parser<'a> {
|
||||||
err.note("for more information, see \
|
err.note("for more information, see \
|
||||||
https://github.com/rust-lang/rust/issues/23416");
|
https://github.com/rust-lang/rust/issues/23416");
|
||||||
}
|
}
|
||||||
self.last_type_ascription = None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1083,8 +1082,15 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool {
|
pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool {
|
||||||
|
(self.token == token::Lt && // `foo:<bar`, likely a typoed turbofish.
|
||||||
|
self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
|
||||||
|
) ||
|
||||||
self.token.is_ident() &&
|
self.token.is_ident() &&
|
||||||
if let ast::ExprKind::Path(..) = node { true } else { false } &&
|
match node {
|
||||||
|
// `foo::` → `foo:` or `foo.bar::` → `foo.bar:`
|
||||||
|
ast::ExprKind::Path(..) | ast::ExprKind::Field(..) => true,
|
||||||
|
_ => false,
|
||||||
|
} &&
|
||||||
!self.token.is_reserved_ident() && // v `foo:bar(baz)`
|
!self.token.is_reserved_ident() && // v `foo:bar(baz)`
|
||||||
self.look_ahead(1, |t| t == &token::OpenDelim(token::Paren)) ||
|
self.look_ahead(1, |t| t == &token::OpenDelim(token::Paren)) ||
|
||||||
self.look_ahead(1, |t| t == &token::Lt) && // `foo:bar<baz`
|
self.look_ahead(1, |t| t == &token::Lt) && // `foo:bar<baz`
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: expected `::`, found `(`
|
||||||
LL | vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
|
LL | vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
|
||||||
| - ^ expected `::`
|
| - ^ expected `::`
|
||||||
| |
|
| |
|
||||||
| tried to parse a type due to this type ascription
|
| help: maybe write a path separator here: `::`
|
||||||
|
|
|
|
||||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||||
= note: for more information, see https://github.com/rust-lang/rust/issues/23416
|
= note: for more information, see https://github.com/rust-lang/rust/issues/23416
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue