aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc6
-rw-r--r--gcc/testsuite/rust/compile/issue-1289.rs42
2 files changed, 48 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 84aa835..c509d9b 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2441,6 +2441,9 @@ ReferenceType::is_equal (const BaseType &other) const
return false;
auto other2 = static_cast<const ReferenceType &> (other);
+ if (mutability () != other2.mutability ())
+ return false;
+
return get_base ()->is_equal (*other2.get_base ());
}
@@ -2535,6 +2538,9 @@ PointerType::is_equal (const BaseType &other) const
return false;
auto other2 = static_cast<const PointerType &> (other);
+ if (mutability () != other2.mutability ())
+ return false;
+
return get_base ()->is_equal (*other2.get_base ());
}
diff --git a/gcc/testsuite/rust/compile/issue-1289.rs b/gcc/testsuite/rust/compile/issue-1289.rs
new file mode 100644
index 0000000..8634f1d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1289.rs
@@ -0,0 +1,42 @@
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+mod intrinsics {
+ extern "rust-intrinsic" {
+ pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
+ }
+}
+
+#[lang = "mut_ptr"]
+impl<T> *mut T {
+ pub const unsafe fn offset(self, count: isize) -> *mut T {
+ unsafe { intrinsics::offset(self, count) as *mut T }
+ }
+
+ pub const unsafe fn add(self, count: usize) -> Self {
+ unsafe { self.offset(count as isize) }
+ }
+}
+
+#[lang = "const_ptr"]
+impl<T> *const T {
+ pub const unsafe fn offset(self, count: isize) -> *mut T {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ unsafe { intrinsics::offset(self, count) as *mut T }
+ }
+
+ pub const unsafe fn add(self, count: usize) -> Self {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ unsafe { self.offset(count as isize) }
+ }
+}
+
+fn main() -> i32 {
+ let a: *mut _ = &mut 123;
+ unsafe {
+ let _b = a.add(123);
+ }
+
+ 0
+}