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)
This commit is contained in:
commit
8ddbfadda0
5 changed files with 41 additions and 1 deletions
|
@ -1601,6 +1601,14 @@ pub(crate) struct UnexpectedSelfInGenericParameters {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue