Skip to content

The help message when an invalid calling convention is specified is getting a little unwieldy #93601

Closed
@nagisa

Description

@nagisa
Member

After #93561 misspelling a calling convention will output the following note:

LL | extern "路濫狼á́́" fn foo() {}
   |        ^^^^^^^^^ invalid ABI
   |
   = help: valid ABIs: Rust, C, C-unwind, cdecl, cdecl-unwind, stdcall, stdcall-unwind, fastcall, fastcall-unwind, vectorcall, vectorcall-unwind, thiscall, thiscall-unwind, aapcs, aapcs-unwind, win64, win64-unwind, sysv64, sysv64-unwind, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted

This is getting pretty hard to read!

There are a couple of improvements we could make:

  1. Invoke Levenshtein magic and only suggest some calling conventions that are close, if any (covers mis-spellings);
    • This could be a MachineApplicable::MaybeIncorrect rustfix!
  2. Suggest at most a couple of the most common ABIs (possibly a target-specific list?);
  3. Do not suggest CCs that cannot be used due to them being unstable and feature not being enabled; and finally
  4. Explain where to find a full list (may involve adding CLI surface to rustc).

With these suggestions in place the message could look like:

LL | extern "wni64" fn foo() {}
   |        ^^^^^^^ invalid ABI
   |
   = help: did you mean `win64`?
   = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions

or

LL | extern "路濫狼á́́" fn foo() {}
   |        ^^^^^^^^^ invalid ABI
   |
   = help: commonly used calling conventions include: `C`, `system`, `sysv64`, `win64` and `wasm`
   = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
on Feb 2, 2022
added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
on Jun 20, 2022
ritobanrc

ritobanrc commented on Jul 4, 2022

@ritobanrc

I'd be interested in tackling this, though it would be my first contribution, so I'll probably need some additional guidance.

ritobanrc

ritobanrc commented on Jul 4, 2022

@ritobanrc

@rustbot claim

khyperia

khyperia commented on Aug 13, 2022

@khyperia
Contributor

Hey, are you still working on this? If not, I'm going to take a shot at it 🙂

ritobanrc

ritobanrc commented on Aug 13, 2022

@ritobanrc
added a commit that references this issue on Sep 23, 2022

Auto merge of rust-lang#100488 - khyperia:invalid-calling-convention-…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @nagisa@khyperia@compiler-errors@ritobanrc

      Issue actions

        The help message when an invalid calling convention is specified is getting a little unwieldy · Issue #93601 · rust-lang/rust