Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #![allow(unreachable_code)]
  2.  
  3.  
  4. fn main() {
  5. let b = Box::new([1, 2u8]) as Box<[u8]>;
  6. let fat_ptr = Box::into_raw(b);
  7. let thin_ptr = fat_ptr as *mut u8;
  8. let b2 = unsafe {
  9. let s = ::std::slice::from_raw_parts_mut(thin_ptr, 2);
  10. Box::from_raw(s)
  11. };
  12. println!("{:?}", b2);
  13. }
  14.  
  15.  
  16. /* ~~~~=== stderr ===~~~~
  17. Compiling playground v0.0.1 (/playground)
  18. error[E0599]: no method named `into_raw` found for type `std::boxed::Box<[u8]>` in the current scope
  19. --> src/main.rs:6:60
  20. |
  21. 6 | let b = Box::new([1, 2]) as Box<[u8]>; let ptr = b.into_raw(); let s = ::std::slice::from_raw_parts(ptr, 2); Box::from_raw(s)
  22. | --^^^^^^^^
  23. | | |
  24. | | this is an associated function, not a method
  25. | help: use associated function syntax instead: `std::boxed::Box<[u8]>::into_raw`
  26. |
  27. = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
  28. = note: the candidate is defined in an impl for the type `std::boxed::Box<_>`
  29.  
  30. error[E0308]: mismatched types
  31. --> src/main.rs:6:132
  32. |
  33. 6 | let b = Box::new([1, 2]) as Box<[u8]>; let ptr = b.into_raw(); let s = ::std::slice::from_raw_parts(ptr, 2); Box::from_raw(s)
  34. | ^ types differ in mutability
  35. |
  36. = note: expected type `*mut _`
  37. found type `&[_]`
  38.  
  39. error: aborting due to 2 previous errors
  40.  
  41. Some errors occurred: E0308, E0599.
  42. For more information about an error, try `rustc --explain E0308`.
  43. error: Could not compile `playground`.
  44.  
  45. To learn more, run the command again with --verbose.
  46.  
  47. */
  48.  
  49. /* ~~~~=== stdout ===~~~~
  50.  
  51. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement