/src/test/run-pass/item-attributes.rs

http://github.com/jruderman/rust · Rust · 197 lines · 118 code · 38 blank · 41 comment · 0 complexity · fa54d86b96c99f14c50da8d8c4ec03b2 MD5 · raw file

  1. // These are attributes of the implicit crate. Really this just needs to parse
  2. // for completeness since .rs files linked from .rc files support this
  3. // notation to specify their module's attributes
  4. #[attr1 = "val"];
  5. #[attr2 = "val"];
  6. #[attr3];
  7. #[attr4(attr5)];
  8. // Special linkage attributes for the crate
  9. #[link(name = "std",
  10. vers = "0.1",
  11. uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
  12. url = "http://rust-lang.org/src/std")];
  13. // These are are attributes of the following mod
  14. #[attr1 = "val"]
  15. #[attr2 = "val"]
  16. mod test_first_item_in_file_mod { }
  17. mod test_single_attr_outer {
  18. #[attr = "val"]
  19. const x: int = 10;
  20. #[attr = "val"]
  21. fn f() { }
  22. #[attr = "val"]
  23. mod mod1 { }
  24. #[attr = "val"]
  25. #[abi = "cdecl"]
  26. extern mod rustrt { }
  27. }
  28. mod test_multi_attr_outer {
  29. #[attr1 = "val"]
  30. #[attr2 = "val"]
  31. const x: int = 10;
  32. #[attr1 = "val"]
  33. #[attr2 = "val"]
  34. fn f() { }
  35. #[attr1 = "val"]
  36. #[attr2 = "val"]
  37. mod mod1 { }
  38. #[attr1 = "val"]
  39. #[attr2 = "val"]
  40. #[abi = "cdecl"]
  41. extern mod rustrt { }
  42. #[attr1 = "val"]
  43. #[attr2 = "val"]
  44. type t = {x: int};
  45. }
  46. mod test_stmt_single_attr_outer {
  47. fn f() {
  48. #[attr = "val"]
  49. const x: int = 10;
  50. #[attr = "val"]
  51. fn f() { }
  52. /* FIXME: Issue #493
  53. #[attr = "val"]
  54. mod mod1 {
  55. }
  56. #[attr = "val"]
  57. #[abi = "cdecl"]
  58. extern mod rustrt {
  59. }
  60. */
  61. }
  62. }
  63. mod test_stmt_multi_attr_outer {
  64. fn f() {
  65. #[attr1 = "val"]
  66. #[attr2 = "val"]
  67. const x: int = 10;
  68. #[attr1 = "val"]
  69. #[attr2 = "val"]
  70. fn f() { }
  71. /* FIXME: Issue #493
  72. #[attr1 = "val"]
  73. #[attr2 = "val"]
  74. mod mod1 {
  75. }
  76. #[attr1 = "val"]
  77. #[attr2 = "val"]
  78. #[abi = "cdecl"]
  79. extern mod rustrt {
  80. }
  81. */
  82. }
  83. }
  84. mod test_attr_inner {
  85. mod m {
  86. // This is an attribute of mod m
  87. #[attr = "val"];
  88. }
  89. }
  90. mod test_attr_inner_then_outer {
  91. mod m {
  92. // This is an attribute of mod m
  93. #[attr = "val"];
  94. // This is an attribute of fn f
  95. #[attr = "val"]
  96. fn f() { }
  97. }
  98. }
  99. mod test_attr_inner_then_outer_multi {
  100. mod m {
  101. // This is an attribute of mod m
  102. #[attr1 = "val"];
  103. #[attr2 = "val"];
  104. // This is an attribute of fn f
  105. #[attr1 = "val"]
  106. #[attr2 = "val"]
  107. fn f() { }
  108. }
  109. }
  110. mod test_distinguish_syntax_ext {
  111. use std;
  112. fn f() {
  113. fmt!{"test%s", ~"s"};
  114. #[attr = "val"]
  115. fn g() { }
  116. }
  117. }
  118. mod test_other_forms {
  119. #[attr]
  120. #[attr(word)]
  121. #[attr(attr(word))]
  122. #[attr(key1 = "val", key2 = "val", attr)]
  123. fn f() { }
  124. }
  125. mod test_foreign_items {
  126. #[abi = "cdecl"]
  127. extern mod rustrt {
  128. #[attr];
  129. #[attr]
  130. fn get_task_id() -> libc::intptr_t;
  131. }
  132. }
  133. mod test_literals {
  134. #[str = "s"];
  135. #[char = 'c'];
  136. #[int = 100];
  137. #[uint = 100u];
  138. #[mach_int = 100u32];
  139. #[float = 1.0];
  140. #[mach_float = 1.0f32];
  141. #[nil = ()];
  142. #[bool = true];
  143. mod m { }
  144. }
  145. fn test_fn_inner() {
  146. #[inner_fn_attr];
  147. }
  148. fn main() { }
  149. //
  150. // Local Variables:
  151. // mode: rust
  152. // fill-column: 78;
  153. // indent-tabs-mode: nil
  154. // c-basic-offset: 4
  155. // buffer-file-coding-system: utf-8-unix
  156. // End:
  157. //