mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00

Track where diagnostics were created. This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`. For example, the following code... ```rust struct A; struct B; fn main(){ let _: A = B; } ``` ...now emits the following error message: ``` error[E0308]: mismatched types --> src\main.rs:5:16 | 5 | let _: A = B; | - ^ expected struct `A`, found struct `B` | | | expected due to this -Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31 ```
80 lines
2.1 KiB
Rust
80 lines
2.1 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use rustc_errors::ErrorGuaranteed;
|
|
use rustc_errors::IntoDiagnostic;
|
|
use rustc_macros::{Diagnostic, LintDiagnostic};
|
|
use rustc_span::Span;
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(monomorphize_recursion_limit)]
|
|
pub struct RecursionLimit {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
pub shrunk: String,
|
|
#[note]
|
|
pub def_span: Span,
|
|
pub def_path_str: String,
|
|
#[note(monomorphize_written_to_path)]
|
|
pub was_written: Option<()>,
|
|
pub path: PathBuf,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(monomorphize_type_length_limit)]
|
|
#[help(monomorphize_consider_type_length_limit)]
|
|
pub struct TypeLengthLimit {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
pub shrunk: String,
|
|
#[note(monomorphize_written_to_path)]
|
|
pub was_written: Option<()>,
|
|
pub path: PathBuf,
|
|
pub type_length: usize,
|
|
}
|
|
|
|
pub struct UnusedGenericParams {
|
|
pub span: Span,
|
|
pub param_spans: Vec<Span>,
|
|
pub param_names: Vec<String>,
|
|
}
|
|
|
|
impl IntoDiagnostic<'_> for UnusedGenericParams {
|
|
#[track_caller]
|
|
fn into_diagnostic(
|
|
self,
|
|
handler: &'_ rustc_errors::Handler,
|
|
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
|
|
let mut diag = handler.struct_err(rustc_errors::fluent::monomorphize_unused_generic_params);
|
|
diag.set_span(self.span);
|
|
for (span, name) in self.param_spans.into_iter().zip(self.param_names) {
|
|
// FIXME: I can figure out how to do a label with a fluent string with a fixed message,
|
|
// or a label with a dynamic value in a hard-coded string, but I haven't figured out
|
|
// how to combine the two. 😢
|
|
diag.span_label(span, format!("generic parameter `{}` is unused", name));
|
|
}
|
|
diag
|
|
}
|
|
}
|
|
|
|
#[derive(LintDiagnostic)]
|
|
#[diag(monomorphize_large_assignments)]
|
|
#[note]
|
|
pub struct LargeAssignmentsLint {
|
|
#[label]
|
|
pub span: Span,
|
|
pub size: u64,
|
|
pub limit: u64,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(monomorphize_unknown_partition_strategy)]
|
|
pub struct UnknownPartitionStrategy;
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(monomorphize_symbol_already_defined)]
|
|
pub struct SymbolAlreadyDefined {
|
|
#[primary_span]
|
|
pub span: Option<Span>,
|
|
pub symbol: String,
|
|
}
|