8

Github Rustdoc: Fix macros 2.0 and built-in derives being shown at the wrong pat...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/77862
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Member

jyn514 left a comment

This is awful, but I don't know a better way to do it.

src/librustdoc/visit_ast.rs

Outdated

Show resolved

for path_segment in macro_parent_module.data {

let path_segment = path_segment.to_string();

cur_mod = cur_mod.mods.iter_mut().find(|module| {

matches!(

module.name, Some(symbol)

if symbol.with(|mod_name| mod_name == path_segment)

)

})?;

}

Comment on lines

105 to 109

jyn514 on Oct 13, 2020

Member

Ugh, I really wish rustdoc didn't use its own data structures (#76382). That said, if this works I won't block on it, but it's unambiguously a hack.

Suggested change
for path_segment in macro_parent_module.data { let path_segment = path_segment.to_string(); cur_mod = cur_mod.mods.iter_mut().find(|module| { matches!( module.name, Some(symbol) if symbol.with(|mod_name| mod_name == path_segment) ) })?; } // HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId // HACK: instead, lookup the module by its name, by looking at each path segment one at a time // WARNING: this will probably break in the presence of re-exports or shadowing. for path_segment in macro_parent_module.data { let path_segment = path_segment.to_string(); cur_mod = cur_mod.mods.iter_mut().find(|module| { matches!( module.name, Some(symbol) if symbol.with(|mod_name| mod_name == path_segment) ) })?; }

@GuillaumeGomez before I sign off on this, do you know a better way to do this?

danielhenrymantilla on Oct 13, 2020

Author

Contributor

That said, if this works I won't block on it, but it's unambiguously a hack.

Definitely! The reason I've submitted this code (despite my not having cleaned that try block elsewhere) was for you people to tell me if there was some obvious tool I had missed in places like here, given my lack of experience with rustdoc and rustc internals baby


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK