about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2023-05-06 00:29:52 +0100
committerclubby789 <jamie@hill-daniel.co.uk>2023-05-26 10:44:18 +0000
commit220bb61b3317340d01d95aad4f4d30cca91943f2 (patch)
tree60d1f45ef2ea552546afc0eb23799a997623c467
parent9b5574f028c75d794b51c96ff6471ddf756f329b (diff)
downloadrust-220bb61b3317340d01d95aad4f4d30cca91943f2.tar.gz
rust-220bb61b3317340d01d95aad4f4d30cca91943f2.zip
Fix diagnostics with errors
-rw-r--r--compiler/rustc_fluent_macro/src/fluent.rs21
-rw-r--r--compiler/rustc_hir_analysis/messages.ftl2
-rw-r--r--compiler/rustc_macros/src/diagnostics/diagnostic.rs19
-rw-r--r--compiler/rustc_passes/src/errors.rs8
-rw-r--r--tests/ui/stability-attribute/auxiliary/default_body.rs4
-rw-r--r--tests/ui/stability-attribute/default-body-stability-err.rs1
-rw-r--r--tests/ui/stability-attribute/default-body-stability-err.stderr14
-rw-r--r--tests/ui/stability-attribute/default-body-stability-ok-impls.rs2
8 files changed, 35 insertions, 36 deletions
diff --git a/compiler/rustc_fluent_macro/src/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs
index b1c83e0dedc..56e23ac2775 100644
--- a/compiler/rustc_fluent_macro/src/fluent.rs
+++ b/compiler/rustc_fluent_macro/src/fluent.rs
@@ -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 {
diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl
index 02d1dfcd113..5225fee4916 100644
--- a/compiler/rustc_hir_analysis/messages.ftl
+++ b/compiler/rustc_hir_analysis/messages.ftl
@@ -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 =
diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs
index b9eba65f66a..04b7c5feebe 100644
--- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs
+++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs
@@ -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()) {
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs
index 99fc69d1bec..4d9254a0a45 100644
--- a/compiler/rustc_passes/src/errors.rs
+++ b/compiler/rustc_passes/src/errors.rs
@@ -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,
diff --git a/tests/ui/stability-attribute/auxiliary/default_body.rs b/tests/ui/stability-attribute/auxiliary/default_body.rs
index 3a177419d66..2f315eb1bc8 100644
--- a/tests/ui/stability-attribute/auxiliary/default_body.rs
+++ b/tests/ui/stability-attribute/auxiliary/default_body.rs
@@ -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)]
diff --git a/tests/ui/stability-attribute/default-body-stability-err.rs b/tests/ui/stability-attribute/default-body-stability-err.rs
index ecb281bccf6..d1a3597687d 100644
--- a/tests/ui/stability-attribute/default-body-stability-err.rs
+++ b/tests/ui/stability-attribute/default-body-stability-err.rs
@@ -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]
diff --git a/tests/ui/stability-attribute/default-body-stability-err.stderr b/tests/ui/stability-attribute/default-body-stability-err.stderr
index ef666f30fc2..12ec9ea3adb 100644
--- a/tests/ui/stability-attribute/default-body-stability-err.stderr
+++ b/tests/ui/stability-attribute/default-body-stability-err.stderr
@@ -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`.
diff --git a/tests/ui/stability-attribute/default-body-stability-ok-impls.rs b/tests/ui/stability-attribute/default-body-stability-ok-impls.rs
index e1f5c017096..b29d45256bf 100644
--- a/tests/ui/stability-attribute/default-body-stability-ok-impls.rs
+++ b/tests/ui/stability-attribute/default-body-stability-ok-impls.rs
@@ -12,6 +12,8 @@ impl JustTrait for Type {
     const CONSTANT: usize = 1;
 
     fn fun() {}
+
+    fn fun2() {}
 }
 
 impl Equal for Type {