diff --git a/.travis.yml b/.travis.yml index 2664a01ea476..8fe1be2ddfaf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ script: - cargo test --features debugging - mkdir -p ~/rust/cargo/bin - cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy + - cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver - PATH=$PATH:~/rust/cargo/bin cargo clippy --all -- -D clippy - cd clippy_workspace_tests && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy && cd .. - cd clippy_workspace_tests/src && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy && cd ../.. diff --git a/CHANGELOG.md b/CHANGELOG.md index 989f9f2da787..0e3fb8be43de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.165 +* Rust upgrade to rustc 1.22.0-nightly (0e6f4cf51 2017-09-27) +* New lint: [`mut_range_bound`] + +## 0.0.164 +* Update to *rustc 1.22.0-nightly (6c476ce46 2017-09-25)* +* New lint: [`int_plus_one`] + +## 0.0.163 +* Update to *rustc 1.22.0-nightly (14039a42a 2017-09-22)* + +## 0.0.162 +* Update to *rustc 1.22.0-nightly (0701b37d9 2017-09-18)* +* New lint: [`chars_last_cmp`] +* Improved suggestions for [`needless_borrow`], [`ptr_arg`], + ## 0.0.161 * Update to *rustc 1.22.0-nightly (539f2083d 2017-09-13)* @@ -457,6 +473,7 @@ All notable changes to this project will be documented in this file. [`cast_precision_loss`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#cast_precision_loss [`cast_sign_loss`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#cast_sign_loss [`char_lit_as_u8`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#char_lit_as_u8 +[`chars_last_cmp`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#chars_last_cmp [`chars_next_cmp`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#chars_next_cmp [`clone_double_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#clone_double_ref [`clone_on_copy`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#clone_on_copy @@ -510,6 +527,7 @@ All notable changes to this project will be documented in this file. [`ineffective_bit_mask`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ineffective_bit_mask [`infinite_iter`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#infinite_iter [`inline_always`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#inline_always +[`int_plus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#int_plus_one [`integer_arithmetic`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#integer_arithmetic [`invalid_regex`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_regex [`invalid_upcast_comparisons`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons @@ -547,6 +565,7 @@ All notable changes to this project will be documented in this file. [`modulo_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#modulo_one [`mut_from_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mut_from_ref [`mut_mut`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mut_mut +[`mut_range_bound`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mut_range_bound [`mutex_atomic`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mutex_atomic [`mutex_integer`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mutex_integer [`naive_bytecount`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#naive_bytecount diff --git a/Cargo.lock b/Cargo.lock index ffc84a488eb9..1eed9fa4e954 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "clippy_lints" -version = "0.0.161" +version = "0.0.165" dependencies = [ "itertools 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -9,10 +9,11 @@ dependencies = [ "quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -28,22 +29,22 @@ name = "backtrace" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "backtrace-sys" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -61,11 +62,16 @@ name = "cargo_metadata" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cc" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cfg-if" version = "0.1.2" @@ -73,17 +79,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clippy" -version = "0.0.161" +version = "0.0.165" dependencies = [ "cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "clippy-mini-macro-test 0.1.0", - "clippy_lints 0.0.161", + "clippy_lints 0.0.165", "compiletest_rs 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "duct 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -137,16 +143,21 @@ dependencies = [ "backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "gcc" -version = "0.3.53" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "getopts" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "idna" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.6.2" @@ -157,7 +168,7 @@ dependencies = [ [[package]] name = "itoa" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -181,7 +192,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.30" +version = "0.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -199,7 +210,7 @@ name = "memchr" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -209,7 +220,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -228,6 +239,11 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "percent-encoding" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pulldown-cmark" version = "0.0.15" @@ -289,12 +305,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -317,9 +333,9 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -328,7 +344,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -364,7 +380,15 @@ name = "toml" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -385,6 +409,16 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "url" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "utf8-ranges" version = "1.0.0" @@ -408,10 +442,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" "checksum backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "99f2ce94e22b8e664d95c57fff45b98a966c2252b60691d0b7aeeccd88d70983" -"checksum backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "afccc5772ba333abccdf60d55200fa3406f8c59dcf54d5f7998c9107d3799c7c" +"checksum backtrace-sys 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "c63ea141ef8fdb10409d0f5daf30ac51f84ef43bff66f16627773d2a292cd189" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" +"checksum cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7db2f146208d7e0fbee761b09cd65a7f51ccc38705d4e7262dad4d73b12a76b1" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum compiletest_rs 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2741d378feb7a434dba54228c89a70b4e427fee521de67cdda3750b8a0265f5a" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" @@ -419,20 +454,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum duct 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e45aa15fe0a8a8f511e6d834626afd55e49b62e5c8802e18328a87e8a8f6065c" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46" -"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" "checksum getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "65922871abd2f101a2eb0eaebadc66668e54a87ad9c3dd82520b5f86ede5eff9" +"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum itertools 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22c285d60139cf413244894189ca52debcfd70b57966feed060da76802e415a0" -"checksum itoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ac17257442c2ed77dbc9fd555cf83c58b0c7f7d0e8f2ae08c0ac05c72842e1f6" +"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum lazycell 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b585b7a6811fb03aa10e74b278a0f00f8dd9b45dc681f148bb29fa5cb61859b" -"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" +"checksum libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d1419b2939a0bc44b77feb34661583c7546b532b192feab36249ab584b86856c" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487" "checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0" "checksum os_pipe 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "998bfbb3042e715190fe2a41abfa047d7e8cb81374d2977d7f100eacd8619cb1" +"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum pulldown-cmark 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "378e941dbd392c101f2cb88097fa4d7167bc421d4b88de3ff7dbee503bc3233b" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" @@ -442,8 +478,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "bcb6a7637a47663ee073391a139ed07851f27ed2532c2abc88c6bf27a16cdf34" -"checksum serde_derive 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "812ff66056fd9a9a5b7c119714243b0862cf98340e7d4b5ee05a932c40d5ea6c" +"checksum serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "6a7046c9d4c6c522d10b2d098f9bebe2bef227e0e74044d8c1bfcf6b476af799" +"checksum serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1afcaae083fd1c46952a315062326bc9957f182358eb7da03b57ef1c688f7aa9" "checksum serde_derive_internals 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd381f6d01a6616cdba8530492d453b7761b456ba974e98768a18cad2cd76f58" "checksum serde_json 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d243424e06f9f9c39e3cd36147470fd340db785825e367625f79298a6ac6b7ac" "checksum shared_child 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "099b38928dbe4a0a01fcd8c233183072f14a7d126a34bed05880869be66e14cc" @@ -451,9 +487,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" "checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" +"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +"checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/Cargo.toml b/Cargo.toml index 41ea684f327f..3d3b8abaa769 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.161" +version = "0.0.165" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -14,6 +14,7 @@ readme = "README.md" license = "MPL-2.0" keywords = ["clippy", "lint", "plugin"] categories = ["development-tools", "development-tools::cargo-plugins"] +build = "build.rs" [badges] travis-ci = { repository = "rust-lang-nursery/rust-clippy" } @@ -29,9 +30,14 @@ name = "cargo-clippy" test = false path = "src/main.rs" +[[bin]] +name = "clippy-driver" +test = false +path = "src/driver.rs" + [dependencies] # begin automatic update -clippy_lints = { version = "0.0.161", path = "clippy_lints" } +clippy_lints = { version = "0.0.165", path = "clippy_lints" } # end automatic update cargo_metadata = "0.2" diff --git a/PUBLISH.md b/PUBLISH.md index 1ff3f2b4b731..a9496d5b414d 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -7,7 +7,7 @@ Steps to publish a new clippy version - `git push` - Wait for Travis's approval. - Merge. -- `cargo publish` in `./clippy_clints`. +- `cargo publish` in `./clippy_lints`. - `cargo publish` in the root directory. - `git pull`. - `git tag -s v0.0.X -m "v0.0.X"`. diff --git a/build.rs b/build.rs new file mode 100644 index 000000000000..1c930c1b2c95 --- /dev/null +++ b/build.rs @@ -0,0 +1,8 @@ +use std::env; + +fn main() { + // Forward the profile to the main compilation + println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap()); + // Don't rebuild even if nothing changed + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index fee0391dacd6..9c78514285d4 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.161" +version = "0.0.165" # end automatic update authors = [ "Manish Goregaokar ", @@ -28,6 +28,7 @@ serde_derive = "1.0" toml = "0.4" unicode-normalization = "0.1" pulldown-cmark = "0.0.15" +url = "1.5.0" [features] debugging = [] diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index db57864cb2f0..6372221fd440 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -90,7 +90,17 @@ declare_lint! { } #[derive(Copy, Clone)] -pub struct BitMask; +pub struct BitMask { + verbose_bit_mask_threshold: u64, +} + +impl BitMask { + pub fn new(verbose_bit_mask_threshold: u64) -> Self { + Self { + verbose_bit_mask_threshold: verbose_bit_mask_threshold, + } + } +} impl LintPass for BitMask { fn get_lints(&self) -> LintArray { @@ -119,6 +129,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { let Expr_::ExprLit(ref lit1) = right.node, let LitKind::Int(0, _) = lit1.node, n.leading_zeros() == n.count_zeros(), + n > u128::from(self.verbose_bit_mask_threshold), ], { span_lint_and_then(cx, VERBOSE_BIT_MASK, @@ -307,7 +318,7 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option { cx.tcx.mir_const_qualif(def_id); cx.tcx.hir.body(cx.tcx.hir.body_owned_by(id)) } else { - cx.tcx.extern_const_body(def_id) + cx.tcx.extern_const_body(def_id).body }; fetch_int_literal(cx, &body.value) }) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 2611ba1adf2d..7e6f3c2acf11 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -298,7 +298,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { self.tcx.mir_const_qualif(def_id); self.tcx.hir.body(self.tcx.hir.body_owned_by(id)) } else { - self.tcx.extern_const_body(def_id) + self.tcx.extern_const_body(def_id).body }; let ret = cx.expr(&body.value); if ret.is_some() { diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 170ca5cf0079..3162dbc422bd 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -5,6 +5,7 @@ use syntax::ast; use syntax::codemap::{BytePos, Span}; use syntax_pos::Pos; use utils::span_lint; +use url::Url; /// **What it does:** Checks for the presence of `_`, `::` or camel-case words /// outside ticks in documentation. @@ -195,16 +196,26 @@ fn check_doc<'a, Events: Iterator)>>( use pulldown_cmark::Tag::*; let mut in_code = false; + let mut in_link = None; for (offset, event) in docs { match event { Start(CodeBlock(_)) | Start(Code) => in_code = true, End(CodeBlock(_)) | End(Code) => in_code = false, - Start(_tag) | End(_tag) => (), // We don't care about other tags + Start(Link(link, _)) => in_link = Some(link), + End(Link(_, _)) => in_link = None, + Start(_tag) | End(_tag) => (), // We don't care about other tags Html(_html) | InlineHtml(_html) => (), // HTML is weird, just ignore it SoftBreak => (), HardBreak => (), FootnoteReference(text) | Text(text) => { + if Some(&text) == in_link.as_ref() { + // Probably a link of the form `` + // Which are represented as a link to "http://example.com" with + // text "http://example.com" by pulldown-cmark + continue; + } + if !in_code { let index = match spans.binary_search_by(|c| c.0.cmp(&offset)) { Ok(o) => o, @@ -270,6 +281,18 @@ fn check_word(cx: &EarlyContext, word: &str, span: Span) { s != "_" && !s.contains("\\_") && s.contains('_') } + if let Ok(url) = Url::parse(word) { + // try to get around the fact that `foo::bar` parses as a valid URL + if !url.cannot_be_a_base() { + span_lint(cx, + DOC_MARKDOWN, + span, + "you should put bare URLs between `<`/`>` or make a proper Markdown link"); + + return; + } + } + if has_underscore(word) || word.contains("::") || is_camel_case(word) { span_lint( cx, diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index f1a450e58df3..6a6cbadb6fa3 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -1,9 +1,7 @@ use rustc::hir::*; -use rustc::hir::map::Node::NodeItem; use rustc::lint::*; use rustc::ty; use syntax::ast::LitKind; -use syntax::symbol::InternedString; use utils::paths; use utils::{is_expn_of, match_def_path, match_type, resolve_node, span_lint, walk_ptrs_ty, opt_def_id}; @@ -50,8 +48,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id)), match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1), // ensure the format string is `"{..}"` with only one argument and no text - check_static_str(cx, &args[0]), + check_static_str(&args[0]), // ensure the format argument is `{}` ie. Display with no fancy option + // and that the argument is a string check_arg_is_display(cx, &args[1]) ], { span_lint(cx, USELESS_FORMAT, span, "useless use of `format!`"); @@ -69,44 +68,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { } } -/// Returns the slice of format string parts in an `Arguments::new_v1` call. -/// Public because it's shared with a lint in print.rs. -pub fn get_argument_fmtstr_parts<'a, 'b>(cx: &LateContext<'a, 'b>, expr: &'a Expr) -> Option> { +/// Checks if the expressions matches `&[""]` +fn check_static_str(expr: &Expr) -> bool { if_let_chain! {[ - let ExprBlock(ref block) = expr.node, - block.stmts.len() == 1, - let StmtDecl(ref decl, _) = block.stmts[0].node, - let DeclItem(ref decl) = decl.node, - let Some(NodeItem(decl)) = cx.tcx.hir.find(decl.id), - decl.name == "__STATIC_FMTSTR", - let ItemStatic(_, _, ref expr) = decl.node, - let ExprAddrOf(_, ref expr) = cx.tcx.hir.body(*expr).value.node, // &["…", "…", …] - let ExprArray(ref exprs) = expr.node, + let ExprAddrOf(_, ref expr) = expr.node, // &[""] + let ExprArray(ref exprs) = expr.node, // [""] + exprs.len() == 1, + let ExprLit(ref lit) = exprs[0].node, + let LitKind::Str(ref lit, _) = lit.node, ], { - let mut result = Vec::new(); - for expr in exprs { - if let ExprLit(ref lit) = expr.node { - if let LitKind::Str(ref lit, _) = lit.node { - result.push(lit.as_str()); - } - } - } - return Some(result); + return lit.as_str().is_empty(); }} - None -} -/// Checks if the expressions matches -/// ```rust, ignore -/// { static __STATIC_FMTSTR: &'static[&'static str] = &["a", "b", c]; -/// __STATIC_FMTSTR } -/// ``` -fn check_static_str(cx: &LateContext, expr: &Expr) -> bool { - if let Some(expr) = get_argument_fmtstr_parts(cx, expr) { - expr.len() == 1 && expr[0].is_empty() - } else { - false - } + false } /// Checks if the expressions matches diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs new file mode 100644 index 000000000000..d64f352d7f16 --- /dev/null +++ b/clippy_lints/src/identity_conversion.rs @@ -0,0 +1,96 @@ +use rustc::lint::*; +use rustc::hir::*; +use syntax::ast::NodeId; +use utils::{in_macro, match_def_path, match_trait_method, same_tys, snippet, span_lint_and_then}; +use utils::{opt_def_id, paths, resolve_node}; + +/// **What it does:** Checks for always-identical `Into`/`From` conversions. +/// +/// **Why is this bad?** Redundant code. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// // format!() returns a `String` +/// let s: String = format!("hello").into(); +/// ``` +declare_lint! { + pub IDENTITY_CONVERSION, + Warn, + "using always-identical `Into`/`From` conversions" +} + +#[derive(Default)] +pub struct IdentityConversion { + try_desugar_arm: Vec, +} + +impl LintPass for IdentityConversion { + fn get_lints(&self) -> LintArray { + lint_array!(IDENTITY_CONVERSION) + } +} + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + if in_macro(e.span) { + return; + } + + if Some(&e.id) == self.try_desugar_arm.last() { + return; + } + + match e.node { + ExprMatch(_, ref arms, MatchSource::TryDesugar) => { + let e = match arms[0].body.node { + ExprRet(Some(ref e)) | ExprBreak(_, Some(ref e)) => e, + _ => return, + }; + if let ExprCall(_, ref args) = e.node { + self.try_desugar_arm.push(args[0].id); + } else { + return; + } + }, + + ExprMethodCall(ref name, .., ref args) => { + if match_trait_method(cx, e, &paths::INTO[..]) && &*name.name.as_str() == "into" { + let a = cx.tables.expr_ty(e); + let b = cx.tables.expr_ty(&args[0]); + if same_tys(cx, a, b) { + let sugg = snippet(cx, args[0].span, "").into_owned(); + span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { + db.span_suggestion(e.span, "consider removing `.into()`", sugg); + }); + } + } + }, + + ExprCall(ref path, ref args) => if let ExprPath(ref qpath) = path.node { + if let Some(def_id) = opt_def_id(resolve_node(cx, qpath, path.hir_id)) { + if match_def_path(cx.tcx, def_id, &paths::FROM_FROM[..]) { + let a = cx.tables.expr_ty(e); + let b = cx.tables.expr_ty(&args[0]); + if same_tys(cx, a, b) { + let sugg = snippet(cx, args[0].span, "").into_owned(); + let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from")); + span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { + db.span_suggestion(e.span, &sugg_msg, sugg); + }); + } + } + } + }, + + _ => {}, + } + } + + fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + if Some(&e.id) == self.try_desugar_arm.last() { + self.try_desugar_arm.pop(); + } + } +} diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs new file mode 100644 index 000000000000..420427e7d0ab --- /dev/null +++ b/clippy_lints/src/int_plus_one.rs @@ -0,0 +1,143 @@ +//! lint on blocks unnecessarily using >= with a + 1 or - 1 + +use rustc::lint::*; +use syntax::ast::*; + +use utils::{span_lint_and_then, snippet_opt}; + +/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block +/// +/// +/// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// x >= y + 1 +/// ``` +/// +/// Could be written: +/// +/// ```rust +/// x > y +/// ``` +declare_lint! { + pub INT_PLUS_ONE, + Allow, + "instead of using x >= y + 1, use x > y" +} + +pub struct IntPlusOne; + +impl LintPass for IntPlusOne { + fn get_lints(&self) -> LintArray { + lint_array!(INT_PLUS_ONE) + } +} + +// cases: +// BinOpKind::Ge +// x >= y + 1 +// x - 1 >= y +// +// BinOpKind::Le +// x + 1 <= y +// x <= y - 1 + +enum Side { + LHS, + RHS, +} + +impl IntPlusOne { + #[allow(cast_sign_loss)] + fn check_lit(&self, lit: &Lit, target_value: i128) -> bool { + if let LitKind::Int(value, ..) = lit.node { + return value == (target_value as u128) + } + false + } + + fn check_binop(&self, cx: &EarlyContext, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option { + match (binop, &lhs.node, &rhs.node) { + // case where `x - 1 >= ...` or `-1 + x >= ...` + (BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => { + match (lhskind.node, &lhslhs.node, &lhsrhs.node) { + // `-1 + x` + (BinOpKind::Add, &ExprKind::Lit(ref lit), _) if self.check_lit(lit, -1) => self.generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS), + // `x - 1` + (BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if self.check_lit(lit, 1) => self.generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS), + _ => None + } + }, + // case where `... >= y + 1` or `... >= 1 + y` + (BinOpKind::Ge, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) if rhskind.node == BinOpKind::Add => { + match (&rhslhs.node, &rhsrhs.node) { + // `y + 1` and `1 + y` + (&ExprKind::Lit(ref lit), _) if self.check_lit(lit, 1) => self.generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS), + (_, &ExprKind::Lit(ref lit)) if self.check_lit(lit, 1) => self.generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS), + _ => None + } + }, + // case where `x + 1 <= ...` or `1 + x <= ...` + (BinOpKind::Le, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) if lhskind.node == BinOpKind::Add => { + match (&lhslhs.node, &lhsrhs.node) { + // `1 + x` and `x + 1` + (&ExprKind::Lit(ref lit), _) if self.check_lit(lit, 1) => self.generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS), + (_, &ExprKind::Lit(ref lit)) if self.check_lit(lit, 1) => self.generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS), + _ => None + } + }, + // case where `... >= y - 1` or `... >= -1 + y` + (BinOpKind::Le, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) => { + match (rhskind.node, &rhslhs.node, &rhsrhs.node) { + // `-1 + y` + (BinOpKind::Add, &ExprKind::Lit(ref lit), _) if self.check_lit(lit, -1) => self.generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS), + // `y - 1` + (BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if self.check_lit(lit, 1) => self.generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS), + _ => None + } + }, + _ => None + } + } + + fn generate_recommendation(&self, cx: &EarlyContext, binop: BinOpKind, node: &Expr, other_side: &Expr, side: Side) -> Option { + let binop_string = match binop { + BinOpKind::Ge => ">", + BinOpKind::Le => "<", + _ => return None + }; + if let Some(snippet) = snippet_opt(cx, node.span) { + if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) { + let rec = match side { + Side::LHS => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)), + Side::RHS => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)), + }; + return rec; + } + } + None + } + + fn emit_warning(&self, cx: &EarlyContext, block: &Expr, recommendation: String) { + span_lint_and_then(cx, + INT_PLUS_ONE, + block.span, + "Unnecessary `>= y + 1` or `x - 1 >=`", + |db| { + db.span_suggestion(block.span, "change `>= y + 1` to `> y` as shown", recommendation); + }); + } +} + +impl EarlyLintPass for IntPlusOne { + fn check_expr(&mut self, cx: &EarlyContext, item: &Expr) { + if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.node { + if let Some(ref rec) = self.check_binop(cx, kind.node, lhs, rhs) { + self.emit_warning(cx, item, rec.clone()); + } + } + } +} diff --git a/clippy_lints/src/invalid_ref.rs b/clippy_lints/src/invalid_ref.rs new file mode 100644 index 000000000000..ad3398cb0782 --- /dev/null +++ b/clippy_lints/src/invalid_ref.rs @@ -0,0 +1,55 @@ +use rustc::lint::*; +use rustc::ty; +use rustc::hir::*; +use utils::{match_def_path, paths, span_help_and_lint, opt_def_id}; + +/// **What it does:** Checks for creation of references to zeroed or uninitialized memory. +/// +/// **Why is this bad?** Creation of null references is undefined behavior. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// let bad_ref: &usize = std::mem::zeroed(); +/// ``` + +declare_lint! { + pub INVALID_REF, + Warn, + "creation of invalid reference" +} + +const ZERO_REF_SUMMARY: &str = "reference to zeroed memory"; +const UNINIT_REF_SUMMARY: &str = "reference to uninitialized memory"; +const HELP: &str = "Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html"; + +pub struct InvalidRef; + +impl LintPass for InvalidRef { + fn get_lints(&self) -> LintArray { + lint_array!(INVALID_REF) + } +} + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + if_let_chain!{[ + let ExprCall(ref path, ref args) = expr.node, + let ExprPath(ref qpath) = path.node, + args.len() == 0, + let ty::TyRef(..) = cx.tables.expr_ty(expr).sty, + let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id)), + ], { + let msg = if match_def_path(cx.tcx, def_id, &paths::MEM_ZEROED) | match_def_path(cx.tcx, def_id, &paths::INIT) { + ZERO_REF_SUMMARY + } else if match_def_path(cx.tcx, def_id, &paths::MEM_UNINIT) | match_def_path(cx.tcx, def_id, &paths::UNINIT) { + UNINIT_REF_SUMMARY + } else { + return; + }; + span_help_and_lint(cx, INVALID_REF, expr.span, msg, HELP); + }} + return; + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 520f9362c0fd..d4af88d5fede 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -51,6 +51,7 @@ extern crate lazy_static; extern crate itertools; extern crate pulldown_cmark; +extern crate url; macro_rules! declare_restriction_lint { { pub $name:tt, $description:tt } => { @@ -92,10 +93,13 @@ pub mod eval_order_dependence; pub mod format; pub mod formatting; pub mod functions; +pub mod identity_conversion; pub mod identity_op; pub mod if_let_redundant_pattern_matching; pub mod if_not_else; pub mod infinite_iter; +pub mod int_plus_one; +pub mod invalid_ref; pub mod is_unit_expr; pub mod items_after_statements; pub mod large_enum_variant; @@ -231,7 +235,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold)); reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse); reg.register_late_lint_pass(box enum_clike::UnportableVariant); - reg.register_late_lint_pass(box bit_mask::BitMask); + reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold)); reg.register_late_lint_pass(box ptr::PointerPass); reg.register_late_lint_pass(box needless_bool::NeedlessBool); reg.register_late_lint_pass(box needless_bool::BoolComparison); @@ -299,6 +303,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_early_lint_pass(box formatting::Formatting); reg.register_late_lint_pass(box swap::Swap); reg.register_early_lint_pass(box if_not_else::IfNotElse); + reg.register_early_lint_pass(box int_plus_one::IntPlusOne); reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional); reg.register_late_lint_pass(box unused_label::UnusedLabel); reg.register_late_lint_pass(box new_without_default::NewWithoutDefault); @@ -326,6 +331,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_late_lint_pass(box use_self::UseSelf); reg.register_late_lint_pass(box bytecount::ByteCount); reg.register_late_lint_pass(box infinite_iter::Pass); + reg.register_late_lint_pass(box invalid_ref::InvalidRef); + reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default()); reg.register_lint_group("clippy_restrictions", vec![ arithmetic::FLOAT_ARITHMETIC, @@ -342,6 +349,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { enum_variants::STUTTER, if_not_else::IF_NOT_ELSE, infinite_iter::MAYBE_INFINITE_ITER, + int_plus_one::INT_PLUS_ONE, + invalid_ref::INVALID_REF, items_after_statements::ITEMS_AFTER_STATEMENTS, matches::SINGLE_MATCH_ELSE, mem_forget::MEM_FORGET, @@ -424,6 +433,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { formatting::SUSPICIOUS_ELSE_FORMATTING, functions::NOT_UNSAFE_PTR_ARG_DEREF, functions::TOO_MANY_ARGUMENTS, + identity_conversion::IDENTITY_CONVERSION, identity_op::IDENTITY_OP, if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING, infinite_iter::INFINITE_ITER, @@ -446,6 +456,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { loops::FOR_LOOP_OVER_RESULT, loops::ITER_NEXT_LOOP, loops::MANUAL_MEMCPY, + loops::MUT_RANGE_BOUND, loops::NEEDLESS_RANGE_LOOP, loops::NEVER_LOOP, loops::REVERSE_RANGE_LOOP, @@ -458,6 +469,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { matches::MATCH_REF_PATS, matches::MATCH_WILD_ERR_ARM, matches::SINGLE_MATCH, + methods::CHARS_LAST_CMP, methods::CHARS_NEXT_CMP, methods::CLONE_DOUBLE_REF, methods::CLONE_ON_COPY, @@ -535,6 +547,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { transmute::TRANSMUTE_PTR_TO_REF, transmute::USELESS_TRANSMUTE, transmute::WRONG_TRANSMUTE, + transmute::TRANSMUTE_INT_TO_CHAR, + transmute::TRANSMUTE_INT_TO_BOOL, + transmute::TRANSMUTE_INT_TO_FLOAT, types::ABSURD_EXTREME_COMPARISONS, types::BORROWED_BOX, types::BOX_VEC, diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 9e7e19a8df5a..16d636c68ab6 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -104,19 +104,20 @@ fn check_fn_inner<'a, 'tcx>( for typ in &generics.ty_params { for bound in &typ.bounds { if let TraitTyParamBound(ref trait_ref, _) = *bound { - let bounds = &trait_ref + let params = &trait_ref .trait_ref .path .segments .last() .expect("a path must have at least one segment") - .parameters - .lifetimes; - for bound in bounds { - if bound.name != "'static" && !bound.is_elided() { - return; + .parameters; + if let Some(ref params) = *params { + for bound in ¶ms.lifetimes { + if bound.name.name() != "'static" && !bound.is_elided() { + return; + } + bounds_lts.push(bound); } - bounds_lts.push(bound); } } } @@ -225,7 +226,7 @@ fn allowed_lts_from(named_lts: &[LifetimeDef]) -> HashSet { let mut allowed_lts = HashSet::new(); for lt in named_lts { if lt.bounds.is_empty() { - allowed_lts.insert(RefLt::Named(lt.lifetime.name)); + allowed_lts.insert(RefLt::Named(lt.lifetime.name.name())); } } allowed_lts.insert(RefLt::Unnamed); @@ -235,8 +236,8 @@ fn allowed_lts_from(named_lts: &[LifetimeDef]) -> HashSet { fn lts_from_bounds<'a, T: Iterator>(mut vec: Vec, bounds_lts: T) -> Vec { for lt in bounds_lts { - if lt.name != "'static" { - vec.push(RefLt::Named(lt.name)); + if lt.name.name() != "'static" { + vec.push(RefLt::Named(lt.name.name())); } } @@ -266,12 +267,12 @@ impl<'v, 't> RefVisitor<'v, 't> { fn record(&mut self, lifetime: &Option) { if let Some(ref lt) = *lifetime { - if lt.name == "'static" { + if lt.name.name() == "'static" { self.lts.push(RefLt::Static); } else if lt.is_elided() { self.lts.push(RefLt::Unnamed); } else { - self.lts.push(RefLt::Named(lt.name)); + self.lts.push(RefLt::Named(lt.name.name())); } } else { self.lts.push(RefLt::Unnamed); @@ -287,23 +288,24 @@ impl<'v, 't> RefVisitor<'v, 't> { } fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) { - let last_path_segment = &last_path_segment(qpath).parameters; - if !last_path_segment.parenthesized && last_path_segment.lifetimes.is_empty() { - let hir_id = self.cx.tcx.hir.node_to_hir_id(ty.id); - match self.cx.tables.qpath_def(qpath, hir_id) { - Def::TyAlias(def_id) | Def::Struct(def_id) => { - let generics = self.cx.tcx.generics_of(def_id); - for _ in generics.regions.as_slice() { - self.record(&None); - } - }, - Def::Trait(def_id) => { - let trait_def = self.cx.tcx.trait_def(def_id); - for _ in &self.cx.tcx.generics_of(trait_def.def_id).regions { - self.record(&None); - } - }, - _ => (), + if let Some(ref last_path_segment) = last_path_segment(qpath).parameters { + if !last_path_segment.parenthesized && last_path_segment.lifetimes.is_empty() { + let hir_id = self.cx.tcx.hir.node_to_hir_id(ty.id); + match self.cx.tables.qpath_def(qpath, hir_id) { + Def::TyAlias(def_id) | Def::Struct(def_id) => { + let generics = self.cx.tcx.generics_of(def_id); + for _ in generics.regions.as_slice() { + self.record(&None); + } + }, + Def::Trait(def_id) => { + let trait_def = self.cx.tcx.trait_def(def_id); + for _ in &self.cx.tcx.generics_of(trait_def.def_id).regions { + self.record(&None); + } + }, + _ => (), + } } } } @@ -396,7 +398,7 @@ struct LifetimeChecker { impl<'tcx> Visitor<'tcx> for LifetimeChecker { // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - self.map.remove(&lifetime.name); + self.map.remove(&lifetime.name.name()); } fn visit_lifetime_def(&mut self, _: &'tcx LifetimeDef) { @@ -415,7 +417,7 @@ fn report_extra_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, func: &'tcx let hs = generics .lifetimes .iter() - .map(|lt| (lt.lifetime.name, lt.lifetime.span)) + .map(|lt| (lt.lifetime.name.name(), lt.lifetime.span)) .collect(); let mut checker = LifetimeChecker { map: hs }; @@ -434,7 +436,7 @@ struct BodyLifetimeChecker { impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - if lifetime.name != keywords::Invalid.name() && lifetime.name != "'static" { + if lifetime.name.name() != keywords::Invalid.name() && lifetime.name.name() != "'static" { self.lifetimes_used_in_body = true; } } diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 1cd539eac398..b656fed1cfbc 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -279,12 +279,19 @@ impl LiteralDigitGrouping { let fractional_part = &parts[1].chars().rev().collect::(); let _ = Self::do_lint(fractional_part) .map(|fractional_group_size| { - let consistent = Self::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), parts[1].len()); + let consistent = Self::parts_consistent(integral_group_size, + fractional_group_size, + parts[0].len(), + parts[1].len()); if !consistent { - WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(), cx, &lit.span); + WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(), + cx, + &lit.span); } }) - .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)); + .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), + cx, + &lit.span)); } }) .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)); @@ -332,7 +339,8 @@ impl LiteralDigitGrouping { .windows(2) .all(|ps| ps[1] - ps[0] == group_size + 1) // number of digits to the left of the last group cannot be bigger than group size. - && (digits.len() - underscore_positions.last().expect("there's at least one element") <= group_size + 1); + && (digits.len() - underscore_positions.last() + .expect("there's at least one element") <= group_size + 1); if !consistent { return Err(WarningType::InconsistentDigitGrouping); diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 42b31f8eaaaf..8d2a2f8fac61 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -2,16 +2,22 @@ use itertools::Itertools; use reexport::*; use rustc::hir::*; use rustc::hir::def::Def; +use rustc::hir::def_id; use rustc::hir::intravisit::{walk_block, walk_decl, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; use rustc::hir::map::Node::{NodeBlock, NodeExpr, NodeStmt}; use rustc::lint::*; use rustc::middle::const_val::ConstVal; use rustc::middle::region; +// use rustc::middle::region::CodeExtent; +use rustc::middle::expr_use_visitor::*; +use rustc::middle::mem_categorization::Categorization; +use rustc::middle::mem_categorization::cmt; use rustc::ty::{self, Ty}; use rustc::ty::subst::{Subst, Substs}; use rustc_const_eval::ConstContext; use std::collections::{HashMap, HashSet}; use syntax::ast; +use syntax::codemap::Span; use utils::sugg; use utils::const_to_u64; @@ -328,6 +334,14 @@ declare_lint! { "any loop that will always `break` or `return`" } +/// TODO: add documentation + +declare_lint! { + pub MUT_RANGE_BOUND, + Warn, + "for loop over a range where one of the bounds is a mutable variable" +} + #[derive(Copy, Clone)] pub struct Pass; @@ -348,7 +362,8 @@ impl LintPass for Pass { EMPTY_LOOP, WHILE_LET_ON_ITERATOR, FOR_KV_MAP, - NEVER_LOOP + NEVER_LOOP, + MUT_RANGE_BOUND ) } } @@ -363,7 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { match expr.node { ExprWhile(_, ref block, _) | ExprLoop(ref block, _, _) => { - if never_loop(block, &expr.id) { + if never_loop(block, expr.id) { span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"); } }, @@ -470,11 +485,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { } } -fn never_loop(block: &Block, id: &NodeId) -> bool { - !contains_continue_block(block, id) && loop_exit_block(block) +fn never_loop(block: &Block, id: NodeId) -> bool { + !contains_continue_block(block, Some(id)) && loop_exit_block(block, &mut vec![id]) } -fn contains_continue_block(block: &Block, dest: &NodeId) -> bool { +fn contains_continue_block(block: &Block, dest: Option) -> bool { block.stmts.iter().any(|e| contains_continue_stmt(e, dest)) || block.expr.as_ref().map_or( false, @@ -482,7 +497,7 @@ fn contains_continue_block(block: &Block, dest: &NodeId) -> bool { ) } -fn contains_continue_stmt(stmt: &Stmt, dest: &NodeId) -> bool { +fn contains_continue_stmt(stmt: &Stmt, dest: Option) -> bool { match stmt.node { StmtSemi(ref e, _) | StmtExpr(ref e, _) => contains_continue_expr(e, dest), @@ -490,7 +505,7 @@ fn contains_continue_stmt(stmt: &Stmt, dest: &NodeId) -> bool { } } -fn contains_continue_decl(decl: &Decl, dest: &NodeId) -> bool { +fn contains_continue_decl(decl: &Decl, dest: Option) -> bool { match decl.node { DeclLocal(ref local) => { local.init.as_ref().map_or( @@ -502,7 +517,7 @@ fn contains_continue_decl(decl: &Decl, dest: &NodeId) -> bool { } } -fn contains_continue_expr(expr: &Expr, dest: &NodeId) -> bool { +fn contains_continue_expr(expr: &Expr, dest: Option) -> bool { match expr.node { ExprRet(Some(ref e)) | ExprBox(ref e) | @@ -540,31 +555,32 @@ fn contains_continue_expr(expr: &Expr, dest: &NodeId) -> bool { |e| contains_continue_expr(e, dest), ) }, - ExprAgain(d) => d.target_id.opt_id().map_or(false, |id| id == *dest), + ExprAgain(d) => dest.map_or(true, |dest| d.target_id.opt_id().map_or(false, |id| id == dest)), _ => false, } } -fn loop_exit_block(block: &Block) -> bool { - block.stmts.iter().any(|e| loop_exit_stmt(e)) || block.expr.as_ref().map_or(false, |e| loop_exit_expr(e)) +fn loop_exit_block(block: &Block, loops: &mut Vec) -> bool { + block.stmts.iter().take_while(|s| !contains_continue_stmt(s, None)).any(|s| loop_exit_stmt(s, loops)) + || block.expr.as_ref().map_or(false, |e| loop_exit_expr(e, loops)) } -fn loop_exit_stmt(stmt: &Stmt) -> bool { +fn loop_exit_stmt(stmt: &Stmt, loops: &mut Vec) -> bool { match stmt.node { StmtSemi(ref e, _) | - StmtExpr(ref e, _) => loop_exit_expr(e), - StmtDecl(ref d, _) => loop_exit_decl(d), + StmtExpr(ref e, _) => loop_exit_expr(e, loops), + StmtDecl(ref d, _) => loop_exit_decl(d, loops), } } -fn loop_exit_decl(decl: &Decl) -> bool { +fn loop_exit_decl(decl: &Decl, loops: &mut Vec) -> bool { match decl.node { - DeclLocal(ref local) => local.init.as_ref().map_or(false, |e| loop_exit_expr(e)), + DeclLocal(ref local) => local.init.as_ref().map_or(false, |e| loop_exit_expr(e, loops)), _ => false, } } -fn loop_exit_expr(expr: &Expr) -> bool { +fn loop_exit_expr(expr: &Expr, loops: &mut Vec) -> bool { match expr.node { ExprBox(ref e) | ExprUnary(_, ref e) | @@ -573,22 +589,34 @@ fn loop_exit_expr(expr: &Expr) -> bool { ExprField(ref e, _) | ExprTupField(ref e, _) | ExprAddrOf(_, ref e) | - ExprRepeat(ref e, _) => loop_exit_expr(e), + ExprRepeat(ref e, _) => loop_exit_expr(e, loops), ExprArray(ref es) | ExprMethodCall(_, _, ref es) | - ExprTup(ref es) => es.iter().any(|e| loop_exit_expr(e)), - ExprCall(ref e, ref es) => loop_exit_expr(e) || es.iter().any(|e| loop_exit_expr(e)), + ExprTup(ref es) => es.iter().any(|e| loop_exit_expr(e, loops)), + ExprCall(ref e, ref es) => loop_exit_expr(e, loops) || es.iter().any(|e| loop_exit_expr(e, loops)), ExprBinary(_, ref e1, ref e2) | ExprAssign(ref e1, ref e2) | ExprAssignOp(_, ref e1, ref e2) | - ExprIndex(ref e1, ref e2) => [e1, e2].iter().any(|e| loop_exit_expr(e)), - ExprIf(ref e, ref e2, ref e3) => { - loop_exit_expr(e) || e3.as_ref().map_or(false, |e| loop_exit_expr(e)) && loop_exit_expr(e2) + ExprIndex(ref e1, ref e2) => [e1, e2].iter().any(|e| loop_exit_expr(e, loops)), + ExprIf(ref e, ref e2, ref e3) => loop_exit_expr(e, loops) + || e3.as_ref().map_or(false, |e3| loop_exit_expr(e3, loops)) && loop_exit_expr(e2, loops), + ExprLoop(ref b, _, _) => { + loops.push(expr.id); + let val = loop_exit_block(b, loops); + loops.pop(); + val }, - ExprWhile(ref e, ref b, _) => loop_exit_expr(e) || loop_exit_block(b), - ExprMatch(ref e, ref arms, _) => loop_exit_expr(e) || arms.iter().all(|a| loop_exit_expr(&a.body)), - ExprBlock(ref b) => loop_exit_block(b), - ExprBreak(_, _) | ExprAgain(_) | ExprRet(_) => true, + ExprWhile(ref e, ref b, _) => { + loops.push(expr.id); + let val = loop_exit_expr(e, loops) || loop_exit_block(b, loops); + loops.pop(); + val + }, + ExprMatch(ref e, ref arms, _) => loop_exit_expr(e, loops) || arms.iter().all(|a| loop_exit_expr(&a.body, loops)), + ExprBlock(ref b) => loop_exit_block(b, loops), + ExprAgain(d) => d.target_id.opt_id().map_or(false, |id| loops.iter().skip(1).all(|&id2| id != id2)), + ExprBreak(d, _) => d.target_id.opt_id().map_or(false, |id| loops[0] == id), + ExprRet(_) => true, _ => false, } } @@ -605,6 +633,7 @@ fn check_for_loop<'a, 'tcx>( check_for_loop_arg(cx, pat, arg, expr); check_for_loop_explicit_counter(cx, arg, body, expr); check_for_loop_over_map_kv(cx, pat, arg, body, expr); + check_for_mut_range_bound(cx, arg, body); detect_manual_memcpy(cx, pat, arg, body, expr); } @@ -1294,6 +1323,102 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( } } +struct MutateDelegate { + node_id_low: Option, + node_id_high: Option, + span_low: Option, + span_high: Option, +} + +impl<'tcx> Delegate<'tcx> for MutateDelegate { + fn consume(&mut self, _: NodeId, _: Span, _: cmt<'tcx>, _: ConsumeMode) { + } + + fn matched_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: MatchMode) { + } + + fn consume_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: ConsumeMode) { + } + + fn borrow(&mut self, _: NodeId, sp: Span, cmt: cmt<'tcx>, _: ty::Region, bk: ty::BorrowKind, _: LoanCause) { + if let ty::BorrowKind::MutBorrow = bk { + if let Categorization::Local(id) = cmt.cat { + if Some(id) == self.node_id_low { + self.span_low = Some(sp) + } + if Some(id) == self.node_id_high { + self.span_high = Some(sp) + } + } + } + } + + fn mutate(&mut self, _: NodeId, sp: Span, cmt: cmt<'tcx>, _: MutateMode) { + if let Categorization::Local(id) = cmt.cat { + if Some(id) == self.node_id_low { + self.span_low = Some(sp) + } + if Some(id) == self.node_id_high { + self.span_high = Some(sp) + } + } + } + + fn decl_without_init(&mut self, _: NodeId, _: Span) { + } +} + +impl<'tcx> MutateDelegate { + fn mutation_span(&self) -> (Option, Option) { + (self.span_low, self.span_high) + } +} + +fn check_for_mut_range_bound(cx: &LateContext, arg: &Expr, body: &Expr) { + if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(arg) { + let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)]; + if mut_ids[0].is_some() || mut_ids[1].is_some() { + let (span_low, span_high) = check_for_mutation(cx, body, &mut_ids); + mut_warn_with_span(cx, span_low); + mut_warn_with_span(cx, span_high); + } + } +} + +fn mut_warn_with_span(cx: &LateContext, span: Option) { + if let Some(sp) = span { + span_lint(cx, MUT_RANGE_BOUND, sp, "attempt to mutate range bound within loop; note that the range of the loop is unchanged"); + } +} + +fn check_for_mutability(cx: &LateContext, bound: &Expr) -> Option { + if_let_chain! {[ + let ExprPath(ref qpath) = bound.node, + let QPath::Resolved(None, _) = *qpath, + ], { + let def = cx.tables.qpath_def(qpath, bound.hir_id); + if let Def::Local(node_id) = def { + let node_str = cx.tcx.hir.get(node_id); + if_let_chain! {[ + let map::Node::NodeBinding(pat) = node_str, + let PatKind::Binding(bind_ann, _, _, _) = pat.node, + let BindingAnnotation::Mutable = bind_ann, + ], { + return Some(node_id); + }} + } + }} + None +} + +fn check_for_mutation(cx: &LateContext, body: &Expr, bound_ids: &[Option]) -> (Option, Option) { + let mut delegate = MutateDelegate { node_id_low: bound_ids[0], node_id_high: bound_ids[1], span_low: None, span_high: None }; + let def_id = def_id::DefId::local(body.hir_id.owner); + let region_scope_tree = &cx.tcx.region_scope_tree(def_id); + ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables).walk_expr(body); + delegate.mutation_span() +} + /// Return true if the pattern is a `PatWild` or an ident prefixed with `'_'`. fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool { match *pat { @@ -1492,7 +1617,7 @@ fn is_ref_iterable_type(cx: &LateContext, e: &Expr) -> bool { fn is_iterable_array(ty: Ty) -> bool { // IntoIterator is currently only implemented for array sizes <= 32 in rustc match ty.sty { - ty::TyArray(_, n) => (0...32).contains(const_to_u64(n)), + ty::TyArray(_, n) => (0..=32).contains(const_to_u64(n)), _ => false, } } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 733022f1703f..e35e1ab477c0 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -100,7 +100,8 @@ fn expr_eq_name(expr: &Expr, id: ast::Name) -> bool { let arg_segment = [ PathSegment { name: id, - parameters: PathParameters::none(), + parameters: None, + infer_types: true, }, ]; !path.is_global() && path.segments[..] == arg_segment diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index b36e1851d0de..6d3a3f39d1a2 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1617,11 +1617,18 @@ fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Gener match_path(path, name) && path.segments .last() - .map_or(false, |s| if s.parameters.parenthesized { - false - } else { - s.parameters.types.len() == 1 && - (is_self_ty(&s.parameters.types[0]) || is_ty(&*s.parameters.types[0], self_ty)) + .map_or(false, |s| { + if let Some(ref params) = s.parameters { + if params.parenthesized { + false + } else { + params.types.len() == 1 && + (is_self_ty(¶ms.types[0]) + || is_ty(&*params.types[0], self_ty)) + } + } else { + false + } }) } else { false diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 81a8b4ffb2e4..2ad6c36ab5f0 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -15,16 +15,7 @@ // *rustc*'s // [`missing_doc`]. // -// [`missing_doc`]: -// https://github. -// com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/builtin. -// -// -// -// -// -// -// rs#L246 +// [`missing_doc`]: https://github.com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/builtin.rs#L246 // use rustc::hir; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 4a7a042924a2..ccdb3c179cc1 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -144,7 +144,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let TyPath(QPath::Resolved(_, ref path)) = input.node, let Some(elem_ty) = path.segments.iter() .find(|seg| seg.name == "Vec") - .map(|ps| &ps.parameters.types[0]), + .and_then(|ps| ps.parameters.as_ref()) + .map(|params| ¶ms.types[0]), ], { let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_")); db.span_suggestion(input.span, diff --git a/clippy_lints/src/print.rs b/clippy_lints/src/print.rs index 1f24a7af0526..96557b8b0cb4 100644 --- a/clippy_lints/src/print.rs +++ b/clippy_lints/src/print.rs @@ -1,9 +1,10 @@ use rustc::hir::*; use rustc::hir::map::Node::{NodeImplItem, NodeItem}; use rustc::lint::*; -use utils::{paths, opt_def_id}; +use syntax::ast::LitKind; +use syntax::symbol::InternedString; use utils::{is_expn_of, match_def_path, match_path, resolve_node, span_lint}; -use format::get_argument_fmtstr_parts; +use utils::{paths, opt_def_id}; /// **What it does:** This lint warns when you using `print!()` with a format /// string that @@ -103,15 +104,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let ExprTup(ref args) = args.node, // collect the format string parts and check the last one - let Some(fmtstrs) = get_argument_fmtstr_parts(cx, &args_args[0]), - let Some(last_str) = fmtstrs.last(), - let Some('\n') = last_str.chars().last(), + let Some((fmtstr, fmtlen)) = get_argument_fmtstr_parts(&args_args[0]), + let Some('\n') = fmtstr.chars().last(), // "foo{}bar" is made into two strings + one argument, // if the format string starts with `{}` (eg. "{}foo"), // the string array is prepended an empty string "". // We only want to check the last string after any `{}`: - args.len() < fmtstrs.len(), + args.len() < fmtlen, ], { span_lint(cx, PRINT_WITH_NEWLINE, span, "using `print!()` with a format string that ends in a \ @@ -124,7 +124,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { else if args.len() == 2 && match_def_path(cx.tcx, fun_id, &paths::FMT_ARGUMENTV1_NEW) { if let ExprPath(ref qpath) = args[1].node { if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, args[1].hir_id)) { - if match_def_path(cx.tcx, def_id, &paths::DEBUG_FMT_METHOD) && !is_in_debug_impl(cx, expr) && is_expn_of(expr.span, "panic").is_none() { + if match_def_path(cx.tcx, def_id, &paths::DEBUG_FMT_METHOD) + && !is_in_debug_impl(cx, expr) && is_expn_of(expr.span, "panic").is_none() { span_lint(cx, USE_DEBUG, args[0].span, "use of `Debug`-based formatting"); } } @@ -149,3 +150,17 @@ fn is_in_debug_impl(cx: &LateContext, expr: &Expr) -> bool { false } + +/// Returns the slice of format string parts in an `Arguments::new_v1` call. +fn get_argument_fmtstr_parts(expr: &Expr) -> Option<(InternedString, usize)> { + if_let_chain! {[ + let ExprAddrOf(_, ref expr) = expr.node, // &["…", "…", …] + let ExprArray(ref exprs) = expr.node, + let Some(expr) = exprs.last(), + let ExprLit(ref lit) = expr.node, + let LitKind::Str(ref lit, _) = lit.node, + ], { + return Some((lit.as_str(), exprs.len())); + }} + None +} diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index cbba4ad26108..03c94cbf3fbd 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -1,5 +1,6 @@ //! Checks for usage of `&Vec[_]` and `&String`. +use std::borrow::Cow; use rustc::hir::*; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::map::NodeItem; @@ -158,49 +159,53 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option< let mut ty_snippet = None; if_let_chain!([ let TyPath(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).node, - let Some(&PathSegment{ref parameters, ..}) = path.segments.last(), + let Some(&PathSegment{parameters: Some(ref parameters), ..}) = path.segments.last(), parameters.types.len() == 1, ], { ty_snippet = snippet_opt(cx, parameters.types[0].span); }); - let spans = get_spans(cx, opt_body_id, idx, "to_owned"); - span_lint_and_then( - cx, - PTR_ARG, - arg.span, - "writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used \ - with non-Vec-based slices.", - |db| { - if let Some(ref snippet) = ty_snippet { + if let Ok(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_owned()")]) { + span_lint_and_then( + cx, + PTR_ARG, + arg.span, + "writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used \ + with non-Vec-based slices.", + |db| { + if let Some(ref snippet) = ty_snippet { + db.span_suggestion(arg.span, + "change this to", + format!("&[{}]", snippet)); + } + for (clonespan, suggestion) in spans { + db.span_suggestion(clonespan, + &snippet_opt(cx, clonespan).map_or("change the call to".into(), + |x| Cow::Owned(format!("change `{}` to", x))), + suggestion.into()); + } + } + ); + } + } else if match_type(cx, ty, &paths::STRING) { + if let Ok(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) { + span_lint_and_then( + cx, + PTR_ARG, + arg.span, + "writing `&String` instead of `&str` involves a new object where a slice will do.", + |db| { db.span_suggestion(arg.span, "change this to", - format!("&[{}]", snippet)); + "&str".into()); + for (clonespan, suggestion) in spans { + db.span_suggestion_short(clonespan, + &snippet_opt(cx, clonespan).map_or("change the call to".into(), + |x| Cow::Owned(format!("change `{}` to", x))), + suggestion.into()); + } } - for (clonespan, suggestion) in spans { - db.span_suggestion(clonespan, - "change the `.clone()` to", - suggestion); - } - } - ); - } else if match_type(cx, ty, &paths::STRING) { - let spans = get_spans(cx, opt_body_id, idx, "to_string"); - span_lint_and_then( - cx, - PTR_ARG, - arg.span, - "writing `&String` instead of `&str` involves a new object where a slice will do.", - |db| { - db.span_suggestion(arg.span, - "change this to", - "&str".into()); - for (clonespan, suggestion) in spans { - db.span_suggestion_short(clonespan, - "change the `.clone` to ", - suggestion); - } - } - ); + ); + } } } } @@ -229,38 +234,50 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option< } } -fn get_spans(cx: &LateContext, opt_body_id: Option, idx: usize, fn_name: &'static str) -> Vec<(Span, String)> { +fn get_spans(cx: &LateContext, opt_body_id: Option, idx: usize, replacements: &'static [(&'static str, &'static str)]) -> Result)>, ()> { if let Some(body) = opt_body_id.map(|id| cx.tcx.hir.body(id)) { - get_binding_name(&body.arguments[idx]).map_or_else(Vec::new, - |name| extract_clone_suggestions(cx, name, fn_name, body)) + get_binding_name(&body.arguments[idx]).map_or_else(|| Ok(vec![]), + |name| extract_clone_suggestions(cx, name, replacements, body)) } else { - vec![] + Ok(vec![]) } } -fn extract_clone_suggestions<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, name: Name, fn_name: &'static str, body: &'tcx Body) -> Vec<(Span, String)> { +fn extract_clone_suggestions<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, name: Name, replace: &'static [(&'static str, &'static str)], body: &'tcx Body) -> Result)>, ()> { let mut visitor = PtrCloneVisitor { cx, name, - fn_name, - spans: vec![] + replace, + spans: vec![], + abort: false, }; visitor.visit_body(body); - visitor.spans + if visitor.abort { Err(()) } else { Ok(visitor.spans) } } struct PtrCloneVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, name: Name, - fn_name: &'static str, - spans: Vec<(Span, String)>, + replace: &'static [(&'static str, &'static str)], + spans: Vec<(Span, Cow<'static, str>)>, + abort: bool, } impl<'a, 'tcx: 'a> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr) { + if self.abort { return; } if let ExprMethodCall(ref seg, _, ref args) = expr.node { - if args.len() == 1 && match_var(&args[0], self.name) && seg.name == "clone" { - self.spans.push((expr.span, format!("{}.{}()", snippet(self.cx, args[0].span, "_"), self.fn_name))); + if args.len() == 1 && match_var(&args[0], self.name) { + if seg.name == "capacity" { + self.abort = true; + return; + } + for &(fn_name, suffix) in self.replace { + if seg.name == fn_name { + self.spans.push((expr.span, snippet(self.cx, args[0].span, "_") + suffix)); + return; + } + } } return; } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 18b80c76810c..a97c24166b48 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -1,6 +1,8 @@ use rustc::lint::*; use rustc::ty::{self, Ty}; use rustc::hir::*; +use std::borrow::Cow; +use syntax::ast; use utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then}; use utils::{sugg, opt_def_id}; @@ -76,11 +78,73 @@ declare_lint! { "transmutes from a pointer to a reference type" } +/// **What it does:** Checks for transmutes from an integer to a `char`. +/// +/// **Why is this bad?** Not every integer is a unicode scalar value. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// let _: char = std::mem::transmute(x); // where x: u32 +/// // should be: +/// let _: Option = std::char::from_u32(x); +/// ``` +declare_lint! { + pub TRANSMUTE_INT_TO_CHAR, + Warn, + "transmutes from an integer to a `char`" +} + +/// **What it does:** Checks for transmutes from an integer to a `bool`. +/// +/// **Why is this bad?** This might result in an invalid in-memory representation of a `bool`. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// let _: bool = std::mem::transmute(x); // where x: u8 +/// // should be: +/// let _: bool = x != 0; +/// ``` +declare_lint! { + pub TRANSMUTE_INT_TO_BOOL, + Warn, + "transmutes from an integer to a `bool`" +} + +/// **What it does:** Checks for transmutes from an integer to a float. +/// +/// **Why is this bad?** This might result in an invalid in-memory representation of a float. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// let _: f32 = std::mem::transmute(x); // where x: u32 +/// // should be: +/// let _: f32 = f32::from_bits(x); +/// ``` +declare_lint! { + pub TRANSMUTE_INT_TO_FLOAT, + Warn, + "transmutes from an integer to a float" +} + pub struct Transmute; impl LintPass for Transmute { fn get_lints(&self) -> LintArray { - lint_array!(CROSSPOINTER_TRANSMUTE, TRANSMUTE_PTR_TO_REF, USELESS_TRANSMUTE, WRONG_TRANSMUTE) + lint_array!( + CROSSPOINTER_TRANSMUTE, + TRANSMUTE_PTR_TO_REF, + USELESS_TRANSMUTE, + WRONG_TRANSMUTE, + TRANSMUTE_INT_TO_CHAR, + TRANSMUTE_INT_TO_BOOL, + TRANSMUTE_INT_TO_FLOAT + ) } } @@ -177,6 +241,50 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string()); }, ), + (&ty::TyInt(ast::IntTy::I32), &ty::TyChar) | + (&ty::TyUint(ast::UintTy::U32), &ty::TyChar) => span_lint_and_then( + cx, + TRANSMUTE_INT_TO_CHAR, + e.span, + &format!("transmute from a `{}` to a `char`", from_ty), + |db| { + let arg = sugg::Sugg::hir(cx, &args[0], ".."); + let arg = if let ty::TyInt(_) = from_ty.sty { + arg.as_ty(ty::TyUint(ast::UintTy::U32)) + } else { + arg + }; + db.span_suggestion(e.span, "consider using", format!("std::char::from_u32({})", arg.to_string())); + } + ), + (&ty::TyInt(ast::IntTy::I8), &ty::TyBool) | + (&ty::TyUint(ast::UintTy::U8), &ty::TyBool) => span_lint_and_then( + cx, + TRANSMUTE_INT_TO_BOOL, + e.span, + &format!("transmute from a `{}` to a `bool`", from_ty), + |db| { + let arg = sugg::Sugg::hir(cx, &args[0], ".."); + let zero = sugg::Sugg::NonParen(Cow::from("0")); + db.span_suggestion(e.span, "consider using", sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string()); + } + ), + (&ty::TyInt(_), &ty::TyFloat(_)) | + (&ty::TyUint(_), &ty::TyFloat(_)) => span_lint_and_then( + cx, + TRANSMUTE_INT_TO_FLOAT, + e.span, + &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), + |db| { + let arg = sugg::Sugg::hir(cx, &args[0], ".."); + let arg = if let ty::TyInt(int_ty) = from_ty.sty { + arg.as_ty(format!("u{}", int_ty.bit_width().map_or_else(|| "size".to_string(), |v| v.to_string()))) + } else { + arg + }; + db.span_suggestion(e.span, "consider using", format!("{}::from_bits({})", to_ty, arg.to_string())); + } + ), _ => return, }; } @@ -194,8 +302,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: Ty) -> String { let seg = last_path_segment(path); if_let_chain!{[ - !seg.parameters.parenthesized, - let Some(to_ty) = seg.parameters.types.get(1), + let Some(ref params) = seg.parameters, + !params.parenthesized, + let Some(to_ty) = params.types.get(1), let TyRptr(_, ref to_ty) = to_ty.node, ], { return snippet(cx, to_ty.ty.span, &to_rty.to_string()).to_string(); diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 567e8b5423e1..acea709123bd 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -154,8 +154,9 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) { if Some(def_id) == cx.tcx.lang_items().owned_box() { let last = last_path_segment(qpath); if_let_chain! {[ - !last.parameters.parenthesized, - let Some(vec) = last.parameters.types.get(0), + let Some(ref params) = last.parameters, + !params.parenthesized, + let Some(vec) = params.types.get(0), let TyPath(ref qpath) = vec.node, let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, cx.tcx.hir.node_to_hir_id(vec.id))), match_def_path(cx.tcx, did, &paths::VEC), @@ -183,67 +184,32 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) { check_ty(cx, ty, is_local); for ty in p.segments .iter() - .flat_map(|seg| seg.parameters.types.iter()) + .flat_map(|seg| seg.parameters.as_ref() + .map_or_else(|| [].iter(), + |params| params.types.iter())) { check_ty(cx, ty, is_local); } }, QPath::Resolved(None, ref p) => for ty in p.segments .iter() - .flat_map(|seg| seg.parameters.types.iter()) + .flat_map(|seg| seg.parameters.as_ref() + .map_or_else(|| [].iter(), + |params| params.types.iter())) { check_ty(cx, ty, is_local); }, QPath::TypeRelative(ref ty, ref seg) => { check_ty(cx, ty, is_local); - for ty in seg.parameters.types.iter() { - check_ty(cx, ty, is_local); + if let Some(ref params) = seg.parameters { + for ty in params.types.iter() { + check_ty(cx, ty, is_local); + } } }, } }, - TyRptr(ref lt, MutTy { ref ty, ref mutbl }) => { - match ty.node { - TyPath(ref qpath) => { - let hir_id = cx.tcx.hir.node_to_hir_id(ty.id); - let def = cx.tables.qpath_def(qpath, hir_id); - if_let_chain! {[ - let Some(def_id) = opt_def_id(def), - Some(def_id) == cx.tcx.lang_items().owned_box(), - let QPath::Resolved(None, ref path) = *qpath, - let [ref bx] = *path.segments, - !bx.parameters.parenthesized, - let [ref inner] = *bx.parameters.types - ], { - if is_any_trait(inner) { - // Ignore `Box` types, see #1884 for details. - return; - } - - let ltopt = if lt.is_elided() { - "".to_owned() - } else { - format!("{} ", lt.name.as_str()) - }; - let mutopt = if *mutbl == Mutability::MutMutable { - "mut " - } else { - "" - }; - span_lint_and_sugg(cx, - BORROWED_BOX, - ast_ty.span, - "you seem to be trying to use `&Box`. Consider using just `&T`", - "try", - format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")) - ); - return; // don't recurse into the type - }}; - check_ty(cx, ty, is_local); - }, - _ => check_ty(cx, ty, is_local), - } - }, + TyRptr(ref lt, ref mut_ty) => check_ty_rptr(cx, ast_ty, is_local, lt, mut_ty), // recurse TySlice(ref ty) | TyArray(ref ty, _) | TyPtr(MutTy { ref ty, .. }) => check_ty(cx, ty, is_local), TyTup(ref tys) => for ty in tys { @@ -253,6 +219,50 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) { } } +fn check_ty_rptr(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) { + match mut_ty.ty.node { + TyPath(ref qpath) => { + let hir_id = cx.tcx.hir.node_to_hir_id(mut_ty.ty.id); + let def = cx.tables.qpath_def(qpath, hir_id); + if_let_chain! {[ + let Some(def_id) = opt_def_id(def), + Some(def_id) == cx.tcx.lang_items().owned_box(), + let QPath::Resolved(None, ref path) = *qpath, + let [ref bx] = *path.segments, + let Some(ref params) = bx.parameters, + !params.parenthesized, + let [ref inner] = *params.types + ], { + if is_any_trait(inner) { + // Ignore `Box` types, see #1884 for details. + return; + } + + let ltopt = if lt.is_elided() { + "".to_owned() + } else { + format!("{} ", lt.name.name().as_str()) + }; + let mutopt = if mut_ty.mutbl == Mutability::MutMutable { + "mut " + } else { + "" + }; + span_lint_and_sugg(cx, + BORROWED_BOX, + ast_ty.span, + "you seem to be trying to use `&Box`. Consider using just `&T`", + "try", + format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")) + ); + return; // don't recurse into the type + }}; + check_ty(cx, &mut_ty.ty, is_local); + }, + _ => check_ty(cx, &mut_ty.ty, is_local), + } +} + // Returns true if given type is `Any` trait. fn is_any_trait(t: &hir::Ty) -> bool { if_let_chain! {[ diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index bb5f6075d0da..946df625cb61 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -59,7 +59,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf { let Ty_::TyPath(QPath::Resolved(_, ref item_path)) = item_type.node, ], { let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).parameters; - if !parameters.parenthesized && parameters.lifetimes.len() == 0 { + let should_check = if let Some(ref params) = *parameters { + !params.parenthesized && params.lifetimes.len() == 0 + } else { + true + }; + if should_check { let visitor = &mut UseSelfVisitor { item_path: item_path, cx: cx, diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 7251538c09aa..68ac74d4eefb 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -82,7 +82,8 @@ macro_rules! define_Conf { #[serde(rename_all="kebab-case")] #[serde(deny_unknown_fields)] pub struct Conf { - $(#[$doc] #[serde(default=$rust_name_str)] #[serde(with=$rust_name_str)] pub $rust_name: define_Conf!(TY $($ty)+),)+ + $(#[$doc] #[serde(default=$rust_name_str)] #[serde(with=$rust_name_str)] + pub $rust_name: define_Conf!(TY $($ty)+),)+ #[allow(dead_code)] #[serde(default)] third_party: Option<::toml::Value>, @@ -91,10 +92,12 @@ macro_rules! define_Conf { mod $rust_name { use serde; use serde::Deserialize; - pub fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result { + pub fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D) + -> Result { type T = define_Conf!(TY $($ty)+); Ok(T::deserialize(deserializer).unwrap_or_else(|e| { - ::utils::conf::ERRORS.lock().expect("no threading here").push(::utils::conf::Error::Toml(e.to_string())); + ::utils::conf::ERRORS.lock().expect("no threading here") + .push(::utils::conf::Error::Toml(e.to_string())); super::$rust_name() })) } @@ -154,10 +157,10 @@ define_Conf! { "JavaScript", "NaN", "OAuth", - "OpenGL", + "OpenGL", "OpenSSH", "OpenSSL", "TrueType", "iOS", "macOS", - "TeX", "LaTeX", "BibTex", "BibLaTex", + "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", ] => Vec), /// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have @@ -172,6 +175,8 @@ define_Conf! { (enum_variant_name_threshold, "enum_variant_name_threshold", 3 => u64), /// Lint: LARGE_ENUM_VARIANT. The maximum size of a emum's variant to avoid box suggestion (enum_variant_size_threshold, "enum_variant_size_threshold", 200 => u64), + /// Lint: VERBOSE_BIT_MASK. The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros' + (verbose_bit_mask_threshold, "verbose_bit_mask_threshold", 1 => u64), } /// Search for the configuration file. diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 2d3d5874d821..f7867dfd0bd4 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -214,7 +214,14 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { fn eq_path_segment(&self, left: &PathSegment, right: &PathSegment) -> bool { // The == of idents doesn't work with different contexts, // we have to be explicit about hygiene - left.name.as_str() == right.name.as_str() && self.eq_path_parameters(&left.parameters, &right.parameters) + if left.name.as_str() != right.name.as_str() { + return false; + } + match (&left.parameters, &right.parameters) { + (&None, &None) => true, + (&Some(ref l), &Some(ref r)) => self.eq_path_parameters(l, r), + _ => false + } } fn eq_ty(&self, left: &Ty, right: &Ty) -> bool { diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index d18a5af59e3b..d517d32b64ca 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -26,10 +26,13 @@ pub const DOUBLE_ENDED_ITERATOR: [&'static str; 4] = ["core", "iter", "traits", pub const DROP: [&'static str; 3] = ["core", "mem", "drop"]; pub const FMT_ARGUMENTS_NEWV1: [&'static str; 4] = ["core", "fmt", "Arguments", "new_v1"]; pub const FMT_ARGUMENTV1_NEW: [&'static str; 4] = ["core", "fmt", "ArgumentV1", "new"]; +pub const FROM_FROM: [&'static str; 4] = ["core", "convert", "From", "from"]; pub const HASH: [&'static str; 2] = ["hash", "Hash"]; pub const HASHMAP: [&'static str; 5] = ["std", "collections", "hash", "map", "HashMap"]; pub const HASHMAP_ENTRY: [&'static str; 5] = ["std", "collections", "hash", "map", "Entry"]; pub const HASHSET: [&'static str; 5] = ["std", "collections", "hash", "set", "HashSet"]; +pub const INIT: [&'static str; 4] = ["core", "intrinsics", "", "init"]; +pub const INTO: [&'static str; 3] = ["core", "convert", "Into"]; pub const INTO_ITERATOR: [&'static str; 4] = ["core", "iter", "traits", "IntoIterator"]; pub const IO_PRINT: [&'static str; 4] = ["std", "io", "stdio", "_print"]; pub const IO_READ: [&'static str; 3] = ["std", "io", "Read"]; @@ -39,6 +42,8 @@ pub const LINKED_LIST: [&'static str; 3] = ["alloc", "linked_list", "LinkedList" pub const LINT: [&'static str; 3] = ["rustc", "lint", "Lint"]; pub const LINT_ARRAY: [&'static str; 3] = ["rustc", "lint", "LintArray"]; pub const MEM_FORGET: [&'static str; 3] = ["core", "mem", "forget"]; +pub const MEM_UNINIT: [&'static str; 3] = ["core", "mem", "uninitialized"]; +pub const MEM_ZEROED: [&'static str; 3] = ["core", "mem", "zeroed"]; pub const MUTEX: [&'static str; 4] = ["std", "sync", "mutex", "Mutex"]; pub const OPEN_OPTIONS: [&'static str; 3] = ["std", "fs", "OpenOptions"]; pub const OPS_MODULE: [&'static str; 2] = ["core", "ops"]; @@ -80,6 +85,7 @@ pub const TO_OWNED: [&'static str; 3] = ["alloc", "borrow", "ToOwned"]; pub const TO_STRING: [&'static str; 3] = ["alloc", "string", "ToString"]; pub const TRANSMUTE: [&'static str; 4] = ["core", "intrinsics", "", "transmute"]; pub const TRY_INTO_RESULT: [&'static str; 4] = ["std", "ops", "Try", "into_result"]; +pub const UNINIT: [&'static str; 4] = ["core", "intrinsics", "", "uninit"]; pub const VEC: [&'static str; 3] = ["alloc", "vec", "Vec"]; pub const VEC_DEQUE: [&'static str; 3] = ["alloc", "vec_deque", "VecDeque"]; pub const VEC_FROM_ELEM: [&'static str; 3] = ["alloc", "vec", "from_elem"]; diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index ec0a351b8b09..d811de59844f 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -126,7 +126,7 @@ impl<'a> Sugg<'a> { ast::ExprKind::While(..) | ast::ExprKind::WhileLet(..) => Sugg::NonParen(snippet), ast::ExprKind::Range(.., RangeLimits::HalfOpen) => Sugg::BinOp(AssocOp::DotDot, snippet), - ast::ExprKind::Range(.., RangeLimits::Closed) => Sugg::BinOp(AssocOp::DotDotDot, snippet), + ast::ExprKind::Range(.., RangeLimits::Closed) => Sugg::BinOp(AssocOp::DotDotEq, snippet), ast::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet), ast::ExprKind::AssignOp(op, ..) => Sugg::BinOp(astbinop2assignop(op), snippet), ast::ExprKind::Binary(op, ..) => Sugg::BinOp(AssocOp::from_ast_binop(op.node), snippet), @@ -165,7 +165,7 @@ impl<'a> Sugg<'a> { pub fn range(self, end: Self, limit: ast::RangeLimits) -> Sugg<'static> { match limit { ast::RangeLimits::HalfOpen => make_assoc(AssocOp::DotDot, &self, &end), - ast::RangeLimits::Closed => make_assoc(AssocOp::DotDotDot, &self, &end), + ast::RangeLimits::Closed => make_assoc(AssocOp::DotDotEq, &self, &end), } } @@ -312,7 +312,7 @@ pub fn make_assoc(op: AssocOp, lhs: &Sugg, rhs: &Sugg) -> Sugg<'static> { AssocOp::AssignOp(op) => format!("{} {}= {}", lhs, token_to_string(&token::BinOp(op)), rhs), AssocOp::As => format!("{} as {}", lhs, rhs), AssocOp::DotDot => format!("{}..{}", lhs, rhs), - AssocOp::DotDotDot => format!("{}...{}", lhs, rhs), + AssocOp::DotDotEq => format!("{}..={}", lhs, rhs), AssocOp::Colon => format!("{}: {}", lhs, rhs), }; @@ -362,7 +362,7 @@ fn associativity(op: &AssocOp) -> Associativity { ShiftLeft | ShiftRight | Subtract => Associativity::Left, - DotDot | DotDotDot => Associativity::None, + DotDot | DotDotEq => Associativity::None, } } diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 367235f7eeed..6044eaac3769 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -67,7 +67,7 @@ fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecA .eval(len) .is_ok() { - format!("&[{}; {}]", snippet(cx, elem.span, "elem"), snippet(cx, len.span, "len")).into() + format!("&[{}; {}]", snippet(cx, elem.span, "elem"), snippet(cx, len.span, "len")) } else { return; } @@ -75,7 +75,7 @@ fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecA higher::VecArgs::Vec(args) => if let Some(last) = args.iter().last() { let span = args[0].span.to(last.span); - format!("&[{}]", snippet(cx, span, "..")).into() + format!("&[{}]", snippet(cx, span, "..")) } else { "&[]".into() }, diff --git a/mut_range_bound b/mut_range_bound new file mode 100755 index 000000000000..fdf917d51588 Binary files /dev/null and b/mut_range_bound differ diff --git a/src/driver.rs b/src/driver.rs new file mode 100644 index 000000000000..ab5e90141a9a --- /dev/null +++ b/src/driver.rs @@ -0,0 +1,198 @@ +// error-pattern:yummy +#![feature(box_syntax)] +#![feature(rustc_private)] +#![allow(unknown_lints, missing_docs_in_private_items)] + +extern crate clippy_lints; +extern crate getopts; +extern crate rustc; +extern crate rustc_driver; +extern crate rustc_errors; +extern crate rustc_plugin; +extern crate syntax; + +use rustc_driver::{driver, Compilation, CompilerCalls, RustcDefaultCalls}; +use rustc::session::{config, CompileIncomplete, Session}; +use rustc::session::config::{ErrorOutputType, Input}; +use std::path::PathBuf; +use std::process::Command; +use syntax::ast; + +struct ClippyCompilerCalls { + default: RustcDefaultCalls, + run_lints: bool, +} + +impl ClippyCompilerCalls { + fn new(run_lints: bool) -> Self { + Self { + default: RustcDefaultCalls, + run_lints: run_lints, + } + } +} + +impl<'a> CompilerCalls<'a> for ClippyCompilerCalls { + fn early_callback( + &mut self, + matches: &getopts::Matches, + sopts: &config::Options, + cfg: &ast::CrateConfig, + descriptions: &rustc_errors::registry::Registry, + output: ErrorOutputType, + ) -> Compilation { + self.default + .early_callback(matches, sopts, cfg, descriptions, output) + } + fn no_input( + &mut self, + matches: &getopts::Matches, + sopts: &config::Options, + cfg: &ast::CrateConfig, + odir: &Option, + ofile: &Option, + descriptions: &rustc_errors::registry::Registry, + ) -> Option<(Input, Option)> { + self.default + .no_input(matches, sopts, cfg, odir, ofile, descriptions) + } + fn late_callback( + &mut self, + matches: &getopts::Matches, + sess: &Session, + crate_stores: &rustc::middle::cstore::CrateStore, + input: &Input, + odir: &Option, + ofile: &Option, + ) -> Compilation { + self.default + .late_callback(matches, sess, crate_stores, input, odir, ofile) + } + fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> driver::CompileController<'a> { + let mut control = self.default.build_controller(sess, matches); + + if self.run_lints { + let old = std::mem::replace(&mut control.after_parse.callback, box |_| {}); + control.after_parse.callback = Box::new(move |state| { + { + let mut registry = rustc_plugin::registry::Registry::new( + state.session, + state + .krate + .as_ref() + .expect( + "at this compilation stage \ + the krate must be parsed", + ) + .span, + ); + registry.args_hidden = Some(Vec::new()); + clippy_lints::register_plugins(&mut registry); + + let rustc_plugin::registry::Registry { + early_lint_passes, + late_lint_passes, + lint_groups, + llvm_passes, + attributes, + .. + } = registry; + let sess = &state.session; + let mut ls = sess.lint_store.borrow_mut(); + for pass in early_lint_passes { + ls.register_early_pass(Some(sess), true, pass); + } + for pass in late_lint_passes { + ls.register_late_pass(Some(sess), true, pass); + } + + for (name, to) in lint_groups { + ls.register_group(Some(sess), true, name, to); + } + + sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes); + sess.plugin_attributes.borrow_mut().extend(attributes); + } + old(state); + }); + } + + control + } +} + +#[allow(print_stdout)] +fn show_version() { + println!("{}", env!("CARGO_PKG_VERSION")); +} + +pub fn main() { + use std::env; + + if env::var("CLIPPY_DOGFOOD").map(|_| true).unwrap_or(false) { + panic!("yummy"); + } + + if std::env::args().any(|a| a == "--version" || a == "-V") { + show_version(); + return; + } + + let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); + let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); + let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) { + format!("{}/toolchains/{}", home, toolchain) + } else { + option_env!("SYSROOT") + .map(|s| s.to_owned()) + .or_else(|| { + Command::new("rustc") + .arg("--print") + .arg("sysroot") + .output() + .ok() + .and_then(|out| String::from_utf8(out.stdout).ok()) + .map(|s| s.trim().to_owned()) + }) + .expect( + "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust", + ) + }; + + rustc_driver::in_rustc_thread(|| { + // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. + // We're invoking the compiler programatically, so we ignore this/ + let mut orig_args: Vec = env::args().collect(); + if orig_args[1] == "rustc" { + // we still want to be able to invoke it normally though + orig_args.remove(1); + } + // this conditional check for the --sysroot flag is there so users can call + // `clippy_driver` directly + // without having to pass --sysroot or anything + let mut args: Vec = if orig_args.iter().any(|s| s == "--sysroot") { + orig_args.clone() + } else { + orig_args.clone().into_iter() + .chain(Some("--sysroot".to_owned())) + .chain(Some(sys_root)) + .collect() + }; + + // this check ensures that dependencies are built but not linted and the final + // crate is + // linted but not built + let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true") || + orig_args.iter().any(|s| s == "--emit=metadata"); + + if clippy_enabled { + args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); + } + + let mut ccc = ClippyCompilerCalls::new(clippy_enabled); + let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None); + if let Err(CompileIncomplete::Errored(_)) = result { + std::process::exit(1); + } + }).expect("rustc_thread failed"); +} diff --git a/src/main.rs b/src/main.rs index f4945998fde5..69f416e20925 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,128 +3,12 @@ #![feature(rustc_private)] #![allow(unknown_lints, missing_docs_in_private_items)] -extern crate clippy_lints; -extern crate getopts; -extern crate rustc; -extern crate rustc_driver; -extern crate rustc_errors; -extern crate rustc_plugin; -extern crate syntax; - -use rustc_driver::{driver, Compilation, CompilerCalls, RustcDefaultCalls}; -use rustc::session::{config, CompileIncomplete, Session}; -use rustc::session::config::{ErrorOutputType, Input}; use std::collections::HashMap; -use std::path::PathBuf; -use std::process::{self, Command}; -use syntax::ast; +use std::process; use std::io::{self, Write}; extern crate cargo_metadata; -struct ClippyCompilerCalls { - default: RustcDefaultCalls, - run_lints: bool, -} - -impl ClippyCompilerCalls { - fn new(run_lints: bool) -> Self { - Self { - default: RustcDefaultCalls, - run_lints: run_lints, - } - } -} - -impl<'a> CompilerCalls<'a> for ClippyCompilerCalls { - fn early_callback( - &mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - descriptions: &rustc_errors::registry::Registry, - output: ErrorOutputType, - ) -> Compilation { - self.default - .early_callback(matches, sopts, cfg, descriptions, output) - } - fn no_input( - &mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - odir: &Option, - ofile: &Option, - descriptions: &rustc_errors::registry::Registry, - ) -> Option<(Input, Option)> { - self.default - .no_input(matches, sopts, cfg, odir, ofile, descriptions) - } - fn late_callback( - &mut self, - matches: &getopts::Matches, - sess: &Session, - crate_stores: &rustc::middle::cstore::CrateStore, - input: &Input, - odir: &Option, - ofile: &Option, - ) -> Compilation { - self.default - .late_callback(matches, sess, crate_stores, input, odir, ofile) - } - fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> driver::CompileController<'a> { - let mut control = self.default.build_controller(sess, matches); - - if self.run_lints { - let old = std::mem::replace(&mut control.after_parse.callback, box |_| {}); - control.after_parse.callback = Box::new(move |state| { - { - let mut registry = rustc_plugin::registry::Registry::new( - state.session, - state - .krate - .as_ref() - .expect( - "at this compilation stage \ - the krate must be parsed", - ) - .span, - ); - registry.args_hidden = Some(Vec::new()); - clippy_lints::register_plugins(&mut registry); - - let rustc_plugin::registry::Registry { - early_lint_passes, - late_lint_passes, - lint_groups, - llvm_passes, - attributes, - .. - } = registry; - let sess = &state.session; - let mut ls = sess.lint_store.borrow_mut(); - for pass in early_lint_passes { - ls.register_early_pass(Some(sess), true, pass); - } - for pass in late_lint_passes { - ls.register_late_pass(Some(sess), true, pass); - } - - for (name, to) in lint_groups { - ls.register_group(Some(sess), true, name, to); - } - - sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes); - sess.plugin_attributes.borrow_mut().extend(attributes); - } - old(state); - }); - } - - control - } -} - use std::path::Path; const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code. @@ -181,162 +65,105 @@ pub fn main() { return; } - if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) { - // this arm is executed on the initial call to `cargo clippy` + let manifest_path_arg = std::env::args() + .skip(2) + .find(|val| val.starts_with("--manifest-path=")); - let manifest_path_arg = std::env::args() - .skip(2) - .find(|val| val.starts_with("--manifest-path=")); + let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) + { + metadata + } else { + let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n")); + process::exit(101); + }; - let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) - { - metadata - } else { - let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n")); - process::exit(101); - }; + let manifest_path = manifest_path_arg.map(|arg| { + Path::new(&arg["--manifest-path=".len()..]) + .canonicalize() + .expect("manifest path could not be canonicalized") + }); - let manifest_path = manifest_path_arg.map(|arg| { - Path::new(&arg["--manifest-path=".len()..]) - .canonicalize() - .expect("manifest path could not be canonicalized") - }); - - let packages = if std::env::args().any(|a| a == "--all") { - metadata.packages - } else { - let package_index = { - if let Some(manifest_path) = manifest_path { - metadata.packages.iter().position(|package| { - let package_manifest_path = Path::new(&package.manifest_path) - .canonicalize() - .expect("package manifest path could not be canonicalized"); - package_manifest_path == manifest_path - }) - } else { - let package_manifest_paths: HashMap<_, _> = metadata - .packages - .iter() - .enumerate() - .map(|(i, package)| { - let package_manifest_path = Path::new(&package.manifest_path) - .parent() - .expect("could not find parent directory of package manifest") - .canonicalize() - .expect("package directory cannot be canonicalized"); - (package_manifest_path, i) - }) - .collect(); - - let current_dir = std::env::current_dir() - .expect("could not read current directory") + let packages = if std::env::args().any(|a| a == "--all") { + metadata.packages + } else { + let package_index = { + if let Some(manifest_path) = manifest_path { + metadata.packages.iter().position(|package| { + let package_manifest_path = Path::new(&package.manifest_path) .canonicalize() - .expect("current directory cannot be canonicalized"); + .expect("package manifest path could not be canonicalized"); + package_manifest_path == manifest_path + }) + } else { + let package_manifest_paths: HashMap<_, _> = metadata + .packages + .iter() + .enumerate() + .map(|(i, package)| { + let package_manifest_path = Path::new(&package.manifest_path) + .parent() + .expect("could not find parent directory of package manifest") + .canonicalize() + .expect("package directory cannot be canonicalized"); + (package_manifest_path, i) + }) + .collect(); - let mut current_path: &Path = ¤t_dir; + let current_dir = std::env::current_dir() + .expect("could not read current directory") + .canonicalize() + .expect("current directory cannot be canonicalized"); - // This gets the most-recent parent (the one that takes the fewest `cd ..`s to - // reach). - loop { - if let Some(&package_index) = package_manifest_paths.get(current_path) { - break Some(package_index); - } else { - // We'll never reach the filesystem root, because to get to this point in the - // code - // the call to `cargo_metadata::metadata` must have succeeded. So it's okay to - // unwrap the current path's parent. - current_path = current_path - .parent() - .unwrap_or_else(|| panic!("could not find parent of path {}", current_path.display())); - } + let mut current_path: &Path = ¤t_dir; + + // This gets the most-recent parent (the one that takes the fewest `cd ..`s to + // reach). + loop { + if let Some(&package_index) = package_manifest_paths.get(current_path) { + break Some(package_index); + } else { + // We'll never reach the filesystem root, because to get to this point in the + // code + // the call to `cargo_metadata::metadata` must have succeeded. So it's okay to + // unwrap the current path's parent. + current_path = current_path + .parent() + .unwrap_or_else(|| panic!("could not find parent of path {}", current_path.display())); } } - }.expect("could not find matching package"); + } + }.expect("could not find matching package"); - vec![metadata.packages.remove(package_index)] - }; + vec![metadata.packages.remove(package_index)] + }; - for package in packages { - let manifest_path = package.manifest_path; + for package in packages { + let manifest_path = package.manifest_path; - for target in package.targets { - let args = std::env::args() - .skip(2) - .filter(|a| a != "--all" && !a.starts_with("--manifest-path=")); + for target in package.targets { + let args = std::env::args() + .skip(2) + .filter(|a| a != "--all" && !a.starts_with("--manifest-path=")); - let args = std::iter::once(format!("--manifest-path={}", manifest_path)).chain(args); - if let Some(first) = target.kind.get(0) { - if target.kind.len() > 1 || first.ends_with("lib") { - if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args)) { - std::process::exit(code); - } - } else if ["bin", "example", "test", "bench"].contains(&&**first) { - if let Err(code) = process( - vec![format!("--{}", first), target.name] - .into_iter() - .chain(args), - ) { - std::process::exit(code); - } + let args = std::iter::once(format!("--manifest-path={}", manifest_path)).chain(args); + if let Some(first) = target.kind.get(0) { + if target.kind.len() > 1 || first.ends_with("lib") { + if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args)) { + std::process::exit(code); + } + } else if ["bin", "example", "test", "bench"].contains(&&**first) { + if let Err(code) = process( + vec![format!("--{}", first), target.name] + .into_iter() + .chain(args), + ) { + std::process::exit(code); } - } else { - panic!("badly formatted cargo metadata: target::kind is an empty array"); } + } else { + panic!("badly formatted cargo metadata: target::kind is an empty array"); } } - } else { - // this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC` - // env var set to itself - - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) { - format!("{}/toolchains/{}", home, toolchain) - } else { - option_env!("SYSROOT") - .map(|s| s.to_owned()) - .or_else(|| { - Command::new("rustc") - .arg("--print") - .arg("sysroot") - .output() - .ok() - .and_then(|out| String::from_utf8(out.stdout).ok()) - .map(|s| s.trim().to_owned()) - }) - .expect( - "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust", - ) - }; - - rustc_driver::in_rustc_thread(|| { - // this conditional check for the --sysroot flag is there so users can call - // `cargo-clippy` directly - // without having to pass --sysroot or anything - let mut args: Vec = if env::args().any(|s| s == "--sysroot") { - env::args().collect() - } else { - env::args() - .chain(Some("--sysroot".to_owned())) - .chain(Some(sys_root)) - .collect() - }; - - // this check ensures that dependencies are built but not linted and the final - // crate is - // linted but not built - let clippy_enabled = env::args().any(|s| s == "--emit=metadata"); - - if clippy_enabled { - args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); - } - - let mut ccc = ClippyCompilerCalls::new(clippy_enabled); - let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None); - if let Err(CompileIncomplete::Errored(_)) = result { - std::process::exit(1); - } - }).expect("rustc_thread failed"); } } @@ -358,10 +185,12 @@ where args.push("--cfg".to_owned()); args.push(r#"feature="cargo-clippy""#.to_owned()); - let path = std::env::current_exe().expect("current executable path invalid"); + let path = std::env::current_exe() + .expect("current executable path invalid") + .with_file_name("clippy-driver"); let exit_status = std::process::Command::new("cargo") .args(&args) - .env("RUSTC", path) + .env("RUSTC_WRAPPER", path) .spawn() .expect("could not run cargo") .wait() diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 8fa0d440ee7b..be8793215dc2 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -3,6 +3,14 @@ extern crate compiletest_rs as compiletest; use std::path::PathBuf; use std::env::{set_var, var}; +fn clippy_driver_path() -> PathBuf { + if let Some(path) = option_env!("CLIPPY_DRIVER_PATH") { + PathBuf::from(path) + } else { + PathBuf::from(concat!("target/", env!("PROFILE"), "/clippy-driver")) + } +} + fn run_mode(dir: &'static str, mode: &'static str) { let mut config = compiletest::Config::default(); @@ -16,12 +24,15 @@ fn run_mode(dir: &'static str, mode: &'static str) { config.mode = cfg_mode; config.build_base = PathBuf::from("target/debug/test_build_base"); config.src_base = PathBuf::from(format!("tests/{}", dir)); + config.rustc_path = clippy_driver_path(); compiletest::run_tests(&config); } fn prepare_env() { set_var("CLIPPY_DISABLE_DOCS_LINKS", "true"); + set_var("CLIPPY_TESTS", "true"); + set_var("RUST_BACKTRACE", "0"); } #[test] @@ -29,8 +40,4 @@ fn compile_test() { prepare_env(); run_mode("run-pass", "run-pass"); run_mode("ui", "ui"); - #[cfg(target_os = "windows")] - run_mode("ui-windows", "ui"); - #[cfg(not(target_os = "windows"))] - run_mode("ui-posix", "ui"); } diff --git a/tests/run-pass/conf_whitelisted.rs b/tests/conf_whitelisted.rs similarity index 87% rename from tests/run-pass/conf_whitelisted.rs rename to tests/conf_whitelisted.rs index 1c82a010b3d4..198bf465bd57 100644 --- a/tests/run-pass/conf_whitelisted.rs +++ b/tests/conf_whitelisted.rs @@ -1,4 +1,3 @@ #![feature(plugin)] #![plugin(clippy(conf_file="./tests/auxiliary/conf_whitelisted.toml"))] -fn main() {} diff --git a/tests/run-pass/associated-constant-ice.rs b/tests/run-pass/associated-constant-ice.rs index 8fb55fa2272a..744de9bcf384 100644 --- a/tests/run-pass/associated-constant-ice.rs +++ b/tests/run-pass/associated-constant-ice.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + pub trait Trait { const CONSTANT: u8; diff --git a/tests/run-pass/enum-glob-import-crate.rs b/tests/run-pass/enum-glob-import-crate.rs index e08a00d26e2f..21ed2dbf9910 100644 --- a/tests/run-pass/enum-glob-import-crate.rs +++ b/tests/run-pass/enum-glob-import-crate.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![deny(clippy)] #![allow(unused_imports)] diff --git a/tests/run-pass/ice-1588.rs b/tests/run-pass/ice-1588.rs index d53d3a1cc758..780df5235115 100644 --- a/tests/run-pass/ice-1588.rs +++ b/tests/run-pass/ice-1588.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(clippy)] fn main() { diff --git a/tests/run-pass/ice-1969.rs b/tests/run-pass/ice-1969.rs index 23a002a5cdee..296339828480 100644 --- a/tests/run-pass/ice-1969.rs +++ b/tests/run-pass/ice-1969.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(clippy)] fn main() { } diff --git a/tests/run-pass/ice-700.rs b/tests/run-pass/ice-700.rs index a7ff78eac146..a1e3a6756e9e 100644 --- a/tests/run-pass/ice-700.rs +++ b/tests/run-pass/ice-700.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![deny(clippy)] fn core() {} diff --git a/tests/run-pass/mut_mut_macro.rs b/tests/run-pass/mut_mut_macro.rs index a6473b0f909e..adc308626b1b 100644 --- a/tests/run-pass/mut_mut_macro.rs +++ b/tests/run-pass/mut_mut_macro.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![deny(mut_mut, zero_ptr, cmp_nan)] #![allow(dead_code)] diff --git a/tests/run-pass/needless_lifetimes_impl_trait.rs b/tests/run-pass/needless_lifetimes_impl_trait.rs index 8edb444f936c..0ebc1bf3c6c1 100644 --- a/tests/run-pass/needless_lifetimes_impl_trait.rs +++ b/tests/run-pass/needless_lifetimes_impl_trait.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![feature(conservative_impl_trait)] #![deny(needless_lifetimes)] #![allow(dead_code)] diff --git a/tests/run-pass/procedural_macro.rs b/tests/run-pass/procedural_macro.rs index 91269726172d..b185f6dc4277 100644 --- a/tests/run-pass/procedural_macro.rs +++ b/tests/run-pass/procedural_macro.rs @@ -1,5 +1,5 @@ #![feature(plugin)] -#![plugin(clippy, clippy_mini_macro_test)] +#![plugin(clippy_mini_macro_test)] #[deny(warnings)] fn main() { diff --git a/tests/run-pass/regressions.rs b/tests/run-pass/regressions.rs index 442b01d35f80..d5e343c56c20 100644 --- a/tests/run-pass/regressions.rs +++ b/tests/run-pass/regressions.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(blacklisted_name)] pub fn foo(bar: *const u8) { diff --git a/tests/run-pass/single-match-else.rs b/tests/run-pass/single-match-else.rs index fe3cf1ce71f0..b8fa7294dcde 100644 --- a/tests/run-pass/single-match-else.rs +++ b/tests/run-pass/single-match-else.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(single_match_else)] fn main() { diff --git a/tests/ui-posix/conf_non_existant.rs b/tests/ui-posix/conf_non_existant.rs deleted file mode 100644 index e287f7e02af9..000000000000 --- a/tests/ui-posix/conf_non_existant.rs +++ /dev/null @@ -1,6 +0,0 @@ -// error-pattern: error reading Clippy's configuration file - -#![feature(plugin)] -#![plugin(clippy(conf_file="./tests/auxiliary/non_existant_conf.toml"))] - -fn main() {} diff --git a/tests/ui-posix/conf_non_existant.stderr b/tests/ui-posix/conf_non_existant.stderr deleted file mode 100644 index 7920bd35589d..000000000000 --- a/tests/ui-posix/conf_non_existant.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error: error reading Clippy's configuration file: No such file or directory (os error 2) - -error: aborting due to previous error - diff --git a/tests/ui-posix/update-all-references.sh b/tests/ui-posix/update-all-references.sh deleted file mode 100755 index d6aa69c7e8d3..000000000000 --- a/tests/ui-posix/update-all-references.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -# A script to update the references for all tests. The idea is that -# you do a run, which will generate files in the build directory -# containing the (normalized) actual output of the compiler. You then -# run this script, which will copy those files over. If you find -# yourself manually editing a foo.stderr file, you're doing it wrong. -# -# See all `update-references.sh`, if you just want to update a single test. - -if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" ]]; then - echo "usage: $0" -fi - -BUILD_DIR=$PWD/target/debug/test_build_base -MY_DIR=$(dirname $0) -cd $MY_DIR -find . -name '*.rs' | xargs ./update-references.sh $BUILD_DIR diff --git a/tests/ui-posix/update-references.sh b/tests/ui-posix/update-references.sh deleted file mode 100755 index aa99d35f7aa7..000000000000 --- a/tests/ui-posix/update-references.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -# A script to update the references for particular tests. The idea is -# that you do a run, which will generate files in the build directory -# containing the (normalized) actual output of the compiler. This -# script will then copy that output and replace the "expected output" -# files. You can then commit the changes. -# -# If you find yourself manually editing a foo.stderr file, you're -# doing it wrong. - -if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then - echo "usage: $0 " - echo "" - echo "For example:" - echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs" -fi - -MYDIR=$(dirname $0) - -BUILD_DIR="$1" -shift - -while [[ "$1" != "" ]]; do - STDERR_NAME="${1/%.rs/.stderr}" - STDOUT_NAME="${1/%.rs/.stdout}" - shift - if [ -f $BUILD_DIR/$STDOUT_NAME ] && \ - ! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then - echo updating $MYDIR/$STDOUT_NAME - cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME - fi - if [ -f $BUILD_DIR/$STDERR_NAME ] && \ - ! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then - echo updating $MYDIR/$STDERR_NAME - cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME - fi -done - - diff --git a/tests/ui-windows/conf_non_existant.rs b/tests/ui-windows/conf_non_existant.rs deleted file mode 100644 index e287f7e02af9..000000000000 --- a/tests/ui-windows/conf_non_existant.rs +++ /dev/null @@ -1,6 +0,0 @@ -// error-pattern: error reading Clippy's configuration file - -#![feature(plugin)] -#![plugin(clippy(conf_file="./tests/auxiliary/non_existant_conf.toml"))] - -fn main() {} diff --git a/tests/ui-windows/conf_non_existant.stderr b/tests/ui-windows/conf_non_existant.stderr deleted file mode 100644 index f21ae524f5ea..000000000000 --- a/tests/ui-windows/conf_non_existant.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error: error reading Clippy's configuration file: The system cannot find the file specified. (os error 2) - -error: aborting due to previous error - diff --git a/tests/ui-windows/update-all-references.sh b/tests/ui-windows/update-all-references.sh deleted file mode 100755 index d6aa69c7e8d3..000000000000 --- a/tests/ui-windows/update-all-references.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -# A script to update the references for all tests. The idea is that -# you do a run, which will generate files in the build directory -# containing the (normalized) actual output of the compiler. You then -# run this script, which will copy those files over. If you find -# yourself manually editing a foo.stderr file, you're doing it wrong. -# -# See all `update-references.sh`, if you just want to update a single test. - -if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" ]]; then - echo "usage: $0" -fi - -BUILD_DIR=$PWD/target/debug/test_build_base -MY_DIR=$(dirname $0) -cd $MY_DIR -find . -name '*.rs' | xargs ./update-references.sh $BUILD_DIR diff --git a/tests/ui-windows/update-references.sh b/tests/ui-windows/update-references.sh deleted file mode 100755 index aa99d35f7aa7..000000000000 --- a/tests/ui-windows/update-references.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -# A script to update the references for particular tests. The idea is -# that you do a run, which will generate files in the build directory -# containing the (normalized) actual output of the compiler. This -# script will then copy that output and replace the "expected output" -# files. You can then commit the changes. -# -# If you find yourself manually editing a foo.stderr file, you're -# doing it wrong. - -if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then - echo "usage: $0 " - echo "" - echo "For example:" - echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs" -fi - -MYDIR=$(dirname $0) - -BUILD_DIR="$1" -shift - -while [[ "$1" != "" ]]; do - STDERR_NAME="${1/%.rs/.stderr}" - STDOUT_NAME="${1/%.rs/.stdout}" - shift - if [ -f $BUILD_DIR/$STDOUT_NAME ] && \ - ! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then - echo updating $MYDIR/$STDOUT_NAME - cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME - fi - if [ -f $BUILD_DIR/$STDERR_NAME ] && \ - ! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then - echo updating $MYDIR/$STDERR_NAME - cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME - fi -done - - diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index ad381c6cd491..1f88d94bd2ba 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(absurd_extreme_comparisons)] #![allow(unused, eq_op, no_effect, unnecessary_operation, needless_pass_by_value)] diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index 2b1e9ad66feb..a4b8839797c3 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -143,5 +143,3 @@ error: <-comparison of unit values detected. This will always be false | = note: `-D unit-cmp` implied by `-D warnings` -error: aborting due to 18 previous errors - diff --git a/tests/ui/approx_const.rs b/tests/ui/approx_const.rs index eb66a633f9e1..f2239ecb467c 100644 --- a/tests/ui/approx_const.rs +++ b/tests/ui/approx_const.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(approx_constant)] #[allow(unused, shadow_unrelated, similar_names)] diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr index dda28433d7a9..f102dc5b5dca 100644 --- a/tests/ui/approx_const.stderr +++ b/tests/ui/approx_const.stderr @@ -114,5 +114,3 @@ error: approximate value of `f{32, 64}::consts::SQRT_2` found. Consider using it 55 | let my_sq2 = 1.4142; | ^^^^^^ -error: aborting due to 19 previous errors - diff --git a/tests/ui/arithmetic.rs b/tests/ui/arithmetic.rs index b281c239f36d..7ed71b597074 100644 --- a/tests/ui/arithmetic.rs +++ b/tests/ui/arithmetic.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(integer_arithmetic, float_arithmetic)] #![allow(unused, shadow_reuse, shadow_unrelated, no_effect, unnecessary_operation)] diff --git a/tests/ui/arithmetic.stderr b/tests/ui/arithmetic.stderr index ad4a02e21901..ea32a0052190 100644 --- a/tests/ui/arithmetic.stderr +++ b/tests/ui/arithmetic.stderr @@ -69,5 +69,3 @@ error: floating-point arithmetic detected 29 | -f; | ^^ -error: aborting due to 11 previous errors - diff --git a/tests/ui/array_indexing.rs b/tests/ui/array_indexing.rs index 34b422db6e96..faafa9a7a0d2 100644 --- a/tests/ui/array_indexing.rs +++ b/tests/ui/array_indexing.rs @@ -1,5 +1,5 @@ #![feature(inclusive_range_syntax, plugin)] -#![plugin(clippy)] + #![warn(indexing_slicing)] #![warn(out_of_bounds_indexing)] @@ -13,8 +13,8 @@ fn main() { x[1 << 3]; &x[1..5]; &x[0..3]; - &x[0...4]; - &x[...4]; + &x[0..=4]; + &x[..=4]; &x[..]; &x[1..]; &x[4..]; @@ -26,19 +26,19 @@ fn main() { y[0]; &y[1..2]; &y[..]; - &y[0...4]; - &y[...4]; + &y[0..=4]; + &y[..=4]; let empty: [i8; 0] = []; empty[0]; &empty[1..5]; - &empty[0...4]; - &empty[...4]; + &empty[0..=4]; + &empty[..=4]; &empty[..]; &empty[0..]; &empty[0..0]; - &empty[0...0]; - &empty[...0]; + &empty[0..=0]; + &empty[..=0]; &empty[..0]; &empty[1..]; &empty[..4]; diff --git a/tests/ui/array_indexing.stderr b/tests/ui/array_indexing.stderr index ea95c3254606..dd11247243c2 100644 --- a/tests/ui/array_indexing.stderr +++ b/tests/ui/array_indexing.stderr @@ -21,13 +21,13 @@ error: range is out of bounds error: range is out of bounds --> $DIR/array_indexing.rs:16:6 | -16 | &x[0...4]; +16 | &x[0..=4]; | ^^^^^^^^ error: range is out of bounds --> $DIR/array_indexing.rs:17:6 | -17 | &x[...4]; +17 | &x[..=4]; | ^^^^^^^ error: range is out of bounds @@ -59,13 +59,13 @@ error: slicing may panic error: slicing may panic --> $DIR/array_indexing.rs:29:6 | -29 | &y[0...4]; +29 | &y[0..=4]; | ^^^^^^^^ error: slicing may panic --> $DIR/array_indexing.rs:30:6 | -30 | &y[...4]; +30 | &y[..=4]; | ^^^^^^^ error: const index is out of bounds @@ -83,25 +83,25 @@ error: range is out of bounds error: range is out of bounds --> $DIR/array_indexing.rs:35:6 | -35 | &empty[0...4]; +35 | &empty[0..=4]; | ^^^^^^^^^^^^ error: range is out of bounds --> $DIR/array_indexing.rs:36:6 | -36 | &empty[...4]; +36 | &empty[..=4]; | ^^^^^^^^^^^ error: range is out of bounds --> $DIR/array_indexing.rs:40:6 | -40 | &empty[0...0]; +40 | &empty[0..=0]; | ^^^^^^^^^^^^ error: range is out of bounds --> $DIR/array_indexing.rs:41:6 | -41 | &empty[...0]; +41 | &empty[..=0]; | ^^^^^^^^^^^ error: range is out of bounds @@ -116,5 +116,3 @@ error: range is out of bounds 44 | &empty[..4]; | ^^^^^^^^^^ -error: aborting due to 19 previous errors - diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs index f92f2252114f..2b49f2146ba4 100644 --- a/tests/ui/assign_ops.rs +++ b/tests/ui/assign_ops.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(assign_ops)] #[allow(unused_assignments)] diff --git a/tests/ui/assign_ops.stderr b/tests/ui/assign_ops.stderr index 2123507e2ef6..c1cc5d24426c 100644 --- a/tests/ui/assign_ops.stderr +++ b/tests/ui/assign_ops.stderr @@ -134,5 +134,3 @@ error: manual implementation of an assign operation 40 | s = s + "bla"; | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` -error: aborting due to 22 previous errors - diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index b5de5b712ff1..8d6ef827f52d 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[allow(unused_assignments)] #[warn(misrefactored_assign_op)] diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index 0ff211259c03..47528c315d43 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -48,5 +48,3 @@ error: variable appears on both sides of an assignment operation 15 | a &= a & 1; | ^^^^^^^^^^ help: replace it with: `a &= 1` -error: aborting due to 8 previous errors - diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 1ff5edcd6307..eb27b833aded 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(inline_always, deprecated_semver)] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index f743399a6069..9e4ac3d12834 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -20,5 +20,3 @@ error: the since field must contain a semver-compliant version 30 | #[deprecated(since = "1")] | ^^^^^^^^^^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs index c211b85d7e27..4843b4eba0d4 100644 --- a/tests/ui/bit_masks.rs +++ b/tests/ui/bit_masks.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + const THREE_BITS : i64 = 7; const EVEN_MORE_REDIRECTION : i64 = THREE_BITS; diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index 4b40fa086b84..9f2c2d0a2c4a 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -6,20 +6,6 @@ error: &-masking with zero | = note: `-D bad-bit-mask` implied by `-D warnings` -error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/bit_masks.rs:12:5 - | -12 | x & 0 == 0; - | ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 0` - | - = note: `-D verbose-bit-mask` implied by `-D warnings` - -error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/bit_masks.rs:14:5 - | -14 | x & 1 == 0; //ok, compared with zero - | ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 1` - error: incompatible bit mask: `_ & 2` can never be equal to `1` --> $DIR/bit_masks.rs:15:5 | @@ -106,5 +92,3 @@ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared 55 | x | 1 >= 8; | ^^^^^^^^^^ -error: aborting due to 17 previous errors - diff --git a/tests/ui/blacklisted_name.rs b/tests/ui/blacklisted_name.rs index dabce55883b8..7baeb7bb75cb 100644 --- a/tests/ui/blacklisted_name.rs +++ b/tests/ui/blacklisted_name.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code, similar_names, single_match, toplevel_ref_arg, unused_mut, unused_variables)] #![warn(blacklisted_name)] diff --git a/tests/ui/blacklisted_name.stderr b/tests/ui/blacklisted_name.stderr index 68fbe27a01ee..a08a53268943 100644 --- a/tests/ui/blacklisted_name.stderr +++ b/tests/ui/blacklisted_name.stderr @@ -84,5 +84,3 @@ error: use of a blacklisted/placeholder name `baz` 35 | if let Some(ref mut baz) = Some(42) {} | ^^^ -error: aborting due to 14 previous errors - diff --git a/tests/ui/block_in_if_condition.rs b/tests/ui/block_in_if_condition.rs index 08e510317d92..9e65a127af28 100644 --- a/tests/ui/block_in_if_condition.rs +++ b/tests/ui/block_in_if_condition.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(block_in_if_condition_expr)] #![warn(block_in_if_condition_stmt)] diff --git a/tests/ui/block_in_if_condition.stderr b/tests/ui/block_in_if_condition.stderr index 4b7d12598ecf..86a289c19a84 100644 --- a/tests/ui/block_in_if_condition.stderr +++ b/tests/ui/block_in_if_condition.stderr @@ -50,5 +50,3 @@ error: this boolean expression can be simplified | = note: `-D nonminimal-bool` implied by `-D warnings` -error: aborting due to 5 previous errors - diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index 9b32ed7304bb..f05b9894fea0 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(bool_comparison)] fn main() { diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr index 4436980bc117..e5e062e0246d 100644 --- a/tests/ui/bool_comparison.stderr +++ b/tests/ui/bool_comparison.stderr @@ -24,5 +24,3 @@ error: equality checks against false can be replaced by a negation 10 | if false == x { "yes" } else { "no" }; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` -error: aborting due to 4 previous errors - diff --git a/tests/ui/booleans.rs b/tests/ui/booleans.rs index ac60bf5e3458..0434285a5238 100644 --- a/tests/ui/booleans.rs +++ b/tests/ui/booleans.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(nonminimal_bool, logic_bug)] #[allow(unused, many_single_char_names)] diff --git a/tests/ui/booleans.stderr b/tests/ui/booleans.stderr index a76eb7a5cc04..0311e95a4f11 100644 --- a/tests/ui/booleans.stderr +++ b/tests/ui/booleans.stderr @@ -130,5 +130,3 @@ help: try 39 | let _ = !(a == b && c == d); | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors - diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index b5543da6e35c..394b810ed866 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![deny(borrowed_box)] #![allow(blacklisted_name)] diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index 2cf0ea79626c..74134f4f2b18 100644 --- a/tests/ui/borrow_box.stderr +++ b/tests/ui/borrow_box.stderr @@ -28,5 +28,3 @@ error: you seem to be trying to use `&Box`. Consider using just `&T` 22 | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` -error: aborting due to 4 previous errors - diff --git a/tests/ui/box_vec.rs b/tests/ui/box_vec.rs index f8c5a80c59de..75b3b62643e8 100644 --- a/tests/ui/box_vec.rs +++ b/tests/ui/box_vec.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(boxed_local, needless_pass_by_value)] diff --git a/tests/ui/box_vec.stderr b/tests/ui/box_vec.stderr index 254d07713862..c1badd0dc9b4 100644 --- a/tests/ui/box_vec.stderr +++ b/tests/ui/box_vec.stderr @@ -7,5 +7,3 @@ error: you seem to be trying to use `Box>`. Consider using just `Vec` = note: `-D box-vec` implied by `-D warnings` = help: `Vec` is already on the heap, `Box>` makes an extra allocation. -error: aborting due to previous error - diff --git a/tests/ui/builtin-type-shadow.rs b/tests/ui/builtin-type-shadow.rs index a3609cfe1046..4c4f5cbd3fe7 100644 --- a/tests/ui/builtin-type-shadow.rs +++ b/tests/ui/builtin-type-shadow.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(builtin_type_shadow)] fn foo(a: u32) -> u32 { diff --git a/tests/ui/builtin-type-shadow.stderr b/tests/ui/builtin-type-shadow.stderr index eb4c73b65c69..058813356cd0 100644 --- a/tests/ui/builtin-type-shadow.stderr +++ b/tests/ui/builtin-type-shadow.stderr @@ -17,5 +17,3 @@ error[E0308]: mismatched types = note: expected type `u32` found type `{integer}` -error: aborting due to 2 previous errors - diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 8fc27c49f34b..fc94667d968f 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[deny(naive_bytecount)] fn main() { diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 307edecfde1a..c4f6b65a21ea 100644 --- a/tests/ui/bytecount.stderr +++ b/tests/ui/bytecount.stderr @@ -22,5 +22,3 @@ error: You appear to be counting bytes the naive way 22 | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider using the bytecount crate: `bytecount::count(x, b + 1)` -error: aborting due to 3 previous errors - diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 82427c128e4f..1ad4630989dd 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(cast_precision_loss, cast_possible_truncation, cast_sign_loss, cast_possible_wrap, cast_lossless)] #[allow(no_effect, unnecessary_operation)] diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 8787083b4298..5e7ed6fae99c 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -460,5 +460,3 @@ error: casting to the same type is unnecessary (`bool` -> `bool`) 88 | false as bool; | ^^^^^^^^^^^^^ -error: aborting due to 75 previous errors - diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index 6f07b60fb101..c69181c76493 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(char_lit_as_u8)] #![allow(unused_variables)] diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr index fcf038fe002d..4e7c1866a9af 100644 --- a/tests/ui/char_lit_as_u8.stderr +++ b/tests/ui/char_lit_as_u8.stderr @@ -8,5 +8,3 @@ error: casting character literal to u8. `char`s are 4 bytes wide in rust, so cas = help: Consider using a byte literal instead: b'a' -error: aborting due to previous error - diff --git a/tests/ui/cmp_nan.rs b/tests/ui/cmp_nan.rs index e8639273485c..71dfdd43da7c 100644 --- a/tests/ui/cmp_nan.rs +++ b/tests/ui/cmp_nan.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(cmp_nan)] #[allow(float_cmp, no_effect, unnecessary_operation)] diff --git a/tests/ui/cmp_nan.stderr b/tests/ui/cmp_nan.stderr index 46f3d3d57e0c..9ea1a29d29da 100644 --- a/tests/ui/cmp_nan.stderr +++ b/tests/ui/cmp_nan.stderr @@ -72,5 +72,3 @@ error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead 21 | y >= std::f64::NAN; | ^^^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors - diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index 47ecacd5558b..0f463bcfc30d 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(cmp_null)] #![allow(unused_mut)] diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index 481a4d0f9420..51c0ceea4b14 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -12,5 +12,3 @@ error: Comparing with null is better expressed by the .is_null() method 16 | if m == ptr::null_mut() { | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/cmp_owned.rs b/tests/ui/cmp_owned.rs index 4b9b6434ebca..36d3140d246f 100644 --- a/tests/ui/cmp_owned.rs +++ b/tests/ui/cmp_owned.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(cmp_owned)] #[allow(unnecessary_operation)] diff --git a/tests/ui/cmp_owned.stderr b/tests/ui/cmp_owned.stderr index d40fb4b8add8..e69962446642 100644 --- a/tests/ui/cmp_owned.stderr +++ b/tests/ui/cmp_owned.stderr @@ -36,5 +36,3 @@ error: this creates an owned instance just for comparison 30 | self.to_owned() == *other | ^^^^^^^^^^^^^^^ try calling implementing the comparison without allocating -error: aborting due to 6 previous errors - diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index d03a1ee19801..3c5c38525fe7 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(collapsible_if)] fn main() { diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index 940749d3f407..e726a36282b5 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -252,5 +252,3 @@ help: try 112 | } | -error: aborting due to 13 previous errors - diff --git a/tests/ui/complex_types.rs b/tests/ui/complex_types.rs index 481a6a82cf55..7719a7a86322 100644 --- a/tests/ui/complex_types.rs +++ b/tests/ui/complex_types.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(unused, needless_pass_by_value)] #![feature(associated_type_defaults)] diff --git a/tests/ui/complex_types.stderr b/tests/ui/complex_types.stderr index 829a22c233f0..8ce63652f0b6 100644 --- a/tests/ui/complex_types.stderr +++ b/tests/ui/complex_types.stderr @@ -90,5 +90,3 @@ error: very complex type used. Consider factoring parts into `type` definitions 40 | let _y: Vec>> = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 15 previous errors - diff --git a/tests/ui/conf_bad_arg.rs b/tests/ui/conf_bad_arg.rs index 68b902719f6e..b988fdb13853 100644 --- a/tests/ui/conf_bad_arg.rs +++ b/tests/ui/conf_bad_arg.rs @@ -1,6 +1,6 @@ // error-pattern: `conf_file` must be a named value -#![feature(plugin)] + #![plugin(clippy(conf_file))] fn main() {} diff --git a/tests/ui/conf_bad_arg.stderr b/tests/ui/conf_bad_arg.stderr index 92b3c82d4583..d91729039b19 100644 --- a/tests/ui/conf_bad_arg.stderr +++ b/tests/ui/conf_bad_arg.stderr @@ -1,14 +1,8 @@ -error: `conf_file` must be a named value - --> $DIR/conf_bad_arg.rs:4:18 +error: compiler plugins are experimental and possibly buggy (see issue #29597) + --> $DIR/conf_bad_arg.rs:4:1 | 4 | #![plugin(clippy(conf_file))] - | ^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: Clippy will use default configuration - --> $DIR/conf_bad_arg.rs:4:18 - | -4 | #![plugin(clippy(conf_file))] - | ^^^^^^^^^ - -error: aborting due to previous error + = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/tests/ui/conf_bad_toml.rs b/tests/ui/conf_bad_toml.rs index 22cbfca759e9..4de2cf6ae73c 100644 --- a/tests/ui/conf_bad_toml.rs +++ b/tests/ui/conf_bad_toml.rs @@ -1,6 +1,6 @@ // error-pattern: error reading Clippy's configuration file -#![feature(plugin)] + #![plugin(clippy(conf_file="./tests/ui/conf_bad_toml.toml"))] fn main() {} diff --git a/tests/ui/conf_bad_toml.stderr b/tests/ui/conf_bad_toml.stderr index 8ee392f89248..5ddf8c14f70f 100644 --- a/tests/ui/conf_bad_toml.stderr +++ b/tests/ui/conf_bad_toml.stderr @@ -1,4 +1,8 @@ -error: error reading Clippy's configuration file: expected an equals, found an identifier at line 1 - -error: aborting due to previous error +error: compiler plugins are experimental and possibly buggy (see issue #29597) + --> $DIR/conf_bad_toml.rs:4:1 + | +4 | #![plugin(clippy(conf_file="./$DIR/conf_bad_toml.toml"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/tests/ui/conf_bad_type.rs b/tests/ui/conf_bad_type.rs index d5cca60a3013..4cb21b91582e 100644 --- a/tests/ui/conf_bad_type.rs +++ b/tests/ui/conf_bad_type.rs @@ -1,6 +1,6 @@ // error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer` -#![feature(plugin)] + #![plugin(clippy(conf_file="./tests/ui/conf_bad_type.toml"))] fn main() {} diff --git a/tests/ui/conf_bad_type.stderr b/tests/ui/conf_bad_type.stderr index 5cb4d05afef2..961df381c991 100644 --- a/tests/ui/conf_bad_type.stderr +++ b/tests/ui/conf_bad_type.stderr @@ -1,4 +1,8 @@ -error: error reading Clippy's configuration file: invalid type: integer `42`, expected a sequence - -error: aborting due to previous error +error: compiler plugins are experimental and possibly buggy (see issue #29597) + --> $DIR/conf_bad_type.rs:4:1 + | +4 | #![plugin(clippy(conf_file="./$DIR/conf_bad_type.toml"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/tests/ui/conf_french_blacklisted_name.rs b/tests/ui/conf_french_blacklisted_name.rs index 5bf1e896f5d1..9f22ff659f23 100644 --- a/tests/ui/conf_french_blacklisted_name.rs +++ b/tests/ui/conf_french_blacklisted_name.rs @@ -1,4 +1,4 @@ -#![feature(plugin)] + #![plugin(clippy(conf_file="./tests/auxiliary/conf_french_blacklisted_name.toml"))] #![allow(dead_code)] diff --git a/tests/ui/conf_french_blacklisted_name.stderr b/tests/ui/conf_french_blacklisted_name.stderr index b2b0f26b1405..c98adb6029fa 100644 --- a/tests/ui/conf_french_blacklisted_name.stderr +++ b/tests/ui/conf_french_blacklisted_name.stderr @@ -1,46 +1,8 @@ -error: use of a blacklisted/placeholder name `toto` - --> $DIR/conf_french_blacklisted_name.rs:9:9 +error: compiler plugins are experimental and possibly buggy (see issue #29597) + --> $DIR/conf_french_blacklisted_name.rs:2:1 | -9 | fn test(toto: ()) {} - | ^^^^ +2 | #![plugin(clippy(conf_file="./tests/auxiliary/conf_french_blacklisted_name.toml"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D blacklisted-name` implied by `-D warnings` - -error: use of a blacklisted/placeholder name `toto` - --> $DIR/conf_french_blacklisted_name.rs:12:9 - | -12 | let toto = 42; - | ^^^^ - -error: use of a blacklisted/placeholder name `tata` - --> $DIR/conf_french_blacklisted_name.rs:13:9 - | -13 | let tata = 42; - | ^^^^ - -error: use of a blacklisted/placeholder name `titi` - --> $DIR/conf_french_blacklisted_name.rs:14:9 - | -14 | let titi = 42; - | ^^^^ - -error: use of a blacklisted/placeholder name `toto` - --> $DIR/conf_french_blacklisted_name.rs:20:10 - | -20 | (toto, Some(tata), titi @ Some(_)) => (), - | ^^^^ - -error: use of a blacklisted/placeholder name `tata` - --> $DIR/conf_french_blacklisted_name.rs:20:21 - | -20 | (toto, Some(tata), titi @ Some(_)) => (), - | ^^^^ - -error: use of a blacklisted/placeholder name `titi` - --> $DIR/conf_french_blacklisted_name.rs:20:28 - | -20 | (toto, Some(tata), titi @ Some(_)) => (), - | ^^^^ - -error: aborting due to 7 previous errors + = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/tests/ui/conf_path_non_string.rs b/tests/ui/conf_path_non_string.rs index f6f40513be8a..8d1f01358fc8 100644 --- a/tests/ui/conf_path_non_string.rs +++ b/tests/ui/conf_path_non_string.rs @@ -1,5 +1,5 @@ #![feature(attr_literals)] -#![feature(plugin)] + #![plugin(clippy(conf_file=42))] fn main() {} diff --git a/tests/ui/conf_path_non_string.stderr b/tests/ui/conf_path_non_string.stderr index 3bf53f10cce4..4b15b5d0e170 100644 --- a/tests/ui/conf_path_non_string.stderr +++ b/tests/ui/conf_path_non_string.stderr @@ -1,14 +1,8 @@ -error: `conf_file` value must be a string - --> $DIR/conf_path_non_string.rs:3:28 +error: compiler plugins are experimental and possibly buggy (see issue #29597) + --> $DIR/conf_path_non_string.rs:3:1 | 3 | #![plugin(clippy(conf_file=42))] - | ^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: Clippy will use default configuration - --> $DIR/conf_path_non_string.rs:3:28 - | -3 | #![plugin(clippy(conf_file=42))] - | ^^ - -error: aborting due to previous error + = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/tests/ui/conf_unknown_key.rs b/tests/ui/conf_unknown_key.rs index b5c1b240e4d1..aec2c883367c 100644 --- a/tests/ui/conf_unknown_key.rs +++ b/tests/ui/conf_unknown_key.rs @@ -1,6 +1,6 @@ // error-pattern: error reading Clippy's configuration file: unknown key `foobar` -#![feature(plugin)] + #![plugin(clippy(conf_file="./tests/auxiliary/conf_unknown_key.toml"))] fn main() {} diff --git a/tests/ui/conf_unknown_key.stderr b/tests/ui/conf_unknown_key.stderr index bd16dfd47da9..9fc7dbea5634 100644 --- a/tests/ui/conf_unknown_key.stderr +++ b/tests/ui/conf_unknown_key.stderr @@ -1,4 +1,8 @@ -error: error reading Clippy's configuration file: unknown field `foobar`, expected one of `blacklisted-names`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `third-party` - -error: aborting due to previous error +error: compiler plugins are experimental and possibly buggy (see issue #29597) + --> $DIR/conf_unknown_key.rs:4:1 + | +4 | #![plugin(clippy(conf_file="./tests/auxiliary/conf_unknown_key.toml"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/tests/ui/copies.rs b/tests/ui/copies.rs index a7b992527359..4c4050c014fd 100644 --- a/tests/ui/copies.rs +++ b/tests/ui/copies.rs @@ -1,5 +1,4 @@ -#![feature(plugin, inclusive_range_syntax)] -#![plugin(clippy)] +#![feature(dotdoteq_in_patterns, inclusive_range_syntax)] #![allow(dead_code, no_effect, unnecessary_operation)] #![allow(let_and_return)] @@ -33,7 +32,7 @@ fn if_same_then_else() -> Result<&'static str, ()> { ..; 0..; ..10; - 0...10; + 0..=10; foo(); } else { @@ -42,7 +41,7 @@ fn if_same_then_else() -> Result<&'static str, ()> { ..; 0..; ..10; - 0...10; + 0..=10; foo(); } @@ -64,7 +63,7 @@ fn if_same_then_else() -> Result<&'static str, ()> { 0..10; } else { - 0...10; + 0..=10; } if true { @@ -161,7 +160,7 @@ fn if_same_then_else() -> Result<&'static str, ()> { let _ = match 42 { 42 => 1, a if a > 0 => 2, - 10...15 => 3, + 10..=15 => 3, _ => 4, }; } @@ -172,7 +171,7 @@ fn if_same_then_else() -> Result<&'static str, ()> { let _ = match 42 { 42 => 1, a if a > 0 => 2, - 10...15 => 3, + 10..=15 => 3, _ => 4, }; } diff --git a/tests/ui/copies.stderr b/tests/ui/copies.stderr index bf9e8ed577d0..4457e2b7d731 100644 --- a/tests/ui/copies.stderr +++ b/tests/ui/copies.stderr @@ -1,11 +1,11 @@ error: This else block is redundant. - --> $DIR/copies.rs:121:20 + --> $DIR/copies.rs:120:20 | -121 | } else { +120 | } else { | ____________________^ -122 | | continue; -123 | | } +121 | | continue; +122 | | } | |_____________^ | = note: `-D needless-continue` implied by `-D warnings` @@ -18,12 +18,12 @@ error: This else block is redundant. error: This else block is redundant. - --> $DIR/copies.rs:131:20 + --> $DIR/copies.rs:130:20 | -131 | } else { +130 | } else { | ____________________^ -132 | | continue; -133 | | } +131 | | continue; +132 | | } | |_____________^ | = help: Consider dropping the else clause and merging the code that follows (in the loop) with the if block, like so: @@ -33,5 +33,3 @@ error: This else block is redundant. } -error: aborting due to 2 previous errors - diff --git a/tests/ui/cyclomatic_complexity.rs b/tests/ui/cyclomatic_complexity.rs index a236d6e869f3..0f5726e1ad73 100644 --- a/tests/ui/cyclomatic_complexity.rs +++ b/tests/ui/cyclomatic_complexity.rs @@ -1,5 +1,5 @@ #![feature(plugin, custom_attribute)] -#![plugin(clippy)] + #![allow(clippy)] #![warn(cyclomatic_complexity)] #![allow(unused)] diff --git a/tests/ui/cyclomatic_complexity.stderr b/tests/ui/cyclomatic_complexity.stderr index 43676762d6c0..62fd5313ccb6 100644 --- a/tests/ui/cyclomatic_complexity.stderr +++ b/tests/ui/cyclomatic_complexity.stderr @@ -269,5 +269,3 @@ error: the function has a cyclomatic complexity of 8 | = help: you could split it up into multiple smaller functions -error: aborting due to 20 previous errors - diff --git a/tests/ui/cyclomatic_complexity_attr_used.rs b/tests/ui/cyclomatic_complexity_attr_used.rs index 48ae12bc2d8c..5284d60a5245 100644 --- a/tests/ui/cyclomatic_complexity_attr_used.rs +++ b/tests/ui/cyclomatic_complexity_attr_used.rs @@ -1,5 +1,5 @@ #![feature(plugin, custom_attribute)] -#![plugin(clippy)] + #![warn(cyclomatic_complexity)] #![warn(unused)] diff --git a/tests/ui/cyclomatic_complexity_attr_used.stderr b/tests/ui/cyclomatic_complexity_attr_used.stderr index e671b34393b5..a9cefe93e329 100644 --- a/tests/ui/cyclomatic_complexity_attr_used.stderr +++ b/tests/ui/cyclomatic_complexity_attr_used.stderr @@ -13,5 +13,3 @@ error: the function has a cyclomatic complexity of 3 = note: `-D cyclomatic-complexity` implied by `-D warnings` = help: you could split it up into multiple smaller functions -error: aborting due to previous error - diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index e0c856e3d7cc..0598e174e50a 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(str_to_string)] diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index 7d5d594cfa1c..4255959675a9 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -24,5 +24,3 @@ error: lint unstable_as_mut_slice has been removed: `Vec::as_mut_slice` has been 10 | #[warn(unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors - diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index 11cade0dc8e5..6440f73f31bd 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![feature(untagged_unions)] diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index ffeed948ba55..f336dc3a8e13 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -106,5 +106,3 @@ note: consider deriving `Clone` or removing `Copy` 87 | | } | |_^ -error: aborting due to 7 previous errors - diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index 7ae531cc6f27..d2aea93a77d8 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -1,5 +1,5 @@ #![feature(plugin, never_type)] -#![plugin(clippy)] + #![warn(diverging_sub_expression)] #![allow(match_same_arms, logic_bug)] diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 0d7b1ca6fd66..b39d1ae07e5e 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -36,5 +36,3 @@ error: sub-expression diverges 37 | _ => true || break, | ^^^^^ -error: aborting due to 6 previous errors - diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs index 5e4e1cb2a64f..217a564742cf 100644 --- a/tests/ui/dlist.rs +++ b/tests/ui/dlist.rs @@ -1,7 +1,7 @@ #![feature(plugin, alloc)] #![feature(associated_type_defaults)] -#![plugin(clippy)] + #![warn(clippy)] #![allow(dead_code, needless_pass_by_value)] diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr index de0422e17edd..95872c02994f 100644 --- a/tests/ui/dlist.stderr +++ b/tests/ui/dlist.stderr @@ -47,5 +47,3 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct | = help: a VecDeque might work -error: aborting due to 6 previous errors - diff --git a/tests/ui/doc.rs b/tests/ui/doc.rs index 9e7b34e3ea50..45e25409b128 100644 --- a/tests/ui/doc.rs +++ b/tests/ui/doc.rs @@ -1,7 +1,7 @@ //! This file tests for the DOC_MARKDOWN lint -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code)] #![warn(doc_markdown)] @@ -159,3 +159,11 @@ fn issue_1469() {} *This would also be an error under a strict common mark interpretation */ fn issue_1920() {} + +/// Ok: +/// +/// Not ok: http://www.unicode.org +/// Not ok: https://www.unicode.org +/// Not ok: http://www.unicode.org/ +/// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels +fn issue_1832() {} diff --git a/tests/ui/doc.stderr b/tests/ui/doc.stderr index c3146f17d088..fc036d01b866 100644 --- a/tests/ui/doc.stderr +++ b/tests/ui/doc.stderr @@ -156,5 +156,27 @@ error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the doc 138 | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 26 previous errors +error: you should put bare URLs between `<`/`>` or make a proper Markdown link + --> $DIR/doc.rs:165:13 + | +165 | /// Not ok: http://www.unicode.org + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put bare URLs between `<`/`>` or make a proper Markdown link + --> $DIR/doc.rs:166:13 + | +166 | /// Not ok: https://www.unicode.org + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put bare URLs between `<`/`>` or make a proper Markdown link + --> $DIR/doc.rs:167:13 + | +167 | /// Not ok: http://www.unicode.org/ + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put bare URLs between `<`/`>` or make a proper Markdown link + --> $DIR/doc.rs:168:13 + | +168 | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/double_neg.rs b/tests/ui/double_neg.rs index d462e6f4ab6b..641e334fd165 100644 --- a/tests/ui/double_neg.rs +++ b/tests/ui/double_neg.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(double_neg)] fn main() { diff --git a/tests/ui/double_neg.stderr b/tests/ui/double_neg.stderr index fd4da8820a24..8c64eb37e154 100644 --- a/tests/ui/double_neg.stderr +++ b/tests/ui/double_neg.stderr @@ -6,5 +6,3 @@ error: `--x` could be misinterpreted as pre-decrement by C programmers, is usual | = note: `-D double-neg` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/double_parens.rs b/tests/ui/double_parens.rs index 8b57619edb0d..19d177328675 100644 --- a/tests/ui/double_parens.rs +++ b/tests/ui/double_parens.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(double_parens)] #![allow(dead_code)] diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr index a77b08528c49..ab3e844d7a7f 100644 --- a/tests/ui/double_parens.stderr +++ b/tests/ui/double_parens.stderr @@ -30,5 +30,3 @@ error: Consider removing unnecessary double parentheses 32 | (()) | ^^^^ -error: aborting due to 5 previous errors - diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs index 4e48a89b6598..9fef06b0edef 100644 --- a/tests/ui/drop_forget_copy.rs +++ b/tests/ui/drop_forget_copy.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(drop_copy, forget_copy)] #![allow(toplevel_ref_arg, drop_ref, forget_ref, unused_mut)] diff --git a/tests/ui/drop_forget_copy.stderr b/tests/ui/drop_forget_copy.stderr index 3ea7bf9735af..f399c5a125f8 100644 --- a/tests/ui/drop_forget_copy.stderr +++ b/tests/ui/drop_forget_copy.stderr @@ -72,5 +72,3 @@ note: argument has type SomeStruct 42 | forget(s4); | ^^ -error: aborting due to 6 previous errors - diff --git a/tests/ui/drop_forget_ref.rs b/tests/ui/drop_forget_ref.rs index 48811f03b6f2..e8ab6a0d5d13 100644 --- a/tests/ui/drop_forget_ref.rs +++ b/tests/ui/drop_forget_ref.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(drop_ref, forget_ref)] #![allow(toplevel_ref_arg, similar_names, needless_pass_by_value)] diff --git a/tests/ui/drop_forget_ref.stderr b/tests/ui/drop_forget_ref.stderr index 1654fdd2861a..6058b89c70f3 100644 --- a/tests/ui/drop_forget_ref.stderr +++ b/tests/ui/drop_forget_ref.stderr @@ -216,5 +216,3 @@ note: argument has type &SomeStruct 59 | std::mem::forget(&SomeStruct); | ^^^^^^^^^^^ -error: aborting due to 18 previous errors - diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs index 893cc43f3646..df00f56aa621 100644 --- a/tests/ui/duplicate_underscore_argument.rs +++ b/tests/ui/duplicate_underscore_argument.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(duplicate_underscore_argument)] #[allow(dead_code, unused)] diff --git a/tests/ui/duplicate_underscore_argument.stderr b/tests/ui/duplicate_underscore_argument.stderr index c926f57f154f..de9e6f1e056c 100644 --- a/tests/ui/duplicate_underscore_argument.stderr +++ b/tests/ui/duplicate_underscore_argument.stderr @@ -6,5 +6,3 @@ error: `darth` already exists, having another argument having almost the same na | = note: `-D duplicate-underscore-argument` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs index 98138add0de3..c6e6946de866 100644 --- a/tests/ui/empty_enum.rs +++ b/tests/ui/empty_enum.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code)] #![warn(empty_enum)] diff --git a/tests/ui/empty_enum.stderr b/tests/ui/empty_enum.stderr index ca377cee8221..a0d491b6f968 100644 --- a/tests/ui/empty_enum.stderr +++ b/tests/ui/empty_enum.stderr @@ -11,5 +11,3 @@ help: consider using the uninhabited type `!` or a wrapper around it 7 | enum Empty {} | ^^^^^^^^^^^^^ -error: aborting due to previous error - diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index 1ae39689d8be..ccbc7038f136 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused, needless_pass_by_value)] #![warn(map_entry)] diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index 09c4a8822802..e60c158d7c06 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -42,5 +42,3 @@ error: usage of `contains_key` followed by `insert` on a `BTreeMap` 37 | if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` -error: aborting due to 7 previous errors - diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index 514ef47c566d..76d0d29bb539 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy, clippy_pedantic)] #![allow(unused_imports, dead_code, missing_docs_in_private_items)] diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr index 2d53618c1b18..1e0fffb9ac44 100644 --- a/tests/ui/enum_glob_use.stderr +++ b/tests/ui/enum_glob_use.stderr @@ -12,5 +12,3 @@ error: don't use glob imports for enum variants 12 | use self::Enum::*; | ^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index a12eb3fd3447..9901baf9e128 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -1,5 +1,5 @@ #![feature(plugin, non_ascii_idents)] -#![plugin(clippy)] + #![warn(clippy, pub_enum_variant_names)] enum FakeCallType { diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index e33e29ec78e1..7e2716b8ea20 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -97,5 +97,3 @@ error: All variants have the same prefix: `With` = note: `-D pub-enum-variant-names` implied by `-D warnings` = help: remove the prefixes and use full paths to the variants instead of glob imports -error: aborting due to 10 previous errors - diff --git a/tests/ui/enums_clike.rs b/tests/ui/enums_clike.rs index fd2240353dd4..618603683e83 100644 --- a/tests/ui/enums_clike.rs +++ b/tests/ui/enums_clike.rs @@ -1,6 +1,6 @@ // ignore-x86 -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(unused)] diff --git a/tests/ui/enums_clike.stderr b/tests/ui/enums_clike.stderr index d6a137c6fe4d..e0555bb02398 100644 --- a/tests/ui/enums_clike.stderr +++ b/tests/ui/enums_clike.stderr @@ -48,5 +48,3 @@ error: Clike enum variant discriminant is not portable to 32-bit targets 37 | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors - diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index 12d62042dca8..89d85d1b3e9d 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(eq_op)] #[allow(identity_op, double_parens, many_single_char_names)] diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index 46c0ac108cda..914a85719d0f 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -204,5 +204,3 @@ error: taken reference of right operand | = note: `-D op-ref` implied by `-D warnings` -error: aborting due to 33 previous errors - diff --git a/tests/ui/escape_analysis.rs b/tests/ui/escape_analysis.rs index b4793198b7a1..b99534d05e17 100644 --- a/tests/ui/escape_analysis.rs +++ b/tests/ui/escape_analysis.rs @@ -1,5 +1,5 @@ #![feature(plugin, box_syntax)] -#![plugin(clippy)] + #![allow(warnings, clippy)] #![warn(boxed_local)] diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index 46ac0ec8c736..0ff02a0b2ccc 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unknown_lints, unused, no_effect, redundant_closure_call, many_single_char_names, needless_pass_by_value)] #![warn(redundant_closure)] diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 5dca265c2a40..34a6217cd709 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -32,5 +32,3 @@ error: redundant closure found 18 | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: remove closure as shown: `generic` -error: aborting due to 5 previous errors - diff --git a/tests/ui/eval_order_dependence.rs b/tests/ui/eval_order_dependence.rs index 853c61af2f25..e7ccb190d2c7 100644 --- a/tests/ui/eval_order_dependence.rs +++ b/tests/ui/eval_order_dependence.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(eval_order_dependence)] #[allow(unused_assignments, unused_variables, many_single_char_names, no_effect, dead_code, blacklisted_name)] diff --git a/tests/ui/eval_order_dependence.stderr b/tests/ui/eval_order_dependence.stderr index 2e01a167c01b..e9bdc3b51d9d 100644 --- a/tests/ui/eval_order_dependence.stderr +++ b/tests/ui/eval_order_dependence.stderr @@ -47,5 +47,3 @@ note: whether read occurs before this write depends on evaluation order 21 | x += { x = 20; 2 }; | ^^^^^^ -error: aborting due to 4 previous errors - diff --git a/tests/ui/filter_methods.rs b/tests/ui/filter_methods.rs index 77ebe9d12ddf..29230c48ea3e 100644 --- a/tests/ui/filter_methods.rs +++ b/tests/ui/filter_methods.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy, clippy_pedantic)] #![allow(missing_docs_in_private_items)] diff --git a/tests/ui/filter_methods.stderr b/tests/ui/filter_methods.stderr index cec03a47bfde..8f1853c3952b 100644 --- a/tests/ui/filter_methods.stderr +++ b/tests/ui/filter_methods.stderr @@ -36,5 +36,3 @@ error: called `filter_map(p).map(q)` on an `Iterator`. This is more succinctly e 25 | | .map(|x| x.checked_mul(2)) | |__________________________________________________________^ -error: aborting due to 4 previous errors - diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index f3f66f3c9c5e..9dd9ea9b04d5 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(float_cmp)] #![allow(unused, no_effect, unnecessary_operation, cast_lossless)] diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index a764403d0397..d2903f501f5f 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -95,5 +95,3 @@ note: std::f32::EPSILON and std::f64::EPSILON are available. 57 | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors - diff --git a/tests/ui/for_loop.rs b/tests/ui/for_loop.rs index aa8b96322930..083e6f9a6e5a 100644 --- a/tests/ui/for_loop.rs +++ b/tests/ui/for_loop.rs @@ -1,5 +1,5 @@ #![feature(plugin, inclusive_range_syntax)] -#![plugin(clippy)] + use std::collections::*; use std::rc::Rc; @@ -125,7 +125,7 @@ fn main() { println!("{}", vec[i]); } - for i in 0...MAX_LEN { + for i in 0..=MAX_LEN { println!("{}", vec[i]); } @@ -133,7 +133,7 @@ fn main() { println!("{}", vec[i]); } - for i in 5...10 { + for i in 5..=10 { println!("{}", vec[i]); } @@ -149,7 +149,7 @@ fn main() { println!("{}", i); } - for i in 10...0 { + for i in 10..=0 { println!("{}", i); } @@ -161,7 +161,7 @@ fn main() { println!("{}", i); } - for i in 5...5 { + for i in 5..=5 { // not an error, this is the range with only one element “5” println!("{}", i); } diff --git a/tests/ui/for_loop.stderr b/tests/ui/for_loop.stderr index 79c6c781a7a5..620c32b6ab50 100644 --- a/tests/ui/for_loop.stderr +++ b/tests/ui/for_loop.stderr @@ -178,7 +178,7 @@ help: consider using an iterator error: the loop variable `i` is only used to index `vec`. --> $DIR/for_loop.rs:128:5 | -128 | / for i in 0...MAX_LEN { +128 | / for i in 0..=MAX_LEN { 129 | | println!("{}", vec[i]); 130 | | } | |_____^ @@ -204,7 +204,7 @@ help: consider using an iterator error: the loop variable `i` is only used to index `vec`. --> $DIR/for_loop.rs:136:5 | -136 | / for i in 5...10 { +136 | / for i in 5..=10 { 137 | | println!("{}", vec[i]); 138 | | } | |_____^ @@ -257,7 +257,7 @@ help: consider using the following if you are attempting to iterate over this ra error: this range is empty so this for loop will never run --> $DIR/for_loop.rs:152:5 | -152 | / for i in 10...0 { +152 | / for i in 10..=0 { 153 | | println!("{}", i); 154 | | } | |_____^ @@ -586,5 +586,3 @@ error: it looks like you're manually copying between slices 549 | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])` -error: aborting due to 59 previous errors - diff --git a/tests/ui/format.rs b/tests/ui/format.rs index 377bcc7ca8d3..e9379d0a05bd 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(useless_format)] fn main() { diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 5f5bdc02a592..67d97f295d81 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -6,5 +6,15 @@ error: useless use of `format!` | = note: `-D useless-format` implied by `-D warnings` -error: aborting due to previous error +error: useless use of `format!` + --> $DIR/format.rs:8:5 + | +8 | format!("{}", "foo"); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: useless use of `format!` + --> $DIR/format.rs:15:5 + | +15 | format!("{}", arg); + | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 7e2691776bf7..20b1c1655a72 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(unused_variables)] diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index 266de262ea0a..d121929d0c2d 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -86,5 +86,3 @@ error: possibly missing a comma here | = note: to remove this lint, add a comma or write the expr in a single line -error: aborting due to 10 previous errors - diff --git a/tests/ui/functions.rs b/tests/ui/functions.rs index 13d116542ac2..5688c471d86b 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(dead_code)] diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index 0a97748954f3..c8b4db352457 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -75,5 +75,3 @@ error: this public function dereferences a raw pointer but is not marked `unsafe 63 | unsafe { std::ptr::read(p) }; | ^ -error: aborting due to 12 previous errors - diff --git a/tests/ui/ices.rs b/tests/ui/ices.rs deleted file mode 100644 index 9c5129654e41..000000000000 --- a/tests/ui/ices.rs +++ /dev/null @@ -1,5 +0,0 @@ - -// this used to ICE -fubar!(); - -fn main() {} diff --git a/tests/ui/ices.stderr b/tests/ui/ices.stderr deleted file mode 100644 index cadd7cd417d4..000000000000 --- a/tests/ui/ices.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: cannot find macro `fubar!` in this scope - --> $DIR/ices.rs:3:1 - | -3 | fubar!(); - | ^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/identity_conversion.rs b/tests/ui/identity_conversion.rs new file mode 100644 index 000000000000..d254b746d79f --- /dev/null +++ b/tests/ui/identity_conversion.rs @@ -0,0 +1,40 @@ +#![deny(identity_conversion)] + +fn test_generic(val: T) -> T { + let _ = T::from(val); + val.into() +} + +fn test_generic2 + Into, U: From>(val: T) { + // ok + let _: i32 = val.into(); + let _: U = val.into(); + let _ = U::from(val); +} + +fn test_questionmark() -> Result<(), ()> { + { + let _: i32 = 0i32.into(); + Ok(Ok(())) + }??; + Ok(()) +} + +fn main() { + test_generic(10i32); + test_generic2::(10i32); + test_questionmark().unwrap(); + + let _: String = "foo".into(); + let _: String = From::from("foo"); + let _ = String::from("foo"); + #[allow(identity_conversion)] + { + let _: String = "foo".into(); + let _ = String::from("foo"); + } + + let _: String = "foo".to_string().into(); + let _: String = From::from("foo".to_string()); + let _ = String::from("foo".to_string()); +} diff --git a/tests/ui/identity_conversion.stderr b/tests/ui/identity_conversion.stderr new file mode 100644 index 000000000000..152bb8882bda --- /dev/null +++ b/tests/ui/identity_conversion.stderr @@ -0,0 +1,42 @@ +error: identical conversion + --> $DIR/identity_conversion.rs:4:13 + | +4 | let _ = T::from(val); + | ^^^^^^^^^^^^ help: consider removing `T::from()`: `val` + | +note: lint level defined here + --> $DIR/identity_conversion.rs:1:9 + | +1 | #![deny(identity_conversion)] + | ^^^^^^^^^^^^^^^^^^^ + +error: identical conversion + --> $DIR/identity_conversion.rs:5:5 + | +5 | val.into() + | ^^^^^^^^^^ help: consider removing `.into()`: `val` + +error: identical conversion + --> $DIR/identity_conversion.rs:17:22 + | +17 | let _: i32 = 0i32.into(); + | ^^^^^^^^^^^ help: consider removing `.into()`: `0i32` + +error: identical conversion + --> $DIR/identity_conversion.rs:37:21 + | +37 | let _: String = "foo".to_string().into(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()` + +error: identical conversion + --> $DIR/identity_conversion.rs:38:21 + | +38 | let _: String = From::from("foo".to_string()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()` + +error: identical conversion + --> $DIR/identity_conversion.rs:39:13 + | +39 | let _ = String::from("foo".to_string()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()` + diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index e6ebb9726432..b474344977c8 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + const ONE : i64 = 1; const NEG_ONE : i64 = -1; diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index 94b9b727a510..30367c989ec8 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -42,5 +42,3 @@ error: the operation is ineffective. Consider reducing it to `x` 29 | -1 & x; | ^^^^^^ -error: aborting due to 7 previous errors - diff --git a/tests/ui/if_let_redundant_pattern_matching.rs b/tests/ui/if_let_redundant_pattern_matching.rs index 6444bd8ef685..0963caa62e28 100644 --- a/tests/ui/if_let_redundant_pattern_matching.rs +++ b/tests/ui/if_let_redundant_pattern_matching.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![warn(if_let_redundant_pattern_matching)] diff --git a/tests/ui/if_let_redundant_pattern_matching.stderr b/tests/ui/if_let_redundant_pattern_matching.stderr index e7bfd0275d8e..b15d17e372e0 100644 --- a/tests/ui/if_let_redundant_pattern_matching.stderr +++ b/tests/ui/if_let_redundant_pattern_matching.stderr @@ -24,5 +24,3 @@ error: redundant pattern matching, consider using `is_some()` 17 | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` -error: aborting due to 4 previous errors - diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index 7b838560ed10..9436af70cb8f 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![warn(if_not_else)] diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index b920ef3b6250..f9462f422ea7 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -23,5 +23,3 @@ error: Unnecessary `!=` operation | = help: change to `==` and swap the blocks of the if/else -error: aborting due to 2 previous errors - diff --git a/tests/ui/inconsistent_digit_grouping.rs b/tests/ui/inconsistent_digit_grouping.rs index 06e8996deb7b..ed6dc06edb17 100644 --- a/tests/ui/inconsistent_digit_grouping.rs +++ b/tests/ui/inconsistent_digit_grouping.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(inconsistent_digit_grouping)] #[allow(unused_variables)] fn main() { diff --git a/tests/ui/inconsistent_digit_grouping.stderr b/tests/ui/inconsistent_digit_grouping.stderr index 12d9e3cf0fd7..2725d5f4ef7f 100644 --- a/tests/ui/inconsistent_digit_grouping.stderr +++ b/tests/ui/inconsistent_digit_grouping.stderr @@ -39,5 +39,3 @@ error: digits grouped inconsistently by underscores | = help: consider: 1.234_567_8_f32 -error: aborting due to 5 previous errors - diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index fd433edf98d2..08596ff20169 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -1,6 +1,5 @@ -#![feature(plugin)] #![feature(iterator_for_each)] -#![plugin(clippy)] + use std::iter::repeat; fn square_is_lower_64(x: &u32) -> bool { x * x < 64 } diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index b3d2f08a8657..87b7ca493222 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -1,100 +1,98 @@ error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator - --> $DIR/infinite_iter.rs:11:5 + --> $DIR/infinite_iter.rs:10:5 | -11 | repeat(0_u8).collect::>(); // infinite iter +10 | repeat(0_u8).collect::>(); // infinite iter | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unused-collect` implied by `-D warnings` error: infinite iteration detected - --> $DIR/infinite_iter.rs:11:5 + --> $DIR/infinite_iter.rs:10:5 | -11 | repeat(0_u8).collect::>(); // infinite iter +10 | repeat(0_u8).collect::>(); // infinite iter | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: lint level defined here - --> $DIR/infinite_iter.rs:9:8 + --> $DIR/infinite_iter.rs:8:8 | -9 | #[deny(infinite_iter)] +8 | #[deny(infinite_iter)] | ^^^^^^^^^^^^^ +error: infinite iteration detected + --> $DIR/infinite_iter.rs:11:5 + | +11 | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: infinite iteration detected --> $DIR/infinite_iter.rs:12:5 | -12 | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:13:5 - | -13 | (0..8_u64).chain(0..).max(); // infinite iter +12 | (0..8_u64).chain(0..).max(); // infinite iter | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:15:5 + --> $DIR/infinite_iter.rs:14:5 | -15 | (0..8_u32).rev().cycle().map(|x| x + 1_u32).for_each(|x| println!("{}", x)); // infinite iter +14 | (0..8_u32).rev().cycle().map(|x| x + 1_u32).for_each(|x| println!("{}", x)); // infinite iter | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: infinite iteration detected + --> $DIR/infinite_iter.rs:16:5 + | +16 | (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: infinite iteration detected --> $DIR/infinite_iter.rs:17:5 | -17 | (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:18:5 - | -18 | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter +17 | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: possible infinite iteration detected + --> $DIR/infinite_iter.rs:24:5 + | +24 | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/infinite_iter.rs:22:8 + | +22 | #[deny(maybe_infinite_iter)] + | ^^^^^^^^^^^^^^^^^^^ + error: possible infinite iteration detected --> $DIR/infinite_iter.rs:25:5 | -25 | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: lint level defined here - --> $DIR/infinite_iter.rs:23:8 - | -23 | #[deny(maybe_infinite_iter)] - | ^^^^^^^^^^^^^^^^^^^ +25 | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected --> $DIR/infinite_iter.rs:26:5 | -26 | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +26 | (1..).scan(0, |state, x| { *state += x; Some(*state) }).min(); // maybe infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected --> $DIR/infinite_iter.rs:27:5 | -27 | (1..).scan(0, |state, x| { *state += x; Some(*state) }).min(); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +27 | (0..).find(|x| *x == 24); // maybe infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected --> $DIR/infinite_iter.rs:28:5 | -28 | (0..).find(|x| *x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^ +28 | (0..).position(|x| x == 24); // maybe infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected --> $DIR/infinite_iter.rs:29:5 | -29 | (0..).position(|x| x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +29 | (0..).any(|x| x == 24); // maybe infinite iter + | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected --> $DIR/infinite_iter.rs:30:5 | -30 | (0..).any(|x| x == 24); // maybe infinite iter +30 | (0..).all(|x| x == 24); // maybe infinite iter | ^^^^^^^^^^^^^^^^^^^^^^ -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:31:5 - | -31 | (0..).all(|x| x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 14 previous errors - diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs new file mode 100644 index 000000000000..90375dad555f --- /dev/null +++ b/tests/ui/int_plus_one.rs @@ -0,0 +1,18 @@ +#![feature(plugin)] +#![plugin(clippy)] + +#[allow(no_effect, unnecessary_operation)] +#[warn(int_plus_one)] +fn main() { + let x = 1i32; + let y = 0i32; + + x >= y + 1; + y + 1 <= x; + + x - 1 >= y; + y <= x - 1; + + x > y; // should be ok + y < x; // should be ok +} diff --git a/tests/ui/int_plus_one.stderr b/tests/ui/int_plus_one.stderr new file mode 100644 index 000000000000..92b012bd104f --- /dev/null +++ b/tests/ui/int_plus_one.stderr @@ -0,0 +1,47 @@ +warning: running cargo clippy on a crate that also imports the clippy plugin + +error: Unnecessary `>= y + 1` or `x - 1 >=` + --> $DIR/int_plus_one.rs:10:5 + | +10 | x >= y + 1; + | ^^^^^^^^^^ + | + = note: `-D int-plus-one` implied by `-D warnings` +help: change `>= y + 1` to `> y` as shown + | +10 | x > y; + | ^^^^^ + +error: Unnecessary `>= y + 1` or `x - 1 >=` + --> $DIR/int_plus_one.rs:11:5 + | +11 | y + 1 <= x; + | ^^^^^^^^^^ + | +help: change `>= y + 1` to `> y` as shown + | +11 | y < x; + | ^^^^^ + +error: Unnecessary `>= y + 1` or `x - 1 >=` + --> $DIR/int_plus_one.rs:13:5 + | +13 | x - 1 >= y; + | ^^^^^^^^^^ + | +help: change `>= y + 1` to `> y` as shown + | +13 | x > y; + | ^^^^^ + +error: Unnecessary `>= y + 1` or `x - 1 >=` + --> $DIR/int_plus_one.rs:14:5 + | +14 | y <= x - 1; + | ^^^^^^^^^^ + | +help: change `>= y + 1` to `> y` as shown + | +14 | y < x; + | ^^^^^ + diff --git a/tests/ui/invalid_ref.rs b/tests/ui/invalid_ref.rs new file mode 100644 index 000000000000..2b8f04c9781c --- /dev/null +++ b/tests/ui/invalid_ref.rs @@ -0,0 +1,66 @@ +#![feature(plugin)] +#![plugin(clippy)] + +#![allow(unused)] +#![feature(core_intrinsics)] + +extern crate core; +use std::intrinsics::{init, uninit}; + +fn main() { + let x = 1; + unsafe { + ref_to_zeroed_std(&x); + ref_to_zeroed_core(&x); + ref_to_zeroed_intr(&x); + ref_to_uninit_std(&x); + ref_to_uninit_core(&x); + ref_to_uninit_intr(&x); + some_ref(); + std_zeroed_no_ref(); + core_zeroed_no_ref(); + intr_init_no_ref(); + } +} + +unsafe fn ref_to_zeroed_std(t: &T) { + let ref_zero: &T = std::mem::zeroed(); // warning +} + +unsafe fn ref_to_zeroed_core(t: &T) { + let ref_zero: &T = core::mem::zeroed(); // warning +} + +unsafe fn ref_to_zeroed_intr(t: &T) { + let ref_zero: &T = std::intrinsics::init(); // warning +} + +unsafe fn ref_to_uninit_std(t: &T) { + let ref_uninit: &T = std::mem::uninitialized(); // warning +} + +unsafe fn ref_to_uninit_core(t: &T) { + let ref_uninit: &T = core::mem::uninitialized(); // warning +} + +unsafe fn ref_to_uninit_intr(t: &T) { + let ref_uninit: &T = std::intrinsics::uninit(); // warning +} + +fn some_ref() { + let some_ref = &1; +} + +unsafe fn std_zeroed_no_ref() { + let mem_zero: usize = std::mem::zeroed(); // no warning +} + +unsafe fn core_zeroed_no_ref() { + let mem_zero: usize = core::mem::zeroed(); // no warning +} + +unsafe fn intr_init_no_ref() { + let mem_zero: usize = std::intrinsics::init(); // no warning +} + + diff --git a/tests/ui/invalid_ref.stderr b/tests/ui/invalid_ref.stderr new file mode 100644 index 000000000000..18064c91a017 --- /dev/null +++ b/tests/ui/invalid_ref.stderr @@ -0,0 +1,51 @@ +warning: running cargo clippy on a crate that also imports the clippy plugin + +error: reference to zeroed memory + --> $DIR/invalid_ref.rs:27:24 + | +27 | let ref_zero: &T = std::mem::zeroed(); // warning + | ^^^^^^^^^^^^^^^^^^ + | + = note: `-D invalid-ref` implied by `-D warnings` + = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html + +error: reference to zeroed memory + --> $DIR/invalid_ref.rs:31:24 + | +31 | let ref_zero: &T = core::mem::zeroed(); // warning + | ^^^^^^^^^^^^^^^^^^^ + | + = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html + +error: reference to zeroed memory + --> $DIR/invalid_ref.rs:35:24 + | +35 | let ref_zero: &T = std::intrinsics::init(); // warning + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html + +error: reference to uninitialized memory + --> $DIR/invalid_ref.rs:39:26 + | +39 | let ref_uninit: &T = std::mem::uninitialized(); // warning + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html + +error: reference to uninitialized memory + --> $DIR/invalid_ref.rs:43:26 + | +43 | let ref_uninit: &T = core::mem::uninitialized(); // warning + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html + +error: reference to uninitialized memory + --> $DIR/invalid_ref.rs:47:26 + | +47 | let ref_uninit: &T = std::intrinsics::uninit(); // warning + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html + diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index 8d8e7bd8de11..5bf0bfdcb983 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(invalid_upcast_comparisons)] #![allow(unused, eq_op, no_effect, unnecessary_operation, cast_lossless)] diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr index eb46802899e7..3f11c3730745 100644 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -162,5 +162,3 @@ error: because of the numeric bounds on `u8` prior to casting, this expression i 78 | -5 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^ -error: aborting due to 27 previous errors - diff --git a/tests/ui/is_unit_expr.rs b/tests/ui/is_unit_expr.rs index 164e391ff242..24a2587dc534 100644 --- a/tests/ui/is_unit_expr.rs +++ b/tests/ui/is_unit_expr.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(unit_expr)] #[allow(unused_variables)] diff --git a/tests/ui/is_unit_expr.stderr b/tests/ui/is_unit_expr.stderr index 2d9fcfff74f8..5524f866488c 100644 --- a/tests/ui/is_unit_expr.stderr +++ b/tests/ui/is_unit_expr.stderr @@ -51,5 +51,3 @@ note: Consider removing the trailing semicolon 42 | x; | ^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/item_after_statement.rs b/tests/ui/item_after_statement.rs index e3e4a4c75783..710a1adca565 100644 --- a/tests/ui/item_after_statement.rs +++ b/tests/ui/item_after_statement.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(items_after_statements)] fn ok() { diff --git a/tests/ui/item_after_statement.stderr b/tests/ui/item_after_statement.stderr index ec1296caf83e..e98e7ee129d8 100644 --- a/tests/ui/item_after_statement.stderr +++ b/tests/ui/item_after_statement.stderr @@ -12,5 +12,3 @@ error: adding items after statements is confusing, since items exist from the st 17 | fn foo() { println!("foo"); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs index 65bcdc7435e8..5d0fb11dbea5 100644 --- a/tests/ui/large_digit_groups.rs +++ b/tests/ui/large_digit_groups.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(large_digit_groups)] #[allow(unused_variables)] fn main() { diff --git a/tests/ui/large_digit_groups.stderr b/tests/ui/large_digit_groups.stderr index 6fc285274a0b..db49ded1d8a0 100644 --- a/tests/ui/large_digit_groups.stderr +++ b/tests/ui/large_digit_groups.stderr @@ -47,5 +47,3 @@ error: digit groups should be smaller | = help: consider: 123_456.123_456_f32 -error: aborting due to 6 previous errors - diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 31a7760aa19c..aaf3e2924b31 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code)] #![allow(unused_variables)] diff --git a/tests/ui/large_enum_variant.stderr b/tests/ui/large_enum_variant.stderr index bb889087095b..899a84edeaad 100644 --- a/tests/ui/large_enum_variant.stderr +++ b/tests/ui/large_enum_variant.stderr @@ -68,5 +68,3 @@ help: consider boxing the large fields to reduce the total size of the enum 49 | StructLikeLarge2 { x: Box<[i32; 8000]> }, | ^^^^^^^^^^^^^^^^ -error: aborting due to 6 previous errors - diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index 9c66d5a8148a..aba1dd3055af 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(len_without_is_empty, len_zero)] #![allow(dead_code, unused)] diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index 6e3cf1b3ca1d..d23a972dddcb 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -94,5 +94,3 @@ error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_e 191 | | } | |_^ -error: aborting due to 12 previous errors - diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index 2d3ab7da9964..564a67d2c8ef 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused_variables, unused_assignments, similar_names, blacklisted_name)] #![warn(useless_let_if_seq)] diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index b912373f95c6..39686a9dd07f 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -46,5 +46,3 @@ error: `if _ { .. } else { .. }` is an expression | = note: you might not need `mut` at all -error: aborting due to 4 previous errors - diff --git a/tests/ui/let_return.rs b/tests/ui/let_return.rs index 6aab70dbd8a4..1083603b2d63 100644 --- a/tests/ui/let_return.rs +++ b/tests/ui/let_return.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused)] #![warn(let_and_return)] diff --git a/tests/ui/let_return.stderr b/tests/ui/let_return.stderr index 459b2eafa26f..b38c9ab2e913 100644 --- a/tests/ui/let_return.stderr +++ b/tests/ui/let_return.stderr @@ -23,5 +23,3 @@ note: this expression can be directly returned 15 | let x = 5; | ^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index d07cf8ede2f4..032dc85f2cd5 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(let_unit_value)] #![allow(unused_variables)] diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index da579ec80f31..196afc0570cd 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -12,5 +12,3 @@ error: this let-binding has unit value. Consider omitting `let _a =` 18 | let _a = (); | ^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/lifetimes.rs b/tests/ui/lifetimes.rs index 5f3c3604d809..dce9c23da686 100644 --- a/tests/ui/lifetimes.rs +++ b/tests/ui/lifetimes.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(needless_lifetimes, unused_lifetimes)] #![allow(dead_code, needless_pass_by_value)] diff --git a/tests/ui/lifetimes.stderr b/tests/ui/lifetimes.stderr index 23b353d13d2e..744e1ce21ec3 100644 --- a/tests/ui/lifetimes.stderr +++ b/tests/ui/lifetimes.stderr @@ -86,5 +86,3 @@ error: explicit lifetimes given in parameter types where they could be elided 120 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 14 previous errors - diff --git a/tests/ui/lint_pass.rs b/tests/ui/lint_pass.rs index 5ecbeb7f11a6..1990e137e678 100644 --- a/tests/ui/lint_pass.rs +++ b/tests/ui/lint_pass.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] + #![feature(rustc_private)] -#![plugin(clippy)] + #![warn(lint_without_lint_pass)] diff --git a/tests/ui/lint_pass.stderr b/tests/ui/lint_pass.stderr index 2f9a6813b96d..66f2d62ed24a 100644 --- a/tests/ui/lint_pass.stderr +++ b/tests/ui/lint_pass.stderr @@ -6,5 +6,3 @@ error: the lint `MISSING_LINT` is not added to any `LintPass` | = note: `-D lint-without-lint-pass` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index e8105a74b5cf..c11adc0b0904 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(mixed_case_hex_literals)] #![warn(unseparated_literal_suffix)] #![warn(zero_prefixed_literal)] diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 17210b6b275a..82c651e62902 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -87,5 +87,3 @@ help: if you mean to use an octal constant, use `0o` 30 | let fail8 = 0o123; | ^^^^^ -error: aborting due to 11 previous errors - diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 81e298390f57..f11d21d2dfaf 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(map_clone)] #![allow(clone_on_copy, unused)] diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index c29f37918517..272b868a278a 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -98,5 +98,3 @@ error: you seem to be using .map() to clone the contents of an Option, consider = help: try x.as_ref().cloned() -error: aborting due to 11 previous errors - diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs index be1ca72aece6..f97038ca1f04 100644 --- a/tests/ui/matches.rs +++ b/tests/ui/matches.rs @@ -1,7 +1,7 @@ -#![feature(plugin)] + #![feature(exclusive_range_pattern)] -#![plugin(clippy)] + #![warn(clippy)] #![allow(unused, if_let_redundant_pattern_matching)] #![warn(single_match_else)] diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index 2f55428cca7c..1c2452c46ce6 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -392,5 +392,3 @@ note: consider refactoring into `Ok(3) | Ok(_)` | ^^^^^^^^^^^^^^ = note: this error originates in a macro outside of the current crate -error: aborting due to 33 previous errors - diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index 7854a3739680..991a402e2076 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + use std::sync::Arc; diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 6e7a44694e14..c79afa829fe5 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -18,5 +18,3 @@ error: usage of mem::forget on Drop type 24 | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index 48132cc662cc..08ff47714205 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] + #![feature(const_fn)] -#![plugin(clippy)] + #![warn(clippy, clippy_pedantic)] #![allow(blacklisted_name, unused, print_stdout, non_ascii_literal, new_without_default, new_without_default_derive, missing_docs_in_private_items)] diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index 7f3d505a3cd2..c5fab711fe1f 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -836,5 +836,3 @@ error: you should use the `ends_with` method 578 | Some(' ') != "".chars().next_back(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` -error: aborting due to 123 previous errors - diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs index 9a077eae4d92..1199206e42c3 100644 --- a/tests/ui/min_max.rs +++ b/tests/ui/min_max.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] use std::cmp::{min, max}; diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index de4c4e16fa03..e9225f93b5e5 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -42,5 +42,3 @@ error: this min/max combination leads to constant result 30 | max(min(s, "Apple"), "Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 7 previous errors - diff --git a/tests/ui/missing-doc.rs b/tests/ui/missing-doc.rs index 596cec886f4e..cbd6439d47e8 100644 --- a/tests/ui/missing-doc.rs +++ b/tests/ui/missing-doc.rs @@ -11,8 +11,8 @@ * except according to those terms. */ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(missing_docs_in_private_items)] // When denying at the crate level, be sure to not get random warnings from the diff --git a/tests/ui/missing-doc.stderr b/tests/ui/missing-doc.stderr index e25edb64181e..55eab4f5d692 100644 --- a/tests/ui/missing-doc.stderr +++ b/tests/ui/missing-doc.stderr @@ -270,5 +270,3 @@ error: missing documentation for a function 202 | fn main() {} | ^^^^^^^^^^^^ -error: aborting due to 40 previous errors - diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs index e934c64023b4..77bd446c569c 100644 --- a/tests/ui/module_inception.rs +++ b/tests/ui/module_inception.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(module_inception)] mod foo { diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr index c9d3319db1b6..cb6ea951a171 100644 --- a/tests/ui/module_inception.stderr +++ b/tests/ui/module_inception.stderr @@ -16,5 +16,3 @@ error: module has the same name as its containing module 14 | | } | |_____^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index cda3f190f1e6..847ea1d9ab64 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(modulo_one)] #![allow(no_effect, unnecessary_operation)] diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index ccfca7154e04..48cfe6c38cc2 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -6,5 +6,3 @@ error: any number modulo 1 will be 0 | = note: `-D modulo-one` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs index 55498bad7597..9e757155260c 100644 --- a/tests/ui/mut_from_ref.rs +++ b/tests/ui/mut_from_ref.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused)] #![warn(mut_from_ref)] diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index a7cbc0b7a096..eacda70ce074 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -59,5 +59,3 @@ note: immutable borrow here 32 | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^ ^^^^^^^ -error: aborting due to 5 previous errors - diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs index 766276bc4173..54176cd6d553 100644 --- a/tests/ui/mut_mut.rs +++ b/tests/ui/mut_mut.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused, no_effect, unnecessary_operation)] #![warn(mut_mut)] diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index dd3a85c97760..31f9178aa272 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -27,12 +27,6 @@ error: this expression mutably borrows a mutable reference. Consider reborrowing 26 | let mut y = &mut x; | ^^^^^^ -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:30:17 - | -30 | let y : &mut &mut u32 = &mut &mut 2; - | ^^^^^^^^^^^^^ - error: generally you want to avoid `&mut &mut _` if possible --> $DIR/mut_mut.rs:30:33 | @@ -46,16 +40,10 @@ error: generally you want to avoid `&mut &mut _` if possible | ^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:35:17 + --> $DIR/mut_mut.rs:30:17 | -35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:35:22 - | -35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^ +30 | let y : &mut &mut u32 = &mut &mut 2; + | ^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible --> $DIR/mut_mut.rs:35:38 @@ -75,11 +63,21 @@ error: generally you want to avoid `&mut &mut _` if possible 35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^ +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:35:17 + | +35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^^^^^^ + error: generally you want to avoid `&mut &mut _` if possible --> $DIR/mut_mut.rs:35:22 | 35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:35:22 + | +35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^ diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs new file mode 100644 index 000000000000..835ceeedc94d --- /dev/null +++ b/tests/ui/mut_range_bound.rs @@ -0,0 +1,56 @@ +#![feature(plugin)] +#![plugin(clippy)] + +#![allow(unused)] + +fn main() { + mut_range_bound_upper(); + mut_range_bound_lower(); + mut_range_bound_both(); + mut_range_bound_no_mutation(); + immut_range_bound(); + mut_borrow_range_bound(); + immut_borrow_range_bound(); +} + +fn mut_range_bound_upper() { + let mut m = 4; + for i in 0..m { m = 5; } // warning +} + +fn mut_range_bound_lower() { + let mut m = 4; + for i in m..10 { m *= 2; } // warning +} + +fn mut_range_bound_both() { + let mut m = 4; + let mut n = 6; + for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound) +} + +fn mut_range_bound_no_mutation() { + let mut m = 4; + for i in 0..m { continue; } // no warning +} + +fn mut_borrow_range_bound() { + let mut m = 4; + for i in 0..m { + let n = &mut m; // warning + *n += 1; + } +} + +fn immut_borrow_range_bound() { + let mut m = 4; + for i in 0..m { + let n = &m; // should be no warning? + } +} + + +fn immut_range_bound() { + let m = 4; + for i in 0..m { continue; } // no warning +} diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr new file mode 100644 index 000000000000..f516ec9d95e3 --- /dev/null +++ b/tests/ui/mut_range_bound.stderr @@ -0,0 +1,34 @@ +warning: running cargo clippy on a crate that also imports the clippy plugin + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:18:21 + | +18 | for i in 0..m { m = 5; } // warning + | ^^^^^ + | + = note: `-D mut-range-bound` implied by `-D warnings` + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:23:22 + | +23 | for i in m..10 { m *= 2; } // warning + | ^^^^^^ + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:29:21 + | +29 | for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound) + | ^^^^^ + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:29:28 + | +29 | for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound) + | ^^^^^ + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:40:22 + | +40 | let n = &mut m; // warning + | ^ + diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index d746fc5e529c..ac40bf2a1867 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused_variables)] diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index 73df19bf1583..6708bca8b2ee 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -18,5 +18,3 @@ error: The function/method `takes_an_immutable_reference` doesn't need a mutable 28 | my_struct.takes_an_immutable_reference(&mut 42); | ^^^^^^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/mutex_atomic.rs b/tests/ui/mutex_atomic.rs index b84ece497eb6..96502738456c 100644 --- a/tests/ui/mutex_atomic.rs +++ b/tests/ui/mutex_atomic.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![warn(mutex_integer)] diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 354f9891c178..d46c713164ae 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -44,5 +44,3 @@ error: Consider using an AtomicIsize instead of a Mutex here. If you just want t 16 | Mutex::new(0i32); | ^^^^^^^^^^^^^^^^ -error: aborting due to 7 previous errors - diff --git a/tests/ui/needless_bool.rs b/tests/ui/needless_bool.rs index bd44332a1708..1213539c8276 100644 --- a/tests/ui/needless_bool.rs +++ b/tests/ui/needless_bool.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(needless_bool)] #[allow(if_same_then_else)] diff --git a/tests/ui/needless_bool.stderr b/tests/ui/needless_bool.stderr index 63e0632445f6..a25b34bfaafa 100644 --- a/tests/ui/needless_bool.stderr +++ b/tests/ui/needless_bool.stderr @@ -66,5 +66,3 @@ error: this if-then-else expression returns a bool literal 50 | if x && y { return false } else { return true }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `return !(x && y)` -error: aborting due to 11 previous errors - diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 23d935e7df8c..78c1a125c94f 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + fn x(y: &i32) -> i32 { *y diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index fde38508b323..16962bb48f1c 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -38,5 +38,3 @@ error: this pattern creates a reference to a reference 50 | let _ = v.iter().filter(|&ref a| a.is_empty()); | ^^^^^ help: change this to: `a` -error: aborting due to 6 previous errors - diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index 4e9986561bc1..75ffa211180d 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(needless_borrowed_reference)] #[allow(unused_variables)] diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr index 2a8cf4348d39..c85bf9f5a7c7 100644 --- a/tests/ui/needless_borrowed_ref.stderr +++ b/tests/ui/needless_borrowed_ref.stderr @@ -24,5 +24,3 @@ error: this pattern takes a reference on something that is being de-referenced 42 | (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref' | ^^^^^^ help: try removing the `&ref` part and just keep: `k` -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 6710867077d2..3574b0fb3fdf 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + macro_rules! zero { ($x:expr) => ($x == 0); diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 3e0368892a43..f63f120fcc7e 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -55,5 +55,3 @@ error: There is no need for an explicit `else` block for this `if` expression println!("Jabber"); ... -error: aborting due to 2 previous errors - diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index ea97e875ff73..6218bfb09206 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(needless_pass_by_value)] #![allow(dead_code, single_match, if_let_redundant_pattern_matching, many_single_char_names)] diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 02293c9cb3cf..c081574127af 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -56,5 +56,3 @@ help: consider taking a reference instead 56 | let Wrapper(_) = *y; // still not moved | -error: aborting due to 7 previous errors - diff --git a/tests/ui/needless_pass_by_value_proc_macro.rs b/tests/ui/needless_pass_by_value_proc_macro.rs index 0d5bc4172d86..652e11fee9d6 100644 --- a/tests/ui/needless_pass_by_value_proc_macro.rs +++ b/tests/ui/needless_pass_by_value_proc_macro.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![crate_type = "proc-macro"] #![warn(needless_pass_by_value)] diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 403e5b8342e8..4739ded7b7ea 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(needless_return)] diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index 42dc6e6594c5..68c2654c8635 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -48,5 +48,3 @@ error: unneeded return statement 39 | let _ = || return true; | ^^^^^^^^^^^ help: remove `return` as shown: `true` -error: aborting due to 8 previous errors - diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 99876121ae77..35d5730dda1e 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(needless_update)] #![allow(no_effect)] diff --git a/tests/ui/needless_update.stderr b/tests/ui/needless_update.stderr index 3e509870d00f..978fd8e625ba 100644 --- a/tests/ui/needless_update.stderr +++ b/tests/ui/needless_update.stderr @@ -6,5 +6,3 @@ error: struct update has no effect, all the fields in the struct have already be | = note: `-D needless-update` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 75dc7c381fdb..367d2d5edfbd 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(neg_multiply)] #![allow(no_effect, unnecessary_operation)] diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr index 1d52ba16eae8..6ed31d384a02 100644 --- a/tests/ui/neg_multiply.stderr +++ b/tests/ui/neg_multiply.stderr @@ -12,5 +12,3 @@ error: Negation by multiplying with -1 32 | -1 * x; | ^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs index ff0126704b54..715a83efd93d 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(single_match, unused_assignments, unused_variables)] fn test1() { @@ -126,6 +126,19 @@ pub fn test12(a: bool, b: bool) { } } +pub fn test13() { + let mut a = true; + loop { // infinite loop + while a { + if true { + a = false; + continue; + } + return; + } + } +} + fn main() { test1(); test2(); @@ -139,5 +152,6 @@ fn main() { test10(); test11(|| 0); test12(true, false); + test13(); } diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index dace2b7e261a..1ecdb5030f93 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -68,5 +68,3 @@ error: this loop never actually loops 103 | | } | |_____^ -error: aborting due to 7 previous errors - diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index a10db135c5e4..9fd0fea137c8 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -1,5 +1,5 @@ #![feature(plugin, const_fn)] -#![plugin(clippy)] + #![allow(dead_code)] #![warn(new_without_default, new_without_default_derive)] diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 91e437a6eb54..0ced183b1e07 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -38,5 +38,3 @@ help: try this 69 | ... -error: aborting due to 3 previous errors - diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 4062b36883a0..1b7da6496bf2 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -1,5 +1,5 @@ #![feature(plugin, box_syntax, inclusive_range_syntax)] -#![plugin(clippy)] + #![warn(no_effect, unnecessary_operation)] #![allow(dead_code)] @@ -71,7 +71,7 @@ fn main() { 5..; ..5; 5..6; - 5...6; + 5..=6; [42, 55]; [42, 55][1]; (42, 55).1; diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index c7c334546ffb..9a161ce96439 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -111,7 +111,7 @@ error: statement with no effect error: statement with no effect --> $DIR/no_effect.rs:74:5 | -74 | 5...6; +74 | 5..=6; | ^^^^^^ error: statement with no effect @@ -266,5 +266,3 @@ error: statement can be reduced 110 | {get_number()}; | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` -error: aborting due to 44 previous errors - diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs index f32dad2080fd..9eb3e5a82a7c 100644 --- a/tests/ui/non_expressive_names.rs +++ b/tests/ui/non_expressive_names.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy,similar_names)] #![allow(unused)] diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr index 780d7d8aec90..014d45992712 100644 --- a/tests/ui/non_expressive_names.stderr +++ b/tests/ui/non_expressive_names.stderr @@ -129,5 +129,3 @@ error: 5th binding whose name is just one char 129 | e => panic!(), | ^ -error: aborting due to 11 previous errors - diff --git a/tests/ui/ok_if_let.rs b/tests/ui/ok_if_let.rs index dda38fec2873..fdc01bcc7bc0 100644 --- a/tests/ui/ok_if_let.rs +++ b/tests/ui/ok_if_let.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(if_let_some_result)] diff --git a/tests/ui/ok_if_let.stderr b/tests/ui/ok_if_let.stderr index e1371d924eb6..b696672d2fd0 100644 --- a/tests/ui/ok_if_let.stderr +++ b/tests/ui/ok_if_let.stderr @@ -11,5 +11,3 @@ error: Matching on `Some` with `ok()` is redundant = note: `-D if-let-some-result` implied by `-D warnings` = help: Consider matching on `Ok(y)` and removing the call to `ok` instead -error: aborting due to previous error - diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index 315e6535ef62..9eb697571b69 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused_variables, blacklisted_name)] @@ -21,4 +21,4 @@ fn main() { if b < &a { println!("OK"); } -} \ No newline at end of file +} diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index 715c7378e0cf..dbe53933fd5e 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -10,5 +10,3 @@ help: use the values directly 13 | let foo = 5 - 6; | ^ -error: aborting due to previous error - diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index c409aa564f8f..514808d41f1e 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + use std::fs::OpenOptions; #[allow(unused_must_use)] diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index f0d419041523..2f4070c2868f 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -42,5 +42,3 @@ error: the method "truncate" is called more than once 15 | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 7 previous errors - diff --git a/tests/ui/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs index a669f741f290..889c339c8fda 100644 --- a/tests/ui/overflow_check_conditional.rs +++ b/tests/ui/overflow_check_conditional.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(many_single_char_names)] #![warn(overflow_check_conditional)] diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr index 8a80dbedaeb4..9f23e96c0655 100644 --- a/tests/ui/overflow_check_conditional.stderr +++ b/tests/ui/overflow_check_conditional.stderr @@ -48,5 +48,3 @@ error: You are trying to use classic C underflow conditions that will fail in Ru 32 | if a < a - b { | ^^^^^^^^^ -error: aborting due to 8 previous errors - diff --git a/tests/ui/panic.rs b/tests/ui/panic.rs index 03d3c3dc2d94..f621a5f636df 100644 --- a/tests/ui/panic.rs +++ b/tests/ui/panic.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(panic_params)] diff --git a/tests/ui/panic.stderr b/tests/ui/panic.stderr index 25113ed80b6e..f2480dfea6ed 100644 --- a/tests/ui/panic.stderr +++ b/tests/ui/panic.stderr @@ -18,5 +18,3 @@ error: you probably are missing some parameter in your format string 12 | assert!(true, "here be missing values: {}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index 41772700109e..36dd4df8a6ec 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code)] diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index 5e536cc51d28..c332ce53c1a4 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -6,5 +6,3 @@ error: re-implementing `PartialEq::ne` is unnecessary | = note: `-D partialeq-ne-impl` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 793b2b111d6d..65e319e2f881 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused)] #![warn(clippy)] diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr index 59bce3a9a8f6..9a246c483b2b 100644 --- a/tests/ui/patterns.stderr +++ b/tests/ui/patterns.stderr @@ -6,5 +6,3 @@ error: the `y @ _` pattern can be written as just `y` | = note: `-D redundant-pattern` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs index c6865632cf72..720637c94b56 100644 --- a/tests/ui/precedence.rs +++ b/tests/ui/precedence.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(precedence)] #[allow(identity_op)] diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr index 9f0e53ffca2b..26fbd75164d1 100644 --- a/tests/ui/precedence.stderr +++ b/tests/ui/precedence.stderr @@ -54,5 +54,3 @@ error: unary minus has lower precedence than method call 16 | -1f32.abs(); | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())` -error: aborting due to 9 previous errors - diff --git a/tests/ui/print.rs b/tests/ui/print.rs index f1fb3cba8c1d..91304d961a7a 100644 --- a/tests/ui/print.rs +++ b/tests/ui/print.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(print_stdout, use_debug)] use std::fmt::{Debug, Display, Formatter, Result}; diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr index 789e1218b780..fa547949bdb5 100644 --- a/tests/ui/print.stderr +++ b/tests/ui/print.stderr @@ -50,5 +50,3 @@ error: use of `Debug`-based formatting 31 | print!("Hello {:#?}", "#orld"); | ^^^^^^^ -error: aborting due to 8 previous errors - diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index d852e375ded0..5cc50dea8104 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(print_with_newline)] fn main() { diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index e69de29bb2d1..2ade3ae4ef59 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -0,0 +1,26 @@ +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:6:5 + | +6 | print!("Hello/n"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: `-D print-with-newline` implied by `-D warnings` + +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:7:5 + | +7 | print!("Hello {}/n", "world"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:8:5 + | +8 | print!("Hello {} {}/n/n", "world", "#2"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:9:5 + | +9 | print!("{}/n", 1265); + | ^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index a386fcf82df7..14b26e168474 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused, many_single_char_names)] #![warn(ptr_arg)] @@ -55,3 +55,15 @@ fn str_cloned(x: &String) -> String { .clone(); x.clone() } + +fn false_positive_capacity(x: &Vec, y: &String) { + let a = x.capacity(); + let b = y.clone(); + let c = y.as_str(); +} + +fn false_positive_capacity_too(x: &String) -> String { + if x.capacity() > 1024 { panic!("Too large!"); } + x.clone() +} + diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 46d7cbdb0310..13be68d4cd42 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -28,11 +28,11 @@ help: change this to | 40 | fn cloned(x: &[u8]) -> Vec { | ^^^^^ -help: change the `.clone()` to +help: change `x.clone()` to | 41 | let e = x.to_owned(); | ^^^^^^^^^^^^ -help: change the `.clone()` to +help: change `x.clone()` to | 46 | x.to_owned() | ^^^^^^^^^^^^ @@ -47,18 +47,35 @@ help: change this to | 49 | fn str_cloned(x: &str) -> String { | ^^^^ -help: change the `.clone` to +help: change `x.clone()` to | 50 | let a = x.to_string(); | ^^^^^^^^^^^^^ -help: change the `.clone` to +help: change `x.clone()` to | 51 | let b = x.to_string(); | ^^^^^^^^^^^^^ -help: change the `.clone` to +help: change `x.clone()` to | 56 | x.to_string() | ^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: writing `&String` instead of `&str` involves a new object where a slice will do. + --> $DIR/ptr_arg.rs:59:44 + | +59 | fn false_positive_capacity(x: &Vec, y: &String) { + | ^^^^^^^ + | +help: change this to + | +59 | fn false_positive_capacity(x: &Vec, y: &str) { + | ^^^^ +help: change `y.clone()` to + | +61 | let b = y.to_string(); + | ^^^^^^^^^^^^^ +help: change `y.as_str()` to + | +62 | let c = y; + | ^ diff --git a/tests/ui/range.rs b/tests/ui/range.rs index 4f4573d9e602..71f2f2b219bd 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -1,7 +1,7 @@ #![feature(iterator_step_by)] #![feature(inclusive_range_syntax)] -#![feature(plugin)] -#![plugin(clippy)] + + struct NotARange; impl NotARange { @@ -15,7 +15,7 @@ fn main() { let _ = (0..1).step_by(1); let _ = (1..).step_by(0); - let _ = (1...2).step_by(0); + let _ = (1..=2).step_by(0); let x = 0..1; let _ = x.step_by(0); diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr index 772375c179b0..4098d32d08e3 100644 --- a/tests/ui/range.stderr +++ b/tests/ui/range.stderr @@ -15,7 +15,7 @@ error: Iterator::step_by(0) will panic at runtime error: Iterator::step_by(0) will panic at runtime --> $DIR/range.rs:18:13 | -18 | let _ = (1...2).step_by(0); +18 | let _ = (1..=2).step_by(0); | ^^^^^^^^^^^^^^^^^^ error: Iterator::step_by(0) will panic at runtime @@ -38,5 +38,3 @@ error: Iterator::step_by(0) will panic at runtime 33 | let _ = v1.iter().step_by(2/3); | ^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 6 previous errors - diff --git a/tests/ui/redundant_closure_call.rs b/tests/ui/redundant_closure_call.rs index 2c079273b7b5..ab3897bc3150 100644 --- a/tests/ui/redundant_closure_call.rs +++ b/tests/ui/redundant_closure_call.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(redundant_closure_call)] diff --git a/tests/ui/redundant_closure_call.stderr b/tests/ui/redundant_closure_call.stderr index e2865edc8705..d8ec72fda92a 100644 --- a/tests/ui/redundant_closure_call.stderr +++ b/tests/ui/redundant_closure_call.stderr @@ -30,5 +30,3 @@ error: Try not to call a closure in the expression where it is declared. 12 | k = (|a,b| a*b)(1,5); | ^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors - diff --git a/tests/ui/reference.rs b/tests/ui/reference.rs index 9451e19e3367..0bd000082e83 100644 --- a/tests/ui/reference.rs +++ b/tests/ui/reference.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + fn get_number() -> usize { 10 diff --git a/tests/ui/reference.stderr b/tests/ui/reference.stderr index 741c0cc10385..2e6b23f6dc0f 100644 --- a/tests/ui/reference.stderr +++ b/tests/ui/reference.stderr @@ -66,5 +66,3 @@ error: immediately dereferencing a reference 53 | let y = **&mut &mut x; | ^^^^^^^^^^^^ help: try this: `&mut x` -error: aborting due to 11 previous errors - diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 56539c5468fc..3dd1f64202c7 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused)] #![warn(invalid_regex, trivial_regex, regex_macro)] diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 1c3a47b82be7..1c244c1df127 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -149,5 +149,3 @@ error: trivial regex | = help: consider using consider using `str::is_empty` -error: aborting due to 21 previous errors - diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index 61c691c01c1d..792ebc9b0ea1 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(serde_api_misuse)] #![allow(dead_code)] diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index 58667e0f820b..da0a96b2a3dc 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -10,5 +10,3 @@ error: you should not implement `visit_string` without also implementing `visit_ | = note: `-D serde-api-misuse` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index e1f2ffacf496..fbe695a7657c 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy, clippy_pedantic)] #![allow(unused_parens, unused_variables, missing_docs_in_private_items)] diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr index 3fc2b7234f78..50f41627acbf 100644 --- a/tests/ui/shadow.stderr +++ b/tests/ui/shadow.stderr @@ -134,5 +134,3 @@ note: previous binding is here 21 | let x = y; | ^ -error: aborting due to 9 previous errors - diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index e783c6e5e690..0f5773623be3 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(short_circuit_statement)] diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr index 7697cbd1c64c..d7a02d7b9c3c 100644 --- a/tests/ui/short_circuit_statement.stderr +++ b/tests/ui/short_circuit_statement.stderr @@ -18,5 +18,3 @@ error: boolean short circuit operator in statement may be clearer using an expli 9 | 1 == 2 || g(); | ^^^^^^^^^^^^^^ help: replace it with: `if !(1 == 2) { g(); }` -error: aborting due to 3 previous errors - diff --git a/tests/ui/should_assert_eq.rs b/tests/ui/should_assert_eq.rs index ac5fca8dd0b3..5814e9977530 100644 --- a/tests/ui/should_assert_eq.rs +++ b/tests/ui/should_assert_eq.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(needless_pass_by_value)] #![warn(should_assert_eq)] diff --git a/tests/ui/should_assert_eq.stderr b/tests/ui/should_assert_eq.stderr index 57abf8004988..5b393e1dbe87 100644 --- a/tests/ui/should_assert_eq.stderr +++ b/tests/ui/should_assert_eq.stderr @@ -55,5 +55,3 @@ error: use `assert_ne` for better reporting | = note: this error originates in a macro outside of the current crate -error: aborting due to 7 previous errors - diff --git a/tests/ui/strings.rs b/tests/ui/strings.rs index 1cb5619dd1da..66d24a3c0702 100644 --- a/tests/ui/strings.rs +++ b/tests/ui/strings.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(string_add)] #[allow(string_add_assign)] diff --git a/tests/ui/strings.stderr b/tests/ui/strings.stderr index d098ce9df5ea..a8fd59e12b27 100644 --- a/tests/ui/strings.stderr +++ b/tests/ui/strings.stderr @@ -72,5 +72,3 @@ error: manual implementation of an assign operation 65 | ; x = x + 1; | ^^^^^^^^^ help: replace it with: `x += 1` -error: aborting due to 11 previous errors - diff --git a/tests/ui/stutter.rs b/tests/ui/stutter.rs index 3fd410c08afd..24612fd3b3ef 100644 --- a/tests/ui/stutter.rs +++ b/tests/ui/stutter.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(stutter)] #![allow(dead_code)] diff --git a/tests/ui/stutter.stderr b/tests/ui/stutter.stderr index b68f561b483c..38cbcaa32f59 100644 --- a/tests/ui/stutter.stderr +++ b/tests/ui/stutter.stderr @@ -24,5 +24,3 @@ error: item name ends with its containing module's name 11 | pub enum CakeFoo {} | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors - diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index abcafac4b9db..d1d12641c46a 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(blacklisted_name, unused_assignments)] diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index a01ec375e639..0bda9bc8d2b9 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -65,5 +65,3 @@ error: this looks like you are trying to swap `c.0` and `a` | = note: or maybe you should use `std::mem::replace`? -error: aborting due to 7 previous errors - diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index 4a12d38285cf..8f25aad72bb5 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(temporary_assignment)] diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 979720c914d1..73a4818ba160 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -12,5 +12,3 @@ error: assignment to temporary 30 | (0, 0).0 = 1; | ^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index 7be52580c6f9..a0d6dd2dabd5 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -1,6 +1,6 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(unused)] diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index f360e85329f5..525b181bf91a 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -30,5 +30,3 @@ error: `ref` on an entire `let` pattern is discouraged, take a reference with `& 24 | let ref mut z = 1 + 2; | ----^^^^^^^^^--------- help: try: `let z = &mut (1 + 2);` -error: aborting due to 5 previous errors - diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index 40f588cecef2..6a7b6b05e701 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -1,5 +1,5 @@ #![feature(plugin, custom_attribute, stmt_expr_attributes)] -#![plugin(clippy)] + #![allow(unused_parens)] fn main() { @@ -7,4 +7,5 @@ fn main() { let _ = #[clippy(author)] (x & 0b1111 == 0); // suggest trailing_zeros let _ = x & 0b1_1111 == 0; // suggest trailing_zeros let _ = x & 0b1_1010 == 0; // do not lint + let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 91e4d59da986..0a4b5361d862 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -12,5 +12,3 @@ error: bit mask could be simplified with a call to `trailing_zeros` 8 | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` -error: aborting due to 2 previous errors - diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index a83e5194736f..81582b5a15fa 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code)] @@ -118,4 +118,21 @@ fn crosspointer() { } } +#[warn(transmute_int_to_char)] +fn int_to_char() { + let _: char = unsafe { std::mem::transmute(0_u32) }; + let _: char = unsafe { std::mem::transmute(0_i32) }; +} + +#[warn(transmute_int_to_bool)] +fn int_to_bool() { + let _: bool = unsafe { std::mem::transmute(0_u8) }; +} + +#[warn(transmute_int_to_float)] +fn int_to_float() { + let _: f32 = unsafe { std::mem::transmute(0_u32) }; + let _: f32 = unsafe { std::mem::transmute(0_i32) }; +} + fn main() { } diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index a571fed24f05..c81ec5260be2 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -154,5 +154,39 @@ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) 117 | let _: *mut Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 25 previous errors +error: transmute from a `u32` to a `char` + --> $DIR/transmute.rs:123:28 + | +123 | let _: char = unsafe { std::mem::transmute(0_u32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32)` + | + = note: `-D transmute-int-to-char` implied by `-D warnings` + +error: transmute from a `i32` to a `char` + --> $DIR/transmute.rs:124:28 + | +124 | let _: char = unsafe { std::mem::transmute(0_i32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32)` + +error: transmute from a `u8` to a `bool` + --> $DIR/transmute.rs:129:28 + | +129 | let _: bool = unsafe { std::mem::transmute(0_u8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` + | + = note: `-D transmute-int-to-bool` implied by `-D warnings` + +error: transmute from a `u32` to a `f32` + --> $DIR/transmute.rs:134:27 + | +134 | let _: f32 = unsafe { std::mem::transmute(0_u32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` + | + = note: `-D transmute-int-to-float` implied by `-D warnings` + +error: transmute from a `i32` to a `f32` + --> $DIR/transmute.rs:135:27 + | +135 | let _: f32 = unsafe { std::mem::transmute(0_i32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` diff --git a/tests/ui/transmute_32bit.rs b/tests/ui/transmute_32bit.rs index 4f9555297ff3..08866c63ec6f 100644 --- a/tests/ui/transmute_32bit.rs +++ b/tests/ui/transmute_32bit.rs @@ -1,6 +1,6 @@ //ignore-x86_64 -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(wrong_transmute)] fn main() { diff --git a/tests/ui/transmute_64bit.rs b/tests/ui/transmute_64bit.rs index 9be1e37b13e1..65240c80a480 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -1,7 +1,7 @@ //ignore-x86 //no-ignore-x86_64 -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(wrong_transmute)] fn main() { diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index 3a6a6e73f575..b679b9138771 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -12,5 +12,3 @@ error: transmute from a `f64` to a pointer 11 | let _: *mut usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index 55dd0862700d..5bb0e7edfeda 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(zero_width_space)] fn zero() { diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 8a173daec9da..73599235ea81 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -28,5 +28,3 @@ error: literal non-ASCII character detected = help: Consider replacing the string with: ""/u{dc}ben!"" -error: aborting due to 3 previous errors - diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index ff57d2822cba..2b6d757845fe 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(unit_cmp)] #![allow(no_effect, unnecessary_operation)] diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 51ad3fca9479..a85e4150a3eb 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -12,5 +12,3 @@ error: >-comparison of unit values detected. This will always be false 19 | if { true; } > { false; } { | ^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors - diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index c2f5b11e24cd..8c9606022642 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(unneeded_field_pattern)] #[allow(dead_code, unused)] diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr index 7e4c3a6cb9cb..ef1a8d75732e 100644 --- a/tests/ui/unneeded_field_pattern.stderr +++ b/tests/ui/unneeded_field_pattern.stderr @@ -15,5 +15,3 @@ error: All the struct fields are matched to a wildcard pattern, consider using ` | = help: Try with `Foo { .. }` instead -error: aborting due to 2 previous errors - diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 45daf70b171a..327fea254a8c 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[warn(unreadable_literal)] #[allow(unused_variables)] fn main() { diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index 72cb160fafcb..81b69937a6da 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -31,5 +31,3 @@ error: long literal lacking separators | = help: consider: 1.234_56_f32 -error: aborting due to 4 previous errors - diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index 8e90964da8cc..29f34d31a8e9 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused_imports)] #![allow(dead_code)] #![warn(unsafe_removed_from_name)] diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr index 93f2ddd533fe..7d455d31bcec 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -18,5 +18,3 @@ error: removed "unsafe" from the name of `Unsafe` in use as `LieAboutModSafety` 23 | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index 9beec63a6f01..ea72c1b1b704 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(dead_code)] #![warn(unused_io_amount)] diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 0ce6887f5f20..8739ac245a79 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -39,5 +39,3 @@ error: handle read amount returned or use `Read::read_exact` instead 27 | s.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 6 previous errors - diff --git a/tests/ui/unused_labels.rs b/tests/ui/unused_labels.rs index 6d1e8c2a31c5..115121dc2757 100644 --- a/tests/ui/unused_labels.rs +++ b/tests/ui/unused_labels.rs @@ -1,5 +1,5 @@ -#![plugin(clippy)] -#![feature(plugin)] + + #![allow(dead_code, items_after_statements, never_loop)] #![warn(unused_label)] diff --git a/tests/ui/unused_labels.stderr b/tests/ui/unused_labels.stderr index 19c91e2a6a3c..338eb2f1551f 100644 --- a/tests/ui/unused_labels.stderr +++ b/tests/ui/unused_labels.stderr @@ -22,5 +22,3 @@ error: unused label `'same_label_in_two_fns` 34 | | } | |_____^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/unused_lt.rs b/tests/ui/unused_lt.rs index 722e19e6217c..91bca47eb12c 100644 --- a/tests/ui/unused_lt.rs +++ b/tests/ui/unused_lt.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![allow(unused, dead_code, needless_lifetimes, needless_pass_by_value)] #![warn(unused_lifetimes)] diff --git a/tests/ui/unused_lt.stderr b/tests/ui/unused_lt.stderr index b1fcebe6eed5..a4f01de18f7b 100644 --- a/tests/ui/unused_lt.stderr +++ b/tests/ui/unused_lt.stderr @@ -18,5 +18,3 @@ error: this lifetime isn't used in the function definition 50 | fn x<'a>(&self) {} | ^^ -error: aborting due to 3 previous errors - diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 14e31aae8ee5..b12900b7691a 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(use_self)] #![allow(dead_code)] #![allow(should_implement_trait)] diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index bfd334335d88..9d316dd3e083 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -36,5 +36,3 @@ error: unnecessary structure name repetition 24 | Foo::new() | ^^^^^^^^ help: use the applicable keyword: `Self` -error: aborting due to 6 previous errors - diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index d8fc7c7cbca3..60a2c4e8b4c9 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(clippy)] #![allow(blacklisted_name)] diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr index 712f81c1b6ff..388a3491477d 100644 --- a/tests/ui/used_underscore_binding.stderr +++ b/tests/ui/used_underscore_binding.stderr @@ -30,5 +30,3 @@ error: used binding `_underscore_field` which is prefixed with an underscore. A 36 | s._underscore_field += 1; | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors - diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index cd2636a5b6f9..4c2fb221af8e 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(useless_attribute)] #[allow(dead_code, unused_extern_crates)] diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index 707a11d55cc6..0bb87f8c5389 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -6,5 +6,3 @@ error: useless lint attribute | = note: `-D useless-attribute` implied by `-D warnings` -error: aborting due to previous error - diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs index 1845b509af0d..23e438724540 100644 --- a/tests/ui/vec.rs +++ b/tests/ui/vec.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(useless_vec)] diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr index 6a47eb5b064e..a1555bc79073 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/vec.stderr @@ -36,5 +36,3 @@ error: useless use of `vec!` 49 | for a in vec![1, 2, 3] { | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` -error: aborting due to 6 previous errors - diff --git a/tests/ui/while_loop.rs b/tests/ui/while_loop.rs index 9bae1bc48e6a..b7ef39da8175 100644 --- a/tests/ui/while_loop.rs +++ b/tests/ui/while_loop.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(while_let_loop, empty_loop, while_let_on_iterator)] #![allow(dead_code, never_loop, unused, cyclomatic_complexity)] diff --git a/tests/ui/while_loop.stderr b/tests/ui/while_loop.stderr index 689c92d6fb69..edc88405c40e 100644 --- a/tests/ui/while_loop.stderr +++ b/tests/ui/while_loop.stderr @@ -110,5 +110,3 @@ error: this loop could be written as a `for` loop 184 | | } | |_________^ help: try: `for v in y { .. }` -error: aborting due to 11 previous errors - diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index 91b60c8faaa2..bef87e2bb010 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #![warn(wrong_self_convention)] #![warn(wrong_pub_self_convention)] diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index 216fd0bb82b8..e57ffc3266b9 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -72,5 +72,3 @@ error: methods called `from_*` usually take no self; consider choosing a less am 54 | pub fn from_i64(self) {} | ^^^^ -error: aborting due to 12 previous errors - diff --git a/tests/ui/zero_div_zero.rs b/tests/ui/zero_div_zero.rs index af61e1c84299..65e1e2399803 100644 --- a/tests/ui/zero_div_zero.rs +++ b/tests/ui/zero_div_zero.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[allow(unused_variables)] #[warn(zero_divided_by_zero)] diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index b81e59c07f15..697432af4087 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -57,5 +57,3 @@ error: constant division of 0.0 with 0.0 will always result in NaN | = help: Consider using `std::f64::NAN` if you would like a constant representing NaN -error: aborting due to 8 previous errors - diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs index a72223ef54c1..4a6010f4bd0b 100644 --- a/tests/ui/zero_ptr.rs +++ b/tests/ui/zero_ptr.rs @@ -1,5 +1,5 @@ -#![feature(plugin)] -#![plugin(clippy)] + + #[allow(unused_variables)] fn main() { diff --git a/tests/ui/zero_ptr.stderr b/tests/ui/zero_ptr.stderr index 5155dc401bd1..fb87a47536e0 100644 --- a/tests/ui/zero_ptr.stderr +++ b/tests/ui/zero_ptr.stderr @@ -12,5 +12,3 @@ error: `0 as *mut _` detected. Consider using `ptr::null_mut()` 7 | let y = 0 as *mut f64; | ^^^^^^^^^^^^^ -error: aborting due to 2 previous errors -