Skip to content

Commit cafe02e

Browse files
Add first_span to doc attribute
1 parent 4933094 commit cafe02e

5 files changed

Lines changed: 10 additions & 0 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ impl DocParser {
701701
for i in items.mixed() {
702702
match i {
703703
MetaItemOrLitParser::MetaItemParser(mip) => {
704+
if self.nb_doc_attrs == 0 {
705+
self.attribute.first_span = cx.attr_span;
706+
}
704707
self.nb_doc_attrs += 1;
705708
self.parse_single_doc_attr_item(cx, mip);
706709
}

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ pub struct CfgHideShow {
544544

545545
#[derive(Clone, Debug, Default, HashStable_Generic, Decodable, PrintAttribute)]
546546
pub struct DocAttribute {
547+
pub first_span: Span,
548+
547549
pub aliases: FxIndexMap<Symbol, Span>,
548550
pub hidden: Option<Span>,
549551
// Because we need to emit the error if there is more than one `inline` attribute on an item
@@ -581,6 +583,7 @@ pub struct DocAttribute {
581583
impl<E: rustc_span::SpanEncoder> rustc_serialize::Encodable<E> for DocAttribute {
582584
fn encode(&self, encoder: &mut E) {
583585
let DocAttribute {
586+
first_span,
584587
aliases,
585588
hidden,
586589
inline,
@@ -603,6 +606,7 @@ impl<E: rustc_span::SpanEncoder> rustc_serialize::Encodable<E> for DocAttribute
603606
test_attrs,
604607
no_crate_inject,
605608
} = self;
609+
rustc_serialize::Encodable::<E>::encode(first_span, encoder);
606610
rustc_serialize::Encodable::<E>::encode(aliases, encoder);
607611
rustc_serialize::Encodable::<E>::encode(hidden, encoder);
608612

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10271027
/// [`check_doc_inline`]: Self::check_doc_inline
10281028
fn check_doc_attrs(&self, attr: &DocAttribute, hir_id: HirId, target: Target) {
10291029
let DocAttribute {
1030+
first_span: _,
10301031
aliases,
10311032
// valid pretty much anywhere, not checked here?
10321033
// FIXME: should we?

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,7 @@ fn add_without_unwanted_attributes<'hir>(
27802780
hir::Attribute::Parsed(AttributeKind::Doc(box d)) => {
27812781
// Remove attributes from `normal` that should not be inherited by `use` re-export.
27822782
let DocAttribute {
2783+
first_span: _,
27832784
aliases,
27842785
hidden,
27852786
inline,

src/librustdoc/json/conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ fn maybe_from_hir_attr(attr: &hir::Attribute, item_id: ItemId, tcx: TyCtxt<'_>)
960960
}
961961

962962
let DocAttribute {
963+
first_span: _,
963964
aliases,
964965
hidden,
965966
inline,

0 commit comments

Comments
 (0)