FIX - adopt new Diagnostic naming in newly migrated modules

FIX - ambiguous Diagnostic link in docs

UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic

[Gardening] FIX - formatting via `x fmt`

FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way

DELETE - unneeded allow attributes in Handler method

FIX - broken test

FIX - Rebase conflict

UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
This commit is contained in:
Jhonny Bill Mena 2022-09-15 00:01:44 -04:00
parent 5f91719f75
commit e52e2344dc
28 changed files with 88 additions and 127 deletions

View File

@ -335,7 +335,7 @@ pub struct InclusiveRangeWithNoEnd {
pub span: Span,
}
#[derive(SessionDiagnostic, Clone, Copy)]
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::trait_fn_async, code = "E0706")]
#[note]
#[note(ast_lowering::note2)]

View File

@ -2,8 +2,7 @@ use std::num::IntErrorKind;
use rustc_ast as ast;
use rustc_errors::{
error_code, fluent, Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed,
Handler,
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
};
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};

View File

@ -178,7 +178,7 @@ impl IntoDiagnosticArg for hir::ConstContext {
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
#[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Subdiagnostic")]
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "AddToDiagnostic")]
pub trait AddToDiagnostic {
/// Add a subdiagnostic to an existing diagnostic.
fn add_to_diagnostic(self, diag: &mut Diagnostic);

View File

@ -16,7 +16,7 @@ use std::thread::panicking;
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic].
#[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")]
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Diagnostic")]
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "IntoDiagnostic")]
pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `Handler`.
#[must_use]

View File

