//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
+use errors::{Applicability, DiagnosticBuilder};
use lint::{LintPass, LateLintPass, LintArray};
+use session::Session;
+use syntax::ast;
+use syntax::codemap::Span;
+
+declare_lint! {
+ pub EXCEEDING_BITSHIFTS,
+ Deny,
+ "shift exceeds the type's number of bits"
+}
declare_lint! {
pub CONST_ERR,
- Warn,
+ Deny,
"constant evaluation detected erroneous expression"
}
"detects unreachable code paths"
}
+declare_lint! {
+ pub UNREACHABLE_PATTERNS,
+ Warn,
+ "detects unreachable patterns"
+}
+
+declare_lint! {
+ pub UNUSED_MACROS,
+ Warn,
+ "detects macros that were not used"
+}
+
declare_lint! {
pub WARNINGS,
Warn,
"unknown crate type found in #[crate_type] directive"
}
-declare_lint! {
- pub VARIANT_SIZE_DIFFERENCES,
- Allow,
- "detects enums with widely varying variant sizes"
-}
-
-declare_lint! {
- pub FAT_PTR_TRANSMUTES,
- Allow,
- "detects transmutes of fat pointers"
-}
-
declare_lint! {
pub TRIVIAL_CASTS,
Allow,
}
declare_lint! {
- pub INACCESSIBLE_EXTERN_CRATE,
- Warn,
- "use of inaccessible extern crate erroneously allowed"
+ pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
+ Deny,
+ "detect public re-exports of private extern crates"
}
declare_lint! {
pub INVALID_TYPE_PARAM_DEFAULT,
- Warn,
+ Deny,
"type parameter default erroneously allowed in invalid location"
}
declare_lint! {
- pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
+ pub RENAMED_AND_REMOVED_LINTS,
+ Warn,
+ "lints that have been renamed or removed"
+}
+
+declare_lint! {
+ pub SAFE_EXTERN_STATICS,
+ Deny,
+ "safe access to extern statics was erroneously allowed"
+}
+
+declare_lint! {
+ pub SAFE_PACKED_BORROWS,
Warn,
- "floating-point constants cannot be used in patterns"
+ "safe borrows of fields of packed structs were was erroneously allowed"
}
declare_lint! {
- pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
+ pub PATTERNS_IN_FNS_WITHOUT_BODY,
Warn,
- "constants of struct or enum type can only be used in a pattern if \
- the struct or enum has `#[derive(PartialEq, Eq)]`"
+ "patterns in functions without body were erroneously allowed"
}
declare_lint! {
- pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
+ pub LEGACY_DIRECTORY_OWNERSHIP,
Deny,
- "unit struct or enum variant erroneously allowed to match via path::ident(..)"
+ "non-inline, non-`#[path]` modules (e.g. `mod foo;`) were erroneously allowed in some files \
+ not named `mod.rs`"
}
declare_lint! {
- pub RAW_POINTER_DERIVE,
+ pub LEGACY_CONSTRUCTOR_VISIBILITY,
+ Deny,
+ "detects use of struct constructors that would be invisible with new visibility rules"
+}
+
+declare_lint! {
+ pub MISSING_FRAGMENT_SPECIFIER,
+ Deny,
+ "detects missing fragment specifiers in unused `macro_rules!` patterns"
+}
+
+declare_lint! {
+ pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
+ Deny,
+ "detects parenthesized generic parameters in type and module names"
+}
+
+declare_lint! {
+ pub LATE_BOUND_LIFETIME_ARGUMENTS,
Warn,
- "uses of #[derive] with raw pointers are rarely correct"
+ "detects generic lifetime arguments in path segments with late bound lifetime parameters"
+}
+
+declare_lint! {
+ pub INCOHERENT_FUNDAMENTAL_IMPLS,
+ Deny,
+ "potentially-conflicting impls were erroneously allowed"
}
declare_lint! {
- pub TRANSMUTE_FROM_FN_ITEM_TYPES,
+ pub BAD_REPR,
Warn,
- "transmute from function item type to pointer-sized type erroneously allowed"
+ "detects incorrect use of `repr` attribute"
}
declare_lint! {
- pub HR_LIFETIME_IN_ASSOC_TYPE,
+ pub DEPRECATED,
Warn,
- "binding for associated type references higher-ranked lifetime \
- that does not appear in the trait input types"
+ "detects use of deprecated items"
}
declare_lint! {
- pub OVERLAPPING_INHERENT_IMPLS,
+ pub UNUSED_UNSAFE,
Warn,
- "two overlapping inherent impls define an item with the same name were erroneously allowed"
+ "unnecessary use of an `unsafe` block"
}
declare_lint! {
- pub RENAMED_AND_REMOVED_LINTS,
+ pub UNUSED_MUT,
Warn,
- "lints that have been renamed or removed"
+ "detect mut variables which don't need to be mutable"
+}
+
+declare_lint! {
+ pub SINGLE_USE_LIFETIMES,
+ Allow,
+ "detects lifetime parameters that are only used once"
+}
+
+declare_lint! {
+ pub UNUSED_LIFETIMES,
+ Allow,
+ "detects lifetime parameters that are never used"
+}
+
+declare_lint! {
+ pub TYVAR_BEHIND_RAW_POINTER,
+ Warn,
+ "raw pointer to an inference variable"
+}
+
+declare_lint! {
+ pub ELIDED_LIFETIMES_IN_PATHS,
+ Allow,
+ "hidden lifetime parameters are deprecated, try `Foo<'_>`"
}
declare_lint! {
- pub SUPER_OR_SELF_IN_GLOBAL_PATH,
+ pub BARE_TRAIT_OBJECTS,
+ Allow,
+ "suggest using `dyn Trait` for trait objects"
+}
+
+declare_lint! {
+ pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
+ Allow,
+ "fully qualified paths that start with a module name \
+ instead of `crate`, `self`, or an extern crate name"
+}
+
+declare_lint! {
+ pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
Warn,
- "detects super or self keywords at the beginning of global path"
+ "floating-point literals cannot be used in patterns"
}
declare_lint! {
- pub UNSIZED_IN_TUPLE,
+ pub UNSTABLE_NAME_COLLISIONS,
Warn,
- "unsized types in the interior of a tuple were erroneously allowed"
+ "detects name collision with an existing but unstable method"
+}
+
+declare_lint! {
+ pub UNUSED_LABELS,
+ Allow,
+ "detects labels that are never used"
}
declare_lint! {
- pub OBJECT_UNSAFE_FRAGMENT,
+ pub DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
Warn,
- "object-unsafe non-principal fragments in object types were erroneously allowed"
+ "warns about duplicate associated type bindings in generics"
+}
+
+declare_lint! {
+ pub DUPLICATE_MACRO_EXPORTS,
+ Deny,
+ "detects duplicate macro exports"
+}
+
+declare_lint! {
+ pub INTRA_DOC_LINK_RESOLUTION_FAILURE,
+ Warn,
+ "warn about documentation intra links resolution failure"
}
/// Does nothing as a lint pass, but registers some `Lint`s
impl LintPass for HardwiredLints {
fn get_lints(&self) -> LintArray {
lint_array!(
+ ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
+ EXCEEDING_BITSHIFTS,
UNUSED_IMPORTS,
UNUSED_EXTERN_CRATES,
UNUSED_QUALIFICATIONS,
UNUSED_ASSIGNMENTS,
DEAD_CODE,
UNREACHABLE_CODE,
+ UNREACHABLE_PATTERNS,
+ UNUSED_MACROS,
WARNINGS,
UNUSED_FEATURES,
STABLE_FEATURES,
UNKNOWN_CRATE_TYPES,
- VARIANT_SIZE_DIFFERENCES,
- FAT_PTR_TRANSMUTES,
TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS,
PRIVATE_IN_PUBLIC,
- INACCESSIBLE_EXTERN_CRATE,
+ PUB_USE_OF_PRIVATE_EXTERN_CRATE,
INVALID_TYPE_PARAM_DEFAULT,
- ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
- ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
- MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
CONST_ERR,
- RAW_POINTER_DERIVE,
- TRANSMUTE_FROM_FN_ITEM_TYPES,
- OVERLAPPING_INHERENT_IMPLS,
RENAMED_AND_REMOVED_LINTS,
- SUPER_OR_SELF_IN_GLOBAL_PATH,
- UNSIZED_IN_TUPLE,
- OBJECT_UNSAFE_FRAGMENT,
- HR_LIFETIME_IN_ASSOC_TYPE
+ SAFE_EXTERN_STATICS,
+ SAFE_PACKED_BORROWS,
+ PATTERNS_IN_FNS_WITHOUT_BODY,
+ LEGACY_DIRECTORY_OWNERSHIP,
+ LEGACY_CONSTRUCTOR_VISIBILITY,
+ MISSING_FRAGMENT_SPECIFIER,
+ PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
+ LATE_BOUND_LIFETIME_ARGUMENTS,
+ INCOHERENT_FUNDAMENTAL_IMPLS,
+ DEPRECATED,
+ UNUSED_UNSAFE,
+ UNUSED_MUT,
+ SINGLE_USE_LIFETIMES,
+ UNUSED_LIFETIMES,
+ UNUSED_LABELS,
+ TYVAR_BEHIND_RAW_POINTER,
+ ELIDED_LIFETIMES_IN_PATHS,
+ BARE_TRAIT_OBJECTS,
+ ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
+ UNSTABLE_NAME_COLLISIONS,
+ DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
+ DUPLICATE_MACRO_EXPORTS,
+ INTRA_DOC_LINK_RESOLUTION_FAILURE,
)
}
}
-impl LateLintPass for HardwiredLints {}
+// this could be a closure, but then implementing derive traits
+// becomes hacky (and it gets allocated)
+#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
+pub enum BuiltinLintDiagnostics {
+ Normal,
+ BareTraitObject(Span, /* is_global */ bool),
+ AbsPathWithModule(Span),
+ DuplicatedMacroExports(ast::Ident, Span, Span),
+}
+
+impl BuiltinLintDiagnostics {
+ pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder) {
+ match self {
+ BuiltinLintDiagnostics::Normal => (),
+ BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
+ let (sugg, app) = match sess.codemap().span_to_snippet(span) {
+ Ok(ref s) if is_global => (format!("dyn ({})", s),
+ Applicability::MachineApplicable),
+ Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
+ Err(_) => (format!("dyn <type>"), Applicability::HasPlaceholders)
+ };
+ db.span_suggestion_with_applicability(span, "use `dyn`", sugg, app);
+ }
+ BuiltinLintDiagnostics::AbsPathWithModule(span) => {
+ let (sugg, app) = match sess.codemap().span_to_snippet(span) {
+ Ok(ref s) => {
+ // FIXME(Manishearth) ideally the emitting code
+ // can tell us whether or not this is global
+ let opt_colon = if s.trim_left().starts_with("::") {
+ ""
+ } else {
+ "::"
+ };
+
+ (format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable)
+ }
+ Err(_) => (format!("crate::<path>"), Applicability::HasPlaceholders)
+ };
+ db.span_suggestion_with_applicability(span, "use `crate`", sugg, app);
+ }
+ BuiltinLintDiagnostics::DuplicatedMacroExports(ident, earlier_span, later_span) => {
+ db.span_label(later_span, format!("`{}` already exported", ident));
+ db.span_note(earlier_span, "previous macro export is now shadowed");
+ }
+ }
+ }
+}
+
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {}