/src/librustc/lint/builtin.rs

https://gitlab.com/alx741/rust · Rust · 242 lines · 191 code · 35 blank · 16 comment · 2 complexity · ffc238198aa27a72d0b608a45aea7c2d MD5 · raw file

  1. // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. //! Some lints that are built in to the compiler.
  11. //!
  12. //! These are the built-in lints that are emitted direct in the main
  13. //! compiler code, rather than using their own custom pass. Those
  14. //! lints are all available in `rustc_lint::builtin`.
  15. use lint::{LintPass, LateLintPass, LintArray};
  16. declare_lint! {
  17. pub CONST_ERR,
  18. Warn,
  19. "constant evaluation detected erroneous expression"
  20. }
  21. declare_lint! {
  22. pub UNUSED_IMPORTS,
  23. Warn,
  24. "imports that are never used"
  25. }
  26. declare_lint! {
  27. pub UNUSED_EXTERN_CRATES,
  28. Allow,
  29. "extern crates that are never used"
  30. }
  31. declare_lint! {
  32. pub UNUSED_QUALIFICATIONS,
  33. Allow,
  34. "detects unnecessarily qualified names"
  35. }
  36. declare_lint! {
  37. pub UNKNOWN_LINTS,
  38. Warn,
  39. "unrecognized lint attribute"
  40. }
  41. declare_lint! {
  42. pub UNUSED_VARIABLES,
  43. Warn,
  44. "detect variables which are not used in any way"
  45. }
  46. declare_lint! {
  47. pub UNUSED_ASSIGNMENTS,
  48. Warn,
  49. "detect assignments that will never be read"
  50. }
  51. declare_lint! {
  52. pub DEAD_CODE,
  53. Warn,
  54. "detect unused, unexported items"
  55. }
  56. declare_lint! {
  57. pub UNREACHABLE_CODE,
  58. Warn,
  59. "detects unreachable code paths"
  60. }
  61. declare_lint! {
  62. pub WARNINGS,
  63. Warn,
  64. "mass-change the level for lints which produce warnings"
  65. }
  66. declare_lint! {
  67. pub UNUSED_FEATURES,
  68. Warn,
  69. "unused or unknown features found in crate-level #[feature] directives"
  70. }
  71. declare_lint! {
  72. pub STABLE_FEATURES,
  73. Warn,
  74. "stable features found in #[feature] directive"
  75. }
  76. declare_lint! {
  77. pub UNKNOWN_CRATE_TYPES,
  78. Deny,
  79. "unknown crate type found in #[crate_type] directive"
  80. }
  81. declare_lint! {
  82. pub VARIANT_SIZE_DIFFERENCES,
  83. Allow,
  84. "detects enums with widely varying variant sizes"
  85. }
  86. declare_lint! {
  87. pub FAT_PTR_TRANSMUTES,
  88. Allow,
  89. "detects transmutes of fat pointers"
  90. }
  91. declare_lint! {
  92. pub TRIVIAL_CASTS,
  93. Allow,
  94. "detects trivial casts which could be removed"
  95. }
  96. declare_lint! {
  97. pub TRIVIAL_NUMERIC_CASTS,
  98. Allow,
  99. "detects trivial casts of numeric types which could be removed"
  100. }
  101. declare_lint! {
  102. pub PRIVATE_IN_PUBLIC,
  103. Warn,
  104. "detect private items in public interfaces not caught by the old implementation"
  105. }
  106. declare_lint! {
  107. pub INACCESSIBLE_EXTERN_CRATE,
  108. Warn,
  109. "use of inaccessible extern crate erroneously allowed"
  110. }
  111. declare_lint! {
  112. pub INVALID_TYPE_PARAM_DEFAULT,
  113. Warn,
  114. "type parameter default erroneously allowed in invalid location"
  115. }
  116. declare_lint! {
  117. pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
  118. Warn,
  119. "floating-point constants cannot be used in patterns"
  120. }
  121. declare_lint! {
  122. pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
  123. Warn,
  124. "constants of struct or enum type can only be used in a pattern if \
  125. the struct or enum has `#[derive(PartialEq, Eq)]`"
  126. }
  127. declare_lint! {
  128. pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
  129. Deny,
  130. "unit struct or enum variant erroneously allowed to match via path::ident(..)"
  131. }
  132. declare_lint! {
  133. pub RAW_POINTER_DERIVE,
  134. Warn,
  135. "uses of #[derive] with raw pointers are rarely correct"
  136. }
  137. declare_lint! {
  138. pub TRANSMUTE_FROM_FN_ITEM_TYPES,
  139. Warn,
  140. "transmute from function item type to pointer-sized type erroneously allowed"
  141. }
  142. declare_lint! {
  143. pub OVERLAPPING_INHERENT_IMPLS,
  144. Warn,
  145. "two overlapping inherent impls define an item with the same name were erroneously allowed"
  146. }
  147. declare_lint! {
  148. pub RENAMED_AND_REMOVED_LINTS,
  149. Warn,
  150. "lints that have been renamed or removed"
  151. }
  152. declare_lint! {
  153. pub SUPER_OR_SELF_IN_GLOBAL_PATH,
  154. Warn,
  155. "detects super or self keywords at the beginning of global path"
  156. }
  157. declare_lint! {
  158. pub UNSIZED_IN_TUPLE,
  159. Warn,
  160. "unsized types in the interior of a tuple were erroneously allowed"
  161. }
  162. declare_lint! {
  163. pub OBJECT_UNSAFE_FRAGMENT,
  164. Warn,
  165. "object-unsafe non-principal fragments in object types were erroneously allowed"
  166. }
  167. /// Does nothing as a lint pass, but registers some `Lint`s
  168. /// which are used by other parts of the compiler.
  169. #[derive(Copy, Clone)]
  170. pub struct HardwiredLints;
  171. impl LintPass for HardwiredLints {
  172. fn get_lints(&self) -> LintArray {
  173. lint_array!(
  174. UNUSED_IMPORTS,
  175. UNUSED_EXTERN_CRATES,
  176. UNUSED_QUALIFICATIONS,
  177. UNKNOWN_LINTS,
  178. UNUSED_VARIABLES,
  179. UNUSED_ASSIGNMENTS,
  180. DEAD_CODE,
  181. UNREACHABLE_CODE,
  182. WARNINGS,
  183. UNUSED_FEATURES,
  184. STABLE_FEATURES,
  185. UNKNOWN_CRATE_TYPES,
  186. VARIANT_SIZE_DIFFERENCES,
  187. FAT_PTR_TRANSMUTES,
  188. TRIVIAL_CASTS,
  189. TRIVIAL_NUMERIC_CASTS,
  190. PRIVATE_IN_PUBLIC,
  191. INACCESSIBLE_EXTERN_CRATE,
  192. INVALID_TYPE_PARAM_DEFAULT,
  193. ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
  194. ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
  195. MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
  196. CONST_ERR,
  197. RAW_POINTER_DERIVE,
  198. TRANSMUTE_FROM_FN_ITEM_TYPES,
  199. OVERLAPPING_INHERENT_IMPLS,
  200. RENAMED_AND_REMOVED_LINTS,
  201. SUPER_OR_SELF_IN_GLOBAL_PATH,
  202. UNSIZED_IN_TUPLE,
  203. OBJECT_UNSAFE_FRAGMENT
  204. )
  205. }
  206. }
  207. impl LateLintPass for HardwiredLints {}