1
Fork 0

Detect :: -> : typo when involving turbofish

This commit is contained in:
Esteban Küber 2019-11-04 16:19:55 -08:00
parent d3d28a4920
commit 3bbfc7320b
4 changed files with 21 additions and 1 deletions

View file

@ -354,7 +354,7 @@ impl<'a> Parser<'a> {
}
pub fn maybe_annotate_with_ascription(
&self,
&mut self,
err: &mut DiagnosticBuilder<'_>,
maybe_expected_semicolon: bool,
) {
@ -395,6 +395,7 @@ impl<'a> Parser<'a> {
err.note("for more information, see \
https://github.com/rust-lang/rust/issues/23416");
}
self.last_type_ascription = None;
}
}

View file

@ -397,6 +397,7 @@ impl<'a> Parser<'a> {
}
let stmt = match self.parse_full_stmt(false) {
Err(mut err) => {
self.maybe_annotate_with_ascription(&mut err, false);
err.emit();
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
Some(Stmt {

View file

@ -0,0 +1,5 @@
fn main() -> Result<(), ()> {
vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
//~^ ERROR expected `::`, found `(`
Ok(())
}

View file

@ -0,0 +1,13 @@
error: expected `::`, found `(`
--> $DIR/type-ascription-instead-of-path-2.rs:2:55
|
LL | vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
| - ^ expected `::`
| |
| tried to parse a type due to this type ascription
|
= 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
error: aborting due to previous error