diff options
| author | bors <bors@rust-lang.org> | 2024-04-24 11:57:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-24 11:57:35 +0000 |
| commit | 5557f8c9d08d7f3f680943dcf97b6d4a7eb13aea (patch) | |
| tree | 846484bd65fa87e206d8a01e1d98e58efb13f430 /compiler/rustc_parse/src/parser | |
| parent | e9362896e0eaaa86372b8ee2634b5761dd9e5ab7 (diff) | |
| parent | 7b7c26f09bbc292da8600e8dfaa454de63ada886 (diff) | |
| download | rust-5557f8c9d08d7f3f680943dcf97b6d4a7eb13aea.tar.gz rust-5557f8c9d08d7f3f680943dcf97b6d4a7eb13aea.zip | |
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.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 84ecd0a0de5..ed51710564a 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -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>( |
