1
Fork 0

Do not suggest impl traits as type arguments

This commit is contained in:
Yuki Okushi 2021-06-16 06:32:22 +09:00
parent 3354a44d2f
commit 14e92d7116
No known key found for this signature in database
GPG key ID: DABA5B072961C18A
7 changed files with 71 additions and 16 deletions

View file

@ -753,23 +753,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let (UnderspecifiedArgKind::Const { .. }, Some(parent_data)) =
(&arg_data.kind, &arg_data.parent)
{
let has_impl_trait =
self.tcx.generics_of(parent_data.def_id).params.iter().any(|param| {
matches!(
param.kind,
ty::GenericParamDefKind::Type {
synthetic: Some(
hir::SyntheticTyParamKind::ImplTrait
| hir::SyntheticTyParamKind::FromAttr,
),
..
}
)
});
// (#83606): Do not emit a suggestion if the parent has an `impl Trait`
// as an argument otherwise it will cause the E0282 error.
if !has_impl_trait || self.tcx.features().explicit_generic_args_with_impl_trait {
if !self.tcx.generics_of(parent_data.def_id).has_impl_trait()
|| self.tcx.features().explicit_generic_args_with_impl_trait
{
err.span_suggestion_verbose(
span,
"consider specifying the const argument",
@ -814,7 +802,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let borrow = typeck_results.borrow();
if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) {
let generics = self.tcx.generics_of(did);
if !generics.params.is_empty() {
if !generics.params.is_empty() && !generics.has_impl_trait() {
err.span_suggestion_verbose(
segment.ident.span.shrink_to_hi(),
&format!(