Rollup merge of #100844 - evopen:migrate-diag, r=davidtwco
migrate rustc_query_system to use SessionDiagnostic issues: * variable list is not supported in fluent * ~~cannot have two sub diagnostic with the same tag (eg. 2 .note or 2 .help)~~ allow multiple tag with SessionSubdiagnostic derive
This commit is contained in:
commit
22c5c83a68
10 changed files with 487 additions and 816 deletions
25
compiler/rustc_error_messages/locales/en-US/query_system.ftl
Normal file
25
compiler/rustc_error_messages/locales/en-US/query_system.ftl
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
query_system_reentrant = internal compiler error: re-entrant incremental verify failure, suppressing message
|
||||||
|
|
||||||
|
query_system_increment_compilation = internal compiler error: encountered incremental compilation error with {$dep_node}
|
||||||
|
.help = This is a known issue with the compiler. Run {$run_cmd} to allow your project to compile
|
||||||
|
|
||||||
|
query_system_increment_compilation_note1 = Please follow the instructions below to create a bug report with the provided information
|
||||||
|
query_system_increment_compilation_note2 = See <https://github.com/rust-lang/rust/issues/84970> for more information
|
||||||
|
|
||||||
|
query_system_cycle = cycle detected when {$stack_bottom}
|
||||||
|
|
||||||
|
query_system_cycle_usage = cycle used when {$usage}
|
||||||
|
|
||||||
|
query_system_cycle_stack_single = ...which immediately requires {$stack_bottom} again
|
||||||
|
|
||||||
|
query_system_cycle_stack_multiple = ...which again requires {$stack_bottom}, completing the cycle
|
||||||
|
|
||||||
|
query_system_cycle_recursive_ty_alias = type aliases cannot be recursive
|
||||||
|
query_system_cycle_recursive_ty_alias_help1 = consider using a struct, enum, or union instead to break the cycle
|
||||||
|
query_system_cycle_recursive_ty_alias_help2 = see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
|
||||||
|
|
||||||
|
query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
|
||||||
|
|
||||||
|
query_system_cycle_which_requires = ...which requires {$desc}...
|
||||||
|
|
||||||
|
query_system_query_overflow = queries overflow the depth limit!
|
|
@ -50,6 +50,7 @@ fluent_messages! {
|
||||||
passes => "../locales/en-US/passes.ftl",
|
passes => "../locales/en-US/passes.ftl",
|
||||||
plugin_impl => "../locales/en-US/plugin_impl.ftl",
|
plugin_impl => "../locales/en-US/plugin_impl.ftl",
|
||||||
privacy => "../locales/en-US/privacy.ftl",
|
privacy => "../locales/en-US/privacy.ftl",
|
||||||
|
query_system => "../locales/en-US/query_system.ftl",
|
||||||
save_analysis => "../locales/en-US/save_analysis.ftl",
|
save_analysis => "../locales/en-US/save_analysis.ftl",
|
||||||
ty_utils => "../locales/en-US/ty_utils.ftl",
|
ty_utils => "../locales/en-US/ty_utils.ftl",
|
||||||
typeck => "../locales/en-US/typeck.ftl",
|
typeck => "../locales/en-US/typeck.ftl",
|
||||||
|
|
|
@ -12,7 +12,7 @@ use quote::{format_ident, quote};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use syn::{spanned::Spanned, Attribute, Meta, MetaList, MetaNameValue, NestedMeta, Path};
|
use syn::{spanned::Spanned, Meta, MetaList, MetaNameValue, NestedMeta, Path};
|
||||||
use synstructure::{BindingInfo, Structure, VariantInfo};
|
use synstructure::{BindingInfo, Structure, VariantInfo};
|
||||||
|
|
||||||
/// Which kind of suggestion is being created?
|
/// Which kind of suggestion is being created?
|
||||||
|
@ -28,41 +28,8 @@ enum SubdiagnosticSuggestionKind {
|
||||||
Verbose,
|
Verbose,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for SubdiagnosticSuggestionKind {
|
|
||||||
type Err = ();
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match s {
|
|
||||||
"" => Ok(SubdiagnosticSuggestionKind::Normal),
|
|
||||||
"_short" => Ok(SubdiagnosticSuggestionKind::Short),
|
|
||||||
"_hidden" => Ok(SubdiagnosticSuggestionKind::Hidden),
|
|
||||||
"_verbose" => Ok(SubdiagnosticSuggestionKind::Verbose),
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubdiagnosticSuggestionKind {
|
|
||||||
pub fn to_suggestion_style(&self) -> TokenStream {
|
|
||||||
match self {
|
|
||||||
SubdiagnosticSuggestionKind::Normal => {
|
|
||||||
quote! { rustc_errors::SuggestionStyle::ShowCode }
|
|
||||||
}
|
|
||||||
SubdiagnosticSuggestionKind::Short => {
|
|
||||||
quote! { rustc_errors::SuggestionStyle::HideCodeInline }
|
|
||||||
}
|
|
||||||
SubdiagnosticSuggestionKind::Hidden => {
|
|
||||||
quote! { rustc_errors::SuggestionStyle::HideCodeAlways }
|
|
||||||
}
|
|
||||||
SubdiagnosticSuggestionKind::Verbose => {
|
|
||||||
quote! { rustc_errors::SuggestionStyle::ShowAlways }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Which kind of subdiagnostic is being created from a variant?
|
/// Which kind of subdiagnostic is being created from a variant?
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy)]
|
||||||
enum SubdiagnosticKind {
|
enum SubdiagnosticKind {
|
||||||
/// `#[label(...)]`
|
/// `#[label(...)]`
|
||||||
Label,
|
Label,
|
||||||
|
@ -73,9 +40,31 @@ enum SubdiagnosticKind {
|
||||||
/// `#[warning(...)]`
|
/// `#[warning(...)]`
|
||||||
Warn,
|
Warn,
|
||||||
/// `#[suggestion{,_short,_hidden,_verbose}]`
|
/// `#[suggestion{,_short,_hidden,_verbose}]`
|
||||||
Suggestion { suggestion_kind: SubdiagnosticSuggestionKind, code: TokenStream },
|
Suggestion(SubdiagnosticSuggestionKind),
|
||||||
/// `#[multipart_suggestion{,_short,_hidden,_verbose}]`
|
}
|
||||||
MultipartSuggestion { suggestion_kind: SubdiagnosticSuggestionKind },
|
|
||||||
|
impl FromStr for SubdiagnosticKind {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"label" => Ok(SubdiagnosticKind::Label),
|
||||||
|
"note" => Ok(SubdiagnosticKind::Note),
|
||||||
|
"help" => Ok(SubdiagnosticKind::Help),
|
||||||
|
"warning" => Ok(SubdiagnosticKind::Warn),
|
||||||
|
"suggestion" => Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Normal)),
|
||||||
|
"suggestion_short" => {
|
||||||
|
Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Short))
|
||||||
|
}
|
||||||
|
"suggestion_hidden" => {
|
||||||
|
Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Hidden))
|
||||||
|
}
|
||||||
|
"suggestion_verbose" => {
|
||||||
|
Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Verbose))
|
||||||
|
}
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quote::IdentFragment for SubdiagnosticKind {
|
impl quote::IdentFragment for SubdiagnosticKind {
|
||||||
|
@ -85,9 +74,17 @@ impl quote::IdentFragment for SubdiagnosticKind {
|
||||||
SubdiagnosticKind::Note => write!(f, "note"),
|
SubdiagnosticKind::Note => write!(f, "note"),
|
||||||
SubdiagnosticKind::Help => write!(f, "help"),
|
SubdiagnosticKind::Help => write!(f, "help"),
|
||||||
SubdiagnosticKind::Warn => write!(f, "warn"),
|
SubdiagnosticKind::Warn => write!(f, "warn"),
|
||||||
SubdiagnosticKind::Suggestion { .. } => write!(f, "suggestion_with_style"),
|
SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Normal) => {
|
||||||
SubdiagnosticKind::MultipartSuggestion { .. } => {
|
write!(f, "suggestion")
|
||||||
write!(f, "multipart_suggestion_with_style")
|
}
|
||||||
|
SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Short) => {
|
||||||
|
write!(f, "suggestion_short")
|
||||||
|
}
|
||||||
|
SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Hidden) => {
|
||||||
|
write!(f, "suggestion_hidden")
|
||||||
|
}
|
||||||
|
SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Verbose) => {
|
||||||
|
write!(f, "suggestion_verbose")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,9 +148,11 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
|
||||||
variant,
|
variant,
|
||||||
span,
|
span,
|
||||||
fields: fields_map,
|
fields: fields_map,
|
||||||
|
kinds: Vec::new(),
|
||||||
|
slugs: Vec::new(),
|
||||||
|
code: None,
|
||||||
span_field: None,
|
span_field: None,
|
||||||
applicability: None,
|
applicability: None,
|
||||||
has_suggestion_parts: false,
|
|
||||||
};
|
};
|
||||||
builder.into_tokens().unwrap_or_else(|v| v.to_compile_error())
|
builder.into_tokens().unwrap_or_else(|v| v.to_compile_error())
|
||||||
});
|
});
|
||||||
|
@ -194,15 +193,21 @@ struct SessionSubdiagnosticDeriveBuilder<'a> {
|
||||||
/// derive builder.
|
/// derive builder.
|
||||||
fields: HashMap<String, TokenStream>,
|
fields: HashMap<String, TokenStream>,
|
||||||
|
|
||||||
|
/// Subdiagnostic kind of the type/variant.
|
||||||
|
kinds: Vec<(SubdiagnosticKind, proc_macro::Span)>,
|
||||||
|
|
||||||
|
/// Slugs of the subdiagnostic - corresponds to the Fluent identifier for the message - from the
|
||||||
|
/// `#[kind(slug)]` attribute on the type or variant.
|
||||||
|
slugs: Vec<(Path, proc_macro::Span)>,
|
||||||
|
/// If a suggestion, the code to suggest as a replacement - from the `#[kind(code = "...")]`
|
||||||
|
/// attribute on the type or variant.
|
||||||
|
code: Option<(TokenStream, proc_macro::Span)>,
|
||||||
|
|
||||||
/// Identifier for the binding to the `#[primary_span]` field.
|
/// Identifier for the binding to the `#[primary_span]` field.
|
||||||
span_field: Option<(proc_macro2::Ident, proc_macro::Span)>,
|
span_field: Option<(proc_macro2::Ident, proc_macro::Span)>,
|
||||||
/// If a suggestion, the identifier for the binding to the `#[applicability]` field or a
|
/// If a suggestion, the identifier for the binding to the `#[applicability]` field or a
|
||||||
/// `rustc_errors::Applicability::*` variant directly.
|
/// `rustc_errors::Applicability::*` variant directly.
|
||||||
applicability: Option<(TokenStream, proc_macro::Span)>,
|
applicability: Option<(TokenStream, proc_macro::Span)>,
|
||||||
|
|
||||||
/// Set to true when a `#[suggestion_part]` field is encountered, used to generate an error
|
|
||||||
/// during finalization if still `false`.
|
|
||||||
has_suggestion_parts: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> {
|
impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> {
|
||||||
|
@ -212,133 +217,124 @@ impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
|
impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
|
||||||
fn identify_kind(
|
fn identify_kind(&mut self) -> Result<(), DiagnosticDeriveError> {
|
||||||
&mut self,
|
for (i, attr) in self.variant.ast().attrs.iter().enumerate() {
|
||||||
) -> Result<Option<(SubdiagnosticKind, Path)>, DiagnosticDeriveError> {
|
|
||||||
let mut kind_slug = None;
|
|
||||||
|
|
||||||
for attr in self.variant.ast().attrs {
|
|
||||||
let span = attr.span().unwrap();
|
let span = attr.span().unwrap();
|
||||||
|
|
||||||
let name = attr.path.segments.last().unwrap().ident.to_string();
|
let name = attr.path.segments.last().unwrap().ident.to_string();
|
||||||
let name = name.as_str();
|
let name = name.as_str();
|
||||||
|
|
||||||
let meta = attr.parse_meta()?;
|
let meta = attr.parse_meta()?;
|
||||||
let Meta::List(MetaList { ref nested, .. }) = meta else {
|
let kind = match meta {
|
||||||
throw_invalid_attr!(attr, &meta);
|
Meta::List(MetaList { ref nested, .. }) => {
|
||||||
};
|
let mut nested_iter = nested.into_iter();
|
||||||
|
if let Some(nested_attr) = nested_iter.next() {
|
||||||
let mut kind = match name {
|
match nested_attr {
|
||||||
"label" => SubdiagnosticKind::Label,
|
NestedMeta::Meta(Meta::Path(path)) => {
|
||||||
"note" => SubdiagnosticKind::Note,
|
self.slugs.push((path.clone(), span));
|
||||||
"help" => SubdiagnosticKind::Help,
|
}
|
||||||
"warning" => SubdiagnosticKind::Warn,
|
NestedMeta::Meta(meta @ Meta::NameValue(_))
|
||||||
_ => {
|
if matches!(
|
||||||
if let Some(suggestion_kind) =
|
meta.path().segments.last().unwrap().ident.to_string().as_str(),
|
||||||
name.strip_prefix("suggestion").and_then(|s| s.parse().ok())
|
"code" | "applicability"
|
||||||
{
|
) =>
|
||||||
SubdiagnosticKind::Suggestion { suggestion_kind, code: TokenStream::new() }
|
{
|
||||||
} else if let Some(suggestion_kind) =
|
// don't error for valid follow-up attributes
|
||||||
name.strip_prefix("multipart_suggestion").and_then(|s| s.parse().ok())
|
}
|
||||||
{
|
nested_attr => {
|
||||||
SubdiagnosticKind::MultipartSuggestion { suggestion_kind }
|
throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
||||||
} else {
|
diag.help(
|
||||||
throw_invalid_attr!(attr, &meta);
|
"first argument of the attribute should be the diagnostic \
|
||||||
|
slug",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut slug = None;
|
for nested_attr in nested_iter {
|
||||||
let mut code = None;
|
let meta = match nested_attr {
|
||||||
|
NestedMeta::Meta(ref meta) => meta,
|
||||||
|
_ => throw_invalid_nested_attr!(attr, &nested_attr),
|
||||||
|
};
|
||||||
|
|
||||||
let mut nested_iter = nested.into_iter();
|
let span = meta.span().unwrap();
|
||||||
if let Some(nested_attr) = nested_iter.next() {
|
let nested_name = meta.path().segments.last().unwrap().ident.to_string();
|
||||||
match nested_attr {
|
let nested_name = nested_name.as_str();
|
||||||
NestedMeta::Meta(Meta::Path(path)) => {
|
|
||||||
slug.set_once((path.clone(), span));
|
|
||||||
}
|
|
||||||
NestedMeta::Meta(meta @ Meta::NameValue(_))
|
|
||||||
if matches!(
|
|
||||||
meta.path().segments.last().unwrap().ident.to_string().as_str(),
|
|
||||||
"code" | "applicability"
|
|
||||||
) =>
|
|
||||||
{
|
|
||||||
// Don't error for valid follow-up attributes.
|
|
||||||
}
|
|
||||||
nested_attr => {
|
|
||||||
throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
|
||||||
diag.help(
|
|
||||||
"first argument of the attribute should be the diagnostic \
|
|
||||||
slug",
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for nested_attr in nested_iter {
|
match meta {
|
||||||
let meta = match nested_attr {
|
Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(s), .. }) => {
|
||||||
NestedMeta::Meta(ref meta) => meta,
|
match nested_name {
|
||||||
_ => throw_invalid_nested_attr!(attr, &nested_attr),
|
"code" => {
|
||||||
};
|
let formatted_str = self.build_format(&s.value(), s.span());
|
||||||
|
self.code.set_once((formatted_str, span));
|
||||||
let span = meta.span().unwrap();
|
}
|
||||||
let nested_name = meta.path().segments.last().unwrap().ident.to_string();
|
"applicability" => {
|
||||||
let nested_name = nested_name.as_str();
|
let value = match Applicability::from_str(&s.value()) {
|
||||||
|
Ok(v) => v,
|
||||||
let value = match meta {
|
Err(()) => {
|
||||||
Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(value), .. }) => value,
|
span_err(span, "invalid applicability").emit();
|
||||||
Meta::Path(_) => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
Applicability::Unspecified
|
||||||
diag.help("a diagnostic slug must be the first argument to the attribute")
|
}
|
||||||
}),
|
};
|
||||||
_ => throw_invalid_nested_attr!(attr, &nested_attr),
|
self.applicability.set_once((quote! { #value }, span));
|
||||||
};
|
}
|
||||||
|
_ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
||||||
match nested_name {
|
diag.help(
|
||||||
"code" => {
|
"only `code` and `applicability` are valid nested \
|
||||||
if matches!(kind, SubdiagnosticKind::Suggestion { .. }) {
|
attributes",
|
||||||
let formatted_str = self.build_format(&value.value(), value.span());
|
)
|
||||||
code.set_once((formatted_str, span));
|
}),
|
||||||
} else {
|
}
|
||||||
span_err(
|
}
|
||||||
span,
|
_ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
||||||
&format!(
|
if matches!(meta, Meta::Path(_)) {
|
||||||
"`code` is not a valid nested attribute of a `{}` attribute",
|
diag.help(
|
||||||
name
|
"a diagnostic slug must be the first argument to the \
|
||||||
),
|
attribute",
|
||||||
)
|
)
|
||||||
.emit();
|
} else {
|
||||||
|
diag
|
||||||
|
}
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"applicability" => {
|
|
||||||
if matches!(
|
let Ok(kind) = SubdiagnosticKind::from_str(name) else {
|
||||||
kind,
|
throw_invalid_attr!(attr, &meta)
|
||||||
SubdiagnosticKind::Suggestion { .. }
|
};
|
||||||
| SubdiagnosticKind::MultipartSuggestion { .. }
|
|
||||||
) {
|
kind
|
||||||
let value =
|
|
||||||
Applicability::from_str(&value.value()).unwrap_or_else(|()| {
|
|
||||||
span_err(span, "invalid applicability").emit();
|
|
||||||
Applicability::Unspecified
|
|
||||||
});
|
|
||||||
self.applicability.set_once((quote! { #value }, span));
|
|
||||||
} else {
|
|
||||||
span_err(
|
|
||||||
span,
|
|
||||||
&format!(
|
|
||||||
"`applicability` is not a valid nested attribute of a `{}` attribute",
|
|
||||||
name
|
|
||||||
)
|
|
||||||
).emit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
|
||||||
diag.help("only `code` and `applicability` are valid nested attributes")
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
_ => throw_invalid_attr!(attr, &meta),
|
||||||
|
};
|
||||||
|
|
||||||
|
if matches!(
|
||||||
|
kind,
|
||||||
|
SubdiagnosticKind::Label | SubdiagnosticKind::Help | SubdiagnosticKind::Note
|
||||||
|
) && self.code.is_some()
|
||||||
|
{
|
||||||
|
throw_span_err!(
|
||||||
|
span,
|
||||||
|
&format!("`code` is not a valid nested attribute of a `{}` attribute", name)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some((slug, _)) = slug else {
|
if matches!(
|
||||||
|
kind,
|
||||||
|
SubdiagnosticKind::Label | SubdiagnosticKind::Help | SubdiagnosticKind::Note
|
||||||
|
) && self.applicability.is_some()
|
||||||
|
{
|
||||||
|
throw_span_err!(
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"`applicability` is not a valid nested attribute of a `{}` attribute",
|
||||||
|
name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.slugs.len() != i + 1 {
|
||||||
throw_span_err!(
|
throw_span_err!(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
|
@ -346,338 +342,146 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
match kind {
|
|
||||||
SubdiagnosticKind::Suggestion { code: ref mut code_field, .. } => {
|
|
||||||
let Some((code, _)) = code else {
|
|
||||||
throw_span_err!(span, "suggestion without `code = \"...\"`");
|
|
||||||
};
|
|
||||||
*code_field = code;
|
|
||||||
}
|
|
||||||
SubdiagnosticKind::Label
|
|
||||||
| SubdiagnosticKind::Note
|
|
||||||
| SubdiagnosticKind::Help
|
|
||||||
| SubdiagnosticKind::Warn
|
|
||||||
| SubdiagnosticKind::MultipartSuggestion { .. } => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kind_slug.set_once(((kind, slug), span))
|
self.kinds.push((kind, span));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(kind_slug.map(|(kind_slug, _)| kind_slug))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the code for a field with no attributes.
|
fn generate_field_code(
|
||||||
fn generate_field_set_arg(&mut self, binding: &BindingInfo<'_>) -> TokenStream {
|
&mut self,
|
||||||
|
binding: &BindingInfo<'_>,
|
||||||
|
have_suggestion: bool,
|
||||||
|
) -> Result<TokenStream, DiagnosticDeriveError> {
|
||||||
let ast = binding.ast();
|
let ast = binding.ast();
|
||||||
assert_eq!(ast.attrs.len(), 0, "field with attribute used as diagnostic arg");
|
|
||||||
|
let inner_ty = FieldInnerTy::from_type(&ast.ty);
|
||||||
|
let info = FieldInfo {
|
||||||
|
binding: binding,
|
||||||
|
ty: inner_ty.inner_type().unwrap_or(&ast.ty),
|
||||||
|
span: &ast.span(),
|
||||||
|
};
|
||||||
|
|
||||||
|
for attr in &ast.attrs {
|
||||||
|
let name = attr.path.segments.last().unwrap().ident.to_string();
|
||||||
|
let name = name.as_str();
|
||||||
|
let span = attr.span().unwrap();
|
||||||
|
|
||||||
|
let meta = attr.parse_meta()?;
|
||||||
|
match meta {
|
||||||
|
Meta::Path(_) => match name {
|
||||||
|
"primary_span" => {
|
||||||
|
report_error_if_not_applied_to_span(attr, &info)?;
|
||||||
|
self.span_field.set_once((binding.binding.clone(), span));
|
||||||
|
return Ok(quote! {});
|
||||||
|
}
|
||||||
|
"applicability" if have_suggestion => {
|
||||||
|
report_error_if_not_applied_to_applicability(attr, &info)?;
|
||||||
|
let binding = binding.binding.clone();
|
||||||
|
self.applicability.set_once((quote! { #binding }, span));
|
||||||
|
return Ok(quote! {});
|
||||||
|
}
|
||||||
|
"applicability" => {
|
||||||
|
span_err(span, "`#[applicability]` is only valid on suggestions").emit();
|
||||||
|
return Ok(quote! {});
|
||||||
|
}
|
||||||
|
"skip_arg" => {
|
||||||
|
return Ok(quote! {});
|
||||||
|
}
|
||||||
|
_ => throw_invalid_attr!(attr, &meta, |diag| {
|
||||||
|
diag.help(
|
||||||
|
"only `primary_span`, `applicability` and `skip_arg` are valid field \
|
||||||
|
attributes",
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
_ => throw_invalid_attr!(attr, &meta),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let ident = ast.ident.as_ref().unwrap();
|
||||||
|
|
||||||
let diag = &self.diag;
|
let diag = &self.diag;
|
||||||
let ident = ast.ident.as_ref().unwrap();
|
let generated = quote! {
|
||||||
quote! {
|
|
||||||
#diag.set_arg(
|
#diag.set_arg(
|
||||||
stringify!(#ident),
|
stringify!(#ident),
|
||||||
#binding
|
#binding
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Ok(inner_ty.with(binding, generated))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the necessary code for all attributes on a field.
|
fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
|
||||||
fn generate_field_attr_code(
|
self.identify_kind()?;
|
||||||
&mut self,
|
if self.kinds.is_empty() {
|
||||||
binding: &BindingInfo<'_>,
|
|
||||||
kind: &SubdiagnosticKind,
|
|
||||||
) -> TokenStream {
|
|
||||||
let ast = binding.ast();
|
|
||||||
assert!(ast.attrs.len() > 0, "field without attributes generating attr code");
|
|
||||||
|
|
||||||
// Abstract over `Vec<T>` and `Option<T>` fields using `FieldInnerTy`, which will
|
|
||||||
// apply the generated code on each element in the `Vec` or `Option`.
|
|
||||||
let inner_ty = FieldInnerTy::from_type(&ast.ty);
|
|
||||||
ast.attrs
|
|
||||||
.iter()
|
|
||||||
.map(|attr| {
|
|
||||||
let info = FieldInfo {
|
|
||||||
binding,
|
|
||||||
ty: inner_ty.inner_type().unwrap_or(&ast.ty),
|
|
||||||
span: &ast.span(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let generated = self
|
|
||||||
.generate_field_code_inner(kind, attr, info)
|
|
||||||
.unwrap_or_else(|v| v.to_compile_error());
|
|
||||||
|
|
||||||
inner_ty.with(binding, generated)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_field_code_inner(
|
|
||||||
&mut self,
|
|
||||||
kind: &SubdiagnosticKind,
|
|
||||||
attr: &Attribute,
|
|
||||||
info: FieldInfo<'_>,
|
|
||||||
) -> Result<TokenStream, DiagnosticDeriveError> {
|
|
||||||
let meta = attr.parse_meta()?;
|
|
||||||
match meta {
|
|
||||||
Meta::Path(path) => self.generate_field_code_inner_path(kind, attr, info, path),
|
|
||||||
Meta::List(list @ MetaList { .. }) => {
|
|
||||||
self.generate_field_code_inner_list(kind, attr, info, list)
|
|
||||||
}
|
|
||||||
_ => throw_invalid_attr!(attr, &meta),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generates the code for a `[Meta::Path]`-like attribute on a field (e.g. `#[primary_span]`).
|
|
||||||
fn generate_field_code_inner_path(
|
|
||||||
&mut self,
|
|
||||||
kind: &SubdiagnosticKind,
|
|
||||||
attr: &Attribute,
|
|
||||||
info: FieldInfo<'_>,
|
|
||||||
path: Path,
|
|
||||||
) -> Result<TokenStream, DiagnosticDeriveError> {
|
|
||||||
let span = attr.span().unwrap();
|
|
||||||
let ident = &path.segments.last().unwrap().ident;
|
|
||||||
let name = ident.to_string();
|
|
||||||
let name = name.as_str();
|
|
||||||
|
|
||||||
match name {
|
|
||||||
"skip_arg" => Ok(quote! {}),
|
|
||||||
"primary_span" => {
|
|
||||||
if matches!(kind, SubdiagnosticKind::MultipartSuggestion { .. }) {
|
|
||||||
throw_invalid_attr!(attr, &Meta::Path(path), |diag| {
|
|
||||||
diag.help(
|
|
||||||
"multipart suggestions use one or more `#[suggestion_part]`s rather \
|
|
||||||
than one `#[primary_span]`",
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
report_error_if_not_applied_to_span(attr, &info)?;
|
|
||||||
|
|
||||||
let binding = info.binding.binding.clone();
|
|
||||||
self.span_field.set_once((binding, span));
|
|
||||||
|
|
||||||
Ok(quote! {})
|
|
||||||
}
|
|
||||||
"suggestion_part" => {
|
|
||||||
self.has_suggestion_parts = true;
|
|
||||||
|
|
||||||
match kind {
|
|
||||||
SubdiagnosticKind::MultipartSuggestion { .. } => {
|
|
||||||
span_err(
|
|
||||||
span,
|
|
||||||
"`#[suggestion_part(...)]` attribute without `code = \"...\"`",
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
Ok(quote! {})
|
|
||||||
}
|
|
||||||
SubdiagnosticKind::Label
|
|
||||||
| SubdiagnosticKind::Note
|
|
||||||
| SubdiagnosticKind::Help
|
|
||||||
| SubdiagnosticKind::Warn
|
|
||||||
| SubdiagnosticKind::Suggestion { .. } => {
|
|
||||||
throw_invalid_attr!(attr, &Meta::Path(path), |diag| {
|
|
||||||
diag.help(
|
|
||||||
"`#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead",
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"applicability" => {
|
|
||||||
if let SubdiagnosticKind::Suggestion { .. }
|
|
||||||
| SubdiagnosticKind::MultipartSuggestion { .. } = kind
|
|
||||||
{
|
|
||||||
report_error_if_not_applied_to_applicability(attr, &info)?;
|
|
||||||
|
|
||||||
let binding = info.binding.binding.clone();
|
|
||||||
self.applicability.set_once((quote! { #binding }, span));
|
|
||||||
} else {
|
|
||||||
span_err(span, "`#[applicability]` is only valid on suggestions").emit();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(quote! {})
|
|
||||||
}
|
|
||||||
_ => throw_invalid_attr!(attr, &Meta::Path(path), |diag| {
|
|
||||||
let span_attr = if let SubdiagnosticKind::MultipartSuggestion { .. } = kind {
|
|
||||||
"suggestion_part"
|
|
||||||
} else {
|
|
||||||
"primary_span"
|
|
||||||
};
|
|
||||||
diag.help(format!(
|
|
||||||
"only `{span_attr}`, `applicability` and `skip_arg` are valid field attributes",
|
|
||||||
))
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generates the code for a `[Meta::List]`-like attribute on a field (e.g.
|
|
||||||
/// `#[suggestion_part(code = "...")]`).
|
|
||||||
fn generate_field_code_inner_list(
|
|
||||||
&mut self,
|
|
||||||
kind: &SubdiagnosticKind,
|
|
||||||
attr: &Attribute,
|
|
||||||
info: FieldInfo<'_>,
|
|
||||||
list: MetaList,
|
|
||||||
) -> Result<TokenStream, DiagnosticDeriveError> {
|
|
||||||
let span = attr.span().unwrap();
|
|
||||||
let ident = &list.path.segments.last().unwrap().ident;
|
|
||||||
let name = ident.to_string();
|
|
||||||
let name = name.as_str();
|
|
||||||
|
|
||||||
match name {
|
|
||||||
"suggestion_part" => {
|
|
||||||
if !matches!(kind, SubdiagnosticKind::MultipartSuggestion { .. }) {
|
|
||||||
throw_invalid_attr!(attr, &Meta::List(list), |diag| {
|
|
||||||
diag.help(
|
|
||||||
"`#[suggestion_part(...)]` is only valid in multipart suggestions",
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
self.has_suggestion_parts = true;
|
|
||||||
|
|
||||||
report_error_if_not_applied_to_span(attr, &info)?;
|
|
||||||
|
|
||||||
let mut code = None;
|
|
||||||
for nested_attr in list.nested.iter() {
|
|
||||||
let NestedMeta::Meta(ref meta) = nested_attr else {
|
|
||||||
throw_invalid_nested_attr!(attr, &nested_attr);
|
|
||||||
};
|
|
||||||
|
|
||||||
let span = meta.span().unwrap();
|
|
||||||
let nested_name = meta.path().segments.last().unwrap().ident.to_string();
|
|
||||||
let nested_name = nested_name.as_str();
|
|
||||||
|
|
||||||
let Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(value), .. }) = meta else {
|
|
||||||
throw_invalid_nested_attr!(attr, &nested_attr);
|
|
||||||
};
|
|
||||||
|
|
||||||
match nested_name {
|
|
||||||
"code" => {
|
|
||||||
let formatted_str = self.build_format(&value.value(), value.span());
|
|
||||||
code.set_once((formatted_str, span));
|
|
||||||
}
|
|
||||||
_ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
|
||||||
diag.help("`code` is the only valid nested attribute")
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some((code, _)) = code else {
|
|
||||||
span_err(span, "`#[suggestion_part(...)]` attribute without `code = \"...\"`")
|
|
||||||
.emit();
|
|
||||||
return Ok(quote! {});
|
|
||||||
};
|
|
||||||
let binding = info.binding;
|
|
||||||
|
|
||||||
Ok(quote! { suggestions.push((#binding, #code)); })
|
|
||||||
}
|
|
||||||
_ => throw_invalid_attr!(attr, &Meta::List(list), |diag| {
|
|
||||||
let span_attr = if let SubdiagnosticKind::MultipartSuggestion { .. } = kind {
|
|
||||||
"suggestion_part"
|
|
||||||
} else {
|
|
||||||
"primary_span"
|
|
||||||
};
|
|
||||||
diag.help(format!(
|
|
||||||
"only `{span_attr}`, `applicability` and `skip_arg` are valid field attributes",
|
|
||||||
))
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
|
|
||||||
let Some((kind, slug)) = self.identify_kind()? else {
|
|
||||||
throw_span_err!(
|
throw_span_err!(
|
||||||
self.variant.ast().ident.span().unwrap(),
|
self.variant.ast().ident.span().unwrap(),
|
||||||
"subdiagnostic kind not specified"
|
"subdiagnostic kind not specified"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
let have_suggestion =
|
||||||
|
self.kinds.iter().any(|(k, _)| matches!(k, SubdiagnosticKind::Suggestion(_)));
|
||||||
|
let mut args = TokenStream::new();
|
||||||
|
for binding in self.variant.bindings() {
|
||||||
|
let arg = self
|
||||||
|
.generate_field_code(binding, have_suggestion)
|
||||||
|
.unwrap_or_else(|v| v.to_compile_error());
|
||||||
|
args.extend(arg);
|
||||||
|
}
|
||||||
|
let mut tokens = TokenStream::new();
|
||||||
|
for ((kind, _), (slug, _)) in self.kinds.iter().zip(&self.slugs) {
|
||||||
|
let code = match self.code.as_ref() {
|
||||||
|
Some((code, _)) => Some(quote! { #code }),
|
||||||
|
None if have_suggestion => {
|
||||||
|
span_err(self.span, "suggestion without `code = \"...\"`").emit();
|
||||||
|
Some(quote! { /* macro error */ "..." })
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let init = match &kind {
|
let span_field = self.span_field.as_ref().map(|(span, _)| span);
|
||||||
SubdiagnosticKind::Label
|
let applicability = match self.applicability.clone() {
|
||||||
| SubdiagnosticKind::Note
|
Some((applicability, _)) => Some(applicability),
|
||||||
| SubdiagnosticKind::Help
|
None if have_suggestion => {
|
||||||
| SubdiagnosticKind::Warn
|
span_err(self.span, "suggestion without `applicability`").emit();
|
||||||
| SubdiagnosticKind::Suggestion { .. } => quote! {},
|
Some(quote! { rustc_errors::Applicability::Unspecified })
|
||||||
SubdiagnosticKind::MultipartSuggestion { .. } => {
|
}
|
||||||
quote! { let mut suggestions = Vec::new(); }
|
None => None,
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let attr_args: TokenStream = self
|
let diag = &self.diag;
|
||||||
.variant
|
let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);
|
||||||
.bindings()
|
let message = quote! { rustc_errors::fluent::#slug };
|
||||||
.iter()
|
let call = if matches!(kind, SubdiagnosticKind::Suggestion(..)) {
|
||||||
.filter(|binding| !binding.ast().attrs.is_empty())
|
|
||||||
.map(|binding| self.generate_field_attr_code(binding, &kind))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let span_field = self.span_field.as_ref().map(|(span, _)| span);
|
|
||||||
let applicability = self.applicability.take().map_or_else(
|
|
||||||
|| quote! { rustc_errors::Applicability::Unspecified },
|
|
||||||
|(applicability, _)| applicability,
|
|
||||||
);
|
|
||||||
|
|
||||||
let diag = &self.diag;
|
|
||||||
let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);
|
|
||||||
let message = quote! { rustc_errors::fluent::#slug };
|
|
||||||
let call = match kind {
|
|
||||||
SubdiagnosticKind::Suggestion { suggestion_kind, code } => {
|
|
||||||
if let Some(span) = span_field {
|
if let Some(span) = span_field {
|
||||||
let style = suggestion_kind.to_suggestion_style();
|
quote! { #diag.#name(#span, #message, #code, #applicability); }
|
||||||
|
|
||||||
quote! { #diag.#name(#span, #message, #code, #applicability, #style); }
|
|
||||||
} else {
|
} else {
|
||||||
span_err(self.span, "suggestion without `#[primary_span]` field").emit();
|
span_err(self.span, "suggestion without `#[primary_span]` field").emit();
|
||||||
quote! { unreachable!(); }
|
quote! { unreachable!(); }
|
||||||
}
|
}
|
||||||
}
|
} else if matches!(kind, SubdiagnosticKind::Label) {
|
||||||
SubdiagnosticKind::MultipartSuggestion { suggestion_kind } => {
|
|
||||||
if !self.has_suggestion_parts {
|
|
||||||
span_err(
|
|
||||||
self.span,
|
|
||||||
"multipart suggestion without any `#[suggestion_part(...)]` fields",
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
}
|
|
||||||
|
|
||||||
let style = suggestion_kind.to_suggestion_style();
|
|
||||||
|
|
||||||
quote! { #diag.#name(#message, suggestions, #applicability, #style); }
|
|
||||||
}
|
|
||||||
SubdiagnosticKind::Label => {
|
|
||||||
if let Some(span) = span_field {
|
if let Some(span) = span_field {
|
||||||
quote! { #diag.#name(#span, #message); }
|
quote! { #diag.#name(#span, #message); }
|
||||||
} else {
|
} else {
|
||||||
span_err(self.span, "label without `#[primary_span]` field").emit();
|
span_err(self.span, "label without `#[primary_span]` field").emit();
|
||||||
quote! { unreachable!(); }
|
quote! { unreachable!(); }
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
_ => {
|
|
||||||
if let Some(span) = span_field {
|
if let Some(span) = span_field {
|
||||||
quote! { #diag.#name(#span, #message); }
|
quote! { #diag.#name(#span, #message); }
|
||||||
} else {
|
} else {
|
||||||
quote! { #diag.#name(#message); }
|
quote! { #diag.#name(#message); }
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
tokens.extend(quote! {
|
||||||
|
#call
|
||||||
|
#args
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let plain_args: TokenStream = self
|
Ok(tokens)
|
||||||
.variant
|
|
||||||
.bindings()
|
|
||||||
.iter()
|
|
||||||
.filter(|binding| binding.ast().attrs.is_empty())
|
|
||||||
.map(|binding| self.generate_field_set_arg(binding))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(quote! {
|
|
||||||
#init
|
|
||||||
#attr_args
|
|
||||||
#call
|
|
||||||
#plain_args
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
73
compiler/rustc_query_system/src/error.rs
Normal file
73
compiler/rustc_query_system/src/error.rs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
use rustc_errors::AddSubdiagnostic;
|
||||||
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
pub struct CycleStack {
|
||||||
|
pub span: Span,
|
||||||
|
pub desc: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddSubdiagnostic for CycleStack {
|
||||||
|
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
|
||||||
|
diag.span_note(self.span, &format!("...which requires {}...", self.desc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionSubdiagnostic)]
|
||||||
|
pub enum StackCount {
|
||||||
|
#[note(query_system::cycle_stack_single)]
|
||||||
|
Single,
|
||||||
|
#[note(query_system::cycle_stack_multiple)]
|
||||||
|
Multiple,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionSubdiagnostic)]
|
||||||
|
pub 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)]
|
||||||
|
Ty,
|
||||||
|
#[note(query_system::cycle_recursive_trait_alias)]
|
||||||
|
Trait,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionSubdiagnostic)]
|
||||||
|
#[note(query_system::cycle_usage)]
|
||||||
|
pub struct CycleUsage {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub usage: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(query_system::cycle, code = "E0391")]
|
||||||
|
pub struct Cycle {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub stack_bottom: String,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub cycle_stack: Vec<CycleStack>,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub stack_count: StackCount,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub alias: Option<Alias>,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub cycle_usage: Option<CycleUsage>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(query_system::reentrant)]
|
||||||
|
pub struct Reentrant;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(query_system::increment_compilation)]
|
||||||
|
#[help]
|
||||||
|
#[note(query_system::increment_compilation_note1)]
|
||||||
|
#[note(query_system::increment_compilation_note2)]
|
||||||
|
pub struct IncrementCompilation {
|
||||||
|
pub run_cmd: String,
|
||||||
|
pub dep_node: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(query_system::query_overflow)]
|
||||||
|
pub struct QueryOverflow;
|
|
@ -5,6 +5,8 @@
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(extern_types)]
|
#![feature(extern_types)]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
// #![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
@ -15,5 +17,6 @@ extern crate rustc_macros;
|
||||||
|
|
||||||
pub mod cache;
|
pub mod cache;
|
||||||
pub mod dep_graph;
|
pub mod dep_graph;
|
||||||
|
mod error;
|
||||||
pub mod ich;
|
pub mod ich;
|
||||||
pub mod query;
|
pub mod query;
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
use crate::error::CycleStack;
|
||||||
use crate::query::plumbing::CycleError;
|
use crate::query::plumbing::CycleError;
|
||||||
use crate::query::{QueryContext, QueryStackFrame};
|
use crate::query::{QueryContext, QueryStackFrame};
|
||||||
use rustc_hir::def::DefKind;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{
|
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level};
|
||||||
struct_span_err, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level,
|
use rustc_hir::def::DefKind;
|
||||||
};
|
use rustc_session::{Session, SessionDiagnostic};
|
||||||
use rustc_session::Session;
|
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
@ -536,46 +535,44 @@ pub(crate) fn report_cycle<'a>(
|
||||||
assert!(!stack.is_empty());
|
assert!(!stack.is_empty());
|
||||||
|
|
||||||
let span = stack[0].query.default_span(stack[1 % stack.len()].span);
|
let span = stack[0].query.default_span(stack[1 % stack.len()].span);
|
||||||
let mut err =
|
|
||||||
struct_span_err!(sess, span, E0391, "cycle detected when {}", stack[0].query.description);
|
let mut cycle_stack = Vec::new();
|
||||||
|
|
||||||
|
use crate::error::StackCount;
|
||||||
|
let stack_count = if stack.len() == 1 { StackCount::Single } else { StackCount::Multiple };
|
||||||
|
|
||||||
for i in 1..stack.len() {
|
for i in 1..stack.len() {
|
||||||
let query = &stack[i].query;
|
let query = &stack[i].query;
|
||||||
let span = query.default_span(stack[(i + 1) % stack.len()].span);
|
let span = query.default_span(stack[(i + 1) % stack.len()].span);
|
||||||
err.span_note(span, &format!("...which requires {}...", query.description));
|
cycle_stack.push(CycleStack { span, desc: query.description.to_owned() });
|
||||||
}
|
|
||||||
|
|
||||||
if stack.len() == 1 {
|
|
||||||
err.note(&format!("...which immediately requires {} again", stack[0].query.description));
|
|
||||||
} else {
|
|
||||||
err.note(&format!(
|
|
||||||
"...which again requires {}, completing the cycle",
|
|
||||||
stack[0].query.description
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if stack.iter().all(|entry| {
|
|
||||||
entry
|
|
||||||
.query
|
|
||||||
.def_kind
|
|
||||||
.map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias | DefKind::TraitAlias))
|
|
||||||
}) {
|
|
||||||
if stack.iter().all(|entry| {
|
|
||||||
entry.query.def_kind.map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias))
|
|
||||||
}) {
|
|
||||||
err.note("type aliases cannot be recursive");
|
|
||||||
err.help("consider using a struct, enum, or union instead to break the cycle");
|
|
||||||
err.help("see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information");
|
|
||||||
} else {
|
|
||||||
err.note("trait aliases cannot be recursive");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut cycle_usage = None;
|
||||||
if let Some((span, query)) = usage {
|
if let Some((span, query)) = usage {
|
||||||
err.span_note(query.default_span(span), &format!("cycle used when {}", query.description));
|
cycle_usage = Some(crate::error::CycleUsage {
|
||||||
|
span: query.default_span(span),
|
||||||
|
usage: query.description,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
err
|
let alias = if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TyAlias)) {
|
||||||
|
Some(crate::error::Alias::Ty)
|
||||||
|
} else if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TraitAlias)) {
|
||||||
|
Some(crate::error::Alias::Trait)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let cycle_diag = crate::error::Cycle {
|
||||||
|
span,
|
||||||
|
cycle_stack,
|
||||||
|
stack_bottom: stack[0].query.description.to_owned(),
|
||||||
|
alias,
|
||||||
|
cycle_usage: cycle_usage,
|
||||||
|
stack_count,
|
||||||
|
};
|
||||||
|
|
||||||
|
cycle_diag.into_diagnostic(&sess.parse_sess)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_query_stack<CTX: QueryContext>(
|
pub fn print_query_stack<CTX: QueryContext>(
|
||||||
|
|
|
@ -125,6 +125,6 @@ pub trait QueryContext: HasDepContext {
|
||||||
) -> R;
|
) -> R;
|
||||||
|
|
||||||
fn depth_limit_error(&self) {
|
fn depth_limit_error(&self) {
|
||||||
self.dep_context().sess().fatal("queries overflow the depth limit!");
|
self.dep_context().sess().emit_fatal(crate::error::QueryOverflow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,16 +618,12 @@ fn incremental_verify_ich_cold(sess: &Session, dep_node: DebugArg<'_>, result: D
|
||||||
let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
|
let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
|
||||||
|
|
||||||
if old_in_panic {
|
if old_in_panic {
|
||||||
sess.struct_err(
|
sess.emit_err(crate::error::Reentrant);
|
||||||
"internal compiler error: re-entrant incremental verify failure, suppressing message",
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
} else {
|
} else {
|
||||||
sess.struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
|
sess.emit_err(crate::error::IncrementCompilation {
|
||||||
.help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
|
run_cmd,
|
||||||
.note("Please follow the instructions below to create a bug report with the provided information")
|
dep_node: format!("{:?}", dep_node),
|
||||||
.note("See <https://github.com/rust-lang/rust/issues/84970> for more information")
|
});
|
||||||
.emit();
|
|
||||||
panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
|
panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,8 +167,8 @@ enum P {
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
enum Q {
|
enum Q {
|
||||||
#[bar]
|
#[bar]
|
||||||
//~^ ERROR `#[bar]` is not a valid attribute
|
//~^ ERROR `#[bar]` is not a valid attribute
|
||||||
//~^^ ERROR cannot find attribute `bar` in this scope
|
//~^^ ERROR cannot find attribute `bar` in this scope
|
||||||
A {
|
A {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -179,8 +179,8 @@ enum Q {
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
enum R {
|
enum R {
|
||||||
#[bar = "..."]
|
#[bar = "..."]
|
||||||
//~^ ERROR `#[bar = ...]` is not a valid attribute
|
//~^ ERROR `#[bar = ...]` is not a valid attribute
|
||||||
//~^^ ERROR cannot find attribute `bar` in this scope
|
//~^^ ERROR cannot find attribute `bar` in this scope
|
||||||
A {
|
A {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -191,8 +191,8 @@ enum R {
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
enum S {
|
enum S {
|
||||||
#[bar = 4]
|
#[bar = 4]
|
||||||
//~^ ERROR `#[bar = ...]` is not a valid attribute
|
//~^ ERROR `#[bar = ...]` is not a valid attribute
|
||||||
//~^^ ERROR cannot find attribute `bar` in this scope
|
//~^^ ERROR cannot find attribute `bar` in this scope
|
||||||
A {
|
A {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -203,8 +203,8 @@ enum S {
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
enum T {
|
enum T {
|
||||||
#[bar("...")]
|
#[bar("...")]
|
||||||
//~^ ERROR `#[bar(...)]` is not a valid attribute
|
//~^ ERROR `#[bar("...")]` is not a valid attribute
|
||||||
//~^^ ERROR cannot find attribute `bar` in this scope
|
//~^^ ERROR cannot find attribute `bar` in this scope
|
||||||
A {
|
A {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -215,7 +215,7 @@ enum T {
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
enum U {
|
enum U {
|
||||||
#[label(code = "...")]
|
#[label(code = "...")]
|
||||||
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
|
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
|
||||||
A {
|
A {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -232,7 +232,7 @@ enum V {
|
||||||
var: String,
|
var: String,
|
||||||
},
|
},
|
||||||
B {
|
B {
|
||||||
//~^ ERROR subdiagnostic kind not specified
|
//~^ ERROR subdiagnostic kind not specified
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
var: String,
|
var: String,
|
||||||
|
@ -307,16 +307,6 @@ union AC {
|
||||||
b: u64
|
b: u64
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[label(parser::add_paren)]
|
|
||||||
//~^ NOTE previously specified here
|
|
||||||
#[label(parser::add_paren)]
|
|
||||||
//~^ ERROR specified multiple times
|
|
||||||
struct AD {
|
|
||||||
#[primary_span]
|
|
||||||
span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
#[label(parser::add_paren, parser::add_paren)]
|
#[label(parser::add_paren, parser::add_paren)]
|
||||||
//~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
|
//~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
|
||||||
|
@ -329,16 +319,16 @@ struct AE {
|
||||||
#[label(parser::add_paren)]
|
#[label(parser::add_paren)]
|
||||||
struct AF {
|
struct AF {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
//~^ NOTE previously specified here
|
//~^ NOTE previously specified here
|
||||||
span_a: Span,
|
span_a: Span,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
//~^ ERROR specified multiple times
|
//~^ ERROR specified multiple times
|
||||||
span_b: Span,
|
span_b: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
struct AG {
|
struct AG {
|
||||||
//~^ ERROR subdiagnostic kind not specified
|
//~^ ERROR subdiagnostic kind not specified
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
@ -390,25 +380,27 @@ struct AK {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
#[applicability]
|
#[applicability]
|
||||||
//~^ NOTE previously specified here
|
//~^ NOTE previously specified here
|
||||||
applicability_a: Applicability,
|
applicability_a: Applicability,
|
||||||
#[applicability]
|
#[applicability]
|
||||||
//~^ ERROR specified multiple times
|
//~^ ERROR specified multiple times
|
||||||
applicability_b: Applicability,
|
applicability_b: Applicability,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
#[suggestion(parser::add_paren, code = "...")]
|
#[suggestion(parser::add_paren, code = "...")]
|
||||||
|
//~^ ERROR suggestion without `applicability`
|
||||||
struct AL {
|
struct AL {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
#[applicability]
|
#[applicability]
|
||||||
//~^ ERROR the `#[applicability]` attribute can only be applied to fields of type `Applicability`
|
//~^ ERROR the `#[applicability]` attribute can only be applied to fields of type `Applicability`
|
||||||
applicability: Span,
|
applicability: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
#[suggestion(parser::add_paren, code = "...")]
|
#[suggestion(parser::add_paren, code = "...")]
|
||||||
|
//~^ ERROR suggestion without `applicability`
|
||||||
struct AM {
|
struct AM {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -444,7 +436,8 @@ struct AQ;
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
#[derive(SessionSubdiagnostic)]
|
||||||
#[suggestion(parser::add_paren, code = "...")]
|
#[suggestion(parser::add_paren, code = "...")]
|
||||||
//~^ ERROR suggestion without `#[primary_span]` field
|
//~^ ERROR suggestion without `applicability`
|
||||||
|
//~^^ ERROR suggestion without `#[primary_span]` field
|
||||||
struct AR {
|
struct AR {
|
||||||
var: String,
|
var: String,
|
||||||
}
|
}
|
||||||
|
@ -514,120 +507,3 @@ struct AZ {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[suggestion(parser::add_paren, code = "...")]
|
|
||||||
//~^ ERROR suggestion without `#[primary_span]` field
|
|
||||||
struct BA {
|
|
||||||
#[suggestion_part]
|
|
||||||
//~^ ERROR `#[suggestion_part]` is not a valid attribute
|
|
||||||
span: Span,
|
|
||||||
#[suggestion_part(code = "...")]
|
|
||||||
//~^ ERROR `#[suggestion_part(...)]` is not a valid attribute
|
|
||||||
span2: Span,
|
|
||||||
#[applicability]
|
|
||||||
applicability: Applicability,
|
|
||||||
var: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
|
|
||||||
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
|
|
||||||
//~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute
|
|
||||||
struct BBa {
|
|
||||||
var: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
struct BBb {
|
|
||||||
#[suggestion_part]
|
|
||||||
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
span1: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
struct BBc {
|
|
||||||
#[suggestion_part()]
|
|
||||||
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
span1: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren)]
|
|
||||||
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
|
|
||||||
struct BC {
|
|
||||||
#[primary_span]
|
|
||||||
//~^ ERROR `#[primary_span]` is not a valid attribute
|
|
||||||
span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren)]
|
|
||||||
struct BD {
|
|
||||||
#[suggestion_part]
|
|
||||||
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
span1: Span,
|
|
||||||
#[suggestion_part()]
|
|
||||||
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
span2: Span,
|
|
||||||
#[suggestion_part(foo = "bar")]
|
|
||||||
//~^ ERROR `#[suggestion_part(foo = ...)]` is not a valid attribute
|
|
||||||
span4: Span,
|
|
||||||
#[suggestion_part(code = "...")]
|
|
||||||
//~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
|
||||||
s1: String,
|
|
||||||
#[suggestion_part()]
|
|
||||||
//~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
|
||||||
s2: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
struct BE {
|
|
||||||
#[suggestion_part(code = "...", code = ",,,")]
|
|
||||||
//~^ ERROR specified multiple times
|
|
||||||
//~| NOTE previously specified here
|
|
||||||
span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
struct BF {
|
|
||||||
#[suggestion_part(code = "(")]
|
|
||||||
first: Span,
|
|
||||||
#[suggestion_part(code = ")")]
|
|
||||||
second: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren)]
|
|
||||||
struct BG {
|
|
||||||
#[applicability]
|
|
||||||
appl: Applicability,
|
|
||||||
#[suggestion_part(code = "(")]
|
|
||||||
first: Span,
|
|
||||||
#[suggestion_part(code = ")")]
|
|
||||||
second: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
//~^ NOTE previously specified here
|
|
||||||
struct BH {
|
|
||||||
#[applicability]
|
|
||||||
//~^ ERROR specified multiple times
|
|
||||||
appl: Applicability,
|
|
||||||
#[suggestion_part(code = "(")]
|
|
||||||
first: Span,
|
|
||||||
#[suggestion_part(code = ")")]
|
|
||||||
second: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SessionSubdiagnostic)]
|
|
||||||
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
struct BI {
|
|
||||||
#[suggestion_part(code = "")]
|
|
||||||
spans: Vec<Span>,
|
|
||||||
}
|
|
||||||
|
|
|
@ -65,16 +65,16 @@ LL | #[label()]
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: `code` is not a valid nested attribute of a `label` attribute
|
error: `code` is not a valid nested attribute of a `label` attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:137:28
|
--> $DIR/subdiagnostic-derive.rs:137:1
|
||||||
|
|
|
|
||||||
LL | #[label(parser::add_paren, code = "...")]
|
LL | #[label(parser::add_paren, code = "...")]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: `applicability` is not a valid nested attribute of a `label` attribute
|
error: `applicability` is not a valid nested attribute of a `label` attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:146:28
|
--> $DIR/subdiagnostic-derive.rs:146:1
|
||||||
|
|
|
|
||||||
LL | #[label(parser::add_paren, applicability = "machine-applicable")]
|
LL | #[label(parser::add_paren, applicability = "machine-applicable")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unsupported type attribute for subdiagnostic enum
|
error: unsupported type attribute for subdiagnostic enum
|
||||||
--> $DIR/subdiagnostic-derive.rs:155:1
|
--> $DIR/subdiagnostic-derive.rs:155:1
|
||||||
|
@ -100,11 +100,13 @@ error: `#[bar = ...]` is not a valid attribute
|
||||||
LL | #[bar = 4]
|
LL | #[bar = 4]
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: `#[bar(...)]` is not a valid attribute
|
error: `#[bar("...")]` is not a valid attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:205:5
|
--> $DIR/subdiagnostic-derive.rs:205:11
|
||||||
|
|
|
|
||||||
LL | #[bar("...")]
|
LL | #[bar("...")]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^
|
||||||
|
|
|
||||||
|
= help: first argument of the attribute should be the diagnostic slug
|
||||||
|
|
||||||
error: diagnostic slug must be first argument of a `#[label(...)]` attribute
|
error: diagnostic slug must be first argument of a `#[label(...)]` attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:217:5
|
--> $DIR/subdiagnostic-derive.rs:217:5
|
||||||
|
@ -161,8 +163,6 @@ error: `#[bar(...)]` is not a valid attribute
|
||||||
|
|
|
|
||||||
LL | #[bar("...")]
|
LL | #[bar("...")]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes
|
|
||||||
|
|
||||||
error: unexpected unsupported untagged union
|
error: unexpected unsupported untagged union
|
||||||
--> $DIR/subdiagnostic-derive.rs:304:1
|
--> $DIR/subdiagnostic-derive.rs:304:1
|
||||||
|
@ -174,20 +174,8 @@ LL | | b: u64
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: specified multiple times
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:313:1
|
|
||||||
|
|
|
||||||
LL | #[label(parser::add_paren)]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: previously specified here
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:311:1
|
|
||||||
|
|
|
||||||
LL | #[label(parser::add_paren)]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `#[label(parser::add_paren)]` is not a valid attribute
|
error: `#[label(parser::add_paren)]` is not a valid attribute
|
||||||
--> $DIR/subdiagnostic-derive.rs:321:28
|
--> $DIR/subdiagnostic-derive.rs:311:28
|
||||||
|
|
|
|
||||||
LL | #[label(parser::add_paren, parser::add_paren)]
|
LL | #[label(parser::add_paren, parser::add_paren)]
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
@ -195,226 +183,134 @@ LL | #[label(parser::add_paren, parser::add_paren)]
|
||||||
= help: a diagnostic slug must be the first argument to the attribute
|
= help: a diagnostic slug must be the first argument to the attribute
|
||||||
|
|
||||||
error: specified multiple times
|
error: specified multiple times
|
||||||
--> $DIR/subdiagnostic-derive.rs:334:5
|
--> $DIR/subdiagnostic-derive.rs:324:5
|
||||||
|
|
|
|
||||||
LL | #[primary_span]
|
LL | #[primary_span]
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: previously specified here
|
note: previously specified here
|
||||||
--> $DIR/subdiagnostic-derive.rs:331:5
|
--> $DIR/subdiagnostic-derive.rs:321:5
|
||||||
|
|
|
|
||||||
LL | #[primary_span]
|
LL | #[primary_span]
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: subdiagnostic kind not specified
|
error: subdiagnostic kind not specified
|
||||||
--> $DIR/subdiagnostic-derive.rs:340:8
|
--> $DIR/subdiagnostic-derive.rs:330:8
|
||||||
|
|
|
|
||||||
LL | struct AG {
|
LL | struct AG {
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: specified multiple times
|
error: specified multiple times
|
||||||
--> $DIR/subdiagnostic-derive.rs:377:47
|
--> $DIR/subdiagnostic-derive.rs:367:47
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser::add_paren, code = "...", code = "...")]
|
LL | #[suggestion(parser::add_paren, code = "...", code = "...")]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: previously specified here
|
note: previously specified here
|
||||||
--> $DIR/subdiagnostic-derive.rs:377:33
|
--> $DIR/subdiagnostic-derive.rs:367:33
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser::add_paren, code = "...", code = "...")]
|
LL | #[suggestion(parser::add_paren, code = "...", code = "...")]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error: specified multiple times
|
error: specified multiple times
|
||||||
--> $DIR/subdiagnostic-derive.rs:395:5
|
--> $DIR/subdiagnostic-derive.rs:385:5
|
||||||
|
|
|
|
||||||
LL | #[applicability]
|
LL | #[applicability]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: previously specified here
|
note: previously specified here
|
||||||
--> $DIR/subdiagnostic-derive.rs:392:5
|
--> $DIR/subdiagnostic-derive.rs:382:5
|
||||||
|
|
|
|
||||||
LL | #[applicability]
|
LL | #[applicability]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: the `#[applicability]` attribute can only be applied to fields of type `Applicability`
|
error: the `#[applicability]` attribute can only be applied to fields of type `Applicability`
|
||||||
--> $DIR/subdiagnostic-derive.rs:405:5
|
--> $DIR/subdiagnostic-derive.rs:396:5
|
||||||
|
|
|
|
||||||
LL | #[applicability]
|
LL | #[applicability]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: suggestion without `code = "..."`
|
error: suggestion without `applicability`
|
||||||
--> $DIR/subdiagnostic-derive.rs:418:1
|
--> $DIR/subdiagnostic-derive.rs:391:1
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser::add_paren)]
|
LL | / #[suggestion(parser::add_paren, code = "...")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
LL | |
|
||||||
|
LL | | struct AL {
|
||||||
|
LL | | #[primary_span]
|
||||||
|
... |
|
||||||
|
LL | | applicability: Span,
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
|
error: suggestion without `applicability`
|
||||||
|
--> $DIR/subdiagnostic-derive.rs:402:1
|
||||||
|
|
|
||||||
|
LL | / #[suggestion(parser::add_paren, code = "...")]
|
||||||
|
LL | |
|
||||||
|
LL | | struct AM {
|
||||||
|
LL | | #[primary_span]
|
||||||
|
LL | | span: Span,
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
|
error: suggestion without `code = "..."`
|
||||||
|
--> $DIR/subdiagnostic-derive.rs:410:1
|
||||||
|
|
|
||||||
|
LL | / #[suggestion(parser::add_paren)]
|
||||||
|
LL | |
|
||||||
|
LL | | struct AN {
|
||||||
|
LL | | #[primary_span]
|
||||||
|
... |
|
||||||
|
LL | | applicability: Applicability,
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
error: invalid applicability
|
error: invalid applicability
|
||||||
--> $DIR/subdiagnostic-derive.rs:428:46
|
--> $DIR/subdiagnostic-derive.rs:420:46
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
|
LL | #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: suggestion without `#[primary_span]` field
|
error: suggestion without `applicability`
|
||||||
--> $DIR/subdiagnostic-derive.rs:446:1
|
--> $DIR/subdiagnostic-derive.rs:438:1
|
||||||
|
|
|
|
||||||
LL | / #[suggestion(parser::add_paren, code = "...")]
|
LL | / #[suggestion(parser::add_paren, code = "...")]
|
||||||
LL | |
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | | struct AR {
|
||||||
|
LL | | var: String,
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
|
error: suggestion without `#[primary_span]` field
|
||||||
|
--> $DIR/subdiagnostic-derive.rs:438:1
|
||||||
|
|
|
||||||
|
LL | / #[suggestion(parser::add_paren, code = "...")]
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
LL | | struct AR {
|
LL | | struct AR {
|
||||||
LL | | var: String,
|
LL | | var: String,
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: unsupported type attribute for subdiagnostic enum
|
error: unsupported type attribute for subdiagnostic enum
|
||||||
--> $DIR/subdiagnostic-derive.rs:460:1
|
--> $DIR/subdiagnostic-derive.rs:453:1
|
||||||
|
|
|
|
||||||
LL | #[label]
|
LL | #[label]
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: `var` doesn't refer to a field on this type
|
error: `var` doesn't refer to a field on this type
|
||||||
--> $DIR/subdiagnostic-derive.rs:480:39
|
--> $DIR/subdiagnostic-derive.rs:473:39
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
|
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: `var` doesn't refer to a field on this type
|
error: `var` doesn't refer to a field on this type
|
||||||
--> $DIR/subdiagnostic-derive.rs:499:43
|
--> $DIR/subdiagnostic-derive.rs:492:43
|
||||||
|
|
|
|
||||||
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
|
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: `#[suggestion_part]` is not a valid attribute
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:522:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: `#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead
|
|
||||||
|
|
||||||
error: `#[suggestion_part(...)]` is not a valid attribute
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:525:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part(code = "...")]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: `#[suggestion_part(...)]` is only valid in multipart suggestions
|
|
||||||
|
|
||||||
error: suggestion without `#[primary_span]` field
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:519:1
|
|
||||||
|
|
|
||||||
LL | / #[suggestion(parser::add_paren, code = "...")]
|
|
||||||
LL | |
|
|
||||||
LL | | struct BA {
|
|
||||||
LL | | #[suggestion_part]
|
|
||||||
... |
|
|
||||||
LL | | var: String,
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: `code` is not a valid nested attribute of a `multipart_suggestion` attribute
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:534:43
|
|
||||||
|
|
|
||||||
LL | #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: multipart suggestion without any `#[suggestion_part(...)]` fields
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:534:1
|
|
||||||
|
|
|
||||||
LL | / #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
|
|
||||||
LL | |
|
|
||||||
LL | |
|
|
||||||
LL | | struct BBa {
|
|
||||||
LL | | var: String,
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:544:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:552:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part()]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `#[primary_span]` is not a valid attribute
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:561:5
|
|
||||||
|
|
|
||||||
LL | #[primary_span]
|
|
||||||
| ^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: multipart suggestions use one or more `#[suggestion_part]`s rather than one `#[primary_span]`
|
|
||||||
|
|
||||||
error: multipart suggestion without any `#[suggestion_part(...)]` fields
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:558:1
|
|
||||||
|
|
|
||||||
LL | / #[multipart_suggestion(parser::add_paren)]
|
|
||||||
LL | |
|
|
||||||
LL | | struct BC {
|
|
||||||
LL | | #[primary_span]
|
|
||||||
LL | |
|
|
||||||
LL | | span: Span,
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:569:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `#[suggestion_part(...)]` attribute without `code = "..."`
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:572:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part()]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `#[suggestion_part(foo = ...)]` is not a valid attribute
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:575:23
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part(foo = "bar")]
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: `code` is the only valid nested attribute
|
|
||||||
|
|
||||||
error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:578:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part(code = "...")]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:581:5
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part()]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: specified multiple times
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:589:37
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part(code = "...", code = ",,,")]
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: previously specified here
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:589:23
|
|
||||||
|
|
|
||||||
LL | #[suggestion_part(code = "...", code = ",,,")]
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: specified multiple times
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:619:5
|
|
||||||
|
|
|
||||||
LL | #[applicability]
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: previously specified here
|
|
||||||
--> $DIR/subdiagnostic-derive.rs:616:43
|
|
||||||
|
|
|
||||||
LL | #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: cannot find attribute `foo` in this scope
|
error: cannot find attribute `foo` in this scope
|
||||||
--> $DIR/subdiagnostic-derive.rs:63:3
|
--> $DIR/subdiagnostic-derive.rs:63:3
|
||||||
|
|
|
|
||||||
|
@ -475,6 +371,6 @@ error[E0425]: cannot find value `slug` in module `rustc_errors::fluent`
|
||||||
LL | #[label(slug)]
|
LL | #[label(slug)]
|
||||||
| ^^^^ not found in `rustc_errors::fluent`
|
| ^^^^ not found in `rustc_errors::fluent`
|
||||||
|
|
||||||
error: aborting due to 64 previous errors
|
error: aborting due to 50 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0425`.
|
For more information about this error, try `rustc --explain E0425`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue