Enforce supertrait outlives obligations hold when confirming impl
This commit is contained in:
parent
9179d9b334
commit
6a891ec4fe
10 changed files with 120 additions and 12 deletions
|
@ -7,6 +7,7 @@ use std::fmt::{self, Display};
|
|||
use std::ops::ControlFlow;
|
||||
use std::{cmp, iter};
|
||||
|
||||
use hir::def::DefKind;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::{Diag, EmissionGuarantee};
|
||||
|
@ -14,8 +15,9 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_infer::infer::relate::TypeRelation;
|
||||
use rustc_infer::infer::BoundRegionConversionTime::HigherRankedType;
|
||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
||||
use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType};
|
||||
use rustc_infer::infer::DefineOpaqueTypes;
|
||||
use rustc_infer::traits::util::elaborate;
|
||||
use rustc_infer::traits::TraitObligation;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::dep_graph::{dep_kinds, DepNodeIndex};
|
||||
|
@ -2798,6 +2800,34 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
if matches!(self.tcx().def_kind(def_id), DefKind::Impl { of_trait: true })
|
||||
&& let Some(header) = self.tcx().impl_trait_header(def_id)
|
||||
{
|
||||
let trait_clause: ty::Clause<'tcx> =
|
||||
header.trait_ref.instantiate(self.tcx(), args).upcast(self.tcx());
|
||||
for clause in elaborate(self.tcx(), [trait_clause]) {
|
||||
if matches!(
|
||||
clause.kind().skip_binder(),
|
||||
ty::ClauseKind::TypeOutlives(..) | ty::ClauseKind::RegionOutlives(..)
|
||||
) {
|
||||
let clause = normalize_with_depth_to(
|
||||
self,
|
||||
param_env,
|
||||
cause.clone(),
|
||||
recursion_depth,
|
||||
clause,
|
||||
&mut obligations,
|
||||
);
|
||||
obligations.push(Obligation {
|
||||
cause: cause.clone(),
|
||||
recursion_depth,
|
||||
param_env,
|
||||
predicate: clause.as_predicate(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obligations
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue