E4018

E4018#

Cannot resolve trait for the given type.

Erroneous Example#

///|
trait HasDefault {
  f(Self) -> Unit = _
}

///|
impl HasDefault with f(_) {

}

///|
struct S(Int)

///|
test {
  let s : S = S(3)
  let _ = Show::to_string(s)
  HasDefault::f(s)
}

The example above tries to call the method to_string from the Show trait and the method f from the HasDefault trait on type S, but since S does not implement those traits, it gives the following error:

Type S does not implement trait Show: no `impl` is defined
Type S does not implement trait HasDefault: no `impl` is defined

Hint

For a trait that has default implementations for all its methods, an explicit implementation declaration is still needed.

Suggestion#

Implement the Show trait and the HasDefault trait for the type S:

///|
impl HasDefault for S

///|
impl Show for S with output(s, logger) {
  s.0.output(logger)
}