Fix diagnostics with errors

This commit is contained in:
clubby789 2023-05-06 00:29:52 +01:00
parent 9b5574f028
commit 220bb61b33
8 changed files with 35 additions and 36 deletions

View File

@ -271,17 +271,15 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
);
});
}
#[cfg(debug_assertions)]
{
// Record variables referenced by these messages so we can produce
// tests in the derive diagnostics to validate them.
let ident = quote::format_ident!("{snake_name}_refs");
let vrefs = variable_references(msg);
constants.extend(quote! {
#[cfg(test)]
pub const #ident: &[&str] = &[#(#vrefs),*];
})
}
// Record variables referenced by these messages so we can produce
// tests in the derive diagnostics to validate them.
let ident = quote::format_ident!("{snake_name}_refs");
let vrefs = variable_references(msg);
constants.extend(quote! {
#[cfg(test)]
pub const #ident: &[&str] = &[#(#vrefs),*];
})
}
}
@ -348,7 +346,6 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
.into()
}
#[cfg(debug_assertions)]
fn variable_references<'a>(msg: &Message<&'a str>) -> Vec<&'a str> {
let mut refs = vec![];
if let Some(Pattern { elements }) = &msg.value {

View File

@ -137,7 +137,7 @@ hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snip
hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}`
.note = default implementation of `{$missing_item_name}` is unstable
.some_note = use of unstable library feature '{$feature}': {$r}
.some_note = use of unstable library feature '{$feature}': {$reason}
.none_note = use of unstable library feature '{$feature}'
hir_analysis_missing_type_params =

View File

@ -77,7 +77,7 @@ impl<'a> DiagnosticDerive<'a> {
});
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.kind else { unreachable!() };
#[allow(unused_mut)]
let mut imp = structure.gen_impl(quote! {
gen impl<'__diagnostic_handler_sess, G>
rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
@ -95,11 +95,8 @@ impl<'a> DiagnosticDerive<'a> {
}
}
});
#[cfg(debug_assertions)]
{
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
imp.extend(test);
}
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
imp.extend(test);
}
imp
}
@ -170,7 +167,6 @@ impl<'a> LintDiagnosticDerive<'a> {
});
let diag = &builder.diag;
#[allow(unused_mut)]
let mut imp = structure.gen_impl(quote! {
gen impl<'__a> rustc_errors::DecorateLint<'__a, ()> for @Self {
#[track_caller]
@ -187,12 +183,10 @@ impl<'a> LintDiagnosticDerive<'a> {
}
}
});
#[cfg(debug_assertions)]
{
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
imp.extend(test);
}
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
imp.extend(test);
}
imp
}
}
@ -223,7 +217,6 @@ impl Mismatch {
/// Generates a `#[test]` that verifies that all referenced variables
/// exist on this structure.
#[cfg(debug_assertions)]
fn generate_test(slug: &syn::Path, structure: &Structure<'_>) -> TokenStream {
// FIXME: We can't identify variables in a subdiagnostic
for field in structure.variants().iter().flat_map(|v| v.ast().fields.iter()) {

View File

@ -1153,14 +1153,6 @@ pub struct UnixSigpipeValues {
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(passes_no_main_function, code = "E0601")]
pub struct NoMainFunction {
#[primary_span]
pub span: Span,
pub crate_name: String,
}
pub struct NoMainErr {
pub sp: Span,
pub crate_name: Symbol,

View File

@ -11,6 +11,10 @@ pub trait JustTrait {
#[rustc_default_body_unstable(feature = "fun_default_body", issue = "none")]
#[stable(feature = "stable_feature", since = "1.0.0")]
fn fun() {}
#[rustc_default_body_unstable(feature = "fun_default_body", issue = "none", reason = "reason")]
#[stable(feature = "stable_feature", since = "1.0.0")]
fn fun2() {}
}
#[rustc_must_implement_one_of(eq, neq)]

View File

@ -10,6 +10,7 @@ struct Type;
impl JustTrait for Type {}
//~^ ERROR not all trait items implemented, missing: `CONSTANT` [E0046]
//~| ERROR not all trait items implemented, missing: `fun` [E0046]
//~| ERROR not all trait items implemented, missing: `fun2` [E0046]
impl Equal for Type {
//~^ ERROR not all trait items implemented, missing: `eq` [E0046]

View File

@ -18,8 +18,18 @@ LL | impl JustTrait for Type {}
= note: use of unstable library feature 'fun_default_body'
= help: add `#![feature(fun_default_body)]` to the crate attributes to enable
error[E0046]: not all trait items implemented, missing: `fun2`
--> $DIR/default-body-stability-err.rs:10:1
|
LL | impl JustTrait for Type {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: default implementation of `fun2` is unstable
= note: use of unstable library feature 'fun_default_body': reason
= help: add `#![feature(fun_default_body)]` to the crate attributes to enable
error[E0046]: not all trait items implemented, missing: `eq`
--> $DIR/default-body-stability-err.rs:14:1
--> $DIR/default-body-stability-err.rs:15:1
|
LL | / impl Equal for Type {
LL | |
@ -33,6 +43,6 @@ LL | | }
= note: use of unstable library feature 'eq_default_body'
= help: add `#![feature(eq_default_body)]` to the crate attributes to enable
error: aborting due to 3 previous errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0046`.

View File

@ -12,6 +12,8 @@ impl JustTrait for Type {
const CONSTANT: usize = 1;
fn fun() {}
fn fun2() {}
}
impl Equal for Type {