-
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
9 changed files
with
164 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,13 @@ | ||
include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) main.rs >$(TMPDIR)/main.stdout 2>$(TMPDIR)/main.stderr || echo "failed successfully" | ||
|
||
# Bless like this: RUSTC_BLESS_TEST=1 ./x.py test tests/run-make/unconditional-drop-recursion | ||
ifdef RUSTC_BLESS_TEST | ||
cp "$(TMPDIR)"/main.stdout main.stdout | ||
cp "$(TMPDIR)"/main.stderr main.stderr | ||
else | ||
$(DIFF) main.stdout "$(TMPDIR)"/main.stdout | ||
$(DIFF) main.stderr "$(TMPDIR)"/main.stderr | ||
endif |
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,37 @@ | ||
//! This can not be a regular ui test since we can only lint drop recursion | ||
//! after the drop elaboration MIR pass, which is not performed in ui tests. | ||
|
||
#![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 | ||
--> main.rs:10:5 | ||
| | ||
10 | fn drop(&mut self) { //~ ERROR function cannot return without recursing | ||
| ^^^^^^^^^^^^^^^^^^ cannot return without recursing | ||
11 | let _ = RecursiveDrop; | ||
| - recursive call site | ||
| | ||
= help: a `loop` may express intention better if this is on purpose | ||
note: the lint level is defined here | ||
--> main.rs:4:9 | ||
| | ||
4 | #![deny(unconditional_recursion)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Empty file.