Skip to content

Commit

Permalink
Fix bad copy-paste in can equal interface for pointer types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
philberty committed Mar 17, 2022
1 parent bb234b0 commit 6e385d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gcc/rust/typecheck/rust-tyty-cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ class PointerCmp : public BaseCmp
: BaseCmp (base, emit_errors), base (base)
{}

void visit (const ReferenceType &type) override
void visit (const PointerType &type) override
{
auto base_type = base->get_base ();
auto other_base_type = type.get_base ();
Expand Down
16 changes: 16 additions & 0 deletions gcc/testsuite/rust/compile/issue-1031.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 {
// { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
unsafe { offset(self, count) }
}

pub const unsafe fn add(self, count: usize) -> Self {
// { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
unsafe { self.offset(count as isize) }
}
}

0 comments on commit 6e385d2

Please sign in to comment.