-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement RFC#1559: allow all literals in attributes #35850
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 |
---|---|---|
|
@@ -56,7 +56,7 @@ use std::env; | |
use std::fs::File; | ||
use std::io::Write; | ||
use syntax::ast; | ||
use syntax::attr::AttrMetaMethods; | ||
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods}; | ||
use syntax::parse::token::InternedString; | ||
use syntax_pos::Span; | ||
|
||
|
@@ -116,31 +116,40 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { | |
for attr in self.tcx.get_attrs(def_id).iter() { | ||
if attr.check_name(IF_THIS_CHANGED) { | ||
let mut id = None; | ||
for meta_item in attr.meta_item_list().unwrap_or_default() { | ||
if meta_item.is_word() && id.is_none() { | ||
id = Some(meta_item.name().clone()); | ||
} else { | ||
// FIXME better-encapsulate meta_item (don't directly access `node`) | ||
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node) | ||
for list_item in attr.meta_item_list().unwrap_or_default() { | ||
match list_item.word() { | ||
Some(word) if id.is_none() => { | ||
id = Some(word.name().clone()) | ||
}, | ||
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.
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. This happens in a lot of places without a similar comment. Is it more important to place such a comment here than in other places? 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. I added those fixmes; ultimately, there should be some encapsulation to make meta-items more opaque (so that their internal representation is less obvious and more resilient to changes). If it's done other places, this fixme should be added there, too. 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. Okay, I'll re-add them. |
||
_ => { | ||
// FIXME better-encapsulate meta_item (don't directly access `node`) | ||
span_bug!(list_item.span(), "unexpected list-item {:?}", list_item.node) | ||
} | ||
} | ||
} | ||
|
||
let id = id.unwrap_or(InternedString::new(ID)); | ||
self.if_this_changed.entry(id) | ||
.or_insert(FnvHashSet()) | ||
.insert((attr.span, def_id, DepNode::Hir(def_id))); | ||
} else if attr.check_name(THEN_THIS_WOULD_NEED) { | ||
let mut dep_node_interned = None; | ||
let mut id = None; | ||
for meta_item in attr.meta_item_list().unwrap_or_default() { | ||
if meta_item.is_word() && dep_node_interned.is_none() { | ||
dep_node_interned = Some(meta_item.name().clone()); | ||
} else if meta_item.is_word() && id.is_none() { | ||
id = Some(meta_item.name().clone()); | ||
} else { | ||
// FIXME better-encapsulate meta_item (don't directly access `node`) | ||
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node) | ||
for list_item in attr.meta_item_list().unwrap_or_default() { | ||
match list_item.word() { | ||
Some(word) if dep_node_interned.is_none() => { | ||
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. Same as above; FIXME might still need to be kept. 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. Okay, I'll re-add them. |
||
dep_node_interned = Some(word.name().clone()); | ||
}, | ||
Some(word) if id.is_none() => { | ||
id = Some(word.name().clone()) | ||
}, | ||
_ => { | ||
// FIXME better-encapsulate meta_item (don't directly access `node`) | ||
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item.node) | ||
} | ||
} | ||
} | ||
|
||
let dep_node = match dep_node_interned { | ||
Some(ref n) => { | ||
match DepNode::from_label_string(&n[..], def_id) { | ||
|
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.
Given that this is not meant to be a user-facing error message, I don't think we need two different messages
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 two different error messages should help out if the conditions are ever hit. I propose we keep them: doing so doesn't hurt and can only help.