Skip to content

Commit 7684346

Browse files
authored
Fix rustc and clippy warnings (#492)
* Fix most rustc warnings * Fix clippy warnings * Abstract LLVMConstArray * Fix CI
1 parent 6c0fb56 commit 7684346

Some content is hidden

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

43 files changed

+309
-290
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push, pull_request]
55
env:
66
CARGO_TERM_COLOR: always
77
DOC_LLVM_FEATURE: llvm17-0
8-
DOC_LLVM_VERSION: '17.0'
8+
DOC_LLVM_VERSION: "17.0"
99
DOC_PATH: target/doc
1010

1111
jobs:
@@ -14,9 +14,9 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Install Rust Stable
17-
run: rustup toolchain install stable
17+
uses: dtolnay/rust-toolchain@stable
1818
- name: Install typos
19-
run: cargo install typos-cli
19+
uses: taiki-e/install-action@typos
2020
- name: Run typos
2121
run: typos .
2222
tests:
@@ -39,22 +39,24 @@ jobs:
3939
- ["15.0", "15-0"]
4040
- ["16.0", "16-0"]
4141
- ["17.0", "17-0"]
42-
# only use ubuntu-22.04 for llvm 16 and higher
4342
include:
4443
- os: ubuntu-20.04
44+
# only use ubuntu-22.04 for llvm 16 and higher
4545
- os: ubuntu-22.04
4646
llvm-version: ["16.0", "16-0"]
4747
- os: ubuntu-22.04
4848
llvm-version: ["17.0", "17-0"]
4949
steps:
5050
- name: Checkout Repo
51-
uses: actions/checkout@v3
51+
uses: actions/checkout@v4
5252
- name: Install LLVM and Clang
5353
uses: KyleMayes/install-llvm-action@v1
5454
with:
5555
version: ${{ matrix.llvm-version[0] }}
5656
- name: llvm-config
5757
run: llvm-config --version --bindir --libdir
58+
- name: Install Rust Stable
59+
uses: dtolnay/rust-toolchain@stable
5860
- name: Build
5961
run: cargo build --release --features llvm${{ matrix.llvm-version[1] }} --verbose
6062
- name: Run tests
@@ -67,19 +69,19 @@ jobs:
6769
needs: [typos, tests]
6870
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
6971
steps:
70-
- uses: actions/checkout@v3
71-
- uses: KyleMayes/install-llvm-action@v1
72-
with:
73-
version: ${{ env.DOC_LLVM_VERSION }}
74-
- name: Install Rust Nightly
75-
run: rustup toolchain install nightly
76-
- name: Build Documentation
77-
run: cargo +nightly doc --features ${{ env.DOC_LLVM_FEATURE }},nightly --verbose
78-
- name: Doc Index Page Redirection
79-
run: echo '<meta http-equiv="refresh" content="1; url=inkwell/index.html">' > ${{ env.DOC_PATH }}/index.html
80-
- name: Deploy Documentation
81-
uses: peaceiris/actions-gh-pages@v3
82-
with:
83-
github_token: ${{ secrets.GITHUB_TOKEN }}
84-
publish_dir: ${{ env.DOC_PATH }}
85-
force_orphan: true
72+
- uses: actions/checkout@v4
73+
- uses: KyleMayes/install-llvm-action@v1
74+
with:
75+
version: ${{ env.DOC_LLVM_VERSION }}
76+
- name: Install Rust Nightly
77+
uses: dtolnay/rust-toolchain@nightly
78+
- name: Build Documentation
79+
run: cargo +nightly doc --features ${{ env.DOC_LLVM_FEATURE }},nightly --verbose
80+
- name: Doc Index Page Redirection
81+
run: echo '<meta http-equiv="refresh" content="1; url=inkwell/index.html">' > ${{ env.DOC_PATH }}/index.html
82+
- name: Deploy Documentation
83+
uses: peaceiris/actions-gh-pages@v3
84+
with:
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
publish_dir: ${{ env.DOC_PATH }}
87+
force_orphan: true

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ edition = "2021"
1313

1414
[features]
1515
default = ["target-all"]
16+
1617
# Please update internal_macros::FEATURE_VERSIONS when adding a new LLVM version
1718
llvm4-0 = ["llvm-sys-40"]
1819
llvm5-0 = ["llvm-sys-50"]
@@ -29,6 +30,7 @@ llvm15-0 = ["llvm-sys-150"]
2930
llvm16-0 = ["llvm-sys-160"]
3031
llvm17-0 = ["llvm-sys-170"]
3132
llvm18-0 = ["llvm-sys-180"]
33+
3234
# Don't link against LLVM libraries. This is useful if another dependency is
3335
# installing LLVM. See llvm-sys for more details. We can't enable a single
3436
# `no-llvm-linking` feature across the board of llvm versions, as it'll cause
@@ -133,9 +135,8 @@ experimental = ["static-alloc"]
133135
nightly = ["inkwell_internals/nightly"]
134136

