From 6a66c9fe64ee25e7e223b0841949cc9ec3128703 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 25 Oct 2019 10:41:05 +0700 Subject: [PATCH 1/5] git quiet --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index a2a67e66e6144..0b80230b61deb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ dist: xenial language: bash +git: + depth: 1 + quiet: true branches: # Don't build these branches From 83b90d8a86c8886186a84ca2370a49a184874022 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 25 Oct 2019 20:09:28 +0700 Subject: [PATCH 2/5] remove needless my_lint ui test --- tests/ui/my_lint.rs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/ui/my_lint.rs diff --git a/tests/ui/my_lint.rs b/tests/ui/my_lint.rs deleted file mode 100644 index c27fd5be13452..0000000000000 --- a/tests/ui/my_lint.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[clippy::author] -#[cfg(any(target_arch = "x86"))] -pub struct Foo { - x: u32, -} - -fn main() {} From 94aa0398c2af9cedfed6edc0f5d0eb4cdd07dbc0 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 26 Oct 2019 00:16:14 +0700 Subject: [PATCH 3/5] build: set up build job for i686 targets --- .travis.yml | 12 +++++++++++- ci/base-tests.sh | 4 ---- setup-toolchain.sh | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0b80230b61deb..41d19b209b6dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ env: - secure: "OKulfkA5OGd/d1IhvBKzRkHQwMcWjzrzbimo7+5NhkUkWxndAzl+719TB3wWvIh1i2wXXrEXsyZkXM5FtRrHm55v1VKQ5ibjEvFg1w3NIg81iDyoLq186fLqywvxGkOAFPrsePPsBj5USd5xvhwwbrjO6L7/RK6Z8shBwOSc41s=" before_install: + - export CARGO_TARGET_DIR="$TRAVIS_BUILD_DIR/target" - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly --profile=minimal - export PATH="$HOME/.cargo/bin:$PATH" install: @@ -51,6 +52,15 @@ matrix: include: # Builds that are executed for every PR - os: linux + # i686 toolchain could run on x86_64 system. + - os: linux + env: HOST_TOOLCHAIN=i686-unknown-linux-gnu + addons: + apt: + packages: + - gcc-multilib + - libssl-dev:i386 # openssl dev in Cargo.toml + if: branch IN (auto, try) - os: windows env: CARGO_INCREMENTAL=0 OS_WINDOWS=true @@ -117,7 +127,7 @@ before_script: SYSROOT=$(rustc --print sysroot) case "$TRAVIS_OS_NAME" in windows ) export PATH="${SYSROOT}/bin:${PATH}" ;; - linux ) export LD_LIBRARY_PATH="${SYSROOT}/lib" ;; + linux ) export LD_LIBRARY_PATH="${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" ;; osx ) # See sudo mkdir -p /usr/local/lib diff --git a/ci/base-tests.sh b/ci/base-tests.sh index d3fd262b60049..010c8919752f0 100755 --- a/ci/base-tests.sh +++ b/ci/base-tests.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash set -ex -# for faster build, share target dir between subcrates -CARGO_TARGET_DIR=$(pwd)/target/ -export CARGO_TARGET_DIR - echo "Running clippy base tests" PATH=$PATH:./node_modules/.bin diff --git a/setup-toolchain.sh b/setup-toolchain.sh index 2388f94ae66b7..88ae90581e568 100755 --- a/setup-toolchain.sh +++ b/setup-toolchain.sh @@ -26,5 +26,11 @@ if rustc +master -Vv 2>/dev/null | grep -q "$RUST_COMMIT"; then exit 0 fi -rustup-toolchain-install-master -f -n master -c rustc-dev -- "$RUST_COMMIT" +if [[ -n "$HOST_TOOLCHAIN" ]]; then + TOOLCHAIN=('--host' "$HOST_TOOLCHAIN") +else + TOOLCHAIN=() +fi + +rustup-toolchain-install-master -f -n master "${TOOLCHAIN[@]}" -c rustc-dev -- "$RUST_COMMIT" rustup override set master From 142b289a5184347f9f22c07a524faa937281e7f6 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 25 Oct 2019 22:17:13 +0700 Subject: [PATCH 4/5] chore: fix and split some ui tests on 32bit system --- clippy_lints/src/enum_clike.rs | 1 + tests/ui/cast_size.rs | 1 + tests/ui/cast_size.stderr | 36 +++--- tests/ui/cast_size_32bit.rs | 35 ++++++ tests/ui/cast_size_32bit.stderr | 132 +++++++++++++++++++++ tests/ui/fn_to_numeric_cast.rs | 2 +- tests/ui/fn_to_numeric_cast_32bit.rs | 55 +++++++++ tests/ui/fn_to_numeric_cast_32bit.stderr | 144 +++++++++++++++++++++++ tests/ui/large_digit_groups.fixed | 11 +- tests/ui/large_digit_groups.rs | 11 +- tests/ui/large_digit_groups.stderr | 8 +- tests/ui/transmute_32bit.rs | 4 +- tests/ui/transmute_32bit.stderr | 28 +++++ tests/ui/transmute_64bit.rs | 3 +- tests/ui/transmute_64bit.stderr | 4 +- tests/ui/unreadable_literal.fixed | 20 ++-- tests/ui/unreadable_literal.rs | 20 ++-- tests/ui/unreadable_literal.stderr | 54 ++++----- 18 files changed, 482 insertions(+), 87 deletions(-) create mode 100644 tests/ui/cast_size_32bit.rs create mode 100644 tests/ui/cast_size_32bit.stderr create mode 100644 tests/ui/fn_to_numeric_cast_32bit.rs create mode 100644 tests/ui/fn_to_numeric_cast_32bit.stderr create mode 100644 tests/ui/transmute_32bit.stderr diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 2a361856a123b..abdfe409b78d2 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -24,6 +24,7 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust + /// # #[cfg(target_pointer_width = "64")] /// #[repr(usize)] /// enum NonPortable { /// X = 0x1_0000_0000, diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index 611e5a855723d..595109be46bb8 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -1,3 +1,4 @@ +// ignore-32bit #[warn( clippy::cast_precision_loss, clippy::cast_possible_truncation, diff --git a/tests/ui/cast_size.stderr b/tests/ui/cast_size.stderr index 735e522b40d9f..ec7ed6aec94ee 100644 --- a/tests/ui/cast_size.stderr +++ b/tests/ui/cast_size.stderr @@ -1,5 +1,5 @@ error: casting isize to i8 may truncate the value - --> $DIR/cast_size.rs:11:5 + --> $DIR/cast_size.rs:12:5 | LL | 1isize as i8; | ^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | 1isize as i8; = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:14:5 + --> $DIR/cast_size.rs:15:5 | LL | x0 as f64; | ^^^^^^^^^ @@ -15,49 +15,49 @@ LL | x0 as f64; = note: `-D clippy::cast-precision-loss` implied by `-D warnings` error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:15:5 + --> $DIR/cast_size.rs:16:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:16:5 + --> $DIR/cast_size.rs:17:5 | LL | x0 as f32; | ^^^^^^^^^ error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:17:5 + --> $DIR/cast_size.rs:18:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:18:5 + --> $DIR/cast_size.rs:19:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:19:5 + --> $DIR/cast_size.rs:20:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:20:5 + --> $DIR/cast_size.rs:21:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:21:5 + --> $DIR/cast_size.rs:22:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:21:5 + --> $DIR/cast_size.rs:22:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -65,49 +65,49 @@ LL | 1usize as i32; = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:23:5 + --> $DIR/cast_size.rs:24:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:24:5 + --> $DIR/cast_size.rs:25:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:25:5 + --> $DIR/cast_size.rs:26:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:25:5 + --> $DIR/cast_size.rs:26:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:26:5 + --> $DIR/cast_size.rs:27:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:27:5 + --> $DIR/cast_size.rs:28:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:32:5 + --> $DIR/cast_size.rs:33:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:33:5 + --> $DIR/cast_size.rs:34:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size_32bit.rs b/tests/ui/cast_size_32bit.rs new file mode 100644 index 0000000000000..99aac6deca324 --- /dev/null +++ b/tests/ui/cast_size_32bit.rs @@ -0,0 +1,35 @@ +// ignore-64bit +#[warn( + clippy::cast_precision_loss, + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + clippy::cast_possible_wrap, + clippy::cast_lossless +)] +#[allow(clippy::no_effect, clippy::unnecessary_operation)] +fn main() { + // Casting from *size + 1isize as i8; + let x0 = 1isize; + let x1 = 1usize; + x0 as f64; + x1 as f64; + x0 as f32; + x1 as f32; + 1isize as i32; + 1isize as u32; + 1usize as u32; + 1usize as i32; + // Casting to *size + 1i64 as isize; + 1i64 as usize; + 1u64 as isize; + 1u64 as usize; + 1u32 as isize; + 1u32 as usize; // Should not trigger any lint + 1i32 as isize; // Neither should this + 1i32 as usize; + // Big integer literal to float + 999_999_999 as f32; + 3_999_999_999usize as f64; +} diff --git a/tests/ui/cast_size_32bit.stderr b/tests/ui/cast_size_32bit.stderr new file mode 100644 index 0000000000000..cb89630718aee --- /dev/null +++ b/tests/ui/cast_size_32bit.stderr @@ -0,0 +1,132 @@ +error: casting isize to i8 may truncate the value + --> $DIR/cast_size_32bit.rs:12:5 + | +LL | 1isize as i8; + | ^^^^^^^^^^^^ + | + = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` + +error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide) + --> $DIR/cast_size_32bit.rs:15:5 + | +LL | x0 as f64; + | ^^^^^^^^^ + | + = note: `-D clippy::cast-precision-loss` implied by `-D warnings` + +error: casting isize to f64 may become silently lossy if you later change the type + --> $DIR/cast_size_32bit.rs:15:5 + | +LL | x0 as f64; + | ^^^^^^^^^ help: try: `f64::from(x0)` + | + = note: `-D clippy::cast-lossless` implied by `-D warnings` + +error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) + --> $DIR/cast_size_32bit.rs:16:5 + | +LL | x1 as f64; + | ^^^^^^^^^ + +error: casting usize to f64 may become silently lossy if you later change the type + --> $DIR/cast_size_32bit.rs:16:5 + | +LL | x1 as f64; + | ^^^^^^^^^ help: try: `f64::from(x1)` + +error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast_size_32bit.rs:17:5 + | +LL | x0 as f32; + | ^^^^^^^^^ + +error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast_size_32bit.rs:18:5 + | +LL | x1 as f32; + | ^^^^^^^^^ + +error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size_32bit.rs:19:5 + | +LL | 1isize as i32; + | ^^^^^^^^^^^^^ + +error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size_32bit.rs:20:5 + | +LL | 1isize as u32; + | ^^^^^^^^^^^^^ + +error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size_32bit.rs:21:5 + | +LL | 1usize as u32; + | ^^^^^^^^^^^^^ + +error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size_32bit.rs:22:5 + | +LL | 1usize as i32; + | ^^^^^^^^^^^^^ + +error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers + --> $DIR/cast_size_32bit.rs:22:5 + | +LL | 1usize as i32; + | ^^^^^^^^^^^^^ + | + = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` + +error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast_size_32bit.rs:24:5 + | +LL | 1i64 as isize; + | ^^^^^^^^^^^^^ + +error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast_size_32bit.rs:25:5 + | +LL | 1i64 as usize; + | ^^^^^^^^^^^^^ + +error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast_size_32bit.rs:26:5 + | +LL | 1u64 as isize; + | ^^^^^^^^^^^^^ + +error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers + --> $DIR/cast_size_32bit.rs:26:5 + | +LL | 1u64 as isize; + | ^^^^^^^^^^^^^ + +error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast_size_32bit.rs:27:5 + | +LL | 1u64 as usize; + | ^^^^^^^^^^^^^ + +error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers + --> $DIR/cast_size_32bit.rs:28:5 + | +LL | 1u32 as isize; + | ^^^^^^^^^^^^^ + +error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast_size_32bit.rs:33:5 + | +LL | 999_999_999 as f32; + | ^^^^^^^^^^^^^^^^^^ + +error: casting integer literal to f64 is unnecessary + --> $DIR/cast_size_32bit.rs:34:5 + | +LL | 3_999_999_999usize as f64; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `3999999999_f64` + | + = note: `-D clippy::unnecessary-cast` implied by `-D warnings` + +error: aborting due to 20 previous errors + diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 21573af870a8d..a456c085c8761 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -1,4 +1,4 @@ -// only-64bit +// ignore-32bit #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] diff --git a/tests/ui/fn_to_numeric_cast_32bit.rs b/tests/ui/fn_to_numeric_cast_32bit.rs new file mode 100644 index 0000000000000..04ee985c0863d --- /dev/null +++ b/tests/ui/fn_to_numeric_cast_32bit.rs @@ -0,0 +1,55 @@ +// ignore-64bit + +#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] + +fn foo() -> String { + String::new() +} + +fn test_function_to_numeric_cast() { + let _ = foo as i8; + let _ = foo as i16; + let _ = foo as i32; + let _ = foo as i64; + let _ = foo as i128; + let _ = foo as isize; + + let _ = foo as u8; + let _ = foo as u16; + let _ = foo as u32; + let _ = foo as u64; + let _ = foo as u128; + + // Casting to usize is OK and should not warn + let _ = foo as usize; + + // Cast `f` (a `FnDef`) to `fn()` should not warn + fn f() {} + let _ = f as fn(); +} + +fn test_function_var_to_numeric_cast() { + let abc: fn() -> String = foo; + + let _ = abc as i8; + let _ = abc as i16; + let _ = abc as i32; + let _ = abc as i64; + let _ = abc as i128; + let _ = abc as isize; + + let _ = abc as u8; + let _ = abc as u16; + let _ = abc as u32; + let _ = abc as u64; + let _ = abc as u128; + + // Casting to usize is OK and should not warn + let _ = abc as usize; +} + +fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { + f as i32 +} + +fn main() {} diff --git a/tests/ui/fn_to_numeric_cast_32bit.stderr b/tests/ui/fn_to_numeric_cast_32bit.stderr new file mode 100644 index 0000000000000..08dd611d67524 --- /dev/null +++ b/tests/ui/fn_to_numeric_cast_32bit.stderr @@ -0,0 +1,144 @@ +error: casting function pointer `foo` to `i8`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:10:13 + | +LL | let _ = foo as i8; + | ^^^^^^^^^ help: try: `foo as usize` + | + = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` + +error: casting function pointer `foo` to `i16`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:11:13 + | +LL | let _ = foo as i16; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `i32` + --> $DIR/fn_to_numeric_cast_32bit.rs:12:13 + | +LL | let _ = foo as i32; + | ^^^^^^^^^^ help: try: `foo as usize` + | + = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` + +error: casting function pointer `foo` to `i64` + --> $DIR/fn_to_numeric_cast_32bit.rs:13:13 + | +LL | let _ = foo as i64; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `i128` + --> $DIR/fn_to_numeric_cast_32bit.rs:14:13 + | +LL | let _ = foo as i128; + | ^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `isize` + --> $DIR/fn_to_numeric_cast_32bit.rs:15:13 + | +LL | let _ = foo as isize; + | ^^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u8`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:17:13 + | +LL | let _ = foo as u8; + | ^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u16`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:18:13 + | +LL | let _ = foo as u16; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u32` + --> $DIR/fn_to_numeric_cast_32bit.rs:19:13 + | +LL | let _ = foo as u32; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u64` + --> $DIR/fn_to_numeric_cast_32bit.rs:20:13 + | +LL | let _ = foo as u64; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u128` + --> $DIR/fn_to_numeric_cast_32bit.rs:21:13 + | +LL | let _ = foo as u128; + | ^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `abc` to `i8`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:34:13 + | +LL | let _ = abc as i8; + | ^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i16`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:35:13 + | +LL | let _ = abc as i16; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i32` + --> $DIR/fn_to_numeric_cast_32bit.rs:36:13 + | +LL | let _ = abc as i32; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i64` + --> $DIR/fn_to_numeric_cast_32bit.rs:37:13 + | +LL | let _ = abc as i64; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i128` + --> $DIR/fn_to_numeric_cast_32bit.rs:38:13 + | +LL | let _ = abc as i128; + | ^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `isize` + --> $DIR/fn_to_numeric_cast_32bit.rs:39:13 + | +LL | let _ = abc as isize; + | ^^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u8`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:41:13 + | +LL | let _ = abc as u8; + | ^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u16`, which truncates the value + --> $DIR/fn_to_numeric_cast_32bit.rs:42:13 + | +LL | let _ = abc as u16; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u32` + --> $DIR/fn_to_numeric_cast_32bit.rs:43:13 + | +LL | let _ = abc as u32; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u64` + --> $DIR/fn_to_numeric_cast_32bit.rs:44:13 + | +LL | let _ = abc as u64; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u128` + --> $DIR/fn_to_numeric_cast_32bit.rs:45:13 + | +LL | let _ = abc as u128; + | ^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `f` to `i32` + --> $DIR/fn_to_numeric_cast_32bit.rs:52:5 + | +LL | f as i32 + | ^^^^^^^^ help: try: `f as usize` + +error: aborting due to 23 previous errors + diff --git a/tests/ui/large_digit_groups.fixed b/tests/ui/large_digit_groups.fixed index 02daa22bb36e3..859fad2f54d9d 100644 --- a/tests/ui/large_digit_groups.fixed +++ b/tests/ui/large_digit_groups.fixed @@ -1,6 +1,6 @@ // run-rustfix -#[warn(clippy::large_digit_groups)] -#[allow(unused_variables)] +#![warn(clippy::large_digit_groups)] + fn main() { macro_rules! mac { () => { @@ -8,7 +8,7 @@ fn main() { }; } - let good = ( + let _good = ( 0b1011_i64, 0o1_234_u32, 0x1_234_567, @@ -18,15 +18,14 @@ fn main() { 1_234.123_f32, 1.123_4_f32, ); - let bad = ( + let _bad = ( 0b11_0110_i64, - 0x0123_4567_8901_usize, + 0xdead_beef_usize, 123_456_f32, 123_456.12_f32, 123_456.123_45_f64, 123_456.123_456_f64, ); - // Ignore literals in macros let _ = mac!(); } diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs index c1bb78c9d832f..ac116d5dbda15 100644 --- a/tests/ui/large_digit_groups.rs +++ b/tests/ui/large_digit_groups.rs @@ -1,6 +1,6 @@ // run-rustfix -#[warn(clippy::large_digit_groups)] -#[allow(unused_variables)] +#![warn(clippy::large_digit_groups)] + fn main() { macro_rules! mac { () => { @@ -8,7 +8,7 @@ fn main() { }; } - let good = ( + let _good = ( 0b1011_i64, 0o1_234_u32, 0x1_234_567, @@ -18,15 +18,14 @@ fn main() { 1_234.123_f32, 1.123_4_f32, ); - let bad = ( + let _bad = ( 0b1_10110_i64, - 0x1_23456_78901_usize, + 0xd_e_adbee_f_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f64, 1_23456.12345_6_f64, ); - // Ignore literals in macros let _ = mac!(); } diff --git a/tests/ui/large_digit_groups.stderr b/tests/ui/large_digit_groups.stderr index ba8ea6b53e7f1..b6d9672a78e21 100644 --- a/tests/ui/large_digit_groups.stderr +++ b/tests/ui/large_digit_groups.stderr @@ -6,11 +6,13 @@ LL | 0b1_10110_i64, | = note: `-D clippy::large-digit-groups` implied by `-D warnings` -error: digit groups should be smaller +error: digits grouped inconsistently by underscores --> $DIR/large_digit_groups.rs:23:9 | -LL | 0x1_23456_78901_usize, - | ^^^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize` +LL | 0xd_e_adbee_f_usize, + | ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize` + | + = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` error: digit groups should be smaller --> $DIR/large_digit_groups.rs:24:9 diff --git a/tests/ui/transmute_32bit.rs b/tests/ui/transmute_32bit.rs index 1b50133d3918f..ffe22b12f5510 100644 --- a/tests/ui/transmute_32bit.rs +++ b/tests/ui/transmute_32bit.rs @@ -1,6 +1,6 @@ -//ignore-x86_64 +// ignore-64bit -#[warn(wrong_transmute)] +#[warn(clippy::wrong_transmute)] fn main() { unsafe { let _: *const usize = std::mem::transmute(6.0f32); diff --git a/tests/ui/transmute_32bit.stderr b/tests/ui/transmute_32bit.stderr new file mode 100644 index 0000000000000..040519564b94c --- /dev/null +++ b/tests/ui/transmute_32bit.stderr @@ -0,0 +1,28 @@ +error: transmute from a `f32` to a pointer + --> $DIR/transmute_32bit.rs:6:31 + | +LL | let _: *const usize = std::mem::transmute(6.0f32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::wrong-transmute` implied by `-D warnings` + +error: transmute from a `f32` to a pointer + --> $DIR/transmute_32bit.rs:8:29 + | +LL | let _: *mut usize = std::mem::transmute(6.0f32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a `char` to a pointer + --> $DIR/transmute_32bit.rs:10:31 + | +LL | let _: *const usize = std::mem::transmute('x'); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a `char` to a pointer + --> $DIR/transmute_32bit.rs:12:29 + | +LL | let _: *mut usize = std::mem::transmute('x'); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/transmute_64bit.rs b/tests/ui/transmute_64bit.rs index aee5152d6472e..00dc0b2c36081 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -1,5 +1,4 @@ -//ignore-x86 -//no-ignore-x86_64 +// ignore-32bit #[warn(clippy::wrong_transmute)] fn main() { diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index 457050ec504b6..d1854c009ef56 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -1,5 +1,5 @@ error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:7:31 + --> $DIR/transmute_64bit.rs:6:31 | LL | let _: *const usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); = note: `-D clippy::wrong-transmute` implied by `-D warnings` error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:9:29 + --> $DIR/transmute_64bit.rs:8:29 | LL | let _: *mut usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed index 679b962756ca4..3f358d9ecaa0a 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -1,5 +1,7 @@ // run-rustfix +#![warn(clippy::unreadable_literal)] + struct Foo(u64); macro_rules! foo { @@ -8,10 +10,8 @@ macro_rules! foo { }; } -#[warn(clippy::unreadable_literal)] -#[allow(unused_variables)] fn main() { - let good = ( + let _good = ( 0b1011_i64, 0o1_234_u32, 0x1_234_567, @@ -22,14 +22,14 @@ fn main() { 1_234.123_f32, 1.123_4_f32, ); - let bad = (0b11_0110_i64, 0x0123_4567_8901_usize, 123_456_f32, 1.234_567_f32); - let good_sci = 1.1234e1; - let bad_sci = 1.123_456e1; + let _bad = (0b11_0110_i64, 0xcafe_babe_usize, 123_456_f32, 1.234_567_f32); + let _good_sci = 1.1234e1; + let _bad_sci = 1.123_456e1; - let fail9 = 0x00ab_cdef; - let fail10: u32 = 0xBAFE_BAFE; - let fail11 = 0x0abc_deff; - let fail12: i128 = 0x00ab_cabc_abca_bcab_cabc; + let _fail9 = 0x00ab_cdef; + let _fail10: u32 = 0xBAFE_BAFE; + let _fail11 = 0x0abc_deff; + let _fail12: i128 = 0x00ab_cabc_abca_bcab_cabc; let _ = foo!(); } diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 9922f01aa00f9..e658a5f28c90e 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -1,5 +1,7 @@ // run-rustfix +#![warn(clippy::unreadable_literal)] + struct Foo(u64); macro_rules! foo { @@ -8,10 +10,8 @@ macro_rules! foo { }; } -#[warn(clippy::unreadable_literal)] -#[allow(unused_variables)] fn main() { - let good = ( + let _good = ( 0b1011_i64, 0o1_234_u32, 0x1_234_567, @@ -22,14 +22,14 @@ fn main() { 1_234.123_f32, 1.123_4_f32, ); - let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32); - let good_sci = 1.1234e1; - let bad_sci = 1.123456e1; + let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); + let _good_sci = 1.1234e1; + let _bad_sci = 1.123456e1; - let fail9 = 0xabcdef; - let fail10: u32 = 0xBAFEBAFE; - let fail11 = 0xabcdeff; - let fail12: i128 = 0xabcabcabcabcabcabc; + let _fail9 = 0xabcdef; + let _fail10: u32 = 0xBAFEBAFE; + let _fail11 = 0xabcdeff; + let _fail12: i128 = 0xabcabcabcabcabcabc; let _ = foo!(); } diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index a31ff75955ca6..1b2ff6bff048c 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -1,58 +1,58 @@ error: long literal lacking separators - --> $DIR/unreadable_literal.rs:25:16 + --> $DIR/unreadable_literal.rs:25:17 | -LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` +LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); + | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:25:30 + --> $DIR/unreadable_literal.rs:25:31 | -LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize` +LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); + | ^^^^^^^^^^^^^^^^ help: consider: `0xcafe_babe_usize` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:25:51 + --> $DIR/unreadable_literal.rs:25:49 | -LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^ help: consider: `123_456_f32` +LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); + | ^^^^^^^^^^ help: consider: `123_456_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:25:63 + --> $DIR/unreadable_literal.rs:25:61 | -LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` +LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); + | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:27:19 + --> $DIR/unreadable_literal.rs:27:20 | -LL | let bad_sci = 1.123456e1; - | ^^^^^^^^^^ help: consider: `1.123_456e1` +LL | let _bad_sci = 1.123456e1; + | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:29:17 + --> $DIR/unreadable_literal.rs:29:18 | -LL | let fail9 = 0xabcdef; - | ^^^^^^^^ help: consider: `0x00ab_cdef` +LL | let _fail9 = 0xabcdef; + | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:30:23 + --> $DIR/unreadable_literal.rs:30:24 | -LL | let fail10: u32 = 0xBAFEBAFE; - | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` +LL | let _fail10: u32 = 0xBAFEBAFE; + | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:31:18 + --> $DIR/unreadable_literal.rs:31:19 | -LL | let fail11 = 0xabcdeff; - | ^^^^^^^^^ help: consider: `0x0abc_deff` +LL | let _fail11 = 0xabcdeff; + | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:32:24 + --> $DIR/unreadable_literal.rs:32:25 | -LL | let fail12: i128 = 0xabcabcabcabcabcabc; - | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` +LL | let _fail12: i128 = 0xabcabcabcabcabcabc; + | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: aborting due to 9 previous errors From 7156aa7f950faf182aaf39fed4f8b09aad20623a Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 26 Oct 2019 00:05:07 +0700 Subject: [PATCH 5/5] build(tests/fmt): use shared target dir --- tests/fmt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/fmt.rs b/tests/fmt.rs index bc37be84b433e..ba35abbfbbb7d 100644 --- a/tests/fmt.rs +++ b/tests/fmt.rs @@ -19,9 +19,11 @@ fn fmt() { let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); let dev_dir = root_dir.join("clippy_dev"); + let target_dir = root_dir.join("target"); + let target_dir = target_dir.to_str().unwrap(); let output = Command::new("cargo") .current_dir(dev_dir) - .args(&["+nightly", "run", "--", "fmt", "--check"]) + .args(&["+nightly", "run", "--target-dir", target_dir, "--", "fmt", "--check"]) .output() .unwrap();