Rollup merge of #97109 - TaKO8Ki:fix-misleading-cannot-infer-type-for-type-parameter-error, r=oli-obk
Fix misleading `cannot infer type for type parameter` error closes #93198
This commit is contained in:
commit
76f662c963
17 changed files with 150 additions and 0 deletions
|
@ -866,6 +866,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
self.report_ambiguous_type_parameter(&mut err, arg);
|
||||
err.span_label(
|
||||
span,
|
||||
arg_data.cannot_infer_msg(use_diag.filter(|d| d.applies_to(span))),
|
||||
|
@ -933,6 +934,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn report_ambiguous_type_parameter(&self, err: &mut Diagnostic, arg: GenericArg<'tcx>) {
|
||||
if let GenericArgKind::Type(ty) = arg.unpack()
|
||||
&& let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind()
|
||||
{
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let ty_vars = &inner.type_variables();
|
||||
let var_origin = ty_vars.var_origin(ty_vid);
|
||||
if let TypeVariableOriginKind::TypeParameterDefinition(_, Some(def_id)) =
|
||||
var_origin.kind
|
||||
&& let Some(parent_def_id) = self.tcx.parent(def_id).as_local()
|
||||
&& let Some(node) = self.tcx.hir().find_by_def_id(parent_def_id)
|
||||
{
|
||||
match node {
|
||||
hir::Node::Item(item) if matches!(item.kind, hir::ItemKind::Impl(_) | hir::ItemKind::Fn(..)) => (),
|
||||
hir::Node::ImplItem(impl_item) if matches!(impl_item.kind, hir::ImplItemKind::Fn(..)) => (),
|
||||
_ => return,
|
||||
}
|
||||
err.span_help(self.tcx.def_span(def_id), "type parameter declared here");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn need_type_info_err_in_generator(
|
||||
&self,
|
||||
kind: hir::GeneratorKind,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue