Rustc cross-checker compiler plugin

This is a simple cross-check inserter for Rust code that is implemented as a Rust compiler plugin.

Usage

To use the compiler plugin, you need to take several steps.First, add the plugin as a Cargo dependency to your Cargo.toml file:

1. [dependencies]
2. c2rust-xcheck-plugin = { path = ".../C2Rust/cross-checks/rust-checks/rustc-plugin" }
3. c2rust-xcheck-derive = { path = ".../C2Rust/cross-checks/rust-checks/derive-macros" }
4. c2rust-xcheck-runtime = { path = ".../C2Rust/cross-checks/rust-checks/runtime" }

with … as the full path to the C2Rust repository.Next, add the following preamble to your main.rs or lib.rs file:

2. #![allow(unused_variables)]
3. #![feature(plugin)]
4. #![plugin(c2rust_xcheck_plugin)]

6. fn main() {
7. #[macro_use]
8. extern crate c2rust_xcheck_derive;
9. #[macro_use]
10. extern crate c2rust_xcheck_runtime;
11. }

Cross-checker options

Cross-checking is enabled and configured using the #[cross_check] directive,which can either be enabled globally (using #![cross_check] at the beginning of main.rs or lib.rs) or individuallyper function (the per-function settings override the global ones).

The directive optionally takes the following options:

  • yes and enabled enable cross-checking for the current scope (crateor function).
  • none and disabled disable cross-checking for the current scope.
  • entry(djb2="foo") sets the cross-checking name for the current function entry point to the DJB2 hash of foo.
  • entry(fixed=NNN) sets the cross-checking ID for the current function entry point to NNN.

Example:

2. #![allow(unused_variables)]
3. fn main() {
4. #[cross_check(yes, entry(djb2="foo"))]
5. fn bar() { }

7. #[cross_check(yes, entry(fixed=0x1234))]
8. fn baz() { }

10. #[cross_check(no)]
11. fn foo() { }
12. }