Should libstd use descriptive names for type parameters?

Sometimes names of type parameters leak into error messages, e.g.:

fn main() {
    (0..1000).sum() as f32;
}
(0..1000).sum() as f32;
^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `S`

I haven't written S. It isn't anywhere in my source code, and it's a cryptic name. For the sake of error messages where the type parameter appears, would it be better to use descriptive types names, e.g. fn sum<SumAccumulatorType>?

(0..1000).sum() as f32;
^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `SumAccumulatorType`
17 Likes

Make it SumAccumulator, without the Type at the end, and I’ll be happy.

1 Like

It would be clearer IMHO to just quote the definition of sum where S is defined.

11 Likes

Suggestion: when the type variable cannot be inferred, show the definition site of the type variable as so (as mark-i-m suggests as well):

(0..1000).sum() as f32;
^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `S` in `Iterator::sum::<S>`
21 Likes

Or just SumResult

See also https://github.com/rust-lang-nursery/api-guidelines/issues/111.

Looks to me more like the error message shouldn’t quote local names used in another library, at least not without any context. (So, I agree with @CAD97 and @mark-i-m ).

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.