rename functions
This commit is contained in:
parent
ff7009a4d2
commit
32195ac8f4
@ -221,7 +221,7 @@ impl Into<rustc_errors::DiagnosticId> for TypeAnnotationNeeded {
|
||||
}
|
||||
|
||||
/// Information about a constant or a type containing inference variables.
|
||||
pub struct InferDiagnosticsData {
|
||||
pub struct InferenceDiagnosticsData {
|
||||
pub name: String,
|
||||
pub span: Option<Span>,
|
||||
pub description: Cow<'static, str>,
|
||||
@ -232,11 +232,11 @@ pub struct InferDiagnosticsData {
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// Extracts data used by diagnostic for either types or constants
|
||||
/// which were stuck during inference.
|
||||
pub fn extract_infer_data(
|
||||
pub fn extract_inference_diagnostics_data(
|
||||
&self,
|
||||
arg: GenericArg<'tcx>,
|
||||
highlight: Option<ty::print::RegionHighlightMode>,
|
||||
) -> InferDiagnosticsData {
|
||||
) -> InferenceDiagnosticsData {
|
||||
match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => {
|
||||
if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() {
|
||||
@ -266,7 +266,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
};
|
||||
|
||||
if name != kw::SelfUpper {
|
||||
return InferDiagnosticsData {
|
||||
return InferenceDiagnosticsData {
|
||||
name: name.to_string(),
|
||||
span: Some(var_origin.span),
|
||||
description: "type parameter".into(),
|
||||
@ -283,7 +283,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
printer.region_highlight_mode = highlight;
|
||||
}
|
||||
let _ = ty.print(printer);
|
||||
InferDiagnosticsData {
|
||||
InferenceDiagnosticsData {
|
||||
name: s,
|
||||
span: None,
|
||||
description: ty.prefix_string(),
|
||||
@ -317,7 +317,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
return InferDiagnosticsData {
|
||||
return InferenceDiagnosticsData {
|
||||
name: name.to_string(),
|
||||
span: Some(origin.span),
|
||||
description: "const parameter".into(),
|
||||
@ -334,7 +334,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
printer.region_highlight_mode = highlight;
|
||||
}
|
||||
let _ = ct.print(printer);
|
||||
InferDiagnosticsData {
|
||||
InferenceDiagnosticsData {
|
||||
name: s,
|
||||
span: Some(origin.span),
|
||||
description: "the constant".into(),
|
||||
@ -349,16 +349,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn need_type_info_err(
|
||||
pub fn emit_inference_failure_err(
|
||||
&self,
|
||||
body_id: Option<hir::BodyId>,
|
||||
span: Span,
|
||||
arg: GenericArg<'tcx>,
|
||||
error_code: TypeAnnotationNeeded,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let ty = self.resolve_vars_if_possible(&arg);
|
||||
let arg_data = self.extract_infer_data(arg, None);
|
||||
let kind_str = match ty.unpack() {
|
||||
let arg = self.resolve_vars_if_possible(&arg);
|
||||
let arg_data = self.extract_inference_diagnostics_data(arg, None);
|
||||
let kind_str = match arg.unpack() {
|
||||
GenericArgKind::Type(_) => "type",
|
||||
GenericArgKind::Const(_) => "the value",
|
||||
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
|
||||
@ -700,7 +700,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let data = self.extract_infer_data(ty.into(), None);
|
||||
let data = self.extract_inference_diagnostics_data(ty.into(), None);
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
@ -396,7 +396,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
) -> Option<RegionNameHighlight> {
|
||||
let mut highlight = RegionHighlightMode::default();
|
||||
highlight.highlighting_region_vid(needle_fr, counter);
|
||||
let type_name = self.infcx.extract_infer_data(ty.into(), Some(highlight)).name;
|
||||
let type_name =
|
||||
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
|
||||
|
||||
debug!(
|
||||
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
|
||||
@ -645,7 +646,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
|
||||
let mut highlight = RegionHighlightMode::default();
|
||||
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
|
||||
let type_name = self.infcx.extract_infer_data(return_ty.into(), Some(highlight)).name;
|
||||
let type_name =
|
||||
self.infcx.extract_inference_diagnostics_data(return_ty.into(), Some(highlight)).name;
|
||||
|
||||
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
|
||||
|
||||
@ -697,7 +699,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
|
||||
let mut highlight = RegionHighlightMode::default();
|
||||
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
|
||||
let type_name = self.infcx.extract_infer_data(yield_ty.into(), Some(highlight)).name;
|
||||
let type_name =
|
||||
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
|
||||
|
||||
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
|
||||
|
||||
|
@ -1512,11 +1512,21 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
// check upstream for type errors and don't add the obligations to
|
||||
// begin with in those cases.
|
||||
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
|
||||
self.need_type_info_err(body_id, span, self_ty.into(), ErrorCode::E0282).emit();
|
||||
self.emit_inference_failure_err(
|
||||
body_id,
|
||||
span,
|
||||
self_ty.into(),
|
||||
ErrorCode::E0282,
|
||||
)
|
||||
.emit();
|
||||
return;
|
||||
}
|
||||
let mut err =
|
||||
self.need_type_info_err(body_id, span, self_ty.into(), ErrorCode::E0283);
|
||||
let mut err = self.emit_inference_failure_err(
|
||||
body_id,
|
||||
span,
|
||||
self_ty.into(),
|
||||
ErrorCode::E0283,
|
||||
);
|
||||
err.note(&format!("cannot satisfy `{}`", predicate));
|
||||
if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code {
|
||||
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
|
||||
@ -1580,7 +1590,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
return;
|
||||
}
|
||||
|
||||
self.need_type_info_err(body_id, span, arg, ErrorCode::E0282)
|
||||
self.emit_inference_failure_err(body_id, span, arg, ErrorCode::E0282)
|
||||
}
|
||||
|
||||
ty::PredicateAtom::Subtype(data) => {
|
||||
@ -1591,7 +1601,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let SubtypePredicate { a_is_expected: _, a, b } = data;
|
||||
// both must be type variables, or the other would've been instantiated
|
||||
assert!(a.is_ty_var() && b.is_ty_var());
|
||||
self.need_type_info_err(body_id, span, a.into(), ErrorCode::E0282)
|
||||
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282)
|
||||
}
|
||||
ty::PredicateAtom::Projection(data) => {
|
||||
let trait_ref = ty::Binder::bind(data).to_poly_trait_ref(self.tcx);
|
||||
@ -1602,8 +1612,12 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
if self_ty.needs_infer() && ty.needs_infer() {
|
||||
// We do this for the `foo.collect()?` case to produce a suggestion.
|
||||
let mut err =
|
||||
self.need_type_info_err(body_id, span, self_ty.into(), ErrorCode::E0284);
|
||||
let mut err = self.emit_inference_failure_err(
|
||||
body_id,
|
||||
span,
|
||||
self_ty.into(),
|
||||
ErrorCode::E0284,
|
||||
);
|
||||
err.note(&format!("cannot satisfy `{}`", predicate));
|
||||
err
|
||||
} else {
|
||||
|
@ -2991,7 +2991,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty
|
||||
} else {
|
||||
if !self.is_tainted_by_errors() {
|
||||
self.need_type_info_err((**self).body_id, sp, ty.into(), E0282)
|
||||
self.emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282)
|
||||
.note("type must be known at this point")
|
||||
.emit();
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
|
||||
fn report_type_error(&self, t: Ty<'tcx>) {
|
||||
if !self.tcx.sess.has_errors() {
|
||||
self.infcx
|
||||
.need_type_info_err(
|
||||
.emit_inference_failure_err(
|
||||
Some(self.body.id()),
|
||||
self.span.to_span(self.tcx),
|
||||
t.into(),
|
||||
@ -666,7 +666,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
|
||||
fn report_const_error(&self, c: &'tcx ty::Const<'tcx>) {
|
||||
if !self.tcx.sess.has_errors() {
|
||||
self.infcx
|
||||
.need_type_info_err(
|
||||
.emit_inference_failure_err(
|
||||
Some(self.body.id()),
|
||||
self.span.to_span(self.tcx),
|
||||
c.into(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user