Esteban Küber
49bb371ca7
When single impl can satisfy inference error, suggest type
...
When encountering an inference error where a return type must be known, like when calling `Iterator::sum::<T>()` without specifying `T`, look for all `T` that would satisfy `Sum<S>`. If only one, suggest it.
```
error[E0283]: type annotations needed
--> $DIR/cannot-infer-iterator-sum-return-type.rs:4:9
|
LL | let sum = v
| ^^^
...
LL | .sum(); // `sum::<T>` needs `T` to be specified
| --- type must be known at this point
|
= note: cannot satisfy `_: Sum<i32>`
help: the trait `Sum` is implemented for `i32`
--> $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL
::: $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL
|
= note: in this macro invocation
note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
= note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider giving `sum` an explicit type, where the type for type parameter `S` is specified
|
LL | let sum: i32 = v
| +++++
```
2026-03-18 18:16:47 +00:00
..
2024-03-11 19:42:04 +00:00
2025-02-24 18:48:40 +00:00
2026-01-21 12:53:44 +01:00
2025-01-28 17:52:28 +00:00
2025-01-28 17:52:28 +00:00
2025-02-28 20:43:15 +00:00
2025-02-28 20:43:15 +00:00
2024-09-29 23:40:43 -05:00
2026-01-01 18:12:34 -08:00
2023-11-24 19:15:52 +01:00
2026-01-01 18:12:34 -08:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-12-07 21:29:58 +00:00
2024-12-07 21:29:58 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-02-28 20:43:15 +00:00
2025-06-11 15:30:15 +01:00
2025-06-11 15:30:15 +01:00
2025-09-15 09:01:22 +00:00
2024-09-29 23:40:43 -05:00
2024-07-17 11:01:29 +01:00
2024-02-16 20:02:50 +00:00
2024-07-17 11:01:29 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2026-02-24 00:04:45 -05:00
2023-11-24 19:15:52 +01:00
2024-02-01 16:18:03 +01:00
2024-02-16 20:02:50 +00:00
2024-03-21 00:03:59 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-01 16:18:03 +01:00
2024-02-16 20:02:50 +00:00
2024-12-12 23:36:27 +00:00
2023-11-24 19:15:52 +01:00
2026-01-01 18:12:34 -08:00
2023-11-24 19:15:52 +01:00
2024-02-01 16:18:03 +01:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-01 16:18:03 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2025-06-07 13:01:16 +02:00
2025-04-08 23:06:31 +03:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-08-19 21:27:10 +02:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-02-28 20:43:15 +00:00
2025-02-28 20:43:15 +00:00
2024-02-16 20:02:50 +00:00
2025-05-21 20:20:19 +01:00
2025-06-30 08:45:43 +00:00
2025-02-28 20:43:15 +00:00
2025-02-28 20:43:15 +00:00
2024-07-11 11:00:15 +00:00
2023-11-24 19:15:52 +01:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-07-17 11:01:29 +01:00
2025-02-28 20:43:15 +00:00
2025-02-28 20:43:15 +00:00
2024-05-28 11:55:20 +00:00
2024-02-16 20:02:50 +00:00
2024-02-14 11:12:19 +00:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2024-07-17 11:01:29 +01:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-09-29 23:40:43 -05:00
2025-04-08 23:06:31 +03:00
2024-09-29 23:40:43 -05:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-06-07 13:01:16 +02:00
2024-01-24 02:53:15 +00:00
2023-11-30 20:59:51 +01:00
2025-06-07 13:01:16 +02:00
2026-02-17 16:51:44 +00:00
2026-02-17 16:51:44 +00:00
2026-03-18 18:16:47 +00:00
2024-02-16 20:02:50 +00:00
2025-08-19 21:27:10 +02:00
2025-05-21 20:20:19 +01:00
2025-05-21 20:20:19 +01:00
2024-03-21 00:03:59 +00:00
2024-03-21 00:03:59 +00:00
2024-03-21 00:03:59 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2025-06-14 13:44:43 +08:00
2025-08-19 21:27:10 +02:00
2025-06-14 13:44:43 +08:00
2025-08-19 21:27:10 +02:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-02-10 20:21:39 +00:00
2024-02-16 20:02:50 +00:00
2026-01-06 17:23:16 +00:00
2024-02-16 20:02:50 +00:00
2025-02-28 20:43:15 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-07-21 09:11:21 +00:00
2025-07-21 09:11:21 +00:00
2025-02-28 20:43:15 +00:00
2024-07-17 11:01:29 +01:00
2024-07-17 11:01:29 +01:00
2024-03-21 00:03:59 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-09-24 13:29:23 +00:00
2024-02-16 20:02:50 +00:00
2025-11-08 07:37:15 +01:00
2025-11-08 07:37:15 +01:00
2024-07-17 11:01:29 +01:00
2026-03-17 17:39:59 +08:00
2025-06-07 13:42:30 +02:00
2024-02-16 20:02:50 +00:00
2024-07-17 11:01:29 +01:00