@@ -2344,38 +2344,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2344
2344
}
2345
2345
}
2346
2346
2347
- /// See `ParameterEnvironment` struct def'n for details.
2348
- pub fn parameter_environment ( self , def_id : DefId ) -> ParameterEnvironment < ' gcx > {
2349
- //
2350
- // Compute the bounds on Self and the type parameters.
2351
- //
2352
-
2353
- let tcx = self . global_tcx ( ) ;
2354
- let bounds = tcx. predicates_of ( def_id) . instantiate_identity ( tcx) ;
2355
- let predicates = bounds. predicates ;
2356
-
2357
- // Finally, we have to normalize the bounds in the environment, in
2358
- // case they contain any associated type projections. This process
2359
- // can yield errors if the put in illegal associated types, like
2360
- // `<i32 as Foo>::Bar` where `i32` does not implement `Foo`. We
2361
- // report these errors right here; this doesn't actually feel
2362
- // right to me, because constructing the environment feels like a
2363
- // kind of a "idempotent" action, but I'm not sure where would be
2364
- // a better place. In practice, we construct environments for
2365
- // every fn once during type checking, and we'll abort if there
2366
- // are any errors at that point, so after type checking you can be
2367
- // sure that this will succeed without errors anyway.
2368
- //
2369
-
2370
- let unnormalized_env = ty:: ParameterEnvironment :: new ( tcx. intern_predicates ( & predicates) ) ;
2371
-
2372
- let body_id = self . hir . as_local_node_id ( def_id) . map_or ( DUMMY_NODE_ID , |id| {
2373
- self . hir . maybe_body_owned_by ( id) . map_or ( id, |body| body. node_id )
2374
- } ) ;
2375
- let cause = traits:: ObligationCause :: misc ( tcx. def_span ( def_id) , body_id) ;
2376
- traits:: normalize_param_env_or_error ( tcx, def_id, unnormalized_env, cause)
2377
- }
2378
-
2379
2347
pub fn node_scope_region ( self , id : NodeId ) -> Region < ' tcx > {
2380
2348
self . mk_region ( ty:: ReScope ( CodeExtent :: Misc ( id) ) )
2381
2349
}
@@ -2535,6 +2503,35 @@ fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option
2535
2503
} )
2536
2504
}
2537
2505
2506
+ /// See `ParameterEnvironment` struct def'n for details.
2507
+ fn parameter_environment < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
2508
+ def_id : DefId )
2509
+ -> ParameterEnvironment < ' tcx > {
2510
+ // Compute the bounds on Self and the type parameters.
2511
+
2512
+ let bounds = tcx. predicates_of ( def_id) . instantiate_identity ( tcx) ;
2513
+ let predicates = bounds. predicates ;
2514
+
2515
+ // Finally, we have to normalize the bounds in the environment, in
2516
+ // case they contain any associated type projections. This process
2517
+ // can yield errors if the put in illegal associated types, like
2518
+ // `<i32 as Foo>::Bar` where `i32` does not implement `Foo`. We
2519
+ // report these errors right here; this doesn't actually feel
2520
+ // right to me, because constructing the environment feels like a
2521
+ // kind of a "idempotent" action, but I'm not sure where would be
2522
+ // a better place. In practice, we construct environments for
2523
+ // every fn once during type checking, and we'll abort if there
2524
+ // are any errors at that point, so after type checking you can be
2525
+ // sure that this will succeed without errors anyway.
2526
+
2527
+ let unnormalized_env = ty:: ParameterEnvironment :: new ( tcx. intern_predicates ( & predicates) ) ;
2528
+
2529
+ let body_id = tcx. hir . as_local_node_id ( def_id) . map_or ( DUMMY_NODE_ID , |id| {
2530
+ tcx. hir . maybe_body_owned_by ( id) . map_or ( id, |body| body. node_id )
2531
+ } ) ;
2532
+ let cause = traits:: ObligationCause :: misc ( tcx. def_span ( def_id) , body_id) ;
2533
+ traits:: normalize_param_env_or_error ( tcx, def_id, unnormalized_env, cause)
2534
+ }
2538
2535
2539
2536
pub fn provide ( providers : & mut ty:: maps:: Providers ) {
2540
2537
util:: provide ( providers) ;
@@ -2544,6 +2541,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
2544
2541
adt_sized_constraint,
2545
2542
adt_dtorck_constraint,
2546
2543
def_span,
2544
+ parameter_environment,
2547
2545
trait_of_item,
2548
2546
trait_impls_of : trait_def:: trait_impls_of_provider,
2549
2547
relevant_trait_impls_for : trait_def:: relevant_trait_impls_provider,
@@ -2557,6 +2555,7 @@ pub fn provide_extern(providers: &mut ty::maps::Providers) {
2557
2555
adt_dtorck_constraint,
2558
2556
trait_impls_of : trait_def:: trait_impls_of_provider,
2559
2557
relevant_trait_impls_for : trait_def:: relevant_trait_impls_provider,
2558
+ parameter_environment,
2560
2559
..* providers
2561
2560
} ;
2562
2561
}
0 commit comments