diff options
| author | Michael Howell <michael@notriddle.com> | 2021-09-16 13:05:14 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2021-09-16 15:06:31 -0700 |
| commit | d8e9db0dcf0fc5cd6585a86145bfed5ea3c55031 (patch) | |
| tree | dd1f386eb00616ab149eaded516addf2065d8cc1 /compiler/rustc_parse/src/parser | |
| parent | 2b5ddf36fdc784106b3a064d93dd054c32b1f10f (diff) | |
| download | rust-d8e9db0dcf0fc5cd6585a86145bfed5ea3c55031.tar.gz rust-d8e9db0dcf0fc5cd6585a86145bfed5ea3c55031.zip | |
feat(rustc_parse): recover from pre-RFC-2000 const generics syntax
Fixes #89013
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 953c6915068..4e4130dfc23 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -495,11 +495,16 @@ impl<'a> Parser<'a> { None => { let after_eq = eq.shrink_to_hi(); let before_next = self.token.span.shrink_to_lo(); + let the_type_placeholder = if matches!(self.token.kind, token::Comma | token::Gt) { + " TheType" + } else { + " TheType " + }; self.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`") .span_suggestion( self.sess.source_map().next_point(eq).to(before_next), "to constrain the associated type, add a type after `=`", - " TheType".to_string(), + the_type_placeholder.to_string(), Applicability::HasPlaceholders, ) .span_suggestion( @@ -572,6 +577,19 @@ impl<'a> Parser<'a> { return self.recover_const_arg(start, err).map(Some); } } + } else if self.eat_keyword_noexpect(kw::Const) { + // Detect and recover from the old, pre-RFC2000 syntax for const generics. + let mut err = self.struct_span_err( + start, + "expected lifetime, type, or constant, found keyword `const`", + ); + if self.check_const_arg() { + err.emit(); + GenericArg::Const(self.parse_const_arg()?) + } else { + let after_kw_const = self.token.span; + return self.recover_const_arg(after_kw_const, err).map(Some); + } } else { return Ok(None); }; |
