Commit 1259e85
committed
Make use of the crate's prelude to replace individual imports
Automatically apply changes with the following:
#!/bin/bash
set -eux
files=()
# Types either defined in this crate or in `core`
prelude_types=(
c_char
c_double
c_float
c_int
c_longlong
c_long
c_short
c_uchar
c_uint
c_ulonglong
c_ulong
c_ushort
c_void
intptr_t
size_t
ssize_t
Clone
Copy
Option
Send
Sync
)
# Reexports from core
prelude_modules=(
fmt
hash
iter
mem
)
# Everything in the prelude
prelude=( "${prelude_types[@]}" "${prelude_modules[@]}" )
# Generate a list of all files excluding `lib.rs` (since the prelude being
# defined there makes string matching weird).
while IFS= read -r -d '' file; do
files+=("$file")
done < <(find src -name '*.rs' -not -name '*lib.rs' -not -name '*macros.rs' -not -name 'fixed_width_ints.rs' -print0)
for file in "${files[@]}"; do
needs_prelude=0
# If the file already has some sort of glob import, skip it
if rg --pcre2 -q 'use (crate|super)::(?!prelude).*\*' "$file"; then
continue
fi
# Core types always require the prelude to handle rustc-dep-of-std
if rg --pcre2 -q '\b(?<!\.)(Option|Clone|Copy|Send|Sync|fmt|hash|iter|mem)\b' "$file"; then
needs_prelude=1
fi
# If we use any types that are specified in the prelude then we will import it
for ty in "${prelude[@]}"; do
# If the type is defined in the current module, we don't need it from the prelude
if rg -q "type $ty =" "$file"; then
continue
fi
if rg -qU '((crate|super)::'"$ty"'|use (crate|super)::(\{\n){0,2}.*'"$ty)" "$file"; then
needs_prelude=1
fi
done
# Check if the prelude is needed and does not already exist; if so, add it
if [ "$needs_prelude" = "1" ] && ! rg -q 'use crate::prelude::\*' "$file"; then
# Split the file into two parts: module-level attributes and rest
# Imports will be added after module-level attributes
attrs=$(awk '/^#!|^\/\/!/ {found=NR} {lines[NR]=$0} END {for (i=1; i<=found; i++) print lines[i]}' "$file")
rest=$(awk '/^#!|^\/\/!/ {found=NR} END {if (found) {for (i=found+1; i<=NR; i++) print lines[i]} else {for (i=1; i<=NR; i++) print lines[i]}} {lines[NR]=$0}' "$file")
printf "%s\n" "$attrs" > "$file"
printf "\n%s\n\n" "use crate::prelude::*;" >> "$file"
printf "%s" "$rest" >> "$file"
fi
for ty in "${prelude[@]}"; do
export TY="$ty" # env for perl to use
# Remove simple imports `use crate::ty;`
perl -pi -0777 -e 's/use ((crate|super)::)?($ENV{TY});//g' "$file"
# Remove the type if it is part of a group import
perl -pi -0777 -e 's/(use (crate|super)::\{?(.*|(\n.*){0,2}))\b$ENV{TY}\b,? ?/$1/g' "$file"
# Replace pathed `crate::ty`
perl -pi -0777 -e 's/(crate|super)::($ENV{TY})\b/$2/g' "$file"
done
# For some reason, rustfmt doesn't trim leading newlines. Do so manually here.
perl -pi -0777 -e 's/\A\n+//' "$file"
rustfmt "$file"
done
./ci/style.sh1 parent ec0a677 commit 1259e85
File tree
149 files changed
+1521
-1531
lines changed- src
- fuchsia
- solid
- teeos
- unix
- aix
- bsd
- apple
- b32
- b64
- aarch64
- x86_64
- freebsdlike
- dragonfly
- freebsd
- freebsd11
- freebsd12
- freebsd13
- freebsd14
- freebsd15
- x86_64
- netbsdlike
- netbsd
- openbsd
- haiku
- hurd
- linux_like
- android
- b32
- x86
- b64
- aarch64
- riscv64
- x86_64
- emscripten
- linux
- arch
- generic
- mips
- powerpc
- sparc
- gnu
- b32
- arm
- csky
- m68k
- mips
- riscv32
- sparc
- x86
- b64
- aarch64
- loongarch64
- mips64
- powerpc64
- riscv64
- sparc64
- x86_64
- musl
- b32
- arm
- mips
- riscv32
- x86
- b64
- aarch64
- loongarch64
- riscv64
- x86_64
- uclibc
- arm
- mips
- mips32
- mips64
- x86_64
- newlib
- aarch64
- arm
- espidf
- horizon
- powerpc
- rtems
- vita
- nto
- nuttx
- redox
- solarish
- vxworks
- wasi
- windows
- gnu
- msvc
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
149 files changed
+1521
-1531
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
1073 | 1073 | | |
1074 | 1074 | | |
1075 | 1075 | | |
1076 | | - | |
1077 | | - | |
| 1076 | + | |
| 1077 | + | |
1078 | 1078 | | |
1079 | 1079 | | |
1080 | 1080 | | |
| |||
1093 | 1093 | | |
1094 | 1094 | | |
1095 | 1095 | | |
1096 | | - | |
1097 | | - | |
| 1096 | + | |
| 1097 | + | |
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
| |||
1123 | 1123 | | |
1124 | 1124 | | |
1125 | 1125 | | |
1126 | | - | |
1127 | | - | |
| 1126 | + | |
| 1127 | + | |
1128 | 1128 | | |
1129 | 1129 | | |
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
1133 | 1133 | | |
1134 | | - | |
1135 | | - | |
| 1134 | + | |
| 1135 | + | |
1136 | 1136 | | |
1137 | 1137 | | |
1138 | 1138 | | |
| |||
1150 | 1150 | | |
1151 | 1151 | | |
1152 | 1152 | | |
1153 | | - | |
1154 | | - | |
| 1153 | + | |
| 1154 | + | |
1155 | 1155 | | |
1156 | 1156 | | |
1157 | 1157 | | |
1158 | 1158 | | |
1159 | 1159 | | |
1160 | 1160 | | |
1161 | 1161 | | |
1162 | | - | |
1163 | | - | |
| 1162 | + | |
| 1163 | + | |
1164 | 1164 | | |
1165 | 1165 | | |
1166 | 1166 | | |
| |||
1196 | 1196 | | |
1197 | 1197 | | |
1198 | 1198 | | |
1199 | | - | |
1200 | | - | |
| 1199 | + | |
| 1200 | + | |
1201 | 1201 | | |
1202 | 1202 | | |
1203 | 1203 | | |
| |||
1207 | 1207 | | |
1208 | 1208 | | |
1209 | 1209 | | |
1210 | | - | |
1211 | | - | |
| 1210 | + | |
| 1211 | + | |
1212 | 1212 | | |
1213 | 1213 | | |
1214 | 1214 | | |
| |||
1231 | 1231 | | |
1232 | 1232 | | |
1233 | 1233 | | |
1234 | | - | |
1235 | | - | |
| 1234 | + | |
| 1235 | + | |
1236 | 1236 | | |
1237 | 1237 | | |
1238 | 1238 | | |
| |||
1242 | 1242 | | |
1243 | 1243 | | |
1244 | 1244 | | |
1245 | | - | |
1246 | | - | |
| 1245 | + | |
| 1246 | + | |
1247 | 1247 | | |
1248 | 1248 | | |
1249 | 1249 | | |
| |||
1266 | 1266 | | |
1267 | 1267 | | |
1268 | 1268 | | |
1269 | | - | |
1270 | | - | |
| 1269 | + | |
| 1270 | + | |
1271 | 1271 | | |
1272 | 1272 | | |
1273 | 1273 | | |
| |||
1277 | 1277 | | |
1278 | 1278 | | |
1279 | 1279 | | |
1280 | | - | |
1281 | | - | |
| 1280 | + | |
| 1281 | + | |
1282 | 1282 | | |
1283 | 1283 | | |
1284 | 1284 | | |
| |||
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
1299 | | - | |
1300 | | - | |
| 1299 | + | |
| 1300 | + | |
1301 | 1301 | | |
1302 | 1302 | | |
1303 | 1303 | | |
| |||
1306 | 1306 | | |
1307 | 1307 | | |
1308 | 1308 | | |
1309 | | - | |
1310 | | - | |
| 1309 | + | |
| 1310 | + | |
1311 | 1311 | | |
1312 | 1312 | | |
1313 | 1313 | | |
| |||
1323 | 1323 | | |
1324 | 1324 | | |
1325 | 1325 | | |
1326 | | - | |
1327 | | - | |
| 1326 | + | |
| 1327 | + | |
1328 | 1328 | | |
1329 | 1329 | | |
1330 | 1330 | | |
1331 | 1331 | | |
1332 | 1332 | | |
1333 | 1333 | | |
1334 | 1334 | | |
1335 | | - | |
1336 | | - | |
| 1335 | + | |
| 1336 | + | |
1337 | 1337 | | |
1338 | 1338 | | |
1339 | 1339 | | |
| |||
1350 | 1350 | | |
1351 | 1351 | | |
1352 | 1352 | | |
1353 | | - | |
1354 | | - | |
| 1353 | + | |
| 1354 | + | |
1355 | 1355 | | |
1356 | 1356 | | |
1357 | 1357 | | |
| |||
1361 | 1361 | | |
1362 | 1362 | | |
1363 | 1363 | | |
1364 | | - | |
1365 | | - | |
| 1364 | + | |
| 1365 | + | |
1366 | 1366 | | |
1367 | 1367 | | |
1368 | 1368 | | |
| |||
1377 | 1377 | | |
1378 | 1378 | | |
1379 | 1379 | | |
1380 | | - | |
1381 | | - | |
| 1380 | + | |
| 1381 | + | |
1382 | 1382 | | |
1383 | 1383 | | |
1384 | 1384 | | |
1385 | 1385 | | |
1386 | 1386 | | |
1387 | | - | |
1388 | | - | |
| 1387 | + | |
| 1388 | + | |
1389 | 1389 | | |
1390 | 1390 | | |
1391 | 1391 | | |
| |||
1396 | 1396 | | |
1397 | 1397 | | |
1398 | 1398 | | |
1399 | | - | |
1400 | | - | |
| 1399 | + | |
| 1400 | + | |
1401 | 1401 | | |
1402 | 1402 | | |
1403 | 1403 | | |
1404 | 1404 | | |
1405 | 1405 | | |
1406 | | - | |
1407 | | - | |
| 1406 | + | |
| 1407 | + | |
1408 | 1408 | | |
1409 | 1409 | | |
1410 | 1410 | | |
| |||
1415 | 1415 | | |
1416 | 1416 | | |
1417 | 1417 | | |
1418 | | - | |
1419 | | - | |
| 1418 | + | |
| 1419 | + | |
1420 | 1420 | | |
1421 | 1421 | | |
1422 | 1422 | | |
1423 | 1423 | | |
1424 | 1424 | | |
1425 | | - | |
1426 | | - | |
| 1425 | + | |
| 1426 | + | |
1427 | 1427 | | |
1428 | 1428 | | |
1429 | 1429 | | |
| |||
3372 | 3372 | | |
3373 | 3373 | | |
3374 | 3374 | | |
3375 | | - | |
| 3375 | + | |
3376 | 3376 | | |
3377 | 3377 | | |
3378 | 3378 | | |
3379 | 3379 | | |
3380 | 3380 | | |
3381 | 3381 | | |
3382 | | - | |
| 3382 | + | |
3383 | 3383 | | |
3384 | 3384 | | |
3385 | 3385 | | |
3386 | 3386 | | |
3387 | 3387 | | |
3388 | | - | |
| 3388 | + | |
3389 | 3389 | | |
3390 | 3390 | | |
3391 | 3391 | | |
| |||
3403 | 3403 | | |
3404 | 3404 | | |
3405 | 3405 | | |
3406 | | - | |
| 3406 | + | |
3407 | 3407 | | |
3408 | 3408 | | |
3409 | 3409 | | |
3410 | 3410 | | |
3411 | 3411 | | |
3412 | 3412 | | |
3413 | | - | |
| 3413 | + | |
3414 | 3414 | | |
3415 | 3415 | | |
3416 | 3416 | | |
3417 | 3417 | | |
3418 | 3418 | | |
3419 | 3419 | | |
3420 | | - | |
| 3420 | + | |
3421 | 3421 | | |
3422 | 3422 | | |
3423 | 3423 | | |
| |||
3445 | 3445 | | |
3446 | 3446 | | |
3447 | 3447 | | |
3448 | | - | |
| 3448 | + | |
3449 | 3449 | | |
3450 | | - | |
| 3450 | + | |
3451 | 3451 | | |
3452 | 3452 | | |
3453 | 3453 | | |
3454 | 3454 | | |
3455 | 3455 | | |
3456 | 3456 | | |
3457 | 3457 | | |
3458 | | - | |
| 3458 | + | |
3459 | 3459 | | |
3460 | 3460 | | |
3461 | 3461 | | |
3462 | 3462 | | |
3463 | 3463 | | |
3464 | 3464 | | |
3465 | 3465 | | |
3466 | | - | |
| 3466 | + | |
3467 | 3467 | | |
3468 | 3468 | | |
3469 | 3469 | | |
3470 | | - | |
| 3470 | + | |
3471 | 3471 | | |
3472 | 3472 | | |
3473 | 3473 | | |
3474 | | - | |
| 3474 | + | |
3475 | 3475 | | |
3476 | 3476 | | |
3477 | 3477 | | |
| |||
3525 | 3525 | | |
3526 | 3526 | | |
3527 | 3527 | | |
3528 | | - | |
3529 | | - | |
| 3528 | + | |
| 3529 | + | |
3530 | 3530 | | |
3531 | 3531 | | |
3532 | 3532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
0 commit comments