aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/rust/typecheck/rust-casts.cc9
-rw-r--r--gcc/testsuite/rust/compile/issue-2195.rs8
2 files changed, 15 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 8e5e65e..c9a25a0 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 0000000..c955df4
--- /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 ();
+}