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 {
|
pub fn is_meta_item_list(&self) -> bool {
|
||||||
self.meta_item_list().is_some()
|
self.meta_item_list().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn name_value_literal_span(&self) -> Option<Span> {
|
||||||
|
self.meta_item()?.name_value_literal_span()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Attribute {
|
impl Attribute {
|
||||||
|
@ -175,6 +179,13 @@ impl Attribute {
|
||||||
pub fn is_value_str(&self) -> bool {
|
pub fn is_value_str(&self) -> bool {
|
||||||
self.value_str().is_some()
|
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 {
|
impl MetaItem {
|
||||||
|
@ -227,6 +238,10 @@ impl MetaItem {
|
||||||
pub fn is_value_str(&self) -> bool {
|
pub fn is_value_str(&self) -> bool {
|
||||||
self.value_str().is_some()
|
self.value_str().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn name_value_literal_span(&self) -> Option<Span> {
|
||||||
|
Some(self.name_value_literal()?.span)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AttrItem {
|
impl AttrItem {
|
||||||
|
|
|
@ -294,7 +294,7 @@ where
|
||||||
or \"none\"",
|
or \"none\"",
|
||||||
)
|
)
|
||||||
.span_label(
|
.span_label(
|
||||||
mi.name_value_literal().unwrap().span,
|
mi.name_value_literal_span().unwrap(),
|
||||||
msg,
|
msg,
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
|
|
@ -1603,23 +1603,22 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||||
items.push(ast::NestedMetaItem::MetaItem(item));
|
items.push(ast::NestedMetaItem::MetaItem(item));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let lit =
|
let lit_span = it.name_value_literal_span().unwrap();
|
||||||
it.meta_item().and_then(|item| item.name_value_literal()).unwrap();
|
|
||||||
|
|
||||||
if e.kind() == ErrorKind::InvalidData {
|
if e.kind() == ErrorKind::InvalidData {
|
||||||
self.cx
|
self.cx
|
||||||
.struct_span_err(
|
.struct_span_err(
|
||||||
lit.span,
|
lit_span,
|
||||||
&format!("{} wasn't a utf-8 file", filename.display()),
|
&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();
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
let mut err = self.cx.struct_span_err(
|
let mut err = self.cx.struct_span_err(
|
||||||
lit.span,
|
lit_span,
|
||||||
&format!("couldn't read {}: {}", filename.display(), e),
|
&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();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,7 @@ fn update_limit(
|
||||||
|
|
||||||
let value_span = attr
|
let value_span = attr
|
||||||
.meta()
|
.meta()
|
||||||
.and_then(|meta| meta.name_value_literal().cloned())
|
.and_then(|meta| meta.name_value_literal_span())
|
||||||
.map(|lit| lit.span)
|
|
||||||
.unwrap_or(attr.span);
|
.unwrap_or(attr.span);
|
||||||
|
|
||||||
let error_str = match e.kind() {
|
let error_str = match e.kind() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue