Skip to content
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

Add Expr::Infer variant for inferred const generic arguments #1295

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ ast_enum_of_structs! {
/// A square bracketed indexing expression: `vector[2]`.
Index(ExprIndex),

/// The inferred value of a const generic argument, denoted `_`.
Infer(ExprInfer),

/// A `let` guard: `let Some(x) = opt`.
Let(ExprLet),

Expand Down Expand Up @@ -473,6 +476,14 @@ ast_struct! {
}
}

ast_struct! {
/// The inferred value of a const generic argument, denoted `_`.
pub struct ExprInfer #full {
pub attrs: Vec<Attribute>,
pub underscore_token: Token![_],
}
}

ast_struct! {
/// A `let` guard: `let Some(x) = opt`.
#[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
Expand Down Expand Up @@ -740,6 +751,7 @@ impl Expr {
| Expr::Group(ExprGroup { attrs, .. })
| Expr::If(ExprIf { attrs, .. })
| Expr::Index(ExprIndex { attrs, .. })
| Expr::Infer(ExprInfer { attrs, .. })
| Expr::Let(ExprLet { attrs, .. })
| Expr::Lit(ExprLit { attrs, .. })
| Expr::Loop(ExprLoop { attrs, .. })
Expand Down Expand Up @@ -1005,8 +1017,6 @@ pub(crate) mod parsing {
use crate::parse::ParseBuffer;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
#[cfg(feature = "full")]
use proc_macro2::TokenTree;
use std::cmp::Ordering;

crate::custom_keyword!(raw);
Expand Down Expand Up @@ -1687,9 +1697,7 @@ pub(crate) mod parsing {
} else if input.peek(Token![..]) {
expr_range(input, allow_struct).map(Expr::Range)
} else if input.peek(Token![_]) {
Ok(Expr::Verbatim(TokenStream::from(
input.parse::<TokenTree>()?,
)))
input.parse().map(Expr::Infer)
} else if input.peek(Lifetime) {
let the_label: Label = input.parse()?;
let mut expr = if input.peek(Token![while]) {
Expand Down Expand Up @@ -2103,6 +2111,17 @@ pub(crate) mod parsing {
Ok((else_token, Box::new(else_branch)))
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprInfer {
fn parse(input: ParseStream) -> Result<Self> {
Ok(ExprInfer {
attrs: input.call(Attribute::parse_outer)?,
underscore_token: input.parse()?,
})
}
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprForLoop {
Expand Down Expand Up @@ -3293,6 +3312,15 @@ pub(crate) mod printing {
}
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprInfer {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
self.underscore_token.to_tokens(tokens);
}
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for RangeLimits {
Expand Down
12 changes: 12 additions & 0 deletions src/gen/clone.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/gen/debug.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/gen/eq.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/gen/fold.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 37 additions & 22 deletions src/gen/hash.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/gen/visit.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading