Skip to content

Commit 828c2a9

Browse files
committed
Auto merge of #147360 - chenyukang:yukang-fix-assoc-eq-missing-term, r=nnethercote
Remove extra space for missing associated type term suggestion r? `@nnethercote`
2 parents 4fa824b + 34ad919 commit 828c2a9

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

compiler/rustc_parse/src/parser/path.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -753,18 +753,13 @@ impl<'a> Parser<'a> {
753753
}
754754
let kind = if self.eat(exp!(Colon)) {
755755
AssocItemConstraintKind::Bound { bounds: self.parse_generic_bounds()? }
756-
} else if self.eat(exp!(Eq)) {
757-
self.parse_assoc_equality_term(
758-
ident,
759-
gen_args.as_ref(),
760-
self.prev_token.span,
761-
)?
756+
} else if self.check(exp!(Eq)) {
757+
self.parse_assoc_equality_term(ident, gen_args.as_ref())?
762758
} else {
763759
unreachable!();
764760
};
765761

766762
let span = lo.to(self.prev_token.span);
767-
768763
let constraint =
769764
AssocItemConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span };
770765
Ok(Some(AngleBracketedArg::Constraint(constraint)))
@@ -792,8 +787,10 @@ impl<'a> Parser<'a> {
792787
&mut self,
793788
ident: Ident,
794789
gen_args: Option<&GenericArgs>,
795-
eq: Span,
796790
) -> PResult<'a, AssocItemConstraintKind> {
791+
let prev_token_span = self.prev_token.span;
792+
let eq_span = self.token.span;
793+
self.expect(exp!(Eq))?;
797794
let arg = self.parse_generic_arg(None)?;
798795
let span = ident.span.to(self.prev_token.span);
799796
let term = match arg {
@@ -814,20 +811,20 @@ impl<'a> Parser<'a> {
814811
self.mk_ty(lt.ident.span, ast::TyKind::Err(guar)).into()
815812
}
816813
None => {
817-
let after_eq = eq.shrink_to_hi();
814+
let after_eq = eq_span.shrink_to_hi();
818815
let before_next = self.token.span.shrink_to_lo();
819816
let mut err = self
820817
.dcx()
821818
.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`");
822819
if matches!(self.token.kind, token::Comma | token::Gt) {
823820
err.span_suggestion(
824-
self.psess.source_map().next_point(eq).to(before_next),
821+
self.psess.source_map().next_point(eq_span).to(before_next),
825822
"to constrain the associated type, add a type after `=`",
826823
" TheType",
827824
Applicability::HasPlaceholders,
828825
);
829826
err.span_suggestion(
830-
eq.to(before_next),
827+
prev_token_span.shrink_to_hi().to(before_next),
831828
format!("remove the `=` if `{ident}` is a type"),
832829
"",
833830
Applicability::MaybeIncorrect,

tests/ui/parser/recover/recover-assoc-eq-missing-term.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | bar::<Item = TheType>();
1111
help: remove the `=` if `Item` is a type
1212
|
1313
LL - bar::<Item = >();
14-
LL + bar::<Item >();
14+
LL + bar::<Item>();
1515
|
1616

1717
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)