Skip to content

Commit

Permalink
Update lint description
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcrosta committed Dec 4, 2023
1 parent ce8ac6a commit df51755
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
33 changes: 11 additions & 22 deletions detectors/core-mem-forget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,19 @@ dylint_linting::impl_pre_expansion_lint! {
/// This is a bad practice because it can lead to memory leaks, resource leaks and logic errors.
/// ### Example
/// ```rust
/// pub fn forget_value(&mut self) {
/// let forgotten_value = self.value;
/// self.value = false;
/// core::mem::forget(forgotten_value);
/// }
/// pub fn forget_something(n: WithoutCopy) -> u64 {
/// core::mem::forget(n);
/// 0
/// }
/// ```
///
/// ```
/// Use instead:
///```rust
/// pub fn forget_value(&mut self) {
/// let forgotten_value = self.value;
/// self.value = false;
/// let _ = forgotten_value;
/// }
///
/// // or use drop if droppable
///
/// pub fn drop_value(&mut self) {
/// let forgotten_value = self.value;
/// self.value = false;
/// forget_value.drop();
/// }
///```
/// ```rust
/// pub fn forget_something(n: WithoutCopy) -> u64 {
/// let _ = n;
/// 0
/// }
/// ```
pub CORE_MEM_FORGET,
Warn,
Expand Down Expand Up @@ -69,7 +59,6 @@ impl EarlyLintPass for CoreMemForget {
if path.segments[1].ident.name.to_string() == "mem";
if path.segments[2].ident.name.to_string() == "forget";
then {

Detector::CoreMemForget.span_lint_and_help(
cx,
CORE_MEM_FORGET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ mod tests {

#[test]
fn test_forget_something() {
// Given
let test_value: WithoutCopy = WithoutCopy { a: 80, b: 60 };

// When
let result = CoreMemForget::forget_something(test_value);

// Then
assert_eq!(result, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ mod tests {

#[test]
fn test_forget_something() {
// Given
let test_value: WithoutCopy = WithoutCopy { a: 80, b: 60 };

// When
let result = CoreMemForget::forget_something(test_value);

// Then
assert_eq!(result, 0);
}
}

0 comments on commit df51755

Please sign in to comment.