37
37
#![ recursion_limit = "256" ]
38
38
#![ allow( rustc:: potential_query_instability) ]
39
39
40
+ #[ macro_use]
41
+ extern crate tracing;
42
+
40
43
use rustc_ast:: visit;
41
44
use rustc_ast:: { self as ast, * } ;
42
45
use rustc_ast_pretty:: pprust;
@@ -63,7 +66,6 @@ use rustc_span::{Span, DUMMY_SP};
63
66
64
67
use smallvec:: SmallVec ;
65
68
use std:: collections:: hash_map:: Entry ;
66
- use tracing:: { debug, trace} ;
67
69
68
70
macro_rules! arena_vec {
69
71
( $this: expr; $( $x: expr) ,* ) => (
@@ -439,7 +441,7 @@ pub fn lower_crate<'a, 'hir>(
439
441
arena. alloc ( krate)
440
442
}
441
443
442
- #[ derive( Copy , Clone , PartialEq ) ]
444
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
443
445
enum ParamMode {
444
446
/// Any path in a type context.
445
447
Explicit ,
@@ -455,6 +457,7 @@ enum ParenthesizedGenericArgs {
455
457
}
456
458
457
459
impl < ' a , ' hir > LoweringContext < ' a , ' hir > {
460
+ #[ instrument( level = "debug" , skip( self , f) ) ]
458
461
fn with_hir_id_owner (
459
462
& mut self ,
460
463
owner : NodeId ,
@@ -599,12 +602,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
599
602
self . lower_node_id ( node_id)
600
603
}
601
604
605
+ #[ instrument( level = "trace" , skip( self ) ) ]
602
606
fn lower_res ( & mut self , res : Res < NodeId > ) -> Res {
603
607
let res: Result < Res , ( ) > = res. apply_id ( |id| {
604
608
let owner = self . current_hir_id_owner ;
605
609
let local_id = self . node_id_to_local_id . get ( & id) . copied ( ) . ok_or ( ( ) ) ?;
606
610
Ok ( hir:: HirId { owner, local_id } )
607
611
} ) ;
612
+ trace ! ( ?res) ;
613
+
608
614
// We may fail to find a HirId when the Res points to a Local from an enclosing HIR owner.
609
615
// This can happen when trying to lower the return type `x` in erroneous code like
610
616
// async fn foo(x: u8) -> x {}
@@ -851,6 +857,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
851
857
/// ```
852
858
///
853
859
/// returns a `hir::TypeBinding` representing `Item`.
860
+ #[ instrument( level = "debug" , skip( self ) ) ]
854
861
fn lower_assoc_ty_constraint (
855
862
& mut self ,
856
863
constraint : & AssocConstraint ,
@@ -1011,6 +1018,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1011
1018
err. emit ( ) ;
1012
1019
}
1013
1020
1021
+ #[ instrument( level = "debug" , skip( self ) ) ]
1014
1022
fn lower_generic_arg (
1015
1023
& mut self ,
1016
1024
arg : & ast:: GenericArg ,
@@ -1081,6 +1089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1081
1089
}
1082
1090
}
1083
1091
1092
+ #[ instrument( level = "debug" , skip( self ) ) ]
1084
1093
fn lower_ty ( & mut self , t : & Ty , itctx : ImplTraitContext ) -> & ' hir hir:: Ty < ' hir > {
1085
1094
self . arena . alloc ( self . lower_ty_direct ( t, itctx) )
1086
1095
}
@@ -1212,41 +1221,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1212
1221
)
1213
1222
}
1214
1223
ImplTraitContext :: Universal => {
1215
- // Add a definition for the in-band `Param`.
1216
- let def_id = self . resolver . local_def_id ( def_node_id) ;
1217
-
1218
- let hir_bounds =
1219
- self . lower_param_bounds ( bounds, ImplTraitContext :: Universal ) ;
1220
- // Set the name to `impl Bound1 + Bound2`.
1224
+ let span = t. span ;
1221
1225
let ident = Ident :: from_str_and_span ( & pprust:: ty_to_string ( t) , span) ;
1222
- let param = hir:: GenericParam {
1223
- hir_id : self . lower_node_id ( def_node_id) ,
1224
- name : ParamName :: Plain ( self . lower_ident ( ident) ) ,
1225
- pure_wrt_drop : false ,
1226
- span : self . lower_span ( span) ,
1227
- kind : hir:: GenericParamKind :: Type { default : None , synthetic : true } ,
1228
- colon_span : None ,
1229
- } ;
1226
+ let ( param, bounds, path) =
1227
+ self . lower_generic_and_bounds ( def_node_id, span, ident, bounds) ;
1230
1228
self . impl_trait_defs . push ( param) ;
1231
-
1232
- if let Some ( preds) = self . lower_generic_bound_predicate (
1233
- ident,
1234
- def_node_id,
1235
- & GenericParamKind :: Type { default : None } ,
1236
- hir_bounds,
1237
- hir:: PredicateOrigin :: ImplTrait ,
1238
- ) {
1239
- self . impl_trait_bounds . push ( preds)
1229
+ if let Some ( bounds) = bounds {
1230
+ self . impl_trait_bounds . push ( bounds) ;
1240
1231
}
1241
-
1242
- hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1243
- None ,
1244
- self . arena . alloc ( hir:: Path {
1245
- span : self . lower_span ( span) ,
1246
- res : Res :: Def ( DefKind :: TyParam , def_id. to_def_id ( ) ) ,
1247
- segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident( self . lower_ident( ident) ) ] ,
1248
- } ) ,
1249
- ) )
1232
+ path
1250
1233
}
1251
1234
ImplTraitContext :: Disallowed ( position) => {
1252
1235
let mut err = struct_span_err ! (
@@ -1737,6 +1720,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1737
1720
)
1738
1721
}
1739
1722
1723
+ #[ instrument( level = "trace" , skip( self ) ) ]
1740
1724
fn lower_param_bound (
1741
1725
& mut self ,
1742
1726
tpb : & GenericBound ,
@@ -1862,8 +1846,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1862
1846
self . arena . alloc_from_iter ( self . lower_generic_params_mut ( params) )
1863
1847
}
1864
1848
1849
+ #[ instrument( level = "trace" , skip( self ) ) ]
1865
1850
fn lower_generic_param ( & mut self , param : & GenericParam ) -> hir:: GenericParam < ' hir > {
1866
- let ( name, kind) = match param. kind {
1851
+ let ( name, kind) = self . lower_generic_param_kind ( param) ;
1852
+
1853
+ let hir_id = self . lower_node_id ( param. id ) ;
1854
+ self . lower_attrs ( hir_id, & param. attrs ) ;
1855
+ hir:: GenericParam {
1856
+ hir_id,
1857
+ name,
1858
+ span : self . lower_span ( param. span ( ) ) ,
1859
+ pure_wrt_drop : self . sess . contains_name ( & param. attrs , sym:: may_dangle) ,
1860
+ kind,
1861
+ colon_span : param. colon_span . map ( |s| self . lower_span ( s) ) ,
1862
+ }
1863
+ }
1864
+
1865
+ fn lower_generic_param_kind (
1866
+ & mut self ,
1867
+ param : & GenericParam ,
1868
+ ) -> ( hir:: ParamName , hir:: GenericParamKind < ' hir > ) {
1869
+ match param. kind {
1867
1870
GenericParamKind :: Lifetime => {
1868
1871
// AST resolution emitted an error on those parameters, so we lower them using
1869
1872
// `ParamName::Error`.
@@ -1897,17 +1900,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1897
1900
hir:: GenericParamKind :: Const { ty, default } ,
1898
1901
)
1899
1902
}
1900
- } ;
1901
-
1902
- let hir_id = self . lower_node_id ( param. id ) ;
1903
- self . lower_attrs ( hir_id, & param. attrs ) ;
1904
- hir:: GenericParam {
1905
- hir_id,
1906
- name,
1907
- span : self . lower_span ( param. span ( ) ) ,
1908
- pure_wrt_drop : self . sess . contains_name ( & param. attrs , sym:: may_dangle) ,
1909
- kind,
1910
- colon_span : param. colon_span . map ( |s| self . lower_span ( s) ) ,
1911
1903
}
1912
1904
}
1913
1905
@@ -1954,6 +1946,47 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1954
1946
bounds. iter ( ) . map ( move |bound| self . lower_param_bound ( bound, itctx) )
1955
1947
}
1956
1948
1949
+ fn lower_generic_and_bounds (
1950
+ & mut self ,
1951
+ node_id : NodeId ,
1952
+ span : Span ,
1953
+ ident : Ident ,
1954
+ bounds : & [ GenericBound ] ,
1955
+ ) -> ( hir:: GenericParam < ' hir > , Option < hir:: WherePredicate < ' hir > > , hir:: TyKind < ' hir > ) {
1956
+ // Add a definition for the in-band `Param`.
1957
+ let def_id = self . resolver . local_def_id ( node_id) ;
1958
+
1959
+ let hir_bounds = self . lower_param_bounds ( bounds, ImplTraitContext :: Universal ) ;
1960
+ // Set the name to `impl Bound1 + Bound2`.
1961
+ let param = hir:: GenericParam {
1962
+ hir_id : self . lower_node_id ( node_id) ,
1963
+ name : ParamName :: Plain ( self . lower_ident ( ident) ) ,
1964
+ pure_wrt_drop : false ,
1965
+ span : self . lower_span ( span) ,
1966
+ kind : hir:: GenericParamKind :: Type { default : None , synthetic : true } ,
1967
+ colon_span : None ,
1968
+ } ;
1969
+
1970
+ let preds = self . lower_generic_bound_predicate (
1971
+ ident,
1972
+ node_id,
1973
+ & GenericParamKind :: Type { default : None } ,
1974
+ hir_bounds,
1975
+ hir:: PredicateOrigin :: ImplTrait ,
1976
+ ) ;
1977
+
1978
+ let ty = hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1979
+ None ,
1980
+ self . arena . alloc ( hir:: Path {
1981
+ span : self . lower_span ( span) ,
1982
+ res : Res :: Def ( DefKind :: TyParam , def_id. to_def_id ( ) ) ,
1983
+ segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident( self . lower_ident( ident) ) ] ,
1984
+ } ) ,
1985
+ ) ) ;
1986
+
1987
+ ( param, preds, ty)
1988
+ }
1989
+
1957
1990
/// Lowers a block directly to an expression, presuming that it
1958
1991
/// has no attributes and is not targeted by a `break`.
1959
1992
fn lower_block_expr ( & mut self , b : & Block ) -> hir:: Expr < ' hir > {
0 commit comments