2014-12-31 10:06:38 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
#![deny(unconditional_recursion)]
|
2017-11-20 06:13:27 -06:00
|
|
|
|
2014-12-31 10:06:38 -06:00
|
|
|
#![allow(dead_code)]
|
|
|
|
fn foo() { //~ ERROR function cannot return without recurring
|
2017-12-10 14:29:24 -06:00
|
|
|
foo();
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bar() {
|
|
|
|
if true {
|
|
|
|
bar()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn baz() { //~ ERROR function cannot return without recurring
|
|
|
|
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 {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn quz() -> bool { //~ ERROR function cannot return without recurring
|
|
|
|
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 {
|
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recurring
|
2017-12-10 14:29:24 -06:00
|
|
|
self.bar()
|
2014-12-31 10:06:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for Box<Foo+'static> {
|
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recurring
|
|
|
|
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 {
|
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recurring
|
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 {
|
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recurring
|
2017-12-10 14:29:24 -06:00
|
|
|
Foo2::bar(self)
|
2015-08-03 17:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo2 for Box<Foo2+'static> {
|
|
|
|
fn bar(&self) { //~ ERROR function cannot return without recurring
|
|
|
|
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.
|
2014-12-31 10:06:38 -06:00
|
|
|
fn qux(&self) { //~ ERROR function cannot return without recurring
|
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.
|
|
|
|
fn as_ref(&self) -> &Self { //~ ERROR function cannot return without recurring
|
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 {
|
|
|
|
fn default() -> Baz { //~ ERROR function cannot return without recurring
|
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 = ();
|
|
|
|
fn deref(&self) -> &() { //~ ERROR function cannot return without recurring
|
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;
|
|
|
|
fn index(&self, x: usize) -> &Baz { //~ ERROR function cannot return without recurring
|
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;
|
|
|
|
fn deref(&self) -> &Baz { //~ ERROR function cannot return without recurring
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-31 10:06:38 -06:00
|
|
|
fn main() {}
|