Why does the `?` operator convert a `&str` into an `String` (implicitly)?

35 points Sematre

While working on a project I found out by accident that the ? operator turns a &str into a String.

fn do_stuff() -> Result<(), String> {
    Err("important error message").map_err(|_| "new error message")?;
    Ok(())
}

although this doesn't work:

fn do_stuff() -> Result<(), String> {
    Err("important error message").map_err(|_| "new error message")
}

why is that?

Context: I would've expected that one would need a to_string() call for that to work, but I guess not?