Skip to content

Commit db13fe6

Browse files
committed
Feature gate async fn methods
1 parent b13562a commit db13fe6

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/libsyntax/feature_gate.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -2034,28 +2034,22 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
20342034
fn_decl: &'a ast::FnDecl,
20352035
span: Span,
20362036
_node_id: NodeId) {
2037-
match fn_kind {
2038-
FnKind::ItemFn(_, header, _, _) => {
2039-
// Check for const fn and async fn declarations.
2040-
if header.asyncness.node.is_async() {
2041-
gate_feature_post!(&self, async_await, span, "async fn is unstable");
2042-
}
2037+
if let Some(header) = fn_kind.header() {
2038+
// Check for const fn and async fn declarations.
2039+
if header.asyncness.node.is_async() {
2040+
gate_feature_post!(&self, async_await, span, "async fn is unstable");
2041+
}
20432042

2044-
if fn_decl.c_variadic {
2045-
gate_feature_post!(&self, c_variadic, span,
2046-
"C-varaidic functions are unstable");
2047-
}
2048-
// Stability of const fn methods are covered in
2049-
// `visit_trait_item` and `visit_impl_item` below; this is
2050-
// because default methods don't pass through this point.
2043+
// Stability of const fn methods are covered in
2044+
// `visit_trait_item` and `visit_impl_item` below; this is
2045+
// because default methods don't pass through this point.
2046+
self.check_abi(header.abi, span);
2047+
}
20512048

2052-
self.check_abi(header.abi, span);
2053-
}
2054-
FnKind::Method(_, sig, _, _) => {
2055-
self.check_abi(sig.header.abi, span);
2056-
}
2057-
_ => {}
2049+
if fn_decl.c_variadic {
2050+
gate_feature_post!(&self, c_variadic, span, "C-varaidic functions are unstable");
20582051
}
2052+
20592053
visit::walk_fn(self, fn_kind, fn_decl, span);
20602054
}
20612055

src/libsyntax/visit.rs

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pub enum FnKind<'a> {
3131
Closure(&'a Expr),
3232
}
3333

34+
impl<'a> FnKind<'a> {
35+
pub fn header(&self) -> Option<&'a FnHeader> {
36+
match *self {
37+
FnKind::ItemFn(_, header, _, _) => Some(header),
38+
FnKind::Method(_, sig, _, _) => Some(&sig.header),
39+
FnKind::Closure(_) => None,
40+
}
41+
}
42+
}
43+
3444
/// Each method of the Visitor trait is a hook to be potentially
3545
/// overridden. Each method's default implementation recursively visits
3646
/// the substructure of the input via the corresponding `walk` method;

0 commit comments

Comments
 (0)