Structural collapse and superconductivity in rare-earth-doped CaFe2As2