Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3812,7 +3812,6 @@ dependencies = [
"rustc_pattern_analysis",
"rustc_privacy",
"rustc_public",
"rustc_query_system",
"rustc_resolve",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -4572,7 +4571,6 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_hashes",
"rustc_hir",
"rustc_index",
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rustc_passes = { path = "../rustc_passes" }
rustc_pattern_analysis = { path = "../rustc_pattern_analysis" }
rustc_privacy = { path = "../rustc_privacy" }
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
rustc_query_system = { path = "../rustc_query_system" }
rustc_resolve = { path = "../rustc_resolve" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_passes::DEFAULT_LOCALE_RESOURCE,
rustc_pattern_analysis::DEFAULT_LOCALE_RESOURCE,
rustc_privacy::DEFAULT_LOCALE_RESOURCE,
rustc_query_system::DEFAULT_LOCALE_RESOURCE,
rustc_resolve::DEFAULT_LOCALE_RESOURCE,
rustc_session::DEFAULT_LOCALE_RESOURCE,
rustc_trait_selection::DEFAULT_LOCALE_RESOURCE,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'a> DiagnosticDerive<'a> {
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
};
messages.borrow_mut().push(message.clone());
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));

let init = quote! {
let mut diag = rustc_errors::Diag::new(
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'a> LintDiagnosticDerive<'a> {
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
};
messages.borrow_mut().push(message.clone());
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
let primary_message = quote! {
diag.primary_message(#message);
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl DiagnosticDeriveVariantBuilder {
applicability.set_once(quote! { #static_applicability }, span);
}

let message = slug.diag_message(variant);
let message = slug.diag_message(Some(variant));
let applicability = applicability
.value()
.unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified });
Expand Down Expand Up @@ -487,7 +487,7 @@ impl DiagnosticDeriveVariantBuilder {
variant: &VariantInfo<'_>,
) -> TokenStream {
let fn_name = format_ident!("span_{}", kind);
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
quote! {
diag.#fn_name(
#field_binding,
Expand All @@ -504,7 +504,7 @@ impl DiagnosticDeriveVariantBuilder {
message: Message,
variant: &VariantInfo<'_>,
) -> TokenStream {
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
quote! {
diag.#kind(#message);
}
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_macros/src/diagnostics/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ pub(crate) enum Message {
}

impl Message {
pub(crate) fn diag_message(&self, variant: &VariantInfo<'_>) -> TokenStream {
/// Get the diagnostic message for this diagnostic
/// The passed `variant` is used to check whether all variables in the message are used.
/// For subdiagnostics, we cannot check this.
pub(crate) fn diag_message(&self, variant: Option<&VariantInfo<'_>>) -> TokenStream {
match self {
Message::Slug(slug) => {
quote! { crate::fluent_generated::#slug }
}
Message::Inline(message_span, message) => {
verify_fluent_message(*message_span, &message, variant);
if let Some(variant) = variant {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite get why this had to change to an option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an edgecase I missed in the initial implementation.
Subdiagnostics can use variables from their parent. Because the #[derive(Subdiagnostic)] cannot see the parent diagnostic, we can't always verify the variables in the subdiagnostic

For example: https://github.com/rust-lang/rust/pull/152041/changes#diff-cd9aee6d8730bdbb5caab22a0b1a07d44c4b64f7e65fc55b044bca9903eeb081R15

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

verify_fluent_message(*message_span, &message, variant);
}
quote! { rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(#message)) }
}
}
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl SubdiagnosticDerive {
has_subdiagnostic: false,
is_enum,
};
builder.into_tokens(variant).unwrap_or_else(|v| v.to_compile_error())
builder.into_tokens().unwrap_or_else(|v| v.to_compile_error())
});

quote! {
Expand Down Expand Up @@ -497,10 +497,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
}
}

pub(crate) fn into_tokens(
&mut self,
variant: &VariantInfo<'_>,
) -> Result<TokenStream, DiagnosticDeriveError> {
pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
let kind_slugs = self.identify_kind()?;

let kind_stats: KindsStatistics = kind_slugs.iter().map(|(kind, _slug)| kind).collect();
Expand Down Expand Up @@ -538,7 +535,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
let mut calls = TokenStream::new();
for (kind, slug) in kind_slugs {
let message = format_ident!("__message");
let message_stream = slug.diag_message(variant);
let message_stream = slug.diag_message(None);
calls.extend(quote! { let #message = #diag.eagerly_translate(#message_stream); });

let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hashes = { path = "../rustc_hashes" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
Expand Down
30 changes: 0 additions & 30 deletions compiler/rustc_query_system/messages.ftl

This file was deleted.

46 changes: 27 additions & 19 deletions compiler/rustc_query_system/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};

#[derive(Subdiagnostic)]
#[note(query_system_cycle_stack_middle)]
#[note("...which requires {$desc}...")]
pub(crate) struct CycleStack {
#[primary_span]
pub span: Span,
Expand All @@ -13,32 +13,34 @@ pub(crate) struct CycleStack {

#[derive(Subdiagnostic)]
pub(crate) enum StackCount {
#[note(query_system_cycle_stack_single)]
#[note("...which immediately requires {$stack_bottom} again")]
Single,
#[note(query_system_cycle_stack_multiple)]
#[note("...which again requires {$stack_bottom}, completing the cycle")]
Multiple,
}

#[derive(Subdiagnostic)]
pub(crate) enum Alias {
#[note(query_system_cycle_recursive_ty_alias)]
#[help(query_system_cycle_recursive_ty_alias_help1)]
#[help(query_system_cycle_recursive_ty_alias_help2)]
#[note("type aliases cannot be recursive")]
#[help("consider using a struct, enum, or union instead to break the cycle")]
#[help(
"see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information"
)]
Ty,
#[note(query_system_cycle_recursive_trait_alias)]
#[note("trait aliases cannot be recursive")]
Trait,
}

#[derive(Subdiagnostic)]
#[note(query_system_cycle_usage)]
#[note("cycle used when {$usage}")]
pub(crate) struct CycleUsage {
#[primary_span]
pub span: Span,
pub usage: String,
}

#[derive(Diagnostic)]
#[diag(query_system_cycle, code = E0391)]
#[diag("cycle detected when {$stack_bottom}", code = E0391)]
pub(crate) struct Cycle {
#[primary_span]
pub span: Span,
Expand All @@ -51,28 +53,34 @@ pub(crate) struct Cycle {
pub alias: Option<Alias>,
#[subdiagnostic]
pub cycle_usage: Option<CycleUsage>,
#[note]
#[note(
"see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information"
)]
pub note_span: (),
}

#[derive(Diagnostic)]
#[diag(query_system_reentrant)]
#[diag("internal compiler error: reentrant incremental verify failure, suppressing message")]
pub(crate) struct Reentrant;

#[derive(Diagnostic)]
#[diag(query_system_increment_compilation)]
#[note(query_system_increment_compilation_note1)]
#[note(query_system_increment_compilation_note2)]
#[note(query_system_increment_compilation_note3)]
#[note(query_system_increment_compilation_note4)]
#[diag("internal compiler error: encountered incremental compilation error with {$dep_node}")]
#[note("please follow the instructions below to create a bug report with the provided information")]
#[note("for incremental compilation bugs, having a reproduction is vital")]
#[note(
"an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again"
)]
#[note("as a workaround, you can run {$run_cmd} to allow your project to compile")]
pub(crate) struct IncrementCompilation {
pub run_cmd: String,
pub dep_node: String,
}

#[derive(Diagnostic)]
#[help]
#[diag(query_system_query_overflow)]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
#[diag("queries overflow the depth limit!")]
pub struct QueryOverflow {
#[primary_span]
pub span: Span,
Expand All @@ -83,7 +91,7 @@ pub struct QueryOverflow {
}

#[derive(Subdiagnostic)]
#[note(query_system_overflow_note)]
#[note("query depth increased by {$depth} when {$desc}")]
pub struct QueryOverflowNote {
pub desc: String,
pub depth: usize,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ mod values;

pub use error::{QueryOverflow, QueryOverflowNote};
pub use values::Value;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
Loading