Skip to content

Commit 45196ce

Browse files
committed
Auto merge of #4690 - lzutao:fix-test-on-non-amd64, r=flip1995
generate stderr file on 32bit pointer system changelog: none
2 parents 5a75502 + 7156aa7 commit 45196ce

23 files changed

+506
-101
lines changed

.travis.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
dist: xenial
22
language: bash
3+
git:
4+
depth: 1
5+
quiet: true
36

47
branches:
58
# Don't build these branches
@@ -22,6 +25,7 @@ env:
2225
- secure: "OKulfkA5OGd/d1IhvBKzRkHQwMcWjzrzbimo7+5NhkUkWxndAzl+719TB3wWvIh1i2wXXrEXsyZkXM5FtRrHm55v1VKQ5ibjEvFg1w3NIg81iDyoLq186fLqywvxGkOAFPrsePPsBj5USd5xvhwwbrjO6L7/RK6Z8shBwOSc41s="
2326

2427
before_install:
28+
- export CARGO_TARGET_DIR="$TRAVIS_BUILD_DIR/target"
2529
- curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly --profile=minimal
2630
- export PATH="$HOME/.cargo/bin:$PATH"
2731
install:
@@ -48,6 +52,15 @@ matrix:
4852
include:
4953
# Builds that are executed for every PR
5054
- os: linux
55+
# i686 toolchain could run on x86_64 system.
56+
- os: linux
57+
env: HOST_TOOLCHAIN=i686-unknown-linux-gnu
58+
addons:
59+
apt:
60+
packages:
61+
- gcc-multilib
62+
- libssl-dev:i386 # openssl dev in Cargo.toml
63+
if: branch IN (auto, try)
5164
- os: windows
5265
env: CARGO_INCREMENTAL=0 OS_WINDOWS=true
5366

@@ -114,7 +127,7 @@ before_script:
114127
SYSROOT=$(rustc --print sysroot)
115128
case "$TRAVIS_OS_NAME" in
116129
windows ) export PATH="${SYSROOT}/bin:${PATH}" ;;
117-
linux ) export LD_LIBRARY_PATH="${SYSROOT}/lib" ;;
130+
linux ) export LD_LIBRARY_PATH="${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" ;;
118131
osx )
119132
# See <https://github.com/nteract/nteract/issues/1523#issuecomment-301623519>
120133
sudo mkdir -p /usr/local/lib

ci/base-tests.sh

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
# for faster build, share target dir between subcrates
5-
CARGO_TARGET_DIR=$(pwd)/target/
6-
export CARGO_TARGET_DIR
7-
84
echo "Running clippy base tests"
95

106
PATH=$PATH:./node_modules/.bin

clippy_lints/src/enum_clike.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare_clippy_lint! {
2424
///
2525
/// **Example:**
2626
/// ```rust
27+
/// # #[cfg(target_pointer_width = "64")]
2728
/// #[repr(usize)]
2829
/// enum NonPortable {
2930
/// X = 0x1_0000_0000,

setup-toolchain.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@ if rustc +master -Vv 2>/dev/null | grep -q "$RUST_COMMIT"; then
2626
exit 0
2727
fi
2828

29-
rustup-toolchain-install-master -f -n master -c rustc-dev -- "$RUST_COMMIT"
29+
if [[ -n "$HOST_TOOLCHAIN" ]]; then
30+
TOOLCHAIN=('--host' "$HOST_TOOLCHAIN")
31+
else
32+
TOOLCHAIN=()
33+
fi
34+
35+
rustup-toolchain-install-master -f -n master "${TOOLCHAIN[@]}" -c rustc-dev -- "$RUST_COMMIT"
3036
rustup override set master

tests/fmt.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ fn fmt() {
1919

2020
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
2121
let dev_dir = root_dir.join("clippy_dev");
22+
let target_dir = root_dir.join("target");
23+
let target_dir = target_dir.to_str().unwrap();
2224
let output = Command::new("cargo")
2325
.current_dir(dev_dir)
24-
.args(&["+nightly", "run", "--", "fmt", "--check"])
26+
.args(&["+nightly", "run", "--target-dir", target_dir, "--", "fmt", "--check"])
2527
.output()
2628
.unwrap();
2729

tests/ui/cast_size.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-32bit
12
#[warn(
23
clippy::cast_precision_loss,
34
clippy::cast_possible_truncation,

tests/ui/cast_size.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
11
error: casting isize to i8 may truncate the value
2-
--> $DIR/cast_size.rs:11:5
2+
--> $DIR/cast_size.rs:12:5
33
|
44
LL | 1isize as i8;
55
| ^^^^^^^^^^^^
66
|
77
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
88

99
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)
10-
--> $DIR/cast_size.rs:14:5
10+
--> $DIR/cast_size.rs:15:5
1111
|
1212
LL | x0 as f64;
1313
| ^^^^^^^^^
1414
|
1515
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
1616

1717
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)
18-
--> $DIR/cast_size.rs:15:5
18+
--> $DIR/cast_size.rs:16:5
1919
|
2020
LL | x1 as f64;
2121
| ^^^^^^^^^
2222

