Skip to content

Commit 429ef87

Browse files
committed
rustdoc: Handle links to reexported items
When building up our path cache, we don't plaster over a path which was previously inserted if we're inserting a non-public-item thing. Closes #11678
1 parent cac9107 commit 429ef87

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/librustdoc/html/render.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct Cache {
157157
priv parent_stack: ~[ast::NodeId],
158158
priv search_index: ~[IndexItem],
159159
priv privmod: bool,
160+
priv public_items: HashSet<ast::NodeId>,
160161
}
161162

162163
/// Helper struct to render all source code to HTML pages
@@ -231,18 +232,23 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
231232
}
232233

233234
// Crawl the crate to build various caches used for the output
234-
let mut cache = Cache {
235-
impls: HashMap::new(),
236-
typarams: HashMap::new(),
237-
paths: HashMap::new(),
238-
traits: HashMap::new(),
239-
implementors: HashMap::new(),
240-
stack: ~[],
241-
parent_stack: ~[],
242-
search_index: ~[],
243-
extern_locations: HashMap::new(),
244-
privmod: false,
245-
};
235+
let mut cache = local_data::get(::analysiskey, |analysis| {
236+
let public_items = analysis.map(|a| a.public_items.clone());
237+
let public_items = public_items.unwrap_or(HashSet::new());
238+
Cache {
239+
impls: HashMap::new(),
240+
typarams: HashMap::new(),
241+
paths: HashMap::new(),
242+
traits: HashMap::new(),
243+
implementors: HashMap::new(),
244+
stack: ~[],
245+
parent_stack: ~[],
246+
search_index: ~[],
247+
extern_locations: HashMap::new(),
248+
privmod: false,
249+
public_items: public_items,
250+
}
251+
});
246252
cache.stack.push(krate.name.clone());
247253
krate = cache.fold_crate(krate);
248254

@@ -566,7 +572,16 @@ impl DocFolder for Cache {
566572
clean::TypedefItem(..) | clean::TraitItem(..) |
567573
clean::FunctionItem(..) | clean::ModuleItem(..) |
568574
clean::ForeignFunctionItem(..) => {
569-
self.paths.insert(item.id, (self.stack.clone(), shortty(&item)));
575+
// Reexported items mean that the same id can show up twice in
576+
// the rustdoc ast that we're looking at. We know, however, that
577+
// a reexported item doesn't show up in the `public_items` map,
578+
// so we can skip inserting into the paths map if there was
579+
// already an entry present and we're not a public item.
580+
if !self.paths.contains_key(&item.id) ||
581+
self.public_items.contains(&item.id) {
582+
self.paths.insert(item.id,
583+
(self.stack.clone(), shortty(&item)));
584+
}
570585
}
571586
// link variants to their parent enum because pages aren't emitted
572587
// for each variant

src/libstd/macros.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ macro_rules! log_enabled(
130130
/// # Example
131131
///
132132
/// ```should_fail
133+
/// # #[allow(unreachable_code)];
133134
/// fail!();
134135
/// fail!("this is a terrible mistake!");
135136
/// fail!(4); // fail with the value of 4 to be collected elsewhere
@@ -228,13 +229,15 @@ macro_rules! assert_eq(
228229
/// # Example
229230
///
230231
/// ~~~rust
232+
/// struct Item { weight: uint }
233+
///
231234
/// fn choose_weighted_item(v: &[Item]) -> Item {
232235
/// assert!(!v.is_empty());
233236
/// let mut so_far = 0u;
234237
/// for item in v.iter() {
235238
/// so_far += item.weight;
236239
/// if so_far > 100 {
237-
/// return item;
240+
/// return *item;
238241
/// }
239242
/// }
240243
/// // The above loop always returns, so we must hint to the
@@ -336,7 +339,7 @@ macro_rules! println(
336339
/// local_data_key!(my_integer: int)
337340
///
338341
/// local_data::set(my_integer, 2);
339-
/// local_data::get(my_integer, |val| println!("{}", val));
342+
/// local_data::get(my_integer, |val| println!("{}", val.map(|i| *i)));
340343
/// ```
341344
#[macro_export]
342345
macro_rules! local_data_key(

0 commit comments

Comments
 (0)