2022-08-18 15:51:47 -06:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-06-18 10:35:56 +00:00
|
|
|
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level};
|
2022-09-18 11:46:56 -04:00
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic};
|
2023-08-29 19:29:14 +02:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-18 15:51:47 -06:00
|
|
|
|
2022-10-13 10:13:02 +01:00
|
|
|
use crate::fluent_generated as fluent;
|
2024-07-29 08:13:50 +10:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(monomorphize_recursion_limit)]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct RecursionLimit {
|
2022-08-18 15:51:47 -06:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub shrunk: String,
|
|
|
|
#[note]
|
|
|
|
pub def_span: Span,
|
|
|
|
pub def_path_str: String,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[note(monomorphize_written_to_path)]
|
2024-08-21 00:57:58 -04:00
|
|
|
pub was_written: bool,
|
2022-08-18 15:51:47 -06:00
|
|
|
pub path: PathBuf,
|
|
|
|
}
|
|
|
|
|
2023-08-29 19:29:14 +02:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(monomorphize_no_optimized_mir)]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct NoOptimizedMir {
|
2023-08-29 19:29:14 +02:00
|
|
|
#[note]
|
|
|
|
pub span: Span,
|
|
|
|
pub crate_name: Symbol,
|
|
|
|
}
|
|
|
|
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct UnusedGenericParamsHint {
|
2022-08-18 15:51:47 -06:00
|
|
|
pub span: Span,
|
|
|
|
pub param_spans: Vec<Span>,
|
|
|
|
pub param_names: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2024-03-06 11:02:56 +11:00
|
|
|
impl<G: EmissionGuarantee> Diagnostic<'_, G> for UnusedGenericParamsHint {
|
2022-10-31 16:14:29 +01:00
|
|
|
#[track_caller]
|
2024-06-18 10:35:56 +00:00
|
|
|
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
|
2024-02-23 10:20:45 +11:00
|
|
|
let mut diag = Diag::new(dcx, level, fluent::monomorphize_unused_generic_params);
|
2023-12-24 09:08:41 +11:00
|
|
|
diag.span(self.span);
|
2022-08-18 15:51:47 -06:00
|
|
|
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. 😢
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 16:44:30 +11:00
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
2022-12-19 10:31:55 +01:00
|
|
|
diag.span_label(span, format!("generic parameter `{name}` is unused"));
|
2022-08-18 15:51:47 -06:00
|
|
|
}
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(monomorphize_large_assignments)]
|
2022-08-18 15:51:47 -06:00
|
|
|
#[note]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct LargeAssignmentsLint {
|
2022-08-18 15:51:47 -06:00
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub size: u64,
|
|
|
|
pub limit: u64,
|
|
|
|
}
|
2022-08-23 11:20:01 -06:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(monomorphize_symbol_already_defined)]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct SymbolAlreadyDefined {
|
2022-08-23 11:20:01 -06:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Option<Span>,
|
|
|
|
pub symbol: String,
|
|
|
|
}
|
2022-12-08 19:21:08 +00:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(monomorphize_couldnt_dump_mono_stats)]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct CouldntDumpMonoStats {
|
2022-12-08 19:21:08 +00:00
|
|
|
pub error: String,
|
|
|
|
}
|
2022-08-19 14:48:15 +01:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(monomorphize_encountered_error_while_instantiating)]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct EncounteredErrorWhileInstantiating {
|
2022-08-19 14:48:15 +01:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub formatted_item: String,
|
|
|
|
}
|
|
|
|
|
2023-10-02 12:32:31 +00:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(monomorphize_start_not_found)]
|
|
|
|
#[help]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct StartNotFound;
|
2023-10-02 12:32:31 +00:00
|
|
|
|
2022-08-19 14:48:15 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(monomorphize_unknown_cgu_collection_mode)]
|
2024-08-29 15:08:07 +10:00
|
|
|
pub(crate) struct UnknownCguCollectionMode<'a> {
|
2022-08-19 14:48:15 +01:00
|
|
|
pub mode: &'a str,
|
|
|
|
}
|