-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
unconditional_recursion
warning detect recursive drops
- Loading branch information
Showing
7 changed files
with
152 additions
and
19 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
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,38 @@ | ||
// Because drop recursion can only be detected after drop elaboration which | ||
// happens for codegen: | ||
// build-fail | ||
|
||
#![deny(unconditional_recursion)] | ||
#![allow(dead_code)] | ||
|
||
pub struct RecursiveDrop; | ||
|
||
impl Drop for RecursiveDrop { | ||
fn drop(&mut self) { //~ ERROR function cannot return without recursing | ||
let _ = RecursiveDrop; | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
struct NotRecursiveDrop1; | ||
|
||
impl Drop for NotRecursiveDrop1 { | ||
fn drop(&mut self) { | ||
// Before drop elaboration, the MIR can look like a recursive drop will | ||
// occur. But it will not, since forget() prevents drop() from running. | ||
let taken = std::mem::take(self); | ||
std::mem::forget(taken); | ||
} | ||
} | ||
|
||
struct NotRecursiveDrop2; | ||
|
||
impl Drop for NotRecursiveDrop2 { | ||
fn drop(&mut self) { | ||
// Before drop elaboration, the MIR can look like a recursive drop will | ||
// occur. But it will not, since this will panic. | ||
std::panic::panic_any(NotRecursiveDrop2); | ||
} | ||
} | ||
|
||
fn main() {} |
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,17 @@ | ||
error: function cannot return without recursing | ||
--> $DIR/lint-unconditional-drop-recursion.rs:11:5 | ||
| | ||
LL | fn drop(&mut self) { | ||
| ^^^^^^^^^^^^^^^^^^ cannot return without recursing | ||
LL | let _ = RecursiveDrop; | ||
| - recursive call site | ||
| | ||
= help: a `loop` may express intention better if this is on purpose | ||
note: the lint level is defined here | ||
--> $DIR/lint-unconditional-drop-recursion.rs:5:9 | ||
| | ||
LL | #![deny(unconditional_recursion)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|