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.
This commit is contained in:
parent
cee9abf10c
commit
429c09ead2
3 changed files with 20 additions and 0 deletions
|
|
@ -70,6 +70,8 @@ impl LateLintPass<'_> for DefaultConstructedUnitStructs {
|
|||
&& let var @ ty::VariantDef { ctor: Some((hir::def::CtorKind::Const, _)), .. } = def.non_enum_variant()
|
||||
&& !var.is_field_list_non_exhaustive()
|
||||
&& !expr.span.from_expansion() && !qpath.span().from_expansion()
|
||||
// do not suggest replacing an expression by a type name with placeholders
|
||||
&& !base.is_suggestable_infer_ty()
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
|
|
|||
|
|
@ -161,3 +161,12 @@ fn main() {
|
|||
|
||||
let _ = <struct_from_macro!()>::default();
|
||||
}
|
||||
|
||||
fn issue12654() {
|
||||
#[derive(Default)]
|
||||
struct G;
|
||||
|
||||
fn f(_g: G) {}
|
||||
|
||||
f(<_>::default());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,3 +161,12 @@ fn main() {
|
|||
|
||||
let _ = <struct_from_macro!()>::default();
|
||||
}
|
||||
|
||||
fn issue12654() {
|
||||
#[derive(Default)]
|
||||
struct G;
|
||||
|
||||
fn f(_g: G) {}
|
||||
|
||||
f(<_>::default());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue