Skip to content

Commit 748c548

Browse files
committed
Auto merge of #129546 - compiler-errors:no-pred-on, r=fee1-dead
Get rid of `predicates_defined_on` This is the uncontroversial part of #129532. This simply inlines the `predicates_defined_on` into into `predicates_of`. Nothing should change here logically.
2 parents d9a2cc4 + dbf06d2 commit 748c548

File tree

5 files changed

+22
-63
lines changed

5 files changed

+22
-63
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+1-30
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_infer::traits::ObligationCause;
3434
use rustc_middle::hir::nested_filter;
3535
use rustc_middle::query::Providers;
3636
use rustc_middle::ty::util::{Discr, IntTypeExt};
37-
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast};
37+
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt};
3838
use rustc_middle::{bug, span_bug};
3939
use rustc_span::symbol::{kw, sym, Ident, Symbol};
4040
use rustc_span::{Span, DUMMY_SP};
@@ -70,7 +70,6 @@ pub fn provide(providers: &mut Providers) {
7070
impl_super_outlives: item_bounds::impl_super_outlives,
7171
generics_of: generics_of::generics_of,
7272
predicates_of: predicates_of::predicates_of,
73-
predicates_defined_on,
7473
explicit_predicates_of: predicates_of::explicit_predicates_of,
7574
explicit_super_predicates_of: predicates_of::explicit_super_predicates_of,
7675
explicit_implied_predicates_of: predicates_of::explicit_implied_predicates_of,
@@ -1775,34 +1774,6 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
17751774
})
17761775
}
17771776

1778-
/// Returns a list of type predicates for the definition with ID `def_id`, including inferred
1779-
/// lifetime constraints. This includes all predicates returned by `explicit_predicates_of`, plus
1780-
/// inferred constraints concerning which regions outlive other regions.
1781-
#[instrument(level = "debug", skip(tcx))]
1782-
fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
1783-
let mut result = tcx.explicit_predicates_of(def_id);
1784-
debug!("predicates_defined_on: explicit_predicates_of({:?}) = {:?}", def_id, result);
1785-
let inferred_outlives = tcx.inferred_outlives_of(def_id);
1786-
if !inferred_outlives.is_empty() {
1787-
debug!(
1788-
"predicates_defined_on: inferred_outlives_of({:?}) = {:?}",
1789-
def_id, inferred_outlives,
1790-
);
1791-
let inferred_outlives_iter =
1792-
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
1793-
if result.predicates.is_empty() {
1794-
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
1795-
} else {
1796-
result.predicates = tcx.arena.alloc_from_iter(
1797-
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
1798-
);
1799-
}
1800-
}
1801-
1802-
debug!("predicates_defined_on({:?}) = {:?}", def_id, result);
1803-
result
1804-
}
1805-
18061777
fn compute_sig_of_foreign_fn_decl<'tcx>(
18071778
tcx: TyCtxt<'tcx>,
18081779
def_id: LocalDefId,

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,26 @@ use crate::delegation::inherit_predicates_for_delegation_item;
1818
use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter, RegionInferReason};
1919

2020
/// Returns a list of all type predicates (explicit and implicit) for the definition with
21-
/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
22-
/// `Self: Trait` predicates for traits.
21+
/// ID `def_id`. This includes all predicates returned by `explicit_predicates_of`, plus
22+
/// inferred constraints concerning which regions outlive other regions.
23+
#[instrument(level = "debug", skip(tcx))]
2324
pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
24-
let mut result = tcx.predicates_defined_on(def_id);
25+
let mut result = tcx.explicit_predicates_of(def_id);
26+
debug!("predicates_of: explicit_predicates_of({:?}) = {:?}", def_id, result);
27+
28+
let inferred_outlives = tcx.inferred_outlives_of(def_id);
29+
if !inferred_outlives.is_empty() {
30+
debug!("predicates_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,);
31+
let inferred_outlives_iter =
32+
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
33+
if result.predicates.is_empty() {
34+
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
35+
} else {
36+
result.predicates = tcx.arena.alloc_from_iter(
37+
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
38+
);
39+
}
40+
}
2541

2642
if tcx.is_trait(def_id) {
2743
// For traits, add `Self: Trait` predicate. This is
@@ -51,7 +67,8 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
5167
.chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
5268
);
5369
}
54-
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
70+
71+
debug!("predicates_of({:?}) = {:?}", def_id, result);
5572
result
5673
}
5774

compiler/rustc_middle/src/query/mod.rs

-19
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,6 @@ rustc_queries! {
312312
/// predicates (where-clauses) that must be proven true in order
313313
/// to reference it. This is almost always the "predicates query"
314314
/// that you want.
315-
///
316-
/// `predicates_of` builds on `predicates_defined_on` -- in fact,
317-
/// it is almost always the same as that query, except for the
318-
/// case of traits. For traits, `predicates_of` contains
319-
/// an additional `Self: Trait<...>` predicate that users don't
320-
/// actually write. This reflects the fact that to invoke the
321-
/// trait (e.g., via `Default::default`) you must supply types
322-
/// that actually implement the trait. (However, this extra
323-
/// predicate gets in the way of some checks, which are intended
324-
/// to operate over only the actual where-clauses written by the
325-
/// user.)
326315
query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
327316
desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
328317
cache_on_disk_if { key.is_local() }
@@ -619,14 +608,6 @@ rustc_queries! {
619608
desc { "getting wasm import module map" }
620609
}
621610

622-
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
623-
/// predicates (where-clauses) directly defined on it. This is
624-
/// equal to the `explicit_predicates_of` predicates plus the
625-
/// `inferred_outlives_of` predicates.
626-
query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
627-
desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
628-
}
629-
630611
/// Returns everything that looks like a predicate written explicitly
631612
/// by the user on a trait item.
632613
///

tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0391]: cycle detected when computing predicates of `Foo`
44
LL | struct Foo {
55
| ^^^^^^^^^^
66
|
7-
note: ...which requires computing predicates of `Foo`...
8-
--> $DIR/cycle-iat-inside-of-adt.rs:7:1
9-
|
10-
LL | struct Foo {
11-
| ^^^^^^^^^^
127
note: ...which requires computing inferred outlives predicates of `Foo`...
138
--> $DIR/cycle-iat-inside-of-adt.rs:7:1
149
|

tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0391]: cycle detected when computing predicates of `user`
44
LL | fn user<T>() where S<T>::P: std::fmt::Debug {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires computing predicates of `user`...
8-
--> $DIR/cycle-iat-inside-of-where-predicate.rs:8:1
9-
|
10-
LL | fn user<T>() where S<T>::P: std::fmt::Debug {}
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127
note: ...which requires computing explicit predicates of `user`...
138
--> $DIR/cycle-iat-inside-of-where-predicate.rs:8:1
149
|

0 commit comments

Comments
 (0)