public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7626] gccrs: Fix cast site to not miss type-unifications
@ 2024-01-16 17:46 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1b34e40e5e41bdcb227b40523cd3a64c6f2fde00
commit r14-7626-g1b34e40e5e41bdcb227b40523cd3a64c6f2fde00
Author: Philip Herron <herron.philip@googlemail.com>
Date: Tue May 30 17:16:30 2023 +0100
gccrs: Fix cast site to not miss type-unifications
When attempting casts we can try a type coercion first, this is a
TryCoercion which will return a result. In the event this is ok we need to
perform a true coercion so that we don't leave missing infeence variable's
ununified.
Fixes #2195
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::check): do coercion
(TypeCastRules::emit_cast_error): clang-format
gcc/testsuite/ChangeLog:
* rust/compile/issue-2195.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/typecheck/rust-casts.cc | 9 +++++++--
gcc/testsuite/rust/compile/issue-2195.rs | 8 ++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 8e5e65eb22c..c9a25a03355 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -42,7 +42,12 @@ TypeCastRules::check ()
= TypeCoercionRules::TryCoerce (from.get_ty (), to.get_ty (), locus,
true /*allow-autoderef*/);
if (!possible_coercion.is_error ())
- return possible_coercion;
+ {
+ // given the attempt was ok we need to ensure we perform it so that any
+ // inference variables are unified correctly
+ return TypeCoercionRules::Coerce (from.get_ty (), to.get_ty (), locus,
+ true /*allow-autoderef*/);
+ }
// try the simple cast rules
auto simple_cast = cast_rules ();
@@ -303,4 +308,4 @@ TypeCastRules::emit_cast_error () const
}
} // namespace Resolver
-} // namespace Rust
\ No newline at end of file
+} // namespace Rust
diff --git a/gcc/testsuite/rust/compile/issue-2195.rs b/gcc/testsuite/rust/compile/issue-2195.rs
new file mode 100644
index 00000000000..c955df4f1c6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2195.rs
@@ -0,0 +1,8 @@
+struct A<T> {
+ // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+ f: *const T,
+}
+
+pub fn cast<T>(a: A<T>) {
+ let z = a.f as *const ();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 17:46 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:46 [gcc r14-7626] gccrs: Fix cast site to not miss type-unifications 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).