2015-02-19 12:04:56 -06:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
2014-06-01 18:16:00 -05:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Lints built in to rustc.
|
2014-06-06 17:49:48 -05:00
|
|
|
//!
|
|
|
|
//! This is a sibling of `lint::context` in order to ensure that
|
|
|
|
//! lints implemented here use the same public API as lint plugins.
|
|
|
|
//!
|
|
|
|
//! To add a new lint to rustc, declare it here using `declare_lint!()`.
|
|
|
|
//! Then add code to emit the new lint in the appropriate circumstances.
|
|
|
|
//! You can do that in an existing `LintPass` if it makes sense, or in
|
|
|
|
//! a new `LintPass`, or using `Session::add_lint` elsewhere in the
|
|
|
|
//! compiler. Only do the latter if the check can't be written cleanly
|
|
|
|
//! as a `LintPass`.
|
|
|
|
//!
|
|
|
|
//! If you define a new `LintPass`, you will also need to add it to the
|
2014-06-13 00:20:47 -05:00
|
|
|
//! `add_builtin!` or `add_builtin_with_new!` invocation in `context.rs`.
|
|
|
|
//! Use the former for unit-like structs and the latter for structs with
|
|
|
|
//! a `pub fn new()`.
|
2014-06-01 18:16:00 -05:00
|
|
|
|
2015-02-25 05:44:44 -06:00
|
|
|
use lint::{LintPass, LintArray};
|
2015-02-12 00:33:07 -06:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNUSED_IMPORTS,
|
|
|
|
Warn,
|
|
|
|
"imports that are never used"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNUSED_EXTERN_CRATES,
|
|
|
|
Allow,
|
|
|
|
"extern crates that are never used"
|
|
|
|
}
|
2014-09-11 12:14:43 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNUSED_QUALIFICATIONS,
|
|
|
|
Allow,
|
|
|
|
"detects unnecessarily qualified names"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNKNOWN_LINTS,
|
|
|
|
Warn,
|
|
|
|
"unrecognized lint attribute"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNUSED_VARIABLES,
|
|
|
|
Warn,
|
|
|
|
"detect variables which are not used in any way"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNUSED_ASSIGNMENTS,
|
|
|
|
Warn,
|
|
|
|
"detect assignments that will never be read"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub DEAD_CODE,
|
|
|
|
Warn,
|
|
|
|
"detect unused, unexported items"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNREACHABLE_CODE,
|
|
|
|
Warn,
|
|
|
|
"detects unreachable code paths"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub WARNINGS,
|
|
|
|
Warn,
|
|
|
|
"mass-change the level for lints which produce warnings"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
2015-01-16 12:25:16 -06:00
|
|
|
pub UNUSED_FEATURES,
|
2015-01-31 00:27:36 -06:00
|
|
|
Warn,
|
2015-01-16 12:25:16 -06:00
|
|
|
"unused or unknown features found in crate-level #[feature] directives"
|
2014-11-14 11:18:10 -06:00
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2015-02-02 22:25:42 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub STABLE_FEATURES,
|
|
|
|
Warn,
|
|
|
|
"stable features found in #[feature] directive"
|
|
|
|
}
|
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub UNKNOWN_CRATE_TYPES,
|
|
|
|
Deny,
|
|
|
|
"unknown crate type found in #[crate_type] directive"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub VARIANT_SIZE_DIFFERENCES,
|
|
|
|
Allow,
|
|
|
|
"detects enums with widely varying variant sizes"
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-11-14 11:18:10 -06:00
|
|
|
declare_lint! {
|
|
|
|
pub FAT_PTR_TRANSMUTES,
|
|
|
|
Allow,
|
|
|
|
"detects transmutes of fat pointers"
|
|
|
|
}
|
2014-08-06 04:59:40 -05:00
|
|
|
|
2014-06-04 16:35:58 -05:00
|
|
|
/// Does nothing as a lint pass, but registers some `Lint`s
|
|
|
|
/// which are used by other parts of the compiler.
|
2015-01-03 21:54:18 -06:00
|
|
|
#[derive(Copy)]
|
2014-06-04 16:35:58 -05:00
|
|
|
pub struct HardwiredLints;
|
|
|
|
|
|
|
|
impl LintPass for HardwiredLints {
|
|
|
|
fn get_lints(&self) -> LintArray {
|
|
|
|
lint_array!(
|
2014-06-18 14:35:48 -05:00
|
|
|
UNUSED_IMPORTS,
|
2014-10-14 13:37:16 -05:00
|
|
|
UNUSED_EXTERN_CRATES,
|
|
|
|
UNUSED_QUALIFICATIONS,
|
|
|
|
UNKNOWN_LINTS,
|
|
|
|
UNUSED_VARIABLES,
|
|
|
|
UNUSED_ASSIGNMENTS,
|
2014-06-18 14:35:48 -05:00
|
|
|
DEAD_CODE,
|
|
|
|
UNREACHABLE_CODE,
|
|
|
|
WARNINGS,
|
2015-01-16 12:25:16 -06:00
|
|
|
UNUSED_FEATURES,
|
2015-02-02 22:25:42 -06:00
|
|
|
STABLE_FEATURES,
|
2014-10-14 13:37:16 -05:00
|
|
|
UNKNOWN_CRATE_TYPES,
|
2014-10-14 15:36:19 -05:00
|
|
|
VARIANT_SIZE_DIFFERENCES,
|
|
|
|
FAT_PTR_TRANSMUTES
|
2014-06-18 14:35:48 -05:00
|
|
|
)
|
2014-06-04 16:35:58 -05:00
|
|
|
}
|
|
|
|
}
|