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