Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arbitrary_self_types method resolution is incorrect #15083

Closed
alexkirsz opened this issue Jun 19, 2023 · 1 comment · Fixed by #15118
Closed

arbitrary_self_types method resolution is incorrect #15083

alexkirsz opened this issue Jun 19, 2023 · 1 comment · Fixed by #15118
Labels
A-ty type system / type inference / traits / method resolution B-unstable unstable feature C-feature Category: feature request

Comments

@alexkirsz
Copy link
Contributor

alexkirsz commented Jun 19, 2023

rust-analyzer version: 0.3.1557-standalone (cd3bf9f 2023-06-18)

rustc version: rustc 1.72.0-nightly (2d0aa5768 2023-06-18)

relevant settings: N/A

In the following example (playground):

#![feature(arbitrary_self_types)]

struct Ptr<T> {
    ptr: *const T,
}

impl<T> std::ops::Deref for Ptr<T> {
    type Target = *const T;

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

struct Val;

impl Val {
    fn add(self: Ptr<Val>) {}
}

fn main() {
    let val = Val;
    let val_ptr = Ptr { ptr: &val };
    val_ptr.add();
}

RA complains on line 24 (val_ptr.add()):

this operation is unsafe and requires an unsafe function or blockrust-analyzer[missing-unsafe](https://rust-analyzer.github.io/manual.html#missing-unsafe)
expected 1 argument, found 0rust-analyzer[mismatched-arg-count](https://rust-analyzer.github.io/manual.html#mismatched-arg-count)

The .add method is resolved to <*const Val>::add, when it should be resolved to Val::add.

@alexkirsz alexkirsz added the C-bug Category: bug label Jun 19, 2023
@Veykril Veykril added the A-ty type system / type inference / traits / method resolution label Jun 19, 2023
@flodiebold flodiebold added C-feature Category: feature request and removed C-bug Category: bug labels Jun 19, 2023
@flodiebold
Copy link
Member

We don't support arbitrary self types at all yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution B-unstable unstable feature C-feature Category: feature request
Projects
None yet
4 participants