Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Deref support #967

Closed
mqudsi opened this issue Jul 29, 2018 · 2 comments
Closed

Deref support #967

mqudsi opened this issue Jul 29, 2018 · 2 comments
Labels
racer an issue caused by or could be solved by Racer

Comments

@mqudsi
Copy link

mqudsi commented Jul 29, 2018

NB: This might be a duplicate as I'm surprised it's never been even brought up, but I can't find any issues matching Deref with GitHub search

It does not appear that autocompletion is recursively triggered for the target of a Deref operation, both when triggered implicitly or explicitly.

Given the following code, which compiles and runs correctly:

use std::ops::Deref;

struct DerefExample<T> {
    value: T
}

impl<T> Deref for DerefExample<T> {
    type Target = T;

    fn deref(&self) -> &T {
        &self.value
    }
}


fn main() -> () {
    let x = DerefExample { value: "a".to_string() };
    x.deref().starts_with("a");
}

Explicit Deref

On the line x.deref().starts_with..., autocompletion after x.deref(). suggests nothing. This is presumably tied to another bug, as the signature is clear (and rls itself is aware of x.deref() -> &T's existence).

Implicit Deref

On the same line, x. suggests value, deref() -> &T, and deref() -> &Self::Target. It does not suggest starts_with(...) -> bool.

@aloucks
Copy link
Contributor

aloucks commented Jul 29, 2018

Auto-completion is currently powered by racer. It looks like there's an open issue for enhancements that includes better deref support.

From racer-rust/racer#829

use std::ops::Deref;

struct Foo {}

impl Foo {
    fn bar(&self) {
        println!("nights");
    }
}

struct Ref<'a, T: 'a> {
    obj: &'a T,
}

impl<'a, T> Deref for Ref<'a, T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        self.obj
    }
}

fn main() {
    let a = Ref { obj: &Foo {} };
    // a. // Auto-complete does not work here
}

@nrc
Copy link
Member

nrc commented Jul 29, 2018

Closing in favour of the Racer issue.

@nrc nrc closed this as completed Jul 29, 2018
@nrc nrc added the racer an issue caused by or could be solved by Racer label Jul 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
racer an issue caused by or could be solved by Racer
Projects
None yet
Development

No branches or pull requests

3 participants