Skip to content

Commit dfd8b2d

Browse files
authored
Fix new_without_default FP on private type with trait impl (#15782)
Closes #15778 changelog: [`new_without_default`] fix FP on private type with trait impl
2 parents 3c93ba0 + 17cecfd commit dfd8b2d

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

clippy_lints/src/new_without_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
9494
return;
9595
}
9696
if sig.decl.inputs.is_empty()
97-
&& cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id)
97+
&& cx.effective_visibilities.is_exported(impl_item.owner_id.def_id)
9898
&& let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
9999
&& self_ty == return_ty(cx, impl_item.owner_id)
100100
&& let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)

tests/ui/new_without_default.fixed

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,23 @@ where
322322
Self { _kv: None }
323323
}
324324
}
325+
326+
mod issue15778 {
327+
pub struct Foo(Vec<i32>);
328+
329+
impl Foo {
330+
pub fn new() -> Self {
331+
Self(Vec::new())
332+
}
333+
}
334+
335+
impl<'a> IntoIterator for &'a Foo {
336+
type Item = &'a i32;
337+
338+
type IntoIter = std::slice::Iter<'a, i32>;
339+
340+
fn into_iter(self) -> Self::IntoIter {
341+
self.0.as_slice().iter()
342+
}
343+
}
344+
}

tests/ui/new_without_default.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,23 @@ where
265265
Self { _kv: None }
266266
}
267267
}
268+
269+
mod issue15778 {
270+
pub struct Foo(Vec<i32>);
271+
272+
impl Foo {
273+
pub fn new() -> Self {
274+
Self(Vec::new())
275+
}
276+
}
277+
278+
impl<'a> IntoIterator for &'a Foo {
279+
type Item = &'a i32;
280+
281+
type IntoIter = std::slice::Iter<'a, i32>;
282+
283+
fn into_iter(self) -> Self::IntoIter {
284+
self.0.as_slice().iter()
285+
}
286+
}
287+
}

0 commit comments

Comments
 (0)