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

Support literals in const generics without a block #263

Merged
merged 1 commit into from
Dec 5, 2017
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
2 changes: 1 addition & 1 deletion src/gen/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ pub fn fold_generic_argument<V: Folder + ?Sized>(_visitor: &mut V, _i: GenericAr
}
Const(_binding_0, ) => {
Const (
full!(_visitor.fold_expr_block(_binding_0)),
_visitor.fold_expr(_binding_0),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gen/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ pub fn visit_generic_argument<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V,
_visitor.visit_type_binding(&* _binding_0);
}
Const(ref _binding_0, ) => {
full!(_visitor.visit_expr_block(&* _binding_0));
_visitor.visit_expr(&* _binding_0);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gen/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ pub fn visit_generic_argument_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i:
_visitor.visit_type_binding_mut(&mut * _binding_0);
}
Const(ref mut _binding_0, ) => {
full!(_visitor.visit_expr_block_mut(&mut * _binding_0));
_visitor.visit_expr_mut(&mut * _binding_0);
}
}
}
Expand Down
25 changes: 19 additions & 6 deletions src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ast_enum! {
///
/// NOTE: Identity expressions are represented as Type arguments, as
/// they are indistinguishable syntactically.
Const(ExprBlock),
Const(Expr),
}
}

Expand Down Expand Up @@ -716,7 +716,9 @@ pub mod parsing {
|
syn!(TypeBinding) => { GenericArgument::TypeBinding }
|
syn!(ExprBlock) => { GenericArgument::Const }
syn!(Lit) => { |l| GenericArgument::Const(ExprKind::Lit(l).into()) }
|
syn!(ExprBlock) => { |b| GenericArgument::Const(ExprKind::Block(b).into()) }
));
}

Expand Down Expand Up @@ -1048,10 +1050,21 @@ mod printing {
GenericArgument::Lifetime(ref lt) => lt.to_tokens(tokens),
GenericArgument::Type(ref ty) => ty.to_tokens(tokens),
GenericArgument::TypeBinding(ref tb) => tb.to_tokens(tokens),
#[cfg(not(feature = "full"))]
GenericArgument::Const(_) => unreachable!(),
#[cfg(feature = "full")]
GenericArgument::Const(ref eb) => eb.to_tokens(tokens),
GenericArgument::Const(ref e) => match e.node {
ExprKind::Lit(_) => e.to_tokens(tokens),

// NOTE: We should probably support parsing blocks with only
// expressions in them without the full feature for const
// generics.
#[cfg(feature = "full")]
ExprKind::Block(_) => e.to_tokens(tokens),

// ERROR CORRECTION: Add braces to make sure that the
// generated code is valid.
_ => tokens::Brace::default().surround(tokens, |tokens| {
e.to_tokens(tokens);
}),
}
}
}
}
Expand Down