Should libstd use descriptive names for type parameters?

#1

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

#2

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

1 Like

#3

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

11 Likes

#4

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>`
20 Likes

#5

Or just SumResult

0 Likes

#6

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

0 Likes

#7

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