rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.27k stars 1.61k forks source link

"Rename" for references in HRTB #17887

Open decorator-factory opened 2 months ago

decorator-factory commented 2 months ago

It seems like rust-analyzer doesn't support renaming lifetimes within a higher-ranked trait bound.

Example code: (from https://doc.rust-lang.org/nomicon/hrtb.html)

struct Closure<F> {
    data: (u8, u16),
    func: F,
}

impl<F> Closure<F>
where
    for<'a> F: Fn(&'a (u8, u16)) -> &'a u8,
{
    fn call<'x>(&'x self) -> &'x u8 {
        (self.func)(&self.data)
    }
}

Going to 'x and pressing F2 in VSCode shows a renaming dialog. However, trying to rename 'a doesn't work (Request failed: No references found at position in the trace).

image

ChayimFriedman2 commented 2 months ago

Not just rename, all features don't work with HRTB.

Veykril commented 2 months ago

We mostly ignore HRTBs right now (in part due to us generally not resolving lifetimes within the HIR yet)

Veykril commented 2 months ago

This seems to stem in part from https://github.com/rust-lang/rust-analyzer/blob/bd4785a6f017ec52bc0fb6c061c5f42228946462/crates/hir/src/semantics.rs#L1129-L1138 and ast::WherePred not implementing HasGenericParamList (closures also don't even though they should now) meaning we fully ignore them in that code snippet, but even then it will fail as we don't record HRTBs in the hir yet I think