From f5af266b6d707da0f6a6cf388a93e14e38a8a1ef Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 4 Aug 2022 13:59:25 +0000 Subject: [PATCH] Address nits --- compiler/rustc_trait_selection/src/traits/mod.rs | 8 ++++++++ .../src/traits/select/candidate_assembly.rs | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 5fc0128d8c6b..2e5400c42d0f 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -378,6 +378,7 @@ pub fn normalize_param_env_or_error<'tcx>( ) } +/// Normalize a type and process all resulting obligations, returning any errors pub fn fully_normalize<'a, 'tcx, T>( infcx: &InferCtxt<'a, 'tcx>, cause: ObligationCause<'tcx>, @@ -412,6 +413,8 @@ pub fn fully_normalize<'a, 'tcx, T>( Ok(resolved_value) } +/// Process an obligation (and any nested obligations that come from it) to +/// completion, returning any errors pub fn fully_solve_obligation<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, obligation: PredicateObligation<'tcx>, @@ -421,6 +424,8 @@ pub fn fully_solve_obligation<'a, 'tcx>( engine.select_all_or_error(infcx) } +/// Process a set of obligations (and any nested obligations that come from them) +/// to completion pub fn fully_solve_obligations<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, obligations: impl IntoIterator>, @@ -430,6 +435,9 @@ pub fn fully_solve_obligations<'a, 'tcx>( engine.select_all_or_error(infcx) } +/// Process a bound (and any nested obligations that come from it) to completion. +/// This is a convenience function for traits that have no generic arguments, such +/// as auto traits, and builtin traits like Copy or Sized. pub fn fully_solve_bound<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, cause: ObligationCause<'tcx>, diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index b296dadec9d9..50e9b95a445f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -707,6 +707,7 @@ fn need_migrate_deref_output_trait_object( &mut self, ty: Ty<'tcx>, param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Option<(Ty<'tcx>, DefId)> { let tcx = self.tcx(); if tcx.features().trait_upcasting { @@ -720,7 +721,7 @@ fn need_migrate_deref_output_trait_object( }; let obligation = traits::Obligation::new( - ObligationCause::dummy(), + cause.clone(), param_env, ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), ); @@ -735,7 +736,7 @@ fn need_migrate_deref_output_trait_object( item_def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs, }, - ObligationCause::dummy(), + cause.clone(), 0, // We're *intentionally* throwing these away, // since we don't actually use them. @@ -809,7 +810,11 @@ fn assemble_candidates_for_unsizing( let target_trait_did = principal_def_id_b.unwrap(); let source_trait_ref = principal_a.with_self_ty(self.tcx(), source); if let Some((deref_output_ty, deref_output_trait_did)) = self - .need_migrate_deref_output_trait_object(source, obligation.param_env) + .need_migrate_deref_output_trait_object( + source, + obligation.param_env, + &obligation.cause, + ) { if deref_output_trait_did == target_trait_did { self.tcx().struct_span_lint_hir(