Skip to content

[experiment] How expensive are doc comments? #60930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ impl MissingDoc {
*self.doc_hidden_stack.last().expect("empty doc_hidden_stack")
}

#[allow(unused)]
fn check_missing_docs_attrs(&self,
cx: &LateContext<'_, '_>,
id: Option<hir::HirId>,
Expand Down Expand Up @@ -344,9 +345,9 @@ impl MissingDoc {

let has_doc = attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.span_lint(MISSING_DOCS,
cx.tcx.sess.source_map().def_span(sp),
&format!("missing documentation for {}", desc));
// cx.span_lint(MISSING_DOCS,
// cx.tcx.sess.source_map().def_span(sp),
// &format!("missing documentation for {}", desc));
}
}
}
Expand Down Expand Up @@ -374,9 +375,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
for macro_def in &krate.exported_macros {
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.span_lint(MISSING_DOCS,
cx.tcx.sess.source_map().def_span(macro_def.span),
"missing documentation for macro");
// cx.span_lint(MISSING_DOCS,
// cx.tcx.sess.source_map().def_span(macro_def.span),
// "missing documentation for macro");
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions src/libsyntax/parse/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ impl<'a> Parser<'a> {
attrs.push(self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?);
just_parsed_doc_comment = false;
}
token::DocComment(s) => {
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
if attr.style != ast::AttrStyle::Outer {
let mut err = self.fatal("expected outer doc comment");
err.note("inner doc comments like this (starting with \
`//!` or `/*!`) can only appear before items");
return Err(err);
}
attrs.push(attr);
token::DocComment(_s) => {
// let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
// if attr.style != ast::AttrStyle::Outer {
// let mut err = self.fatal("expected outer doc comment");
// err.note("inner doc comments like this (starting with \
// `//!` or `/*!`) can only appear before items");
// return Err(err);
// }
// attrs.push(attr);
self.bump();
just_parsed_doc_comment = true;
// just_parsed_doc_comment = true;
}
_ => break,
}
Expand Down Expand Up @@ -199,15 +199,16 @@ impl<'a> Parser<'a> {
assert_eq!(attr.style, ast::AttrStyle::Inner);
attrs.push(attr);
}
token::DocComment(s) => {
token::DocComment(_s) => {
self.bump();
// we need to get the position of this token before we bump.
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
if attr.style == ast::AttrStyle::Inner {
attrs.push(attr);
self.bump();
} else {
break;
}
// let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
// if attr.style == ast::AttrStyle::Inner {
// attrs.push(attr);
// self.bump();
// } else {
// break;
// }
}
_ => break,
}
Expand Down
31 changes: 0 additions & 31 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ impl SeqSep {
mod tests {
use super::*;
use crate::ast::{self, Ident, PatKind};
use crate::attr::first_attr_value_str_by_name;
use crate::ptr::P;
use crate::print::pprust::item_to_string;
use crate::tokenstream::{DelimSpan, TokenTree};
Expand Down Expand Up @@ -575,36 +574,6 @@ mod tests {
})
}

#[test] fn crlf_doc_comments() {
with_globals(|| {
use crate::symbol::sym;

let sess = ParseSess::new(FilePathMapping::empty());

let name_1 = FileName::Custom("crlf_source_1".to_string());
let source = "/// doc comment\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name_1, source, &sess)
.unwrap().unwrap();
let doc = first_attr_value_str_by_name(&item.attrs, sym::doc).unwrap();
assert_eq!(doc.as_str(), "/// doc comment");

let name_2 = FileName::Custom("crlf_source_2".to_string());
let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name_2, source, &sess)
.unwrap().unwrap();
let docs = item.attrs.iter().filter(|a| a.path == sym::doc)
.map(|a| a.value_str().unwrap().to_string()).collect::<Vec<_>>();
let b: &[_] = &["/// doc comment".to_string(), "/// line 2".to_string()];
assert_eq!(&docs[..], b);

let name_3 = FileName::Custom("clrf_source_3".to_string());
let source = "/** doc comment\r\n * with CRLF */\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name_3, source, &sess).unwrap().unwrap();
let doc = first_attr_value_str_by_name(&item.attrs, sym::doc).unwrap();
assert_eq!(doc.as_str(), "/** doc comment\n * with CRLF */");
});
}

#[test]
fn ttdelim_span() {
fn parse_expr_from_source_str(
Expand Down
53 changes: 0 additions & 53 deletions src/test/pretty/doc-comments.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/pretty/top-level-doc-comments.rs

This file was deleted.

28 changes: 0 additions & 28 deletions src/test/rustdoc/all.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/test/rustdoc/assoc-consts-version.rs

This file was deleted.

99 changes: 0 additions & 99 deletions src/test/rustdoc/assoc-consts.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/rustdoc/assoc-item-cast.rs

This file was deleted.

Loading