diff options
| author | bors <bors@rust-lang.org> | 2022-09-30 10:39:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-30 10:39:09 +0000 |
| commit | f914b82a754c6d85c0a909ab152f5b611defef73 (patch) | |
| tree | 4aadd6df5dcdf3bea8a2cbd16bf91fb0e2753c92 /compiler/rustc_parse/src | |
| parent | 4a0ee3cdc66573c8b46471462db7088a89d25183 (diff) | |
| parent | 588a25a6f8bfeec3a6bb8d8f498b0ed0794f7096 (diff) | |
| download | rust-f914b82a754c6d85c0a909ab152f5b611defef73.tar.gz rust-f914b82a754c6d85c0a909ab152f5b611defef73.zip | |
Auto merge of #102509 - matthiaskrgr:rollup-gtenet8, r=matthiaskrgr
Rollup of 5 pull requests
Successful merges:
- #101075 (Migrate rustc_codegen_gcc to SessionDiagnostics )
- #102350 (Improve errors for incomplete functions in struct definitions)
- #102481 (rustdoc: remove unneeded CSS `.rust-example-rendered { position }`)
- #102491 (rustdoc: remove no-op source sidebar `opacity`)
- #102499 (Adjust the s390x data layout for LLVM 16)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index c8a8e00b1fa..25425fbb2c6 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1753,18 +1753,24 @@ impl<'a> Parser<'a> { }; // We use `parse_fn` to get a span for the function let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true }; - if let Err(mut db) = - self.parse_fn(&mut AttrVec::new(), fn_parse_mode, lo, &inherited_vis) - { - db.delay_as_bug(); + match self.parse_fn(&mut AttrVec::new(), fn_parse_mode, lo, &inherited_vis) { + Ok(_) => { + let mut err = self.struct_span_err( + lo.to(self.prev_token.span), + &format!("functions are not allowed in {adt_ty} definitions"), + ); + err.help( + "unlike in C++, Java, and C#, functions are declared in `impl` blocks", + ); + err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information"); + err + } + Err(err) => { + err.cancel(); + self.restore_snapshot(snapshot); + self.expected_ident_found() + } } - let mut err = self.struct_span_err( - lo.to(self.prev_token.span), - &format!("functions are not allowed in {adt_ty} definitions"), - ); - err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks"); - err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information"); - err } else if self.eat_keyword(kw::Struct) { match self.parse_item_struct() { Ok((ident, _)) => { |