@ -437,11 +437,11 @@ struct HandlerInner {
/// have been converted.
check_unstable_expect_diagnostics: bool,
/// Expected [`Diagnostic`]s store a [`LintExpectationId`] as part of
/// Expected [`Diagnostic`][diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of
/// the lint level. [`LintExpectationId`]s created early during the compilation
/// (before `HirId`s have been defined) are not stable and can therefore not be
/// stored on disk. This buffer stores these diagnostics until the ID has been
/// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`]s are the
/// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][diagnostic::Diagnostic]s are the
/// submitted for storage and added to the list of fulfilled expectations.
unstable_expect_diagnostics: Vec<Diagnostic>,
@ -647,8 +647,6 @@ impl Handler {
/// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_diagnostic<G: EmissionGuarantee>(
&self,
msg: impl Into<DiagnosticMessage>,
@ -662,8 +660,6 @@ impl Handler {
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_warn(
&self,
span: impl Into<MultiSpan>,
@ -680,8 +676,6 @@ impl Handler {
/// Attempting to `.emit()` the builder will only emit if either:
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_warn_with_expectation(
&self,
span: impl Into<MultiSpan>,
@ -695,8 +689,6 @@ impl Handler {
/// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_allow(
&self,
span: impl Into<MultiSpan>,
@ -710,8 +702,6 @@ impl Handler {
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
/// Also include a code.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_warn_with_code(
&self,
span: impl Into<MultiSpan>,
@ -729,8 +719,6 @@ impl Handler {
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Warning(None), msg)
}
@ -741,8 +729,6 @@ impl Handler {
/// Attempting to `.emit()` the builder will only emit if either:
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_warn_with_expectation(
&self,
msg: impl Into<DiagnosticMessage>,
@ -753,16 +739,12 @@ impl Handler {
/// Construct a builder at the `Allow` level with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Allow, msg)
}
/// Construct a builder at the `Expect` level with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_expect(
&self,
msg: impl Into<DiagnosticMessage>,
@ -773,8 +755,6 @@ impl Handler {
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_err(
&self,
span: impl Into<MultiSpan>,
@ -787,8 +767,6 @@ impl Handler {
/// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_err_with_code(
&self,
span: impl Into<MultiSpan>,
@ -803,8 +781,6 @@ impl Handler {
/// Construct a builder at the `Error` level with the `msg`.
// FIXME: This method should be removed (every error should have an associated error code).
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_err(
&self,
msg: impl Into<DiagnosticMessage>,
@ -814,16 +790,12 @@ impl Handler {
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
#[doc(hidden)]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_err_lint(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Error { lint: true }, msg)
}
/// Construct a builder at the `Error` level with the `msg` and the `code`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_err_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
@ -836,8 +808,6 @@ impl Handler {
/// Construct a builder at the `Warn` level with the `msg` and the `code`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_warn_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
@ -850,8 +820,6 @@ impl Handler {
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_fatal(
&self,
span: impl Into<MultiSpan>,
@ -864,8 +832,6 @@ impl Handler {
/// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
@ -879,24 +845,18 @@ impl Handler {
/// Construct a builder at the `Error` level with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
DiagnosticBuilder::new_fatal(self, msg)
}
/// Construct a builder at the `Help` level with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Help, msg)
}
/// Construct a builder at the `Note` level with the `msg`.
#[rustc_lint_diagnostics]
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
pub fn struct_note_without_error(
&self,
msg: impl Into<DiagnosticMessage>,

View File

@ -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, IntoDiagnostic, ErrorGuaranteed, MultiSpan, PResult,
Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan, PResult,
};
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};

View File

@ -1,10 +1,10 @@
use hir::GenericParamKind;
use rustc_errors::{
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
fluent, AddToDiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::{FnRetTy, Ty};
use rustc_macros::SessionDiagnostic;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::{Region, TyCtxt};
use rustc_span::symbol::kw;
use rustc_span::{symbol::Ident, BytePos, Span};
@ -16,7 +16,7 @@ use crate::infer::error_reporting::{
pub mod note_and_explain;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::opaque_hidden_type)]
pub struct OpaqueHiddenTypeDiag {
#[primary_span]
@ -28,7 +28,7 @@ pub struct OpaqueHiddenTypeDiag {
pub hidden_type: Span,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::type_annotations_needed, code = "E0282")]
pub struct AnnotationRequired<'a> {
#[primary_span]
@ -46,7 +46,7 @@ pub struct AnnotationRequired<'a> {
}
// Copy of `AnnotationRequired` for E0283
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::type_annotations_needed, code = "E0283")]
pub struct AmbigousImpl<'a> {
#[primary_span]
@ -64,7 +64,7 @@ pub struct AmbigousImpl<'a> {
}
// Copy of `AnnotationRequired` for E0284
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::type_annotations_needed, code = "E0284")]
pub struct AmbigousReturn<'a> {
#[primary_span]
@ -81,7 +81,7 @@ pub struct AmbigousReturn<'a> {
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::need_type_info_in_generator, code = "E0698")]
pub struct NeedTypeInfoInGenerator<'a> {
#[primary_span]
@ -92,7 +92,7 @@ pub struct NeedTypeInfoInGenerator<'a> {
}
// Used when a better one isn't available
#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
#[label(infer::label_bad)]
pub struct InferenceBadError<'a> {
#[primary_span]
@ -106,7 +106,7 @@ pub struct InferenceBadError<'a> {
pub name: String,
}
#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum SourceKindSubdiag<'a> {
#[suggestion_verbose(
infer::source_kind_subdiag_let,
@ -147,7 +147,7 @@ pub enum SourceKindSubdiag<'a> {
},
}
#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum SourceKindMultiSuggestion<'a> {
#[multipart_suggestion_verbose(
infer::source_kind_fully_qualified,
@ -228,7 +228,7 @@ pub enum RegionOriginNote<'a> {
},
}
impl AddSubdiagnostic for RegionOriginNote<'_> {
impl AddToDiagnostic for RegionOriginNote<'_> {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
let mut label_or_note = |span, msg: DiagnosticMessage| {
let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
@ -289,7 +289,7 @@ pub enum LifetimeMismatchLabels {
},
}
impl AddSubdiagnostic for LifetimeMismatchLabels {
impl AddToDiagnostic for LifetimeMismatchLabels {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self {
LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
@ -339,7 +339,7 @@ pub struct AddLifetimeParamsSuggestion<'a> {
pub add_note: bool,
}
impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> {
impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
let mut mk_suggestion = || {
let (
@ -422,7 +422,7 @@ impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> {
}
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::lifetime_mismatch, code = "E0623")]
pub struct LifetimeMismatch<'a> {
#[primary_span]
@ -438,7 +438,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq {
pub binding_span: Span,
}
impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
self.unmet_requirements
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
@ -450,7 +450,7 @@ pub struct ImplNote {
pub impl_span: Option<Span>,
}
impl AddSubdiagnostic for ImplNote {
impl AddToDiagnostic for ImplNote {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self.impl_span {
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
@ -465,7 +465,7 @@ pub enum TraitSubdiag {
}
// FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support
impl AddSubdiagnostic for TraitSubdiag {
impl AddToDiagnostic for TraitSubdiag {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self {
TraitSubdiag::Note { span } => {
@ -483,7 +483,7 @@ impl AddSubdiagnostic for TraitSubdiag {
}
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(infer::mismatched_static_lifetime)]
pub struct MismatchedStaticLifetime<'a> {
#[primary_span]

View File

@ -1,5 +1,5 @@
use crate::infer::error_reporting::nice_region_error::find_anon_type;
use rustc_errors::{self, fluent, AddSubdiagnostic, IntoDiagnosticArg};
use rustc_errors::{self, fluent, AddToDiagnostic, IntoDiagnosticArg};
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{symbol::kw, Span};
@ -158,7 +158,7 @@ impl RegionExplanation<'_> {
}
}
impl AddSubdiagnostic for RegionExplanation<'_> {
impl AddToDiagnostic for RegionExplanation<'_> {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
if let Some(span) = self.desc.span {
diag.span_note(span, fluent::infer::region_explanation);

View File

@ -11,7 +11,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::SubregionOrigin;
use crate::infer::TyCtxt;
use rustc_errors::AddSubdiagnostic;
use rustc_errors::AddToDiagnostic;
use rustc_errors::{Diagnostic, ErrorGuaranteed};
use rustc_hir::Ty;
use rustc_middle::ty::Region;

View File

@ -1,4 +1,4 @@
use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler};
use rustc_errors::{fluent, AddToDiagnostic, ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::lint::Level;
use rustc_span::{Span, Symbol};

View File

@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics {
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
let Some(def_id) = of_trait.trait_def_id() &&
let Some(name) = cx.tcx.get_diagnostic_name(def_id) &&
matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint)
matches!(name, sym::IntoDiagnostic | sym::AddToDiagnostic | sym::DecorateLint)
{
found_impl = true;
break;

View File

@ -9,13 +9,13 @@ use syn::spanned::Spanned;
use synstructure::Structure;
/// The central struct for constructing the `into_diagnostic` method from an annotated struct.
pub(crate) struct SessionDiagnosticDerive<'a> {
pub(crate) struct DiagnosticDerive<'a> {
structure: Structure<'a>,
handler: syn::Ident,
builder: DiagnosticDeriveBuilder,
}
impl<'a> SessionDiagnosticDerive<'a> {
impl<'a> DiagnosticDerive<'a> {
pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self {
Self {
builder: DiagnosticDeriveBuilder {
@ -31,7 +31,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
}
pub(crate) fn into_tokens(self) -> TokenStream {
let SessionDiagnosticDerive { mut structure, handler, mut builder } = self;
let DiagnosticDerive { mut structure, handler, mut builder } = self;
let ast = structure.ast();
let implementation = {

View File

@ -5,7 +5,7 @@ mod fluent;
mod subdiagnostic;
mod utils;
use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive};
use diagnostic::{DiagnosticDerive, LintDiagnosticDerive};
pub(crate) use fluent::fluent_messages;
use proc_macro2::TokenStream;
use quote::format_ident;
@ -59,7 +59,7 @@ use synstructure::Structure;
/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens()
DiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens()
}
/// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct,
@ -103,7 +103,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// ```
///
/// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/sessiondiagnostic.html>
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#reference>
pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens()
}

View File

@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};
use rustc_errors::{error_code, IntoDiagnostic, ErrorGuaranteed};
use rustc_errors::{error_code, ErrorGuaranteed, IntoDiagnostic};
use rustc_macros::Diagnostic;
use rustc_session::config;
use rustc_span::{sym, Span, Symbol};

View File

@ -53,6 +53,7 @@ use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_session::config::{CrateType, OutputFilenames};
use rustc_session::cstore::CrateStoreDyn;
use rustc_session::errors::TargetDataLayoutErrorsWrapper;
use rustc_session::lint::Lint;
use rustc_session::Limit;
use rustc_session::Session;
@ -1245,7 +1246,7 @@ impl<'tcx> TyCtxt<'tcx> {
output_filenames: OutputFilenames,
) -> GlobalCtxt<'tcx> {
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
s.emit_fatal(err);
s.emit_fatal(TargetDataLayoutErrorsWrapper(err));
});
let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(

View File

@ -1,7 +1,7 @@
use std::path::PathBuf;
use rustc_errors::IntoDiagnostic;
use rustc_errors::ErrorGuaranteed;
use rustc_errors::IntoDiagnostic;
use rustc_macros::{Diagnostic, LintDiagnostic};
use rustc_span::Span;

View File

@ -434,7 +434,7 @@ pub(crate) struct NotAsNegationOperator {
pub sub: NotAsNegationOperatorSub,
}
#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum NotAsNegationOperatorSub {
#[suggestion_short(
parser::unexpected_token_after_not_default,
@ -737,7 +737,7 @@ pub(crate) struct RemoveLet {
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(parser::use_eq_instead)]
pub(crate) struct UseEqInstead {
#[primary_span]

View File

@ -650,7 +650,7 @@ pub struct RustcLintOptDenyFieldAccess {
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(passes::collapse_debuginfo)]
pub struct CollapseDebuginfo {
#[primary_span]

View File

@ -1,7 +1,7 @@
use rustc_errors::AddToDiagnostic;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::Limit;
use rustc_span::{Span, Symbol};
use rustc_macros::{Diagnostic, Subdiagnostic};
pub struct CycleStack {
pub span: Span,

View File

@ -4,7 +4,7 @@ use crate::query::{QueryContext, QueryStackFrame};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{
Diagnostic, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, Handler, Level,
Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level,
};
use rustc_hir::def::DefKind;
use rustc_session::Session;

View File

@ -3,6 +3,7 @@
pub use crate::options::*;
use crate::errors::TargetDataLayoutErrorsWrapper;
use crate::search_paths::SearchPath;
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
use crate::{early_error, early_warn, Session};
@ -898,7 +899,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
let max_atomic_width = sess.target.max_atomic_width();
let atomic_cas = sess.target.atomic_cas;
let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| {
sess.emit_fatal(err);
sess.emit_fatal(TargetDataLayoutErrorsWrapper(err));
});
let mut ret = CrateConfig::default();

View File

@ -1,9 +1,10 @@
use std::num::NonZeroU32;
use crate::cgu_reuse_tracker::CguReuse;
use crate::{self as rustc_session, SessionDiagnostic};
use rustc_errors::{fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, MultiSpan};
use rustc_macros::SessionDiagnostic;
use rustc_errors::{
fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan,
};
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};
use rustc_target::abi::TargetDataLayoutErrors;
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
@ -46,10 +47,12 @@ pub struct FeatureDiagnosticHelp {
pub feature: Symbol,
}
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
pub struct TargetDataLayoutErrorsWrapper<'a>(pub TargetDataLayoutErrors<'a>);
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrorsWrapper<'_> {
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
let mut diag;
match self {
match self.0 {
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
diag = handler.struct_fatal(fluent::session::target_invalid_address_space);
diag.set_arg("addr_space", addr_space);
@ -97,87 +100,87 @@ impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
}
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::not_circumvent_feature)]
pub struct NotCircumventFeature;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::linker_plugin_lto_windows_not_supported)]
pub struct LinkerPluginToWindowsNotSupported;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::profile_use_file_does_not_exist)]
pub struct ProfileUseFileDoesNotExist<'a> {
pub path: &'a std::path::Path,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::profile_sample_use_file_does_not_exist)]
pub struct ProfileSampleUseFileDoesNotExist<'a> {
pub path: &'a std::path::Path,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::target_requires_unwind_tables)]
pub struct TargetRequiresUnwindTables;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::sanitizer_not_supported)]
pub struct SanitizerNotSupported {
pub us: String,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::sanitizers_not_supported)]
pub struct SanitizersNotSupported {
pub us: String,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::cannot_mix_and_match_sanitizers)]
pub struct CannotMixAndMatchSanitizers {
pub first: String,
pub second: String,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::cannot_enable_crt_static_linux)]
pub struct CannotEnableCrtStaticLinux;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::sanitizer_cfi_enabled)]
pub struct SanitizerCfiEnabled;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::unstable_virtual_function_elimination)]
pub struct UnstableVirtualFunctionElimination;
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::unsupported_dwarf_version)]
pub struct UnsupportedDwarfVersion {
pub dwarf_version: u32,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::target_stack_protector_not_supported)]
pub struct StackProtectorNotSupportedForTarget<'a> {
pub stack_protector: StackProtector,
pub target_triple: &'a TargetTriple,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::split_debuginfo_unstable_platform)]
pub struct SplitDebugInfoUnstablePlatform {
pub debuginfo: SplitDebuginfo,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::file_is_not_writeable)]
pub struct FileIsNotWriteable<'a> {
pub file: &'a std::path::Path,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::crate_name_does_not_match)]
pub struct CrateNameDoesNotMatch<'a> {
#[primary_span]
@ -186,13 +189,13 @@ pub struct CrateNameDoesNotMatch<'a> {
pub name: Symbol,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::crate_name_invalid)]
pub struct CrateNameInvalid<'a> {
pub s: &'a str,
}
#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(session::crate_name_empty)]
pub struct CrateNameEmpty {
#[primary_span]
@ -205,11 +208,8 @@ pub struct InvalidCharacterInCrateName<'a> {
pub crate_name: &'a str,
}
impl crate::SessionDiagnostic<'_> for InvalidCharacterInCrateName<'_> {
fn into_diagnostic(
self,
sess: &Handler,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
impl IntoDiagnostic<'_> for InvalidCharacterInCrateName<'_> {
fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name);
if let Some(sp) = self.span {
diag.set_span(sp);

View File

@ -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, IntoDiagnostic,
DiagnosticId, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey,
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
};
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
use rustc_span::edition::Edition;

View File

@ -27,8 +27,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, IntoDiagnostic, DiagnosticId,
DiagnosticMessage, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan,
};
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;

View File

@ -125,6 +125,7 @@ symbols! {
Symbols {
AcqRel,
Acquire,
AddToDiagnostic,
Alignment,
Any,
Arc,
@ -176,7 +177,6 @@ symbols! {
DecorateLint,
Default,
Deref,
Diagnostic,
DiagnosticMessage,
DirBuilder,
Display,
@ -210,6 +210,7 @@ symbols! {
Implied,
Input,
Into,
IntoDiagnostic,
IntoFuture,
IntoIterator,
IoRead,
@ -282,7 +283,6 @@ symbols! {
String,
StructuralEq,
StructuralPartialEq,
Subdiagnostic,
SubdiagnosticMessage,
Sync,
T,

View File

@ -1,4 +1,4 @@
use rustc_errors::{fluent, IntoDiagnostic, ErrorGuaranteed, Handler};
use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_macros::Diagnostic;
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
use rustc_session::Limit;

View File

@ -20,7 +20,7 @@ use rustc_span::Span;
#[derive(Diagnostic)]
#[diag(parser::expect_path)]
struct DeriveSessionDiagnostic {
struct DeriveDiagnostic {
#[primary_span]
span: Span,
}
@ -32,18 +32,18 @@ struct Note {
span: Span,
}
pub struct UntranslatableInSessionDiagnostic;
pub struct UntranslatableInIntoDiagnostic;
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages
}
}
pub struct TranslatableInSessionDiagnostic;
pub struct TranslatableInIntoDiagnostic;
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err(fluent::parser::expect_path)
}

View File

@ -449,7 +449,7 @@ error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
--> $DIR/diagnostic-derive.rs:331:10
|
LL | #[derive(Diagnostic)]
| ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
| ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
|
= help: normalized in stderr
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`