Skip to content

Commit

Permalink
[Gardening] UPDATE - rename SessionDiagnostic to DiagnosticHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonnyBillM committed Sep 8, 2022
1 parent a5e045e commit 64a4376
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 52 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_attr/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::num::IntErrorKind;

use rustc_ast as ast;
use rustc_errors::SessionDiagnostic;
use rustc_errors::DiagnosticHandler;
use rustc_errors::{
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler,
};
Expand Down Expand Up @@ -50,7 +50,7 @@ pub(crate) struct UnknownMetaItem<'a> {
}

// Manual implementation to be able to format `expected` items correctly.
impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> {
impl<'a> DiagnosticHandler<'a> for UnknownMetaItem<'_> {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>();
let mut diag = handler.struct_span_err_with_code(
Expand Down Expand Up @@ -209,7 +209,7 @@ pub(crate) struct UnsupportedLiteral {
pub start_point_span: Span,
}

impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
impl<'a> DiagnosticHandler<'a> for UnsupportedLiteral {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut diag = handler.struct_span_err_with_code(
self.span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_messages/locales/en-US/lint.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lint_non_existant_doc_keyword = found non-existing keyword `{$keyword}` used in
.help = only existing keywords are allowed in core/std
lint_diag_out_of_impl =
diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
diagnostics should only be created in `DiagnosticHandler`/`AddSubdiagnostic` impls
lint_untranslatable_diag = diagnostics should be created using translatable messages
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::thread::panicking;
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic].
#[rustc_diagnostic_item = "SessionDiagnostic"]
pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
pub trait DiagnosticHandler<'a, T: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `Handler`.
#[must_use]
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod snippet;
mod styled_buffer;
pub mod translation;

pub use diagnostic_builder::SessionDiagnostic;
pub use diagnostic_builder::DiagnosticHandler;
pub use snippet::Style;

pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorGuaranteed>>;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_attr::{self as attr, Deprecation, Stability};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{
Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SessionDiagnostic,
Applicability, DiagnosticBuilder, DiagnosticHandler, ErrorGuaranteed, MultiSpan, PResult,
};
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
Expand Down Expand Up @@ -1104,12 +1104,12 @@ impl<'a> ExtCtxt<'a> {

pub fn create_err(
&self,
err: impl SessionDiagnostic<'a>,
err: impl DiagnosticHandler<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.sess.create_err(err)
}

pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
pub fn emit_err(&self, err: impl DiagnosticHandler<'a>) -> ErrorGuaranteed {
self.sess.emit_err(err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::errors::{
};
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::InferCtxt;
use rustc_errors::SessionDiagnostic;
use rustc_errors::DiagnosticHandler;
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, IntoDiagnosticArg};
use rustc_hir as hir;
use rustc_hir::def::Res;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler, SessionDiagnostic};
use rustc_errors::{fluent, AddSubdiagnostic, DiagnosticHandler, ErrorGuaranteed, Handler};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_session::lint::Level;
use rustc_span::{Span, Symbol};
Expand Down Expand Up @@ -119,7 +119,7 @@ pub struct CheckNameUnknown {
pub sub: RequestedLevel,
}

impl SessionDiagnostic<'_> for CheckNameUnknown {
impl DiagnosticHandler<'_> for CheckNameUnknown {
fn into_diagnostic(
self,
handler: &Handler,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ impl<'a> SessionDiagnosticDerive<'a> {
};

structure.gen_impl(quote! {
gen impl<'__session_diagnostic_sess, G>
rustc_errors::SessionDiagnostic<'__session_diagnostic_sess, G>
gen impl<'__diagnostic_handler_sess, G>
rustc_errors::DiagnosticHandler<'__diagnostic_handler_sess, G>
for @Self
where G: rustc_errors::EmissionGuarantee
{
fn into_diagnostic(
self,
#sess: &'__session_diagnostic_sess rustc_errors::Handler
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, G> {
#sess: &'__diagnostic_handler_sess rustc_errors::Handler
) -> rustc_errors::DiagnosticBuilder<'__diagnostic_handler_sess, G> {
use rustc_errors::IntoDiagnosticArg;
#implementation
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use rustc_errors::{error_code, ErrorGuaranteed, SessionDiagnostic};
use rustc_errors::{error_code, DiagnosticHandler, ErrorGuaranteed};
use rustc_macros::SessionDiagnostic;
use rustc_session::config;
use rustc_span::{sym, Span, Symbol};
Expand Down Expand Up @@ -421,7 +421,7 @@ pub(crate) struct MultipleCandidates {
pub candidates: Vec<PathBuf>,
}

impl SessionDiagnostic<'_> for MultipleCandidates {
impl DiagnosticHandler<'_> for MultipleCandidates {
fn into_diagnostic(
self,
handler: &'_ rustc_errors::Handler,
Expand Down Expand Up @@ -537,7 +537,7 @@ pub struct InvalidMetadataFiles {
pub crate_rejections: Vec<String>,
}

impl SessionDiagnostic<'_> for InvalidMetadataFiles {
impl DiagnosticHandler<'_> for InvalidMetadataFiles {
fn into_diagnostic(
self,
handler: &'_ rustc_errors::Handler,
Expand Down Expand Up @@ -565,7 +565,7 @@ pub struct CannotFindCrate {
pub locator_triple: TargetTriple,
}

impl SessionDiagnostic<'_> for CannotFindCrate {
impl DiagnosticHandler<'_> for CannotFindCrate {
fn into_diagnostic(
self,
handler: &'_ rustc_errors::Handler,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use rustc_errors::DiagnosticHandler;
use rustc_errors::ErrorGuaranteed;
use rustc_errors::SessionDiagnostic;
use rustc_macros::{LintDiagnostic, SessionDiagnostic};
use rustc_span::Span;

Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct UnusedGenericParams {
pub param_names: Vec<String>,
}

impl SessionDiagnostic<'_> for UnusedGenericParams {
impl DiagnosticHandler<'_> for UnusedGenericParams {
fn into_diagnostic(
self,
handler: &'_ rustc_errors::Handler,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
use rustc_ast::{ClosureBinder, StmtKind};
use rustc_ast_pretty::pprust;
use rustc_errors::SessionDiagnostic;
use rustc_errors::DiagnosticHandler;
use rustc_errors::{Applicability, Diagnostic, PResult};
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
use rustc_session::lint::BuiltinLintDiagnostics;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::query::{QueryContext, QueryStackFrame};

use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{
Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level, SessionDiagnostic,
Diagnostic, DiagnosticBuilder, DiagnosticHandler, ErrorGuaranteed, Handler, Level,
};
use rustc_hir::def::DefKind;
use rustc_session::Session;
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
use rustc_errors::{
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, SessionDiagnostic, StashKey,
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticHandler,
DiagnosticId, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey,
};
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
use rustc_span::edition::Edition;
Expand Down Expand Up @@ -340,34 +340,34 @@ impl ParseSess {

pub fn create_err<'a>(
&'a self,
err: impl SessionDiagnostic<'a>,
err: impl DiagnosticHandler<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
err.into_diagnostic(&self.span_diagnostic)
}

pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
pub fn emit_err<'a>(&'a self, err: impl DiagnosticHandler<'a>) -> ErrorGuaranteed {
self.create_err(err).emit()
}

pub fn create_warning<'a>(
&'a self,
warning: impl SessionDiagnostic<'a, ()>,
warning: impl DiagnosticHandler<'a, ()>,
) -> DiagnosticBuilder<'a, ()> {
warning.into_diagnostic(&self.span_diagnostic)
}

pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) {
pub fn emit_warning<'a>(&'a self, warning: impl DiagnosticHandler<'a, ()>) {
self.create_warning(warning).emit()
}

pub fn create_fatal<'a>(
&'a self,
fatal: impl SessionDiagnostic<'a, !>,
fatal: impl DiagnosticHandler<'a, !>,
) -> DiagnosticBuilder<'a, !> {
fatal.into_diagnostic(&self.span_diagnostic)
}

pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! {
pub fn emit_fatal<'a>(&'a self, fatal: impl DiagnosticHandler<'a, !>) -> ! {
self.create_fatal(fatal).emit()
}

Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry;
use rustc_errors::{
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, SessionDiagnostic,
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticHandler, DiagnosticId,
DiagnosticMessage, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
};
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;
Expand Down Expand Up @@ -454,13 +454,13 @@ impl Session {
}
pub fn create_err<'a>(
&'a self,
err: impl SessionDiagnostic<'a>,
err: impl DiagnosticHandler<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.parse_sess.create_err(err)
}
pub fn create_feature_err<'a>(
&'a self,
err: impl SessionDiagnostic<'a>,
err: impl DiagnosticHandler<'a>,
feature: Symbol,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut err = self.parse_sess.create_err(err);
Expand All @@ -470,25 +470,25 @@ impl Session {
add_feature_diagnostics(&mut err, &self.parse_sess, feature);
err
}
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
pub fn emit_err<'a>(&'a self, err: impl DiagnosticHandler<'a>) -> ErrorGuaranteed {
self.parse_sess.emit_err(err)
}
pub fn create_warning<'a>(
&'a self,
err: impl SessionDiagnostic<'a, ()>,
err: impl DiagnosticHandler<'a, ()>,
) -> DiagnosticBuilder<'a, ()> {
self.parse_sess.create_warning(err)
}
pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) {
pub fn emit_warning<'a>(&'a self, warning: impl DiagnosticHandler<'a, ()>) {
self.parse_sess.emit_warning(warning)
}
pub fn create_fatal<'a>(
&'a self,
fatal: impl SessionDiagnostic<'a, !>,
fatal: impl DiagnosticHandler<'a, !>,
) -> DiagnosticBuilder<'a, !> {
self.parse_sess.create_fatal(fatal)
}
pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! {
pub fn emit_fatal<'a>(&'a self, fatal: impl DiagnosticHandler<'a, !>) -> ! {
self.parse_sess.emit_fatal(fatal)
}
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_errors::{fluent, ErrorGuaranteed, Handler, SessionDiagnostic};
use rustc_errors::{fluent, DiagnosticHandler, ErrorGuaranteed, Handler};
use rustc_macros::SessionDiagnostic;
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
use rustc_session::Limit;
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct NegativePositiveConflict<'a> {
pub positive_impl_span: Result<Span, Symbol>,
}

impl SessionDiagnostic<'_> for NegativePositiveConflict<'_> {
impl DiagnosticHandler<'_> for NegativePositiveConflict<'_> {
fn into_diagnostic(
self,
handler: &Handler,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Errors emitted by typeck.
use rustc_errors::SessionDiagnostic;
use rustc_errors::DiagnosticHandler;
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
use rustc_middle::ty::Ty;
Expand Down Expand Up @@ -250,7 +250,7 @@ pub struct MissingTypeParams {
}

// Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`.
impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
impl<'a> DiagnosticHandler<'a> for MissingTypeParams {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut err = handler.struct_span_err_with_code(
self.span,
Expand Down
11 changes: 6 additions & 5 deletions src/test/ui-fulldeps/internal-lints/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ extern crate rustc_session;
extern crate rustc_span;

use rustc_errors::{
AddSubdiagnostic, SessionDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent
AddSubdiagnostic, DiagnosticHandler, Diagnostic, DiagnosticBuilder,
ErrorGuaranteed, Handler, fluent
};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_span::Span;
Expand All @@ -33,7 +34,7 @@ struct Note {

pub struct UntranslatableInSessionDiagnostic;

impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
impl<'a> DiagnosticHandler<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages
Expand All @@ -42,7 +43,7 @@ impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagn

pub struct TranslatableInSessionDiagnostic;

impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
impl<'a> DiagnosticHandler<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err(fluent::parser::expect_path)
}
Expand All @@ -67,10 +68,10 @@ impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {

pub fn make_diagnostics<'a>(handler: &'a Handler) {
let _diag = handler.struct_err(fluent::parser::expect_path);
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
//~^ ERROR diagnostics should only be created in `DiagnosticHandler`/`AddSubdiagnostic` impls

let _diag = handler.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
//~^ ERROR diagnostics should only be created in `DiagnosticHandler`/`AddSubdiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui-fulldeps/internal-lints/diagnostics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error: diagnostics should be created using translatable messages
LL | diag.note("untranslatable diagnostic");
| ^^^^

error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
error: diagnostics should only be created in `DiagnosticHandler`/`AddSubdiagnostic` impls
--> $DIR/diagnostics.rs:70:25
|
LL | let _diag = handler.struct_err(fluent::parser::expect_path);
Expand All @@ -28,7 +28,7 @@ note: the lint level is defined here
LL | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
error: diagnostics should only be created in `DiagnosticHandler`/`AddSubdiagnostic` impls
--> $DIR/diagnostics.rs:73:25
|
LL | let _diag = handler.struct_err("untranslatable diagnostic");
Expand Down

0 comments on commit 64a4376

Please sign in to comment.