Skip to content

Commit

Permalink
Enable clippy, suppress lots, fix a couple. (#703)
Browse files Browse the repository at this point in the history
This enables clippy in CI and suppresses most of the existing
warnings. We can drill down and fix those later, but this will
help start getting things under control.
  • Loading branch information
waywardmonkeys authored Aug 13, 2024
1 parent 39a3955 commit fb71d45
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"

jobs:
rustfmt:
Expand Down Expand Up @@ -46,6 +47,9 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run clippy
if: matrix.os == 'macos-14' && matrix.toolchain == 'stable'
run: cargo clippy --all-targets --workspace
typos:
# If this fails, consider changing your text or adding something to .typos.toml
runs-on: ubuntu-latest
Expand Down
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/core-foundation-rs"
rust-version = "1.65"

# TODO: Remove most of these by fixing the actual issues.
[workspace.lints]
clippy.assertions_on_constants = "allow"
clippy.len_without_is_empty = "allow"
clippy.manual_range_contains = "allow"
clippy.missing_safety_doc = "allow"
clippy.new_ret_no_self = "allow"
clippy.new_without_default = "allow"
clippy.non_canonical_partial_ord_impl = "allow"
clippy.not_unsafe_ptr_arg_deref = "allow"
clippy.result_unit_err = "allow"
clippy.too_many_arguments = "allow"
clippy.type_complexity = "allow"

[workspace.dependencies]
cocoa-foundation = { default-features = false, path = "cocoa-foundation", version = "0.2" }
core-foundation = { default-features = false, path = "core-foundation", version = "0.10" }
Expand Down
3 changes: 3 additions & 0 deletions cocoa-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ rust-version.workspace = true
[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
core-foundation.workspace = true
core-graphics-types.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion cocoa-foundation/src/foundation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub type NSInteger = core::ffi::c_long;
#[cfg(target_pointer_width = "64")]
pub type NSUInteger = core::ffi::c_ulong;

pub const NSIntegerMax: NSInteger = NSInteger::max_value();
pub const NSIntegerMax: NSInteger = NSInteger::MAX;
pub const NSNotFound: NSInteger = NSIntegerMax;

const UTF8_ENCODING: usize = 4;
Expand Down
3 changes: 3 additions & 0 deletions cocoa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ rust-version.workspace = true
[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
cocoa-foundation.workspace = true
core-foundation.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions core-foundation-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rust-version.workspace = true
all-features = true
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]

[features]
Expand Down
3 changes: 3 additions & 0 deletions core-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ rust-version.workspace = true
all-features = true
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
core-foundation-sys.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion core-foundation/src/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ pub mod test {
assert_eq!(mut_dict.retain_count(), 2);
assert_eq!(dict.retain_count(), 2);
assert_eq!(
*dict.get(&CFString::from_static_string("Bar")),
*dict.get(CFString::from_static_string("Bar")),
CFBoolean::false_value()
);

Expand Down
3 changes: 3 additions & 0 deletions core-graphics-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ rust-version.workspace = true
[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
core-foundation.workspace = true

Expand Down
3 changes: 3 additions & 0 deletions core-graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rust-version.workspace = true
all-features = true
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
core-foundation.workspace = true
core-graphics-types.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions core-graphics/src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl CGDataProvider {
pub fn from_buffer<T: AsRef<[u8]> + Sync + Send>(buffer: Arc<T>) -> Self {
unsafe {
let ptr = (*buffer).as_ref().as_ptr() as *const c_void;
let len = (*buffer).as_ref().len() as usize;
let len = (*buffer).as_ref().len();
let info = Arc::into_raw(buffer) as *mut c_void;
let result = CGDataProviderCreateWithData(info, ptr, len, Some(release::<T>));
return CGDataProvider::from_ptr(result);
Expand All @@ -69,11 +69,11 @@ impl CGDataProvider {
}
}

/// Creates a data prvider from a given slice. The data provider does not own the slice in this
/// Creates a data provider from a given slice. The data provider does not own the slice in this
/// case, so it's up to the user to ensure the memory safety here.
pub unsafe fn from_slice(buffer: &[u8]) -> Self {
let ptr = buffer.as_ptr() as *const c_void;
let len = buffer.len() as usize;
let len = buffer.len();
let result = CGDataProviderCreateWithData(ptr::null_mut(), ptr, len, None);
CGDataProvider::from_ptr(result)
}
Expand Down
3 changes: 3 additions & 0 deletions core-text/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rust-version.workspace = true
all-features = true
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
core-foundation.workspace = true
core-graphics.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions core-text/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,13 @@ fn macos_version() -> (i32, i32, i32) {
let k = unsafe { propertylist::CFPropertyList::wrap_under_create_rule(list) };

let dict = unsafe {
std::mem::transmute::<_, CFDictionary<CFType, CFType>>(
std::mem::transmute::<CFDictionary, CFDictionary<CFType, CFType>>(
k.downcast::<CFDictionary>().unwrap(),
)
};

let version = dict
.find(&CFString::new("ProductVersion").as_CFType())
.find(CFString::new("ProductVersion").as_CFType())
.as_ref()
.unwrap()
.downcast::<CFString>()
Expand Down
3 changes: 3 additions & 0 deletions io-surface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ rust-version.workspace = true
[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"

[lints]
workspace = true

[dependencies]
core-foundation.workspace = true
core-foundation-sys.workspace = true
Expand Down

0 comments on commit fb71d45

Please sign in to comment.