-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Migrate rustc_monomorphize to use SessionDiagnostic #100730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 9 commits into
rust-lang:master
from
CleanCut:diagnostics-rustc_monomorphize
Aug 31, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
137f20c
rebased: convert rustc_monomorphize errors to SessionDiagnostic
CleanCut 40f4473
replace some usages of [Span]FatalError with error-specific types
CleanCut 33cbbc2
remove stray comment
CleanCut e914247
bless the change in note/help order due to migrating to SessionDiagno…
CleanCut 30c7506
allow non-monomorphize modules to access hard-coded error message thr…
CleanCut 6cdfdd0
adjust to new error value
CleanCut 82d609c
have LangItemError derive everything LangItem does
CleanCut a19139f
remove unnecessary comment
CleanCut 845d567
revert src/tools/cargo submodule to where it ought to be from where w…
CleanCut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); | ||
davidtwco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)); | ||
davidtwco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.