Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,18 +753,13 @@ impl<'a> Parser<'a> {
}
let kind = if self.eat(exp!(Colon)) {
AssocItemConstraintKind::Bound { bounds: self.parse_generic_bounds()? }
} else if self.eat(exp!(Eq)) {
self.parse_assoc_equality_term(
ident,
gen_args.as_ref(),
self.prev_token.span,
)?
} else if self.check(exp!(Eq)) {
self.parse_assoc_equality_term(ident, gen_args.as_ref())?
} else {
unreachable!();
};

let span = lo.to(self.prev_token.span);

let constraint =
AssocItemConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span };
Ok(Some(AngleBracketedArg::Constraint(constraint)))
Expand Down Expand Up @@ -792,8 +787,10 @@ impl<'a> Parser<'a> {
&mut self,
ident: Ident,
gen_args: Option<&GenericArgs>,
eq: Span,
) -> PResult<'a, AssocItemConstraintKind> {
let prev_token_span = self.prev_token.span;
let eq_span = self.token.span;
self.expect(exp!(Eq))?;
let arg = self.parse_generic_arg(None)?;
let span = ident.span.to(self.prev_token.span);
let term = match arg {
Expand All @@ -814,20 +811,20 @@ impl<'a> Parser<'a> {
self.mk_ty(lt.ident.span, ast::TyKind::Err(guar)).into()
}
None => {
let after_eq = eq.shrink_to_hi();
let after_eq = eq_span.shrink_to_hi();
let before_next = self.token.span.shrink_to_lo();
let mut err = self
.dcx()
.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`");
if matches!(self.token.kind, token::Comma | token::Gt) {
err.span_suggestion(
self.psess.source_map().next_point(eq).to(before_next),
self.psess.source_map().next_point(eq_span).to(before_next),
"to constrain the associated type, add a type after `=`",
" TheType",
Applicability::HasPlaceholders,
);
err.span_suggestion(
eq.to(before_next),
prev_token_span.shrink_to_hi().to(before_next),
format!("remove the `=` if `{ident}` is a type"),
"",
Applicability::MaybeIncorrect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | bar::<Item = TheType>();
help: remove the `=` if `Item` is a type
|
LL - bar::<Item = >();
LL + bar::<Item >();
LL + bar::<Item>();
|

error: aborting due to 1 previous error
Expand Down
Loading