This repository was archived by the owner on Dec 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: env;
2+ use std:: process:: Command ;
3+ use std:: str;
4+
5+ fn main ( ) {
6+ let compiler = match rustc_version ( ) {
7+ Some ( compiler) => compiler,
8+ None => return ,
9+ } ;
10+
11+ if compiler. minor < 33 {
12+ println ! ( "cargo:rustc-cfg=proc_macro_hack_no_crate_as_underscore" ) ;
13+ }
14+ }
15+
16+ struct Compiler {
17+ minor : u32 ,
18+ }
19+
20+ fn rustc_version ( ) -> Option < Compiler > {
21+ let rustc = env:: var_os ( "RUSTC" ) ?;
22+ let output = Command :: new ( rustc) . arg ( "--version" ) . output ( ) . ok ( ) ?;
23+ let version = str:: from_utf8 ( & output. stdout ) . ok ( ) ?;
24+ let mut pieces = version. split ( '.' ) ;
25+ if pieces. next ( ) != Some ( "rustc 1" ) {
26+ return None ;
27+ }
28+ let minor = pieces. next ( ) ?. parse ( ) . ok ( ) ?;
29+ Some ( Compiler { minor } )
30+ }
Original file line number Diff line number Diff line change @@ -332,6 +332,16 @@ fn expand_export(export: Export, args: ExportArgs) -> TokenStream {
332332 } ) ;
333333 }
334334
335+ let extern_crate = if cfg ! ( proc_macro_hack_no_crate_as_underscore) {
336+ quote ! ( )
337+ } else {
338+ quote ! {
339+ #[ allow( unused_imports) ]
340+ #[ macro_use]
341+ extern crate #from as _;
342+ }
343+ } ;
344+
335345 if export. macros . len ( ) != 1 {
336346 export_dispatch = quote ! ( { #export_dispatch} ) ;
337347 export_call_site = quote ! ( { #export_call_site} ) ;
@@ -357,6 +367,8 @@ fn expand_export(export: Export, args: ExportArgs) -> TokenStream {
357367 } ;
358368
359369 let expanded = quote ! {
370+ #extern_crate
371+
360372 #[ doc( hidden) ]
361373 #vis use #from:: #actual_names;
362374
You can’t perform that action at this time.
0 commit comments