rust-analyzer
rust-analyzer copied to clipboard
RA does not identify types of parameters for a closure returned from a closure if the closure is a `trait` with `Fn` as a supertrait
Given the code:
pub trait Second: Fn(String) -> String {}
impl<F> Second for F where F: Clone + Fn(String) -> String {}
pub trait First: Fn(String) -> Box<dyn Second> {}
impl<F> First for F where F: Clone + Fn(String) -> Box<dyn Second> {}
fn example() -> Box<dyn First> {
// ↓ s: {unknown}
Box::new(|s| Box::new(|v| v))
}
Rust Analyzer is not able to detect the type of s for usage. It does, however, recognize when methods are not present on s:

I think the problem is that deduce_sig_from_dyn_ty only looks for Fn traits in the bounds, instead of looking through the super traits. Presumably that's what rustc does, though it'd be worth checking.