Skip to content

Commit 6455886

Browse files
committed
Merge branch 'master' into fn-ptr
2 parents 1645da1 + ff93441 commit 6455886

491 files changed

Lines changed: 608 additions & 963 deletions

File tree

Some content is hidden

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

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
if: matrix.language == 'rust'
3131
uses: dtolnay/rust-toolchain@master
3232
with:
33-
toolchain: 1.94.0
33+
toolchain: 1.95.0
3434

3535
- name: Initialize CodeQL
3636
uses: github/codeql-action/init@v4

.github/workflows/format.yml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
name: Format Check
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches: [ "**" ]
49

510
jobs:
611
format:
712
runs-on: ubuntu-latest
813
permissions:
9-
contents: read
14+
contents: write
1015

1116
steps:
1217
- name: Checkout code
@@ -20,8 +25,36 @@ jobs:
2025
- name: Setup Rust
2126
uses: dtolnay/rust-toolchain@master
2227
with:
23-
toolchain: 1.94.0
24-
components: rustfmt
28+
toolchain: 1.95.0
29+
components: rustfmt, clippy
30+
31+
- name: Setup nightly Rust for rule-preprocessor clippy
32+
uses: dtolnay/rust-toolchain@master
33+
with:
34+
toolchain: nightly
35+
components: rustfmt, clippy, rustc-dev
36+
37+
- name: Apply C++ formatting fixes
38+
run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format -i
39+
40+
- name: Apply Rust lint fixes
41+
run: |
42+
cargo clippy --fix --allow-dirty --manifest-path rules/Cargo.toml --all-targets
43+
cargo +nightly clippy --fix --allow-dirty --manifest-path rule-preprocessor/Cargo.toml --all-targets
44+
cargo clippy --fix --allow-dirty --manifest-path libcc2rs/Cargo.toml --all-targets
45+
46+
- name: Apply Rust formatting fixes
47+
run: |
48+
cargo fmt --manifest-path rules/Cargo.toml
49+
cargo fmt --manifest-path rule-preprocessor/Cargo.toml
50+
cargo fmt --manifest-path libcc2rs/Cargo.toml
51+
find tests -name '*.rs' -print0 | xargs -0 rustfmt
52+
53+
- name: Commit auto-fixes
54+
if: github.ref != 'refs/heads/master'
55+
uses: stefanzweifel/git-auto-commit-action@v5
56+
with:
57+
commit_message: "Automatically apply formatting and lint fixes"
2558

2659
- name: Check C++ formatting
2760
run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format --dry-run --Werror
@@ -31,3 +64,10 @@ jobs:
3164
cargo fmt --manifest-path rules/Cargo.toml -- --check
3265
cargo fmt --manifest-path rule-preprocessor/Cargo.toml -- --check
3366
cargo fmt --manifest-path libcc2rs/Cargo.toml -- --check
67+
find tests -name '*.rs' -print0 | xargs -0 rustfmt --check
68+
69+
- name: Check Rust lints
70+
run: |
71+
cargo clippy --manifest-path rules/Cargo.toml --all-targets --all-features -- -Dwarnings
72+
cargo +nightly clippy --manifest-path rule-preprocessor/Cargo.toml --all-targets --all-features -- -Dwarnings
73+
cargo clippy --manifest-path libcc2rs/Cargo.toml --all-targets --all-features -- -Dwarnings

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Setup Rust
2929
uses: dtolnay/rust-toolchain@master
3030
with:
31-
toolchain: 1.94.0
31+
toolchain: 1.95.0
3232
components: rustfmt
3333

3434
- name: Setup Python

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if (NOT RUSTC_LLVM_VERSION STREQUAL LLVM_PACKAGE_VERSION)
6363
message(WARNING "The LLVM versions used by rustc and clang are different!")
6464
endif()
6565

66-
set(RUST_STABLE_VERSION "1.94.0")
66+
set(RUST_STABLE_VERSION "1.95.0")
6767

6868
function(write_rust_toolchain DIR)
6969
set(_content "[toolchain]\nchannel = \"${RUST_STABLE_VERSION}\"\n")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ On Ubuntu, install the required dependencies with:
3737

3838
```bash
3939
sudo apt install libclang-22-dev clang++-22 ninja-build cmake python3-tomli
40-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.94.0
40+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.95.0
4141
```
4242

4343

cpp2rust/converter/converter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ use libc::*;
4848
extern crate libcc2rs;
4949
use libcc2rs::*;
5050
use std::collections::BTreeMap;
51-
use std::rc::Rc;
52-
use std::io::{Read, Write};
53-
use std::io::Seek;
51+
use std::io::{Read, Write, Seek};
5452
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
53+
use std::rc::Rc;
5554
)");
5655
}
5756

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ void ConverterRefCount::EmitFilePreamble() {
2323
StrCat(R"(
2424
extern crate libcc2rs;
2525
use libcc2rs::*;
26-
use std::collections::BTreeMap;
2726
use std::cell::RefCell;
28-
use std::io::{Read, Write};
29-
use std::rc::{Rc, Weak};
30-
use std::io::Seek;
31-
use std::os::fd::AsFd;
27+
use std::collections::BTreeMap;
28+
use std::io::{Read, Write, Seek};
3229
use std::io::prelude::*;
30+
use std::os::fd::AsFd;
31+
use std::rc::{Rc, Weak};
3332
)");
3433
}
3534

libcc2rs/rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.94.0"
2+
channel = "1.95.0"

libcc2rs/src/compat.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ extern "C" {
1313
fn platform_malloc_size(ptr: *const c_void) -> usize;
1414
}
1515

16+
/// # Safety
17+
///
18+
/// The pointer `ptr` must be a pointer to a block of memory allocated by
19+
/// the appropriate allocator (e.g., `malloc`).
20+
// The memory must not have been deallocated.
1621
pub unsafe fn malloc_usable_size(ptr: *mut c_void) -> usize {
1722
#[cfg(target_os = "linux")]
1823
{

libcc2rs/src/dec.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ prefix_wrap_dec_impl!(i8, u8, i16, u16, i32, u32, i64, u64, isize, usize);
6666
prefix_nowrap_dec_impl!(f32, f64);
6767

6868
pub trait UnsafePostfixDec {
69+
/// # Safety
70+
/// This function decrements a pointer and returns the old value.
71+
/// The caller must ensure the pointer is valid and doesn't underflow.
6972
unsafe fn postfix_dec(&mut self) -> Self;
7073
}
7174

@@ -88,6 +91,9 @@ impl<T> UnsafePostfixDec for *mut T {
8891
}
8992

9093
pub trait UnsafePrefixDec {
94+
/// # Safety
95+
/// This function decrements a pointer and returns the new value.
96+
/// The caller must ensure the pointer is valid and doesn't underflow.
9197
unsafe fn prefix_dec(&mut self) -> Self;
9298
}
9399

0 commit comments

Comments
 (0)