public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7673] gccrs: we can't check the bounds involving empty placeholder types
@ 2024-01-16 17:52 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:52 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:0f15c111397bedbc0b01c65aa9cb477d65af53fe
commit r14-7673-g0f15c111397bedbc0b01c65aa9cb477d65af53fe
Author: Philip Herron <herron.philip@googlemail.com>
Date: Wed Jun 14 12:11:38 2023 +0100
gccrs: we can't check the bounds involving empty placeholder types
We use placeholders for assoicated types on traits but if we are unifying
types against a placeholder its not possible to check the bounds as the
placeholder does not have enough information yet at this point to determine
if bounds will or won't be satisfied. That check will occur when associated
types and generics are setup.
Fixes #2036
gcc/rust/ChangeLog:
* typecheck/rust-unify.cc (UnifyRules::go): dont check bounds on placeholders
gcc/testsuite/ChangeLog:
* rust/compile/issue-2036.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/typecheck/rust-unify.cc | 6 +++++-
gcc/testsuite/rust/compile/issue-2036.rs | 36 ++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 42e10950917..0e62a21dc25 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -151,7 +151,11 @@ UnifyRules::go ()
rtype->debug_str ().c_str ());
// check bounds
- bool should_check_bounds = !ltype->is_equal (*rtype);
+ bool ltype_is_placeholder = ltype->get_kind () == TyTy::TypeKind::PLACEHOLDER;
+ bool rtype_is_placeholder = rtype->get_kind () == TyTy::TypeKind::PLACEHOLDER;
+ bool types_equal = ltype->is_equal (*rtype);
+ bool should_check_bounds
+ = !types_equal && !(ltype_is_placeholder || rtype_is_placeholder);
if (should_check_bounds)
{
if (ltype->num_specified_bounds () > 0)
diff --git a/gcc/testsuite/rust/compile/issue-2036.rs b/gcc/testsuite/rust/compile/issue-2036.rs
new file mode 100644
index 00000000000..d1459752ea5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2036.rs
@@ -0,0 +1,36 @@
+trait Hash<H> {
+ fn hash2(&self, hasher: &H) -> u64;
+}
+
+trait Stream {
+ fn input(&mut self, bytes: &[u8]);
+ fn result(&self) -> u64;
+}
+
+trait StreamHasher {
+ type S: Stream;
+ fn stream(&self) -> Self::S;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+trait StreamHash<H: StreamHasher>: Hash<H> {
+ fn input_stream(&self, stream: &mut H::S);
+}
+
+impl<H: StreamHasher> Hash<H> for u8 {
+ fn hash2(&self, hasher: &H) -> u64 {
+ let mut stream = hasher.stream();
+ self.input_stream(&mut stream);
+ // { dg-error "type annotations needed" "" { target *-*-* } .-1 }
+ Stream::result(&stream)
+ }
+}
+
+impl<H: StreamHasher> StreamHash<H> for u8 {
+ fn input_stream(&self, stream: &mut H::S) {
+ Stream::input(stream, &[*self]);
+ }
+}
+
+fn main() {}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 17:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:52 [gcc r14-7673] gccrs: we can't check the bounds involving empty placeholder types Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).