Skip to content

Commit bf5c0d8

Browse files
Add tests for extension of unconditional_recursion lint on Default trait
1 parent 2666f39 commit bf5c0d8

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

tests/ui/unconditional_recursion.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@no-rustfix
22

33
#![warn(clippy::unconditional_recursion)]
4-
#![allow(clippy::partialeq_ne_impl)]
4+
#![allow(clippy::partialeq_ne_impl, clippy::default_constructed_unit_structs)]
55

66
enum Foo {
77
A,
@@ -232,6 +232,38 @@ impl std::string::ToString for S11 {
232232
}
233233
}
234234

235+
struct S12;
236+
237+
impl std::default::Default for S12 {
238+
fn default() -> Self {
239+
Self::new()
240+
}
241+
}
242+
243+
impl S12 {
244+
fn new() -> Self {
245+
//~^ ERROR: function cannot return without recursing
246+
Self::default()
247+
}
248+
249+
fn bar() -> Self {
250+
// Should not warn!
251+
Self::default()
252+
}
253+
}
254+
255+
#[derive(Default)]
256+
struct S13 {
257+
f: u32,
258+
}
259+
260+
impl S13 {
261+
fn new() -> Self {
262+
// Shoud not warn!
263+
Self::default()
264+
}
265+
}
266+
235267
fn main() {
236268
// test code goes here
237269
}

tests/ui/unconditional_recursion.stderr

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,20 @@ note: recursive call site
325325
LL | mine == theirs
326326
| ^^^^^^^^^^^^^^
327327

328-
error: aborting due to 25 previous errors
328+
error: function cannot return without recursing
329+
--> $DIR/unconditional_recursion.rs:244:5
330+
|
331+
LL | / fn new() -> Self {
332+
LL | |
333+
LL | | Self::default()
334+
LL | | }
335+
| |_____^
336+
|
337+
note: recursive call site
338+
--> $DIR/unconditional_recursion.rs:246:9
339+
|
340+
LL | Self::default()
341+
| ^^^^^^^^^^^^^^^
342+
343+
error: aborting due to 26 previous errors
329344

0 commit comments

Comments
 (0)