Skip to content

Commit 4470d7a

Browse files
authored
Merge branch 'master' into move_links
2 parents f515d7b + d6fc34f commit 4470d7a

File tree

107 files changed

+3290
-2128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3290
-2128
lines changed

.github/deploy.sh

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ if [ -n "$TRAVIS_TAG" ]; then
3333
ln -s "$TRAVIS_TAG" out/current
3434
fi
3535

36+
# Generate version index that is shown as root index page
37+
(
38+
cp util/gh-pages/versions.html out/index.html
39+
40+
cd out
41+
python -c '\
42+
import os, json;\
43+
print json.dumps([\
44+
dir for dir in os.listdir(".")\
45+
if not dir.startswith(".") and os.path.isdir(dir)\
46+
])' > versions.json
47+
)
48+
3649
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
3750
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
3851
# Tags should deploy

.travis.yml

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ os:
88

99
sudo: false
1010

11-
cache:
12-
cargo: true
13-
directories:
14-
- target
15-
1611
env:
1712
global:
1813
# TRAVIS_TOKEN_CLIPPY_SERVICE

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.151
5+
* Update to *rustc 1.21.0-nightly (13d94d5fa 2017-08-10)*
6+
7+
## 0.0.150
8+
* Update to *rustc 1.21.0-nightly (215e0b10e 2017-08-08)*
9+
410
## 0.0.148
511
* Update to *rustc 1.21.0-nightly (37c7d0ebb 2017-07-31)*
612
* New lints: [`unreadable_literal`], [`inconsisten_digit_grouping`], [`large_digit_groups`]

CONTRIBUTING.md

+21-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ Hello fellow Rustacean! Great to see your interest in compiler internals and lin
44

55
## Getting started
66

7-
All issues on Clippy are mentored, if you want help with a bug just ask @Manishearth or @llogiq.
7+
High level approach:
8+
9+
1. Find something to fix/improve
10+
2. Change code (likely some file in `clippy_lints/src/`)
11+
3. Run `cargo test` in the root directory and wiggle code until it passes
12+
4. Open a PR (also can be done between 2. and 3. if you run into problems)
13+
14+
### Finding something to fix/improve
15+
16+
All issues on Clippy are mentored, if you want help with a bug just ask @Manishearth, @llogiq, @mcarton or @oli-obk.
817

918
Some issues are easier than others. The [E-easy](https://github.com/rust-lang-nursery/rust-clippy/labels/E-easy)
1019
label can be used to find the easy issues. If you want to work on an issue, please leave a comment
@@ -16,7 +25,8 @@ matching of the syntax tree structure, and are generally easier than
1625
and resolved paths.
1726

1827
Issues marked [E-medium](https://github.com/rust-lang-nursery/rust-clippy/labels/E-medium) are generally
19-
pretty easy too, though it's recommended you work on an E-easy issue first.
28+
pretty easy too, though it's recommended you work on an E-easy issue first. They are mostly classified
29+
as `E-medium`, since they might be somewhat involved code wise, but not difficult per-se.
2030

2131
[Llogiq's blog post on lints](https://llogiq.github.io/2015/06/04/workflows.html) is a nice primer
2232
to lint-writing, though it does get into advanced stuff. Most lints consist of an implementation of
@@ -35,16 +45,14 @@ T-middle issues can be more involved and require verifying types. The
3545
lot of methods that are useful, though one of the most useful would be `expr_ty` (gives the type of
3646
an AST expression). `match_def_path()` in Clippy's `utils` module can also be useful.
3747

48+
### Writing code
49+
3850
Compiling clippy can take almost a minute or more depending on your machine.
3951
You can set the environment flag `CARGO_INCREMENTAL=1` to cut down that time to
4052
almost a third on average, depending on the influence your change has.
4153

42-
Clippy uses UI tests. UI tests check that the output of the compiler is exactly as expected.
43-
Of course there's little sense in writing the output yourself or copying it around.
44-
Therefore you can simply run `tests/ui/update-all-references.sh` and check whether
45-
the output looks as you expect with `git diff`. Commit all `*.stderr` files, too.
54+
Please document your lint with a doc comment akin to the following:
4655

47-
Also please document your lint with a doc comment akin to the following:
4856
```rust
4957
/// **What it does:** Checks for ... (describe what the lint matches).
5058
///
@@ -58,7 +66,12 @@ Also please document your lint with a doc comment akin to the following:
5866
/// ```
5967
```
6068

61-
Our `util/update_wiki.py` script can then add your lint docs to the wiki.
69+
### Running test suite
70+
71+
Clippy uses UI tests. UI tests check that the output of the compiler is exactly as expected.
72+
Of course there's little sense in writing the output yourself or copying it around.
73+
Therefore you can simply run `tests/ui/update-all-references.sh` and check whether
74+
the output looks as you expect with `git diff`. Commit all `*.stderr` files, too.
6275

6376
## Contributions
6477

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.149"
3+
version = "0.0.151"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",
@@ -31,7 +31,7 @@ path = "src/main.rs"
3131

3232
[dependencies]
3333
# begin automatic update
34-
clippy_lints = { version = "0.0.149", path = "clippy_lints" }
34+
clippy_lints = { version = "0.0.151", path = "clippy_lints" }
3535
# end automatic update
3636
cargo_metadata = "0.2"
3737

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.0.149"
4+
version = "0.0.151"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <[email protected]>",

clippy_lints/src/approx_const.rs

+33-25
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use utils::span_lint;
77

88
/// **What it does:** Checks for floating point literals that approximate
99
/// constants which are defined in
10-
/// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
10+
/// [`std::f32::consts`](https://doc.rust-lang.
11+
/// org/stable/std/f32/consts/#constants)
1112
/// or
12-
/// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants),
13+
/// [`std::f64::consts`](https://doc.rust-lang.
14+
/// org/stable/std/f64/consts/#constants),
1315
/// respectively, suggesting to use the predefined constant.
1416
///
1517
/// **Why is this bad?** Usually, the definition in the standard library is more
@@ -33,24 +35,26 @@ declare_lint! {
3335
}
3436

3537
// Tuples are of the form (constant, name, min_digits)
36-
const KNOWN_CONSTS: &'static [(f64, &'static str, usize)] = &[(f64::E, "E", 4),
37-
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
38-
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
39-
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
40-
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
41-
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
42-
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
43-
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
44-
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
45-
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
46-
(f64::LN_10, "LN_10", 5),
47-
(f64::LN_2, "LN_2", 5),
48-
(f64::LOG10_E, "LOG10_E", 5),
49-
(f64::LOG2_E, "LOG2_E", 5),
50-
(f64::PI, "PI", 3),
51-
(f64::SQRT_2, "SQRT_2", 5)];
38+
const KNOWN_CONSTS: &'static [(f64, &'static str, usize)] = &[
39+
(f64::E, "E", 4),
40+
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
41+
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
42+
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
43+
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
44+
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
45+
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
46+
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
47+
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
48+
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
49+
(f64::LN_10, "LN_10", 5),
50+
(f64::LN_2, "LN_2", 5),
51+
(f64::LOG10_E, "LOG10_E", 5),
52+
(f64::LOG2_E, "LOG2_E", 5),
53+
(f64::PI, "PI", 3),
54+
(f64::SQRT_2, "SQRT_2", 5),
55+
];
5256

53-
#[derive(Copy,Clone)]
57+
#[derive(Copy, Clone)]
5458
pub struct Pass;
5559

5660
impl LintPass for Pass {
@@ -81,13 +85,17 @@ fn check_known_consts(cx: &LateContext, e: &Expr, s: &symbol::Symbol, module: &s
8185
if s.parse::<f64>().is_ok() {
8286
for &(constant, name, min_digits) in KNOWN_CONSTS {
8387
if is_approx_const(constant, &s, min_digits) {
84-
span_lint(cx,
85-
APPROX_CONSTANT,
86-
e.span,
87-
&format!("approximate value of `{}::consts::{}` found. \
88+
span_lint(
89+
cx,
90+
APPROX_CONSTANT,
91+
e.span,
92+
&format!(
93+
"approximate value of `{}::consts::{}` found. \
8894
Consider using it directly",
89-
module,
90-
&name));
95+
module,
96+
&name
97+
),
98+
);
9199
return;
92100
}
93101
}

clippy_lints/src/array_indexing.rs

+28-30
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use rustc::hir;
88
use syntax::ast::RangeLimits;
99
use utils::{self, higher};
1010

11-
/// **What it does:** Checks for out of bounds array indexing with a constant index.
11+
/// **What it does:** Checks for out of bounds array indexing with a constant
12+
/// index.
1213
///
1314
/// **Why is this bad?** This will always panic at runtime.
1415
///
@@ -46,7 +47,7 @@ declare_restriction_lint! {
4647
"indexing/slicing usage"
4748
}
4849

49-
#[derive(Copy,Clone)]
50+
#[derive(Copy, Clone)]
5051
pub struct ArrayIndexing;
5152

5253
impl LintPass for ArrayIndexing {
@@ -61,8 +62,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
6162
// Array with known size can be checked statically
6263
let ty = cx.tables.expr_ty(array);
6364
if let ty::TyArray(_, size) = ty.sty {
64-
let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type)
65-
.expect("array size is invalid"));
65+
let size = ConstInt::Usize(
66+
ConstUsize::new(size as u64, cx.sess().target.uint_type).expect("array size is invalid"),
67+
);
6668
let parent_item = cx.tcx.hir.get_parent(e.id);
6769
let parent_def_id = cx.tcx.hir.local_def_id(parent_item);
6870
let substs = Substs::identity_for_item(cx.tcx, parent_def_id);
@@ -80,12 +82,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
8082

8183
// Index is a constant range
8284
if let Some(range) = higher::range(index) {
83-
let start = range.start
84-
.map(|start| constcx.eval(start))
85-
.map(|v| v.ok());
86-
let end = range.end
87-
.map(|end| constcx.eval(end))
88-
.map(|v| v.ok());
85+
let start = range.start.map(|start| constcx.eval(start)).map(|v| v.ok());
86+
let end = range.end.map(|end| constcx.eval(end)).map(|v| v.ok());
8987

9088
if let Some((start, end)) = to_const_range(&start, &end, range.limits, size) {
9189
if start > size || end > size {
@@ -111,12 +109,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
111109
}
112110
}
113111

114-
/// Returns an option containing a tuple with the start and end (exclusive) of the range.
112+
/// Returns an option containing a tuple with the start and end (exclusive) of
113+
/// the range.
115114
fn to_const_range(
116115
start: &Option<Option<ConstVal>>,
117116
end: &Option<Option<ConstVal>>,
118117
limits: RangeLimits,
119-
array_size: ConstInt
118+
array_size: ConstInt,
120119
) -> Option<(ConstInt, ConstInt)> {
121120
let start = match *start {
122121
Some(Some(ConstVal::Integral(x))) => x,
@@ -128,24 +127,23 @@ fn to_const_range(
128127
Some(Some(ConstVal::Integral(x))) => {
129128
if limits == RangeLimits::Closed {
130129
match x {
131-
ConstInt::U8(_) => (x + ConstInt::U8(1)),
132-
ConstInt::U16(_) => (x + ConstInt::U16(1)),
133-
ConstInt::U32(_) => (x + ConstInt::U32(1)),
134-
ConstInt::U64(_) => (x + ConstInt::U64(1)),
135-
ConstInt::U128(_) => (x + ConstInt::U128(1)),
136-
ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))),
137-
ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))),
138-
ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))),
139-
ConstInt::I8(_) => (x + ConstInt::I8(1)),
140-
ConstInt::I16(_) => (x + ConstInt::I16(1)),
141-
ConstInt::I32(_) => (x + ConstInt::I32(1)),
142-
ConstInt::I64(_) => (x + ConstInt::I64(1)),
143-
ConstInt::I128(_) => (x + ConstInt::I128(1)),
144-
ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))),
145-
ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))),
146-
ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))),
147-
}
148-
.expect("such a big array is not realistic")
130+
ConstInt::U8(_) => (x + ConstInt::U8(1)),
131+
ConstInt::U16(_) => (x + ConstInt::U16(1)),
132+
ConstInt::U32(_) => (x + ConstInt::U32(1)),
133+
ConstInt::U64(_) => (x + ConstInt::U64(1)),
134+
ConstInt::U128(_) => (x + ConstInt::U128(1)),
135+
ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))),
136+
ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))),
137+
ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))),
138+
ConstInt::I8(_) => (x + ConstInt::I8(1)),
139+
ConstInt::I16(_) => (x + ConstInt::I16(1)),
140+
ConstInt::I32(_) => (x + ConstInt::I32(1)),
141+
ConstInt::I64(_) => (x + ConstInt::I64(1)),
142+
ConstInt::I128(_) => (x + ConstInt::I128(1)),
143+
ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))),
144+
ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))),
145+
ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))),
146+
}.expect("such a big array is not realistic")
149147
} else {
150148
x
151149
}

0 commit comments

Comments
 (0)