@@ -20,7 +20,8 @@ use super::*;
20
20
pub ( super ) fn mod_contents ( p : & mut Parser < ' _ > , stop_on_r_curly : bool ) {
21
21
attributes:: inner_attrs ( p) ;
22
22
while !( p. at ( EOF ) || ( p. at ( T ! [ '}' ] ) && stop_on_r_curly) ) {
23
- item_or_macro ( p, stop_on_r_curly) ;
23
+ // We can set `is_in_extern=true`, because it only allows `safe fn`, and there is no ambiguity here.
24
+ item_or_macro ( p, stop_on_r_curly, true ) ;
24
25
}
25
26
}
26
27
@@ -41,11 +42,11 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[
41
42
T ! [ ; ] ,
42
43
] ) ;
43
44
44
- pub ( super ) fn item_or_macro ( p : & mut Parser < ' _ > , stop_on_r_curly : bool ) {
45
+ pub ( super ) fn item_or_macro ( p : & mut Parser < ' _ > , stop_on_r_curly : bool , is_in_extern : bool ) {
45
46
let m = p. start ( ) ;
46
47
attributes:: outer_attrs ( p) ;
47
48
48
- let m = match opt_item ( p, m) {
49
+ let m = match opt_item ( p, m, is_in_extern ) {
49
50
Ok ( ( ) ) => {
50
51
if p. at ( T ! [ ; ] ) {
51
52
p. err_and_bump (
@@ -91,7 +92,7 @@ pub(super) fn item_or_macro(p: &mut Parser<'_>, stop_on_r_curly: bool) {
91
92
}
92
93
93
94
/// Try to parse an item, completing `m` in case of success.
94
- pub ( super ) fn opt_item ( p : & mut Parser < ' _ > , m : Marker ) -> Result < ( ) , Marker > {
95
+ pub ( super ) fn opt_item ( p : & mut Parser < ' _ > , m : Marker , is_in_extern : bool ) -> Result < ( ) , Marker > {
95
96
// test_err pub_expr
96
97
// fn foo() { pub 92; }
97
98
let has_visibility = opt_visibility ( p, false ) ;
@@ -135,7 +136,9 @@ pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> {
135
136
has_mods = true ;
136
137
}
137
138
138
- if p. at_contextual_kw ( T ! [ safe] ) {
139
+ // test safe_outside_of_extern
140
+ // fn foo() { safe = true; }
141
+ if is_in_extern && p. at_contextual_kw ( T ! [ safe] ) {
139
142
p. eat_contextual_kw ( T ! [ safe] ) ;
140
143
has_mods = true ;
141
144
}
0 commit comments