+ // 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 error_code = error_code.into();
+ let mut err = self.tcx.sess.struct_span_err_with_code(
+ local_visitor.target_span,
+ &format!("type annotations needed"),
+ error_code,
+ );
+
+ err.note("unable to infer the value of a const parameter");
+
+ err
+ }
+