2014-12-31 10:06:38 -06:00
|
|
|
#![deny(unconditional_recursion)]
|
2017-11-20 06:13:27 -06:00
|
|
|
|
2014-12-31 10:06:38 -06:00
|
|
|
#![allow(dead_code)]
|
2018-08-21 01:09:15 -05:00
|
|
|
fn foo() { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
foo();
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bar() {
|
|
|
|
if true {
|
|
|
|
bar()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 01:09:15 -05:00
|
|
|
fn baz() { //~ ERROR function cannot return without recursing
|
2014-12-31 10:06:38 -06:00
|
|
|
if true {
|
2017-12-10 14:29:24 -06:00
|
|
|
baz()
|
2014-12-31 10:06:38 -06:00
|
|
|
} else {
|
2017-12-10 14:29:24 -06:00
|
|
|
baz()
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn qux() {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
2018-08-21 01:09:15 -05:00
|
|
|
fn quz() -> bool { //~ ERROR function cannot return without recursing
|
2014-12-31 10:06:38 -06:00
|
|
|
if true {
|
2017-12-10 14:29:24 -06:00
|
|
|
while quz() {}
|
2014-12-31 10:06:38 -06:00
|
|
|
true
|
|
|
|
} else {
|
2017-12-10 14:29:24 -06:00
|
|
|
loop { quz(); }
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 17:17:56 -05:00
|
|
|
// Trait method calls.
|
2014-12-31 10:06:38 -06:00
|
|
|
trait Foo {
|
2018-08-21 01:09:15 -05:00
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
self.bar()
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
impl Foo for Box<dyn Foo + 'static> {
|
2018-08-21 01:09:15 -05:00
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recursing
|
2014-12-31 10:06:38 -06:00
|
|
|
loop {
|
2017-12-10 14:29:24 -06:00
|
|
|
self.bar()
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
}
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Trait method call with integer fallback after method resolution.
|
|
|
|
impl Foo for i32 {
|
2018-08-21 01:09:15 -05:00
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
0.bar()
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for u32 {
|
|
|
|
fn bar(&self) {
|
|
|
|
0.bar()
|
|
|
|
}
|
|
|
|
}
|
2014-12-31 10:06:38 -06:00
|
|
|
|
2015-08-03 17:17:56 -05:00
|
|
|
// Trait method calls via paths.
|
|
|
|
trait Foo2 {
|
2018-08-21 01:09:15 -05:00
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
Foo2::bar(self)
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
impl Foo2 for Box<dyn Foo2 + 'static> {
|
2018-08-21 01:09:15 -05:00
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recursing
|
2015-08-03 17:17:56 -05:00
|
|
|
loop {
|
2017-12-10 14:29:24 -06:00
|
|
|
Foo2::bar(self)
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Baz;
|
|
|
|
impl Baz {
|
2015-08-03 17:17:56 -05:00
|
|
|
// Inherent method call.
|
2018-08-21 01:09:15 -05:00
|
|
|
fn qux(&self) { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
self.qux();
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
2015-08-03 17:17:56 -05:00
|
|
|
|
|
|
|
// Inherent method call via path.
|
2018-08-21 01:09:15 -05:00
|
|
|
fn as_ref(&self) -> &Self { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
Baz::as_ref(self)
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trait method calls to impls via paths.
|
|
|
|
impl Default for Baz {
|
2018-08-21 01:09:15 -05:00
|
|
|
fn default() -> Baz { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
let x = Default::default();
|
2015-08-03 17:17:56 -05:00
|
|
|
x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded operators.
|
|
|
|
impl std::ops::Deref for Baz {
|
|
|
|
type Target = ();
|
2018-08-21 01:09:15 -05:00
|
|
|
fn deref(&self) -> &() { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
&**self
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Index<usize> for Baz {
|
|
|
|
type Output = Baz;
|
2018-08-21 01:09:15 -05:00
|
|
|
fn index(&self, x: usize) -> &Baz { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
&self[x]
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded autoderef.
|
|
|
|
struct Quux;
|
|
|
|
impl std::ops::Deref for Quux {
|
|
|
|
type Target = Baz;
|
2018-08-21 01:09:15 -05:00
|
|
|
fn deref(&self) -> &Baz { //~ ERROR function cannot return without recursing
|
2017-12-10 14:29:24 -06:00
|
|
|
self.as_ref()
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
|
2015-06-29 16:51:56 -05:00
|
|
|
fn all_fine() {
|
|
|
|
let _f = all_fine;
|
|
|
|
}
|
|
|
|
|
2015-06-29 17:56:00 -05:00
|
|
|
// issue 26333
|
|
|
|
trait Bar {
|
|
|
|
fn method<T: Bar>(&self, x: &T) {
|
|
|
|
x.method(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 14:04:31 -05:00
|
|
|
// Do not trigger on functions that may diverge instead of self-recursing (#54444)
|
|
|
|
|
|
|
|
pub fn loops(x: bool) {
|
|
|
|
if x {
|
|
|
|
loops(x);
|
|
|
|
} else {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn panics(x: bool) {
|
|
|
|
if x {
|
|
|
|
panics(!x);
|
|
|
|
} else {
|
|
|
|
panic!("panics");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 18:00:00 -06:00
|
|
|
pub fn unreachable1() {
|
|
|
|
panic!();
|
|
|
|
unreachable1(); // WARN unreachable statement
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unreachable2() {
|
|
|
|
loop {}
|
|
|
|
unreachable2(); // WARN unreachable statement
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn drop_and_replace(mut a: Option<String>) { //~ ERROR function cannot return without recursing
|
|
|
|
a = None;
|
|
|
|
drop_and_replace(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calls are assumed to return normally.
|
|
|
|
pub fn call() -> String { //~ ERROR function cannot return without recursing
|
|
|
|
let s = String::new();
|
|
|
|
call();
|
|
|
|
s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arithmetic operations are assumed not to overflow.
|
|
|
|
pub fn overflow_check(a: i32, b: i32) { //~ ERROR function cannot return without recursing
|
|
|
|
let _ = a + b;
|
|
|
|
overflow_check(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Point {
|
|
|
|
pub x: f32,
|
|
|
|
pub y: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Point {
|
|
|
|
fn default() -> Self { //~ ERROR function cannot return without recursing
|
|
|
|
Point {
|
|
|
|
x: Default::default(),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-31 10:06:38 -06:00
|
|
|
fn main() {}
|