Skip to content

Commit 1a73979

Browse files
committed
Auto merge of #125153 - compiler-errors:opt-poly, r=lcnr
`to_opt_poly_X_pred` -> `as_X_clause` r? lcnr
2 parents c7716d5 + 2025e44 commit 1a73979

File tree

9 files changed

+23
-23
lines changed

9 files changed

+23
-23
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ fn try_report_async_mismatch<'tcx>(
22502250
for error in errors {
22512251
if let ObligationCauseCode::WhereClause(def_id, _) = *error.root_obligation.cause.code()
22522252
&& def_id == async_future_def_id
2253-
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
2253+
&& let Some(proj) = error.root_obligation.predicate.as_projection_clause()
22542254
&& let Some(proj) = proj.no_bound_vars()
22552255
&& infcx.can_eq(
22562256
error.root_obligation.param_env,

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,12 @@ fn check_impl<'tcx>(
13501350
// We already have a better span.
13511351
continue;
13521352
}
1353-
if let Some(pred) = obligation.predicate.to_opt_poly_trait_pred()
1353+
if let Some(pred) = obligation.predicate.as_trait_clause()
13541354
&& pred.skip_binder().self_ty() == trait_ref.self_ty()
13551355
{
13561356
obligation.cause.span = hir_self_ty.span;
13571357
}
1358-
if let Some(pred) = obligation.predicate.to_opt_poly_projection_pred()
1358+
if let Some(pred) = obligation.predicate.as_projection_clause()
13591359
&& pred.skip_binder().self_ty() == trait_ref.self_ty()
13601360
{
13611361
obligation.cause.span = hir_self_ty.span;

Diff for: compiler/rustc_hir_typeck/src/op.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
583583
if !errors.is_empty() {
584584
for error in errors {
585585
if let Some(trait_pred) =
586-
error.obligation.predicate.to_opt_poly_trait_pred()
586+
error.obligation.predicate.as_trait_clause()
587587
{
588588
let output_associated_item = match error.obligation.cause.code()
589589
{
@@ -797,9 +797,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
797797
);
798798

799799
if operand_ty.has_non_region_param() {
800-
let predicates = errors.iter().filter_map(|error| {
801-
error.obligation.predicate.to_opt_poly_trait_pred()
802-
});
800+
let predicates = errors
801+
.iter()
802+
.filter_map(|error| error.obligation.predicate.as_trait_clause());
803803
for pred in predicates {
804804
self.err_ctxt().suggest_restricting_param_bound(
805805
&mut err,

Diff for: compiler/rustc_infer/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'tcx, I: Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<
455455

456456
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
457457
while let Some(pred) = self.base_iterator.next() {
458-
if let Some(data) = pred.to_opt_poly_trait_pred() {
458+
if let Some(data) = pred.as_trait_clause() {
459459
return Some(data.map_bound(|t| t.trait_ref));
460460
}
461461
}

Diff for: compiler/rustc_middle/src/ty/predicate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'tcx> UpcastFrom<TyCtxt<'tcx>, NormalizesTo<'tcx>> for Predicate<'tcx> {
702702
}
703703

704704
impl<'tcx> Predicate<'tcx> {
705-
pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
705+
pub fn as_trait_clause(self) -> Option<PolyTraitPredicate<'tcx>> {
706706
let predicate = self.kind();
707707
match predicate.skip_binder() {
708708
PredicateKind::Clause(ClauseKind::Trait(t)) => Some(predicate.rebind(t)),
@@ -722,7 +722,7 @@ impl<'tcx> Predicate<'tcx> {
722722
}
723723
}
724724

725-
pub fn to_opt_poly_projection_pred(self) -> Option<PolyProjectionPredicate<'tcx>> {
725+
pub fn as_projection_clause(self) -> Option<PolyProjectionPredicate<'tcx>> {
726726
let predicate = self.kind();
727727
match predicate.skip_binder() {
728728
PredicateKind::Clause(ClauseKind::Projection(t)) => Some(predicate.rebind(t)),

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
27392739
| ObligationCauseCode::ReferenceOutlivesReferent(..)
27402740
| ObligationCauseCode::ObjectTypeBound(..) => {}
27412741
ObligationCauseCode::RustCall => {
2742-
if let Some(pred) = predicate.to_opt_poly_trait_pred()
2742+
if let Some(pred) = predicate.as_trait_clause()
27432743
&& Some(pred.def_id()) == tcx.lang_items().sized_trait()
27442744
{
27452745
err.note("argument required to be sized due to `extern \"rust-call\"` ABI");
@@ -3725,7 +3725,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
37253725
{
37263726
if let hir::Expr { kind: hir::ExprKind::MethodCall(_, rcvr, _, _), .. } = expr
37273727
&& let Some(ty) = typeck_results.node_type_opt(rcvr.hir_id)
3728-
&& let Some(failed_pred) = failed_pred.to_opt_poly_trait_pred()
3728+
&& let Some(failed_pred) = failed_pred.as_trait_clause()
37293729
&& let pred = failed_pred.map_bound(|pred| pred.with_self_ty(tcx, ty))
37303730
&& self.predicate_must_hold_modulo_regions(&Obligation::misc(
37313731
tcx, expr.span, body_id, param_env, pred,
@@ -3816,7 +3816,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
38163816
&& let Some(where_pred) = where_clauses.predicates.get(*idx)
38173817
{
38183818
if let Some(where_pred) = where_pred.as_trait_clause()
3819-
&& let Some(failed_pred) = failed_pred.to_opt_poly_trait_pred()
3819+
&& let Some(failed_pred) = failed_pred.as_trait_clause()
38203820
{
38213821
self.enter_forall(where_pred, |where_pred| {
38223822
let failed_pred = self.instantiate_binder_with_fresh_vars(
@@ -3842,7 +3842,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
38423842
}
38433843
})
38443844
} else if let Some(where_pred) = where_pred.as_projection_clause()
3845-
&& let Some(failed_pred) = failed_pred.to_opt_poly_projection_pred()
3845+
&& let Some(failed_pred) = failed_pred.as_projection_clause()
38463846
&& let Some(found) = failed_pred.skip_binder().term.ty()
38473847
{
38483848
type_diffs = vec![Sorts(ty::error::ExpectedFound {

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14171417
};
14181418

14191419
let mut code = obligation.cause.code();
1420-
let mut pred = obligation.predicate.to_opt_poly_trait_pred();
1420+
let mut pred = obligation.predicate.as_trait_clause();
14211421
while let Some((next_code, next_pred)) = code.parent() {
14221422
if let Some(pred) = pred {
14231423
self.enter_forall(pred, |pred| {
@@ -1481,16 +1481,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14811481
return true;
14821482
}
14831483

1484-
if let Some(error) = error.to_opt_poly_trait_pred() {
1484+
if let Some(error) = error.as_trait_clause() {
14851485
self.enter_forall(error, |error| {
14861486
elaborate(self.tcx, std::iter::once(cond))
1487-
.filter_map(|implied| implied.to_opt_poly_trait_pred())
1487+
.filter_map(|implied| implied.as_trait_clause())
14881488
.any(|implied| self.can_match_trait(error, implied))
14891489
})
1490-
} else if let Some(error) = error.to_opt_poly_projection_pred() {
1490+
} else if let Some(error) = error.as_projection_clause() {
14911491
self.enter_forall(error, |error| {
14921492
elaborate(self.tcx, std::iter::once(cond))
1493-
.filter_map(|implied| implied.to_opt_poly_projection_pred())
1493+
.filter_map(|implied| implied.as_projection_clause())
14941494
.any(|implied| self.can_match_projection(error, implied))
14951495
})
14961496
} else {
@@ -2415,8 +2415,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
24152415
return e;
24162416
}
24172417
err.note(format!("cannot satisfy `{predicate}`"));
2418-
let impl_candidates = self
2419-
.find_similar_impl_candidates(predicate.to_opt_poly_trait_pred().unwrap());
2418+
let impl_candidates =
2419+
self.find_similar_impl_candidates(predicate.as_trait_clause().unwrap());
24202420
if impl_candidates.len() < 40 {
24212421
self.report_similar_impl_candidates(
24222422
impl_candidates.as_slice(),

Diff for: compiler/rustc_trait_selection/src/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ fn object_ty_for_trait<'tcx>(
653653
let mut elaborated_predicates: Vec<_> = elaborate(tcx, [pred])
654654
.filter_map(|pred| {
655655
debug!(?pred);
656-
let pred = pred.to_opt_poly_projection_pred()?;
656+
let pred = pred.as_projection_clause()?;
657657
Some(pred.map_bound(|p| {
658658
ty::ExistentialPredicate::Projection(ty::ExistentialProjection::erase_self_ty(
659659
tcx, p,

Diff for: compiler/rustc_trait_selection/src/traits/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
377377
let item = self.item;
378378

379379
let extend = |traits::PredicateObligation { predicate, mut cause, .. }| {
380-
if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() {
380+
if let Some(parent_trait_pred) = predicate.as_trait_clause() {
381381
cause = cause.derived_cause(
382382
parent_trait_pred,
383383
traits::ObligationCauseCode::WellFormedDerived,

0 commit comments

Comments
 (0)