Skip to content

The #[panic_handler] attribute can be applied to non-functions #54896

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

Closed
phil-opp opened this issue Oct 7, 2018 · 3 comments
Closed

The #[panic_handler] attribute can be applied to non-functions #54896

phil-opp opened this issue Oct 7, 2018 · 3 comments
Assignees
Labels
P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@phil-opp
Copy link
Contributor

phil-opp commented Oct 7, 2018

It's possible to apply the panic_handler attribute to an extern crate statement without errror:

#[panic_handler]
extern crate some_example_crate;

It only causes a linker error:

rust-lld: error: undefined symbol: rust_begin_unwind

(When the panic_handler attribute is not defined there is a much better "#[panic_handler] function required, but not found" error. There is also a nice error when the function signature is wrong. But it seems like the above case is not handled.)

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

cc @japaric

@Centril Centril added P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 8, 2018
@japaric
Copy link
Member

japaric commented Oct 9, 2018

I'm very busy this week and probably won't have time to look at this until next Wednesday but if someone wants to take a stab at this I would look for the logic used by #[global_allocator]: that attribute gives you "error: allocators must be statics" when applied to non-static items.

@pnkfelix
Copy link
Member

Visited for triage. Does not seem super critical to resolve immediately. Putting on the Release milestone (rather than RC2) to reflect this, and also downgrading priority to P-medium.

@pnkfelix pnkfelix added this to the Rust 2018 Release milestone Oct 11, 2018
@pnkfelix pnkfelix added P-medium Medium priority and removed P-high High priority labels Oct 11, 2018
@davidtwco davidtwco self-assigned this Oct 11, 2018
bors added a commit that referenced this issue Oct 13, 2018
The #[panic_handler] attribute can be applied to non-functions

Fixes #54896.

This commit extends the existing lang items functionality to assert
that the `#[lang_item]` attribute is only found on the appropriate item
for any given lang item. That is, language items representing traits
must only ever have their corresponding attribute placed on a trait, for
example.

r? @nagisa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants