Extract ast TraitImplHeader

This commit is contained in:
Cameron Steffen
2025-07-21 20:05:16 -05:00
parent 3aa0ac0a8a
commit 5bc23ce255
18 changed files with 187 additions and 184 deletions

View File

@@ -663,7 +663,14 @@ impl<'a> Parser<'a> {
};
let trait_ref = TraitRef { path, ref_id: ty_first.id };
(Some(trait_ref), ty_second)
let of_trait = Some(Box::new(TraitImplHeader {
defaultness,
safety,
constness,
polarity,
trait_ref,
}));
(of_trait, ty_second)
}
None => {
let self_ty = ty_first;
@@ -692,16 +699,8 @@ impl<'a> Parser<'a> {
(None, self_ty)
}
};
Ok(ItemKind::Impl(Box::new(Impl {
safety,
polarity,
defaultness,
constness,
generics,
of_trait,
self_ty,
items: impl_items,
})))
Ok(ItemKind::Impl(Impl { generics, of_trait, self_ty, items: impl_items }))
}
fn parse_item_delegation(&mut self) -> PResult<'a, ItemKind> {
@@ -1389,10 +1388,10 @@ impl<'a> Parser<'a> {
};
match &mut item_kind {
ItemKind::Impl(box Impl { of_trait: Some(trai), constness, .. }) => {
*constness = Const::Yes(const_span);
ItemKind::Impl(Impl { of_trait: Some(of_trait), .. }) => {
of_trait.constness = Const::Yes(const_span);
let before_trait = trai.path.span.shrink_to_lo();
let before_trait = of_trait.trait_ref.path.span.shrink_to_lo();
let const_up_to_impl = const_span.with_hi(impl_span.lo());
err.with_multipart_suggestion(
"you might have meant to write a const trait impl",