The Inverse Mellin Transform and residues Context: I saw this solution, and as far as I can tell it uses the following:
$$\int_{\gamma-i\infty}^{\gamma+i\infty}Q(s)/x^sds=\sum_{s_k\text{ poles of } Q}\text{Res}_{s=s_k}Q(s)/x^s+\int_{\gamma'-i\infty}^{\gamma'+i\infty}Q(s)/x^sds,\tag1$$
where $\Re(s)=\gamma$ lies to the right of all the poles $s_k$ and $\Re(s)=\gamma'$ lies to the left of all the poles, and $$Q(s)=\int_0^\infty x^{s-1}f(x)dx,$$
so that $$f(x)=\int_{\gamma-i\infty}^{\gamma+i\infty}Q(s)/x^sds.$$
Question: When, if ever, is $(1)$ true? I have not seen it discussed anywhere other than MSE, where I have seen it a few times without explanation or justification.
Pardon me if this question is trivial, I don't have much experience with complex analysis.
 A: The residue theorem says that for $Q$ meromorphic with poles at $a_k$ and $C$ a rectangle  $(\gamma',\gamma)+i(-T,T)$ with no poles on the boundary then $\int_{\partial C} Q(s)x^{-s}ds=2i\pi \sum_{a_k\in C} Res(Q(s)x^{-s})$ so it remains to check what happens as $|T|\to \infty$.
In your linked question the behavior as $|T|\to\infty$ is clear because $Q(s)$ has finitely many poles and it is rapidly decreasing on vertical strips, so $Q(x)x^{-s}$ is integrable on vertical lines and $\lim_{|T|\to \infty} \int_{\gamma'+iT}^{\gamma+iT} Q(s)x^{-s}ds= 0$.
Sometimes it works as well when $\int_{\gamma-i\infty}^{\gamma+i\infty}Q(s)/x^sds$ only converges conditionnally, sometimes it works when $Q(s)$ has infinitely many poles (or essential singularities or other kind of singularities), sometimes $\lim_{\gamma'\to -\infty}\int_{\gamma'-i\infty}^{\gamma'+i\infty}Q(s)x^{-s}ds=0$ so that $f(x) =2i\pi \sum Res(Q(s)x^{-s})$.
This is standard in the context of the residue theorem that every function is different and that we often need a bit of tricky investigation before finding the correct contours and limits.
