@@ -15,6 +15,7 @@ use rustc_parse::new_parser_from_file;
1515use rustc_parse:: parser:: { ForceCollect , Parser } ;
1616use rustc_session:: lint:: builtin:: INCOMPLETE_INCLUDE ;
1717use rustc_span:: source_map:: SourceMap ;
18+ use rustc_span:: sym;
1819use rustc_span:: symbol:: Symbol ;
1920use rustc_span:: { Pos , Span } ;
2021use smallvec:: SmallVec ;
@@ -26,56 +27,54 @@ use std::rc::Rc;
2627// a given file into the current one.
2728
2829/// line!(): expands to the current line number
29- pub ( crate ) fn expand_line (
30- cx : & mut ExtCtxt < ' _ > ,
31- sp : Span ,
32- tts : TokenStream ,
33- ) -> MacroExpanderResult < ' static > {
30+ pub ( crate ) fn expand_line ( cx : & mut ExtCtxt < ' _ > , sp : Span , tts : TokenStream ) -> TokenStream {
3431 let sp = cx. with_def_site_ctxt ( sp) ;
3532 check_zero_tts ( cx, sp, tts, "line!" ) ;
3633
3734 let topmost = cx. expansion_cause ( ) . unwrap_or ( sp) ;
3835 let loc = cx. source_map ( ) . lookup_char_pos ( topmost. lo ( ) ) ;
3936
40- ExpandResult :: Ready ( MacEager :: expr ( cx. expr_u32 ( topmost, loc. line as u32 ) ) )
37+ let kind = token:: TokenKind :: lit (
38+ token:: LitKind :: Integer ,
39+ sym:: integer ( loc. line as u32 ) ,
40+ Some ( sym:: u32) ,
41+ ) ;
42+ TokenStream :: token_alone ( kind, topmost)
4143}
4244
4345/* column!(): expands to the current column number */
44- pub ( crate ) fn expand_column (
45- cx : & mut ExtCtxt < ' _ > ,
46- sp : Span ,
47- tts : TokenStream ,
48- ) -> MacroExpanderResult < ' static > {
46+ pub ( crate ) fn expand_column ( cx : & mut ExtCtxt < ' _ > , sp : Span , tts : TokenStream ) -> TokenStream {
4947 let sp = cx. with_def_site_ctxt ( sp) ;
5048 check_zero_tts ( cx, sp, tts, "column!" ) ;
5149
5250 let topmost = cx. expansion_cause ( ) . unwrap_or ( sp) ;
5351 let loc = cx. source_map ( ) . lookup_char_pos ( topmost. lo ( ) ) ;
5452
55- ExpandResult :: Ready ( MacEager :: expr ( cx. expr_u32 ( topmost, loc. col . to_usize ( ) as u32 + 1 ) ) )
53+ let kind = token:: TokenKind :: lit (
54+ token:: LitKind :: Integer ,
55+ sym:: integer ( loc. col . to_usize ( ) as u32 + 1 ) ,
56+ Some ( sym:: u32) ,
57+ ) ;
58+ TokenStream :: token_alone ( kind, topmost)
5659}
5760
5861/// file!(): expands to the current filename */
5962/// The source_file (`loc.file`) contains a bunch more information we could spit
6063/// out if we wanted.
61- pub ( crate ) fn expand_file (
62- cx : & mut ExtCtxt < ' _ > ,
63- sp : Span ,
64- tts : TokenStream ,
65- ) -> MacroExpanderResult < ' static > {
64+ pub ( crate ) fn expand_file ( cx : & mut ExtCtxt < ' _ > , sp : Span , tts : TokenStream ) -> TokenStream {
6665 let sp = cx. with_def_site_ctxt ( sp) ;
6766 check_zero_tts ( cx, sp, tts, "file!" ) ;
6867
6968 let topmost = cx. expansion_cause ( ) . unwrap_or ( sp) ;
7069 let loc = cx. source_map ( ) . lookup_char_pos ( topmost. lo ( ) ) ;
7170
7271 use rustc_session:: { config:: RemapPathScopeComponents , RemapFileNameExt } ;
73- ExpandResult :: Ready ( MacEager :: expr ( cx . expr_str (
74- topmost ,
75- Symbol :: intern (
76- & loc . file . name . for_scope ( cx . sess , RemapPathScopeComponents :: MACRO ) . to_string_lossy ( ) ,
77- ) ,
78- ) ) )
72+
73+ let symbol = Symbol :: intern (
74+ & loc . file . name . for_scope ( cx . sess , RemapPathScopeComponents :: MACRO ) . to_string_lossy ( ) ,
75+ ) ;
76+ let kind = token :: TokenKind :: lit ( token :: LitKind :: Str , symbol , None ) ;
77+ TokenStream :: token_alone ( kind , topmost )
7978}
8079
8180pub ( crate ) fn expand_stringify (
@@ -88,17 +87,15 @@ pub(crate) fn expand_stringify(
8887 ExpandResult :: Ready ( MacEager :: expr ( cx. expr_str ( sp, Symbol :: intern ( & s) ) ) )
8988}
9089
91- pub ( crate ) fn expand_mod (
92- cx : & mut ExtCtxt < ' _ > ,
93- sp : Span ,
94- tts : TokenStream ,
95- ) -> MacroExpanderResult < ' static > {
90+ pub ( crate ) fn expand_module_path ( cx : & mut ExtCtxt < ' _ > , sp : Span , tts : TokenStream ) -> TokenStream {
9691 let sp = cx. with_def_site_ctxt ( sp) ;
9792 check_zero_tts ( cx, sp, tts, "module_path!" ) ;
9893 let mod_path = & cx. current_expansion . module . mod_path ;
9994 let string = mod_path. iter ( ) . map ( |x| x. to_string ( ) ) . collect :: < Vec < String > > ( ) . join ( "::" ) ;
10095
101- ExpandResult :: Ready ( MacEager :: expr ( cx. expr_str ( sp, Symbol :: intern ( & string) ) ) )
96+ let symbol = Symbol :: intern ( & string) ;
97+ let kind = token:: TokenKind :: lit ( token:: LitKind :: Str , symbol, None ) ;
98+ TokenStream :: token_alone ( kind, sp)
10299}
103100
104101/// include! : parse the given file as an expr
0 commit comments