Skip to content

Commit ba9be0a

Browse files
committed
rustdoc: Fill in external type parameters correctly
Type parameters were filled in for some areas, but not all. This commit unifies the two code paths to fill in type parameters everywhere. Closes #14508
1 parent 19fe4aa commit ba9be0a

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/librustdoc/clean/mod.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,19 @@ impl Clean<TyParamBound> for ast::TyParamBound {
400400
}
401401
}
402402

403-
fn external_path(name: &str) -> Path {
403+
fn external_path(name: &str, substs: &ty::substs) -> Path {
404404
Path {
405405
global: false,
406406
segments: vec![PathSegment {
407407
name: name.to_string(),
408-
lifetimes: Vec::new(),
409-
types: Vec::new(),
410-
}]
408+
lifetimes: match substs.regions {
409+
ty::ErasedRegions => Vec::new(),
410+
ty::NonerasedRegions(ref v) => {
411+
v.iter().filter_map(|v| v.clean()).collect()
412+
}
413+
},
414+
types: substs.tps.clean(),
415+
}],
411416
}
412417
}
413418

@@ -418,16 +423,21 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
418423
core::Typed(ref tcx) => tcx,
419424
core::NotTyped(_) => return RegionBound,
420425
};
426+
let empty = ty::substs::empty();
421427
let (did, path) = match *self {
422428
ty::BoundStatic => return RegionBound,
423429
ty::BoundSend =>
424-
(tcx.lang_items.send_trait().unwrap(), external_path("Send")),
430+
(tcx.lang_items.send_trait().unwrap(),
431+
external_path("Send", &empty)),
425432
ty::BoundSized =>
426-
(tcx.lang_items.sized_trait().unwrap(), external_path("Sized")),
433+
(tcx.lang_items.sized_trait().unwrap(),
434+
external_path("Sized", &empty)),
427435
ty::BoundCopy =>
428-
(tcx.lang_items.copy_trait().unwrap(), external_path("Copy")),
436+
(tcx.lang_items.copy_trait().unwrap(),
437+
external_path("Copy", &empty)),
429438
ty::BoundShare =>
430-
(tcx.lang_items.share_trait().unwrap(), external_path("Share")),
439+
(tcx.lang_items.share_trait().unwrap(),
440+
external_path("Share", &empty)),
431441
};
432442
let fqn = csearch::get_item_path(tcx, did);
433443
let fqn = fqn.move_iter().map(|i| i.to_str().to_string()).collect();
@@ -451,7 +461,8 @@ impl Clean<TyParamBound> for ty::TraitRef {
451461
let fqn = csearch::get_item_path(tcx, self.def_id);
452462
let fqn = fqn.move_iter().map(|i| i.to_str().to_string())
453463
.collect::<Vec<String>>();
454-
let path = external_path(fqn.last().unwrap().as_slice());
464+
let path = external_path(fqn.last().unwrap().as_slice(),
465+
&self.substs);
455466
cx.external_paths.borrow_mut().get_mut_ref().insert(self.def_id,
456467
(fqn, TypeTrait));
457468
TraitBound(ResolvedPath {
@@ -1040,26 +1051,16 @@ impl Clean<Type> for ty::t {
10401051
let fqn: Vec<String> = fqn.move_iter().map(|i| {
10411052
i.to_str().to_string()
10421053
}).collect();
1043-
let mut path = external_path(fqn.last()
1044-
.unwrap()
1045-
.to_str()
1046-
.as_slice());
10471054
let kind = match ty::get(*self).sty {
10481055
ty::ty_struct(..) => TypeStruct,
10491056
ty::ty_trait(..) => TypeTrait,
10501057
_ => TypeEnum,
10511058
};
1052-
path.segments.get_mut(0).lifetimes = match substs.regions {
1053-
ty::ErasedRegions => Vec::new(),
1054-
ty::NonerasedRegions(ref v) => {
1055-
v.iter().filter_map(|v| v.clean()).collect()
1056-
}
1057-
};
1058-
path.segments.get_mut(0).types = substs.tps.clean();
10591059
cx.external_paths.borrow_mut().get_mut_ref().insert(did,
10601060
(fqn, kind));
10611061
ResolvedPath {
1062-
path: path,
1062+
path: external_path(fqn.last().unwrap().to_str().as_slice(),
1063+
substs),
10631064
typarams: None,
10641065
did: did,
10651066
}

0 commit comments

Comments
 (0)