This question must have a really simple answer that I'm not seeing, since I'm reading it just stated in an undergrad textbook without any proof. It's about fluid dynamics, but the physics of it is actually irrelevant.
It's stated that the following equation
$$\nabla p + \rho\nabla\phi = 0$$
where $p$, $\rho$ and $\phi$ are smooth scalar functions on $\mathbb R^3$, has no solution if $\rho$ is not a constant, since the pressure term $p$ is a pure gradient, and the second term is not.
If $\rho$ is constant then of course there is the trivial solution $p=-\rho\phi + C$ for a constant $C$.
Can someone explain why it cannot have a solution if $\rho$ is not constant? I have some intuition about it, but can't see the statement to be trivial for any arbitrary functions $\rho$ and $\phi$.
Just to be clear, extending an aspect of @QiaochuYuan's answer: there is the very basic equality-of-mixed-partials criterion, that if $F(x,y,z)=(f_x,f_y,f_z)$ for some scalar-valued $f$, then (because under mild hypotheses $(f_x)_y=(f_y)_x)$, etc.), the partial with respect to $y$ of the first component of $F$ must be equal to the partial with respect to $x$ of the second component of $F$, and so on.
In your set-up, this gives a necessary condition on $\rho$.
In fact, locally this is also a sufficient condition, but some of the interesting cases are definitely not local...