135137
[dependencies]
136-
either = "1.5"
137138
inkwell_internals = { path = "./internal_macros", version = "0.9.0" }
138-
libc = "0.2"
139+
139140
llvm-sys-40 = { package = "llvm-sys", version = "40.4", optional = true }
140141
llvm-sys-50 = { package = "llvm-sys", version = "50.4", optional = true }
141142
llvm-sys-60 = { package = "llvm-sys", version = "60.6", optional = true }
@@ -151,9 +152,13 @@ llvm-sys-150 = { package = "llvm-sys", version = "150.0.3", optional = true }
151152
llvm-sys-160 = { package = "llvm-sys", version = "160.1.0", optional = true }
152153
llvm-sys-170 = { package = "llvm-sys", version = "170.0.1", optional = true }
153154
llvm-sys-180 = { package = "llvm-sys", version = "180.0.0", optional = true }
155+
156+
either = "1.5"
157+
libc = "0.2"
154158
once_cell = "1.16"
155-
static-alloc = { version = "0.2", optional = true }
156159
thiserror = "1.0.48"
160+
161+
static-alloc = { version = "0.2", optional = true }
157162
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
158163

159164
[dev-dependencies]

examples/kaleidoscope/implementation_typed_pointers.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ pub struct LexError {
5151
}
5252

5353
impl LexError {
54-
#[allow(unused)]
5554
pub fn new(msg: &'static str) -> LexError {
5655
LexError { error: msg, index: 0 }
5756
}
5857

59-
#[allow(unused)]
6058
pub fn with_index(msg: &'static str, index: usize) -> LexError {
6159
LexError { error: msg, index }
6260
}
@@ -884,7 +882,7 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> {
884882
} => {
885883
let mut old_bindings = Vec::new();
886884

887-
for &(ref var_name, ref initializer) in variables {
885+
for (var_name, initializer) in variables {
888886
let var_name = var_name.as_str();
889887

890888
let initial_val = match *initializer {

examples/kaleidoscope/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ use inkwell::{
3232
use inkwell_internals::llvm_versions;
3333

3434
mod implementation_typed_pointers;
35-
36-
use crate::implementation_typed_pointers::*;
35+
pub use implementation_typed_pointers::*;
3736

3837
// ======================================================================================
3938
// PROGRAM ==============================================================================

src/attributes.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,10 @@ impl AttributeLoc {
369369
match self {
370370
AttributeLoc::Return => 0,
371371
AttributeLoc::Param(index) => {
372-
assert!(
373-
index <= u32::max_value() - 2,
374-
"Param index must be <= u32::max_value() - 2"
375-
);
376-
372+
assert!(index <= u32::MAX - 2, "Param index must be <= u32::MAX - 2");
377373
index + 1
378374
},
379-
AttributeLoc::Function => u32::max_value(),
375+
AttributeLoc::Function => u32::MAX,
380376
}
381377
}
382378
}

src/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'ctx> Builder<'ctx> {
421421
///
422422
/// builder.position_at_end(basic_block);
423423
///
424-
/// let pi = f32_type.const_float(::std::f64::consts::PI);
424+
/// let pi = f32_type.const_float(std::f64::consts::PI);
425425
///
426426
/// builder.build_return(Some(&pi)).unwrap();
427427
///
@@ -542,7 +542,7 @@ impl<'ctx> Builder<'ctx> {
542542
///
543543
/// builder.position_at_end(basic_block);
544544
///
545-
/// let pi = f32_type.const_float(::std::f64::consts::PI);
545+
/// let pi = f32_type.const_float(std::f64::consts::PI);
546546
///
547547
/// builder.build_return(Some(&pi)).unwrap();
548548
///
@@ -900,7 +900,7 @@ impl<'ctx> Builder<'ctx> {
900900
///
901901
/// builder.position_at_end(basic_block);
902902
///
903-
/// let pi = f32_type.const_float(::std::f64::consts::PI);
903+
/// let pi = f32_type.const_float(std::f64::consts::PI);
904904
///
905905
/// builder.build_return(Some(&pi)).unwrap();
906906
///
@@ -3390,7 +3390,7 @@ impl<'ctx> Builder<'ctx> {
33903390
feature = "llvm17-0",
33913391
feature = "llvm18-0"
33923392
)))]
3393-
if ptr.get_type().get_element_type().to_basic_type_enum() != cmp.get_type() {
3393+
if ptr.get_type().get_element_type().as_basic_type_enum() != cmp.get_type() {
33943394
return Err(BuilderError::PointeeTypeMismatch(
33953395
"The pointer does not point to an element of the value type.",
33963396
));

src/context.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use llvm_sys::core::{
2121
LLVMCreateStringAttribute, LLVMDoubleTypeInContext, LLVMFP128TypeInContext, LLVMFloatTypeInContext,
2222
LLVMGetGlobalContext, LLVMGetMDKindIDInContext, LLVMHalfTypeInContext, LLVMInsertBasicBlockInContext,
2323
LLVMInt16TypeInContext, LLVMInt1TypeInContext, LLVMInt32TypeInContext, LLVMInt64TypeInContext,
24-
LLVMInt8TypeInContext, LLVMIntTypeInContext, LLVMMDNodeInContext, LLVMMDStringInContext,
25-
LLVMModuleCreateWithNameInContext, LLVMPPCFP128TypeInContext, LLVMStructCreateNamed, LLVMStructTypeInContext,
26-
LLVMVoidTypeInContext, LLVMX86FP80TypeInContext,
24+
LLVMInt8TypeInContext, LLVMIntTypeInContext, LLVMModuleCreateWithNameInContext, LLVMPPCFP128TypeInContext,
25+
LLVMStructCreateNamed, LLVMStructTypeInContext, LLVMVoidTypeInContext, LLVMX86FP80TypeInContext,
2726
};
27+
#[allow(deprecated)]
28+
use llvm_sys::core::{LLVMMDNodeInContext, LLVMMDStringInContext};
2829
use llvm_sys::ir_reader::LLVMParseIRInContext;
2930
use llvm_sys::prelude::{LLVMContextRef, LLVMDiagnosticInfoRef, LLVMTypeRef, LLVMValueRef};
3031
use llvm_sys::target::{LLVMIntPtrTypeForASInContext, LLVMIntPtrTypeInContext};
@@ -328,6 +329,7 @@ impl ContextImpl {
328329
}
329330
}
330331

332+
#[allow(deprecated)]
331333
fn metadata_node<'ctx>(&self, values: &[BasicMetadataValueEnum<'ctx>]) -> MetadataValue<'ctx> {
332334
let mut tuple_values: Vec<LLVMValueRef> = values.iter().map(|val| val.as_value_ref()).collect();
333335
unsafe {
@@ -339,6 +341,7 @@ impl ContextImpl {
339341
}
340342
}
341343

344+
#[allow(deprecated)]
342345
fn metadata_string<'ctx>(&self, string: &str) -> MetadataValue<'ctx> {
343346
let c_string = to_c_str(string);
344347

src/debug_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl<'ctx> DIScope<'ctx> {
167167
/// Specific scopes (i.e. `DILexicalBlock`) can be turned into a `DIScope` with the
168168
/// `AsDIScope::as_debug_info_scope` trait method.
169169
pub trait AsDIScope<'ctx> {
170+
#[allow(clippy::wrong_self_convention)]
170171
fn as_debug_info_scope(self) -> DIScope<'ctx>;
171172
}
172173

src/execution_engine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'ctx> ExecutionEngine<'ctx> {
406406
let cstring_args: Vec<_> = args.iter().map(|&arg| to_c_str(arg)).collect();
407407
let raw_args: Vec<*const _> = cstring_args.iter().map(|arg| arg.as_ptr()).collect();
408408

409-
let environment_variables = vec![]; // TODO: Support envp. Likely needs to be null terminated
409+
let environment_variables = []; // TODO: Support envp. Likely needs to be null terminated
410410

411411
LLVMRunFunctionAsMain(
412412
self.execution_engine_inner(),
@@ -475,7 +475,7 @@ impl Deref for ExecEngineInner<'_> {
475475
type Target = LLVMExecutionEngineRef;
476476

477477
fn deref(&self) -> &Self::Target {
478-
&*self.0
478+
&self.0
479479
}
480480
}
481481

src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! * Most functions which take a string slice as input may possibly panic in the unlikely event that a c style string cannot be created based on it. (IE if your slice already has a null byte in it)
1010
1111
#![deny(missing_debug_implementations)]
12+
#![allow(clippy::missing_safety_doc, clippy::too_many_arguments, clippy::result_unit_err)]
1213
#![cfg_attr(feature = "nightly", feature(doc_cfg))]
1314

1415
#[macro_use]
@@ -147,15 +148,9 @@ assert_unique_used_features! {
147148
///
148149
/// # Remarks
149150
/// See also: https://llvm.org/doxygen/NVPTXBaseInfo_8h_source.html
150-
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
151+
#[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
151152
pub struct AddressSpace(u32);
152153

153-
impl Default for AddressSpace {
154-
fn default() -> Self {
155-
AddressSpace(0)
156-
}
157-
}
158-
159154
impl From<u16> for AddressSpace {
160155
fn from(val: u16) -> Self {
161156
AddressSpace(val as u32)

0 commit comments

Comments
 (0)