Adressed PR comments.
This commit is contained in:
parent
a5e5ea1646
commit
5553901146
@ -367,18 +367,18 @@ pub fn gather_attr(attr: &ast::Attribute)
|
||||
|
||||
let meta = &attr.node.value;
|
||||
let metas = if let Some(metas) = meta.meta_item_list() {
|
||||
metas
|
||||
} else {
|
||||
out.push(Err(meta.span));
|
||||
return out;
|
||||
};
|
||||
metas
|
||||
} else {
|
||||
out.push(Err(meta.span));
|
||||
return out;
|
||||
};
|
||||
|
||||
for meta in metas {
|
||||
out.push(if meta.is_word() {
|
||||
Ok((meta.name().clone(), level, meta.span))
|
||||
} else {
|
||||
Err(meta.span)
|
||||
});
|
||||
Ok((meta.name().clone(), level, meta.span))
|
||||
} else {
|
||||
Err(meta.span)
|
||||
});
|
||||
}
|
||||
|
||||
out
|
||||
|
@ -394,11 +394,10 @@ fn check_cfg(sopts: &config::Options,
|
||||
let mut saw_invalid_predicate = false;
|
||||
for item in sopts.cfg.iter() {
|
||||
if item.is_meta_item_list() {
|
||||
saw_invalid_predicate = true;
|
||||
saw_invalid_predicate = true;
|
||||
handler.emit(&MultiSpan::new(),
|
||||
&format!("invalid predicate in --cfg command line argument: `{}`",
|
||||
pred),
|
||||
item.name()),
|
||||
errors::Level::Fatal);
|
||||
}
|
||||
}
|
||||
@ -651,10 +650,8 @@ impl RustcDefaultCalls {
|
||||
if cfg.is_word() {
|
||||
println!("{}", cfg.name());
|
||||
} else if cfg.is_value_str() {
|
||||
let rhs = cfg.value_str();
|
||||
match rhs {
|
||||
Some(s) => println!("{}=\"{}\"", cfg.name(), s),
|
||||
None => continue,
|
||||
if let Some(s) = cfg.value_str() {
|
||||
println!("{}=\"{}\"", cfg.name(), s);
|
||||
}
|
||||
} else if cfg.is_meta_item_list() {
|
||||
// Right now there are not and should not be any
|
||||
|
@ -114,9 +114,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
|
||||
id = Some(meta_item.name().clone());
|
||||
} else {
|
||||
// FIXME better-encapsulate meta_item (don't directly access `node`)
|
||||
self.tcx.sess.span_err(
|
||||
meta_item.span(),
|
||||
&format!("unexpected meta-item {:?}", meta_item.node));
|
||||
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node)
|
||||
}
|
||||
}
|
||||
let id = id.unwrap_or(InternedString::new(ID));
|
||||
@ -133,9 +131,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
|
||||
id = Some(meta_item.name().clone());
|
||||
} else {
|
||||
// FIXME better-encapsulate meta_item (don't directly access `node`)
|
||||
self.tcx.sess.span_err(
|
||||
meta_item.span(),
|
||||
&format!("unexpected meta-item {:?}", meta_item.node));
|
||||
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node)
|
||||
}
|
||||
}
|
||||
let dep_node = match dep_node_interned {
|
||||
|
@ -298,13 +298,7 @@ impl MissingDoc {
|
||||
}
|
||||
}
|
||||
|
||||
let has_doc = attrs.iter().any(|a| {
|
||||
if a.is_value_str() && a.name() == "doc" {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.name() == "doc");
|
||||
if !has_doc {
|
||||
cx.span_lint(MISSING_DOCS, sp,
|
||||
&format!("missing documentation for {}", desc));
|
||||
|
@ -504,7 +504,7 @@ impl Clean<Attribute> for ast::MetaItem {
|
||||
NameValue(self.name().to_string(), v.to_string())
|
||||
} else { // must be a list
|
||||
let l = self.meta_item_list().unwrap();
|
||||
List(self.name().to_string(), l.clean(cx))
|
||||
List(self.name().to_string(), l.clean(cx))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2589,26 +2589,6 @@ impl ToSource for syntax_pos::Span {
|
||||
}
|
||||
}
|
||||
|
||||
// fn lit_to_string(lit: &ast::Lit) -> String {
|
||||
// match lit.node {
|
||||
// ast::LitKind::Str(ref st, _) => st.to_string(),
|
||||
// ast::LitKind::ByteStr(ref data) => format!("{:?}", data),
|
||||
// ast::LitKind::Byte(b) => {
|
||||
// let mut res = String::from("b'");
|
||||
// for c in (b as char).escape_default() {
|
||||
// res.push(c);
|
||||
// }
|
||||
// res.push('\'');
|
||||
// res
|
||||
// },
|
||||
// ast::LitKind::Char(c) => format!("'{}'", c),
|
||||
// ast::LitKind::Int(i, _t) => i.to_string(),
|
||||
// ast::LitKind::Float(ref f, _t) => f.to_string(),
|
||||
// ast::LitKind::FloatUnsuffixed(ref f) => f.to_string(),
|
||||
// ast::LitKind::Bool(b) => b.to_string(),
|
||||
// }
|
||||
// }
|
||||
|
||||
fn name_from_pat(p: &hir::Pat) -> String {
|
||||
use rustc::hir::*;
|
||||
debug!("Trying to get a name from pattern: {:?}", p);
|
||||
|
@ -94,10 +94,16 @@ pub trait AttrMetaMethods {
|
||||
|
||||
/// Indicates if the attribute is a Word.
|
||||
fn is_word(&self) -> bool;
|
||||
|
||||
/// Indicates if the attribute is a Value String.
|
||||
fn is_value_str(&self) -> bool;
|
||||
fn is_value_str(&self) -> bool {
|
||||
self.value_str().is_some()
|
||||
}
|
||||
|
||||
/// Indicates if the attribute is a Meta-Item List.
|
||||
fn is_meta_item_list(&self) -> bool;
|
||||
fn is_meta_item_list(&self) -> bool {
|
||||
self.meta_item_list().is_some()
|
||||
}
|
||||
|
||||
fn span(&self) -> Span;
|
||||
}
|
||||
@ -119,9 +125,6 @@ impl AttrMetaMethods for Attribute {
|
||||
}
|
||||
|
||||
fn is_word(&self) -> bool { self.meta().is_word() }
|
||||
fn is_value_str(&self) -> bool { self.meta().is_value_str() }
|
||||
|
||||
fn is_meta_item_list(&self) -> bool { self.meta().is_meta_item_list() }
|
||||
|
||||
fn span(&self) -> Span { self.meta().span }
|
||||
}
|
||||
@ -161,10 +164,6 @@ impl AttrMetaMethods for MetaItem {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_value_str(&self) -> bool { self.value_str().is_some() }
|
||||
|
||||
fn is_meta_item_list(&self) -> bool { self.meta_item_list().is_some() }
|
||||
|
||||
fn span(&self) -> Span { self.span }
|
||||
}
|
||||
|
||||
@ -240,7 +239,7 @@ pub fn mk_word_item(name: InternedString) -> P<MetaItem> {
|
||||
|
||||
pub fn mk_spanned_name_value_item(sp: Span, name: InternedString, value: ast::Lit)
|
||||
-> P<MetaItem> {
|
||||
P(respan(sp,MetaItemKind::NameValue(name, value)))
|
||||
P(respan(sp, MetaItemKind::NameValue(name, value)))
|
||||
}
|
||||
|
||||
pub fn mk_spanned_list_item(sp: Span, name: InternedString, items: Vec<P<MetaItem>>)
|
||||
@ -249,7 +248,7 @@ pub fn mk_spanned_list_item(sp: Span, name: InternedString, items: Vec<P<MetaIte
|
||||
}
|
||||
|
||||
pub fn mk_spanned_word_item(sp: Span, name: InternedString) -> P<MetaItem> {
|
||||
P(respan(sp,MetaItemKind::Word(name)))
|
||||
P(respan(sp, MetaItemKind::Word(name)))
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,6 +254,10 @@ pub const NO_EXPANSION: ExpnId = ExpnId(!0);
|
||||
// For code appearing from the command line
|
||||
pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(!1);
|
||||
|
||||
// For code generated by a procedural macro, without knowing which
|
||||
// Used in `qquote!`
|
||||
pub const PROC_EXPN: ExpnId = ExpnId(!2);
|
||||
|
||||
impl ExpnId {
|
||||
pub fn from_u32(id: u32) -> ExpnId {
|
||||
ExpnId(id)
|
||||
|
Loading…
Reference in New Issue
Block a user