diff options
| author | Michael Howell <michael@notriddle.com> | 2021-12-06 11:07:34 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2021-12-06 11:16:46 -0700 |
| commit | 6611567f9e253edabcfc38006ef817712f6ce595 (patch) | |
| tree | 404ad58fe9394c2c68d2a75857125d3653164d55 /compiler/rustc_parse | |
| parent | 61995926d2bc39e048e3f259cb9363126edbe757 (diff) | |
| download | rust-6611567f9e253edabcfc38006ef817712f6ce595.tar.gz rust-6611567f9e253edabcfc38006ef817712f6ce595.zip | |
Expect extern fn with no body when parsing
Also add a test case for inserting a semicolon on extern fns.
Without this fix, we got an error like this:
error: expected one of `->`, `where`, or `{`, found `}`
--> chk.rs:3:1
|
2 | fn foo()
| --- - expected one of `->`, `where`, or `{`
| |
| while parsing this `fn`
3 | }
| ^ unexpected token
Since this is inside an extern block, you're required to write function
prototypes with no body. This fixes a regression, and adds a test case
for it.
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 0506a6eba3e..831c64e3faf 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -950,7 +950,7 @@ impl<'a> Parser<'a> { &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option<Option<P<ForeignItem>>>> { - let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true }; + let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: false }; Ok(self.parse_item_(fn_parse_mode, force_collect)?.map( |Item { attrs, id, span, vis, ident, kind, tokens }| { let kind = match ForeignItemKind::try_from(kind) { |
