Don't elaborate non-obligations into obligations
This commit is contained in:
parent
96bd50dd47
commit
1ce4b37900
20 changed files with 112 additions and 131 deletions
|
@ -318,16 +318,8 @@ fn check_predicates<'tcx>(
|
|||
span: Span,
|
||||
) {
|
||||
let instantiated = tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs);
|
||||
let impl1_predicates: Vec<_> = traits::elaborate_predicates_with_span(
|
||||
tcx,
|
||||
std::iter::zip(
|
||||
instantiated.predicates,
|
||||
// Don't drop predicates (unsound!) because `spans` is too short
|
||||
instantiated.spans.into_iter().chain(std::iter::repeat(span)),
|
||||
),
|
||||
)
|
||||
.map(|obligation| (obligation.predicate, obligation.cause.span))
|
||||
.collect();
|
||||
let impl1_predicates: Vec<_> =
|
||||
traits::elaborate_predicates_with_span(tcx, instantiated.into_iter()).collect();
|
||||
|
||||
let mut impl2_predicates = if impl2_node.is_from_trait() {
|
||||
// Always applicable traits have to be always applicable without any
|
||||
|
@ -341,7 +333,6 @@ fn check_predicates<'tcx>(
|
|||
.predicates
|
||||
.into_iter(),
|
||||
)
|
||||
.map(|obligation| obligation.predicate)
|
||||
.collect()
|
||||
};
|
||||
debug!(?impl1_predicates, ?impl2_predicates);
|
||||
|
@ -361,12 +352,16 @@ fn check_predicates<'tcx>(
|
|||
// which is sound because we forbid impls like the following
|
||||
//
|
||||
// impl<D: Debug> AlwaysApplicable for D { }
|
||||
let always_applicable_traits = impl1_predicates.iter().copied().filter(|&(predicate, _)| {
|
||||
matches!(
|
||||
trait_predicate_kind(tcx, predicate),
|
||||
Some(TraitSpecializationKind::AlwaysApplicable)
|
||||
)
|
||||
});
|
||||
let always_applicable_traits = impl1_predicates
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|&(predicate, _)| {
|
||||
matches!(
|
||||
trait_predicate_kind(tcx, predicate),
|
||||
Some(TraitSpecializationKind::AlwaysApplicable)
|
||||
)
|
||||
})
|
||||
.map(|(pred, _span)| pred);
|
||||
|
||||
// Include the well-formed predicates of the type parameters of the impl.
|
||||
for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity().substs {
|
||||
|
@ -380,10 +375,7 @@ fn check_predicates<'tcx>(
|
|||
traits::elaborate_obligations(tcx, obligations).map(|obligation| obligation.predicate),
|
||||
)
|
||||
}
|
||||
impl2_predicates.extend(
|
||||
traits::elaborate_predicates_with_span(tcx, always_applicable_traits)
|
||||
.map(|obligation| obligation.predicate),
|
||||
);
|
||||
impl2_predicates.extend(traits::elaborate_predicates(tcx, always_applicable_traits));
|
||||
|
||||
for (predicate, span) in impl1_predicates {
|
||||
if !impl2_predicates.iter().any(|pred2| trait_predicates_eq(tcx, predicate, *pred2, span)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue