fn no_dangle() -> String { let s = String::from("hello"); s } This works without any problems. Ownership is moved out, and nothing is deallocated.