Skip to content

Commit 1f845ac

Browse files
committed
Add genness to FnHeader
1 parent 5facb42 commit 1f845ac

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,16 +2810,19 @@ pub struct FnHeader {
28102810
pub constness: Const,
28112811
/// The `extern` keyword and corresponding ABI string, if any
28122812
pub ext: Extern,
2813+
/// The `gen` keyword, if any
2814+
pub genness: Gen,
28132815
}
28142816

28152817
impl FnHeader {
28162818
/// Does this function header have any qualifiers or is it empty?
28172819
pub fn has_qualifiers(&self) -> bool {
2818-
let Self { unsafety, asyncness, constness, ext } = self;
2820+
let Self { unsafety, asyncness, constness, ext, genness } = self;
28192821
matches!(unsafety, Unsafe::Yes(_))
28202822
|| asyncness.is_async()
28212823
|| matches!(constness, Const::Yes(_))
28222824
|| !matches!(ext, Extern::None)
2825+
|| matches!(genness, Gen::Yes { .. })
28232826
}
28242827
}
28252828

@@ -2830,6 +2833,7 @@ impl Default for FnHeader {
28302833
asyncness: Async::No,
28312834
constness: Const::No,
28322835
ext: Extern::None,
2836+
genness: Gen::No,
28332837
}
28342838
}
28352839
}
@@ -3150,7 +3154,7 @@ mod size_asserts {
31503154
static_assert_size!(Block, 32);
31513155
static_assert_size!(Expr, 72);
31523156
static_assert_size!(ExprKind, 40);
3153-
static_assert_size!(Fn, 152);
3157+
static_assert_size!(Fn, 168);
31543158
static_assert_size!(ForeignItem, 96);
31553159
static_assert_size!(ForeignItemKind, 24);
31563160
static_assert_size!(GenericArg, 24);

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ pub trait MutVisitor: Sized {
125125
noop_visit_asyncness(a, self);
126126
}
127127

128+
fn visit_genness(&mut self, a: &mut Gen) {
129+
noop_visit_genness(a, self);
130+
}
131+
128132
fn visit_closure_binder(&mut self, b: &mut ClosureBinder) {
129133
noop_visit_closure_binder(b, self);
130134
}
@@ -881,6 +885,16 @@ pub fn noop_visit_asyncness<T: MutVisitor>(asyncness: &mut Async, vis: &mut T) {
881885
}
882886
}
883887

888+
pub fn noop_visit_genness<T: MutVisitor>(genness: &mut Gen, vis: &mut T) {
889+
match genness {
890+
Gen::Yes { span: _, closure_id, return_impl_trait_id } => {
891+
vis.visit_id(closure_id);
892+
vis.visit_id(return_impl_trait_id);
893+
}
894+
Gen::No => {}
895+
}
896+
}
897+
884898
pub fn noop_visit_fn_decl<T: MutVisitor>(decl: &mut P<FnDecl>, vis: &mut T) {
885899
let FnDecl { inputs, output } = decl.deref_mut();
886900
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
@@ -1170,9 +1184,10 @@ fn visit_const_item<T: MutVisitor>(
11701184
}
11711185

11721186
pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
1173-
let FnHeader { unsafety, asyncness, constness, ext: _ } = header;
1187+
let FnHeader { unsafety, asyncness, constness, ext: _, genness } = header;
11741188
visit_constness(constness, vis);
11751189
vis.visit_asyncness(asyncness);
1190+
vis.visit_genness(genness);
11761191
visit_unsafety(unsafety, vis);
11771192
}
11781193

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,7 @@ impl<'a> Parser<'a> {
25162516
constness: recover_constness,
25172517
unsafety: recover_unsafety,
25182518
asyncness: recover_asyncness,
2519+
genness, // FIXME(eholk): add keyword recovery logic here too.
25192520
ext,
25202521
});
25212522
}
@@ -2525,7 +2526,7 @@ impl<'a> Parser<'a> {
25252526
}
25262527
}
25272528

2528-
Ok(FnHeader { constness, unsafety, asyncness, ext })
2529+
Ok(FnHeader { constness, unsafety, asyncness, ext, genness })
25292530
}
25302531

25312532
/// Parses the parameter list and result type of a function declaration.

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl<'a> Parser<'a> {
596596
tokens: None,
597597
};
598598
let span_start = self.token.span;
599-
let ast::FnHeader { ext, unsafety, constness, asyncness } =
599+
let ast::FnHeader { ext, unsafety, constness, asyncness, genness: _ } =
600600
self.parse_fn_front_matter(&inherited_vis, Case::Sensitive)?;
601601
if self.may_recover() && self.token.kind == TokenKind::Lt {
602602
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
@@ -612,6 +612,7 @@ impl<'a> Parser<'a> {
612612
if let ast::Async::Yes { span, .. } = asyncness {
613613
self.sess.emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
614614
}
615+
// FIXME(eholk): emit a similar error for `gen fn()`
615616
let decl_span = span_start.to(self.token.span);
616617
Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params: params, decl, decl_span })))
617618
}

0 commit comments

Comments
 (0)