Skip to content

Bad method resolution on pointers #1031

@philberty

Description

@philberty

I tried this code:

extern "rust-intrinsic" {
    pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
}

#[lang = "const_ptr"]
impl<T> *const T {
    pub const unsafe fn offset(self, count: isize) -> *const T {
        unsafe { offset(self, count) }
    }

    pub const unsafe fn add(self, count: usize) -> Self {
        unsafe { self.offset(count as isize) }
    }
}

I expected to see this happen: compile without error

Instead, this happened:

test.rs:12:18: error: expected [* const T=T REF: 33] got [& * const T=T REF: 33]
    8 |         unsafe { offset(self, count) }
      |                         ~
......
   12 |         unsafe { self.offset(count as isize) }
      |                  ^

see https://godbolt.org/z/dsfG8sahP

Meta

  • What version of Rust GCC were you using, git sha if possible. b82408f

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions