Skip to content
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

Fix missing modules because of missing unindent doc comment in early intra-doc pass #96216

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,10 @@ impl Attributes {
ret
}

crate fn doc_contains(&self, c: char) -> bool {
self.doc_strings.iter().any(|s| s.doc.as_str().contains(c))
}

/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
/// with newlines.
crate fn collapsed_doc_value(&self) -> Option<String> {
Expand Down
11 changes: 8 additions & 3 deletions src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ impl EarlyDocLinkResolver<'_, '_> {
fn load_links_in_attrs(&mut self, attrs: &[ast::Attribute]) {
let module_id = self.current_mod.to_def_id();
let mut need_traits_in_scope = false;
for (doc_module, doc) in
Attributes::from_ast(attrs, None).collapsed_doc_value_by_module_level()
{
let mut attrs = Attributes::from_ast(attrs, None);
if !attrs.doc_contains('[') {
// No need to load anything if there is no link inside this doc comment...
return;
}
// The `unindent_comments` pass hasn't been run yet!
attrs.unindent_doc_comments();
for (doc_module, doc) in attrs.collapsed_doc_value_by_module_level() {
assert_eq!(doc_module, None);
for link in markdown_links(&doc.as_str()) {
if let Some(Ok(pinfo)) = preprocess_link(&link) {
Expand Down
26 changes: 26 additions & 0 deletions src/test/rustdoc/early-unindent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This is a regression for https://github.com/rust-lang/rust/issues/96079.

#![crate_name = "foo"]

pub mod app {
pub struct S;

impl S {
// @has 'foo/app/struct.S.html'
// @has - '//a[@href="../enums/enum.Foo.html#method.by_name"]' 'Foo::by_name'
/**
Doc comment hello! [`Foo::by_name`](`crate::enums::Foo::by_name`).
*/
pub fn whatever(&self) {}
}
}

pub mod enums {
pub enum Foo {
Bar,
}

impl Foo {
pub fn by_name(&self) {}
}
}