/src/librustc/lint/builtin.rs

https://gitlab.com/0072016/0072016-rusty · Rust · 178 lines · 136 code · 26 blank · 16 comment · 2 complexity · 145e3eae04d4285da41688b28561772f 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 INVALID_TYPE_PARAM_DEFAULT,
  108. Warn,
  109. "type parameter default erroneously allowed in invalid location"
  110. }
  111. declare_lint! {
  112. pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
  113. Warn,
  114. "unit struct or enum variant erroneously allowed to match via path::ident(..)"
  115. }
  116. declare_lint! {
  117. pub RAW_POINTER_DERIVE,
  118. Warn,
  119. "uses of #[derive] with raw pointers are rarely correct"
  120. }
  121. /// Does nothing as a lint pass, but registers some `Lint`s
  122. /// which are used by other parts of the compiler.
  123. #[derive(Copy, Clone)]
  124. pub struct HardwiredLints;
  125. impl LintPass for HardwiredLints {
  126. fn get_lints(&self) -> LintArray {
  127. lint_array!(
  128. UNUSED_IMPORTS,
  129. UNUSED_EXTERN_CRATES,
  130. UNUSED_QUALIFICATIONS,
  131. UNKNOWN_LINTS,
  132. UNUSED_VARIABLES,
  133. UNUSED_ASSIGNMENTS,
  134. DEAD_CODE,
  135. UNREACHABLE_CODE,
  136. WARNINGS,
  137. UNUSED_FEATURES,
  138. STABLE_FEATURES,
  139. UNKNOWN_CRATE_TYPES,
  140. VARIANT_SIZE_DIFFERENCES,
  141. FAT_PTR_TRANSMUTES,
  142. TRIVIAL_CASTS,
  143. TRIVIAL_NUMERIC_CASTS,
  144. PRIVATE_IN_PUBLIC,
  145. INVALID_TYPE_PARAM_DEFAULT,
  146. MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
  147. CONST_ERR,
  148. RAW_POINTER_DERIVE
  149. )
  150. }
  151. }
  152. impl LateLintPass for HardwiredLints {}