【问题标题】:Rustboot errors with Rust 1.8.0 nightly compilerRust 1.8.0 夜间编译器的 Rustboot 错误
【发布时间】:2016-02-15 18:48:47
【问题描述】:

我正在尝试修复 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

【问题讨论】:

    标签: rust


    【解决方案1】:

    IntRange 没有实现core::iter::Iterator,所以自然不能在for 循环中使用。 i的类型的错误是相关的——因为IntRange没有实现Iterator,所以当它作为一个使用时,它的item的类型是未知的。

    您应该实现Iterator,而不是提供next() 作为固有方法:

    use core::iter::Iterator;
    
    impl Iterator for IntRange {
        type Item = i32;
    
        fn next(&mut self) -> Option<i32> {
            // your implementation
        }
    }
    

    但这可能还不够,因为for 循环也依赖于Option,但我现在不记得它是一个 lang 项还是通过完整路径查找。

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多