Skip to content

Commit 3bbfc73

Browse files
committed
Detect :: -> : typo when involving turbofish
1 parent d3d28a4 commit 3bbfc73

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/libsyntax/parse/parser/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'a> Parser<'a> {
354354
}
355355

356356
pub fn maybe_annotate_with_ascription(
357-
&self,
357+
&mut self,
358358
err: &mut DiagnosticBuilder<'_>,
359359
maybe_expected_semicolon: bool,
360360
) {
@@ -395,6 +395,7 @@ impl<'a> Parser<'a> {
395395
err.note("for more information, see \
396396
https://github.com/rust-lang/rust/issues/23416");
397397
}
398+
self.last_type_ascription = None;
398399
}
399400
}
400401

src/libsyntax/parse/parser/stmt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ impl<'a> Parser<'a> {
397397
}
398398
let stmt = match self.parse_full_stmt(false) {
399399
Err(mut err) => {
400+
self.maybe_annotate_with_ascription(&mut err, false);
400401
err.emit();
401402
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
402403
Some(Stmt {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() -> Result<(), ()> {
2+
vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
3+
//~^ ERROR expected `::`, found `(`
4+
Ok(())
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: expected `::`, found `(`
2+
--> $DIR/type-ascription-instead-of-path-2.rs:2:55
3+
|
4+
LL | vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
5+
| - ^ expected `::`
6+
| |
7+
| tried to parse a type due to this type ascription
8+
|
9+
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
10+
= note: for more information, see https://github.com/rust-lang/rust/issues/23416
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)