diff options
| author | bors <bors@rust-lang.org> | 2024-01-10 18:03:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-10 18:03:53 +0000 |
| commit | a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01 (patch) | |
| tree | 42523e01769059455f89af632b53b841b1401d69 /compiler/rustc_hir_analysis/src/astconv | |
| parent | e9271846294c4ee5bd7706df68180320c0b5ff20 (diff) | |
| parent | 700a3965202f4f403956fcce744ce5ba6adf2ddb (diff) | |
| download | rust-a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01.tar.gz rust-a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01.zip | |
Auto merge of #119751 - nnethercote:error-api-fixes, r=oli-obk
Diagnostic API fixes Some improvements to diagnostic APIs: improve some naming, use shortcuts in more places, and add a couple of missing methods. r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_hir_analysis/src/astconv')
6 files changed, 29 insertions, 28 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs index 38184a5dd18..1f88aaa6a4b 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs @@ -1,5 +1,5 @@ use rustc_data_structures::fx::FxHashMap; -use rustc_errors::struct_span_err; +use rustc_errors::struct_span_code_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -305,7 +305,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { binding.span, format!("{} `{}` is private", assoc_item.kind, binding.item_name), ) - .span_label_mv(binding.span, format!("private {}", assoc_item.kind)) + .with_span_label(binding.span, format!("private {}", assoc_item.kind)) .emit(); } tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None); @@ -462,7 +462,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { late_bound_in_trait_ref, late_bound_in_ty, |br_name| { - struct_span_err!( + struct_span_code_err!( tcx.dcx(), binding.span, E0582, diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 24b55461a42..fc2ed104b3d 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -7,7 +7,7 @@ use crate::fluent_generated as fluent; use crate::traits::error_reporting::report_object_safety_error; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::unord::UnordMap; -use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, ErrorGuaranteed}; +use rustc_errors::{pluralize, struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::traits::FulfillmentError; @@ -346,7 +346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { candidates: Vec<DefId>, span: Span, ) -> ErrorGuaranteed { - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( self.tcx().dcx(), name.span, E0034, @@ -445,7 +445,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { String::new() }; - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( tcx.dcx(), name.span, E0220, @@ -697,7 +697,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let names = names.join(", "); trait_bound_spans.sort(); - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( tcx.dcx(), trait_bound_spans, E0191, diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index adc6a9de808..e2cd4d5f21c 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -5,7 +5,7 @@ use crate::astconv::{ }; use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; -use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan}; +use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; @@ -27,7 +27,7 @@ fn generic_arg_mismatch_err( help: Option<String>, ) -> ErrorGuaranteed { let sess = tcx.sess; - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( tcx.dcx(), arg.span(), E0747, @@ -70,7 +70,7 @@ fn generic_arg_mismatch_err( Res::Err => { add_braces_suggestion(arg, &mut err); return err - .primary_message_mv("unresolved item provided when a constant was expected") + .with_primary_message("unresolved item provided when a constant was expected") .emit(); } Res::Def(DefKind::TyParam, src_def_id) => { @@ -650,8 +650,8 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes( if position == GenericArgPosition::Value && args.num_lifetime_params() != param_counts.lifetimes { - struct_span_err!(tcx.dcx(), span, E0794, "{}", msg) - .span_note_mv(span_late, note) + struct_span_code_err!(tcx.dcx(), span, E0794, "{}", msg) + .with_span_note(span_late, note) .emit(); } else { let mut multispan = MultiSpan::from_span(span); diff --git a/compiler/rustc_hir_analysis/src/astconv/lint.rs b/compiler/rustc_hir_analysis/src/astconv/lint.rs index 6675f517cfa..3761d529517 100644 --- a/compiler/rustc_hir_analysis/src/astconv/lint.rs +++ b/compiler/rustc_hir_analysis/src/astconv/lint.rs @@ -213,7 +213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let msg = "trait objects must include the `dyn` keyword"; let label = "add `dyn` keyword before this trait"; let mut diag = - rustc_errors::struct_span_err!(tcx.dcx(), self_ty.span, E0782, "{}", msg); + rustc_errors::struct_span_code_err!(tcx.dcx(), self_ty.span, E0782, "{}", msg); if self_ty.span.can_be_used_for_suggestions() && !self.maybe_lint_impl_trait(self_ty, &mut diag) { diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index cdfb4c6389e..1f47564649e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -18,8 +18,8 @@ use crate::require_c_abi_if_c_variadic; use rustc_ast::TraitObjectSyntax; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{ - error_code, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, - FatalError, MultiSpan, + error_code, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, + ErrorGuaranteed, FatalError, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; @@ -866,7 +866,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { traits: &[String], name: Symbol, ) -> ErrorGuaranteed { - let mut err = struct_span_err!(self.tcx().dcx(), span, E0223, "ambiguous associated type"); + let mut err = + struct_span_code_err!(self.tcx().dcx(), span, E0223, "ambiguous associated type"); if self .tcx() .resolutions(()) @@ -1313,7 +1314,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let msg = format!("expected type, found variant `{assoc_ident}`"); tcx.dcx().span_err(span, msg) } else if qself_ty.is_enum() { - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( tcx.dcx(), assoc_ident.span, E0599, @@ -1354,7 +1355,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { reported } else if let ty::Alias(ty::Opaque, alias_ty) = qself_ty.kind() { // `<impl Trait as OtherTrait>::Assoc` makes no sense. - struct_span_err!( + struct_span_code_err!( tcx.dcx(), tcx.def_span(alias_ty.def_id), E0667, @@ -1617,9 +1618,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let def_span = tcx.def_span(item); tcx.dcx() .struct_span_err(span, msg) - .code_mv(rustc_errors::error_code!(E0624)) - .span_label_mv(span, format!("private {kind}")) - .span_label_mv(def_span, format!("{kind} defined here")) + .with_code(rustc_errors::error_code!(E0624)) + .with_span_label(span, format!("private {kind}")) + .with_span_label(def_span, format!("{kind} defined here")) .emit(); } tcx.check_stability(item, Some(block), span, None); @@ -1850,7 +1851,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }; let last_span = *arg_spans.last().unwrap(); let span: MultiSpan = arg_spans.into(); - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( self.tcx().dcx(), span, E0109, @@ -2601,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output); self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| { - struct_span_err!( + struct_span_code_err!( tcx.dcx(), decl.output.span(), E0581, diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs index 703e0bdc40e..ea2f5f50b5c 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs @@ -2,7 +2,7 @@ use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBou use crate::bounds::Bounds; use crate::errors::TraitObjectDeclaredWithNoTraits; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; -use rustc_errors::struct_span_err; +use rustc_errors::struct_span_code_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; @@ -89,7 +89,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if regular_traits.len() > 1 { let first_trait = ®ular_traits[0]; let additional_trait = ®ular_traits[1]; - let mut err = struct_span_err!( + let mut err = struct_span_code_err!( tcx.dcx(), additional_trait.bottom().1, E0225, @@ -290,7 +290,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if references_self { let def_id = i.bottom().0.def_id(); - struct_span_err!( + struct_span_code_err!( tcx.dcx(), i.bottom().1, E0038, @@ -298,7 +298,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { tcx.def_descr(def_id), tcx.item_name(def_id), ) - .note_mv( + .with_note( rustc_middle::traits::ObjectSafetyViolation::SupertraitSelf(smallvec![]) .error_msg(), ) @@ -375,7 +375,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.ast_region_to_region(lifetime, None) } else { self.re_infer(None, span).unwrap_or_else(|| { - let err = struct_span_err!( + let err = struct_span_code_err!( tcx.dcx(), span, E0228, |
