diff options
| author | bors <bors@rust-lang.org> | 2019-11-06 02:29:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-06 02:29:21 +0000 |
| commit | e4931eaaa3d95189b30e90d3af9f0db17c41bbb0 (patch) | |
| tree | d121150066de905b1877e0a1fb81884ac4656918 /src/libsyntax/parse/parser | |
| parent | 1423bec54cf2db283b614e527cfd602b481485d1 (diff) | |
| parent | 35a5ffc8eab6d0aceb2f7dba207a0aa42d0264e5 (diff) | |
| download | rust-e4931eaaa3d95189b30e90d3af9f0db17c41bbb0.tar.gz rust-e4931eaaa3d95189b30e90d3af9f0db17c41bbb0.zip | |
Auto merge of #66141 - Centril:rollup-n2fcvp9, r=Centril
Rollup of 11 pull requests Successful merges: - #65892 (Remove `PartialEq` and `Eq` from the `SpecialDerives`.) - #66014 (Show type parameter name and definition in type mismatch error messages ) - #66027 (Move has_panic_handler to query) - #66054 (syntax: Avoid span arithmetic for delimiter tokens) - #66068 (use silent emitter for rustdoc highlighting pass) - #66081 (let caller of check_ptr_access_align control the error message) - #66093 (Do not ICE with a precision flag in formatting str and no format arguments) - #66098 (Detect `::` -> `:` typo when involving turbofish) - #66101 (Tweak type mismatch caused by break on tail expr) - #66106 (Fix typo in explanation of `E0080`) - #66115 (rustc: remove "GlobalMetaData" dead code from hir::map::definitions.) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax/parse/parser')
| -rw-r--r-- | src/libsyntax/parse/parser/diagnostics.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/stmt.rs | 1 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser/diagnostics.rs b/src/libsyntax/parse/parser/diagnostics.rs index fcf3b4c0aa8..453ef5963be 100644 --- a/src/libsyntax/parse/parser/diagnostics.rs +++ b/src/libsyntax/parse/parser/diagnostics.rs @@ -360,11 +360,11 @@ impl<'a> Parser<'a> { } pub fn maybe_annotate_with_ascription( - &self, + &mut self, err: &mut DiagnosticBuilder<'_>, 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 next_pos = sm.lookup_char_pos(self.token.span.lo()); let op_pos = sm.lookup_char_pos(sp.hi()); @@ -1088,8 +1088,15 @@ impl<'a> Parser<'a> { } pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool { - self.token.is_ident() && - if let ast::ExprKind::Path(..) = node { true } else { false } && + (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() && + 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.look_ahead(1, |t| t == &token::OpenDelim(token::Paren)) || self.look_ahead(1, |t| t == &token::Lt) && // `foo:bar<baz` diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index 4f51fefe66f..12c530f3cbb 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -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 { |
