Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
name = "misra_rust"
edition = "2024"
version = "0.1.0"
authors = ["Shea Newton <snewton@polysync.io>"]

[dependencies.clippy]
version = "=0.0.210"

[dev-dependencies.compiletest_rs]
version = "=0.3.11"
version = "0.11.2"

2 changes: 1 addition & 1 deletion tests/compile-fail/Rule_10_5.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
let x: bool = 3 as bool; //~ ERROR cannot cast as `bool`
let x: bool = 3 as bool; //~ cannot cast `i32` as `bool` [E0054]
}
4 changes: 2 additions & 2 deletions tests/compile-fail/Rule_10_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ 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`
let _ = u32_c * //~ ERROR cannot multiply `u32` by `u16` [E0277]
(u16_a + u16_b); //~ ERROR mismatched types [E0308]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_11_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ fn main() {
let t = Type { f: 3.14 };
let r1: &Type = t as &Type;
//~^ ERROR non-primitive cast: `Type` as `&Type`
let r2: &Type = From::from(t);
//~^ ERROR the trait bound `&Type: std::convert::From<Type>` is not satisfied
let r2: &Type = From::from(t); //~ ERROR the trait bound `&Type: From<Type>` is not satisfied [E0277]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_11_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ 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
let tb2: TypeB = From::from(ta); //~ ERROR the trait bound `TypeB: From<TypeA>` is not satisfied [E0277]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_11_8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fn main() {
let a = 1;
*(&mut a) = 2;
//~^ ERROR cannot borrow immutable local variable `a` as mutable
*(&mut a) = 2; //~ ERROR cannot borrow `a` as mutable, as it is not declared as mutable [E0596]
}
5 changes: 2 additions & 3 deletions tests/compile-fail/Rule_12_2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fn main() {
let u8a: u8 = 1;
let _: u8 = u8a << 8;
//~^ ERROR attempt to shift left with overflow
}
let _: u8 = u8a << 8; //~ ERROR this arithmetic operation will overflow [arithmetic_overflow]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_12_4.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fn main() {
let u8a: u8 = 0;
let _x = u8a - 10;
//~^ERROR Non-compliant - attempt to subtract with overflow
let _x = u8a - 10; //~ERROR this arithmetic operation will overflow [arithmetic_overflow]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_15_6.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fn main() {
loop
let _ = 1;
//~^ ERROR expected `{`, found `let`
let _ = 1; //~ expected `{`, found keyword `let`
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_16_4.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fn main() {
let i = 1;
match i {
//~^ ERROR non-exhaustive patterns: `_` not covered
match i { //~ ERROR non-exhaustive patterns: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered [E0004]
0 => {}
}
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_17_4.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fn return_v1(depth: u64) -> u64 {
if depth == 2 {
//~^ ERROR if may be missing an else clause
if depth == 2 { //~ ERROR `if` may be missing an `else` clause [E0317]
return depth;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/compile-fail/Rule_17_5.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_variables)]
fn fn1(data: [u32; 3]) {
//
}
Expand Down
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_17_6.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fn main() {
let data: [u32; static 4];
//~^ ERROR expected one of `move`, `|`, or `||`, found `4`
let data: [u32; static 4]; //~ ERROR expected one of `move`, `use`, `|`, or `||`, found `4`
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_18_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ 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]`
let _ = &a1 - &a2; //~ ERROR cannot subtract `&[i32; 10]` from `&[i32; 10]` [E0369]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_18_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ fn main() {
let a: [u8; 10] = [0; 10];
let ptr = &a[5];

(ptr + 5) = 0;
//~^ ERROR invalid left-hand side expression
(ptr + 5) = 0; //~ ERROR invalid left-hand side of assignment [E0070]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_18_6.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fn func() -> &'static i8 {
let local_auto: i8 = 0;
&local_auto
//~^ ERROR `local_auto` does not live long enough
&local_auto //~ ERROR cannot return reference to local variable `local_auto` [E0515]
}

fn main() {
Expand Down
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_18_7.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fn main() {
let a: [u32];
//~^ ERROR the size for value values of type `[u32]` cannot be known at compilation time
let a: [u32]; //~ ERROR the size for values of type `[u32]` cannot be known at compilation time [E0277]
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_20_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ macro_rules! while { //~ ERROR expected identifier, found keyword `while`
}

fn main() {
let _ = while!();
//~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;`
let _ = while!(); //~ ERROR expected `{`, found `;`
}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_20_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ fn main() {
let _ = double_it!(
#[cfg(feature = 10)]
10
#[cfg(feature = 100)]
//~^ ERROR no rules expected the token `#`
#[cfg(feature = 100)] //~ ERROR no rules expected `#`
100
);
}
5 changes: 3 additions & 2 deletions tests/compile-fail/Rule_2_1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[deny(unreachable_code)]
#[allow(unused_assignments, unused_variables)]

fn main() {
let x: u16;
return;
x = 3; //~ ERROR unreachable statement
x = 3; //~ ERROR unreachable statement [unreachable_code]
}

2 changes: 1 addition & 1 deletion tests/compile-fail/Rule_2_2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[deny(dead_code)]

const DEAD_CODE: i32 = 0;
//~^ ERROR constant item is never used: `DEAD_CODE`
//~^ ERROR 3:7: 3:16: constant `DEAD_CODE` is never used [dead_code]

fn main() {}
2 changes: 1 addition & 1 deletion tests/compile-fail/Rule_2_3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[deny(dead_code)]

fn main() {
type LocalType = i16; //~ ERROR type alias is never used: `LocalType`
type LocalType = i16; //~ ERROR type alias `LocalType` is never used [dead_code]
}
4 changes: 2 additions & 2 deletions tests/compile-fail/Rule_2_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

fn main() {
enum State {
//~^ ERROR enum is never used: `State`
//~^ ERROR enum `State` is never used [dead_code]
SInit,
SRun,
SSleep,
};}
}}
2 changes: 1 addition & 1 deletion tests/compile-fail/Rule_4_1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
let x = "\x41\x4g";
//~^ ERROR invalid character in numeric character escape: g
//~^ ERROR invalid character in numeric character escape: `g`
}
6 changes: 3 additions & 3 deletions tests/compile-fail/Rule_5_4.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
macro_rules! engine_exhaust_gas_temperature_raw {
() => {
3;
3
};
}

