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

Bad method resolution on pointers #1031

Closed
philberty opened this issue Mar 16, 2022 · 1 comment · Fixed by #1033
Closed

Bad method resolution on pointers #1031

philberty opened this issue Mar 16, 2022 · 1 comment · Fixed by #1033
Assignees
Labels

Comments

@philberty
Copy link
Member

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
@philberty philberty added the bug label Mar 16, 2022
@philberty philberty added this to the Macro Expansion milestone Mar 16, 2022
@philberty philberty self-assigned this Mar 16, 2022
@philberty
Copy link
Member Author

The location info looks pretty wrong here as well which does not help.

@philberty philberty mentioned this issue Mar 16, 2022
18 tasks
bors bot added a commit that referenced this issue Mar 17, 2022
1022: attribute expansion: Fix spurious stripping of tail expression r=CohenArthur a=CohenArthur

This commit fixes the issue reported in #391, but highlights another
one, which will be reported.

Closes #391 

1033: Fix bad copy-paste in can equal interface for pointer types r=philberty a=philberty

When we perform method resolution we check if the self arguments can be
matched. Here the bug was that pointer types had a bad vistitor and only
could ever match reference types which is wrong and was a copy paste error.

Fixes #1031
Addresses #849 


Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
@bors bors bot closed this as completed in 6e385d2 Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant