Description
A coworker asked this question, and I was little surprised to not have an answer. I'll quote what he said:
let b1: Result<Vec<i32>, anyhow::Error> = vec![1, 2].into_iter().map(|i| Ok(i)).collect(); let b2: Vec<Box<dyn std::error::Error>> = vec!["1".to_owned()].into_iter().map(Into::into).collect();The call to
collect
for b1 made use of impl<A, E, V> FromIterator<Result<A, E>> for Result<V, E>, but there was no way in the IDE for me to discover that fact—not by hover, not by go-to-def.
Similarly, the call toInto::into
for b2 made use of impl From for Box, but again there's no IDE way for me to discover this.[Some details redacted]
- If you hover over
collect
it currently just prints the verbatim declaration of collect, namelypub fn collect<B>(self) -> B where B: FromIterator<Self::Item>
. I think it should also show (1) what B and Item are in this case, (2) the means by which "B: FromIterator" is satisfied. Similarly forInto::into
.- If you cmd-click over
into
then it takes you toimpl<T,U> const Into<U> for T where U:~const From<T> \\ fn into(self) -> U
. I think the IDE, when given a single-method trait likeFrom
, should also include the impl of that method in its list of go-to-def candidates.
The coworker thought (and I personally agree) that it'd be a neat feature for Rust Analyzer to surface these implementations these implementations at the callsite. I'd be happy to implement this feature, as I'm assuming that Chalk has most of this information already. However, I'm struggling to think of a general, principled way of surfacing this information, but I suppose that having rust-analyzer surface just the From
/Into
/TryFrom
/TryInto
impls for a given type is probably reasonable.