-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn cfg_match
into a builtin
#116323
Turn cfg_match
into a builtin
#116323
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@@ -229,35 +229,61 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool { | |||
#[derive(PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] | |||
pub enum TokenKind { | |||
/* Expression-operator symbols. */ | |||
/// `=` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have often wondered about the meaning of some variants, so let's just comment what they actually are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change and the // tidy-alphabetical
stuff can be submitted separately and I'll approve them right away.
struct CfgMatchOutput(Vec<P<Item>>); | ||
|
||
impl MacResult for CfgMatchOutput { | ||
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[P<AssocItem>; 1]>> { | ||
let mut rslt = SmallVec::with_capacity(self.0.len()); | ||
rslt.extend(self.0.into_iter().filter_map(|item| { | ||
let Item { attrs, id, span, vis, ident, kind, tokens } = item.into_inner(); | ||
let ItemKind::Fn(fun) = kind else { | ||
return None; | ||
}; | ||
Some(P(Item { attrs, id, ident, kind: AssocItemKind::Fn(fun), span, tokens, vis })) | ||
})); | ||
Some(rslt) | ||
} | ||
|
||
fn make_items(self: Box<Self>) -> Option<SmallVec<[P<Item>; 1]>> { | ||
Some(<_>::from(self.0)) | ||
} | ||
|
||
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[Stmt; 1]>> { | ||
let mut rslt = SmallVec::with_capacity(self.0.len()); | ||
rslt.extend(self.0.into_iter().map(|item| { | ||
let id = item.id; | ||
let span = item.span; | ||
Stmt { id, kind: StmtKind::Item(item), span } | ||
})); | ||
Some(rslt) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only items are acceptable as input but the output can be three different things at the current time and I don't know if there are more expected variants. This is a best effort.
let mut parser = cx.new_parser_from_tts(tts); | ||
let mut does_not_have_wildcard = true; | ||
let mut items = Vec::with_capacity(4); | ||
let mut items_offsets = Vec::with_capacity(4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This auxiliary items_offsets
vector is used to avoid creating Vec<Vec<P<Item>>>
, i.e., all items are stored in the same contiguous items
memory.
`items`: [ Items of first arm, Items of second arm, .. ]
|_____0 to 10______| |_____10 to 25_____|
| ______________/
| /
`items_offsets`: [ 10, 25, ..]
This comment has been minimized.
This comment has been minimized.
@@ -478,6 +478,7 @@ make_MacEager! { | |||
trait_items: SmallVec<[P<ast::AssocItem>; 1]>, | |||
foreign_items: SmallVec<[P<ast::ForeignItem>; 1]>, | |||
stmts: SmallVec<[ast::Stmt; 1]>, | |||
token_stream: P<TokenStream>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
Why is this a goal in the first place? |
Personally, I am just trying to resolve concerns in order to use this feature on stable ASAP so it is not very important if Anyway let me know if this PR isn't really necessary. |
Misc improvements cc rust-lang#116323 (comment) r? `@petrochenkov`
Rollup merge of rust-lang#116696 - c410-f3r:in-doc, r=petrochenkov Misc improvements cc rust-lang#116323 (comment) r? `@petrochenkov`
☔ The latest upstream changes (presumably #117335) made this pull request unmergeable. Please resolve the merge conflicts. |
@c410-f3r any updates on this? thanks |
Well, the future of this PR depends on the above conversation 👀 |
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this. @rustbot label: +S-inactive |
In regards to code, there is no missing feature or incomplete functionality so this PR is technically ready. But it seems there is no traction so whatever 🤷 |
ah, there wasn't much waiting in the original form but there was less/no interest in this so i think closing it would be the better option here. |
cc #115585
Such thing allows stuff that can't be easily done with declarative macros. For example, it is now possible to create arms without brackets.
cc @petrochenkov in case you want to say something