Hey I was programming some rust and came across this:
#[allow(dead_code)]
pub fn get_examples() -> HashMap<String, Box<dyn example_manager::Example>> {
let map = HashMap::new();
//map.insert(String::from("Example1"), Box::from(SomeExampleImplementation {}));
map
}
In this case the compiler infers the type of the map correctly (Screenshot 1)
But when I uncomment the map-insertion line it changes the inferred type for the HashMap (For Context SomeExampleImplementation implements example_manager::Example). See Screenshot 2.
Because the compiler changed the inferred type I get an error, that map does not match the functions return type. The compiler could obviously figure out, what type to use for the HashMap. That's why I think that this could be considered a bug. Am I wrong?