Skip to content

Regression in method resolution #21213

@SludgePhD

Description

@SludgePhD

rust-analyzer version: 0.3.2702-standalone

rustc version: 1.91.0

editor or extension: VS Code

relevant settings: none

code snippet to reproduce:

[dependencies]
uoctl = "1.0.1"
pub const UINPUT_IOCTL_BASE: u8 = b'U';
pub const UI_DEV_CREATE: Ioctl = _IO(UINPUT_IOCTL_BASE, 1);

fn main() {
    UI_DEV_CREATE.ioctl(0)
}

There was a regression that happened in the last couple of weeks or months where rust-analyzer stopped correctly resolving the ioctl method. Haven't bisected reduced it or anything (I think this part of r-a is currently being reworked, so bisecting might be a waste of time).

In the uoctl crate, I've used an interesting pattern like this:

pub struct Ioctl<T: ?Sized = NoArgs> {
    request: u32,
    _p: PhantomData<T>,
}

pub struct NoArgs {
    // Unsized type so that the `impl<T> Ioctl<T>` does not conflict.
    _f: [u8],
}

impl Ioctl<NoArgs> {
    pub unsafe fn ioctl(self, fd: &impl AsRawFd) -> io::Result<c_int> { ... }
}

impl<T> Ioctl<T> {
    pub unsafe fn ioctl(self, fd: &impl AsRawFd, arg: T) -> io::Result<c_int> { ... }
}

So these non-overlapping ioctl definitions might be confusing r-a now. Though this did work fine before.

Metadata

Metadata

Labels

A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions