repo
stringlengths
6
65
file_url
stringlengths
81
311
file_path
stringlengths
6
227
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:31:58
2026-01-04 20:25:31
truncated
bool
2 classes
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_5_1.rs
tests/compile-fail/Rule_5_1.rs
#[allow(dead_code, unused_variables)] const ABC: i32 = 0; fn main() { let abc: i32 = 1; //~^ ERROR Non-compliant - variable name shadows ABC let _ = abc + ABC; }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_14_1.rs
tests/compile-fail/Rule_14_1.rs
fn main() { let mut f: f64 = 0_f64; while f < 1.0 { f += 0.001_f64; //^ ERROR Non-compliant - loop counter with floating point type } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_2_7.rs
tests/compile-fail/Rule_2_7.rs
#[deny(unused_variables)] fn has_unused_parameter(p1: &mut u16, unused: i16) { //~^ ERROR unused variable: `unused` *p1 = 0; } fn main() { let mut p1: u16 = 0; has_unused_parameter(&mut p1, 2); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_5_4.rs
tests/compile-fail/Rule_5_4.rs
macro_rules! engine_exhaust_gas_temperature_raw { () => { 3; }; } macro_rules! engine_exhaust_gas_temperature_scaled { //~^ ERROR Non-compliant - variable name shadows engine_exhaust_gas_temperature_raw () => { 4; }; } fn main() { let _ = engine_exhaust_gas_temperature_raw!(); let _ = engine_exhaust_gas_temperature_scaled!(); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_16_1.rs
tests/compile-fail/Rule_16_1.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_12.rs
tests/compile-fail/Rule_20_12.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_15_3.rs
tests/compile-fail/Rule_15_3.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_1.rs
tests/compile-fail/Rule_11_1.rs
/// This function adds one to the input fn add_one(x: i32) -> i32 { x + 1 } fn main() { let _x: u32 = 1 as add_one; //~^ ERROR expected type, found function `add_one` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_2_5.rs
tests/compile-fail/Rule_2_5.rs
#[deny(unused_macros)] macro_rules! data { //~^ ERROR unused macro definition () => { 3; }; } fn main() {}
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_13_1.rs
tests/compile-fail/Rule_13_1.rs
fn main() { let mut x: u8 = 0; let _: [&u8; 2] = [&mut x, &mut x]; //~^ ERROR cannot borrow `x` as mutable more than once at a time }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_3.rs
tests/compile-fail/Rule_21_3.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_13.rs
tests/compile-fail/Rule_8_13.rs
#[allow(unused_variables)] fn main() { let mut _x: Box<u8> = Box::new(8); //~^ ERROR Non-compliant - "pointer" is not const-qualified. }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_14_2.rs
tests/compile-fail/Rule_14_2.rs
fn main() { let mut bound: u32 = 100; for i in 0..bound { bound -= i; //~^ ERROR Non-compliant - attempt to mutate range bound within loop } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_10_6.rs
tests/compile-fail/Rule_10_6.rs
fn main() { let x: u16 = 1; let y: u16 = 2; let z: u32 = x + y; //~^ ERROR mismatched types }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_1.rs
tests/compile-fail/Rule_21_1.rs
macro_rules! println { //~ ERROR Non-compliant - redefinition of macro name () => { 3; }; } fn main() { println!(); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_9_4.rs
tests/compile-fail/Rule_9_4.rs
#[derive(Debug)] struct Once { a: i32, } fn main() { let _ = Once { a: 1, a: 2 }; //~^ ERROR field `a` specified more than once }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_5.rs
tests/compile-fail/Rule_11_5.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_8.rs
tests/compile-fail/Rule_20_8.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_1_2.rs
tests/compile-fail/Rule_1_2.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_10.rs
tests/compile-fail/Rule_8_10.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_2_3.rs
tests/compile-fail/Rule_2_3.rs
#[deny(dead_code)] fn main() { type LocalType = i16; //~ ERROR type alias is never used: `LocalType` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_4.rs
tests/compile-fail/Rule_20_4.rs
macro_rules! while { //~ ERROR expected identifier, found keyword `while` //~^ ERROR unused macro definition () => (3;); } fn main() { let _ = while!(); //~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_3.rs
tests/compile-fail/Rule_8_3.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_4.rs
tests/compile-fail/Rule_8_4.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_22_1.rs
tests/compile-fail/Rule_22_1.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_13_5.rs
tests/compile-fail/Rule_13_5.rs
/// This function has a side effect. fn not(x: &mut bool) -> &mut bool { *x = !*x; x } fn main() { let mut x: bool = true; if *not(&mut x) || *not(&mut x) { //~^ ERROR Non-compliant - right hand operand contains persistent side-effects } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_15_7.rs
tests/compile-fail/Rule_15_7.rs
fn main() { let x = 1; if x == 2 { let _ = 1; } else if x == 3 { let _ = 2; } //~^ ERROR Non-compliant - no terminating `else` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_9.rs
tests/compile-fail/Rule_8_9.rs
const GLOBAL: u32 = 0; fn main() { let _x = GLOBAL + 1; //~^ ERROR Non-compliant - global only used at block scope }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_14_4.rs
tests/compile-fail/Rule_14_4.rs
fn main() { let a: i32 = 0; if a { //~^ ERROR mismatched types } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_7.rs
tests/compile-fail/Rule_8_7.rs
pub const LIBRARY_GLOBAL: u32 = 0; //~^ ERROR Non-compliant - public but not used
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_6.rs
tests/compile-fail/Rule_18_6.rs
fn func() -> &'static i8 { let local_auto: i8 = 0; &local_auto //~^ ERROR `local_auto` does not live long enough } fn main() { func(); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_2.rs
tests/compile-fail/Rule_8_2.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_10_3.rs
tests/compile-fail/Rule_10_3.rs
fn main() { let x: u32 = 2; let y: u16 = x; //~ ERROR mismatched types }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_9.rs
tests/compile-fail/Rule_20_9.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_1.rs
tests/compile-fail/Rule_8_1.rs
#[allow(unused_assignments, unused_variables)] fn main() { let x; //~^ ERROR Non-compliant - type not explicitly specified x = 1; }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_3.rs
tests/compile-fail/Rule_11_3.rs
#[derive(Debug)] struct TypeA { f: f64, } #[derive(Debug)] struct TypeB { f: f64, } fn main() { let ta = TypeA { f: 3.14 }; let tb1: TypeB = ta as TypeB; //~^ ERROR non-primitive cast: `TypeA` as `TypeB` let tb2: TypeB = From::from(ta); //~^ ERROR the trait bound `TypeB: std::convert::From<TypeA>` is not satisfied }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_15_6.rs
tests/compile-fail/Rule_15_6.rs
fn main() { loop let _ = 1; //~^ ERROR expected `{`, found `let` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_12.rs
tests/compile-fail/Rule_8_12.rs
enum Uniqueness { red = 3, blue, green, yellow = 5, //~ ERROR discriminant value `5` already exists } fn main() {}
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_10_2.rs
tests/compile-fail/Rule_10_2.rs
fn main() { let x: i16 = -2; let y = x - 'a'; //~^ ERROR cannot subtract `char` from `i16` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_9_3.rs
tests/compile-fail/Rule_9_3.rs
fn main() { let x: [i32; 3] = [0, 1]; //~^ ERROR mismatched types }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_1.rs
tests/compile-fail/Rule_18_1.rs
fn main() { let c: [i32; 2] = [0; 2]; let mut p = &c[3]; p += 1; //~^ ERROR binary assignment operation `+=` cannot be applied to type `&i32` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_5_5.rs
tests/compile-fail/Rule_5_5.rs
#[allow(unused_variables, unused_macros)] macro_rules! val { () => { 3; }; } fn main() { let val!: i16 = 1; //~ ERROR expected open delimiter }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_3_1.rs
tests/compile-fail/Rule_3_1.rs
fn main() { /* /* Nested comment */ // Nested comment */ //~^ ERROR nested comments }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_17_8.rs
tests/compile-fail/Rule_17_8.rs
fn paramod(mut para: u16) -> u16 { para += 1; //~ ERROR parameter modified without persistent effect let _ = para; 1 } fn main() { paramod(1); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_15_2.rs
tests/compile-fail/Rule_15_2.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_8.rs
tests/compile-fail/Rule_18_8.rs
fn main() { let mut s = 10; let a: [u32; s]; //~^ ERROR attempt to use a non-constant value in a constant }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_16_4.rs
tests/compile-fail/Rule_16_4.rs
fn main() { let i = 1; match i { //~^ ERROR non-exhaustive patterns: `_` not covered 0 => {} } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_6.rs
tests/compile-fail/Rule_11_6.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_10_5.rs
tests/compile-fail/Rule_10_5.rs
fn main() { let x: bool = 3 as bool; //~ ERROR cannot cast as `bool` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_6.rs
tests/compile-fail/Rule_8_6.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_17_2.rs
tests/compile-fail/Rule_17_2.rs
/// This function employs recursion. fn recursive(depth: u64) { if depth == 2 { return; } recursive(depth + 1); //~^ ERROR Non-compliant - function calls itself } fn main() { recursive(0); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_15_5.rs
tests/compile-fail/Rule_15_5.rs
fn main() { let x = 1; if x > 1 { return; } if x < 1 { return; //~^ ERROR Non-compliant - more than one exit point from function } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_3.rs
tests/compile-fail/Rule_20_3.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_2.rs
tests/compile-fail/Rule_21_2.rs
macro_rules! println { //~ ERROR Non-compliant - redefinition of macro name () => { 3; }; } fn main() { println!(); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_9_2.rs
tests/compile-fail/Rule_9_2.rs
union UnionType { f1: i16, f2: i32, } fn main() { let x: UnionType = 0; //~ ERROR mismatched types let y: [[usize;2]; 3] = [0,1,2,3,4,5]; //~^ ERROR mismatched types }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_5.rs
tests/compile-fail/Rule_18_5.rs
fn nesting(p: &&&&&&[u8; 10]) { let _ = ****p; } fn main() { let a = [5; 10]; nesting(&&&&&&a); //~^ ERROR Non-compliant - reference nesting exceeds maximum allowed }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_3.rs
tests/compile-fail/Rule_18_3.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_17_5.rs
tests/compile-fail/Rule_17_5.rs
fn fn1(data: [u32; 3]) { // } fn main() { let data: [u32; 4]; fn1(data); //~^ ERROR mismatched types }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_9.rs
tests/compile-fail/Rule_11_9.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_9.rs
tests/compile-fail/Rule_21_9.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_19_2.rs
tests/compile-fail/Rule_19_2.rs
union UnionA { f1: i16, f2: i32, } fn main() { let mut u = UnionA { f2: 0 }; u.f1 = 3; }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_10_4.rs
tests/compile-fail/Rule_10_4.rs
fn main() { let x: u32 = 2; let y: u16 = 4; let z = x + y; //~ ERROR mismatched types //~^ ERROR cannot add `u16` to `u32` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_13.rs
tests/compile-fail/Rule_20_13.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_7.rs
tests/compile-fail/Rule_21_7.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_2.rs
tests/compile-fail/Rule_18_2.rs
fn main() { let a1: [i32; 10] = [0; 10]; let a2: [i32; 10] = [0; 10]; let _ = &a1 - &a2; //~^ ERROR binary operation `-` cannot be applied to type `&[i32; 10]` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_12.rs
tests/compile-fail/Rule_21_12.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_5_7.rs
tests/compile-fail/Rule_5_7.rs
struct Deer {} fn main() { let _: Deer = Deer {}; { struct Deer {} //~^ ERROR Non-compliant - struct name shadows struct Deer in global scope let _: Deer = Deer {}; } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_1_3.rs
tests/compile-fail/Rule_1_3.rs
#![deny(unsafe_code)] fn main() { let _x = unsafe { *(&0 as *const i32) }; //~^ ERROR usage of an `unsafe` block }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_11.rs
tests/compile-fail/Rule_21_11.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_22_6.rs
tests/compile-fail/Rule_22_6.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_9_1.rs
tests/compile-fail/Rule_9_1.rs
#[allow(unused_variables)] fn main() { let x: u16; let y = x + 1; //~^ ERROR use of possibly uninitialized variable: `x` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_15_4.rs
tests/compile-fail/Rule_15_4.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_4.rs
tests/compile-fail/Rule_11_4.rs
#[derive(Debug)] struct TypeA { f: f64, } fn main() { let i16_a: i16 = 1; let u32_b: u32 = &i16_a as &u16; //~ ERROR mismatched types //~^ ERROR non-primitive cast: `&i16` as `&u16` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_22_4.rs
tests/compile-fail/Rule_22_4.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_17_6.rs
tests/compile-fail/Rule_17_6.rs
fn main() { let data: [u32; static 4]; //~^ ERROR expected one of `move`, `|`, or `||`, found `4` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_16_3.rs
tests/compile-fail/Rule_16_3.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_16_6.rs
tests/compile-fail/Rule_16_6.rs
fn main() { let i = 1; match i { _ => {} //~ ERROR Non-compliant - less that two clauses } }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_17_7.rs
tests/compile-fail/Rule_17_7.rs
fn func(para1: u16) -> u16 { para1 } fn discarded(para2: u16) { func(para2); //~^ ERROR Non-compliant - `func` return discarded } fn main() { discarded(1); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_10.rs
tests/compile-fail/Rule_20_10.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_14.rs
tests/compile-fail/Rule_8_14.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_2_2.rs
tests/compile-fail/Rule_2_2.rs
#[deny(dead_code)] const DEAD_CODE: i32 = 0; //~^ ERROR constant item is never used: `DEAD_CODE` fn main() {}
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_10_7.rs
tests/compile-fail/Rule_10_7.rs
fn main() { let u16_a: u16 = 1; let u16_b: u16 = 2; let u32_c: u32 = 3; let _ = u32_c * (u16_a + u16_b); //~ ERROR mismatched types //~^ ERROR cannot multiply `u16` to `u32` }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_17_4.rs
tests/compile-fail/Rule_17_4.rs
fn return_v1(depth: u64) -> u64 { if depth == 2 { //~^ ERROR if may be missing an else clause return depth; } } fn return_v2(depth: u64) -> u64 { if depth == 2 { return; //~ ERROR `return;` in a function whose return type is not `()` } depth } fn main() { return_v1(0); return_v2(0); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_2_1.rs
tests/compile-fail/Rule_2_1.rs
#[deny(unreachable_code)] fn main() { let x: u16; return; x = 3; //~ ERROR unreachable statement }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_8.rs
tests/compile-fail/Rule_21_8.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_11_7.rs
tests/compile-fail/Rule_11_7.rs
fn main() { let p: &i16; let _ = p as f32; //~^ ERROR casting `&i16` as `f32` is invalid }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_14.rs
tests/compile-fail/Rule_20_14.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_7_2.rs
tests/compile-fail/Rule_7_2.rs
#[allow(unused_variables)] fn main() { let compliant_unsigned: u32 = 1u32; let unsigned: u32 = 1; //~^ ERROR Non-compliant - suffix specifying unsigned type required on integer constants }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_2_4.rs
tests/compile-fail/Rule_2_4.rs
#[deny(dead_code)] fn main() { enum State { //~^ ERROR enum is never used: `State` SInit, SRun, SSleep, };}
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_22_5.rs
tests/compile-fail/Rule_22_5.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_1.rs
tests/compile-fail/Rule_20_1.rs
struct MyStruct { a: u32, } fn func(_: MyStruct) {} use std::fmt; //~ ERROR Non-compliant - `include` directive preceeded by something other than macros or comments impl fmt::Display for MyStruct { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "MyStruct{{ {} }}", self.a) } } fn main() { let s = MyStruct { a: 10 }; func(s); }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_5_9.rs
tests/compile-fail/Rule_5_9.rs
const count: i32 = 0; fn main() { let count: i32 = 1; //~^ ERROR refutable pattern in local binding: `_` not covered }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_20_2.rs
tests/compile-fail/Rule_20_2.rs
include!("../../include/_'_.rs"); //~ ERROR invalid character `'` in crate name: `Rule_20_2_'` fn main() {}
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_21_10.rs
tests/compile-fail/Rule_21_10.rs
"N/A" //~^ ERROR expected item, found `"N/A"`
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_8_11.rs
tests/compile-fail/Rule_8_11.rs
pub const arr: [i32] = []; //~ ERROR the size for value values of type `[i32]` cannot be known at compilation time //~^ ERROR mismatched types fn main() {}
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/tests/compile-fail/Rule_18_7.rs
tests/compile-fail/Rule_18_7.rs
fn main() { let a: [u32]; //~^ ERROR the size for value values of type `[u32]` cannot be known at compilation time }
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
PolySync/misra-rust
https://github.com/PolySync/misra-rust/blob/caa5e5bf9133f277f60a5807e79da6789a1fbb1e/include/_'_.rs
include/_'_.rs
// _'_.rs // Not a MISRA compiant file name.
rust
MIT
caa5e5bf9133f277f60a5807e79da6789a1fbb1e
2026-01-04T20:22:35.104590Z
false
ProjectZKM/zkm
https://github.com/ProjectZKM/zkm/blob/eb09cf6c81bed9717bc98e4a4c9a61f54787a351/runtime/precompiles/src/lib.rs
runtime/precompiles/src/lib.rs
//! Ported from Precompiles for SP1 zkVM. //! //! Specifically, this crate contains user-friendly functions that call SP1 syscalls. Syscalls are //! also declared here for convenience. In order to avoid duplicate symbol errors, the syscall //! function impls must live in sp1-zkvm, which is only imported into the end user program crate. //! In contrast, sp1-precompiles can be imported into any crate in the dependency tree. pub mod io; pub mod utils; pub const BIGINT_WIDTH_WORDS: usize = 8; extern "C" { pub fn syscall_halt(exit_code: u8) -> !; pub fn syscall_write(fd: u32, write_buf: *const u8, nbytes: usize); pub fn syscall_hint_len() -> usize; pub fn syscall_hint_read(ptr: *mut u8, len: usize); pub fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u8; pub fn syscall_verify(claim_digest: &[u8; 32]); /// Executes the Keccak-256 permutation on the given state. pub fn syscall_keccak(state: *const u32, len: usize, result: *mut u8); pub fn syscall_sha256(state: *const u32, len: usize, result: *mut u8); pub fn syscall_sha256_compress(w: *mut u32, state: *mut u32); pub fn syscall_sha256_extend(w: *mut u32); }
rust
MIT
eb09cf6c81bed9717bc98e4a4c9a61f54787a351
2026-01-04T20:21:15.281276Z
false
ProjectZKM/zkm
https://github.com/ProjectZKM/zkm/blob/eb09cf6c81bed9717bc98e4a4c9a61f54787a351/runtime/precompiles/src/io.rs
runtime/precompiles/src/io.rs
//! Ported from Precompiles for SP1 zkVM. #![allow(unused_unsafe)] use crate::syscall_keccak; use crate::syscall_verify; use crate::syscall_write; use crate::{syscall_hint_len, syscall_hint_read}; use crate::{syscall_sha256_compress, syscall_sha256_extend}; use serde::de::DeserializeOwned; use serde::Serialize; use sha2::{Digest, Sha256}; use std::alloc::Layout; use std::io::Write; const FD_HINT: u32 = 4; pub const FD_PUBLIC_VALUES: u32 = 3; pub const ZERO: [u8; 32] = [0u8; 32]; #[allow(dead_code)] pub struct SyscallWriter { fd: u32, } impl std::io::Write for SyscallWriter { fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { let nbytes = buf.len(); let write_buf = buf.as_ptr(); unsafe { syscall_write(self.fd, write_buf, nbytes); } Ok(nbytes) } fn flush(&mut self) -> std::io::Result<()> { Ok(()) } } pub fn read_vec() -> Vec<u8> { let len = unsafe { syscall_hint_len() }; // Round up to the nearest multiple of 4 so that the memory allocated is in whole words let capacity = len.div_ceil(4) * 4; // Allocate a buffer of the required length that is 4 byte aligned let layout = Layout::from_size_align(capacity, 4).expect("vec is too large"); let ptr = unsafe { std::alloc::alloc(layout) }; // SAFETY: // 1. `ptr` was allocated using alloc // 2. We assuume that the VM global allocator doesn't dealloc // 3/6. Size is correct from above // 4/5. Length is 0 // 7. Layout::from_size_align already checks this let mut vec = unsafe { Vec::from_raw_parts(ptr, 0, capacity) }; // Read the vec into uninitialized memory. The syscall assumes the memory is uninitialized, // which should be true because the allocator does not dealloc, so a new alloc should be fresh. unsafe { syscall_hint_read(ptr, len); vec.set_len(len); } vec } pub fn read<T: DeserializeOwned>() -> T { let vec = read_vec(); bincode::deserialize(&vec).expect("deserialization failed") } pub fn commit_slice(buf: &[u8]) { let mut my_writer: SyscallWriter = SyscallWriter { fd: FD_PUBLIC_VALUES, }; my_writer.write_all(buf).unwrap(); } pub fn commit<T: Serialize>(value: &T) { let mut buf = Vec::new(); bincode::serialize_into(&mut buf, value).expect("serialization failed"); commit_slice(buf.as_slice()); } pub fn verify<T: Serialize>(image_id: Vec<u8>, public_input: &T) { let mut buf = Vec::new(); bincode::serialize_into(&mut buf, public_input).expect("serialization failed"); let mut hasher = Sha256::new(); hasher.update(image_id); hasher.update(buf); let digest: [u8; 32] = hasher.finalize().into(); unsafe { syscall_verify(&digest) } } pub fn hint_slice(buf: &[u8]) { let mut my_reader: SyscallWriter = SyscallWriter { fd: FD_HINT }; my_reader.write_all(buf).unwrap(); } pub fn hint<T: Serialize>(value: &T) { let mut buf = Vec::new(); bincode::serialize_into(&mut buf, value).expect("serialization failed"); hint_slice(buf.as_slice()); } /// Write the data `buf` to the file descriptor `fd` using `Write::write_all` . pub fn write(fd: u32, buf: &[u8]) { SyscallWriter { fd }.write_all(buf).unwrap(); } /// Write the data `buf` to the file descriptor `fd` using `Write::write_all` . pub fn print(buf: Vec<u8>) { SyscallWriter { fd: 2u32 } .write_all(buf.as_slice()) .unwrap(); } pub fn keccak(data: &[u8]) -> [u8; 32] { let len = data.len(); let mut u32_array = Vec::new(); if len == 0 { return [ 0xC5, 0xD2, 0x46, 0x01, 0x86, 0xF7, 0x23, 0x3C, 0x92, 0x7E, 0x7D, 0xB2, 0xDC, 0xC7, 0x03, 0xC0, 0xE5, 0, 0xB6, 0x53, 0xCA, 0x82, 0x27, 0x3B, 0x7B, 0xFA, 0xD8, 0x04, 0x5D, 0x85, 0xA4, 0x70, ]; } // covert to u32 to align the memory for i in (0..len).step_by(4) { if i + 4 <= len { let u32_value = u32::from_be_bytes([data[i], data[i + 1], data[i + 2], data[i + 3]]); u32_array.push(u32_value); } else { let mut padded_chunk = [0u8; 4]; padded_chunk[..len - i].copy_from_slice(&data[i..]); padded_chunk[len - i] = 1; let end = len % 136; if end + 4 > 136 { padded_chunk[3] |= 0x80; } let u32_value = u32::from_be_bytes(padded_chunk); u32_array.push(u32_value); } } let mut result = [0u8; 32]; // Read the vec into uninitialized memory. The syscall assumes the memory is uninitialized, // which should be true because the allocator does not dealloc, so a new alloc should be fresh. unsafe { syscall_keccak(u32_array.as_ptr(), len, result.as_mut_ptr()); } result } pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) { unsafe { for block in blocks { let mut w = [0u32; 64]; for (j, item) in w.iter_mut().enumerate().take(16) { *item = u32::from_be_bytes([ block[j * 4], block[j * 4 + 1], block[j * 4 + 2], block[j * 4 + 3], ]); } syscall_sha256_extend(w.as_mut_ptr()); syscall_sha256_compress(w.as_mut_ptr(), state.as_mut_ptr()); } } }
rust
MIT
eb09cf6c81bed9717bc98e4a4c9a61f54787a351
2026-01-04T20:21:15.281276Z
false
ProjectZKM/zkm
https://github.com/ProjectZKM/zkm/blob/eb09cf6c81bed9717bc98e4a4c9a61f54787a351/runtime/precompiles/src/utils.rs
runtime/precompiles/src/utils.rs
//! Ported from Precompiles for SP1 zkVM. pub trait CurveOperations<const NUM_WORDS: usize> { const GENERATOR: [u32; NUM_WORDS]; fn add_assign(limbs: &mut [u32; NUM_WORDS], other: &[u32; NUM_WORDS]); fn double(limbs: &mut [u32; NUM_WORDS]); } #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct AffinePoint<C: CurveOperations<NUM_WORDS>, const NUM_WORDS: usize> { pub(crate) limbs: [u32; NUM_WORDS], _marker: std::marker::PhantomData<C>, } impl<C: CurveOperations<NUM_WORDS> + Copy, const NUM_WORDS: usize> AffinePoint<C, NUM_WORDS> { const GENERATOR: [u32; NUM_WORDS] = C::GENERATOR; pub const fn generator_in_affine() -> Self { Self { limbs: Self::GENERATOR, _marker: std::marker::PhantomData, } } pub const fn new(limbs: [u32; NUM_WORDS]) -> Self { Self { limbs, _marker: std::marker::PhantomData, } } /// x_bytes and y_bytes are the concatenated little endian representations of the x and y coordinates. /// The length of x_bytes and y_bytes must each be NUM_WORDS * 2. pub fn from(x_bytes: &[u8], y_bytes: &[u8]) -> Self { debug_assert!(x_bytes.len() == NUM_WORDS * 2); debug_assert!(y_bytes.len() == NUM_WORDS * 2); let mut limbs = [0u32; NUM_WORDS]; let x = bytes_to_words_le(x_bytes); let y = bytes_to_words_le(y_bytes); debug_assert!(x.len() == NUM_WORDS / 2); debug_assert!(y.len() == NUM_WORDS / 2); limbs[..(NUM_WORDS / 2)].copy_from_slice(&x); limbs[(NUM_WORDS / 2)..].copy_from_slice(&y); Self::new(limbs) } pub fn add_assign(&mut self, other: &AffinePoint<C, NUM_WORDS>) { C::add_assign(&mut self.limbs, &other.limbs); } pub fn double(&mut self) { C::double(&mut self.limbs); } pub fn mul_assign(&mut self, scalar: &[u32]) { debug_assert!(scalar.len() == NUM_WORDS / 2); let mut res: Option<Self> = None; let mut temp = *self; for &words in scalar.iter() { for i in 0..32 { if (words >> i) & 1 == 1 { match res.as_mut() { Some(res) => res.add_assign(&temp), None => res = Some(temp), }; } temp.double(); } } *self = res.unwrap(); } pub fn from_le_bytes(limbs: &[u8]) -> Self { let u32_limbs = bytes_to_words_le(limbs); debug_assert!(u32_limbs.len() == NUM_WORDS); Self { limbs: u32_limbs.try_into().unwrap(), _marker: std::marker::PhantomData, } } pub fn to_le_bytes(&self) -> Vec<u8> { let le_bytes = words_to_bytes_le(&self.limbs); debug_assert!(le_bytes.len() == NUM_WORDS * 4); le_bytes } } /// Converts a slice of words to a byte array in little endian. pub fn words_to_bytes_le(words: &[u32]) -> Vec<u8> { words .iter() .flat_map(|word| word.to_le_bytes().to_vec()) .collect::<Vec<_>>() } /// Converts a byte array in little endian to a slice of words. pub fn bytes_to_words_le(bytes: &[u8]) -> Vec<u32> { bytes .chunks_exact(4) .map(|chunk| u32::from_le_bytes(chunk.try_into().unwrap())) .collect::<Vec<_>>() }
rust
MIT
eb09cf6c81bed9717bc98e4a4c9a61f54787a351
2026-01-04T20:21:15.281276Z
false