Skip to content

Commit

Permalink
rebase and update trait names
Browse files Browse the repository at this point in the history
  • Loading branch information
ellishg committed Sep 24, 2022
1 parent 6e22c0a commit 5c7e629
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 52 deletions.
50 changes: 25 additions & 25 deletions compiler/rustc_codegen_gcc/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_macros::SessionDiagnostic;
use rustc_macros::Diagnostic;
use rustc_middle::ty::Ty;
use rustc_span::{Span, Symbol};
use std::borrow::Cow;
Expand All @@ -17,7 +17,7 @@ impl IntoDiagnosticArg for ExitCode {
}
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::ranlib_failure)]
pub(crate) struct RanlibFailure {
exit_code: ExitCode,
Expand All @@ -30,7 +30,7 @@ impl RanlibFailure {
}
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_basic_integer, code = "E0511")]
pub(crate) struct InvalidMonomorphizationBasicInteger<'a> {
#[primary_span]
Expand All @@ -39,7 +39,7 @@ pub(crate) struct InvalidMonomorphizationBasicInteger<'a> {
pub ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_invalid_float_vector, code = "E0511")]
pub(crate) struct InvalidMonomorphizationInvalidFloatVector<'a> {
#[primary_span]
Expand All @@ -49,7 +49,7 @@ pub(crate) struct InvalidMonomorphizationInvalidFloatVector<'a> {
pub vec_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_not_float, code = "E0511")]
pub(crate) struct InvalidMonomorphizationNotFloat<'a> {
#[primary_span]
Expand All @@ -58,15 +58,15 @@ pub(crate) struct InvalidMonomorphizationNotFloat<'a> {
pub ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_unrecognized, code = "E0511")]
pub(crate) struct InvalidMonomorphizationUnrecognized {
#[primary_span]
pub span: Span,
pub name: Symbol,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_expected_signed_unsigned, code = "E0511")]
pub(crate) struct InvalidMonomorphizationExpectedSignedUnsigned<'a> {
#[primary_span]
Expand All @@ -76,7 +76,7 @@ pub(crate) struct InvalidMonomorphizationExpectedSignedUnsigned<'a> {
pub vec_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_unsupported_element, code = "E0511")]
pub(crate) struct InvalidMonomorphizationUnsupportedElement<'a> {
#[primary_span]
Expand All @@ -87,7 +87,7 @@ pub(crate) struct InvalidMonomorphizationUnsupportedElement<'a> {
pub ret_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_invalid_bitmask, code = "E0511")]
pub(crate) struct InvalidMonomorphizationInvalidBitmask<'a> {
#[primary_span]
Expand All @@ -98,7 +98,7 @@ pub(crate) struct InvalidMonomorphizationInvalidBitmask<'a> {
pub expected_bytes: u64,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_simd_shuffle, code = "E0511")]
pub(crate) struct InvalidMonomorphizationSimdShuffle<'a> {
#[primary_span]
Expand All @@ -107,7 +107,7 @@ pub(crate) struct InvalidMonomorphizationSimdShuffle<'a> {
pub ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_expected_simd, code = "E0511")]
pub(crate) struct InvalidMonomorphizationExpectedSimd<'a> {
#[primary_span]
Expand All @@ -117,7 +117,7 @@ pub(crate) struct InvalidMonomorphizationExpectedSimd<'a> {
pub found_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_mask_type, code = "E0511")]
pub(crate) struct InvalidMonomorphizationMaskType<'a> {
#[primary_span]
Expand All @@ -126,7 +126,7 @@ pub(crate) struct InvalidMonomorphizationMaskType<'a> {
pub ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_return_length, code = "E0511")]
pub(crate) struct InvalidMonomorphizationReturnLength<'a> {
#[primary_span]
Expand All @@ -137,7 +137,7 @@ pub(crate) struct InvalidMonomorphizationReturnLength<'a> {
pub out_len: u64,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_return_length_input_type, code = "E0511")]
pub(crate) struct InvalidMonomorphizationReturnLengthInputType<'a> {
#[primary_span]
Expand All @@ -149,7 +149,7 @@ pub(crate) struct InvalidMonomorphizationReturnLengthInputType<'a> {
pub out_len: u64,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_return_element, code = "E0511")]
pub(crate) struct InvalidMonomorphizationReturnElement<'a> {
#[primary_span]
Expand All @@ -161,7 +161,7 @@ pub(crate) struct InvalidMonomorphizationReturnElement<'a> {
pub out_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_return_type, code = "E0511")]
pub(crate) struct InvalidMonomorphizationReturnType<'a> {
#[primary_span]
Expand All @@ -172,7 +172,7 @@ pub(crate) struct InvalidMonomorphizationReturnType<'a> {
pub ret_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_inserted_type, code = "E0511")]
pub(crate) struct InvalidMonomorphizationInsertedType<'a> {
#[primary_span]
Expand All @@ -183,7 +183,7 @@ pub(crate) struct InvalidMonomorphizationInsertedType<'a> {
pub out_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_return_integer_type, code = "E0511")]
pub(crate) struct InvalidMonomorphizationReturnIntegerType<'a> {
#[primary_span]
Expand All @@ -193,7 +193,7 @@ pub(crate) struct InvalidMonomorphizationReturnIntegerType<'a> {
pub out_ty: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_mismatched_lengths, code = "E0511")]
pub(crate) struct InvalidMonomorphizationMismatchedLengths {
#[primary_span]
Expand All @@ -203,7 +203,7 @@ pub(crate) struct InvalidMonomorphizationMismatchedLengths {
pub v_len: u64,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_unsupported_cast, code = "E0511")]
pub(crate) struct InvalidMonomorphizationUnsupportedCast<'a> {
#[primary_span]
Expand All @@ -215,7 +215,7 @@ pub(crate) struct InvalidMonomorphizationUnsupportedCast<'a> {
pub out_elem: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::invalid_monomorphization_unsupported_operation, code = "E0511")]
pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
#[primary_span]
Expand All @@ -225,26 +225,26 @@ pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
pub in_elem: Ty<'a>,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::layout_size_overflow)]
pub(crate) struct LayoutSizeOverflow {
#[primary_span]
pub span: Span,
pub error: String,
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::linkage_const_or_mut_type)]
pub(crate) struct LinkageConstOrMutType {
#[primary_span]
pub span: Span
}

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::lto_not_supported)]
pub(crate) struct LTONotSupported;

#[derive(SessionDiagnostic)]
#[derive(Diagnostic)]
#[diag(codegen_gcc::unwinding_inline_asm)]
pub(crate) struct UnwindingInlineAsm {
#[primary_span]
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
};
use crate::{Handler, Level, MultiSpan, StashKey};
use rustc_lint_defs::Applicability;
use rustc_span::source_map::Spanned;

use rustc_span::Span;
use std::borrow::Cow;
Expand All @@ -23,6 +24,18 @@ pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
}

impl<'a, T, E> IntoDiagnostic<'a, E> for Spanned<T>
where
T: IntoDiagnostic<'a, E>,
E: EmissionGuarantee,
{
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, E> {
let mut diag = self.node.into_diagnostic(handler);
diag.set_span(self.span);
diag
}
}

/// Used for emitting structured error messages and other diagnostic information.
///
/// If there is some state in a downstream crate you would like to
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ use crate::ty::{
};
use rustc_ast as ast;
use rustc_attr as attr;
use rustc_errors::Handler;
use rustc_errors::{Handler, IntoDiagnostic};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_session::{
config::OptLevel, DataTypeKind, FieldInfo, SessionDiagnostic, SizeKind, VariantInfo,
};
use rustc_session::{config::OptLevel, DataTypeKind, FieldInfo, SizeKind, VariantInfo};
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::call::{
Expand Down Expand Up @@ -209,7 +207,7 @@ pub enum LayoutError<'tcx> {
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
}

impl<'a> SessionDiagnostic<'a, !> for LayoutError<'a> {
impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> {
fn into_diagnostic(self, handler: &'a Handler) -> rustc_errors::DiagnosticBuilder<'a, !> {
handler.struct_fatal(self.to_string())
}
Expand Down
23 changes: 1 addition & 22 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_errors::{
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;
use rustc_span::edition::Edition;
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMap, Span, Spanned};
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMap, Span};
use rustc_span::{sym, SourceFileHashAlgorithm, Symbol};
use rustc_target::asm::InlineAsmArch;
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
Expand Down Expand Up @@ -223,27 +223,6 @@ pub struct PerfStats {
pub normalize_projection_ty: AtomicUsize,
}

/// 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> {
/// Write out as a diagnostic out of `Handler`.
#[must_use]
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
}

impl<'a, T, E> SessionDiagnostic<'a, E> for Spanned<T>
where
T: SessionDiagnostic<'a, E>,
E: EmissionGuarantee,
{
fn into_diagnostic(self, handler: &'a Handler) -> rustc_errors::DiagnosticBuilder<'a, E> {
let mut diag = self.node.into_diagnostic(handler);
diag.set_span(self.span);
diag
}
}

impl Session {
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
self.miri_unleashed_features.lock().push((span, feature_gate));
Expand Down

0 comments on commit 5c7e629

Please sign in to comment.