Skip to content

Commit 429c09e

Browse files
committed
Do not suggest replacing an expression by an ambiguous type name
An expression such as `<_>::default()` should not be replaced by an ambiguous type name such as `_` even if the inferred type in the original expression is a singleton.
1 parent cee9abf commit 429c09e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

clippy_lints/src/default_constructed_unit_structs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ impl LateLintPass<'_> for DefaultConstructedUnitStructs {
7070
&& let var @ ty::VariantDef { ctor: Some((hir::def::CtorKind::Const, _)), .. } = def.non_enum_variant()
7171
&& !var.is_field_list_non_exhaustive()
7272
&& !expr.span.from_expansion() && !qpath.span().from_expansion()
73+
// do not suggest replacing an expression by a type name with placeholders
74+
&& !base.is_suggestable_infer_ty()
7375
{
7476
span_lint_and_sugg(
7577
cx,

tests/ui/default_constructed_unit_structs.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,12 @@ fn main() {
161161

162162
let _ = <struct_from_macro!()>::default();
163163
}
164+
165+
fn issue12654() {
166+
#[derive(Default)]
167+
struct G;
168+
169+
fn f(_g: G) {}
170+
171+
f(<_>::default());
172+
}

tests/ui/default_constructed_unit_structs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,12 @@ fn main() {
161161

162162
let _ = <struct_from_macro!()>::default();
163163
}
164+
165+
fn issue12654() {
166+
#[derive(Default)]
167+
struct G;
168+
169+
fn f(_g: G) {}
170+
171+
f(<_>::default());
172+
}

0 commit comments

Comments
 (0)