Skip to content

Commit 45b7066

Browse files
authored
Standardize project linting using Cargo lint table (#1305)
2 parents f41cacd + 83fd225 commit 45b7066

90 files changed

Lines changed: 216 additions & 99 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright 2016-2023 the Tectonic Project
33
# Licensed under the MIT License.
44

5+
lints.workspace = true
6+
57
[package]
68
name = "tectonic"
79
version = "0.0.0-dev.0" # assigned with cranko (see README)
@@ -27,10 +29,6 @@ license = "MIT"
2729
edition = "2021"
2830
exclude = ["/dist/", "/reference_sources/"]
2931

30-
[lints.rust]
31-
# FIXME(CraftSpider): Switch from error-chain to a newer package, as it's a deprecated project
32-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(backtrace)', 'cfg(has_error_description_deprecated)'] }
33-
3432
[badges]
3533
travis-ci = { repository = "tectonic-typesetting/tectonic" }
3634
codecov = { repository = "tectonic-typesetting/tectonic", service = "github" }
@@ -63,6 +61,14 @@ members = [
6361
"tests/bundle_env_overrides_test",
6462
]
6563

64+
[workspace.lints.rust]
65+
# FIXME(CraftSpider): Switch from error-chain to a newer package, as it's a deprecated project
66+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(has_error_description_deprecated)'] }
67+
missing_docs = "deny"
68+
69+
[workspace.lints.clippy]
70+
undocumented_unsafe_blocks = "deny"
71+
6672
[lib]
6773
name = "tectonic"
6874
crate-type = ["rlib"]

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2016-2021 the Tectonic Project
22
// Licensed under the MIT License.
33

4+
//! Build script for tectonic binary. Handles some simple environment setup.
5+
46
use std::env;
57

68
fn main() {

crates/bridge_core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
# See README.md for discussion of features (or lack thereof) in this crate.
55

6+
lints.workspace = true
7+
68
[package]
79
name = "tectonic_bridge_core"
810
version = "0.0.0-dev.0" # assigned with cranko (see README)

crates/bridge_core/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2020-2021 the Tectonic Project
22
// Licensed under the MIT License.
33

4+
//! Build script for bridging Tectonic core engine functionality into C code
5+
46
use std::{env, path::PathBuf};
57

68
fn main() {

crates/bridge_core/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright 2016-2022 the Tectonic Project
22
// Licensed under the MIT License.
33

4-
#![deny(missing_docs)]
5-
64
//! Core APIs for bridging the C and Rust portions of Tectonic’s processing
75
//! backends.
86
//!
@@ -223,9 +221,13 @@ impl EngineAbortedError {
223221
}
224222
}
225223

226-
unsafe fn new_with_details() -> Self {
227-
let ptr = _ttbc_get_error_message();
228-
let message = CStr::from_ptr(ptr).to_string_lossy().into_owned();
224+
fn new_with_details() -> Self {
225+
// SAFETY: This is always safe to call
226+
let ptr = unsafe { _ttbc_get_error_message() };
227+
// SAFETY: The pointer returned above will always have a null-terminated C-string in it
228+
let message = unsafe { CStr::from_ptr(ptr) }
229+
.to_string_lossy()
230+
.into_owned();
229231
EngineAbortedError { message }
230232
}
231233
}
@@ -314,7 +316,7 @@ impl<'a> CoreBridgeLauncher<'a> {
314316

315317
if let Err(ref e) = result {
316318
if e.downcast_ref::<EngineAbortedError>().is_some() {
317-
return Err(unsafe { EngineAbortedError::new_with_details() }.into());
319+
return Err(EngineAbortedError::new_with_details().into());
318320
}
319321
}
320322

crates/bridge_flate/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
# See README.md for discussion of features (or lack thereof) in this crate.
55

6+
lints.workspace = true
7+
68
[package]
79
name = "tectonic_bridge_flate"
810
version = "0.0.0-dev.0" # assigned with cranko (see README)

crates/bridge_flate/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2020-2021 the Tectonic Project
22
// Licensed under the MIT License.
33

4+
//! Build script for bridging flate2 into C code
5+
46
use std::{env, path::PathBuf};
57

68
fn main() {

crates/bridge_flate/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright 2020 the Tectonic Project
22
// Licensed under the MIT License.
33

4-
#![deny(missing_docs)]
5-
64
//! This crate provides a few extern "C" functions that expose the functionality
75
//! of the flate2 crate in a C API that can be consumed by other C/C++ code in
86
//! the Tectonic codebase.
@@ -156,7 +154,7 @@ pub unsafe extern "C" fn tectonic_flate_new_decompressor(
156154
done: false,
157155
};
158156

159-
Box::leak(Box::new(dc)) as *mut Decompressor as *mut _
157+
Box::into_raw(Box::new(dc)).cast::<libc::c_void>()
160158
}
161159

162160
/// Decompress some DEFLATEd data.
@@ -177,7 +175,7 @@ pub unsafe extern "C" fn tectonic_flate_decompress_chunk(
177175
output_ptr: *mut u8,
178176
output_len: *mut u64,
179177
) -> libc::c_int {
180-
let mut dc = Box::from_raw(handle as *mut Decompressor);
178+
let mut dc = Box::from_raw(handle.cast::<Decompressor>());
181179
let output = slice::from_raw_parts_mut(output_ptr, *output_len as usize);
182180

183181
let (amount, flag) = match dc.decompress_chunk(output) {
@@ -197,6 +195,6 @@ pub unsafe extern "C" fn tectonic_flate_decompress_chunk(
197195
/// This is a C API function, so it is unsafe.
198196
#[no_mangle]
199197
pub unsafe extern "C" fn tectonic_flate_free_decompressor(handle: *mut libc::c_void) {
200-
let _dc = Box::from_raw(handle as *mut Decompressor);
198+
let _dc = Box::from_raw(handle.cast::<Decompressor>());
201199
// The box will be freed as we exit.
202200
}

crates/bridge_fontconfig/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "tectonic_bridge_fontconfig"
35
version = "0.0.0-dev.0"

crates/bridge_fontconfig/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! fontconfig build script. For now, we always find it externally.
2+
13
use tectonic_dep_support::{Configuration, Dependency, Spec};
24

35
struct FontconfigSpec;

0 commit comments

Comments
 (0)