| 1 |
// Copyright 2026 The Fuchsia Authors |
| 2 |
// |
| 3 |
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 4 |
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 5 |
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 6 |
// This file may not be copied, modified, or distributed except according to |
| 7 |
// those terms. |
| 8 |
|
| 9 |
#![no_implicit_prelude] |
| 10 |
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] |
| 11 |
|
| 12 |
include!("include.rs"); |
| 13 |
|
| 14 |
// Original reproducer from #2915 |
| 15 |
#[derive(imp::TryFromBytes)] |
| 16 |
#[zerocopy(crate = "zerocopy_renamed")] |
| 17 |
#[repr(u8)] |
| 18 |
enum MyEnum { |
| 19 |
Type, |
| 20 |
OtherWithData(u8), |
| 21 |
} |
| 22 |
|
| 23 |
// Tests for all other associated types which may be problematic in our codebase |
| 24 |
// as of this commit. |
| 25 |
|
| 26 |
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned, imp::Immutable, imp::KnownLayout)] |
| 27 |
#[zerocopy(crate = "zerocopy_renamed")] |
| 28 |
#[repr(C)] |
| 29 |
pub struct StructCollision { |
| 30 |
pub Type: u8, |
| 31 |
pub LAYOUT: u8, |
| 32 |
pub PointerMetadata: u8, |
| 33 |
pub Tag: u8, |
| 34 |
pub tag: u8, |
| 35 |
pub variants: u8, |
| 36 |
} |
| 37 |
|
| 38 |
impl StructCollision { |
| 39 |
pub const Type: () = (); |
| 40 |
pub const LAYOUT: () = (); |
| 41 |
pub const PointerMetadata: () = (); |
| 42 |
} |
| 43 |
|
| 44 |
#[derive(imp::FromZeros, imp::Immutable, imp::KnownLayout)] |
| 45 |
#[zerocopy(crate = "zerocopy_renamed")] |
| 46 |
#[repr(C)] |
| 47 |
pub enum EnumCollision { |
| 48 |
Type { x: u8 }, |
| 49 |
LAYOUT { x: u8 }, |
| 50 |
PointerMetadata { x: u8 }, |
| 51 |
Tag { x: u8 }, |
| 52 |
tag { x: u8 }, |
| 53 |
variants { x: u8 }, |
| 54 |
} |
| 55 |
|
| 56 |
// Case where generic parameter has associated type colliding with internal usage |
| 57 |
pub trait AmbiguousTrait { |
| 58 |
type Type; |
| 59 |
const LAYOUT: usize; |
| 60 |
type PointerMetadata; |
| 61 |
} |
| 62 |
|
| 63 |
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned, imp::Immutable, imp::KnownLayout)] |
| 64 |
#[zerocopy(crate = "zerocopy_renamed")] |
| 65 |
#[repr(C)] |
| 66 |
pub struct GenericCollision<T: AmbiguousTrait> { |
| 67 |
pub field: u8, |
| 68 |
pub typ: T::Type, |
| 69 |
pub pointer_metadata: T::PointerMetadata, |
| 70 |
pub _marker: imp::PhantomData<T>, |
| 71 |
} |
| 72 |
|
| 73 |
#[test] |
| 74 |
fn test_compilation() { |
| 75 |
// If the derives compile, we are good. |
| 76 |
let _ = StructCollision { Type: 0, LAYOUT: 0, PointerMetadata: 0, Tag: 0, tag: 0, variants: 0 }; |
| 77 |
let _ = EnumCollision::Type { x: 0 }; |
| 78 |
} |