Skip to content

Commit b237f90

Browse files
Don't drop PResult without handling the error
1 parent 8d1e3d3 commit b237f90

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/rustc_parse/src/parser/item.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,10 @@ impl<'a> Parser<'a> {
14741474
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
14751475
} else {
14761476
let err = if self.check_fn_front_matter(false) {
1477-
let _ = self.parse_fn(&mut Vec::new(), |_| true, lo);
1477+
// We use `parse_fn` to get a span for the function
1478+
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
1479+
db.delay_as_bug();
1480+
}
14781481
let mut err = self.struct_span_err(
14791482
lo.to(self.prev_token.span),
14801483
&format!("functions are not allowed in {} definitions", adt_ty),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for #85794
2+
3+
struct Baz {
4+
inner : dyn fn ()
5+
//~^ ERROR expected `,`, or `}`, found keyword `fn`
6+
//~| ERROR functions are not allowed in struct definitions
7+
//~| ERROR cannot find type `dyn` in this scope
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: expected `,`, or `}`, found keyword `fn`
2+
--> $DIR/fn-field-parse-error-ice.rs:4:16
3+
|
4+
LL | inner : dyn fn ()
5+
| ^ help: try adding a comma: `,`
6+
7+
error: functions are not allowed in struct definitions
8+
--> $DIR/fn-field-parse-error-ice.rs:4:17
9+
|
10+
LL | inner : dyn fn ()
11+
| ^^
12+
|
13+
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
14+
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
15+
16+
error[E0412]: cannot find type `dyn` in this scope
17+
--> $DIR/fn-field-parse-error-ice.rs:4:13
18+
|
19+
LL | inner : dyn fn ()
20+
| ^^^ not found in this scope
21+
22+
error: aborting due to 3 previous errors
23+
24+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)