File tree Expand file tree Collapse file tree 2 files changed +108
-0
lines changed Expand file tree Collapse file tree 2 files changed +108
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ struct SUtf16Str {
40+ _data : <Slice as Structure < Utf16 > >:: RefTarget ,
41+ }
42+
43+ impl SUtf16Str {
44+ pub unsafe fn from_ptr < ' a > ( ptr : <Slice as Structure < Utf16 > >:: FfiPtr )
45+ -> Option < & ' a Self > {
46+ std:: mem:: transmute :: < Option < & [ <Utf16 as Encoding >:: Unit ] > , _ > (
47+ <Slice as Structure < Utf16 > >:: borrow_from_ffi_ptr ( ptr) )
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+ }
You can’t perform that action at this time.
0 commit comments