diff options
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/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 5fc0128d8c6..2e5400c42d0 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 @@ where 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<Item = PredicateObligation<'tcx>>, @@ -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 b296dadec9d..50e9b95a445 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }; 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { 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( |
