Skip to content

Commit 930eece

Browse files
Don't compute trait super bounds unless they're positive
1 parent eac3558 commit 930eece

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,15 @@ pub(super) fn implied_predicates_with_filter(
657657
&*tcx.arena.alloc_from_iter(superbounds.predicates().chain(where_bounds_that_match));
658658
debug!(?implied_bounds);
659659

660-
// Now require that immediate supertraits are converted,
661-
// which will, in turn, reach indirect supertraits.
660+
// Now require that immediate supertraits are converted, which will, in
661+
// turn, reach indirect supertraits, so we detect cycles now instead of
662+
// overflowing during elaboration.
662663
if matches!(filter, PredicateFilter::SelfOnly) {
663-
// Now require that immediate supertraits are converted,
664-
// which will, in turn, reach indirect supertraits.
665664
for &(pred, span) in implied_bounds {
666665
debug!("superbound: {:?}", pred);
667-
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) = pred.kind().skip_binder() {
666+
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) = pred.kind().skip_binder()
667+
&& bound.polarity == ty::ImplPolarity::Positive
668+
{
668669
tcx.at(span).super_predicates_of(bound.def_id());
669670
}
670671
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
3+
#![feature(negative_bounds)]
4+
//~^ WARN the feature `negative_bounds` is incomplete
5+
6+
trait A: !B {}
7+
trait B: !A {}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/supertrait.rs:3:12
3+
|
4+
LL | #![feature(negative_bounds)]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)