1 Star 0 Fork 67

programmer12/rust

forked from src-openEuler/rust 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rustc-1.51.0-backport-pr81741.patch 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
wang_yue111 提交于 2021-05-07 16:50 . Update to 1.51.0
From 40d3f2d7ef5835317fe9df9ecc01f4c363def4fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
Date: Thu, 4 Feb 2021 10:23:01 +0200
Subject: [PATCH] Increment `self.index` before calling
`Iterator::self.a.__iterator_get_unchecked` in `Zip` `TrustedRandomAccess`
specialization
Otherwise if `Iterator::self.a.__iterator_get_unchecked` panics the
index would not have been incremented yet and another call to
`Iterator::next` would read from the same index again, which is not
allowed according to the API contract of `TrustedRandomAccess` for
`!Clone`.
Fixes https://github.com/rust-lang/rust/issues/81740
(cherry picked from commit 86a4b27475aab52b998c15f5758540697cc9cff0)
---
library/core/src/iter/adapters/zip.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/library/core/src/iter/adapters/zip.rs b/library/core/src/iter/adapters/zip.rs
index 98b8dca96140..9f9835345200 100644
--- a/library/core/src/iter/adapters/zip.rs
+++ b/library/core/src/iter/adapters/zip.rs
@@ -198,12 +198,13 @@ fn next(&mut self) -> Option<(A::Item, B::Item)> {
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
}
} else if A::may_have_side_effect() && self.index < self.a.size() {
+ let i = self.index;
+ self.index += 1;
// match the base implementation's potential side effects
- // SAFETY: we just checked that `self.index` < `self.a.len()`
+ // SAFETY: we just checked that `i` < `self.a.len()`
unsafe {
- self.a.__iterator_get_unchecked(self.index);
+ self.a.__iterator_get_unchecked(i);
}
- self.index += 1;
None
} else {
None
--
2.31.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/programmer12/rust.git
git@gitee.com:programmer12/rust.git
programmer12
rust
rust
master

搜索帮助