@@ -5,7 +5,6 @@ use crate::trap::{DiagnosticSeverity, TrapFile, TrapId};
55use crate :: trap:: { Label , TrapClass } ;
66use ra_ap_base_db:: EditionedFileId ;
77use ra_ap_hir:: Semantics ;
8- use ra_ap_hir:: db:: ExpandDatabase ;
98use ra_ap_hir_expand:: builtin:: { BuiltinDeriveExpander , find_builtin_derive} ;
109use ra_ap_hir_expand:: span_map:: ExpansionSpanMap ;
1110use ra_ap_hir_expand:: { ExpandResult , ExpandTo , HirFileId , InFile , map_node_range_up_rooted} ;
@@ -22,7 +21,7 @@ use ra_ap_syntax_bridge::{
2221 DocCommentDesugarMode , syntax_node_to_token_tree, token_tree_to_syntax_node,
2322} ;
2423
25- impl Emission < ast:: Item > for Translator < ' _ > {
24+ impl Emission < ast:: Item > for Translator < ' _ , ' _ > {
2625 fn pre_emit ( & mut self , node : & ast:: Item ) -> Option < Label < generated:: Item > > {
2726 self . item_pre_emit ( node) . map ( Into :: into)
2827 }
@@ -32,7 +31,7 @@ impl Emission<ast::Item> for Translator<'_> {
3231 }
3332}
3433
35- impl Emission < ast:: AssocItem > for Translator < ' _ > {
34+ impl Emission < ast:: AssocItem > for Translator < ' _ , ' _ > {
3635 fn pre_emit ( & mut self , node : & ast:: AssocItem ) -> Option < Label < generated:: AssocItem > > {
3736 self . item_pre_emit ( & node. clone ( ) . into ( ) ) . map ( Into :: into)
3837 }
@@ -42,7 +41,7 @@ impl Emission<ast::AssocItem> for Translator<'_> {
4241 }
4342}
4443
45- impl Emission < ast:: ExternItem > for Translator < ' _ > {
44+ impl Emission < ast:: ExternItem > for Translator < ' _ , ' _ > {
4645 fn pre_emit ( & mut self , node : & ast:: ExternItem ) -> Option < Label < generated:: ExternItem > > {
4746 self . item_pre_emit ( & node. clone ( ) . into ( ) ) . map ( Into :: into)
4847 }
@@ -52,7 +51,7 @@ impl Emission<ast::ExternItem> for Translator<'_> {
5251 }
5352}
5453
55- impl Emission < ast:: Meta > for Translator < ' _ > {
54+ impl Emission < ast:: Meta > for Translator < ' _ , ' _ > {
5655 fn pre_emit ( & mut self , _node : & ast:: Meta ) -> Option < Label < generated:: Meta > > {
5756 self . macro_context_depth += 1 ;
5857 None
@@ -63,43 +62,43 @@ impl Emission<ast::Meta> for Translator<'_> {
6362 }
6463}
6564
66- impl Emission < ast:: Fn > for Translator < ' _ > {
65+ impl Emission < ast:: Fn > for Translator < ' _ , ' _ > {
6766 fn post_emit ( & mut self , node : & ast:: Fn , label : Label < generated:: Function > ) {
6867 self . emit_function_has_implementation ( node, label) ;
6968 }
7069}
7170
72- impl Emission < ast:: Struct > for Translator < ' _ > {
71+ impl Emission < ast:: Struct > for Translator < ' _ , ' _ > {
7372 fn post_emit ( & mut self , node : & ast:: Struct , label : Label < generated:: Struct > ) {
7473 self . emit_derive_expansion ( node, label) ;
7574 }
7675}
7776
78- impl Emission < ast:: Enum > for Translator < ' _ > {
77+ impl Emission < ast:: Enum > for Translator < ' _ , ' _ > {
7978 fn post_emit ( & mut self , node : & ast:: Enum , label : Label < generated:: Enum > ) {
8079 self . emit_derive_expansion ( node, label) ;
8180 }
8281}
8382
84- impl Emission < ast:: Union > for Translator < ' _ > {
83+ impl Emission < ast:: Union > for Translator < ' _ , ' _ > {
8584 fn post_emit ( & mut self , node : & ast:: Union , label : Label < generated:: Union > ) {
8685 self . emit_derive_expansion ( node, label) ;
8786 }
8887}
8988
90- impl Emission < ast:: PathSegment > for Translator < ' _ > {
89+ impl Emission < ast:: PathSegment > for Translator < ' _ , ' _ > {
9190 fn post_emit ( & mut self , node : & ast:: PathSegment , label : Label < generated:: PathSegment > ) {
9291 self . extract_types_from_path_segment ( node, label) ;
9392 }
9493}
9594
96- impl Emission < ast:: Const > for Translator < ' _ > {
95+ impl Emission < ast:: Const > for Translator < ' _ , ' _ > {
9796 fn post_emit ( & mut self , node : & ast:: Const , label : Label < generated:: Const > ) {
9897 self . emit_const_has_implementation ( node, label) ;
9998 }
10099}
101100
102- impl Emission < ast:: MacroCall > for Translator < ' _ > {
101+ impl Emission < ast:: MacroCall > for Translator < ' _ , ' _ > {
103102 fn post_emit ( & mut self , node : & ast:: MacroCall , label : Label < generated:: MacroCall > ) {
104103 self . extract_macro_call_expanded ( node, label) ;
105104 }
@@ -123,13 +122,16 @@ pub enum SourceKind {
123122 Library ,
124123}
125124
126- pub struct Translator < ' a > {
125+ // `'a` is the (short) lifetime of the borrowed `path`, `'db` the lifetime of the borrowed
126+ // `Semantics`/database. They must stay separate: `Semantics<'db>` is invariant over `'db`, so
127+ // coupling it to the shorter `'a` fails to type-check.
128+ pub struct Translator < ' a , ' db > {
127129 pub trap : TrapFile ,
128130 path : & ' a str ,
129131 label : Label < generated:: File > ,
130132 line_index : LineIndex ,
131133 file_id : Option < EditionedFileId > ,
132- pub semantics : Option < & ' a Semantics < ' a , RootDatabase > > ,
134+ pub semantics : Option < & ' db Semantics < ' db , RootDatabase > > ,
133135 source_kind : SourceKind ,
134136 pub ( crate ) macro_context_depth : usize ,
135137 diagnostic_count : usize ,
@@ -144,15 +146,15 @@ const UNKNOWN_LOCATION: (LineCol, LineCol) =
144146
145147const DIAGNOSTIC_LIMIT_PER_FILE : usize = 100 ;
146148
147- impl < ' a > Translator < ' a > {
149+ impl < ' a , ' db > Translator < ' a , ' db > {
148150 pub fn new (
149151 trap : TrapFile ,
150152 path : & ' a str ,
151153 label : Label < generated:: File > ,
152154 line_index : LineIndex ,
153- semantic_info : Option < & FileSemanticInformation < ' a > > ,
155+ semantic_info : Option < & FileSemanticInformation < ' db > > ,
154156 source_kind : SourceKind ,
155- ) -> Translator < ' a > {
157+ ) -> Translator < ' a , ' db > {
156158 Translator {
157159 trap,
158160 path,
@@ -372,7 +374,7 @@ impl<'a> Translator<'a> {
372374 if let Some ( value) = semantics
373375 . hir_file_for ( expanded)
374376 . macro_file ( )
375- . and_then ( |macro_call_id| semantics . db . parse_macro_expansion_error ( macro_call_id ) )
377+ . and_then ( |macro_call_id| macro_call_id . parse_macro_expansion_error ( semantics . db ) )
376378 {
377379 if let Some ( err) = & value. err {
378380 let error = err. render_to_string ( semantics. db ) ;
@@ -381,9 +383,8 @@ impl<'a> Translator<'a> {
381383 == hir_file_id. file_id ( ) . map ( |f| f. file_id ( semantics. db ) )
382384 {
383385 let location = err. span ( ) . range
384- + semantics
385- . db
386- . ast_id_map ( hir_file_id)
386+ + hir_file_id
387+ . ast_id_map ( semantics. db )
387388 . get_erased ( err. span ( ) . anchor . ast_id )
388389 . text_range ( )
389390 . start ( ) ;
@@ -515,11 +516,9 @@ impl<'a> Translator<'a> {
515516 None => return false ,
516517 }
517518 }
518- HirFileId :: MacroFile ( macro_call) => sema
519- . db
520- . lookup_intern_macro_call ( macro_call)
521- . krate
522- . cfg_options ( sema. db ) ,
519+ HirFileId :: MacroFile ( macro_call) => {
520+ macro_call. loc ( sema. db ) . krate . cfg_options ( sema. db )
521+ }
523522 } ;
524523 cfg_options. check ( & cfg_expr) == Some ( false )
525524 } )
@@ -755,11 +754,11 @@ impl<'a> Translator<'a> {
755754 let semantics = self . semantics ?;
756755 let db = semantics. db ;
757756 let file_id = semantics. hir_file_for ( adt. syntax ( ) ) ;
758- let span_map = db . span_map ( file_id ) ;
757+ let span_map = file_id . span_map ( db ) ;
759758 let call_site = span_map. span_for_range ( adt. syntax ( ) . text_range ( ) ) ;
760759 let input = syntax_node_to_token_tree (
761760 adt. syntax ( ) ,
762- span_map. as_ref ( ) ,
761+ span_map,
763762 call_site,
764763 DocCommentDesugarMode :: ProcMacro ,
765764 ) ;
0 commit comments