File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
compiler/rustc_parse/src/parser Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -2182,7 +2182,11 @@ impl<'a> Parser<'a> {
2182
2182
// `extern ABI fn`
2183
2183
|| self.check_keyword_case(kw::Extern, case)
2184
2184
&& self.look_ahead(1, |t| t.can_begin_literal_maybe_minus())
2185
- && self.look_ahead(2, |t| t.is_keyword_case(kw::Fn, case))
2185
+ && (self.look_ahead(2, |t| t.is_keyword_case(kw::Fn, case)) ||
2186
+ // this branch is only for better diagnostic in later, `pub` is not allowed here
2187
+ (self.may_recover()
2188
+ && self.look_ahead(2, |t| t.is_keyword(kw::Pub))
2189
+ && self.look_ahead(3, |t| t.is_keyword_case(kw::Fn, case))))
2186
2190
}
2187
2191
2188
2192
/// Parses all the "front matter" (or "qualifiers") for a `fn` declaration,
Original file line number Diff line number Diff line change
1
+ #[link(name = "my_c_library")]
2
+ extern "C" {
3
+ fn my_c_function(x: i32) -> bool;
4
+ }
5
+
6
+ #[no_mangle]
7
+ extern "C" pub fn id(x: i32) -> i32 { x } //~ ERROR expected `fn`, found keyword `pub`
8
+
9
+ fn main() {}
Original file line number Diff line number Diff line change
1
+ error: expected `fn`, found keyword `pub`
2
+ --> $DIR/issue-113342.rs:7:12
3
+ |
4
+ LL | extern "C" pub fn id(x: i32) -> i32 { x }
5
+ | -----------^^^
6
+ | | |
7
+ | | expected `fn`
8
+ | help: visibility `pub` must come before `extern "C"`: `pub extern "C"`
9
+
10
+ error: aborting due to previous error
11
+
You can’t perform that action at this time.
0 commit comments