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 上編輯此頁 最後更新: