@@ -18,6 +18,7 @@ use util::parser::{self, AssocOp, Fixity};
1818use attr;
1919use codemap:: { self , CodeMap } ;
2020use syntax_pos:: { self , BytePos } ;
21+ use syntax_pos:: hygiene:: { Mark , MarkKind , SyntaxContext } ;
2122use parse:: token:: { self , BinOpToken , Token } ;
2223use parse:: lexer:: comments;
2324use parse:: { self , ParseSess } ;
@@ -93,7 +94,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
9394 is_expanded : bool ) -> io:: Result < ( ) > {
9495 let mut s = State :: new_from_input ( cm, sess, filename, input, out, ann, is_expanded) ;
9596
96- if is_expanded && !std_inject:: injected_crate_name ( krate ) . is_none ( ) {
97+ if is_expanded && !std_inject:: injected_crate_name ( ) . is_none ( ) {
9798 // We need to print `#![no_std]` (and its feature gate) so that
9899 // compiling pretty-printed source won't inject libstd again.
99100 // However we don't want these attributes in the AST because
@@ -734,6 +735,8 @@ pub trait PrintState<'a> {
734735 if segment. identifier . name != keywords:: CrateRoot . name ( ) &&
735736 segment. identifier . name != keywords:: DollarCrate . name ( ) {
736737 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 ) ?;
737740 }
738741 }
739742 self . writer ( ) . space ( ) ?;
@@ -822,6 +825,19 @@ pub trait PrintState<'a> {
822825 }
823826
824827 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+ }
825841}
826842
827843impl < ' a > PrintState < ' a > for State < ' a > {
@@ -2411,6 +2427,8 @@ impl<'a> State<'a> {
24112427 if let Some ( ref parameters) = segment. parameters {
24122428 self . print_path_parameters ( parameters, colons_before_params) ?;
24132429 }
2430+ } else if segment. identifier . name == keywords:: DollarCrate . name ( ) {
2431+ self . print_dollar_crate ( segment. identifier . ctxt ) ?;
24142432 }
24152433 Ok ( ( ) )
24162434 }
0 commit comments