1
Fork 0

Auto merge of #122500 - petrochenkov:deleg, r=fmease

delegation: Support renaming, and async, const, extern "ABI" and C-variadic functions

Also allow delegating to functions with opaque types (`impl Trait`).
The delegation item will refer to the original opaque type from the callee, fresh opaque type won't be created, which seems like a reasonable behavior.
(Such delegation items will cause query cycles when used in trait impls, but it can be fixed later.)

Part of https://github.com/rust-lang/rust/issues/118212.
This commit is contained in:
bors 2024-04-24 11:57:35 +00:00
commit 5557f8c9d0
17 changed files with 282 additions and 160 deletions

View file

@ -686,6 +686,8 @@ impl<'a> Parser<'a> {
(None, self.parse_path(PathStyle::Expr)?)
};
let rename = if self.eat_keyword(kw::As) { Some(self.parse_ident()?) } else { None };
let body = if self.check(&token::OpenDelim(Delimiter::Brace)) {
Some(self.parse_block()?)
} else {
@ -695,11 +697,9 @@ impl<'a> Parser<'a> {
let span = span.to(self.prev_token.span);
self.psess.gated_spans.gate(sym::fn_delegation, span);
let ident = path.segments.last().map(|seg| seg.ident).unwrap_or(Ident::empty());
Ok((
ident,
ItemKind::Delegation(Box::new(Delegation { id: DUMMY_NODE_ID, qself, path, body })),
))
let ident = rename.unwrap_or_else(|| path.segments.last().unwrap().ident);
let deleg = Delegation { id: DUMMY_NODE_ID, qself, path, rename, body };
Ok((ident, ItemKind::Delegation(Box::new(deleg))))
}
fn parse_item_list<T>(