Skip to content

Commit

Permalink
init following new lints:
Browse files Browse the repository at this point in the history
[`passing_string_to_c_functions`]
[`untrusted_lib_loading`]
[`falliable_memory_allocation`]

Signed-off-by: J-ZhengLi <[email protected]>
  • Loading branch information
J-ZhengLi committed Jun 17, 2023
1 parent da3cc15 commit a50f308
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4532,6 +4532,7 @@ Released 2018-09-13
[`extend_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_with_drain
[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
[`extra_unused_type_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
[`falliable_memory_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#falliable_memory_allocation
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
Expand Down Expand Up @@ -4635,6 +4636,7 @@ Released 2018-09-13
[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
[`large_futures`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_futures
[`large_include_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_include_file
[`large_memory_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_memory_allocation
[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays
[`large_types_passed_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
Expand Down Expand Up @@ -4814,6 +4816,7 @@ Released 2018-09-13
[`partial_pub_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#partial_pub_fields
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
[`partialeq_to_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_to_none
[`passing_string_to_c_functions`]: https://rust-lang.github.io/rust-clippy/master/index.html#passing_string_to_c_functions
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
[`permissions_set_readonly_false`]: https://rust-lang.github.io/rust-clippy/master/index.html#permissions_set_readonly_false
Expand Down Expand Up @@ -5011,6 +5014,7 @@ Released 2018-09-13
[`unsound_collection_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsound_collection_transmute
[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice
[`untrusted_lib_loading`]: https://rust-lang.github.io/rust-clippy/master/index.html#untrusted_lib_loading
[`unused_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
[`unused_format_specs`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_format_specs
Expand Down
3 changes: 3 additions & 0 deletions clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::functions::TOO_MANY_ARGUMENTS_INFO,
crate::functions::TOO_MANY_LINES_INFO,
crate::future_not_send::FUTURE_NOT_SEND_INFO,
crate::guidelines::FALLIABLE_MEMORY_ALLOCATION_INFO,
crate::guidelines::MEM_UNSAFE_FUNCTIONS_INFO,
crate::guidelines::PASSING_STRING_TO_C_FUNCTIONS_INFO,
crate::guidelines::UNTRUSTED_LIB_LOADING_INFO,
crate::if_let_mutex::IF_LET_MUTEX_INFO,
crate::if_not_else::IF_NOT_ELSE_INFO,
crate::if_then_some_else_none::IF_THEN_SOME_ELSE_NONE_INFO,
Expand Down
8 changes: 8 additions & 0 deletions clippy_lints/src/guidelines/falliable_memory_allocation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use rustc_lint::{LateContext, LintContext};

use super::FALLIABLE_MEMORY_ALLOCATION;

// TODO: Adjust the parameters as necessary
pub(super) fn check(cx: &LateContext<'_>) {
todo!();
}
63 changes: 63 additions & 0 deletions clippy_lints/src/guidelines/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
mod falliable_memory_allocation;
mod mem_unsafe_functions;
mod passing_string_to_c_functions;
mod untrusted_lib_loading;

use rustc_hir as hir;
use rustc_hir::intravisit;
Expand Down Expand Up @@ -30,8 +33,68 @@ declare_clippy_lint! {
"use of potentially dangerous external functions"
}

declare_clippy_lint! {
/// ### What it does
///
/// ### Why is this bad?
///
/// ### Example
/// ```rust
/// // example code where clippy issues a warning
/// ```
/// Use instead:
/// ```rust
/// // example code which does not raise clippy warning
/// ```
#[clippy::version = "1.70.0"]
pub UNTRUSTED_LIB_LOADING,
nursery,
"default lint description"
}

declare_clippy_lint! {
/// ### What it does
///
/// ### Why is this bad?
///
/// ### Example
/// ```rust
/// // example code where clippy issues a warning
/// ```
/// Use instead:
/// ```rust
/// // example code which does not raise clippy warning
/// ```
#[clippy::version = "1.70.0"]
pub PASSING_STRING_TO_C_FUNCTIONS,
nursery,
"default lint description"
}

declare_clippy_lint! {
/// ### What it does
///
/// ### Why is this bad?
///
/// ### Example
/// ```rust
/// // example code where clippy issues a warning
/// ```
/// Use instead:
/// ```rust
/// // example code which does not raise clippy warning
/// ```
#[clippy::version = "1.70.0"]
pub FALLIABLE_MEMORY_ALLOCATION,
nursery,
"default lint description"
}

declare_lint_pass!(GuidelineLints => [
MEM_UNSAFE_FUNCTIONS,
UNTRUSTED_LIB_LOADING,
PASSING_STRING_TO_C_FUNCTIONS,
FALLIABLE_MEMORY_ALLOCATION,
]);

impl<'tcx> LateLintPass<'tcx> for GuidelineLints {
Expand Down
8 changes: 8 additions & 0 deletions clippy_lints/src/guidelines/passing_string_to_c_functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use rustc_lint::{LateContext, LintContext};

use super::PASSING_STRING_TO_C_FUNCTIONS;

// TODO: Adjust the parameters as necessary
pub(super) fn check(cx: &LateContext<'_>) {
todo!();
}
8 changes: 8 additions & 0 deletions clippy_lints/src/guidelines/untrusted_lib_loading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use rustc_lint::{LateContext, LintContext};

use super::UNTRUSTED_LIB_LOADING;

// TODO: Adjust the parameters as necessary
pub(super) fn check(cx: &LateContext<'_>) {
todo!();
}
6 changes: 6 additions & 0 deletions tests/ui/falliable_memory_allocation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(unused)]
#![warn(clippy::falliable_memory_allocation)]

fn main() {
// test code goes here
}
6 changes: 6 additions & 0 deletions tests/ui/passing_string_to_c_functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(unused)]
#![warn(clippy::passing_string_to_c_functions)]

fn main() {
// test code goes here
}
6 changes: 6 additions & 0 deletions tests/ui/untrusted_lib_loading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(unused)]
#![warn(clippy::untrusted_lib_loading)]

fn main() {
// test code goes here
}

0 comments on commit a50f308

Please sign in to comment.