我正在尝试修复 Rustboot,以便它可以使用 i686-unknown-linux-gnu 在 Rust 1.8.0 中每晚构建和运行。我有两个似乎无法修复的主要错误,就是这些错误:
main.rs:50:5: 54:6 error: the trait `core::iter::Iterator` is not implemented for the type `IntRange` [E0277]
main.rs:50 for i in range(0, 80 * 25) {
main.rs:51 unsafe {
main.rs:52 *((0xb8000 + i * 2) as *mut u16) = (background as u16) << 12;
和
main.rs:52:15: 52:44 error: the type of this value must be known in this context
main.rs:52 *((0xb8000 + i * 2) as *mut u16) = (background as u16) << 12;
关于为什么会发生这种情况以及我该如何解决的任何想法?
Rustboot main.rs 文件的链接:http://pastebin.com/wyDywYN8
最佳答案
IntRange
没有实现core::iter::Iterator
,自然不能用在for
循环中。 i
类型的错误是相关的 - 因为 IntRange
没有实现 Iterator
,所以当它作为一个使用时,它的类型项目未知。
您应该实现 Iterator
而不是提供 next()
作为固有方法:
use core::iter::Iterator;
impl Iterator for IntRange {
type Item = i32;
fn next(&mut self) -> Option<i32> {
// your implementation
}
}
然而,这可能还不够,因为 for
循环也依赖于 Option
,但我现在不记得它是 lang 项还是通过完整路径查找。
关于Rust 1.8.0 每晚编译器的 Rustboot 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35394358/