]> git.proxmox.com Git - rustc.git/blob - src/test/ui/unsized/issue-40231-1.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / unsized / issue-40231-1.rs
1 // check-pass
2
3 #![allow(dead_code)]
4
5 trait Structure<E>: Sized where E: Encoding {
6 type RefTarget: ?Sized;
7 type FfiPtr;
8 unsafe fn borrow_from_ffi_ptr<'a>(ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget>;
9 }
10
11 enum Slice {}
12
13 impl<E> Structure<E> for Slice where E: Encoding {
14 type RefTarget = [E::Unit];
15 type FfiPtr = (*const E::FfiUnit, usize);
16 unsafe fn borrow_from_ffi_ptr<'a>(_ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget> {
17 panic!()
18 }
19 }
20
21 trait Encoding {
22 type Unit: Unit;
23 type FfiUnit;
24 }
25
26 trait Unit {}
27
28 enum Utf16 {}
29
30 impl Encoding for Utf16 {
31 type Unit = Utf16Unit;
32 type FfiUnit = u16;
33 }
34
35 struct Utf16Unit(pub u16);
36
37 impl Unit for Utf16Unit {}
38
39 type SUtf16Str = SeStr<Slice, Utf16>;
40
41 struct SeStr<S, E> where S: Structure<E>, E: Encoding {
42 _data: S::RefTarget,
43 }
44
45 impl<S, E> SeStr<S, E> where S: Structure<E>, E: Encoding {
46 pub unsafe fn from_ptr<'a>(_ptr: S::FfiPtr) -> Option<&'a Self> {
47 panic!()
48 }
49 }
50
51 fn main() {
52 const TEXT_U16: &'static [u16] = &[];
53 let _ = unsafe { SUtf16Str::from_ptr((TEXT_U16.as_ptr(), TEXT_U16.len())).unwrap() };
54 }