2022-09-14 23:01:44 -05:00
|
|
|
use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
|
2022-09-18 10:46:56 -05:00
|
|
|
use rustc_macros::Diagnostic;
|
2022-09-22 05:34:23 -05:00
|
|
|
use rustc_middle::ty::{self, PolyTraitRef, Ty};
|
2022-08-26 13:08:58 -05:00
|
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(trait_selection_dump_vtable_entries)]
|
2022-08-26 13:08:58 -05:00
|
|
|
pub struct DumpVTableEntries<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub trait_ref: PolyTraitRef<'a>,
|
|
|
|
pub entries: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(trait_selection_unable_to_construct_constant_value)]
|
2022-08-26 13:08:58 -05:00
|
|
|
pub struct UnableToConstructConstantValue<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-09-22 05:34:23 -05:00
|
|
|
pub unevaluated: ty::UnevaluatedConst<'a>,
|
2022-08-26 13:08:58 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(trait_selection_empty_on_clause_in_rustc_on_unimplemented, code = "E0232")]
|
2022-08-26 13:08:58 -05:00
|
|
|
pub struct EmptyOnClauseInOnUnimplemented {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(trait_selection_invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")]
|
2022-08-26 13:08:58 -05:00
|
|
|
pub struct InvalidOnClauseInOnUnimplemented {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(trait_selection_no_value_in_rustc_on_unimplemented, code = "E0232")]
|
2022-08-26 13:08:58 -05:00
|
|
|
#[note]
|
|
|
|
pub struct NoValueInOnUnimplemented {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-11-09 22:21:11 -06:00
|
|
|
pub struct NegativePositiveConflict<'tcx> {
|
2022-08-26 13:08:58 -05:00
|
|
|
pub impl_span: Span,
|
2022-11-09 22:21:11 -06:00
|
|
|
pub trait_desc: ty::TraitRef<'tcx>,
|
|
|
|
pub self_ty: Option<Ty<'tcx>>,
|
2022-08-26 13:08:58 -05:00
|
|
|
pub negative_impl_span: Result<Span, Symbol>,
|
|
|
|
pub positive_impl_span: Result<Span, Symbol>,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:45:41 -05:00
|
|
|
impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> {
|
2022-10-31 10:14:29 -05:00
|
|
|
#[track_caller]
|
2022-08-26 13:08:58 -05:00
|
|
|
fn into_diagnostic(
|
|
|
|
self,
|
2022-09-04 23:15:50 -05:00
|
|
|
handler: &Handler,
|
2022-08-26 13:08:58 -05:00
|
|
|
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
|
2022-10-22 04:07:54 -05:00
|
|
|
let mut diag = handler.struct_err(fluent::trait_selection_negative_positive_conflict);
|
2022-11-09 22:21:11 -06:00
|
|
|
diag.set_arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
|
2022-08-26 13:08:58 -05:00
|
|
|
diag.set_arg(
|
|
|
|
"self_desc",
|
2022-11-09 22:21:11 -06:00
|
|
|
self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()),
|
2022-08-26 13:08:58 -05:00
|
|
|
);
|
|
|
|
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);
|
2022-08-26 13:08:58 -05:00
|
|
|
}
|
|
|
|
Err(cname) => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.note(fluent::negative_implementation_in_crate);
|
2022-08-26 13:08:58 -05:00
|
|
|
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);
|
2022-08-26 13:08:58 -05:00
|
|
|
}
|
|
|
|
Err(cname) => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.note(fluent::positive_implementation_in_crate);
|
2022-08-26 13:08:58 -05:00
|
|
|
diag.set_arg("positive_impl_cname", cname.to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|