From 2025e44ef894f51a557522fc3057af7dce47a3ce Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 15 May 2024 12:58:41 -0400 Subject: [PATCH] to_opt_poly_X_pred -> as_X_clause --- .../src/check/compare_impl_item.rs | 2 +- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 4 ++-- compiler/rustc_hir_typeck/src/op.rs | 8 ++++---- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_middle/src/ty/predicate.rs | 4 ++-- .../src/traits/error_reporting/suggestions.rs | 8 ++++---- .../traits/error_reporting/type_err_ctxt_ext.rs | 14 +++++++------- .../src/traits/object_safety.rs | 2 +- compiler/rustc_trait_selection/src/traits/wf.rs | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 19645049d0c..44bf8fd2d93 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -2250,7 +2250,7 @@ fn try_report_async_mismatch<'tcx>( for error in errors { if let ObligationCauseCode::WhereClause(def_id, _) = *error.root_obligation.cause.code() && def_id == async_future_def_id - && let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred() + && let Some(proj) = error.root_obligation.predicate.as_projection_clause() && let Some(proj) = proj.no_bound_vars() && infcx.can_eq( error.root_obligation.param_env, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 059e4141e15..e137aab2109 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1350,12 +1350,12 @@ fn check_impl<'tcx>( // We already have a better span. continue; } - if let Some(pred) = obligation.predicate.to_opt_poly_trait_pred() + if let Some(pred) = obligation.predicate.as_trait_clause() && pred.skip_binder().self_ty() == trait_ref.self_ty() { obligation.cause.span = hir_self_ty.span; } - if let Some(pred) = obligation.predicate.to_opt_poly_projection_pred() + if let Some(pred) = obligation.predicate.as_projection_clause() && pred.skip_binder().self_ty() == trait_ref.self_ty() { obligation.cause.span = hir_self_ty.span; diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index e371775be0a..87b76b978b9 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -583,7 +583,7 @@ fn check_overloaded_binop( if !errors.is_empty() { for error in errors { if let Some(trait_pred) = - error.obligation.predicate.to_opt_poly_trait_pred() + error.obligation.predicate.as_trait_clause() { let output_associated_item = match error.obligation.cause.code() { @@ -797,9 +797,9 @@ pub fn check_user_unop( ); if operand_ty.has_non_region_param() { - let predicates = errors.iter().filter_map(|error| { - error.obligation.predicate.to_opt_poly_trait_pred() - }); + let predicates = errors + .iter() + .filter_map(|error| error.obligation.predicate.as_trait_clause()); for pred in predicates { self.err_ctxt().suggest_restricting_param_bound( &mut err, diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 57b85a24a74..cc12a4bf091 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -455,7 +455,7 @@ impl<'tcx, I: Iterator>> Iterator for FilterToTraits< fn next(&mut self) -> Option> { while let Some(pred) = self.base_iterator.next() { - if let Some(data) = pred.to_opt_poly_trait_pred() { + if let Some(data) = pred.as_trait_clause() { return Some(data.map_bound(|t| t.trait_ref)); } } diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index 329ac0b1d72..e490e060345 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -702,7 +702,7 @@ fn upcast_from(from: NormalizesTo<'tcx>, tcx: TyCtxt<'tcx>) -> Self { } impl<'tcx> Predicate<'tcx> { - pub fn to_opt_poly_trait_pred(self) -> Option> { + pub fn as_trait_clause(self) -> Option> { let predicate = self.kind(); match predicate.skip_binder() { PredicateKind::Clause(ClauseKind::Trait(t)) => Some(predicate.rebind(t)), @@ -722,7 +722,7 @@ pub fn to_opt_poly_trait_pred(self) -> Option> { } } - pub fn to_opt_poly_projection_pred(self) -> Option> { + pub fn as_projection_clause(self) -> Option> { let predicate = self.kind(); match predicate.skip_binder() { PredicateKind::Clause(ClauseKind::Projection(t)) => Some(predicate.rebind(t)), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 01804a448df..c1654f60f1c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2739,7 +2739,7 @@ fn note_obligation_cause_code( | ObligationCauseCode::ReferenceOutlivesReferent(..) | ObligationCauseCode::ObjectTypeBound(..) => {} ObligationCauseCode::RustCall => { - if let Some(pred) = predicate.to_opt_poly_trait_pred() + if let Some(pred) = predicate.as_trait_clause() && Some(pred.def_id()) == tcx.lang_items().sized_trait() { err.note("argument required to be sized due to `extern \"rust-call\"` ABI"); @@ -3725,7 +3725,7 @@ fn note_function_argument_obligation( { if let hir::Expr { kind: hir::ExprKind::MethodCall(_, rcvr, _, _), .. } = expr && let Some(ty) = typeck_results.node_type_opt(rcvr.hir_id) - && let Some(failed_pred) = failed_pred.to_opt_poly_trait_pred() + && let Some(failed_pred) = failed_pred.as_trait_clause() && let pred = failed_pred.map_bound(|pred| pred.with_self_ty(tcx, ty)) && self.predicate_must_hold_modulo_regions(&Obligation::misc( tcx, expr.span, body_id, param_env, pred, @@ -3816,7 +3816,7 @@ fn note_function_argument_obligation( && let Some(where_pred) = where_clauses.predicates.get(*idx) { if let Some(where_pred) = where_pred.as_trait_clause() - && let Some(failed_pred) = failed_pred.to_opt_poly_trait_pred() + && let Some(failed_pred) = failed_pred.as_trait_clause() { self.enter_forall(where_pred, |where_pred| { let failed_pred = self.instantiate_binder_with_fresh_vars( @@ -3842,7 +3842,7 @@ fn note_function_argument_obligation( } }) } else if let Some(where_pred) = where_pred.as_projection_clause() - && let Some(failed_pred) = failed_pred.to_opt_poly_projection_pred() + && let Some(failed_pred) = failed_pred.as_projection_clause() && let Some(found) = failed_pred.skip_binder().term.ty() { type_diffs = vec![Sorts(ty::error::ExpectedFound { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index c090cd70888..d693bac90dc 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1417,7 +1417,7 @@ fn report_const_param_not_wf( }; let mut code = obligation.cause.code(); - let mut pred = obligation.predicate.to_opt_poly_trait_pred(); + let mut pred = obligation.predicate.as_trait_clause(); while let Some((next_code, next_pred)) = code.parent() { if let Some(pred) = pred { self.enter_forall(pred, |pred| { @@ -1481,16 +1481,16 @@ fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) - return true; } - if let Some(error) = error.to_opt_poly_trait_pred() { + if let Some(error) = error.as_trait_clause() { self.enter_forall(error, |error| { elaborate(self.tcx, std::iter::once(cond)) - .filter_map(|implied| implied.to_opt_poly_trait_pred()) + .filter_map(|implied| implied.as_trait_clause()) .any(|implied| self.can_match_trait(error, implied)) }) - } else if let Some(error) = error.to_opt_poly_projection_pred() { + } else if let Some(error) = error.as_projection_clause() { self.enter_forall(error, |error| { elaborate(self.tcx, std::iter::once(cond)) - .filter_map(|implied| implied.to_opt_poly_projection_pred()) + .filter_map(|implied| implied.as_projection_clause()) .any(|implied| self.can_match_projection(error, implied)) }) } else { @@ -2415,8 +2415,8 @@ fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) -> Erro return e; } err.note(format!("cannot satisfy `{predicate}`")); - let impl_candidates = self - .find_similar_impl_candidates(predicate.to_opt_poly_trait_pred().unwrap()); + let impl_candidates = + self.find_similar_impl_candidates(predicate.as_trait_clause().unwrap()); if impl_candidates.len() < 40 { self.report_similar_impl_candidates( impl_candidates.as_slice(), diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index b30f26f92f6..abb19c7efd8 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -653,7 +653,7 @@ fn object_ty_for_trait<'tcx>( let mut elaborated_predicates: Vec<_> = elaborate(tcx, [pred]) .filter_map(|pred| { debug!(?pred); - let pred = pred.to_opt_poly_projection_pred()?; + let pred = pred.as_projection_clause()?; Some(pred.map_bound(|p| { ty::ExistentialPredicate::Projection(ty::ExistentialProjection::erase_self_ty( tcx, p, diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 6d84523da8a..f4189ff0902 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -377,7 +377,7 @@ fn compute_trait_pred(&mut self, trait_pred: ty::TraitPredicate<'tcx>, elaborate let item = self.item; let extend = |traits::PredicateObligation { predicate, mut cause, .. }| { - if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() { + if let Some(parent_trait_pred) = predicate.as_trait_clause() { cause = cause.derived_cause( parent_trait_pred, traits::ObligationCauseCode::WellFormedDerived,