From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id B76D83858414; Sun, 5 Mar 2023 11:42:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B76D83858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678016575; bh=LIXbHjzAL6irV2OXKb93mMNn3Z2OABNOL/V0fn3n5uY=; h=From:To:Subject:Date:From; b=a0vDi9KyCwrxAFJTVQNH+nG1TbwmQa0m4KpYRkoG3ZWjGex+PtlZiTqpnPVqC0oEZ M+/ChFcGP1OMtLM95gSHjLf5r3wZhKUkBTChl6PhFLaZTWSYltm+ZO0MAStVaM0pGk +VIRB4Uxcewsom/7sEau/yJ03Xz55EPscx79Zdu4= 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] gccrs: make predicate bounds overwrite-able X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 06e1d43c2f8a05af9fd862e6497c21741fce85c7 X-Git-Newrev: a4aeea9a90b3ed23e154d325b0224d788a89f609 Message-Id: <20230305114255.B76D83858414@sourceware.org> Date: Sun, 5 Mar 2023 11:42:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a4aeea9a90b3ed23e154d325b0224d788a89f609 commit a4aeea9a90b3ed23e154d325b0224d788a89f609 Author: Philip Herron Date: Fri Mar 3 18:17:50 2023 +0000 gccrs: make predicate bounds overwrite-able When compiling types especially when using queries it needs to be permissive and allow them to be overwritten and a predicate might have one set of details in one senario and a new one with the same id later on but with different types. Fixes #1524 Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_resolved_predicate): remove gcc/testsuite/ChangeLog: * rust/compile/issue-1524.rs: New test. Diff: --- gcc/rust/typecheck/rust-typecheck-context.cc | 4 +-- gcc/testsuite/rust/compile/issue-1524.rs | 49 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc index 096ce26f1fa..6bc4160e76e 100644 --- a/gcc/rust/typecheck/rust-typecheck-context.cc +++ b/gcc/rust/typecheck/rust-typecheck-context.cc @@ -437,8 +437,8 @@ void TypeCheckContext::insert_resolved_predicate (HirId id, TyTy::TypeBoundPredicate predicate) { - auto it = predicates.find (id); - rust_assert (it == predicates.end ()); + // auto it = predicates.find (id); + // rust_assert (it == predicates.end ()); predicates.insert ({id, predicate}); } diff --git a/gcc/testsuite/rust/compile/issue-1524.rs b/gcc/testsuite/rust/compile/issue-1524.rs new file mode 100644 index 00000000000..e46efe4595f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1524.rs @@ -0,0 +1,49 @@ +// { dg-additional-options "-w" } +// https://github.com/Rust-GCC/gccrs/issues/1524 +// https://github.com/rust-lang/rust/blob/673d0db5e393e9c64897005b470bfeb6d5aec61b/src/test/ui/methods/method-normalize-bounds-issue-20604.rs +trait Hasher { + type Output; + fn finish(&self) -> Self::Output; +} + +trait Hash { + fn hash(&self, h: &mut H); +} + +trait HashState { + type Wut: Hasher; + fn hasher(&self) -> Self::Wut; +} + +struct SipHasher; +impl Hasher for SipHasher { + type Output = u64; + fn finish(&self) -> u64 { 4 } +} + +impl Hash for isize { + fn hash(&self, h: &mut SipHasher) {} +} + +struct SipState; +impl HashState for SipState { + type Wut = SipHasher; + fn hasher(&self) -> SipHasher { SipHasher } +} + +struct Map { + s: S, +} + +impl Map + where S: HashState, + ::Wut: Hasher, +{ + fn foo(&self, k: K) where K: Hash< ::Wut> {} +} + +fn foo>(map: &Map) { + map.foo(22); +} + +fn main() {}