]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: add lang item "phantom_data"
authorRaiki Tamura <tamaron1203@gmail.com>
Wed, 9 Nov 2022 09:49:12 +0000 (18:49 +0900)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 21 Feb 2023 11:36:44 +0000 (12:36 +0100)
gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add handling for `phantom_data` lang item.

gcc/testsuite/ChangeLog:

* rust/compile/torture/phantom_data.rs: New test.

gcc/rust/util/rust-lang-item.h
gcc/testsuite/rust/compile/torture/phantom_data.rs [new file with mode: 0644]

index 02eeaee60df3f56d0be323f02982c3669b53eb46..ea0c91aa5f20d6d151a1cdc3e35ffd1fbf450d9e 100644 (file)
@@ -73,6 +73,9 @@ public:
     MUT_PTR,
     CONST_SLICE_PTR,
 
+    // https://github.com/rust-lang/rust/blob/master/library/core/src/marker.rs
+    PHANTOM_DATA,
+
     // functions
     FN_ONCE,
     FN_ONCE_OUTPUT,
@@ -222,6 +225,10 @@ public:
       {
        return ItemType::CONST_SLICE_PTR;
       }
+    else if (item.compare ("phantom_data") == 0)
+      {
+       return ItemType::PHANTOM_DATA;
+      }
     else if (item.compare ("fn_once") == 0)
       {
        return ItemType::FN_ONCE;
@@ -308,6 +315,8 @@ public:
        return "mut_ptr";
       case CONST_SLICE_PTR:
        return "const_slice_ptr";
+      case PHANTOM_DATA:
+       return "phantom_data";
       case FN_ONCE:
        return "fn_once";
       case FN_ONCE_OUTPUT:
diff --git a/gcc/testsuite/rust/compile/torture/phantom_data.rs b/gcc/testsuite/rust/compile/torture/phantom_data.rs
new file mode 100644 (file)
index 0000000..89e76ae
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-options "-w" }
+#[lang = "phantom_data"]
+struct PhantomData<T>;
+
+trait Hash {
+    fn hash<H>(&self, state: &mut H);
+}
+
+impl<T> Hash for PhantomData<T> {
+    fn hash<H>(&self, state: &mut H) {}
+}