Skip to content

Commit dc21fcb

Browse files
committed
Remove another use of clone_code
1 parent 063795c commit dc21fcb

File tree

2 files changed

+11
-13
lines changed
  • compiler
    • rustc_middle/src/traits
    • rustc_trait_selection/src/traits/select

2 files changed

+11
-13
lines changed

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> ObligationCause<'tcx> {
183183
pub fn derived_cause(
184184
mut self,
185185
parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
186-
variant: fn(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
186+
variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
187187
) -> ObligationCause<'tcx> {
188188
/*!
189189
* Creates a cause for obligations that are derived from

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use super::util;
1414
use super::util::{closure_trait_ref_and_return_type, predicate_for_trait_def};
1515
use super::wf;
1616
use super::{
17-
DerivedObligationCause, ErrorReporting, ImplDerivedObligation, ImplDerivedObligationCause,
18-
Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow, PredicateObligation,
19-
Selection, SelectionError, SelectionResult, TraitObligation, TraitQueryMode,
17+
ErrorReporting, ImplDerivedObligation, ImplDerivedObligationCause, Normalized, Obligation,
18+
ObligationCause, ObligationCauseCode, Overflow, PredicateObligation, Selection, SelectionError,
19+
SelectionResult, TraitObligation, TraitQueryMode,
2020
};
2121

2222
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
@@ -2316,17 +2316,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23162316
debug!(?predicates);
23172317
assert_eq!(predicates.parent, None);
23182318
let mut obligations = Vec::with_capacity(predicates.predicates.len());
2319-
let parent_code = cause.clone_code();
23202319
for (predicate, span) in predicates.predicates {
23212320
let span = *span;
2322-
let derived =
2323-
DerivedObligationCause { parent_trait_pred, parent_code: parent_code.clone() };
2324-
let code = ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
2325-
derived,
2326-
impl_def_id: def_id,
2327-
span,
2328-
}));
2329-
let cause = ObligationCause::new(cause.span, cause.body_id, code);
2321+
let cause = cause.clone().derived_cause(parent_trait_pred, |derived| {
2322+
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
2323+
derived,
2324+
impl_def_id: def_id,
2325+
span,
2326+
}))
2327+
});
23302328
let predicate = normalize_with_depth_to(
23312329
self,
23322330
param_env,

0 commit comments

Comments
 (0)