diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-02-06 19:54:14 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-06 19:54:14 +0530 |
| commit | 8ddbfadda0cd0b2cde11bd60d1e3785657841fc0 (patch) | |
| tree | efe002b18ca0da69a227aaf335db10ac20404ab8 /compiler/rustc_parse/src | |
| parent | 496adf81deaec94015e4cde2165d094eac09a940 (diff) | |
| parent | d9f60052d2471b15417153d3daca8d83d1c44fd4 (diff) | |
| download | rust-8ddbfadda0cd0b2cde11bd60d1e3785657841fc0.tar.gz rust-8ddbfadda0cd0b2cde11bd60d1e3785657841fc0.zip | |
Rollup merge of #107580 - lenko-d:default_value_for_a_lifetime_generic_parameter_produces_confusing_diagnostic, r=compiler-errors
Recover from lifetimes with default lifetimes in generic args Fixes [#107492](https://github.com/rust-lang/rust/issues/107492)
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index fc7c839f1c4..0c11e002690 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1602,6 +1602,14 @@ pub(crate) struct UnexpectedSelfInGenericParameters { } #[derive(Diagnostic)] +#[diag(parse_unexpected_default_value_for_lifetime_in_generic_parameters)] +pub(crate) struct UnexpectedDefaultValueForLifetimeInGenericParameters { + #[primary_span] + #[label] + pub span: Span, +} + +#[derive(Diagnostic)] #[diag(parse_multiple_where_clauses)] pub(crate) struct MultipleWhereClauses { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 585dfc518b3..23f49ec55a1 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -1,5 +1,6 @@ use crate::errors::{ - MultipleWhereClauses, UnexpectedSelfInGenericParameters, WhereClauseBeforeTupleStructBody, + MultipleWhereClauses, UnexpectedDefaultValueForLifetimeInGenericParameters, + UnexpectedSelfInGenericParameters, WhereClauseBeforeTupleStructBody, WhereClauseBeforeTupleStructBodySugg, }; @@ -145,6 +146,20 @@ impl<'a> Parser<'a> { } else { (None, Vec::new()) }; + + if this.check_noexpect(&token::Eq) + && this.look_ahead(1, |t| t.is_lifetime()) + { + let lo = this.token.span; + // Parse `= 'lifetime`. + this.bump(); // `=` + this.bump(); // `'lifetime` + let span = lo.to(this.prev_token.span); + this.sess.emit_err( + UnexpectedDefaultValueForLifetimeInGenericParameters { span }, + ); + } + Some(ast::GenericParam { ident: lifetime.ident, id: lifetime.id, |
