diff options
| author | Yiming Lei <yiming.lei@futurewei.com> | 2022-10-13 10:30:33 -0700 |
|---|---|---|
| committer | Yiming Lei <yiming.lei@futurewei.com> | 2022-12-13 16:49:20 -0800 |
| commit | 419df5f4a06bc4dff05152413c783758b46ff6b9 (patch) | |
| tree | 6702180aa34d745221df4e64f327dee79afa8c5b /compiler/rustc_parse/src | |
| parent | 37d7de337903a558dbeb1e82c844fe915ab8ff25 (diff) | |
| download | rust-419df5f4a06bc4dff05152413c783758b46ff6b9.tar.gz rust-419df5f4a06bc4dff05152413c783758b46ff6b9.zip | |
error parsing lifetime following by Sized and message + between them
detect the pattern at the general site parse_impl_ty() this will fix #102598
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 19 |
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index beb9d55d454..063421d62fe 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2449,7 +2449,6 @@ impl<'a> Parser<'a> { }; let (pat, ty) = if is_name_required || this.is_named_param() { debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required); - let (pat, colon) = this.parse_fn_param_pat_colon()?; if !colon { let mut err = this.unexpected::<()>().unwrap_err(); diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index b7206b57642..fc26278909c 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -613,6 +613,25 @@ impl<'a> Parser<'a> { /// Parses an `impl B0 + ... + Bn` type. fn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> { // Always parse bounds greedily for better error recovery. + if self.token.is_lifetime() { + self.look_ahead(1, |t| { + if let token::Ident(symname, _) = t.kind { + // parse pattern with "'a Sized" we're supposed to give suggestion like + // "'a + Sized" + self.struct_span_err( + self.token.span, + &format!("expected `+` between lifetime and {}", symname), + ) + .span_suggestion_verbose( + self.token.span.shrink_to_hi(), + "add `+`", + " +", + Applicability::MaybeIncorrect, + ) + .emit(); + } + }) + } let bounds = self.parse_generic_bounds(None)?; *impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus); Ok(TyKind::ImplTrait(ast::DUMMY_NODE_ID, bounds)) |
