Auto merge of #91034 - camelid:docfragment, r=jyn514

rustdoc: Cleanup `DocFragment`

- Remove unused `DocFragment.line` field
- Avoid using `Iterator::count()` where possible
This commit is contained in:
bors 2021-11-19 18:04:14 +00:00
commit a77da2d454
4 changed files with 4 additions and 8 deletions

View File

@ -906,7 +906,6 @@ impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMe
/// kept separate because of issue #42760. /// kept separate because of issue #42760.
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct DocFragment { crate struct DocFragment {
crate line: usize,
crate span: rustc_span::Span, crate span: rustc_span::Span,
/// The module this doc-comment came from. /// The module this doc-comment came from.
/// ///
@ -1027,7 +1026,6 @@ impl Attributes {
additional_attrs: Option<(&[ast::Attribute], DefId)>, additional_attrs: Option<(&[ast::Attribute], DefId)>,
) -> Attributes { ) -> Attributes {
let mut doc_strings: Vec<DocFragment> = vec![]; let mut doc_strings: Vec<DocFragment> = vec![];
let mut doc_line = 0;
fn update_need_backline(doc_strings: &mut Vec<DocFragment>) { fn update_need_backline(doc_strings: &mut Vec<DocFragment>) {
if let Some(prev) = doc_strings.last_mut() { if let Some(prev) = doc_strings.last_mut() {
@ -1045,10 +1043,7 @@ impl Attributes {
DocFragmentKind::RawDoc DocFragmentKind::RawDoc
}; };
let line = doc_line;
doc_line += value.as_str().lines().count();
let frag = DocFragment { let frag = DocFragment {
line,
span: attr.span, span: attr.span,
doc: value, doc: value,
kind, kind,

View File

@ -656,7 +656,7 @@ impl<'a, I> Footnotes<'a, I> {
} }
fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) { fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) {
let new_id = self.footnotes.keys().count() + 1; let new_id = self.footnotes.len() + 1;
let key = key.to_owned(); let key = key.to_owned();
self.footnotes.entry(key).or_insert((Vec::new(), new_id as u16)) self.footnotes.entry(key).or_insert((Vec::new(), new_id as u16))
} }

View File

@ -1,5 +1,7 @@
use std::cmp; use std::cmp;
use rustc_span::symbol::kw;
use crate::clean::{self, DocFragment, DocFragmentKind, Item}; use crate::clean::{self, DocFragment, DocFragmentKind, Item};
use crate::core::DocContext; use crate::core::DocContext;
use crate::fold::{self, DocFolder}; use crate::fold::{self, DocFolder};
@ -87,7 +89,7 @@ fn unindent_fragments(docs: &mut Vec<DocFragment>) {
}; };
for fragment in docs { for fragment in docs {
if fragment.doc.as_str().lines().count() == 0 { if fragment.doc == kw::Empty {
continue; continue;
} }

View File

@ -5,7 +5,6 @@ use rustc_span::symbol::Symbol;
fn create_doc_fragment(s: &str) -> Vec<DocFragment> { fn create_doc_fragment(s: &str) -> Vec<DocFragment> {
vec![DocFragment { vec![DocFragment {
line: 0,
span: DUMMY_SP, span: DUMMY_SP,
parent_module: None, parent_module: None,
doc: Symbol::intern(s), doc: Symbol::intern(s),