duckki
April 29, 2024, 6:26pm
1
When I hover over calls like X.into()
(or X.try_into()
) on VS Code, I wish I could see the eventual Y::from
method called by the blanket implementation.
Also, I'd be happy to help to implement it. Can someone point me to where to look at?
yyogo
April 29, 2024, 7:42pm
2
You're looking for Rust analyzer which is the official rust language server.
duckki
April 30, 2024, 12:58am
3
I just found a Github issue about this (opened back in Oct'22).
feature request: List all applicable From/Into impls
opened 10:01PM - 10 Oct 22 UTC
A-ty
C-feature
A-ide
A-hover
A coworker asked this question, and I was little surprised to not have an answer… . I'll quote what he said:
> ```rust
> 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>](https://doc.rust-lang.org/std/result/enum.Result.html#impl-FromIterator%3CResult%3CA%2C%20E%3E%3E-for-Result%3CV%2C%20E%3E), 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 to `Into::into` for b2 made use of [impl From<String> for Box<dyn Error>](https://doc.rust-lang.org/std/string/struct.String.html#impl-From%3CString%3E-for-Box%3Cdyn%20Error%3E), but again there's no IDE way for me to discover this.
>
> [Some details redacted]
>
> 1. If you hover over `collect` it currently just prints the verbatim declaration of collect, namely `pub 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 for `Into::into`.
> 2. If you cmd-click over `into` then it takes you to `impl<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 like `From`, 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.
There is already quite a bit of discussion over there and I'll follow up there as well.
3 Likes
system
Closed
July 29, 2024, 12:59am
4
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.