2323
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)
24-
--> $DIR/cast_size.rs:16:5
24+
--> $DIR/cast_size.rs:17:5
2525
|
2626
LL | x0 as f32;
2727
| ^^^^^^^^^
2828

2929
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)
30-
--> $DIR/cast_size.rs:17:5
30+
--> $DIR/cast_size.rs:18:5
3131
|
3232
LL | x1 as f32;
3333
| ^^^^^^^^^
3434

3535
error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
36-
--> $DIR/cast_size.rs:18:5
36+
--> $DIR/cast_size.rs:19:5
3737
|
3838
LL | 1isize as i32;
3939
| ^^^^^^^^^^^^^
4040

4141
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
42-
--> $DIR/cast_size.rs:19:5
42+
--> $DIR/cast_size.rs:20:5
4343
|
4444
LL | 1isize as u32;
4545
| ^^^^^^^^^^^^^
4646

4747
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
48-
--> $DIR/cast_size.rs:20:5
48+
--> $DIR/cast_size.rs:21:5
4949
|
5050
LL | 1usize as u32;
5151
| ^^^^^^^^^^^^^
5252

5353
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
54-
--> $DIR/cast_size.rs:21:5
54+
--> $DIR/cast_size.rs:22:5
5555
|
5656
LL | 1usize as i32;
5757
| ^^^^^^^^^^^^^
5858

5959
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
60-
--> $DIR/cast_size.rs:21:5
60+
--> $DIR/cast_size.rs:22:5
6161
|
6262
LL | 1usize as i32;
6363
| ^^^^^^^^^^^^^
6464
|
6565
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
6666

6767
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
68-
--> $DIR/cast_size.rs:23:5
68+
--> $DIR/cast_size.rs:24:5
6969
|
7070
LL | 1i64 as isize;
7171
| ^^^^^^^^^^^^^
7272

7373
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
74-
--> $DIR/cast_size.rs:24:5
74+
--> $DIR/cast_size.rs:25:5
7575
|
7676
LL | 1i64 as usize;
7777
| ^^^^^^^^^^^^^
7878

7979
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
80-
--> $DIR/cast_size.rs:25:5
80+
--> $DIR/cast_size.rs:26:5
8181
|
8282
LL | 1u64 as isize;
8383
| ^^^^^^^^^^^^^
8484

8585
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
86-
--> $DIR/cast_size.rs:25:5
86+
--> $DIR/cast_size.rs:26:5
8787
|
8888
LL | 1u64 as isize;
8989
| ^^^^^^^^^^^^^
9090

9191
error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
92-
--> $DIR/cast_size.rs:26:5
92+
--> $DIR/cast_size.rs:27:5
9393
|
9494
LL | 1u64 as usize;
9595
| ^^^^^^^^^^^^^
9696

9797
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
98-
--> $DIR/cast_size.rs:27:5
98+
--> $DIR/cast_size.rs:28:5
9999
|
100100
LL | 1u32 as isize;
101101
| ^^^^^^^^^^^^^
102102

103103
error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
104-
--> $DIR/cast_size.rs:32:5
104+
--> $DIR/cast_size.rs:33:5
105105
|
106106
LL | 999_999_999 as f32;
107107
| ^^^^^^^^^^^^^^^^^^
108108

109109
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)
110-
--> $DIR/cast_size.rs:33:5
110+
--> $DIR/cast_size.rs:34:5
111111
|
112112
LL | 9_999_999_999_999_999usize as f64;
113113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/cast_size_32bit.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ignore-64bit
2+
#[warn(
3+
clippy::cast_precision_loss,
4+
clippy::cast_possible_truncation,
5+
clippy::cast_sign_loss,
6+
clippy::cast_possible_wrap,
7+
clippy::cast_lossless
8+
)]
9+
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
10+
fn main() {
11+
// Casting from *size
12+
1isize as i8;
13+
let x0 = 1isize;
14+
let x1 = 1usize;
15+
x0 as f64;
16+
x1 as f64;
17+
x0 as f32;
18+
x1 as f32;
19+
1isize as i32;
20+
1isize as u32;
21+
1usize as u32;
22+
1usize as i32;
23+
// Casting to *size
24+
1i64 as isize;
25+
1i64 as usize;
26+
1u64 as isize;
27+
1u64 as usize;
28+
1u32 as isize;
29+
1u32 as usize; // Should not trigger any lint
30+
1i32 as isize; // Neither should this
31+
1i32 as usize;
32+
// Big integer literal to float
33+
999_999_999 as f32;
34+
3_999_999_999usize as f64;
35+
}

