I found the question How to keep Presta valve insert from detaching after inflation? but none of the answers are helpful because this happened to me in the middle of a ride on a rental bike. All I had was a pump, a hex wrench (allen key) for the axle and a tire lever.
I got a puncture, and without a patch kit I swapped on the spare tube. No problems thus far; I proceeded to screw on the pump and inflate the tyre. When I went to unscrew the pump, the valve core unscrewed and the tyre immediately deflated.
(This is when I discovered the tube had a removable valve core.)
On my fifth try (I had nothing but time) managed to make sufficient seal by main force (without fully screwing on the pump) to get a couple bars of pressure in the tyre (fortunately it was a 32, not my normal 25) and it sufficed to get me to a proper pump.
Is there any trick or technique that I could have used to deal with this more effectively?