Rollup merge of #111211 - compiler-errors:negative-bounds-super, r=TaKO8Ki
Don't compute trait super bounds unless they're positive Fixes #111207 The comment is modified to explain the rationale for why we even have this recursive call to supertraits in the first place, which doesn't apply to negative bounds since they don't elaborate at all.
This commit is contained in:
commit
c145d93395
3 changed files with 25 additions and 5 deletions
|
@ -657,14 +657,15 @@ pub(super) fn implied_predicates_with_filter(
|
||||||
&*tcx.arena.alloc_from_iter(superbounds.predicates().chain(where_bounds_that_match));
|
&*tcx.arena.alloc_from_iter(superbounds.predicates().chain(where_bounds_that_match));
|
||||||
debug!(?implied_bounds);
|
debug!(?implied_bounds);
|
||||||
|
|
||||||
// Now require that immediate supertraits are converted,
|
// Now require that immediate supertraits are converted, which will, in
|
||||||
// which will, in turn, reach indirect supertraits.
|
// turn, reach indirect supertraits, so we detect cycles now instead of
|
||||||
|
// overflowing during elaboration.
|
||||||
if matches!(filter, PredicateFilter::SelfOnly) {
|
if matches!(filter, PredicateFilter::SelfOnly) {
|
||||||
// Now require that immediate supertraits are converted,
|
|
||||||
// which will, in turn, reach indirect supertraits.
|
|
||||||
for &(pred, span) in implied_bounds {
|
for &(pred, span) in implied_bounds {
|
||||||
debug!("superbound: {:?}", pred);
|
debug!("superbound: {:?}", pred);
|
||||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) = pred.kind().skip_binder() {
|
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) = pred.kind().skip_binder()
|
||||||
|
&& bound.polarity == ty::ImplPolarity::Positive
|
||||||
|
{
|
||||||
tcx.at(span).super_predicates_of(bound.def_id());
|
tcx.at(span).super_predicates_of(bound.def_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
tests/ui/traits/negative-bounds/supertrait.rs
Normal file
9
tests/ui/traits/negative-bounds/supertrait.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(negative_bounds)]
|
||||||
|
//~^ WARN the feature `negative_bounds` is incomplete
|
||||||
|
|
||||||
|
trait A: !B {}
|
||||||
|
trait B: !A {}
|
||||||
|
|
||||||
|
fn main() {}
|
10
tests/ui/traits/negative-bounds/supertrait.stderr
Normal file
10
tests/ui/traits/negative-bounds/supertrait.stderr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
|
--> $DIR/supertrait.rs:3:12
|
||||||
|
|
|
||||||
|
LL | #![feature(negative_bounds)]
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
Loading…
Add table
Reference in a new issue