Skip to content

Commit a50f308

Browse files
committed
init following new lints:
[`passing_string_to_c_functions`] [`untrusted_lib_loading`] [`falliable_memory_allocation`] Signed-off-by: J-ZhengLi <[email protected]>
1 parent da3cc15 commit a50f308

9 files changed

+112
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,6 +4532,7 @@ Released 2018-09-13
45324532
[`extend_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_with_drain
45334533
[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
45344534
[`extra_unused_type_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
4535+
[`falliable_memory_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#falliable_memory_allocation
45354536
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
45364537
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
45374538
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
@@ -4635,6 +4636,7 @@ Released 2018-09-13
46354636
[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
46364637
[`large_futures`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_futures
46374638
[`large_include_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_include_file
4639+
[`large_memory_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_memory_allocation
46384640
[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays
46394641
[`large_types_passed_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value
46404642
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
@@ -4814,6 +4816,7 @@ Released 2018-09-13
48144816
[`partial_pub_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#partial_pub_fields
48154817
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
48164818
[`partialeq_to_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_to_none
4819+
[`passing_string_to_c_functions`]: https://rust-lang.github.io/rust-clippy/master/index.html#passing_string_to_c_functions
48174820
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
48184821
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
48194822
[`permissions_set_readonly_false`]: https://rust-lang.github.io/rust-clippy/master/index.html#permissions_set_readonly_false
@@ -5011,6 +5014,7 @@ Released 2018-09-13
50115014
[`unsound_collection_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsound_collection_transmute
50125015
[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice
50135016
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice
5017+
[`untrusted_lib_loading`]: https://rust-lang.github.io/rust-clippy/master/index.html#untrusted_lib_loading
50145018
[`unused_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
50155019
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
50165020
[`unused_format_specs`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_format_specs

clippy_lints/src/declared_lints.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
191191
crate::functions::TOO_MANY_ARGUMENTS_INFO,
192192
crate::functions::TOO_MANY_LINES_INFO,
193193
crate::future_not_send::FUTURE_NOT_SEND_INFO,
194+
crate::guidelines::FALLIABLE_MEMORY_ALLOCATION_INFO,
194195
crate::guidelines::MEM_UNSAFE_FUNCTIONS_INFO,
196+
crate::guidelines::PASSING_STRING_TO_C_FUNCTIONS_INFO,
197+
crate::guidelines::UNTRUSTED_LIB_LOADING_INFO,
195198
crate::if_let_mutex::IF_LET_MUTEX_INFO,
196199
crate::if_not_else::IF_NOT_ELSE_INFO,
197200
crate::if_then_some_else_none::IF_THEN_SOME_ELSE_NONE_INFO,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use rustc_lint::{LateContext, LintContext};
2+
3+
use super::FALLIABLE_MEMORY_ALLOCATION;
4+
5+
// TODO: Adjust the parameters as necessary
6+
pub(super) fn check(cx: &LateContext<'_>) {
7+
todo!();
8+
}

clippy_lints/src/guidelines/mod.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
mod falliable_memory_allocation;
12
mod mem_unsafe_functions;
3+
mod passing_string_to_c_functions;
4+
mod untrusted_lib_loading;
25

36
use rustc_hir as hir;
47
use rustc_hir::intravisit;
@@ -30,8 +33,68 @@ declare_clippy_lint! {
3033
"use of potentially dangerous external functions"
3134
}
3235

36+
declare_clippy_lint! {
37+
/// ### What it does
38+
///
39+
/// ### Why is this bad?
40+
///
41+
/// ### Example
42+
/// ```rust
43+
/// // example code where clippy issues a warning
44+
/// ```
45+
/// Use instead:
46+
/// ```rust
47+
/// // example code which does not raise clippy warning
48+
/// ```
49+
#[clippy::version = "1.70.0"]
50+
pub UNTRUSTED_LIB_LOADING,
51+
nursery,
52+
"default lint description"
53+
}
54+
55+
declare_clippy_lint! {
56+
/// ### What it does
57+
///
58+
/// ### Why is this bad?
59+
///
60+
/// ### Example
61+
/// ```rust
62+
/// // example code where clippy issues a warning
63+
/// ```
64+
/// Use instead:
65+
/// ```rust
66+
/// // example code which does not raise clippy warning
67+
/// ```
68+
#[clippy::version = "1.70.0"]
69+
pub PASSING_STRING_TO_C_FUNCTIONS,
70+
nursery,
71+
"default lint description"
72+
}
73+
74+
declare_clippy_lint! {
75+
/// ### What it does
76+
///
77+
/// ### Why is this bad?
78+
///
79+
/// ### Example
80+
/// ```rust
81+
/// // example code where clippy issues a warning
82+
/// ```
83+
/// Use instead:
84+
/// ```rust
85+
/// // example code which does not raise clippy warning
86+
/// ```
87+
#[clippy::version = "1.70.0"]
88+
pub FALLIABLE_MEMORY_ALLOCATION,
89+
nursery,
90+
"default lint description"
91+
}
92+
3393
declare_lint_pass!(GuidelineLints => [
3494
MEM_UNSAFE_FUNCTIONS,
95+
UNTRUSTED_LIB_LOADING,
96+
PASSING_STRING_TO_C_FUNCTIONS,
97+
FALLIABLE_MEMORY_ALLOCATION,
3598
]);
3699

37100
impl<'tcx> LateLintPass<'tcx> for GuidelineLints {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use rustc_lint::{LateContext, LintContext};
2+
3+
use super::PASSING_STRING_TO_C_FUNCTIONS;
4+
5+
// TODO: Adjust the parameters as necessary
6+
pub(super) fn check(cx: &LateContext<'_>) {
7+
todo!();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use rustc_lint::{LateContext, LintContext};
2+
3+
use super::UNTRUSTED_LIB_LOADING;
4+
5+
// TODO: Adjust the parameters as necessary
6+
pub(super) fn check(cx: &LateContext<'_>) {
7+
todo!();
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(unused)]
2+
#![warn(clippy::falliable_memory_allocation)]
3+
4+
fn main() {
5+
// test code goes here
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(unused)]
2+
#![warn(clippy::passing_string_to_c_functions)]
3+
4+
fn main() {
5+
// test code goes here
6+
}

tests/ui/untrusted_lib_loading.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(unused)]
2+
#![warn(clippy::untrusted_lib_loading)]
3+
4+
fn main() {
5+
// test code goes here
6+
}

0 commit comments

Comments
 (0)