trpl-zh-cn icon indicating copy to clipboard operation
trpl-zh-cn copied to clipboard

疑似错误

Open green961 opened this issue 1 year ago • 0 comments

https://kaisery.github.io/trpl-zh-cn/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html

mod front_of_house {
    pub mod hosting {
        pub fn add_to_waitlist() {}
    }
}

use crate::front_of_house::hosting;

mod customer {
    pub fn eat_at_restaurant() {
        hosting::add_to_waitlist();
    }
}

注意这里还有一个警告说 use 在其作用域内不再被使用!为了修复这个问题,可以将 use 移动到 customer 模块内,或者在子模块 customer 内通过 super::hosting 引用父模块中的这个短路径。

super::hosting 应该是 super::front_of_house::hosting

搜狗截图20240208221610

搜狗截图20240208223211

green961 avatar Feb 08 '24 14:02 green961