-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add support for registering attributes with rustc in plugins #25168
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// force-host | ||
|
||
#![feature(plugin_registrar)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate syntax; | ||
|
||
extern crate rustc; | ||
|
||
use syntax::feature_gate::AttributeType; | ||
use rustc::plugin::Registry; | ||
|
||
|
||
|
||
#[plugin_registrar] | ||
pub fn plugin_registrar(reg: &mut Registry) { | ||
reg.register_attribute("foo".to_owned(), AttributeType::Normal); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, what's the point of registering a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, it gets an unused attribute warning, but it doesn't get the custom_attribute feature gate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
reg.register_attribute("bar".to_owned(), AttributeType::CrateLevel); | ||
reg.register_attribute("baz".to_owned(), AttributeType::Whitelisted); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:attr_plugin_test.rs | ||
// ignore-stage1 | ||
|
||
#![feature(plugin)] | ||
#![plugin(attr_plugin_test)] | ||
#![deny(unused_attributes)] | ||
|
||
#[baz] | ||
fn baz() { } // no error | ||
|
||
#[foo] | ||
pub fn main() { | ||
//~^^ ERROR unused | ||
#[bar] | ||
fn inner() {} | ||
//~^^ ERROR crate | ||
//~^^^ ERROR unused | ||
baz(); | ||
inner(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it more that plugins register "known" attributes, i.e. they no longer count as custom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code does feature gating of specific attrs; even if custom_attribute is on, attributes like
rustc_on_unimplemented
can't be used until the specific feature is turned on.AttributeType
has aGated
variant that we check for in the code above, but we don't do that here sinceplugin_attributes
cannot containGated
types.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code below doesn't look at
Gated
attributes at all, the only reason for this shortcircuit to exist here would be to avoid thecustom_attribute
feature gate. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above, not below
https://github.com/rust-lang/rust/pull/25168/files#diff-8fe611e80215042c8d89714f4dd6f8baR382
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so the comment is just contrasting to the behaviour of the code above. Makes sense.
Could you still point out that the loop is still necessary to short-circuit to avoid the checks below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed