Prefer DiagnosticBuilder
over Diagnostic
in diagnostic modifiers.
There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`.
This commit is contained in:
parent
8b21296b5d
commit
b18f3e11fa
66 changed files with 536 additions and 454 deletions
|
@ -2,7 +2,7 @@ use std::cmp;
|
|||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||
use rustc_hir::{HirId, ItemLocalId};
|
||||
use rustc_session::lint::{
|
||||
builtin::{self, FORBIDDEN_LINT_GROUPS},
|
||||
|
@ -204,7 +204,7 @@ pub fn explain_lint_level_source(
|
|||
lint: &'static Lint,
|
||||
level: Level,
|
||||
src: LintLevelSource,
|
||||
err: &mut Diagnostic,
|
||||
err: &mut DiagnosticBuilder<'_, ()>,
|
||||
) {
|
||||
let name = lint.name_lower();
|
||||
if let Level::Allow = level {
|
||||
|
@ -359,7 +359,7 @@ pub fn lint_level(
|
|||
// Lint diagnostics that are covered by the expect level will not be emitted outside
|
||||
// the compiler. It is therefore not necessary to add any information for the user.
|
||||
// This will therefore directly call the decorate function which will in turn emit
|
||||
// the `Diagnostic`.
|
||||
// the diagnostic.
|
||||
if let Level::Expect(_) = level {
|
||||
decorate(&mut err);
|
||||
err.emit();
|
||||
|
@ -401,7 +401,7 @@ pub fn lint_level(
|
|||
|
||||
// Finally, run `decorate`.
|
||||
decorate(&mut err);
|
||||
explain_lint_level_source(lint, level, src, &mut *err);
|
||||
explain_lint_level_source(lint, level, src, &mut err);
|
||||
err.emit()
|
||||
}
|
||||
lint_level_impl(sess, lint, level, src, span, msg, Box::new(decorate))
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_attr::{
|
|||
self as attr, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability,
|
||||
};
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_feature::GateIssue;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap};
|
||||
|
@ -125,7 +125,7 @@ pub fn report_unstable(
|
|||
}
|
||||
|
||||
pub fn deprecation_suggestion(
|
||||
diag: &mut Diagnostic,
|
||||
diag: &mut DiagnosticBuilder<'_, ()>,
|
||||
kind: &str,
|
||||
suggestion: Option<Symbol>,
|
||||
span: Span,
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::ty::GenericArgsRef;
|
|||
use crate::ty::{self, AdtKind, Ty};
|
||||
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, EmissionGuarantee};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||
|
@ -908,7 +908,7 @@ pub enum ObjectSafetyViolationSolution {
|
|||
}
|
||||
|
||||
impl ObjectSafetyViolationSolution {
|
||||
pub fn add_to(self, err: &mut Diagnostic) {
|
||||
pub fn add_to<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) {
|
||||
match self {
|
||||
ObjectSafetyViolationSolution::None => {}
|
||||
ObjectSafetyViolationSolution::AddSelfOrMakeSized {
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::ty::{
|
|||
};
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticArgValue, IntoDiagnosticArg};
|
||||
use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticBuilder, IntoDiagnosticArg};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -111,7 +111,7 @@ where
|
|||
pub fn suggest_arbitrary_trait_bound<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
generics: &hir::Generics<'_>,
|
||||
err: &mut Diagnostic,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_pred: PolyTraitPredicate<'tcx>,
|
||||
associated_ty: Option<(&'static str, Ty<'tcx>)>,
|
||||
) -> bool {
|
||||
|
@ -216,7 +216,7 @@ fn suggest_changing_unsized_bound(
|
|||
pub fn suggest_constraining_type_param(
|
||||
tcx: TyCtxt<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
err: &mut Diagnostic,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
param_name: &str,
|
||||
constraint: &str,
|
||||
def_id: Option<DefId>,
|
||||
|
@ -235,7 +235,7 @@ pub fn suggest_constraining_type_param(
|
|||
pub fn suggest_constraining_type_params<'a>(
|
||||
tcx: TyCtxt<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
err: &mut Diagnostic,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
|
||||
span_to_replace: Option<Span>,
|
||||
) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue