Skip to content

Commit

Permalink
Adressed PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgswords committed Jul 25, 2016
1 parent a5e5ea1 commit 5553901
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 60 deletions.
18 changes: 9 additions & 9 deletions src/librustc/lint/context.rs
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_driver/lib.rs
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_incremental/assert_dep_graph.rs
Expand Up @@ -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));
Expand All @@ -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 {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_lint/builtin.rs
Expand Up @@ -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));
Expand Down
22 changes: 1 addition & 21 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions src/libsyntax/attr.rs
Expand Up @@ -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;
}
Expand All @@ -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 }
}
Expand Down Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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>>)
Expand All @@ -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)))
}


Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax_pos/lib.rs
Expand Up @@ -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)
Expand Down

0 comments on commit 5553901

Please sign in to comment.