Skip to content

Commit a624583

Browse files
committed
new_ret_no_self added test cases
1 parent 079f9f4 commit a624583

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

clippy_lints/src/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,6 @@ enum ImplicitHasherType<'tcx> {
19201920

19211921
impl<'tcx> ImplicitHasherType<'tcx> {
19221922
/// Checks that `ty` is a target type without a BuildHasher.
1923-
#[allow(clippy::new_ret_no_self)]
19241923
fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty) -> Option<Self> {
19251924
if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.node {
19261925
let params: Vec<_> = path.segments.last().as_ref()?.args.as_ref()?

tests/ui/new_ret_no_self.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,24 @@ impl MutPointerReturnerBad {
140140
// should trigger lint
141141
pub fn new() -> *mut V { unimplemented!(); }
142142
}
143+
144+
struct GenericReturnerOk;
145+
146+
impl GenericReturnerOk {
147+
// should not trigger lint
148+
pub fn new() -> Option<Self> { unimplemented!(); }
149+
}
150+
151+
struct GenericReturnerBad;
152+
153+
impl GenericReturnerBad {
154+
// should trigger lint
155+
pub fn new() -> Option<u32> { unimplemented!(); }
156+
}
157+
158+
struct NestedReturnerOk;
159+
160+
impl NestedReturnerOk {
161+
// should trigger lint
162+
pub fn new() -> (Option<Self>, u32) { unimplemented!(); }
163+
}

tests/ui/new_ret_no_self.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ error: methods called `new` usually return `Self`
3636
141 | pub fn new() -> *mut V { unimplemented!(); }
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

39-
error: aborting due to 5 previous errors
39+
error: methods called `new` usually return `Self`
40+
--> $DIR/new_ret_no_self.rs:155:5
41+
|
42+
155 | pub fn new() -> Option<u32> { unimplemented!(); }
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
error: aborting due to 6 previous errors
4046

0 commit comments

Comments
 (0)