Account for number of arguments in suggestion
This commit is contained in:
parent
00265f0cc0
commit
4d16171f56
2 changed files with 39 additions and 20 deletions
|
@ -1762,16 +1762,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
3
|
3
|
||||||
};
|
};
|
||||||
Some((order, item.name))
|
Some((order, item.name, input_len))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
items.sort_by_key(|(order, _)| *order);
|
items.sort_by_key(|(order, _, _)| *order);
|
||||||
match &items[..] {
|
match &items[..] {
|
||||||
[] => {}
|
[] => {}
|
||||||
[(_, name)] => {
|
[(_, name, len)] if *len == args.len() => {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
path_span.shrink_to_hi(),
|
path_span.shrink_to_hi(),
|
||||||
format!("you might have meant to use the `{name}` associated function",),
|
format!("you might have meant to use the `{name}` associated function",),
|
||||||
|
@ -1779,11 +1779,30 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
[(_, name, len)] => {
|
||||||
|
err.span_suggestion_verbose(
|
||||||
|
path_span.shrink_to_hi().with_hi(call_span.hi()),
|
||||||
|
format!("you might have meant to use the `{name}` associated function",),
|
||||||
|
format!(
|
||||||
|
"::{name}({})",
|
||||||
|
std::iter::repeat("_").take(*len).collect::<Vec<_>>().join(", ")
|
||||||
|
),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
err.span_suggestions_with_style(
|
err.span_suggestions_with_style(
|
||||||
path_span.shrink_to_hi(),
|
path_span.shrink_to_hi().with_hi(call_span.hi()),
|
||||||
"you might have meant to use an associated function to build this type",
|
"you might have meant to use an associated function to build this type",
|
||||||
items.iter().map(|(_, name)| format!("::{name}")).collect::<Vec<String>>(),
|
items
|
||||||
|
.iter()
|
||||||
|
.map(|(_, name, len)| {
|
||||||
|
format!(
|
||||||
|
"::{name}({})",
|
||||||
|
std::iter::repeat("_").take(*len).collect::<Vec<_>>().join(", ")
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<String>>(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
SuggestionStyle::ShowAlways,
|
SuggestionStyle::ShowAlways,
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,13 +10,13 @@ LL | let _ = std::collections::HashMap();
|
||||||
help: you might have meant to use an associated function to build this type
|
help: you might have meant to use an associated function to build this type
|
||||||
|
|
|
|
||||||
LL | let _ = std::collections::HashMap::new();
|
LL | let _ = std::collections::HashMap::new();
|
||||||
| +++++
|
| ~~~~~~~
|
||||||
LL | let _ = std::collections::HashMap::with_capacity();
|
LL | let _ = std::collections::HashMap::with_capacity(_);
|
||||||
| +++++++++++++++
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
LL | let _ = std::collections::HashMap::with_hasher();
|
LL | let _ = std::collections::HashMap::with_hasher(_);
|
||||||
| +++++++++++++
|
| ~~~~~~~~~~~~~~~~
|
||||||
LL | let _ = std::collections::HashMap::with_capacity_and_hasher();
|
LL | let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
|
||||||
| ++++++++++++++++++++++++++
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
help: consider using the `Default` trait
|
help: consider using the `Default` trait
|
||||||
|
|
|
|
||||||
LL | let _ = <std::collections::HashMap as std::default::Default>::default();
|
LL | let _ = <std::collections::HashMap as std::default::Default>::default();
|
||||||
|
@ -36,14 +36,14 @@ note: constructor is not visible here due to private fields
|
||||||
= note: private field
|
= note: private field
|
||||||
help: you might have meant to use an associated function to build this type
|
help: you might have meant to use an associated function to build this type
|
||||||
|
|
|
|
||||||
LL | wtf: Some(Box::new(U {
|
LL | wtf: Some(Box::new(_)),
|
||||||
| +++++
|
| ~~~~~~~~
|
||||||
LL | wtf: Some(Box::new_uninit(U {
|
LL | wtf: Some(Box::new_uninit()),
|
||||||
| ++++++++++++
|
| ~~~~~~~~~~~~~~
|
||||||
LL | wtf: Some(Box::new_zeroed(U {
|
LL | wtf: Some(Box::new_zeroed()),
|
||||||
| ++++++++++++
|
| ~~~~~~~~~~~~~~
|
||||||
LL | wtf: Some(Box::new_in(U {
|
LL | wtf: Some(Box::new_in(_, _)),
|
||||||
| ++++++++
|
| ~~~~~~~~~~~~~~
|
||||||
and 10 other candidates
|
and 10 other candidates
|
||||||
help: consider using the `Default` trait
|
help: consider using the `Default` trait
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue