Failure to recognize &String
as equivalent to &str
#125450
Open
Description
opened on May 23, 2024
Code
fn main() {
let string_vec = vec!["1".to_string(), "2".to_string()];
let string_iter = string_vec.iter().map(str_ref_to_string);
}
fn str_ref_to_string(str_arg: &str) -> String {
str_arg.to_string()
}
Current output
type mismatch in function arguments
expected function signature `fn(&std::string::String) -> _`
found function signature `fn(&str) -> _`rustc
Desired output
No error
Rationale and extra context
The compiler interprets &String as equivalent to &str in most cases, so I don't see why it can't do the same in this case.
Other cases
No response
Rust Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Anything else?
No response
Activity