Skip to content

Commit 91bb8d4

Browse files
committed
Make use of the crate's prelude to replace individual imports
This step was performed automatically with the following: #!/bin/bash set -eux files=() prelude_types=( c_char 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 ) # 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' -print0) for file in "${files[@]}"; do # If the file already has some sort of glob import, skip it if rg --pcre2 -q 'use crate::(?!prelude).*\*' "$file"; then continue fi # Core types always require the prelude to handle rustc-dep-of-std if rg -qU "(Option|Clone|Copy)" "$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_types[@]}"; do if rg -qU "(crate::$ty|use crate::(\{\n){,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 perl -pi -0777 -e 's/(use crate::)/use crate::prelude::*;\n$1/' "$file" fi for ty in "${prelude_types[@]}"; do # If the type is defined in the current module, skip it if rg "type $ty =" "$file"; then continue fi export TY="$ty" # env for perl to use # Remove simple imports `use crate::ty;` perl -pi -0777 -e 's/use crate::($ENV{TY});//g' "$file" # Replace pathed `crate::ty` perl -pi -0777 -e 's/crate::($ENV{TY})\b/$1/g' "$file" # Remove the type if it is part of a group import perl -pi -0777 -e 's/(use crate::\{?(.*|(\n.*){,2}))\b$ENV{TY}\b,? ?/$1/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
1 parent b8356e9 commit 91bb8d4

File tree

149 files changed

+258
-244
lines changed

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

+258
-244
lines changed

src/fuchsia/aarch64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{c_int, c_long, c_uint, c_ulong, c_ulonglong, c_ushort, off_t, size_t};
1+
use crate::off_t;
2+
use crate::prelude::*;
23

34
pub type c_char = u8;
45
pub type __u64 = c_ulonglong;

src/fuchsia/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! More functions and definitions can be found in the more specific modules
44
//! according to the platform in question.
55
6-
use crate::c_void;
6+
use crate::prelude::*;
77

88
// PUB_TYPE
99

src/fuchsia/riscv64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{c_int, c_long, c_ulong, c_ulonglong, c_ushort, off_t};
1+
use crate::off_t;
2+
use crate::prelude::*;
23

34
// From psABI Calling Convention for RV64
45
pub type c_char = u8;

src/fuchsia/x86_64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{c_int, c_long, c_ulong, c_ulonglong, off_t, size_t};
1+
use crate::off_t;
2+
use crate::prelude::*;
23

34
pub type c_char = i8;
45
pub type wchar_t = i32;

src/hermit.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Hermit C type definitions
22
3-
use crate::c_void;
4-
53
cfg_if! {
64
if #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] {
75
pub type c_char = u8;

src/solid/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! [SOLID]: https://solid.kmckk.com/
44
5-
use crate::c_void;
5+
use crate::prelude::*;
66

77
pub type c_schar = i8;
88
pub type c_uchar = u8;

src/unix/aix/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::{
2-
c_double, c_int, c_longlong, c_short, c_uchar, c_uint, c_ulonglong, c_ushort, c_void, intptr_t,
3-
size_t, ssize_t,
4-
};
1+
use crate::c_double;
2+
use crate::prelude::*;
53

64
pub type c_char = u8;
75
pub type caddr_t = *mut c_char;

src/unix/aix/powerpc64.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::{
2-
c_char, c_int, c_longlong, c_short, c_uint, c_ulonglong, c_ushort, c_void, off_t, size_t,
3-
ssize_t,
4-
};
1+
use crate::off_t;
2+
use crate::prelude::*;
53

64
pub type c_long = i64;
75
pub type c_ulong = u64;

src/unix/bsd/apple/b32/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! 32-bit specific Apple (ios/darwin) definitions
22
3-
use crate::{c_char, c_int, c_uchar, c_ushort};
3+
use crate::prelude::*;
44

55
pub type c_long = i32;
66
pub type c_ulong = u32;

src/unix/bsd/apple/b64/aarch64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::c_int;
1+
use crate::prelude::*;
22

33
pub type boolean_t = c_int;
44
pub type mcontext_t = *mut __darwin_mcontext64;

0 commit comments

Comments
 (0)