Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
) -> Option<ty::Mutability> {
let tcx = self.infcx.tcx;
let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_binder();
let clauses = tcx.predicates_of(callee_did);
let clauses = tcx.clauses_of(callee_did);

let generic_args = match call_expr.kind {
// For method calls, generic arguments are attached to the call node.
Expand All @@ -688,7 +688,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {

// First, is there at least one method on one of `param`'s trait bounds?
// This keeps us from suggesting borrowing the argument to `mem::drop`, e.g.
if !clauses.instantiate_identity(tcx).predicates.iter().any(|clause| {
if !clauses.instantiate_identity(tcx).clauses.iter().any(|clause| {
clause.as_trait_clause().is_some_and(|tc| {
tc.self_ty().skip_binder().is_param(param.index)
&& tc.polarity() == ty::PredicatePolarity::Positive
Expand Down Expand Up @@ -738,8 +738,8 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
return false;
}

// Test the callee's predicates, substituting in `ref_ty` for the moved argument type.
clauses.instantiate(tcx, new_args).predicates.iter().all(|clause| {
// Test the callee's clauses, substituting in `ref_ty` for the moved argument type.
clauses.instantiate(tcx, new_args).clauses.iter().all(|clause| {
// Normalize before testing to see through type aliases and projections.
let normalized = tcx
.try_normalize_erasing_regions(
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,26 +643,26 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
let closure_hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local());
let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_hir_id) else { return None };

let predicates = match parent.kind {
let gen_clauses = match parent.kind {
hir::ExprKind::Call(callee, _) => {
let ty = typeck_result.node_type_opt(callee.hir_id)?;
let ty::FnDef(fn_def_id, args) = *ty.kind() else { return None };
tcx.predicates_of(fn_def_id).instantiate(tcx, args.no_bound_vars().unwrap())
tcx.clauses_of(fn_def_id).instantiate(tcx, args.no_bound_vars().unwrap())
}
hir::ExprKind::MethodCall(..) => {
let (_, method) = typeck_result.type_dependent_def(parent.hir_id)?;
let args = typeck_result.node_args(parent.hir_id);
tcx.predicates_of(method).instantiate(tcx, args)
tcx.clauses_of(method).instantiate(tcx, args)
}
_ => return None,
};

// Check whether one of the where-bounds requires the closure to impl `Fn[Mut]`
// or `AsyncFn[Mut]`.
for (pred, span) in predicates.predicates.iter().zip(predicates.spans.iter()) {
let pred = pred.skip_norm_wip();
for (clause, span) in gen_clauses.clauses.iter().zip(gen_clauses.spans.iter()) {
let clause = clause.skip_norm_wip();
let dominated_by_fn_trait = self
.closure_clause_kind(pred, def_id, asyncness)
.closure_clause_kind(clause, def_id, asyncness)
.is_some_and(|kind| matches!(kind, ty::ClosureKind::Fn | ty::ClosureKind::FnMut));
if dominated_by_fn_trait {
// Found `<TyOfCapturingClosure as FnMut>` or
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,19 +1210,17 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
return false;
};

tcx.predicates_of(callee_def_id)
.instantiate(tcx, generic_args)
.predicates
.iter()
.any(|predicate| {
predicate.as_trait_clause().is_some_and(|trait_pred| {
tcx.clauses_of(callee_def_id).instantiate(tcx, generic_args).clauses.iter().any(
|clause| {
clause.as_trait_clause().is_some_and(|trait_pred| {
trait_pred.polarity() == ty::PredicatePolarity::Positive
&& tcx.fn_trait_kind_from_def_id(trait_pred.def_id())
== Some(ty::ClosureKind::Fn)
&& trait_pred.self_ty().skip_binder().peel_refs()
== input_ty.peel_refs()
})
})
},
)
};

// If the HIR node is a function or method call, get the DefId
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,17 +1167,17 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
}
});

let preds = tcx.predicates_of(method_def_id).instantiate(tcx, args);
let clauses = tcx.clauses_of(method_def_id).instantiate(tcx, args);

let ocx = ObligationCtxt::new(&self.infcx);
ocx.register_obligations(preds.iter().map(|(pred, span)| {
trace!(?pred);
ocx.register_obligations(clauses.iter().map(|(clause, span)| {
trace!(?clause);
Obligation::misc(
tcx,
span,
self.mir_def_id(),
self.infcx.param_env,
pred.skip_norm_wip(),
clause.skip_norm_wip(),
)
}));

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,12 +1065,12 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
return None;
};

let predicates: Vec<_> = self
let clauses: Vec<_> = self
.infcx
.tcx
.predicates_of(self.body.source.def_id())
.clauses_of(self.body.source.def_id())
.instantiate_identity(self.infcx.tcx)
.predicates
.clauses
.into_iter()
.map(Unnormalized::skip_norm_wip)
.collect();
Expand All @@ -1081,7 +1081,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
.defining_ty
.upvar_tys()
.iter()
.position(|ty| self.any_param_predicate_mentions(&predicates, ty, region))
.position(|ty| self.any_param_clause_mentions(&clauses, ty, region))
{
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
self.infcx.tcx,
Expand All @@ -1099,7 +1099,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
.universal_regions()
.unnormalized_input_tys
.iter()
.position(|ty| self.any_param_predicate_mentions(&predicates, *ty, region))
.position(|ty| self.any_param_clause_mentions(&clauses, *ty, region))
{
let (arg_name, arg_span) = self.regioncx.get_argument_name_and_span_for_region(
self.body,
Expand All @@ -1119,7 +1119,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
}
}

fn any_param_predicate_mentions(
fn any_param_clause_mentions(
&self,
clauses: &[ty::Clause<'tcx>],
ty: Ty<'tcx>,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

#[instrument(level = "debug", skip(self))]
pub(super) fn normalize_and_prove_instantiated_predicates(
pub(super) fn normalize_and_prove_instantiated_clauses(
&mut self,
// Keep this parameter for now, in case we start using
// it in `ConstraintCategory` at some point.
_def_id: DefId,
instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
instantiated_clauses: ty::InstantiatedClauses<'tcx>,
locations: Locations,
) {
for (predicate, span) in instantiated_predicates {
debug!(?span, ?predicate);
for (clause, span) in instantiated_clauses {
debug!(?span, ?clause);
let category = ConstraintCategory::Predicate(span);
let clause = self.normalize_with_category(predicate, locations, category);
let clause = self.normalize_with_category(clause, locations, category);
self.prove_clause(clause, locations, category);
}
}
Expand Down
28 changes: 14 additions & 14 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {

if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env, dst.ty) {
// Wide to thin ptr cast. This may even occur in an env with
// impossible predicates, such as `where dyn Trait: Sized`.
// impossible clauses, such as `where dyn Trait: Sized`.
// In this case, we don't want to fall into the case below,
// since the types may not actually be equatable, but it's
// fine to perform this operation in an impossible env.
Expand Down Expand Up @@ -1722,10 +1722,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
&& tcx.anon_const_kind(def_id) == ty::AnonConstKind::NonTypeSystemInline
{
let def_id = def_id.expect_local();
let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location);
self.normalize_and_prove_instantiated_predicates(
let clauses = self.prove_closure_bounds(tcx, def_id, uv.args, location);
self.normalize_and_prove_instantiated_clauses(
def_id.to_def_id(),
predicates,
clauses,
location.to_locations(),
);
}
Expand Down Expand Up @@ -1840,10 +1840,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {

if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
let args = args.no_bound_vars().unwrap();
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
self.normalize_and_prove_instantiated_predicates(
let instantiated_clauses = tcx.clauses_of(def_id).instantiate(tcx, args);
self.normalize_and_prove_instantiated_clauses(
def_id,
instantiated_predicates,
instantiated_clauses,
locations,
);

Expand Down Expand Up @@ -2603,9 +2603,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
aggregate_kind, location
);

let (def_id, instantiated_predicates) = match *aggregate_kind {
let (def_id, instantiated_clauses) = match *aggregate_kind {
AggregateKind::Adt(adt_did, _, args, _, _) => {
(adt_did, tcx.predicates_of(adt_did).instantiate(tcx, args))
(adt_did, tcx.clauses_of(adt_did).instantiate(tcx, args))
}

// For closures, we have some **extra requirements** we
Expand Down Expand Up @@ -2634,13 +2634,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

AggregateKind::Array(_) | AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
(CRATE_DEF_ID.to_def_id(), ty::InstantiatedPredicates::empty())
(CRATE_DEF_ID.to_def_id(), ty::InstantiatedClauses::empty())
}
};

self.normalize_and_prove_instantiated_predicates(
self.normalize_and_prove_instantiated_clauses(
def_id,
instantiated_predicates,
instantiated_clauses,
location.to_locations(),
);
}
Expand All @@ -2651,7 +2651,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
def_id: LocalDefId,
args: GenericArgsRef<'tcx>,
location: Location,
) -> ty::InstantiatedPredicates<'tcx> {
) -> ty::InstantiatedClauses<'tcx> {
let root_def_id = self.root_cx.root_def_id();
// We will have to handle propagated closure requirements for this closure,
// but need to defer this until the nested body has been fully borrow checked.
Expand Down Expand Up @@ -2695,7 +2695,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
}

tcx.predicates_of(def_id).instantiate(tcx, args)
tcx.clauses_of(def_id).instantiate(tcx, args)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn intern_as_new_static<'tcx>(
feed.eval_static_initializer(Ok(alloc));
feed.generics_of(tcx.generics_of(static_id).clone());
feed.def_ident_span(tcx.def_ident_span(static_id));
feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id));
feed.explicit_clauses_of(tcx.explicit_clauses_of(static_id));
feed.feed_hir();
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/always_applicable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>(
ocx.eq(&ObligationCause::dummy_with_span(impl_span), adt_env, fresh_adt_ty, impl_adt_ty)
.expect("equating fully generic trait ref should never fail");

for (clause, span) in tcx.predicates_of(impl_def_id).instantiate(tcx, fresh_impl_args) {
for (clause, span) in tcx.clauses_of(impl_def_id).instantiate(tcx, fresh_impl_args) {
let normalize_cause = traits::ObligationCause::misc(span, impl_def_id);
let pred = ocx.normalize(&normalize_cause, adt_env, clause);
let cause = traits::ObligationCause::new(
Expand Down
Loading
Loading