From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id BB5D7388B5A4; Wed, 8 Jun 2022 12:50:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB5D7388B5A4 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Add testcase to prove bug is fixed X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: d5c1531cc41ea7fab4d522dafe3ff725a766fb49 X-Git-Newrev: 3a95f28788d6a7b1870f6247c5fa1e5af1ff8a61 Message-Id: <20220608125024.BB5D7388B5A4@sourceware.org> Date: Wed, 8 Jun 2022 12:50:24 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 12:50:24 -0000 https://gcc.gnu.org/g:3a95f28788d6a7b1870f6247c5fa1e5af1ff8a61 commit 3a95f28788d6a7b1870f6247c5fa1e5af1ff8a61 Author: Philip Herron Date: Wed May 25 15:01:52 2022 +0100 Add testcase to prove bug is fixed This bug was fixed in commit cb4d935508def8b250345ba5205a90ad9e177ab4 with related PR #1223 The issue is that associated tpyes get updated depending on the context they are used so we need to monomorphize the types when we can so that we don't then throw off the rest of typechecking with bogus errors like this. Fixes #1237 Diff: --- gcc/testsuite/rust/compile/issue-1237.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gcc/testsuite/rust/compile/issue-1237.rs b/gcc/testsuite/rust/compile/issue-1237.rs new file mode 100644 index 00000000000..542be897949 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1237.rs @@ -0,0 +1,23 @@ +// { dg-additional-options "-w" } +mod intrinsics { + extern "rust-intrinsic" { + pub fn offset(ptr: *const T, count: isize) -> *const T; + } +} + +impl *const T { + pub unsafe fn offset(self, count: isize) -> *const T { + unsafe { intrinsics::offset(self, count) } + } +} + +impl [T] { + pub unsafe fn get_unchecked(&self, index: usize) -> &T { + unsafe { &*(self as *const [T] as *const T).offset(index as isize) } + } +} + +#[inline] +unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 { + (unsafe { *buf.get_unchecked(start) } as u64) +}