macro_rules! engine_exhaust_gas_temperature_scaled {
//~^ ERROR Non-compliant - variable name shadows engine_exhaust_gas_temperature_raw
() => {
4;
4
};
}

fn main() {
let _ = engine_exhaust_gas_temperature_raw!();
let _ = engine_exhaust_gas_temperature_scaled!();
}
}
4 changes: 2 additions & 2 deletions tests/compile-fail/Rule_5_5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

macro_rules! val {
() => {
3;
3
};
}

fn main() {
let val!: i16 = 1; //~ ERROR expected open delimiter
let val!: i16 = 1; //~ ERROR expected one of `(`, `[`, or `{`, found `:`
}
8 changes: 5 additions & 3 deletions tests/compile-fail/Rule_5_8.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(unused_variables)]
#[allow(dead_code)]

pub static count: i32 = 1;

fn main() {
let count: i32 = 1;
//~^ ERROR let bindings cannot shadow statics
}
let count: i32 = 1; //~ ERROR let bindings cannot shadow statics [E0530]
}
2 changes: 1 addition & 1 deletion tests/compile-fail/Rule_5_9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const count: i32 = 0;

fn main() {
let count: i32 = 1;
//~^ ERROR refutable pattern in local binding: `_` not covered
//~^ ERROR refutable pattern in local binding
}
2 changes: 1 addition & 1 deletion tests/compile-fail/Rule_8_11.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const arr: [i32] = []; //~ ERROR the size for value values of type `[i32]` cannot be known at compilation time
pub const arr: [i32] = []; //~ ERROR the size for values of type `[i32]` cannot be known at compilation time [E0277]
//~^ ERROR mismatched types

fn main() {}
10 changes: 5 additions & 5 deletions tests/compile-fail/Rule_8_12.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
enum Uniqueness {
red = 3,
blue,
green,
yellow = 5, //~ ERROR discriminant value `5` already exists
enum Uniqueness { //~ ERROR discriminant value `5` assigned more than once [E0081]
RED = 3,
BLUE,
GREEN,
YELLOW = 5,
}

fn main() {}
4 changes: 4 additions & 0 deletions tests/compile-fail/Rule_8_5.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pub const PUBLIC_ZERO: u64 = 0u64;
pub const PUBLIC_ZERO: u64 = 0u64;
//~^ ERROR the name `PUBLIC_ZERO` is defined multiple times

fn main() {

}
4 changes: 4 additions & 0 deletions tests/compile-fail/Rule_8_7.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
pub const LIBRARY_GLOBAL: u32 = 0;
//~^ ERROR Non-compliant - public but not used

fn main() {

}
3 changes: 1 addition & 2 deletions tests/compile-fail/Rule_9_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

fn main() {
let x: u16;
let y = x + 1;
//~^ ERROR use of possibly uninitialized variable: `x`
let y = x + 1; //~ ERROR used binding `x` isn't initialized [E0381]
}
5 changes: 3 additions & 2 deletions tests/compile-fail/Rule_9_5.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fn main() {
let x: [i32] = [0, 1]; //~ ERROR mismatched types
//~^ ERROR the size for value values of type `[i32]` cannot be known at compilation time
let x: [i32] = //~ ERROR the size for values of type `[i32]` cannot be known at compilation time [E0277]
[0, 1]; //~ ERROR mismatched types

}