R, 56 bytes
-2 bytes thanks to Giuseppe.
function(v,x) sequence(d<-diff(c(0,which(v==x))),d-1,-1)
output
f(int, 0)
# [1] 2 1 0 2 1 0 0
f(int, 1)
# [1] 0 0
f(int, 2)
# [1] 4 3 2 1 0 2 1 0
f(int, 3)
# integer(0)
f(char, "A")
# [1] 0 2 1 0 0
f(char, "B")
# [1] 1 0
f(char, "C")
# [1] 2 1 0
f(char, "D")
# integer(0)
Works for R >= 4.0.0.