mirror of
https://github.com/github/codeql.git
synced 2026-06-29 00:27:05 +02:00
51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
const GLOBAL_CONST: i32 = 42;
|
|
const STRING_CONST: &str = "hello";
|
|
|
|
struct MyStruct {
|
|
value: i32,
|
|
}
|
|
|
|
impl MyStruct {
|
|
const ASSOC_CONST: i32 = 100;
|
|
}
|
|
|
|
mod my_module {
|
|
pub const MODULE_CONST: i32 = 200;
|
|
}
|
|
|
|
fn use_consts() {
|
|
let x = GLOBAL_CONST; // $ const_access=GLOBAL_CONST
|
|
|
|
let s = STRING_CONST; // $ const_access=STRING_CONST
|
|
|
|
let y = MyStruct::ASSOC_CONST; // $ const_access=ASSOC_CONST
|
|
|
|
let z = my_module::MODULE_CONST; // $ const_access=MODULE_CONST
|
|
|
|
#[rustfmt::skip]
|
|
let _ = if GLOBAL_CONST > 0 { // $ const_access=GLOBAL_CONST
|
|
println!("positive");
|
|
};
|
|
|
|
let arr = [MyStruct::ASSOC_CONST; 5]; // $ const_access=ASSOC_CONST
|
|
|
|
#[rustfmt::skip]
|
|
let _ = if let GLOBAL_CONST = 0 { // $ const_access=GLOBAL_CONST
|
|
println!("zero");
|
|
};
|
|
|
|
{
|
|
const STRING_CONST: &str = "inner"; // Inner1
|
|
let _ = STRING_CONST; // $ const_access=Inner1
|
|
|
|
{
|
|
const STRING_CONST: &str = "inner2"; // Inner2
|
|
let _ = STRING_CONST; // $ const_access=Inner2
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
use_consts();
|
|
}
|