E0079#

Warning name: implicit_impl_as_method

Methods from an impl Trait for Type declaration are being attached to Type implicitly. This compatibility behavior is deprecated because it is not explicit or refactoring-safe. The warning is disabled by default in v0.10.4.

Erroneous example#

///|
pub(open) trait Render {
  fn render(Self) -> String
}

///|
pub(all) struct Badge(String)

///|
pub impl Render for Badge with render(self) {
  self.0
}

///|
pub fn show_badge(badge : Badge) -> String {
  badge.render()
}

修正案#

ドット構文をサポートすべきメソッドには extend Type with Trait::{method} を使用します。互換メソッドを移行期間だけ残す場合は、その extend 宣言を #deprecated でマークしてください。それ以外の場合は Trait::method(value) として実装を呼び出します。

///|
pub(open) trait Render {
  fn render(Self) -> String
}

///|
pub(all) struct Badge(String)

///|
pub impl Render for Badge with render(self) {
  self.0
}

///|
pub extend Badge with Render::{render}

///|
pub fn show_badge(badge : Badge) -> String {
  badge.render()
}