Skip to content

Commit 8c8365a

Browse files
Consider param-env candidates, too
1 parent 81d47f3 commit 8c8365a

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

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
22
use rustc_index::bit_set::HybridBitSet;
33
use rustc_index::interval::IntervalSet;
44
use rustc_infer::infer::canonical::QueryRegionConstraints;
5+
use rustc_infer::infer::outlives::test_type_match;
6+
use rustc_infer::infer::region_constraints::VerifyIfEq;
57
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
68
use rustc_middle::traits::query::DropckOutlivesResult;
79
use rustc_middle::ty::{
@@ -568,6 +570,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
568570
bug!();
569571
};
570572
let tcx = self.typeck.infcx.tcx;
573+
let param_env = self.typeck.param_env;
571574
let mut outlives_bounds = tcx
572575
.item_bounds(alias_ty.def_id)
573576
.iter_instantiated(tcx, alias_ty.args)
@@ -579,7 +582,24 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
579582
} else {
580583
None
581584
}
582-
});
585+
})
586+
.chain(param_env.caller_bounds().iter().filter_map(|clause| {
587+
let outlives = clause.as_type_outlives_clause()?;
588+
if let Some(outlives) = outlives.no_bound_vars()
589+
&& outlives.0 == t
590+
{
591+
Some(outlives.1)
592+
} else {
593+
test_type_match::extract_verify_if_eq(
594+
tcx,
595+
param_env,
596+
&outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| {
597+
VerifyIfEq { ty, bound }
598+
}),
599+
t,
600+
)
601+
}
602+
}));
583603
if let Some(r) = outlives_bounds.next()
584604
&& !r.is_late_bound()
585605
&& outlives_bounds.all(|other_r| {
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)