@@ -18,6 +18,7 @@ use util::parser::{self, AssocOp, Fixity};
18
18
use attr;
19
19
use codemap:: { self , CodeMap } ;
20
20
use syntax_pos:: { self , BytePos } ;
21
+ use syntax_pos:: hygiene:: { Mark , MarkKind , SyntaxContext } ;
21
22
use parse:: token:: { self , BinOpToken , Token } ;
22
23
use parse:: lexer:: comments;
23
24
use parse:: { self , ParseSess } ;
@@ -93,7 +94,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
93
94
is_expanded : bool ) -> io:: Result < ( ) > {
94
95
let mut s = State :: new_from_input ( cm, sess, filename, input, out, ann, is_expanded) ;
95
96
96
- if is_expanded && !std_inject:: injected_crate_name ( krate ) . is_none ( ) {
97
+ if is_expanded && !std_inject:: injected_crate_name ( ) . is_none ( ) {
97
98
// We need to print `#![no_std]` (and its feature gate) so that
98
99
// compiling pretty-printed source won't inject libstd again.
99
100
// However we don't want these attributes in the AST because
@@ -734,6 +735,8 @@ pub trait PrintState<'a> {
734
735
if segment. identifier . name != keywords:: CrateRoot . name ( ) &&
735
736
segment. identifier . name != keywords:: DollarCrate . name ( ) {
736
737
self . writer ( ) . word ( & segment. identifier . name . as_str ( ) ) ?;
738
+ } else if segment. identifier . name == keywords:: DollarCrate . name ( ) {
739
+ self . print_dollar_crate ( segment. identifier . ctxt ) ?;
737
740
}
738
741
}
739
742
self . writer ( ) . space ( ) ?;
@@ -822,6 +825,19 @@ pub trait PrintState<'a> {
822
825
}
823
826
824
827
fn nbsp ( & mut self ) -> io:: Result < ( ) > { self . writer ( ) . word ( " " ) }
828
+
829
+ fn print_dollar_crate ( & mut self , mut ctxt : SyntaxContext ) -> io:: Result < ( ) > {
830
+ if let Some ( mark) = ctxt. adjust ( Mark :: root ( ) ) {
831
+ // Make a best effort to print something that complies
832
+ if mark. kind ( ) == MarkKind :: Builtin {
833
+ if let Some ( name) = std_inject:: injected_crate_name ( ) {
834
+ self . writer ( ) . word ( "::" ) ?;
835
+ self . writer ( ) . word ( name) ?;
836
+ }
837
+ }
838
+ }
839
+ Ok ( ( ) )
840
+ }
825
841
}
826
842
827
843
impl < ' a > PrintState < ' a > for State < ' a > {
@@ -2411,6 +2427,8 @@ impl<'a> State<'a> {
2411
2427
if let Some ( ref parameters) = segment. parameters {
2412
2428
self . print_path_parameters ( parameters, colons_before_params) ?;
2413
2429
}
2430
+ } else if segment. identifier . name == keywords:: DollarCrate . name ( ) {
2431
+ self . print_dollar_crate ( segment. identifier . ctxt ) ?;
2414
2432
}
2415
2433
Ok ( ( ) )
2416
2434
}
0 commit comments