This is a (very) contrived example that exhibits the error:
struct X {
x: bool,
}
impl X {
fn new() -> X {
X{x: false}
}
}
trait Thing {
fn toggle(&mut self);
}
impl Thing for X {
fn toggle(&mut self) {
self.x = !self.x;
}
}
fn bounded<T: Thing>(x: &mut X) {
x.toggle()
}
fn main() {
let mut x = X::new();
bounded(&mut x);
}
Fires the error:
bounded.rs:28:5: 28:12 error: cannot determine a type for this bounded type parameter: unconstrained type
bounded.rs:28 bounded(&mut x);
^~~~~~~
The error is fixed by redefining bounded:
fn bounded<T: Thing>(x: &mut T) { // Using 'T' instead of hardcoding the type.
x.toggle()
}
Should this be caught by the linter?