Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3d03fce
ci: run `cargo nextest run` with `--no-fail-fast` in CI
kkysen Mar 6, 2026
e8c3b73
transpile: add `--edition`, defaulting to edition 2021 for now
kkysen Mar 6, 2026
d219d33
transpile: only emit `[profile.release] strip = "debuginfo"` before e…
kkysen Mar 6, 2026
89cd402
transpile: tests: add `expect_compile_error`
kkysen Mar 6, 2026
0da2d8d
transpile: tests: add `edition` to `TranspileTest`
kkysen Mar 6, 2026
f847bcd
rust-tools: use a recent nightly for edition 2024 for `rustfmt` and `…
kkysen Mar 6, 2026
e2a98b4
transpile: make `fn maybe_write_file` take `output` as a `&str` not `…
kkysen Mar 6, 2026
7757a26
transpile: remove `generated-rust-toolchain.toml` and generate it fro…
kkysen Mar 6, 2026
29d8e40
transpile: tests: upgrade tests that require 0 changes to edition 2024
kkysen Mar 6, 2026
856a89d
transpile: emit `#[unsafe(no_mangle)]` for edition 2024
kkysen Mar 6, 2026
48685ef
transpile: emit `unsafe extern "C" }` for edition 2024
kkysen Mar 6, 2026
4e5a3f8
transpile: emit `#[unsafe(export_name = "")]` and `#[unsafe(link_sect…
kkysen Mar 6, 2026
2712287
transpile: reset `.unsafety` for `Builder`s
kkysen Mar 13, 2026
9194235
transpile: fix some comment typos for `__builtin_arm_yield`
kkysen Mar 6, 2026
832b4e6
transpile: remove/split `#![feature(stdsimd)]` in edition 2024
kkysen Mar 6, 2026
452ecc3
transpile: tests: make the snapshot default edition 2024 now that mos…
kkysen Mar 6, 2026
1d0adcb
transpile: tests: compute `snapshot_prefix` with `.flatten()` to simp…
kkysen Mar 6, 2026
6abc746
transpile: tests: make `platform` a `&[&str]` instead of `Option<&str>`
kkysen Mar 6, 2026
c1badd7
transpile: tests: separate platform-specific parts with `.` instead o…
kkysen Mar 6, 2026
4c488d1
transpile: tests: rename snapshots so that platform-specific parts ar…
kkysen Mar 6, 2026
74f75ea
transpile: tests: use `@` as the test name and file name separator fo…
kkysen Mar 6, 2026
266388b
transpile: tests: test on both editions
kkysen Mar 6, 2026
c6c615f
transpile: don't emit now stabilized `#![feature(raw_ref_op)]` in edi…
kkysen Mar 6, 2026
cbd1a07
transpile: move the stabilized feature in edition 2024 check to insid…
kkysen Mar 6, 2026
7ea4bf2
transpile: don't emit now stabilized `#![feature(label_break_value)]`…
kkysen Mar 6, 2026
f7d6ce4
transpile: don't emit now stabilized `#![feature(asm)]` in edition 2024
kkysen Mar 6, 2026
57bcced
transpile: remove `#![feature(stdsimd)]` for `__m64`, stabilized in R…
kkysen Mar 6, 2026
2140e68
tests/unit: change `edition` to an `int` instead of a `str`, as this …
kkysen Mar 6, 2026
48eb85d
tests/unit: hoise `edition = 2021` and gate `#![feature(stdsimd)]` be…
kkysen Mar 6, 2026
107eb0f
tests/unit: enable `--color always` for `cargo build`s
kkysen Mar 6, 2026
12c25a8
tests/unit: use named args for `c_file.translate`
kkysen Mar 7, 2026
02d8a7a
tests/unit: add support for `--edition 2021` and `--edition 2024` in …
kkysen Mar 7, 2026
7350385
tests/unit: switch from `--edition` flags to parsing `Cargo.toml`'s `…
kkysen Mar 8, 2026
0c99358
tests/unit: enable `--color always` for `cargo test`s
kkysen Mar 8, 2026
c625956
tests/unit: `#![allow(unsafe_op_in_unsafe_fn)]` until we add proper `…
kkysen Mar 8, 2026
b6b5567
tests/unit: update most tests to edition 2024
kkysen Mar 8, 2026
03a9e44
rust-tools: rename `RustEdition::{Rust => Edition}{2021,2024}`
kkysen Mar 8, 2026
6dc1e9d
rust-tools: use `RustEditon::ALL` in `impl FromStr`
kkysen Mar 8, 2026
b9afa33
transpile: import `Edition{2021,2024}` directly
kkysen Mar 8, 2026
9179447
tests/unit: remove now-stabilized `#![feature(...)]`s in edition 2024…
kkysen Mar 8, 2026
3d3b282
transpile: use raw `r#""` string to avoid escaping `"` in `fn emit_ru…
kkysen Mar 11, 2026
79cae37
transpile: tests: add `fn_attrs.c` from `tests/unit` as a snapshot te…
kkysen Mar 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
--profile minimal --component rustfmt,rustc-dev
rustup toolchain install nightly-2023-04-15 \
--profile minimal --component rustfmt
rustup toolchain install nightly-2026-03-03 \
--profile minimal --component rustfmt

- uses: taiki-e/install-action@nextest

Expand Down Expand Up @@ -126,7 +128,7 @@ jobs:
run: |
export RUSTFLAGS="$RUSTFLAGS -D warnings"
export RUSTDOCFLAGS="-D warnings"
cargo nextest run --release --workspace
cargo nextest run --release --workspace --no-fail-fast
- name: Test translator
run: |
# `test_translator.py` compiles translated code,
Expand Down Expand Up @@ -212,6 +214,6 @@ jobs:

- run: cargo build --release

- run: cargo nextest run --release --no-tests warn
- run: cargo nextest run --release --no-tests warn --no-fail-fast

- run: cargo doc --document-private-items --no-deps
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 26 additions & 17 deletions c2rust-ast-builder/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Helpers for building AST nodes. Normally used by calling `mk().some_node(args...)`.

use std::str;

use itertools::intersperse;
use proc_macro2::{Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::default::Default;
use std::iter::FromIterator;
use std::mem;
use std::str;
use syn::{__private::ToTokens, punctuated::Punctuated, *};

pub mod properties {
Expand Down Expand Up @@ -49,11 +49,12 @@ pub mod properties {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub enum Unsafety {
Normal,
Unsafe,
}

impl ToToken for Unsafety {
type Token = Token![unsafe];
fn to_token(&self) -> Option<Self::Token> {
Expand Down Expand Up @@ -513,15 +514,15 @@ impl Builder {
K: Make<Path>,
V: Make<Lit>,
{
let meta = mk().meta_namevalue(key, value);
let meta = self.clone().meta_namevalue(key, value);
Comment thread
kkysen marked this conversation as resolved.
self.prepared_attr(meta)
}

pub fn single_attr<K>(self, key: K) -> Self
where
K: Make<Path>,
{
let meta = mk().meta_path(key);
let meta = self.clone().meta_path(key);
self.prepared_attr(meta)
}

Expand All @@ -530,7 +531,7 @@ impl Builder {
K: Make<Path>,
V: Make<TokenStream>,
{
let meta = mk().meta_list(func, arguments);
let meta = self.clone().meta_list(func, arguments);
self.prepared_attr(meta)
}

Expand Down Expand Up @@ -1684,7 +1685,7 @@ impl Builder {

Box::new(Item::ForeignMod(ItemForeignMod {
attrs: self.attrs,
unsafety: None,
unsafety: self.unsafety.to_token(),
brace_token: token::Brace(self.span),
items,
abi,
Expand Down Expand Up @@ -1951,6 +1952,13 @@ impl Builder {
}
}

pub fn meta(self, meta: Meta) -> Meta {
match self.unsafety {
Unsafety::Normal => meta,
Unsafety::Unsafe => mk().meta_list("unsafe", vec![meta]),
}
}

/// makes a meta item with just a path
/// # Examples
///
Expand All @@ -1960,7 +1968,7 @@ impl Builder {
Pa: Make<Path>,
{
let path = path.make(&self);
Meta::Path(path)
self.meta(Meta::Path(path))
}

/// makes a meta item with the given path and some arguments
Expand All @@ -1974,34 +1982,35 @@ impl Builder {
{
let path = path.make(&self);
let args = args.make(&self);
Meta::List(MetaList {
let span = self.span;
self.meta(Meta::List(MetaList {
Comment thread
kkysen marked this conversation as resolved.
path,
delimiter: MacroDelimiter::Paren(token::Paren(self.span)),
delimiter: MacroDelimiter::Paren(token::Paren(span)),
tokens: args,
})
}))
}

/// makes a meta item with key value argument
/// # Examples
///
/// mk().meta_namevalue("target_os", "linux") // -> `target_os = "linux"`
pub fn meta_namevalue<K, V>(self, key: K, value: V) -> Meta
pub fn meta_namevalue<K, V>(mut self, key: K, value: V) -> Meta
where
K: Make<Path>,
V: Make<Lit>,
{
let key = key.make(&self);
let lit = value.make(&self);
let value = Expr::Lit(ExprLit {
attrs: self.attrs,
attrs: mem::take(&mut self.attrs),
lit,
});

Meta::NameValue(MetaNameValue {
let span = self.span;
self.meta(Meta::NameValue(MetaNameValue {
path: key,
eq_token: Token![=](self.span),
eq_token: Token![=](span),
value,
})
}))
}

pub fn empty_mac<Pa>(self, path: Pa, delim: MacroDelimiter) -> Macro
Expand Down
18 changes: 16 additions & 2 deletions c2rust-refactor/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use c2rust_refactor::RustcArgSource;
use c2rust_rust_tools::rustc;
use c2rust_rust_tools::rustfmt;
use c2rust_rust_tools::sanitize_file_name;
use c2rust_rust_tools::EDITION;
use c2rust_rust_tools::RustEdition;
use insta::assert_snapshot;
use itertools::Itertools;
use std::path::Path;
Expand All @@ -16,6 +16,7 @@ struct RefactorTest<'a> {
command: &'a str,
command_args: &'a [&'a str],
path: Option<&'a str>,
edition: RustEdition,
old_expect_format_error: bool,
new_expect_format_error: bool,
old_expect_compile_error: bool,
Expand All @@ -27,6 +28,7 @@ fn refactor(command: &str) -> RefactorTest {
command,
command_args: &[],
path: None,
edition: Default::default(),
old_expect_format_error: false,
new_expect_format_error: false,
old_expect_compile_error: false,
Expand All @@ -50,6 +52,11 @@ impl<'a> RefactorTest<'a> {
}
}

#[allow(unused)] // TODO remove once `c2rust-refactor` is upgraded to edition 2024.
pub fn edition(self, edition: RustEdition) -> Self {
Self { edition, ..self }
}

pub fn old_expect_format_error(self, expect_error: bool) -> Self {
Self {
old_expect_format_error: expect_error,
Expand Down Expand Up @@ -93,6 +100,7 @@ impl<'a> RefactorTest<'a> {
command,
path,
command_args,
edition,
old_expect_format_error,
new_expect_format_error,
old_expect_compile_error,
Expand All @@ -110,6 +118,7 @@ impl<'a> RefactorTest<'a> {
command,
command_args,
path,
edition,
old_expect_format_error,
new_expect_format_error,
old_expect_compile_error,
Expand All @@ -122,6 +131,7 @@ fn test_refactor(
command: &str,
command_args: &[&str],
path: &str,
edition: RustEdition,
old_expect_format_error: bool,
new_expect_format_error: bool,
old_expect_compile_error: bool,
Expand All @@ -131,17 +141,19 @@ fn test_refactor(
let old_path = tests_dir.join(path);

rustfmt(&old_path)
.edition(edition)
.check(true)
.expect_error(old_expect_format_error)
.run();
rustc(&old_path)
.edition(edition)
.expect_error(old_expect_compile_error)
.run();

let new_path = old_path.with_extension("new"); // Output from `alongside`.

let old_path = old_path.to_str().unwrap();
let rustc_args = [old_path, "--edition", EDITION];
let rustc_args = [old_path, "--edition", edition.as_str()];

lib_main(Options {
rewrite_modes: vec![OutputMode::Alongside],
Expand All @@ -164,9 +176,11 @@ fn test_refactor(
// TODO Run `rustfmt` by default as part of `c2rust-refactor`
// with the same `--disable-rustfmt` flag that `c2rust-transpile` has.
rustfmt(&new_path)
.edition(edition)
.expect_error(new_expect_format_error)
.run();
rustc(&new_path)
.edition(edition)
.expect_error(new_expect_compile_error)
.run();

Expand Down
1 change: 1 addition & 0 deletions c2rust-rust-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ categories.workspace = true

[dependencies]
fs-err = "3.3.0"
itertools = "0.14.0"
log = "=0.4.28" # "0.4.29" requires Rust 1.68
Loading
Loading