Skip to content

Commit e425d85

Browse files
Consider param-env candidates, too
1 parent 184d5ef commit e425d85

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use rustc_data_structures::graph::WithSuccessors;
33
use rustc_index::bit_set::{HybridBitSet, SparseBitMatrix};
44
use rustc_index::interval::IntervalSet;
55
use rustc_infer::infer::canonical::QueryRegionConstraints;
6+
use rustc_infer::infer::outlives::test_type_match;
7+
use rustc_infer::infer::region_constraints::VerifyIfEq;
68
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
79
use rustc_middle::traits::query::DropckOutlivesResult;
810
use rustc_middle::ty::{
@@ -622,6 +624,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
622624
bug!();
623625
};
624626
let tcx = self.typeck.infcx.tcx;
627+
let param_env = self.typeck.param_env;
625628
let mut outlives_bounds = tcx
626629
.item_bounds(alias_ty.def_id)
627630
.iter_instantiated(tcx, alias_ty.args)
@@ -633,7 +636,24 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
633636
} else {
634637
None
635638
}
636-
});
639+
})
640+
.chain(param_env.caller_bounds().iter().filter_map(|clause| {
641+
let outlives = clause.as_type_outlives_clause()?;
642+
if let Some(outlives) = outlives.no_bound_vars()
643+
&& outlives.0 == t
644+
{
645+
Some(outlives.1)
646+
} else {
647+
test_type_match::extract_verify_if_eq(
648+
tcx,
649+
param_env,
650+
&outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| {
651+
VerifyIfEq { ty, bound }
652+
}),
653+
t,
654+
)
655+
}
656+
}));
637657
if let Some(r) = outlives_bounds.next()
638658
&& !r.is_late_bound()
639659
&& outlives_bounds.all(|other_r| {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
trait Foo {
4+
type Assoc<'a>
5+
where
6+
Self: 'a;
7+
8+
fn assoc(&mut self) -> Self::Assoc<'_>;
9+
}
10+
11+
fn test<T>(mut t: T)
12+
where
13+
T: Foo,
14+
for<'a> T::Assoc<'a>: 'static,
15+
{
16+
let a = t.assoc();
17+
let b = t.assoc();
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)