Skip to content

Commit 6b891ee

Browse files
Pasta-coderCohenArthur
authored andcommitted
expand: Fix ICE on unimplemented RustcEncodable/Decodable derives
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 #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 <0001jayant@gmail.com>
1 parent 0cc6e9c commit 6b891ee

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

gcc/rust/expand/rust-derive.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ DeriveVisitor::derive (Item &item, const Attribute &attr,
7474
return vec (DeriveOrd (DeriveOrd::Ordering::Total, loc).go (item));
7575
case BuiltinMacro::PartialOrd:
7676
return vec (DeriveOrd (DeriveOrd::Ordering::Partial, loc).go (item));
77+
case BuiltinMacro::RustcEncodable:
78+
case BuiltinMacro::RustcDecodable:
79+
rust_sorry_at (loc, "derive(%s) is not yet implemented",
80+
to_derive == BuiltinMacro::RustcEncodable
81+
? "RustcEncodable"
82+
: "RustcDecodable");
83+
return {};
7784
default:
7885
rust_unreachable ();
7986
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" }
2+
#![feature(no_core)]
3+
#![no_core]
4+
5+
#[derive(RustcDecodable)] // { dg-message "is not yet implemented" }
6+
struct Struct1 {}
7+
8+
#[derive(RustcEncodable)] // { dg-message "is not yet implemented" }
9+
struct Struct2 {}
10+
11+
// Pinpoint the global errors (errors with no line number are at line 0)
12+
// { dg-error "could not resolve trait 'RustcDecodable'" "" { target *-*-* } 0 }
13+
// { dg-error "could not resolve trait 'RustcEncodable'" "" { target *-*-* } 0 }

0 commit comments

Comments
 (0)