error[E0599]: no method named `method` found for struct `MyType` in the current scope

error[E0599]: the method `method` exists for struct `MyType<Xxx>`, but its trait bounds were not satisfied

無効なメソッドの呼出を行った。

パターン

基本形

型にメソッドがないパターン。

サンプル

以下では、型 MyValue にメソッド method が存在しない。


fn main() {
    let value = MyValue();
    value.method();
}

struct MyValue();

error[E0599]: no method named `method` found for struct `MyValue` in the current scope
 --> src\main.rs:3:11
  |
3 |     value.method();
  |           ^^^^^^ method not found in `MyValue`
...
6 | struct MyValue();
  | -------------- method `method` not found for this struct

境界への不適合

型にメソッドはあるが境界に適合しないパターン。

サンプル

以下では、変数 value は型 MyValue<T> ではあるが、メソッド print_binary を呼べない。なぜなら、型パラメタ T に割り当てられた型が bool であり、これは TUpperHex を実装すべきとした print_binary 実装時の境界に違反する。


use std::fmt::UpperHex;

fn main() {
    let value = MyValue(true);
    value.print_binary();
}

struct MyValue<T>(T);
impl<T: UpperHex> MyValue<T> {
    fn print_binary(&self) {
        println!("{:X}", self.0)
    }
}

error[E0599]: the method `print_binary` exists for struct `MyValue<bool>`, but its trait bounds were not satisfied
 --> src\main.rs:5:11
  |
5 |     value.print_binary();
  |           ^^^^^^^^^^^^ method cannot be called on `MyValue<bool>` due to unsatisfied trait bounds
...
8 | struct MyValue<T>(T);
  | ----------------- method `print_binary` not found for this struct
  |
note: trait bound `bool: UpperHex` was not satisfied
 --> src\main.rs:9:9
  |
9 | impl<T: UpperHex> MyValue<T> {
  |         ^^^^^^^^  ----------
  |         |
  |         unsatisfied trait bound introduced here

他エラーとの関係性

型が境界に一致するかついて。『E0308 - 型の不一致』のパターン B で取り上げたのと同じ型推論の影響を受ける。そのため、境界がクロージャについてのもので、それに型推論や HRTB が絡みそうな場合、そちらの情報も参照してほしい。