3

rustdoc: Avoid duplicating macros in sidebar by GuillaumeGomez · Pull Request #9...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/94002
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.

Conversation

Fixes #93912.

cc @jsha (for the GUI test) r? @camelid

@@ -250,6 +250,8 @@ impl<'tcx> Context<'tcx> {

fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {

// BTreeMap instead of HashMap to get a sorted output

let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();

let mut inserted: FxHashMap<ItemType, FxHashSet<Symbol>> = FxHashMap::default();

Using a map to skip duplicates doesn't seem like the correct approach to me. We shouldn't have two macros with the same name in the module in the first place, right?

It's possible because of reexports. Initially, I had rewrote using a BTreeMap but then I discovered that we had an option to keep the declaration order. So I had to revert that and instead using a Hashmap alongside...

// This test ensures that there is no macro duplicates in the sidebar.

goto: file://|DOC_PATH|/test_docs/macro.a.html

// Waiting for the elements in the sidebar to be rendered.

wait-for: ".sidebar-elems .others .macro"

// Check there is only one macro named "a" listed in the sidebar.

assert-count: (

"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='a']",

1,

)

// Check there is only one macro named "b" listed in the sidebar.

assert-count: (

"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='b']",

1,

)

This should be a regular HTML test using @count, not a GUI test.

It's generated by the JS, so can't do that. ^^'

It is? Somewhat off-topic, but why?

I'm wondering the same thing... Will need to dive into this to understand.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK