@@ -20,7 +20,8 @@ use super::*;
2020pub ( super ) fn mod_contents ( p : & mut Parser < ' _ > , stop_on_r_curly : bool ) {
2121 attributes:: inner_attrs ( p) ;
2222 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 ) ;
2425 }
2526}
2627
@@ -41,11 +42,11 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[
4142 T ! [ ; ] ,
4243] ) ;
4344
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 ) {
4546 let m = p. start ( ) ;
4647 attributes:: outer_attrs ( p) ;
4748
48- let m = match opt_item ( p, m) {
49+ let m = match opt_item ( p, m, is_in_extern ) {
4950 Ok ( ( ) ) => {
5051 if p. at ( T ! [ ; ] ) {
5152 p. err_and_bump (
@@ -91,7 +92,7 @@ pub(super) fn item_or_macro(p: &mut Parser<'_>, stop_on_r_curly: bool) {
9192}
9293
9394/// 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 > {
9596 // test_err pub_expr
9697 // fn foo() { pub 92; }
9798 let has_visibility = opt_visibility ( p, false ) ;
@@ -135,7 +136,9 @@ pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> {
135136 has_mods = true ;
136137 }
137138
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] ) {
139142 p. eat_contextual_kw ( T ! [ safe] ) ;
140143 has_mods = true ;
141144 }
0 commit comments