@@ -532,6 +532,25 @@ impl<'a> AstValidator<'a> {
532
532
}
533
533
}
534
534
535
+ /// An item in `extern { ... }` cannot use non-ascii identifier.
536
+ fn check_foreign_item_ascii_only ( & self , ident : Ident ) {
537
+ let symbol_str = ident. as_str ( ) ;
538
+ if !symbol_str. is_ascii ( ) {
539
+ let n = 83942 ;
540
+ self . err_handler ( )
541
+ . struct_span_err (
542
+ ident. span ,
543
+ "items in `extern` blocks cannot use non-ascii identifiers" ,
544
+ )
545
+ . span_label ( self . current_extern_span ( ) , "in this `extern` block" )
546
+ . note ( & format ! (
547
+ "This limitation may be lifted in the future; see issue #{} <https://github.com/rust-lang/rust/issues/{}> for more information" ,
548
+ n, n,
549
+ ) )
550
+ . emit ( ) ;
551
+ }
552
+ }
553
+
535
554
/// Reject C-varadic type unless the function is foreign,
536
555
/// or free and `unsafe extern "C"` semantically.
537
556
fn check_c_varadic_type ( & self , fk : FnKind < ' a > ) {
@@ -592,7 +611,7 @@ impl<'a> AstValidator<'a> {
592
611
self . session,
593
612
ident. span,
594
613
E0754 ,
595
- "trying to load file for module `{}` with non ascii identifer name" ,
614
+ "trying to load file for module `{}` with non- ascii identifier name" ,
596
615
ident. name
597
616
)
598
617
. help ( "consider using `#[path]` attribute to specify filesystem path" )
@@ -1103,15 +1122,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1103
1122
self . check_defaultness ( fi. span , * def) ;
1104
1123
self . check_foreign_fn_bodyless ( fi. ident , body. as_deref ( ) ) ;
1105
1124
self . check_foreign_fn_headerless ( fi. ident , fi. span , sig. header ) ;
1125
+ self . check_foreign_item_ascii_only ( fi. ident ) ;
1106
1126
}
1107
1127
ForeignItemKind :: TyAlias ( box TyAliasKind ( def, generics, bounds, body) ) => {
1108
1128
self . check_defaultness ( fi. span , * def) ;
1109
1129
self . check_foreign_kind_bodyless ( fi. ident , "type" , body. as_ref ( ) . map ( |b| b. span ) ) ;
1110
1130
self . check_type_no_bounds ( bounds, "`extern` blocks" ) ;
1111
1131
self . check_foreign_ty_genericless ( generics) ;
1132
+ self . check_foreign_item_ascii_only ( fi. ident ) ;
1112
1133
}
1113
1134
ForeignItemKind :: Static ( _, _, body) => {
1114
1135
self . check_foreign_kind_bodyless ( fi. ident , "static" , body. as_ref ( ) . map ( |b| b. span ) ) ;
1136
+ self . check_foreign_item_ascii_only ( fi. ident ) ;
1115
1137
}
1116
1138
ForeignItemKind :: MacCall ( ..) => { }
1117
1139
}
0 commit comments