-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let lint_forgetting_references give the suggestion if possible
- Loading branch information
Showing
9 changed files
with
336 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//@ check-fail | ||
//@ run-rustfix | ||
|
||
#![deny(forgetting_references)] | ||
|
||
use std::mem::forget; | ||
|
||
struct SomeStruct; | ||
|
||
fn main() { | ||
let _ = &SomeStruct; //~ ERROR calls to `std::mem::forget` | ||
|
||
let mut owned = SomeStruct; | ||
let _ = &owned; //~ ERROR calls to `std::mem::forget` | ||
let _ = &&owned; //~ ERROR calls to `std::mem::forget` | ||
let _ = &mut owned; //~ ERROR calls to `std::mem::forget` | ||
forget(owned); | ||
|
||
let reference1 = &SomeStruct; | ||
let _ = &*reference1; //~ ERROR calls to `std::mem::forget` | ||
|
||
let reference2 = &mut SomeStruct; | ||
let _ = reference2; //~ ERROR calls to `std::mem::forget` | ||
|
||
let ref reference3 = SomeStruct; | ||
let _ = reference3; //~ ERROR calls to `std::mem::forget` | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn test_generic_fn_forget<T>(val: T) { | ||
let _ = &val; //~ ERROR calls to `std::mem::forget` | ||
forget(val); | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn test_similarly_named_function() { | ||
fn forget<T>(_val: T) {} | ||
forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name | ||
let _ = &SomeStruct; //~ ERROR calls to `std::mem::forget` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//@ check-fail | ||
//@ run-rustfix | ||
|
||
#![deny(forgetting_references)] | ||
|
||
use std::mem::forget; | ||
|
||
struct SomeStruct; | ||
|
||
fn main() { | ||
forget(&SomeStruct); //~ ERROR calls to `std::mem::forget` | ||
|
||
let mut owned = SomeStruct; | ||
forget(&owned); //~ ERROR calls to `std::mem::forget` | ||
forget(&&owned); //~ ERROR calls to `std::mem::forget` | ||
forget(&mut owned); //~ ERROR calls to `std::mem::forget` | ||
forget(owned); | ||
|
||
let reference1 = &SomeStruct; | ||
forget(&*reference1); //~ ERROR calls to `std::mem::forget` | ||
|
||
let reference2 = &mut SomeStruct; | ||
forget(reference2); //~ ERROR calls to `std::mem::forget` | ||
|
||
let ref reference3 = SomeStruct; | ||
forget(reference3); //~ ERROR calls to `std::mem::forget` | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn test_generic_fn_forget<T>(val: T) { | ||
forget(&val); //~ ERROR calls to `std::mem::forget` | ||
forget(val); | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn test_similarly_named_function() { | ||
fn forget<T>(_val: T) {} | ||
forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name | ||
std::mem::forget(&SomeStruct); //~ ERROR calls to `std::mem::forget` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:11:5 | ||
| | ||
LL | forget(&SomeStruct); | ||
| ^^^^^^^-----------^ | ||
| | | ||
| argument has type `&SomeStruct` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/forgetting_references-can-fixed.rs:4:9 | ||
| | ||
LL | #![deny(forgetting_references)] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(&SomeStruct); | ||
LL + let _ = &SomeStruct; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:14:5 | ||
| | ||
LL | forget(&owned); | ||
| ^^^^^^^------^ | ||
| | | ||
| argument has type `&SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(&owned); | ||
LL + let _ = &owned; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:15:5 | ||
| | ||
LL | forget(&&owned); | ||
| ^^^^^^^-------^ | ||
| | | ||
| argument has type `&&SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(&&owned); | ||
LL + let _ = &&owned; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:16:5 | ||
| | ||
LL | forget(&mut owned); | ||
| ^^^^^^^----------^ | ||
| | | ||
| argument has type `&mut SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(&mut owned); | ||
LL + let _ = &mut owned; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:20:5 | ||
| | ||
LL | forget(&*reference1); | ||
| ^^^^^^^------------^ | ||
| | | ||
| argument has type `&SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(&*reference1); | ||
LL + let _ = &*reference1; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:23:5 | ||
| | ||
LL | forget(reference2); | ||
| ^^^^^^^----------^ | ||
| | | ||
| argument has type `&mut SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(reference2); | ||
LL + let _ = reference2; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:26:5 | ||
| | ||
LL | forget(reference3); | ||
| ^^^^^^^----------^ | ||
| | | ||
| argument has type `&SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(reference3); | ||
LL + let _ = reference3; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:31:5 | ||
| | ||
LL | forget(&val); | ||
| ^^^^^^^----^ | ||
| | | ||
| argument has type `&T` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - forget(&val); | ||
LL + let _ = &val; | ||
| | ||
|
||
error: calls to `std::mem::forget` with a reference instead of an owned value does nothing | ||
--> $DIR/forgetting_references-can-fixed.rs:39:5 | ||
| | ||
LL | std::mem::forget(&SomeStruct); | ||
| ^^^^^^^^^^^^^^^^^-----------^ | ||
| | | ||
| argument has type `&SomeStruct` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - std::mem::forget(&SomeStruct); | ||
LL + let _ = &SomeStruct; | ||
| | ||
|
||
error: aborting due to 9 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.