diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-24 15:35:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-24 15:35:13 +0100 |
| commit | 3b827731d04e7d325ef31e16ed64bc88af72196b (patch) | |
| tree | 5ae7149d5073ef51aad92875a6b41c5136c93b99 | |
| parent | dbe33982ccc9e0cbc0dc29cfa7f74ddfe838645a (diff) | |
| parent | 62cb9d1a978a760dad4f56951922b8b533c98d08 (diff) | |
| download | rust-3b827731d04e7d325ef31e16ed64bc88af72196b.tar.gz rust-3b827731d04e7d325ef31e16ed64bc88af72196b.zip | |
Rollup merge of #121520 - matthiaskrgr:cloned, r=jackh726
delay cloning of iterator items
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/coherence.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 3619d02438d..ac0685994ea 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -320,22 +320,25 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>( let mut errors = fulfill_cx.select_where_possible(infcx); errors.pop().map(|err| err.obligation) } else { - obligations.iter().cloned().find(|obligation| { - // We use `evaluate_root_obligation` to correctly track intercrate - // ambiguity clauses. We cannot use this in the new solver. - let evaluation_result = selcx.evaluate_root_obligation(obligation); - - match evaluation_result { - Ok(result) => !result.may_apply(), - // If overflow occurs, we need to conservatively treat the goal as possibly holding, - // since there can be instantiations of this goal that don't overflow and result in - // success. This isn't much of a problem in the old solver, since we treat overflow - // fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>), - // but in the new solver, this is very important for correctness, since overflow - // *must* be treated as ambiguity for completeness. - Err(_overflow) => false, - } - }) + obligations + .iter() + .find(|obligation| { + // We use `evaluate_root_obligation` to correctly track intercrate + // ambiguity clauses. We cannot use this in the new solver. + let evaluation_result = selcx.evaluate_root_obligation(obligation); + + match evaluation_result { + Ok(result) => !result.may_apply(), + // If overflow occurs, we need to conservatively treat the goal as possibly holding, + // since there can be instantiations of this goal that don't overflow and result in + // success. This isn't much of a problem in the old solver, since we treat overflow + // fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>), + // but in the new solver, this is very important for correctness, since overflow + // *must* be treated as ambiguity for completeness. + Err(_overflow) => false, + } + }) + .cloned() } } |
