about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-02-28 03:35:13 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-02-28 03:35:13 +0000
commit86945c0a545643457e551a78e8c2a90355d0f17c (patch)
treea52ec432a83e44ea8f6930417cf9629e3913269c
parentf45d4acf1bb635aa010f19f8a749eed8293203b3 (diff)
downloadrust-86945c0a545643457e551a78e8c2a90355d0f17c.tar.gz
rust-86945c0a545643457e551a78e8c2a90355d0f17c.zip
Tweak incorrect ABI suggestion
Provide a better suggestion message, and make the suggestion verbose.

```
error[E0703]: invalid ABI: found `riscv-interrupt`
  --> $DIR/riscv-discoverability-guidance.rs:17:8
   |
LL | extern "riscv-interrupt" fn isr() {}
   |        ^^^^^^^^^^^^^^^^^ invalid ABI
   |
   = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
help: there's a similarly named valid ABI `"riscv-interrupt-m"`
   |
LL | extern "riscv-interrupt-m" fn isr() {}
   |                        ++
```
-rw-r--r--compiler/rustc_ast_lowering/messages.ftl2
-rw-r--r--compiler/rustc_ast_lowering/src/errors.rs5
-rw-r--r--compiler/rustc_ast_lowering/src/item.rs2
-rw-r--r--tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr19
-rw-r--r--tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr19
-rw-r--r--tests/ui/suggestions/abi-typo.stderr10
6 files changed, 33 insertions, 24 deletions
diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl
index 1b91c33742d..f29c98164d0 100644
--- a/compiler/rustc_ast_lowering/messages.ftl
+++ b/compiler/rustc_ast_lowering/messages.ftl
@@ -88,7 +88,7 @@ ast_lowering_invalid_abi_clobber_abi =
     invalid ABI for `clobber_abi`
     .note = the following ABIs are supported on this target: {$supported_abis}
 
-ast_lowering_invalid_abi_suggestion = did you mean
+ast_lowering_invalid_abi_suggestion = there's a similarly named valid ABI `{$suggestion}`
 
 ast_lowering_invalid_asm_template_modifier_const =
     asm template modifiers are not allowed for `const` arguments
diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs
index f31e2db051d..766c0233408 100644
--- a/compiler/rustc_ast_lowering/src/errors.rs
+++ b/compiler/rustc_ast_lowering/src/errors.rs
@@ -46,8 +46,9 @@ pub(crate) struct TupleStructWithDefault {
 #[derive(Subdiagnostic)]
 #[suggestion(
     ast_lowering_invalid_abi_suggestion,
-    code = "{suggestion}",
-    applicability = "maybe-incorrect"
+    code = "\"{suggestion}\"",
+    applicability = "maybe-incorrect",
+    style = "verbose"
 )]
 pub(crate) struct InvalidAbiSuggestion {
     #[primary_span]
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index a4fc4b3e3a1..15802101f71 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -1510,7 +1510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
             span: abi.span,
             suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
                 span: abi.span,
-                suggestion: format!("\"{suggested_name}\""),
+                suggestion: suggested_name.to_string(),
             }),
             command: "rustc --print=calling-conventions".to_string(),
         });
diff --git a/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr b/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr
index e1f43347985..efa70df9277 100644
--- a/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr
+++ b/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr
@@ -2,23 +2,26 @@ error[E0703]: invalid ABI: found `riscv-interrupt`
   --> $DIR/riscv-discoverability-guidance.rs:17:8
    |
 LL | extern "riscv-interrupt" fn isr() {}
-   |        ^^^^^^^^^^^^^^^^^
-   |        |
-   |        invalid ABI
-   |        help: did you mean: `"riscv-interrupt-m"`
+   |        ^^^^^^^^^^^^^^^^^ invalid ABI
    |
    = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
+help: there's a similarly named valid ABI `riscv-interrupt-m`
+   |
+LL | extern "riscv-interrupt-m" fn isr() {}
+   |                        ++
 
 error[E0703]: invalid ABI: found `riscv-interrupt-u`
   --> $DIR/riscv-discoverability-guidance.rs:22:8
    |
 LL | extern "riscv-interrupt-u" fn isr_U() {}
-   |        ^^^^^^^^^^^^^^^^^^^
-   |        |
-   |        invalid ABI
-   |        help: did you mean: `"riscv-interrupt-m"`
+   |        ^^^^^^^^^^^^^^^^^^^ invalid ABI
    |
    = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
+help: there's a similarly named valid ABI `riscv-interrupt-m`
+   |
+LL - extern "riscv-interrupt-u" fn isr_U() {}
+LL + extern "riscv-interrupt-m" fn isr_U() {}
+   |
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr b/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr
index e1f43347985..efa70df9277 100644
--- a/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr
+++ b/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr
@@ -2,23 +2,26 @@ error[E0703]: invalid ABI: found `riscv-interrupt`
   --> $DIR/riscv-discoverability-guidance.rs:17:8
    |
 LL | extern "riscv-interrupt" fn isr() {}
-   |        ^^^^^^^^^^^^^^^^^
-   |        |
-   |        invalid ABI
-   |        help: did you mean: `"riscv-interrupt-m"`
+   |        ^^^^^^^^^^^^^^^^^ invalid ABI
    |
    = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
+help: there's a similarly named valid ABI `riscv-interrupt-m`
+   |
+LL | extern "riscv-interrupt-m" fn isr() {}
+   |                        ++
 
 error[E0703]: invalid ABI: found `riscv-interrupt-u`
   --> $DIR/riscv-discoverability-guidance.rs:22:8
    |
 LL | extern "riscv-interrupt-u" fn isr_U() {}
-   |        ^^^^^^^^^^^^^^^^^^^
-   |        |
-   |        invalid ABI
-   |        help: did you mean: `"riscv-interrupt-m"`
+   |        ^^^^^^^^^^^^^^^^^^^ invalid ABI
    |
    = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
+help: there's a similarly named valid ABI `riscv-interrupt-m`
+   |
+LL - extern "riscv-interrupt-u" fn isr_U() {}
+LL + extern "riscv-interrupt-m" fn isr_U() {}
+   |
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/suggestions/abi-typo.stderr b/tests/ui/suggestions/abi-typo.stderr
index 5195c43220b..4d89ac16570 100644
--- a/tests/ui/suggestions/abi-typo.stderr
+++ b/tests/ui/suggestions/abi-typo.stderr
@@ -2,12 +2,14 @@ error[E0703]: invalid ABI: found `cdedl`
   --> $DIR/abi-typo.rs:2:8
    |
 LL | extern "cdedl" fn cdedl() {}
-   |        ^^^^^^^
-   |        |
-   |        invalid ABI
-   |        help: did you mean: `"cdecl"`
+   |        ^^^^^^^ invalid ABI
    |
    = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
+help: there's a similarly named valid ABI `cdecl`
+   |
+LL - extern "cdedl" fn cdedl() {}
+LL + extern "cdecl" fn cdedl() {}
+   |
 
 error: aborting due to 1 previous error