Support literals in const generics without a block
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index ed7db7c..08d0b41 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -1486,7 +1486,7 @@
}
Const(_binding_0, ) => {
Const (
- full!(_visitor.fold_expr_block(_binding_0)),
+ _visitor.fold_expr(_binding_0),
)
}
}
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index b91254f..e9f99e3 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -1156,7 +1156,7 @@
_visitor.visit_type_binding(&* _binding_0);
}
Const(ref _binding_0, ) => {
- full!(_visitor.visit_expr_block(&* _binding_0));
+ _visitor.visit_expr(&* _binding_0);
}
}
}
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 5ff8dce..9ce6c42 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -1156,7 +1156,7 @@
_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);
}
}
}
diff --git a/src/ty.rs b/src/ty.rs
index 085bf9c..dd6c206 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -205,7 +205,7 @@
///
/// NOTE: Identity expressions are represented as Type arguments, as
/// they are indistinguishable syntactically.
- Const(ExprBlock),
+ Const(Expr),
}
}
@@ -716,7 +716,9 @@
|
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()) }
));
}
@@ -1048,10 +1050,21 @@
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);
+ }),
+ }
}
}
}