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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/6b891ee3e6b879e402b037c1322a8350c72b7798
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4437
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 79f952e2d..afac1a5b2 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 000000000..71580ef5a
--- /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
base-commit: 0cc6e9cf4603e5d539266abf7b3dbb2c77a74966
--
2.53.0