A &(dyn Error + 'static) should be fine for that; you don't need any allocated/variable sized data in a memory allocation failure.