Created NestedMetaItem::name_value_literal_span method
This commit is contained in:
parent
0fa9d31c41
commit
7df0052df8
4 changed files with 22 additions and 9 deletions
|
@ -115,6 +115,10 @@ impl NestedMetaItem {
|
|||
pub fn is_meta_item_list(&self) -> bool {
|
||||
self.meta_item_list().is_some()
|
||||
}
|
||||
|
||||
pub fn name_value_literal_span(&self) -> Option<Span> {
|
||||
self.meta_item()?.name_value_literal_span()
|
||||
}
|
||||
}
|
||||
|
||||
impl Attribute {
|
||||
|
@ -175,6 +179,13 @@ impl Attribute {
|
|||
pub fn is_value_str(&self) -> bool {
|
||||
self.value_str().is_some()
|
||||
}
|
||||
|
||||
pub fn name_value_literal_span(&self) -> Option<Span> {
|
||||
match self.kind {
|
||||
AttrKind::Normal(ref item, _) => item.meta(self.span).and_then(|meta| meta.name_value_literal_span()),
|
||||
AttrKind::DocComment(..) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaItem {
|
||||
|
@ -227,6 +238,10 @@ impl MetaItem {
|
|||
pub fn is_value_str(&self) -> bool {
|
||||
self.value_str().is_some()
|
||||
}
|
||||
|
||||
pub fn name_value_literal_span(&self) -> Option<Span> {
|
||||
Some(self.name_value_literal()?.span)
|
||||
}
|
||||
}
|
||||
|
||||
impl AttrItem {
|
||||
|
|
|
@ -294,7 +294,7 @@ where
|
|||
or \"none\"",
|
||||
)
|
||||
.span_label(
|
||||
mi.name_value_literal().unwrap().span,
|
||||
mi.name_value_literal_span().unwrap(),
|
||||
msg,
|
||||
)
|
||||
.emit();
|
||||
|
|
|
@ -1603,23 +1603,22 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||
items.push(ast::NestedMetaItem::MetaItem(item));
|
||||
}
|
||||
Err(e) => {
|
||||
let lit =
|
||||
it.meta_item().and_then(|item| item.name_value_literal()).unwrap();
|
||||
let lit_span = it.name_value_literal_span().unwrap();
|
||||
|
||||
if e.kind() == ErrorKind::InvalidData {
|
||||
self.cx
|
||||
.struct_span_err(
|
||||
lit.span,
|
||||
lit_span,
|
||||
&format!("{} wasn't a utf-8 file", filename.display()),
|
||||
)
|
||||
.span_label(lit.span, "contains invalid utf-8")
|
||||
.span_label(lit_span, "contains invalid utf-8")
|
||||
.emit();
|
||||
} else {
|
||||
let mut err = self.cx.struct_span_err(
|
||||
lit.span,
|
||||
lit_span,
|
||||
&format!("couldn't read {}: {}", filename.display(), e),
|
||||
);
|
||||
err.span_label(lit.span, "couldn't read file");
|
||||
err.span_label(lit_span, "couldn't read file");
|
||||
|
||||
err.emit();
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ fn update_limit(
|
|||
|
||||
let value_span = attr
|
||||
.meta()
|
||||
.and_then(|meta| meta.name_value_literal().cloned())
|
||||
.map(|lit| lit.span)
|
||||
.and_then(|meta| meta.name_value_literal_span())
|
||||
.unwrap_or(attr.span);
|
||||
|
||||
let error_str = match e.kind() {
|
||||
|
|
Loading…
Add table
Reference in a new issue