forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#100730 - CleanCut:diagnostics-rustc_monomor…
…phize, r=davidtwco Migrate rustc_monomorphize to use SessionDiagnostic ### Description - Migrates diagnostics in `rustc_monomorphize` to use `SessionDiagnostic` - Adds an `impl IntoDiagnosticArg for PathBuf` ### TODO / Help! - [x] I'm having trouble figuring out how to apply an optional note. 😕 Help!? - Resolved. It was bad docs. Fixed in https://github.com/rust-lang/rustc-dev-guide/pull/1437/files - [x] `errors:RecursionLimit` should be `#[fatal ...]`, but that doesn't exist so it's `#[error ...]` at the moment. - Maybe I can switch after this is merged in? --> rust-lang#100694 - Or maybe I need to manually implement `SessionDiagnostic` instead of deriving it? - [x] How does one go about converting an error inside of [a call to struct_span_lint_hir](https://github.com/rust-lang/rust/blob/8064a495086c2e63c0ef77e8e82fe3b9b5dc535f/compiler/rustc_monomorphize/src/collector.rs#L917-L927)? - [x] ~What placeholder do you use in the fluent template to refer to the value in a vector? It seems like [this code](https://github.com/rust-lang/rust/blob/0b79f758c9aa6646606662a6d623a0752286cd17/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs#L83-L114) ought to have the answer (or something near it)...but I can't figure it out.~ You can't. Punted.
- Loading branch information
Showing
16 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
compiler/rustc_error_messages/locales/en-US/monomorphize.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
monomorphize_recursion_limit = | ||
reached the recursion limit while instantiating `{$shrunk}` | ||
.note = `{$def_path_str}` defined here | ||
monomorphize_written_to_path = the full type name has been written to '{$path}' | ||
monomorphize_type_length_limit = reached the type-length limit while instantiating `{$shrunk}` | ||
monomorphize_consider_type_length_limit = | ||
consider adding a `#![type_length_limit="{$type_length}"]` attribute to your crate | ||
monomorphize_fatal_error = {$error_message} | ||
monomorphize_unknown_partition_strategy = unknown partitioning strategy | ||
monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined | ||
monomorphize_unused_generic_params = item has unused generic parameters | ||
monomorphize_large_assignments = | ||
moving {$size} bytes | ||
.label = value moved from here | ||
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` | ||
monomorphize_requires_lang_item = | ||
requires `{$lang_item}` lang_item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use crate::LangItem; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)] | ||
pub struct LangItemError(pub LangItem); | ||
|
||
impl ToString for LangItemError { | ||
fn to_string(&self) -> String { | ||
format!("requires `{}` lang_item", self.0.name()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::path::PathBuf; | ||
|
||
use rustc_errors::ErrorGuaranteed; | ||
use rustc_macros::{LintDiagnostic, SessionDiagnostic}; | ||
use rustc_session::SessionDiagnostic; | ||
use rustc_span::Span; | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[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(SessionDiagnostic)] | ||
#[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, | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(monomorphize::requires_lang_item)] | ||
pub struct RequiresLangItem { | ||
pub lang_item: String, | ||
} | ||
|
||
pub struct UnusedGenericParams { | ||
pub span: Span, | ||
pub param_spans: Vec<Span>, | ||
pub param_names: Vec<String>, | ||
} | ||
|
||
impl SessionDiagnostic<'_> for UnusedGenericParams { | ||
fn into_diagnostic( | ||
self, | ||
sess: &'_ rustc_session::parse::ParseSess, | ||
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { | ||
let mut diag = sess.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(SessionDiagnostic)] | ||
#[diag(monomorphize::unknown_partition_strategy)] | ||
pub struct UnknownPartitionStrategy; | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(monomorphize::symbol_already_defined)] | ||
pub struct SymbolAlreadyDefined { | ||
#[primary_span] | ||
pub span: Option<Span>, | ||
pub symbol: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.