- // FIXME(const_generics): We should either try and merge this with `need_type_info_err`
- // or improve the errors created here.
- //
- // Unlike for type inference variables, we don't yet store the origin of const inference variables.
- // This is needed for to get a more relevant error span.
- pub fn need_type_info_err_const(
- &self,
- body_id: Option<hir::BodyId>,
- span: Span,
- ct: &'tcx ty::Const<'tcx>,
- error_code: TypeAnnotationNeeded,
- ) -> DiagnosticBuilder<'tcx> {
- let mut local_visitor = FindHirNodeVisitor::new(&self, ct.into(), span);
- if let Some(body_id) = body_id {
- let expr = self.tcx.hir().expect_expr(body_id.hir_id);
- local_visitor.visit_expr(expr);
- }
-
- let mut param_name = None;
- let span = if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val {
- let origin = self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
- if let ConstVariableOriginKind::ConstParameterDefinition(param) = origin.kind {
- param_name = Some(param);
- }
- origin.span
- } else {
- local_visitor.target_span
- };
-
- let error_code = error_code.into();
- let mut err =
- self.tcx.sess.struct_span_err_with_code(span, "type annotations needed", error_code);
-
- if let Some(param_name) = param_name {
- err.note(&format!("cannot infer the value of the const parameter `{}`", param_name));
- } else {
- err.note("unable to infer the value of a const parameter");
- }
-
- err
- }
-