Because the loop does not initialize n if x is empty (the loop never runs) or does not contain any spaces (the if body never runs). Rust insists that you think about every possible scenario, not just the "happy path" or some easy example input. What should ret_s("") or ret_s("hello") return?
The canonical answer is that rather than usize it should return Option<usize> and indeed that’s what the appropriate standard iterator method does:
x.bytes().position(|&byte| byte == b' ')
is equivalent to your loop, except it returns Some(usize) or None if x does not contain a space.