From 7693bb9e1d122bea1b0645dcc201c6ed79c910e2 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Mon, 2 Dec 2019 21:52:04 -0500 Subject: Add long error for E0631 and update ui tests. --- src/librustc_error_codes/error_codes/E0631.md | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/librustc_error_codes/error_codes/E0631.md (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md new file mode 100644 index 00000000000..ad419f82250 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0631.md @@ -0,0 +1,29 @@ +This error indicates a type mismatch in closure arguments. + +Erroneous code example: + +```compile_fail,E0631 +fn test_strings(string_vec: Vec) -> Vec { + string_vec + .iter() + .map(|arg: &i32| arg.eq("Test String")) + .collect() +} +``` + +The closure passed to `map` expects a `&String` argument, since `some_vec` +has the type `Vec`. +However, the closure argument is annotated as an `&i32`, which does not match +the type of the iterable. + +This can be resolved by changing the type annotation or removing it entirely +if it can be inferred. + +``` +fn test_strings(string_vec: Vec) -> Vec { + string_vec + .iter() + .map(|arg| arg.eq("Test String")) + .collect() +} +``` -- cgit 1.4.1-3-g733a5