tests/ui/cast_size_32bit.stderr

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
error: casting isize to i8 may truncate the value
2+
--> $DIR/cast_size_32bit.rs:12:5
3+
|
4+
LL | 1isize as i8;
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
8+
9+
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)
10+
--> $DIR/cast_size_32bit.rs:15:5
11+
|
12+
LL | x0 as f64;
13+
| ^^^^^^^^^
14+
|
15+
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
16+
17+
error: casting isize to f64 may become silently lossy if you later change the type
18+
--> $DIR/cast_size_32bit.rs:15:5
19+
|
20+
LL | x0 as f64;
21+
| ^^^^^^^^^ help: try: `f64::from(x0)`
22+
|
23+
= note: `-D clippy::cast-lossless` implied by `-D warnings`
24+
25+
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)
26+
--> $DIR/cast_size_32bit.rs:16:5
27+
|
28+
LL | x1 as f64;
29+
| ^^^^^^^^^
30+
31+
error: casting usize to f64 may become silently lossy if you later change the type
32+
--> $DIR/cast_size_32bit.rs:16:5
33+
|
34+
LL | x1 as f64;
35+
| ^^^^^^^^^ help: try: `f64::from(x1)`
36+
37+
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)
38+
--> $DIR/cast_size_32bit.rs:17:5
39+
|
40+
LL | x0 as f32;
41+
| ^^^^^^^^^
42+
43+
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)
44+
--> $DIR/cast_size_32bit.rs:18:5
45+
|
46+
LL | x1 as f32;
47+
| ^^^^^^^^^
48+
49+
error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
50+
--> $DIR/cast_size_32bit.rs:19:5
51+
|
52+
LL | 1isize as i32;
53+
| ^^^^^^^^^^^^^
54+
55+
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
56+
--> $DIR/cast_size_32bit.rs:20:5
57+
|
58+
LL | 1isize as u32;
59+
| ^^^^^^^^^^^^^
60+
61+
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
62+
--> $DIR/cast_size_32bit.rs:21:5
63+
|
64+
LL | 1usize as u32;
65+
| ^^^^^^^^^^^^^
66+
67+
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
68+
--> $DIR/cast_size_32bit.rs:22:5
69+
|
70+
LL | 1usize as i32;
71+
| ^^^^^^^^^^^^^
72+
73+
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
74+
--> $DIR/cast_size_32bit.rs:22:5
75+
|
76+
LL | 1usize as i32;
77+
| ^^^^^^^^^^^^^
78+
|
79+
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
80+
81+
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
82+
--> $DIR/cast_size_32bit.rs:24:5
83+
|
84+
LL | 1i64 as isize;
85+
| ^^^^^^^^^^^^^
86+
87+
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
88+
--> $DIR/cast_size_32bit.rs:25:5
89+
|
90+
LL | 1i64 as usize;
91+
| ^^^^^^^^^^^^^
92+
93+
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
94+
--> $DIR/cast_size_32bit.rs:26:5
95+
|
96+
LL | 1u64 as isize;
97+
| ^^^^^^^^^^^^^
98+
99+
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
100+
--> $DIR/cast_size_32bit.rs:26:5
101+
|
102+
LL | 1u64 as isize;
103+
| ^^^^^^^^^^^^^
104+
105+
error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
106+
--> $DIR/cast_size_32bit.rs:27:5
107+
|
108+
LL | 1u64 as usize;
109+
| ^^^^^^^^^^^^^
110+
111+
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
112+
--> $DIR/cast_size_32bit.rs:28:5
113+
|
114+
LL | 1u32 as isize;
115+
| ^^^^^^^^^^^^^
116+
117+
error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
118+
--> $DIR/cast_size_32bit.rs:33:5
119+
|
120+
LL | 999_999_999 as f32;
121+
| ^^^^^^^^^^^^^^^^^^
122+
123+
error: casting integer literal to f64 is unnecessary
124+
--> $DIR/cast_size_32bit.rs:34:5
125+
|
126+
LL | 3_999_999_999usize as f64;
127+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `3999999999_f64`
128+
|
129+
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
130+
131+
error: aborting due to 20 previous errors
132+

tests/ui/fn_to_numeric_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// only-64bit
1+
// ignore-32bit
22

33
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
44

0 commit comments

Comments
 (0)