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.
|
|
|
|
|
2015-02-25 06:03:44 -06:00
|
|
|
//! Some lints that are built in to the compiler.
|
2014-06-06 17:49:48 -05:00
|
|
|
//!
|
2015-02-25 06:03:44 -06:00
|
|
|
//! These are the built-in lints that are emitted direct in the main
|
|
|
|
//! compiler code, rather than using their own custom pass. Those
|
|
|
|
//! lints are all available in `rustc_lint::builtin`.
|
2014-06-01 18:16:00 -05:00
|
|
|
|
2015-09-14 18:35:25 -05:00
|
|
|
use lint::{LintPass, LateLintPass, LintArray};
|
2015-02-12 00:33:07 -06:00
|
|
|
|
2015-10-02 03:36:45 -05:00
|
|
|
declare_lint! {
|
|
|
|
pub CONST_ERR,
|
|
|
|
Warn,
|
|
|
|
"constant evaluation detected erroneous expression"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.
Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.
[breaking change]
* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:
```
let x = 42;
let y = &x as *const u32;
```
Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:
```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-19 23:15:27 -05:00
|
|
|
declare_lint! {
|
2015-03-23 17:23:34 -05:00
|
|
|
pub TRIVIAL_CASTS,
|
2015-03-27 00:41:18 -05:00
|
|
|
Allow,
|
Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.
Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.
[breaking change]
* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:
```
let x = 42;
let y = &x as *const u32;
```
Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:
```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-19 23:15:27 -05:00
|
|
|
"detects trivial casts which could be removed"
|
|
|
|
}
|
|
|
|
|
|
|
|
declare_lint! {
|
2015-03-23 17:23:34 -05:00
|
|
|
pub TRIVIAL_NUMERIC_CASTS,
|
2015-03-27 00:41:18 -05:00
|
|
|
Allow,
|
Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.
Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.
[breaking change]
* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:
```
let x = 42;
let y = &x as *const u32;
```
Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:
```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-19 23:15:27 -05:00
|
|
|
"detects trivial casts of numeric types which could be removed"
|
|
|
|
}
|
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-03-30 08:38:44 -05:00
|
|
|
#[derive(Copy, Clone)]
|
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,
|
Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.
Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.
[breaking change]
* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:
```
let x = 42;
let y = &x as *const u32;
```
Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:
```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-19 23:15:27 -05:00
|
|
|
FAT_PTR_TRANSMUTES,
|
2015-03-23 17:23:34 -05:00
|
|
|
TRIVIAL_CASTS,
|
2015-10-02 03:36:45 -05:00
|
|
|
TRIVIAL_NUMERIC_CASTS,
|
|
|
|
CONST_ERR
|
2014-06-18 14:35:48 -05:00
|
|
|
)
|
2014-06-04 16:35:58 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-14 18:35:25 -05:00
|
|
|
|
|
|
|
impl LateLintPass for HardwiredLints {}
|