docs

#E0135: 方法所属的 trait 不在作用域中

这个方法存在,但它来自一个没有在这里导入的 trait,而 trait 的方法只有在 trait 处于作用域中时才能访问。按 help 所示加上 use path::Trait;,或者以 Trait::method(x, ..) 的形式调用它。

nabi
mod zoo {
    pub trait Wave { fn wave(self) -> str; }
    impl Wave for i32 { fn wave(self) -> str { "hi" } }
}

println(3.wave());
error[E0135]: method `wave` comes from trait `zoo::Wave`, which is not in scope
  --> main.nabi:6:9
   |
 6 | println(3.wave());
   |         ^^^^^^^^
   |
   = help: add `use pkg::zoo::Wave;`

导入这个 trait:

nabi
use pkg::zoo::Wave;

mod zoo {
    pub trait Wave { fn wave(self) -> str; }
    impl Wave for i32 { fn wave(self) -> str { "hi" } }
}

println(3.wave());
hi

相关错误码:E0046 没有这个方法或关联项,E0030 无法解析的导入

发现错误? 在 GitHub 上编辑此页 最后更新: