]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-unconditional-recursion.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![deny(unconditional_recursion)]
13 fn foo() { //~ ERROR function cannot return without recurring
14 foo(); //~ NOTE recursive call site
23 fn baz() { //~ ERROR function cannot return without recurring
25 baz() //~ NOTE recursive call site
27 baz() //~ NOTE recursive call site
35 fn quz() -> bool
{ //~ ERROR function cannot return without recurring
37 while quz() {}
//~ NOTE recursive call site
40 loop { quz(); }
//~ NOTE recursive call site
44 // Trait method calls.
46 fn bar(&self) { //~ ERROR function cannot return without recurring
47 self.bar() //~ NOTE recursive call site
51 impl Foo
for Box
<Foo
+'
static> {
52 fn bar(&self) { //~ ERROR function cannot return without recurring
54 self.bar() //~ NOTE recursive call site
59 // Trait method call with integer fallback after method resolution.
61 fn bar(&self) { //~ ERROR function cannot return without recurring
62 0.bar() //~ NOTE recursive call site
72 // Trait method calls via paths.
74 fn bar(&self) { //~ ERROR function cannot return without recurring
75 Foo2
::bar(self) //~ NOTE recursive call site
79 impl Foo2
for Box
<Foo2
+'
static> {
80 fn bar(&self) { //~ ERROR function cannot return without recurring
82 Foo2
::bar(self) //~ NOTE recursive call site
89 // Inherent method call.
90 fn qux(&self) { //~ ERROR function cannot return without recurring
91 self.qux(); //~ NOTE recursive call site
94 // Inherent method call via path.
95 fn as_ref(&self) -> &Self { //~ ERROR function cannot return without recurring
96 Baz
::as_ref(self) //~ NOTE recursive call site
100 // Trait method calls to impls via paths.
101 impl Default
for Baz
{
102 fn default() -> Baz
{ //~ ERROR function cannot return without recurring
103 let x
= Default
::default(); //~ NOTE recursive call site
108 // Overloaded operators.
109 impl std
::ops
::Deref
for Baz
{
111 fn deref(&self) -> &() { //~ ERROR function cannot return without recurring
112 &**self //~ NOTE recursive call site
116 impl std
::ops
::Index
<usize> for Baz
{
118 fn index(&self, x
: usize) -> &Baz
{ //~ ERROR function cannot return without recurring
119 &self[x
] //~ NOTE recursive call site
123 // Overloaded autoderef.
125 impl std
::ops
::Deref
for Quux
{
127 fn deref(&self) -> &Baz
{ //~ ERROR function cannot return without recurring
128 self.as_ref() //~ NOTE recursive call site
138 fn method
<T
: Bar
>(&self, x
: &T
) {