E0053#
Unused trait bound.
The polymorphic function or method has a trait bound that is not used. This could be a potential bug that you have forgotten to apply the methods from the trait.
错误示例#
///|
trait Any {}
///|
pub fn[T : Any] check(_ : T) -> Unit {
println("Hello")
}
///|
pub fn[T : Compare] shortlex(a : Array[T], b : Array[T]) -> Int {
Int::compare(a.length(), b.length())
}
建议#
有几种方式可以修复这个警告:
If this trait bound is unnecessary, you can remove it
///| pub fn[T] check(_ : T) -> Unit { println("Hello") }
You can cast the variable to a trait object
///| pub fn[T : Any] check_any(t : T) -> Unit { let _ = t as &Any println("Hello") }
You can use the methods defined in the Trait
///| pub fn[T : Compare] shortlex(a : Array[T], b : Array[T]) -> Int { match Int::compare(a.length(), b.length()) { _..<0 => -1 1..<_ => 1 0 => for i = 0; i < a.length(); i = i + 1 { match T::compare(a[i], b[i]) { _..<0 => return -1 1..<_ => return 1 0 => () } } else { return 0 } } }