Skip to content

Commit

Permalink
Fix diagnostics with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed May 26, 2023
1 parent 9b5574f commit 220bb61
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 36 deletions.
21 changes: 9 additions & 12 deletions compiler/rustc_fluent_macro/src/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),*];
})
}
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
19 changes: 6 additions & 13 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
}
Expand Down Expand Up @@ -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]
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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()) {
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/stability-attribute/auxiliary/default_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions tests/ui/stability-attribute/default-body-stability-err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 12 additions & 2 deletions tests/ui/stability-attribute/default-body-stability-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand All @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ impl JustTrait for Type {
const CONSTANT: usize = 1;

fn fun() {}

fn fun2() {}
}

impl Equal for Type {
Expand Down

0 comments on commit 220bb61

Please sign in to comment.