Consider param-env candidates, too

This commit is contained in:
Michael Goulet 2023-09-21 18:02:22 +00:00
parent 184d5ef107
commit e425d85518
2 changed files with 41 additions and 1 deletions

View File

@ -3,6 +3,8 @@
use rustc_index::bit_set::{HybridBitSet, SparseBitMatrix}; use rustc_index::bit_set::{HybridBitSet, SparseBitMatrix};
use rustc_index::interval::IntervalSet; use rustc_index::interval::IntervalSet;
use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::test_type_match;
use rustc_infer::infer::region_constraints::VerifyIfEq;
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location}; use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
use rustc_middle::traits::query::DropckOutlivesResult; use rustc_middle::traits::query::DropckOutlivesResult;
use rustc_middle::ty::{ use rustc_middle::ty::{
@ -622,6 +624,7 @@ fn make_alias_live(&mut self, t: Ty<'tcx>) -> ControlFlow<!> {
bug!(); bug!();
}; };
let tcx = self.typeck.infcx.tcx; let tcx = self.typeck.infcx.tcx;
let param_env = self.typeck.param_env;
let mut outlives_bounds = tcx let mut outlives_bounds = tcx
.item_bounds(alias_ty.def_id) .item_bounds(alias_ty.def_id)
.iter_instantiated(tcx, alias_ty.args) .iter_instantiated(tcx, alias_ty.args)
@ -633,7 +636,24 @@ fn make_alias_live(&mut self, t: Ty<'tcx>) -> ControlFlow<!> {
} else { } else {
None None
} }
}); })
.chain(param_env.caller_bounds().iter().filter_map(|clause| {
let outlives = clause.as_type_outlives_clause()?;
if let Some(outlives) = outlives.no_bound_vars()
&& outlives.0 == t
{
Some(outlives.1)
} else {
test_type_match::extract_verify_if_eq(
tcx,
param_env,
&outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| {
VerifyIfEq { ty, bound }
}),
t,
)
}
}));
if let Some(r) = outlives_bounds.next() if let Some(r) = outlives_bounds.next()
&& !r.is_late_bound() && !r.is_late_bound()
&& outlives_bounds.all(|other_r| { && outlives_bounds.all(|other_r| {

View File

@ -0,0 +1,20 @@
// check-pass
trait Foo {
type Assoc<'a>
where
Self: 'a;
fn assoc(&mut self) -> Self::Assoc<'_>;
}
fn test<T>(mut t: T)
where
T: Foo,
for<'a> T::Assoc<'a>: 'static,
{
let a = t.assoc();
let b = t.assoc();
}
fn main() {}