about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-10-11 11:30:03 -0400
committerMichael Goulet <michael@errs.io>2024-10-11 11:30:08 -0400
commitd6391d5d4d1fa20da66e6a58a593b9cb29fa4b1c (patch)
tree96af017bf5cd7752d37ab6c779b246a225b3f061
parentc085071631bd26227994fefeb4c34aa33e4d4cef (diff)
downloadrust-d6391d5d4d1fa20da66e6a58a593b9cb29fa4b1c.tar.gz
rust-d6391d5d4d1fa20da66e6a58a593b9cb29fa4b1c.zip
Note what qualifier
-rw-r--r--compiler/rustc_ast_passes/messages.ftl4
-rw-r--r--compiler/rustc_ast_passes/src/ast_validation.rs15
-rw-r--r--compiler/rustc_ast_passes/src/errors.rs1
-rw-r--r--tests/ui/extern/issue-95829.rs2
-rw-r--r--tests/ui/extern/issue-95829.stderr4
-rw-r--r--tests/ui/parser/fn-header-semantic-fail.rs10
-rw-r--r--tests/ui/parser/fn-header-semantic-fail.stderr24
-rw-r--r--tests/ui/parser/no-const-fn-in-extern-block.rs6
-rw-r--r--tests/ui/parser/no-const-fn-in-extern-block.stderr8
9 files changed, 39 insertions, 35 deletions
diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl
index f826e71b574..3ea17cbc279 100644
--- a/compiler/rustc_ast_passes/messages.ftl
+++ b/compiler/rustc_ast_passes/messages.ftl
@@ -66,9 +66,9 @@ ast_passes_equality_in_where = equality constraints are not yet supported in `wh
 
 ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
 
-ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have qualifiers
+ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have `{$kw}` qualifier
     .label = in this `extern` block
-    .suggestion = remove this qualifier
+    .suggestion = remove the `{$kw}` qualifier
 
 ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
     .suggestion = add `unsafe` to this `extern` block
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index 5bdd9b6eda8..cd296d39770 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -561,21 +561,24 @@ impl<'a> AstValidator<'a> {
         // Deconstruct to ensure exhaustiveness
         FnHeader { safety: _, coroutine_kind, constness, ext }: FnHeader,
     ) {
-        let report_err = |span| {
-            self.dcx()
-                .emit_err(errors::FnQualifierInExtern { span, block: self.current_extern_span() });
+        let report_err = |span, kw| {
+            self.dcx().emit_err(errors::FnQualifierInExtern {
+                span,
+                kw,
+                block: self.current_extern_span(),
+            });
         };
         match coroutine_kind {
-            Some(knd) => report_err(knd.span()),
+            Some(kind) => report_err(kind.span(), kind.as_str()),
             None => (),
         }
         match constness {
-            Const::Yes(span) => report_err(span),
+            Const::Yes(span) => report_err(span, "const"),
             Const::No => (),
         }
         match ext {
             Extern::None => (),
-            Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span),
+            Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span, "extern"),
         }
     }
 
diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs
index 5cce47ce7bd..712bb4b9ba5 100644
--- a/compiler/rustc_ast_passes/src/errors.rs
+++ b/compiler/rustc_ast_passes/src/errors.rs
@@ -295,6 +295,7 @@ pub(crate) struct FnQualifierInExtern {
     pub span: Span,
     #[label]
     pub block: Span,
+    pub kw: &'static str,
 }
 
 #[derive(Diagnostic)]
diff --git a/tests/ui/extern/issue-95829.rs b/tests/ui/extern/issue-95829.rs
index ad4e04f7c3a..c5ae4c68265 100644
--- a/tests/ui/extern/issue-95829.rs
+++ b/tests/ui/extern/issue-95829.rs
@@ -2,7 +2,7 @@
 
 extern {
     async fn L() { //~ ERROR: incorrect function inside `extern` block
-        //~^ ERROR: functions in `extern` blocks cannot have qualifiers
+        //~^ ERROR: functions in `extern` blocks cannot have `async` qualifier
         async fn M() {}
     }
 }
diff --git a/tests/ui/extern/issue-95829.stderr b/tests/ui/extern/issue-95829.stderr
index 16504d1f0c9..2f396b8cc04 100644
--- a/tests/ui/extern/issue-95829.stderr
+++ b/tests/ui/extern/issue-95829.stderr
@@ -15,13 +15,13 @@ LL | |     }
    = help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
    = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `async` qualifier
   --> $DIR/issue-95829.rs:4:5
    |
 LL | extern {
    | ------ in this `extern` block
 LL |     async fn L() {
-   |     ^^^^^ help: remove this qualifier
+   |     ^^^^^ help: remove the `async` qualifier
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/parser/fn-header-semantic-fail.rs b/tests/ui/parser/fn-header-semantic-fail.rs
index f3d834549a8..202f362c81c 100644
--- a/tests/ui/parser/fn-header-semantic-fail.rs
+++ b/tests/ui/parser/fn-header-semantic-fail.rs
@@ -41,15 +41,15 @@ fn main() {
     }
 
     extern "C" {
-        async fn fe1(); //~ ERROR functions in `extern` blocks cannot have qualifiers
-        unsafe fn fe2(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
-        const fn fe3(); //~ ERROR functions in `extern` blocks cannot have qualifiers
-        extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot have qualifiers
+        async fn fe1(); //~ ERROR functions in `extern` blocks cannot
+        unsafe fn fe2(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot
+        const fn fe3(); //~ ERROR functions in `extern` blocks cannot
+        extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot
         const async unsafe extern "C" fn fe5();
         //~^ ERROR functions in `extern` blocks
         //~| ERROR functions in `extern` blocks
         //~| ERROR functions in `extern` blocks
         //~| ERROR functions cannot be both `const` and `async`
-        //~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
+        //~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have
     }
 }
diff --git a/tests/ui/parser/fn-header-semantic-fail.stderr b/tests/ui/parser/fn-header-semantic-fail.stderr
index 894e03157c1..17e880c3a79 100644
--- a/tests/ui/parser/fn-header-semantic-fail.stderr
+++ b/tests/ui/parser/fn-header-semantic-fail.stderr
@@ -70,13 +70,13 @@ LL |         const async unsafe extern "C" fn fi5() {}
    |         |     `async` because of this
    |         `const` because of this
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `async` qualifier
   --> $DIR/fn-header-semantic-fail.rs:44:9
    |
 LL |     extern "C" {
    |     ---------- in this `extern` block
 LL |         async fn fe1();
-   |         ^^^^^ help: remove this qualifier
+   |         ^^^^^ help: remove the `async` qualifier
 
 error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
   --> $DIR/fn-header-semantic-fail.rs:45:9
@@ -89,50 +89,50 @@ help: add `unsafe` to this `extern` block
 LL |     unsafe extern "C" {
    |     ++++++
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `const` qualifier
   --> $DIR/fn-header-semantic-fail.rs:46:9
    |
 LL |     extern "C" {
    |     ---------- in this `extern` block
 ...
 LL |         const fn fe3();
-   |         ^^^^^ help: remove this qualifier
+   |         ^^^^^ help: remove the `const` qualifier
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `extern` qualifier
   --> $DIR/fn-header-semantic-fail.rs:47:9
    |
 LL |     extern "C" {
    |     ---------- in this `extern` block
 ...
 LL |         extern "C" fn fe4();
-   |         ^^^^^^^^^^ help: remove this qualifier
+   |         ^^^^^^^^^^ help: remove the `extern` qualifier
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `async` qualifier
   --> $DIR/fn-header-semantic-fail.rs:48:15
    |
 LL |     extern "C" {
    |     ---------- in this `extern` block
 ...
 LL |         const async unsafe extern "C" fn fe5();
-   |               ^^^^^ help: remove this qualifier
+   |               ^^^^^ help: remove the `async` qualifier
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `const` qualifier
   --> $DIR/fn-header-semantic-fail.rs:48:9
    |
 LL |     extern "C" {
    |     ---------- in this `extern` block
 ...
 LL |         const async unsafe extern "C" fn fe5();
-   |         ^^^^^ help: remove this qualifier
+   |         ^^^^^ help: remove the `const` qualifier
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `extern` qualifier
   --> $DIR/fn-header-semantic-fail.rs:48:28
    |
 LL |     extern "C" {
    |     ---------- in this `extern` block
 ...
 LL |         const async unsafe extern "C" fn fe5();
-   |                            ^^^^^^^^^^ help: remove this qualifier
+   |                            ^^^^^^^^^^ help: remove the `extern` qualifier
 
 error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
   --> $DIR/fn-header-semantic-fail.rs:48:9
diff --git a/tests/ui/parser/no-const-fn-in-extern-block.rs b/tests/ui/parser/no-const-fn-in-extern-block.rs
index 1d389108494..0f1e44ced10 100644
--- a/tests/ui/parser/no-const-fn-in-extern-block.rs
+++ b/tests/ui/parser/no-const-fn-in-extern-block.rs
@@ -1,9 +1,9 @@
 extern "C" {
     const fn foo();
-    //~^ ERROR functions in `extern` blocks cannot have qualifiers
+    //~^ ERROR functions in `extern` blocks cannot
     const unsafe fn bar();
-    //~^ ERROR functions in `extern` blocks cannot have qualifiers
-    //~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
+    //~^ ERROR functions in `extern` blocks cannot
+    //~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot
 }
 
 fn main() {}
diff --git a/tests/ui/parser/no-const-fn-in-extern-block.stderr b/tests/ui/parser/no-const-fn-in-extern-block.stderr
index d4428d3cb81..46f845e85c2 100644
--- a/tests/ui/parser/no-const-fn-in-extern-block.stderr
+++ b/tests/ui/parser/no-const-fn-in-extern-block.stderr
@@ -1,19 +1,19 @@
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `const` qualifier
   --> $DIR/no-const-fn-in-extern-block.rs:2:5
    |
 LL | extern "C" {
    | ---------- in this `extern` block
 LL |     const fn foo();
-   |     ^^^^^ help: remove this qualifier
+   |     ^^^^^ help: remove the `const` qualifier
 
-error: functions in `extern` blocks cannot have qualifiers
+error: functions in `extern` blocks cannot have `const` qualifier
   --> $DIR/no-const-fn-in-extern-block.rs:4:5
    |
 LL | extern "C" {
    | ---------- in this `extern` block
 ...
 LL |     const unsafe fn bar();
-   |     ^^^^^ help: remove this qualifier
+   |     ^^^^^ help: remove the `const` qualifier
 
 error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
   --> $DIR/no-const-fn-in-extern-block.rs:4:5