Skip to content

arbitrary_self_types method resolution is incorrect #15083

@alexkirsz

Description

@alexkirsz

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

rustc version: rustc 1.72.0-nightly (2d0aa57 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionB-unstableunstable featureC-featureCategory: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions