diff options
| author | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2022-01-27 09:44:25 +0000 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2022-02-23 06:38:52 +0000 |
| commit | b7e95dee65c35db8f8e07046d445b12d92cbae12 (patch) | |
| tree | af9131de515325e67c68ab9bbd3c514298ca57f4 /compiler/rustc_infer | |
| parent | 0b9d70cf6d47df456280f83b58c04c96aa58e89e (diff) | |
| download | rust-b7e95dee65c35db8f8e07046d445b12d92cbae12.tar.gz rust-b7e95dee65c35db8f8e07046d445b12d92cbae12.zip | |
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".
Diffstat (limited to 'compiler/rustc_infer')
8 files changed, 32 insertions, 26 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index cbf28d48e14..9da287c959a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -58,7 +58,7 @@ use crate::traits::{ }; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{pluralize, struct_span_err, Diagnostic}; +use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorReported}; use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -230,7 +230,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( span: Span, hidden_ty: Ty<'tcx>, hidden_region: ty::Region<'tcx>, -) -> DiagnosticBuilder<'tcx> { +) -> DiagnosticBuilder<'tcx, ErrorReported> { let mut err = struct_span_err!( tcx.sess, span, @@ -2014,7 +2014,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, trace: TypeTrace<'tcx>, terr: &TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { use crate::traits::ObligationCauseCode::MatchExpressionArm; debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr); @@ -2222,7 +2222,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { origin: Option<SubregionOrigin<'tcx>>, bound_kind: GenericKind<'tcx>, sub: Region<'tcx>, - ) -> DiagnosticBuilder<'a> { + ) -> DiagnosticBuilder<'a, ErrorReported> { let hir = self.tcx.hir(); // Attempt to obtain the span of the parameter so we can // suggest adding an explicit lifetime bound to it. @@ -2648,7 +2648,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn report_inference_failure( &self, var_origin: RegionVariableOrigin, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let br_string = |br: ty::BoundRegionKind| { let mut s = match br { ty::BrNamed(_, name) => name.to_string(), diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 88a65fbb4e6..8876c3ecd54 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -1,6 +1,8 @@ use crate::infer::type_variable::TypeVariableOriginKind; use crate::infer::{InferCtxt, Symbol}; -use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; +use rustc_errors::{ + pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported, +}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::DefId; @@ -491,7 +493,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { arg: GenericArg<'tcx>, impl_candidates: Vec<ty::TraitRef<'tcx>>, error_code: TypeAnnotationNeeded, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let arg = self.resolve_vars_if_possible(arg); let arg_data = self.extract_inference_diagnostics_data(arg, None); @@ -918,7 +920,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { kind: hir::GeneratorKind, span: Span, ty: Ty<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let ty = self.resolve_vars_if_possible(ty); let data = self.extract_inference_diagnostics_data(ty.into(), None); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index f44e6e04346..a8b878ae344 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -46,7 +46,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> { self.infcx.tcx } - pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'tcx>> { + pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> { // Due to the improved diagnostics returned by the MIR borrow checker, only a subset of // the nice region errors are required when running under the MIR borrow checker. self.try_report_named_anon_conflict().or_else(|| self.try_report_placeholder_conflict()) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 17ff5d45c89..825aadaad9a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -2,13 +2,15 @@ //! where one region is named and the other is anonymous. use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::infer::error_reporting::nice_region_error::NiceRegionError; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_middle::ty; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// When given a `ConcreteFailure` for a function with parameters containing a named region and /// an anonymous region, emit an descriptive diagnostic error. - pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> { + pub(super) fn try_report_named_anon_conflict( + &self, + ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> { let (span, sub, sup) = self.regions()?; debug!( diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index 0be7a67a1b8..8b786e6e85a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -4,7 +4,7 @@ use crate::infer::ValuePairs; use crate::infer::{SubregionOrigin, TypeTrace}; use crate::traits::{ObligationCause, ObligationCauseCode}; use rustc_data_structures::intern::Interned; -use rustc_errors::{Diagnostic, DiagnosticBuilder}; +use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorReported}; use rustc_hir::def::Namespace; use rustc_hir::def_id::DefId; use rustc_middle::ty::error::ExpectedFound; @@ -17,7 +17,9 @@ use std::fmt::{self, Write}; impl<'tcx> NiceRegionError<'_, 'tcx> { /// When given a `ConcreteFailure` for a function with arguments containing a named region and /// an anonymous region, emit a descriptive diagnostic error. - pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> { + pub(super) fn try_report_placeholder_conflict( + &self, + ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> { match &self.error { /////////////////////////////////////////////////////////////////////////// // NB. The ordering of cases in this match is very @@ -153,7 +155,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { sub_placeholder: Option<Region<'tcx>>, sup_placeholder: Option<Region<'tcx>>, value_pairs: &ValuePairs<'tcx>, - ) -> Option<DiagnosticBuilder<'tcx>> { + ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> { let (expected_substs, found_substs, trait_def_id) = match value_pairs { ValuePairs::TraitRefs(ExpectedFound { expected, found }) if expected.def_id == found.def_id => @@ -201,7 +203,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { trait_def_id: DefId, expected_substs: SubstsRef<'tcx>, actual_substs: SubstsRef<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let span = cause.span(self.tcx()); let msg = format!( "implementation of `{}` is not general enough", diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index f44dbef46b8..5dc8c894608 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -1,6 +1,6 @@ use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt}; use crate::infer::{self, InferCtxt, SubregionOrigin}; -use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, ErrorReported}; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{self, Region}; @@ -109,7 +109,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { origin: SubregionOrigin<'tcx>, sub: Region<'tcx>, sup: Region<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { match origin { infer::Subtype(box trace) => { let terr = TypeError::RegionsDoesNotOutlive(sup, sub); @@ -401,7 +401,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { placeholder_origin: SubregionOrigin<'tcx>, sub: Region<'tcx>, sup: Region<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { // I can't think how to do better than this right now. -nikomatsakis debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure"); match placeholder_origin { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index fc54d04d0f9..95608f413d5 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -14,7 +14,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::undo_log::Rollback; use rustc_data_structures::unify as ut; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{DiagnosticBuilder, ErrorReported}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues}; @@ -1475,9 +1475,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { sp: Span, mk_diag: M, actual_ty: Ty<'tcx>, - ) -> DiagnosticBuilder<'tcx> + ) -> DiagnosticBuilder<'tcx, ErrorReported> where - M: FnOnce(String) -> DiagnosticBuilder<'tcx>, + M: FnOnce(String) -> DiagnosticBuilder<'tcx, ErrorReported>, { let actual_ty = self.resolve_vars_if_possible(actual_ty); debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty); @@ -1498,7 +1498,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, err: TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let trace = TypeTrace::types(cause, true, expected, actual); self.report_and_explain_type_error(trace, &err) } @@ -1509,7 +1509,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { expected: ty::Const<'tcx>, actual: ty::Const<'tcx>, err: TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let trace = TypeTrace::consts(cause, true, expected, actual); self.report_and_explain_type_error(trace, &err) } diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index 1a5ffd93701..35430849290 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -2,7 +2,7 @@ use super::ObjectSafetyViolation; use crate::infer::InferCtxt; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{struct_span_err, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorReported}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::ty::TyCtxt; @@ -17,7 +17,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { impl_item_def_id: DefId, trait_item_def_id: DefId, requirement: &dyn fmt::Display, - ) -> DiagnosticBuilder<'tcx> { + ) -> DiagnosticBuilder<'tcx, ErrorReported> { let msg = "impl has stricter requirements than trait"; let sp = self.tcx.sess.source_map().guess_head_span(error_span); @@ -40,7 +40,7 @@ pub fn report_object_safety_error<'tcx>( span: Span, trait_def_id: DefId, violations: &[ObjectSafetyViolation], -) -> DiagnosticBuilder<'tcx> { +) -> DiagnosticBuilder<'tcx, ErrorReported> { let trait_str = tcx.def_path_str(trait_def_id); let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node { hir::Node::Item(item) => Some(item.ident.span), |
