From: jayant chauhan <[email protected]>
When encountering `#[derive(RustcEncodable)]` or `RustcDecodable`, the
`DeriveVisitor` previously fell through to `rust_unreachable ()`,
causing an Internal Compiler Error.
This patch adds cases for these built-in macros to explicitly emit a
"sorry, unimplemented" message instead of crashing.
Fixes Rust-GCC#3951
gcc/rust/ChangeLog:
* expand/rust-derive.cc (DeriveVisitor::derive): Handle
`BuiltinMacro::RustcEncodable` and `BuiltinMacro::RustcDecodable`.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3951.rs: New test.
Signed-off-by: jayant chauhan <[email protected]>
---
gcc/rust/expand/rust-derive.cc | 7 +++++++
gcc/testsuite/rust/compile/issue-3951.rs | 13 +++++++++++++
2 files changed, 20 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3951.rs
diff --git a/gcc/rust/expand/rust-derive.cc b/gcc/rust/expand/rust-derive.cc
index 79f952e2d69..afac1a5b204 100644
--- a/gcc/rust/expand/rust-derive.cc
+++ b/gcc/rust/expand/rust-derive.cc
@@ -74,6 +74,13 @@ DeriveVisitor::derive (Item &item, const Attribute &attr,
return vec (DeriveOrd (DeriveOrd::Ordering::Total, loc).go (item));
case BuiltinMacro::PartialOrd:
return vec (DeriveOrd (DeriveOrd::Ordering::Partial, loc).go (item));
+ case BuiltinMacro::RustcEncodable:
+ case BuiltinMacro::RustcDecodable:
+ rust_sorry_at (loc, "derive(%s) is not yet implemented",
+ to_derive == BuiltinMacro::RustcEncodable
+ ? "RustcEncodable"
+ : "RustcDecodable");
+ return {};
default:
rust_unreachable ();
};
diff --git a/gcc/testsuite/rust/compile/issue-3951.rs
b/gcc/testsuite/rust/compile/issue-3951.rs
new file mode 100644
index 00000000000..71580ef5ad0
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3951.rs
@@ -0,0 +1,13 @@
+// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" }
+#![feature(no_core)]
+#![no_core]
+
+#[derive(RustcDecodable)] // { dg-message "is not yet implemented" }
+struct Struct1 {}
+
+#[derive(RustcEncodable)] // { dg-message "is not yet implemented" }
+struct Struct2 {}
+
+// Pinpoint the global errors (errors with no line number are at line 0)
+// { dg-error "could not resolve trait 'RustcDecodable'" "" { target *-*-* } 0
}
+// { dg-error "could not resolve trait 'RustcEncodable'" "" { target *-*-* } 0
}
\ No newline at end of file
--
2.50.1