Suggest assoc ty bound on lifetime in eq constraint
This commit is contained in:
parent
22b9e960d9
commit
3879acbec0
5 changed files with 49 additions and 21 deletions
|
@ -2611,13 +2611,22 @@ pub(crate) struct GenericsInPath {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_assoc_lifetime)]
|
||||
#[diag(parse_lifetime_in_eq_constraint)]
|
||||
#[help]
|
||||
pub(crate) struct AssocLifetime {
|
||||
pub(crate) struct LifetimeInEqConstraint {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub lifetime: Span,
|
||||
pub span: Span,
|
||||
pub lifetime: Ident,
|
||||
#[label(parse_context_label)]
|
||||
pub binding_label: Span,
|
||||
#[suggestion(
|
||||
parse_colon_sugg,
|
||||
style = "verbose",
|
||||
applicability = "maybe-incorrect",
|
||||
code = ": "
|
||||
)]
|
||||
pub colon_sugg: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
@ -718,7 +718,11 @@ impl<'a> Parser<'a> {
|
|||
let bounds = self.parse_generic_bounds()?;
|
||||
AssocConstraintKind::Bound { bounds }
|
||||
} else if self.eat(&token::Eq) {
|
||||
self.parse_assoc_equality_term(ident, self.prev_token.span)?
|
||||
self.parse_assoc_equality_term(
|
||||
ident,
|
||||
gen_args.as_ref(),
|
||||
self.prev_token.span,
|
||||
)?
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
@ -753,11 +757,13 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parse the term to the right of an associated item equality constraint.
|
||||
/// That is, parse `<term>` in `Item = <term>`.
|
||||
/// Right now, this only admits types in `<term>`.
|
||||
///
|
||||
/// That is, parse `$term` in `Item = $term` where `$term` is a type or
|
||||
/// a const expression (wrapped in curly braces if complex).
|
||||
fn parse_assoc_equality_term(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
gen_args: Option<&GenericArgs>,
|
||||
eq: Span,
|
||||
) -> PResult<'a, AssocConstraintKind> {
|
||||
let arg = self.parse_generic_arg(None)?;
|
||||
|
@ -769,9 +775,15 @@ impl<'a> Parser<'a> {
|
|||
c.into()
|
||||
}
|
||||
Some(GenericArg::Lifetime(lt)) => {
|
||||
let guar =
|
||||
self.dcx().emit_err(errors::AssocLifetime { span, lifetime: lt.ident.span });
|
||||
self.mk_ty(span, ast::TyKind::Err(guar)).into()
|
||||
let guar = self.dcx().emit_err(errors::LifetimeInEqConstraint {
|
||||
span: lt.ident.span,
|
||||
lifetime: lt.ident,
|
||||
binding_label: span,
|
||||
colon_sugg: gen_args
|
||||
.map_or(ident.span, |args| args.span())
|
||||
.between(lt.ident.span),
|
||||
});
|
||||
self.mk_ty(lt.ident.span, ast::TyKind::Err(guar)).into()
|
||||
}
|
||||
None => {
|
||||
let after_eq = eq.shrink_to_hi();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue