When does gene flow facilitate evolutionary rescue?