Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stop reporting missing-unsafe errors in embedded exceptions #9154

Closed
niuiic opened this issue Jun 6, 2021 · 2 comments
Closed

How to stop reporting missing-unsafe errors in embedded exceptions #9154

niuiic opened this issue Jun 6, 2021 · 2 comments

Comments

@niuiic
Copy link

niuiic commented Jun 6, 2021

The code is copied from embedded book, and it doesn't cause any error during compiling. But rust-analyzer reports six errors about missing-unsafe. And there is another error says that Function SysTick should have snake_case name. However, sys_tick really cause an error. It's not a valid exception name.

#[exception]
fn SysTick() {
    static mut COUNT: u32 = 0;
    static mut STDOUT: Option<HStdout> = None;

    *COUNT += 1;

    // Lazy initialization
    if STDOUT.is_none() {
        *STDOUT = hio::hstdout().ok();
    }

    if let Some(hstdout) = STDOUT.as_mut() {
        write!(hstdout, "{}", *COUNT).ok();
    }

    // IMPORTANT omit this `if` block if running on real hardware or your
    // debugger will end in an inconsistent state
    if *COUNT == 9 {
        // This will terminate the QEMU process
        debug::exit(debug::EXIT_SUCCESS);
    }
}

Here is my configuration about rust-analyzer.

  "rust-analyzer.diagnostics.disabled": ["unresolved-macro-call"],
  "rust-analyzer.checkOnSave.target": "thumbv7m-none-eabi",
  "rust-analyzer.checkOnSave.allTargets": false,
  "rust-analyzer.lens.methodReferences": true,
  "rust-analyzer.cargo.loadOutDirsFromCheck": true,
  "rust-analyzer.procMacro.enable": true,
  "rust-analyzer.lruCapacity": 1000,
  "rust-analyzer.updates.channel": "nightly",
  "rust-analyzer.hoverActions.linksInHover": true,

Thank you.

@jonas-schievink
Copy link
Contributor

All diagnostics report their identifier, which you can add to the diagnostics.disabled list you're already using. This will silence the diagnostic.

Note that the reason we report these diagnostics in the first place is because we do not expand the #[exception] macro. This is being worked on and we've landed experimental support for this in #9128, so you can also try that out (this currently breaks IDE functionality within the annotated function, so this is probably not quite usable in your case).

@niuiic
Copy link
Author

niuiic commented Jun 7, 2021

Thank you for your help. Now there is no error and can be formatted.

@niuiic niuiic closed this as completed Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants