diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index e4a0d80674f..0e87dd72ef1 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -474,12 +474,13 @@ impl<'a, 'b, 'ids, I: Iterator- , Range)>> Iterator
if let Some((Event::Start(Tag::Heading(level)), _)) = event {
let mut id = String::new();
for event in &mut self.inner {
- match event.0 {
+ match &event.0 {
Event::End(Tag::Heading(..)) => break,
+ Event::Start(Tag::Link(_, _, _)) | Event::End(Tag::Link(..)) => {}
Event::Text(text) | Event::Code(text) => {
id.extend(text.chars().filter_map(slugify));
+ self.buf.push_back(event);
}
- Event::Start(Tag::Link(_, _, _)) | Event::End(Tag::Link(..)) => {}
_ => self.buf.push_back(event),
}
}