Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ab0eda3
ci: run `cargo nextest run` with `--no-fail-fast` in CI
kkysen Mar 6, 2026
c8f2aff
transpile: add `--edition`, defaulting to edition 2021 for now
kkysen Mar 6, 2026
a4f2ba1
transpile: only emit `[profile.release] strip = "debuginfo"` before e…
kkysen Mar 6, 2026
1036717
transpile: tests: add `expect_compile_error`
kkysen Mar 6, 2026
9693972
transpile: tests: add `edition` to `TranspileTest`
kkysen Mar 6, 2026
a109553
rust-tools: use a recent nightly for edition 2024 for `rustfmt` and `…
kkysen Mar 6, 2026
5a5fa4b
transpile: make `fn maybe_write_file` take `output` as a `&str` not `…
kkysen Mar 6, 2026
b89e837
transpile: remove `generated-rust-toolchain.toml` and generate it fro…
kkysen Mar 6, 2026
549d8b3
transpile: tests: upgrade tests that require 0 changes to edition 2024
kkysen Mar 6, 2026
744e8d6
transpile: emit `#[unsafe(no_mangle)]` for edition 2024
kkysen Mar 6, 2026
ec99a1b
transpile: emit `unsafe extern "C" }` for edition 2024
kkysen Mar 6, 2026
e30779a
transpile: emit `#[unsafe(export_name = "")]` and `#[unsafe(link_sect…
kkysen Mar 6, 2026
9849cae
transpile: fix some comment typos for `__builtin_arm_yield`
kkysen Mar 6, 2026
c5b7cbc
transpile: remove/split `#![feature(stdsimd)]` in edition 2024
kkysen Mar 6, 2026
4a55389
transpile: tests: make the snapshot default edition 2024 now that mos…
kkysen Mar 6, 2026
f955267
transpile: tests: compute `snapshot_prefix` with `.flatten()` to simp…
kkysen Mar 6, 2026
dd1cef9
transpile: tests: make `platform` a `&[&str]` instead of `Option<&str>`
kkysen Mar 6, 2026
d4f49e3
transpile: tests: separate platform-specific parts with `.` instead o…
kkysen Mar 6, 2026
3e40180
transpile: tests: rename snapshots so that platform-specific parts ar…
kkysen Mar 6, 2026
253e66d
transpile: tests: use `@` as the test name and file name separator fo…
kkysen Mar 6, 2026
512b0c6
transpile: tests: test on both editions
kkysen Mar 6, 2026
1c9a6d1
transpile: don't emit now stabilized `#![feature(raw_ref_op)]` in edi…
kkysen Mar 6, 2026
97902eb
transpile: move the stabilized feature in edition 2024 check to insid…
kkysen Mar 6, 2026
1b5050e
transpile: don't emit now stabilized `#![feature(label_break_value)]`…
kkysen Mar 6, 2026
a23298a
transpile: don't emit now stabilized `#![feature(asm)]` in edition 2024
kkysen Mar 6, 2026
64cac44
transpile: remove `#![feature(stdsimd)]` for `__m64`, stabilized in R…
kkysen Mar 6, 2026
3361021
tests/unit: change `edition` to an `int` instead of a `str`, as this …
kkysen Mar 6, 2026
4013b66
tests/unit: hoise `edition = 2021` and gate `#![feature(stdsimd)]` be…
kkysen Mar 6, 2026
6546e91
tests/unit: enable `--color always` for `cargo build`s
kkysen Mar 6, 2026
09ebf4b
tests/unit: use named args for `c_file.translate`
kkysen Mar 7, 2026
d6f5376
tests/unit: add support for `--edition 2021` and `--edition 2024` in …
kkysen Mar 7, 2026
faf532d
tests/unit: switch from `--edition` flags to parsing `Cargo.toml`'s `…
kkysen Mar 8, 2026
0a34f33
tests/unit: enable `--color always` for `cargo test`s
kkysen Mar 8, 2026
5d9c36b
tests/unit: `#![allow(unsafe_op_in_unsafe_fn)]` until we add proper `…
kkysen Mar 8, 2026
6043bee
tests/unit: update most tests to edition 2024
kkysen Mar 8, 2026
3b1424e
rust-tools: rename `RustEdition::{Rust => Edition}{2021,2024}`
kkysen Mar 8, 2026
4470f88
rust-tools: use `RustEditon::ALL` in `impl FromStr`
kkysen Mar 8, 2026
f277687
transpile: import `Edition{2021,2024}` directly
kkysen Mar 8, 2026
9bbfccc
tests/unit: remove now-stabilized `#![feature(...)]`s in edition 2024…
kkysen Mar 8, 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);
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 {
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