Skip to content

Commit c0b5322

Browse files
committed
Add a helper method for extracting spans from AttrArgsEq
1 parent 778321d commit c0b5322

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1750,15 +1750,21 @@ pub enum AttrArgsEq {
17501750
Hir(MetaItemLit),
17511751
}
17521752

1753+
impl AttrArgsEq {
1754+
pub fn span(&self) -> Span {
1755+
match self {
1756+
AttrArgsEq::Ast(p) => p.span,
1757+
AttrArgsEq::Hir(lit) => lit.span,
1758+
}
1759+
}
1760+
}
1761+
17531762
impl AttrArgs {
17541763
pub fn span(&self) -> Option<Span> {
17551764
match self {
17561765
AttrArgs::Empty => None,
17571766
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
1758-
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => Some(eq_span.to(expr.span)),
1759-
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
1760-
unreachable!("in literal form when getting span: {:?}", lit);
1761-
}
1767+
AttrArgs::Eq { eq_span, value } => Some(eq_span.to(value.span())),
17621768
}
17631769
}
17641770

Diff for: compiler/rustc_resolve/src/rustdoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ pub fn attrs_to_doc_fragments<'a>(
220220

221221
fn span_for_value(attr: &ast::Attribute) -> Span {
222222
if let ast::AttrKind::Normal(normal) = &attr.kind
223-
&& let ast::AttrArgs::Eq { value: ast::AttrArgsEq::Hir(meta), .. } = &normal.item.args
223+
&& let ast::AttrArgs::Eq { value, .. } = &normal.item.args
224224
{
225-
meta.span.with_ctxt(attr.span.ctxt())
225+
value.span().with_ctxt(attr.span.ctxt())
226226
} else {
227227
attr.span
228228
}

Diff for: compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter;
22
use std::path::PathBuf;
33

4-
use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind, Attribute, MetaItemInner};
4+
use rustc_ast::{AttrArgs, AttrKind, Attribute, MetaItemInner};
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_errors::codes::*;
77
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
@@ -639,8 +639,7 @@ impl<'tcx> OnUnimplementedDirective {
639639
let report_span = match &item.args {
640640
AttrArgs::Empty => item.path.span,
641641
AttrArgs::Delimited(args) => args.dspan.entire(),
642-
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => eq_span.to(expr.span),
643-
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(expr) } => eq_span.to(expr.span),
642+
AttrArgs::Eq { eq_span, value } => eq_span.to(value.span()),
644643
};
645644

646645
if let Some(item_def_id) = item_def_id.as_local() {

0 commit comments

Comments
 (0)