Add a helper method for extracting spans from AttrArgsEq
This commit is contained in:
parent
778321d155
commit
c0b532277b
3 changed files with 14 additions and 9 deletions
|
@ -1750,15 +1750,21 @@ pub enum AttrArgsEq {
|
||||||
Hir(MetaItemLit),
|
Hir(MetaItemLit),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AttrArgsEq {
|
||||||
|
pub fn span(&self) -> Span {
|
||||||
|
match self {
|
||||||
|
AttrArgsEq::Ast(p) => p.span,
|
||||||
|
AttrArgsEq::Hir(lit) => lit.span,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AttrArgs {
|
impl AttrArgs {
|
||||||
pub fn span(&self) -> Option<Span> {
|
pub fn span(&self) -> Option<Span> {
|
||||||
match self {
|
match self {
|
||||||
AttrArgs::Empty => None,
|
AttrArgs::Empty => None,
|
||||||
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
|
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
|
||||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => Some(eq_span.to(expr.span)),
|
AttrArgs::Eq { eq_span, value } => Some(eq_span.to(value.span())),
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
|
||||||
unreachable!("in literal form when getting span: {:?}", lit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,9 +220,9 @@ pub fn attrs_to_doc_fragments<'a>(
|
||||||
|
|
||||||
fn span_for_value(attr: &ast::Attribute) -> Span {
|
fn span_for_value(attr: &ast::Attribute) -> Span {
|
||||||
if let ast::AttrKind::Normal(normal) = &attr.kind
|
if let ast::AttrKind::Normal(normal) = &attr.kind
|
||||||
&& let ast::AttrArgs::Eq { value: ast::AttrArgsEq::Hir(meta), .. } = &normal.item.args
|
&& let ast::AttrArgs::Eq { value, .. } = &normal.item.args
|
||||||
{
|
{
|
||||||
meta.span.with_ctxt(attr.span.ctxt())
|
value.span().with_ctxt(attr.span.ctxt())
|
||||||
} else {
|
} else {
|
||||||
attr.span
|
attr.span
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind, Attribute, MetaItemInner};
|
use rustc_ast::{AttrArgs, AttrKind, Attribute, MetaItemInner};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::codes::*;
|
use rustc_errors::codes::*;
|
||||||
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
|
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
|
||||||
|
@ -639,8 +639,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
let report_span = match &item.args {
|
let report_span = match &item.args {
|
||||||
AttrArgs::Empty => item.path.span,
|
AttrArgs::Empty => item.path.span,
|
||||||
AttrArgs::Delimited(args) => args.dspan.entire(),
|
AttrArgs::Delimited(args) => args.dspan.entire(),
|
||||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => eq_span.to(expr.span),
|
AttrArgs::Eq { eq_span, value } => eq_span.to(value.span()),
|
||||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(expr) } => eq_span.to(expr.span),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(item_def_id) = item_def_id.as_local() {
|
if let Some(item_def_id) = item_def_id.as_local() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue