Skip to content

Commit 5553901

Browse files
committed
Adressed PR comments.
1 parent a5e5ea1 commit 5553901

File tree

7 files changed

+30
-60
lines changed

7 files changed

+30
-60
lines changed

src/librustc/lint/context.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,18 @@ pub fn gather_attr(attr: &ast::Attribute)
367367

368368
let meta = &attr.node.value;
369369
let metas = if let Some(metas) = meta.meta_item_list() {
370-
metas
371-
} else {
372-
out.push(Err(meta.span));
373-
return out;
374-
};
370+
metas
371+
} else {
372+
out.push(Err(meta.span));
373+
return out;
374+
};
375375

376376
for meta in metas {
377377
out.push(if meta.is_word() {
378-
Ok((meta.name().clone(), level, meta.span))
379-
} else {
380-
Err(meta.span)
381-
});
378+
Ok((meta.name().clone(), level, meta.span))
379+
} else {
380+
Err(meta.span)
381+
});
382382
}
383383

384384
out

src/librustc_driver/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,10 @@ fn check_cfg(sopts: &config::Options,
394394
let mut saw_invalid_predicate = false;
395395
for item in sopts.cfg.iter() {
396396
if item.is_meta_item_list() {
397-
saw_invalid_predicate = true;
398397
saw_invalid_predicate = true;
399398
handler.emit(&MultiSpan::new(),
400399
&format!("invalid predicate in --cfg command line argument: `{}`",
401-
pred),
400+
item.name()),
402401
errors::Level::Fatal);
403402
}
404403
}
@@ -651,10 +650,8 @@ impl RustcDefaultCalls {
651650
if cfg.is_word() {
652651
println!("{}", cfg.name());
653652
} else if cfg.is_value_str() {
654-
let rhs = cfg.value_str();
655-
match rhs {
656-
Some(s) => println!("{}=\"{}\"", cfg.name(), s),
657-
None => continue,
653+
if let Some(s) = cfg.value_str() {
654+
println!("{}=\"{}\"", cfg.name(), s);
658655
}
659656
} else if cfg.is_meta_item_list() {
660657
// Right now there are not and should not be any

src/librustc_incremental/assert_dep_graph.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
114114
id = Some(meta_item.name().clone());
115115
} else {
116116
// FIXME better-encapsulate meta_item (don't directly access `node`)
117-
self.tcx.sess.span_err(
118-
meta_item.span(),
119-
&format!("unexpected meta-item {:?}", meta_item.node));
117+
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node)
120118
}
121119
}
122120
let id = id.unwrap_or(InternedString::new(ID));
@@ -133,9 +131,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
133131
id = Some(meta_item.name().clone());
134132
} else {
135133
// FIXME better-encapsulate meta_item (don't directly access `node`)
136-
self.tcx.sess.span_err(
137-
meta_item.span(),
138-
&format!("unexpected meta-item {:?}", meta_item.node));
134+
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node)
139135
}
140136
}
141137
let dep_node = match dep_node_interned {

src/librustc_lint/builtin.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,7 @@ impl MissingDoc {
298298
}
299299
}
300300

301-
let has_doc = attrs.iter().any(|a| {
302-
if a.is_value_str() && a.name() == "doc" {
303-
true
304-
} else {
305-
false
306-
}
307-
});
301+
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.name() == "doc");
308302
if !has_doc {
309303
cx.span_lint(MISSING_DOCS, sp,
310304
&format!("missing documentation for {}", desc));

src/librustdoc/clean/mod.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl Clean<Attribute> for ast::MetaItem {
504504
NameValue(self.name().to_string(), v.to_string())
505505
} else { // must be a list
506506
let l = self.meta_item_list().unwrap();
507-
List(self.name().to_string(), l.clean(cx))
507+
List(self.name().to_string(), l.clean(cx))
508508
}
509509
}
510510
}
@@ -2589,26 +2589,6 @@ impl ToSource for syntax_pos::Span {
25892589
}
25902590
}
25912591

2592-
// fn lit_to_string(lit: &ast::Lit) -> String {
2593-
// match lit.node {
2594-
// ast::LitKind::Str(ref st, _) => st.to_string(),
2595-
// ast::LitKind::ByteStr(ref data) => format!("{:?}", data),
2596-
// ast::LitKind::Byte(b) => {
2597-
// let mut res = String::from("b'");
2598-
// for c in (b as char).escape_default() {
2599-
// res.push(c);
2600-
// }
2601-
// res.push('\'');
2602-
// res
2603-
// },
2604-
// ast::LitKind::Char(c) => format!("'{}'", c),
2605-
// ast::LitKind::Int(i, _t) => i.to_string(),
2606-
// ast::LitKind::Float(ref f, _t) => f.to_string(),
2607-
// ast::LitKind::FloatUnsuffixed(ref f) => f.to_string(),
2608-
// ast::LitKind::Bool(b) => b.to_string(),
2609-
// }
2610-
// }
2611-
26122592
fn name_from_pat(p: &hir::Pat) -> String {
26132593
use rustc::hir::*;
26142594
debug!("Trying to get a name from pattern: {:?}", p);

src/libsyntax/attr.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ pub trait AttrMetaMethods {
9494

9595
/// Indicates if the attribute is a Word.
9696
fn is_word(&self) -> bool;
97+
9798
/// Indicates if the attribute is a Value String.
98-
fn is_value_str(&self) -> bool;
99+
fn is_value_str(&self) -> bool {
100+
self.value_str().is_some()
101+
}
102+
99103
/// Indicates if the attribute is a Meta-Item List.
100-
fn is_meta_item_list(&self) -> bool;
104+
fn is_meta_item_list(&self) -> bool {
105+
self.meta_item_list().is_some()
106+
}
101107

102108
fn span(&self) -> Span;
103109
}
@@ -119,9 +125,6 @@ impl AttrMetaMethods for Attribute {
119125
}
120126

121127
fn is_word(&self) -> bool { self.meta().is_word() }
122-
fn is_value_str(&self) -> bool { self.meta().is_value_str() }
123-
124-
fn is_meta_item_list(&self) -> bool { self.meta().is_meta_item_list() }
125128

126129
fn span(&self) -> Span { self.meta().span }
127130
}
@@ -161,10 +164,6 @@ impl AttrMetaMethods for MetaItem {
161164
}
162165
}
163166

164-
fn is_value_str(&self) -> bool { self.value_str().is_some() }
165-
166-
fn is_meta_item_list(&self) -> bool { self.meta_item_list().is_some() }
167-
168167
fn span(&self) -> Span { self.span }
169168
}
170169

@@ -240,7 +239,7 @@ pub fn mk_word_item(name: InternedString) -> P<MetaItem> {
240239

241240
pub fn mk_spanned_name_value_item(sp: Span, name: InternedString, value: ast::Lit)
242241
-> P<MetaItem> {
243-
P(respan(sp,MetaItemKind::NameValue(name, value)))
242+
P(respan(sp, MetaItemKind::NameValue(name, value)))
244243
}
245244

246245
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
249248
}
250249

251250
pub fn mk_spanned_word_item(sp: Span, name: InternedString) -> P<MetaItem> {
252-
P(respan(sp,MetaItemKind::Word(name)))
251+
P(respan(sp, MetaItemKind::Word(name)))
253252
}
254253

255254

src/libsyntax_pos/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ pub const NO_EXPANSION: ExpnId = ExpnId(!0);
254254
// For code appearing from the command line
255255
pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(!1);
256256

257+
// For code generated by a procedural macro, without knowing which
258+
// Used in `qquote!`
259+
pub const PROC_EXPN: ExpnId = ExpnId(!2);
260+
257261
impl ExpnId {
258262
pub fn from_u32(id: u32) -> ExpnId {
259263
ExpnId(id)

0 commit comments

Comments
 (0)