rust/compiler/rustc_trait_selection/src/errors.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.7 KiB
Rust
Raw Normal View History

use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_macros::Diagnostic;
2022-09-22 05:34:23 -05:00
use rustc_middle::ty::{self, PolyTraitRef, Ty};
use rustc_span::{Span, Symbol};
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(trait_selection_dump_vtable_entries)]
pub struct DumpVTableEntries<'a> {
#[primary_span]
pub span: Span,
pub trait_ref: PolyTraitRef<'a>,
pub entries: String,
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(trait_selection_unable_to_construct_constant_value)]
pub struct UnableToConstructConstantValue<'a> {
#[primary_span]
pub span: Span,
2022-09-22 05:34:23 -05:00
pub unevaluated: ty::UnevaluatedConst<'a>,
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(trait_selection_empty_on_clause_in_rustc_on_unimplemented, code = "E0232")]
pub struct EmptyOnClauseInOnUnimplemented {
#[primary_span]
#[label]
pub span: Span,
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(trait_selection_invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")]
pub struct InvalidOnClauseInOnUnimplemented {
#[primary_span]
#[label]
pub span: Span,
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(trait_selection_no_value_in_rustc_on_unimplemented, code = "E0232")]
#[note]
pub struct NoValueInOnUnimplemented {
#[primary_span]
#[label]
pub span: Span,
}
pub struct NegativePositiveConflict<'tcx> {
pub impl_span: Span,
pub trait_desc: ty::TraitRef<'tcx>,
pub self_ty: Option<Ty<'tcx>>,
pub negative_impl_span: Result<Span, Symbol>,
pub positive_impl_span: Result<Span, Symbol>,
}
impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> {
2022-10-31 10:14:29 -05:00
#[track_caller]
fn into_diagnostic(
self,
handler: &Handler,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
2022-10-22 04:07:54 -05:00
let mut diag = handler.struct_err(fluent::trait_selection_negative_positive_conflict);
diag.set_arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
diag.set_arg(
"self_desc",
self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()),
);
diag.set_span(self.impl_span);
diag.code(rustc_errors::error_code!(E0751));
match self.negative_impl_span {
Ok(span) => {
2022-10-22 04:07:54 -05:00
diag.span_label(span, fluent::negative_implementation_here);
}
Err(cname) => {
2022-10-22 04:07:54 -05:00
diag.note(fluent::negative_implementation_in_crate);
diag.set_arg("negative_impl_cname", cname.to_string());
}
}
match self.positive_impl_span {
Ok(span) => {
2022-10-22 04:07:54 -05:00
diag.span_label(span, fluent::positive_implementation_here);
}
Err(cname) => {
2022-10-22 04:07:54 -05:00
diag.note(fluent::positive_implementation_in_crate);
diag.set_arg("positive_impl_cname", cname.to_string());
}
}
diag
}
}