-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Writing a custom crate attribute is impossible with the current plugin system #15778
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
Comments
Is this true for attributes in general? Or only for attributes which are themselves syntax extensions (item decorators / modifiers)? |
Its true for attributes in general, its only turning into an issue if a attribute comes from a |
Attributes don't come from anywhere. They're just nested key/value data that any part of the compiler can query by name. There's no central registration of attributes. Also, plugin loading happens after a full parse and before any syntax expansion. So I'm not sure why the order of a plugin and some attribute the plugin will later check would matter. Can you give a specific example of something you'd like to do with crate attributes that you cannot? For example, this plugin: #![feature(plugin_registrar)]
#![feature(box_syntax)]
extern crate syntax;
#[macro_use] extern crate rustc;
use syntax::{ast, attr};
use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
use rustc::plugin::Registry;
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
struct Pass;
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(CRATE_NOT_OKAY)
}
fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) {
if !attr::contains_name(&krate.attrs, "crate_okay") {
cx.span_lint(CRATE_NOT_OKAY, krate.span,
"crate is not marked with #![crate_okay]");
}
}
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_lint_pass(box Pass as LintPassObject);
} works as expected:
|
Hm, it might be that since I opened this issue the plugin system changed in a way that makes this work. I'll have to check with the code that had this issue... |
I added a regression test for the original issue. Please open a new ticket if you find something that's still broken :) |
Currently, its not possible to write a custom attribute that applies to the crate, due to the way syntax extensions and the module system works.
Possible solutions
The text was updated successfully, but these errors were encountered: