-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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()) | ||
| }, | ||
|
||
| _ => { | ||
| // 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() => { | ||
|
||
| 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.