/src/test/ui/asm/naked-functions-unused.rs

https://gitlab.com/rust-lang/rust · Rust · 87 lines · 58 code · 15 blank · 14 comment · 2 complexity · d521c440a902387b3cc19d1e86dd7db0 MD5 · raw file

  1. // revisions: x86_64 aarch64
  2. // needs-asm-support
  3. //[x86_64] only-x86_64
  4. //[aarch64] only-aarch64
  5. #![deny(unused)]
  6. #![feature(naked_functions)]
  7. #![crate_type = "lib"]
  8. pub trait Trait {
  9. extern "C" fn trait_associated(a: usize, b: usize) -> usize;
  10. extern "C" fn trait_method(&self, a: usize, b: usize) -> usize;
  11. }
  12. pub mod normal {
  13. use std::arch::asm;
  14. pub extern "C" fn function(a: usize, b: usize) -> usize {
  15. //~^ ERROR unused variable: `a`
  16. //~| ERROR unused variable: `b`
  17. unsafe { asm!("", options(noreturn)); }
  18. }
  19. pub struct Normal;
  20. impl Normal {
  21. pub extern "C" fn associated(a: usize, b: usize) -> usize {
  22. //~^ ERROR unused variable: `a`
  23. //~| ERROR unused variable: `b`
  24. unsafe { asm!("", options(noreturn)); }
  25. }
  26. pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
  27. //~^ ERROR unused variable: `a`
  28. //~| ERROR unused variable: `b`
  29. unsafe { asm!("", options(noreturn)); }
  30. }
  31. }
  32. impl super::Trait for Normal {
  33. extern "C" fn trait_associated(a: usize, b: usize) -> usize {
  34. //~^ ERROR unused variable: `a`
  35. //~| ERROR unused variable: `b`
  36. unsafe { asm!("", options(noreturn)); }
  37. }
  38. extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
  39. //~^ ERROR unused variable: `a`
  40. //~| ERROR unused variable: `b`
  41. unsafe { asm!("", options(noreturn)); }
  42. }
  43. }
  44. }
  45. pub mod naked {
  46. use std::arch::asm;
  47. #[naked]
  48. pub extern "C" fn function(a: usize, b: usize) -> usize {
  49. unsafe { asm!("", options(noreturn)); }
  50. }
  51. pub struct Naked;
  52. impl Naked {
  53. #[naked]
  54. pub extern "C" fn associated(a: usize, b: usize) -> usize {
  55. unsafe { asm!("", options(noreturn)); }
  56. }
  57. #[naked]
  58. pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
  59. unsafe { asm!("", options(noreturn)); }
  60. }
  61. }
  62. impl super::Trait for Naked {
  63. #[naked]
  64. extern "C" fn trait_associated(a: usize, b: usize) -> usize {
  65. unsafe { asm!("", options(noreturn)); }
  66. }
  67. #[naked]
  68. extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
  69. unsafe { asm!("", options(noreturn)); }
  70. }
  71. }
  72. }