2022-12-01 11:29:38 -06:00
|
|
|
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
|
2023-07-02 07:35:19 -05:00
|
|
|
#![allow(clippy::let_unit_value, clippy::missing_safety_doc, clippy::needless_if)]
|
2022-12-01 11:29:38 -06:00
|
|
|
|
|
|
|
mod unsafe_items_invalid_comment {
|
|
|
|
// SAFETY:
|
|
|
|
const CONST: u32 = 0;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: constant item has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
// SAFETY:
|
|
|
|
static STATIC: u32 = 0;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: static item has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
// SAFETY:
|
|
|
|
struct Struct;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: struct has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
// SAFETY:
|
|
|
|
enum Enum {}
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: enum has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
// SAFETY:
|
|
|
|
mod module {}
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: module has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
mod unnecessary_from_macro {
|
|
|
|
trait T {}
|
|
|
|
|
|
|
|
macro_rules! no_safety_comment {
|
|
|
|
($t:ty) => {
|
|
|
|
impl T for $t {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This is not caught
|
|
|
|
// Safety: unnecessary
|
|
|
|
no_safety_comment!(());
|
|
|
|
|
|
|
|
macro_rules! with_safety_comment {
|
|
|
|
($t:ty) => {
|
|
|
|
// Safety: unnecessary
|
|
|
|
impl T for $t {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
with_safety_comment!(i32);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unnecessary_on_stmt_and_expr() -> u32 {
|
|
|
|
// SAFETY: unnecessary
|
|
|
|
let num = 42;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: statement has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
|
|
|
|
// SAFETY: unnecessary
|
|
|
|
if num > 24 {}
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: statement has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
|
|
|
|
// SAFETY: unnecessary
|
|
|
|
24
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: expression has unnecessary safety comment
|
2022-12-01 11:29:38 -06:00
|
|
|
}
|
|
|
|
|
2023-01-27 14:09:08 -06:00
|
|
|
mod issue_10084 {
|
|
|
|
unsafe fn bar() -> i32 {
|
|
|
|
42
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! foo {
|
|
|
|
() => {
|
|
|
|
// SAFETY: This is necessary
|
|
|
|
unsafe { bar() }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
foo!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-11 10:27:03 -06:00
|
|
|
mod issue_12048 {
|
|
|
|
pub const X: u8 = 0;
|
|
|
|
|
|
|
|
/// Returns a pointer to five.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// use foo::point_to_five;
|
|
|
|
///
|
|
|
|
/// let five_pointer = point_to_five();
|
|
|
|
/// // Safety: this pointer always points to a valid five.
|
|
|
|
/// let five = unsafe { *five_pointer };
|
|
|
|
/// assert_eq!(five, 5);
|
|
|
|
/// ```
|
|
|
|
pub fn point_to_five() -> *const u8 {
|
|
|
|
static FIVE: u8 = 5;
|
|
|
|
&FIVE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 11:29:38 -06:00
|
|
|
fn main() {}
|