@@ -1207,6 +1207,52 @@ fn main() {
12071207```
12081208"## ,
12091209
1210+ E0284 : r##"
1211+ This error occurs when the compiler is unable to unambiguously infer the
1212+ return type of a function or method which is generic on return type, such
1213+ as the `collect` method for `Iterator`s.
1214+
1215+ For example:
1216+
1217+ ```compile_fail,E0284
1218+ fn foo() -> Result<bool, ()> {
1219+ let results = [Ok(true), Ok(false), Err(())].iter().cloned();
1220+ let v : Vec<bool> = results.collect()?;
1221+ // Do things with v...
1222+ Ok(true)
1223+ }
1224+ ```
1225+
1226+ Here we have an iterator `results` over `Result<bool, ()>`.
1227+ Hence, `results.collect()` can return any type implementing
1228+ `FromIterator<Result<bool, ()>>`. On the other hand, the
1229+ `?` operator can accept any type implementing `Try`.
1230+
1231+ The user of this code probably wants `collect()` to return a
1232+ `Result<Vec<bool>, ()>`, but the compiler can't be sure
1233+ that there isn't another type `T` implementing both `Try` and
1234+ `FromIterator<Result<bool, ()>>` in scope such that
1235+ `T::Ok == Vec<bool>`. Hence, this code is ambiguous and an error
1236+ is returned.
1237+
1238+ To resolve this error, use a concrete type for the intermediate expression:
1239+
1240+ ```
1241+ fn foo() -> Result<bool, ()> {
1242+ let results = [Ok(true), Ok(false), Err(())].iter().cloned();
1243+ let v = {
1244+ let temp : Result<Vec<bool>, ()> = results.collect();
1245+ temp?
1246+ };
1247+ // Do things with v...
1248+ Ok(true)
1249+ }
1250+ ```
1251+ Note that the type of `v` can now be inferred from the type of `temp`
1252+
1253+
1254+ "## ,
1255+
12101256E0308 : r##"
12111257This error occurs when the compiler was unable to infer the concrete type of a
12121258variable. It can occur for several cases, the most common of which is a
@@ -2158,7 +2204,6 @@ register_diagnostics! {
21582204 E0278 , // requirement is not satisfied
21592205 E0279 , // requirement is not satisfied
21602206 E0280 , // requirement is not satisfied
2161- E0284 , // cannot resolve type
21622207// E0285, // overflow evaluation builtin bounds
21632208// E0296, // replaced with a generic attribute input check
21642209// E0300, // unexpanded macro
0 commit comments