Skip to content

Commit 87205d7

Browse files
committed
Auto merge of #60930 - petrochenkov:nodoc, r=<try>
[experiment] How expensive are doc comments? What happens if they are interpreted as usual comments and not converted to attributes, and not stored in AST/HIR? (This cannot be checked at lexer level, unfortunately, since some popular crates (`rayon`) rely on `/** text */` being matched by `#[$meta]` in macros.) r? @ghost
2 parents 73a3a90 + 0283814 commit 87205d7

File tree

416 files changed

+29
-7706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

416 files changed

+29
-7706
lines changed

src/librustc_lint/builtin.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl MissingDoc {
316316
*self.doc_hidden_stack.last().expect("empty doc_hidden_stack")
317317
}
318318

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

345346
let has_doc = attrs.iter().any(|a| has_doc(a));
346347
if !has_doc {
347-
cx.span_lint(MISSING_DOCS,
348-
cx.tcx.sess.source_map().def_span(sp),
349-
&format!("missing documentation for {}", desc));
348+
// cx.span_lint(MISSING_DOCS,
349+
// cx.tcx.sess.source_map().def_span(sp),
350+
// &format!("missing documentation for {}", desc));
350351
}
351352
}
352353
}
@@ -374,9 +375,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
374375
for macro_def in &krate.exported_macros {
375376
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
376377
if !has_doc {
377-
cx.span_lint(MISSING_DOCS,
378-
cx.tcx.sess.source_map().def_span(macro_def.span),
379-
"missing documentation for macro");
378+
// cx.span_lint(MISSING_DOCS,
379+
// cx.tcx.sess.source_map().def_span(macro_def.span),
380+
// "missing documentation for macro");
380381
}
381382
}
382383
}

src/libsyntax/parse/attr.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ impl<'a> Parser<'a> {
3838
attrs.push(self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?);
3939
just_parsed_doc_comment = false;
4040
}
41-
token::DocComment(s) => {
42-
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
43-
if attr.style != ast::AttrStyle::Outer {
44-
let mut err = self.fatal("expected outer doc comment");
45-
err.note("inner doc comments like this (starting with \
46-
`//!` or `/*!`) can only appear before items");
47-
return Err(err);
48-
}
49-
attrs.push(attr);
41+
token::DocComment(_s) => {
42+
// let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
43+
// if attr.style != ast::AttrStyle::Outer {
44+
// let mut err = self.fatal("expected outer doc comment");
45+
// err.note("inner doc comments like this (starting with \
46+
// `//!` or `/*!`) can only appear before items");
47+
// return Err(err);
48+
// }
49+
// attrs.push(attr);
5050
self.bump();
51-
just_parsed_doc_comment = true;
51+
// just_parsed_doc_comment = true;
5252
}
5353
_ => break,
5454
}
@@ -199,15 +199,16 @@ impl<'a> Parser<'a> {
199199
assert_eq!(attr.style, ast::AttrStyle::Inner);
200200
attrs.push(attr);
201201
}
202-
token::DocComment(s) => {
202+
token::DocComment(_s) => {
203+
self.bump();
203204
// we need to get the position of this token before we bump.
204-
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
205-
if attr.style == ast::AttrStyle::Inner {
206-
attrs.push(attr);
207-
self.bump();
208-
} else {
209-
break;
210-
}
205+
// let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
206+
// if attr.style == ast::AttrStyle::Inner {
207+
// attrs.push(attr);
208+
// self.bump();
209+
// } else {
210+
// break;
211+
// }
211212
}
212213
_ => break,
213214
}

src/libsyntax/parse/mod.rs

-31
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ impl SeqSep {
357357
mod tests {
358358
use super::*;
359359
use crate::ast::{self, Ident, PatKind};
360-
use crate::attr::first_attr_value_str_by_name;
361360
use crate::ptr::P;
362361
use crate::print::pprust::item_to_string;
363362
use crate::tokenstream::{DelimSpan, TokenTree};
@@ -575,36 +574,6 @@ mod tests {
575574
})
576575
}
577576

578-
#[test] fn crlf_doc_comments() {
579-
with_globals(|| {
580-
use crate::symbol::sym;
581-
582-
let sess = ParseSess::new(FilePathMapping::empty());
583-
584-
let name_1 = FileName::Custom("crlf_source_1".to_string());
585-
let source = "/// doc comment\r\nfn foo() {}".to_string();
586-
let item = parse_item_from_source_str(name_1, source, &sess)
587-
.unwrap().unwrap();
588-
let doc = first_attr_value_str_by_name(&item.attrs, sym::doc).unwrap();
589-
assert_eq!(doc.as_str(), "/// doc comment");
590-
591-
let name_2 = FileName::Custom("crlf_source_2".to_string());
592-
let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string();
593-
let item = parse_item_from_source_str(name_2, source, &sess)
594-
.unwrap().unwrap();
595-
let docs = item.attrs.iter().filter(|a| a.path == sym::doc)
596-
.map(|a| a.value_str().unwrap().to_string()).collect::<Vec<_>>();
597-
let b: &[_] = &["/// doc comment".to_string(), "/// line 2".to_string()];
598-
assert_eq!(&docs[..], b);
599-
600-
let name_3 = FileName::Custom("clrf_source_3".to_string());
601-
let source = "/** doc comment\r\n * with CRLF */\r\nfn foo() {}".to_string();
602-
let item = parse_item_from_source_str(name_3, source, &sess).unwrap().unwrap();
603-
let doc = first_attr_value_str_by_name(&item.attrs, sym::doc).unwrap();
604-
assert_eq!(doc.as_str(), "/** doc comment\n * with CRLF */");
605-
});
606-
}
607-
608577
#[test]
609578
fn ttdelim_span() {
610579
fn parse_expr_from_source_str(

src/test/pretty/doc-comments.rs

-53
This file was deleted.

src/test/pretty/top-level-doc-comments.rs

-13
This file was deleted.

src/test/rustdoc/all.rs

-28
This file was deleted.

src/test/rustdoc/assoc-consts-version.rs

-15
This file was deleted.

src/test/rustdoc/assoc-consts.rs

-99
This file was deleted.

src/test/rustdoc/assoc-item-cast.rs

-16
This file was deleted.

0 commit comments

Comments
 (0)