Skip to content

Commit fdad385

Browse files
committed
Discard region-related bounds from ParamEnv when predicate is global
This allows us to use global caches in more places, since we can drop predicates containing inference variables.
1 parent 84f962a commit fdad385

File tree

1 file changed

+21
-0
lines changed
  • compiler/rustc_trait_selection/src/traits/select

1 file changed

+21
-0
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
723723
// out the param env and get better caching.
724724
debug!("in global");
725725
obligation.param_env = obligation.param_env.without_caller_bounds();
726+
} else if !self.intercrate
727+
&& obligation.predicate.is_global(self.tcx())
728+
&& obligation.param_env.has_free_regions(self.tcx())
729+
{
730+
// Strip out bounds that only reference regions
731+
let new_bounds: Vec<_> = obligation
732+
.param_env
733+
.caller_bounds()
734+
.iter()
735+
.filter(|bound| match bound.kind().skip_binder() {
736+
ty::PredicateKind::RegionOutlives(_) | ty::PredicateKind::TypeOutlives(_) => {
737+
false
738+
}
739+
_ => true,
740+
})
741+
.collect();
742+
obligation.param_env = ty::ParamEnv::new(
743+
self.tcx().intern_predicates(&new_bounds),
744+
obligation.param_env.reveal(),
745+
obligation.param_env.constness(),
746+
);
726747
}
727748

728749
let stack = self.push_stack(previous_stack, &obligation);

0 commit comments

Comments
 (0)