rust-analyzer icon indicating copy to clipboard operation
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

Open chanced opened this issue 3 years ago • 1 comments

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: Screen Shot 2022-07-05 at 2 45 38 PM

chanced avatar Jul 05 '22 18:07 chanced

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.

flodiebold avatar Jul 05 '22 19:07 flodiebold