3535mod expr;
3636mod item;
3737
38+ use crate :: arena:: Arena ;
3839use crate :: dep_graph:: DepGraph ;
3940use crate :: hir:: { self , ParamName } ;
4041use crate :: hir:: HirVec ;
@@ -77,7 +78,7 @@ use rustc_error_codes::*;
7778
7879const HIR_ID_COUNTER_LOCKED : u32 = 0xFFFFFFFF ;
7980
80- pub struct LoweringContext < ' a > {
81+ pub struct LoweringContext < ' a , ' hir : ' a > {
8182 crate_root : Option < Symbol > ,
8283
8384 /// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
@@ -90,6 +91,9 @@ pub struct LoweringContext<'a> {
9091 /// librustc is independent of the parser, we use dynamic dispatch here.
9192 nt_to_tokenstream : NtToTokenstream ,
9293
94+ /// Used to allocate HIR nodes
95+ arena : & ' hir Arena < ' hir > ,
96+
9397 /// The items being lowered are collected here.
9498 items : BTreeMap < hir:: HirId , hir:: Item > ,
9599
@@ -240,13 +244,14 @@ impl<'a> ImplTraitContext<'a> {
240244 }
241245}
242246
243- pub fn lower_crate (
244- sess : & Session ,
245- dep_graph : & DepGraph ,
246- krate : & Crate ,
247- resolver : & mut dyn Resolver ,
247+ pub fn lower_crate < ' a , ' hir > (
248+ sess : & ' a Session ,
249+ dep_graph : & ' a DepGraph ,
250+ krate : & ' a Crate ,
251+ resolver : & ' a mut dyn Resolver ,
248252 nt_to_tokenstream : NtToTokenstream ,
249- ) -> hir:: Crate {
253+ arena : & ' hir Arena < ' hir > ,
254+ ) -> hir:: Crate < ' hir > {
250255 // We're constructing the HIR here; we don't care what we will
251256 // read, since we haven't even constructed the *input* to
252257 // incr. comp. yet.
@@ -259,6 +264,7 @@ pub fn lower_crate(
259264 sess,
260265 resolver,
261266 nt_to_tokenstream,
267+ arena,
262268 items : BTreeMap :: new ( ) ,
263269 trait_items : BTreeMap :: new ( ) ,
264270 impl_items : BTreeMap :: new ( ) ,
@@ -382,19 +388,19 @@ impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> {
382388 }
383389}
384390
385- impl < ' a > LoweringContext < ' a > {
386- fn lower_crate ( mut self , c : & Crate ) -> hir:: Crate {
391+ impl < ' a , ' hir > LoweringContext < ' a , ' hir > {
392+ fn lower_crate ( mut self , c : & Crate ) -> hir:: Crate < ' hir > {
387393 /// Full-crate AST visitor that inserts into a fresh
388394 /// `LoweringContext` any information that may be
389395 /// needed from arbitrary locations in the crate,
390396 /// e.g., the number of lifetime generic parameters
391397 /// declared for every type and trait definition.
392- struct MiscCollector < ' tcx , ' interner > {
393- lctx : & ' tcx mut LoweringContext < ' interner > ,
398+ struct MiscCollector < ' tcx , ' lowering , ' hir > {
399+ lctx : & ' tcx mut LoweringContext < ' lowering , ' hir > ,
394400 hir_id_owner : Option < NodeId > ,
395401 }
396402
397- impl MiscCollector < ' _ , ' _ > {
403+ impl MiscCollector < ' _ , ' _ , ' _ > {
398404 fn allocate_use_tree_hir_id_counters (
399405 & mut self ,
400406 tree : & UseTree ,
@@ -434,7 +440,7 @@ impl<'a> LoweringContext<'a> {
434440 }
435441 }
436442
437- impl < ' tcx , ' interner > Visitor < ' tcx > for MiscCollector < ' tcx , ' interner > {
443+ impl < ' tcx , ' lowering , ' hir > Visitor < ' tcx > for MiscCollector < ' tcx , ' lowering , ' hir > {
438444 fn visit_pat ( & mut self , p : & ' tcx Pat ) {
439445 if let PatKind :: Paren ( ..) | PatKind :: Rest = p. kind {
440446 // Doesn't generate a HIR node
@@ -537,7 +543,7 @@ impl<'a> LoweringContext<'a> {
537543 visit:: walk_crate ( & mut item:: ItemLowerer { lctx : & mut self } , c) ;
538544
539545 let module = self . lower_mod ( & c. module ) ;
540- let attrs = self . lower_attrs ( & c. attrs ) ;
546+ let attrs = self . arena . alloc_from_iter ( self . lower_attrs ( & c. attrs ) . into_iter ( ) ) ;
541547 let body_ids = body_ids ( & self . bodies ) ;
542548
543549 self . resolver
@@ -548,8 +554,8 @@ impl<'a> LoweringContext<'a> {
548554 module,
549555 attrs,
550556 span : c. span ,
551- exported_macros : hir :: HirVec :: from ( self . exported_macros ) ,
552- non_exported_macro_attrs : hir :: HirVec :: from ( self . non_exported_macro_attrs ) ,
557+ exported_macros : self . arena . alloc_from_iter ( self . exported_macros ) ,
558+ non_exported_macro_attrs : self . arena . alloc_from_iter ( self . non_exported_macro_attrs ) ,
553559 items : self . items ,
554560 trait_items : self . trait_items ,
555561 impl_items : self . impl_items ,
@@ -750,7 +756,7 @@ impl<'a> LoweringContext<'a> {
750756 f : F ,
751757 ) -> ( Vec < hir:: GenericParam > , T )
752758 where
753- F : FnOnce ( & mut LoweringContext < ' _ > ) -> ( Vec < hir:: GenericParam > , T ) ,
759+ F : FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> ( Vec < hir:: GenericParam > , T ) ,
754760 {
755761 assert ! ( !self . is_collecting_in_band_lifetimes) ;
756762 assert ! ( self . lifetimes_to_define. is_empty( ) ) ;
@@ -867,7 +873,7 @@ impl<'a> LoweringContext<'a> {
867873 // for them.
868874 fn with_in_scope_lifetime_defs < T , F > ( & mut self , params : & [ GenericParam ] , f : F ) -> T
869875 where
870- F : FnOnce ( & mut LoweringContext < ' _ > ) -> T ,
876+ F : FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
871877 {
872878 let old_len = self . in_scope_lifetimes . len ( ) ;
873879 let lt_def_names = params. iter ( ) . filter_map ( |param| match param. kind {
@@ -896,7 +902,7 @@ impl<'a> LoweringContext<'a> {
896902 f : F ,
897903 ) -> ( hir:: Generics , T )
898904 where
899- F : FnOnce ( & mut LoweringContext < ' _ > , & mut Vec < hir:: GenericParam > ) -> T ,
905+ F : FnOnce ( & mut LoweringContext < ' _ , ' _ > , & mut Vec < hir:: GenericParam > ) -> T ,
900906 {
901907 let ( in_band_defs, ( mut lowered_generics, res) ) = self . with_in_scope_lifetime_defs (
902908 & generics. params ,
@@ -945,7 +951,7 @@ impl<'a> LoweringContext<'a> {
945951
946952 fn with_dyn_type_scope < T , F > ( & mut self , in_scope : bool , f : F ) -> T
947953 where
948- F : FnOnce ( & mut LoweringContext < ' _ > ) -> T ,
954+ F : FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
949955 {
950956 let was_in_dyn_type = self . is_in_dyn_type ;
951957 self . is_in_dyn_type = in_scope;
@@ -959,7 +965,7 @@ impl<'a> LoweringContext<'a> {
959965
960966 fn with_new_scopes < T , F > ( & mut self , f : F ) -> T
961967 where
962- F : FnOnce ( & mut LoweringContext < ' _ > ) -> T ,
968+ F : FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
963969 {
964970 let was_in_loop_condition = self . is_in_loop_condition ;
965971 self . is_in_loop_condition = false ;
@@ -1446,7 +1452,7 @@ impl<'a> LoweringContext<'a> {
14461452 span : Span ,
14471453 fn_def_id : Option < DefId > ,
14481454 opaque_ty_node_id : NodeId ,
1449- lower_bounds : impl FnOnce ( & mut LoweringContext < ' _ > ) -> hir:: GenericBounds ,
1455+ lower_bounds : impl FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> hir:: GenericBounds ,
14501456 ) -> hir:: TyKind {
14511457 debug ! (
14521458 "lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})" ,
@@ -1563,8 +1569,8 @@ impl<'a> LoweringContext<'a> {
15631569 // This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
15641570 // appear in the bounds, excluding lifetimes that are created within the bounds.
15651571 // E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
1566- struct ImplTraitLifetimeCollector < ' r , ' a > {
1567- context : & ' r mut LoweringContext < ' a > ,
1572+ struct ImplTraitLifetimeCollector < ' r , ' a , ' hir > {
1573+ context : & ' r mut LoweringContext < ' a , ' hir > ,
15681574 parent : DefIndex ,
15691575 opaque_ty_id : NodeId ,
15701576 collect_elided_lifetimes : bool ,
@@ -1574,7 +1580,7 @@ impl<'a> LoweringContext<'a> {
15741580 output_lifetime_params : Vec < hir:: GenericParam > ,
15751581 }
15761582
1577- impl < ' r , ' a , ' v > hir:: intravisit:: Visitor < ' v > for ImplTraitLifetimeCollector < ' r , ' a > {
1583+ impl < ' r , ' a , ' v , ' hir > hir:: intravisit:: Visitor < ' v > for ImplTraitLifetimeCollector < ' r , ' a , ' hir > {
15781584 fn nested_visit_map < ' this > (
15791585 & ' this mut self ,
15801586 ) -> hir:: intravisit:: NestedVisitorMap < ' this , ' v > {
@@ -2757,8 +2763,9 @@ impl<'a> LoweringContext<'a> {
27572763 let node = match p. kind {
27582764 PatKind :: Wild => hir:: PatKind :: Wild ,
27592765 PatKind :: Ident ( ref binding_mode, ident, ref sub) => {
2760- let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |x| this. lower_pat ( x) ) ;
2761- self . lower_pat_ident ( p, binding_mode, ident, lower_sub)
2766+ let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |s| this. lower_pat ( & * s) ) ;
2767+ let node = self . lower_pat_ident ( p, binding_mode, ident, lower_sub) ;
2768+ node
27622769 }
27632770 PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( P ( self . lower_expr ( e) ) ) ,
27642771 PatKind :: TupleStruct ( ref path, ref pats) => {
0 commit comments