Skip to content

Commit e7fa081

Browse files
committed
rustdoc: Reduce ambiguity with clean::Type
The "Unresolved" variant could be completely removed becuase it turns out that the interim state only very briefly lives.
1 parent f648690 commit e7fa081

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/librustdoc/clean.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ impl Clean<Item> for doctree::Trait {
471471

472472
impl Clean<Type> for ast::trait_ref {
473473
fn clean(&self) -> Type {
474-
let t = Unresolved(self.path.clean(), None, self.ref_id);
475-
resolve_type(&t)
474+
resolve_type(self.path.clean(), None, self.ref_id)
476475
}
477476
}
478477

@@ -517,9 +516,6 @@ impl Clean<TraitMethod> for ast::trait_method {
517516
/// it does not preserve mutability or boxes.
518517
#[deriving(Clone, Encodable, Decodable)]
519518
pub enum Type {
520-
/// Most types start out as "Unresolved". It serves as an intermediate stage between cleaning
521-
/// and type resolution.
522-
Unresolved(Path, Option<~[TyParamBound]>, ast::NodeId),
523519
/// structs/enums/traits (anything that'd be an ast::ty_path)
524520
ResolvedPath { path: Path, typarams: Option<~[TyParamBound]>, id: ast::NodeId },
525521
/// Reference to an item in an external crate (fully qualified path)
@@ -558,25 +554,25 @@ impl Clean<Type> for ast::Ty {
558554
debug!("cleaning type `%?`", self);
559555
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess.codemap;
560556
debug!("span corresponds to `%s`", codemap.span_to_str(self.span));
561-
let t = match self.node {
557+
match self.node {
562558
ty_nil => Unit,
563-
ty_ptr(ref m) => RawPointer(m.mutbl.clean(), ~resolve_type(&m.ty.clean())),
559+
ty_ptr(ref m) => RawPointer(m.mutbl.clean(), ~m.ty.clean()),
564560
ty_rptr(ref l, ref m) =>
565561
BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
566-
type_: ~resolve_type(&m.ty.clean())},
567-
ty_box(ref m) => Managed(m.mutbl.clean(), ~resolve_type(&m.ty.clean())),
568-
ty_uniq(ref m) => Unique(~resolve_type(&m.ty.clean())),
569-
ty_vec(ref m) => Vector(~resolve_type(&m.ty.clean())),
570-
ty_fixed_length_vec(ref m, ref e) => FixedVector(~resolve_type(&m.ty.clean()),
562+
type_: ~m.ty.clean()},
563+
ty_box(ref m) => Managed(m.mutbl.clean(), ~m.ty.clean()),
564+
ty_uniq(ref m) => Unique(~m.ty.clean()),
565+
ty_vec(ref m) => Vector(~m.ty.clean()),
566+
ty_fixed_length_vec(ref m, ref e) => FixedVector(~m.ty.clean(),
571567
e.span.to_src()),
572-
ty_tup(ref tys) => Tuple(tys.iter().map(|x| resolve_type(&x.clean())).collect()),
573-
ty_path(ref p, ref tpbs, id) => Unresolved(p.clean(), tpbs.clean(), id),
568+
ty_tup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
569+
ty_path(ref p, ref tpbs, id) =>
570+
resolve_type(p.clean(), tpbs.clean(), id),
574571
ty_closure(ref c) => Closure(~c.clean()),
575572
ty_bare_fn(ref barefn) => BareFunction(~barefn.clean()),
576573
ty_bot => Bottom,
577574
ref x => fail!("Unimplemented type %?", x),
578-
};
579-
resolve_type(&t)
575+
}
580576
}
581577
}
582578

@@ -1039,14 +1035,10 @@ fn remove_comment_tags(s: &str) -> ~str {
10391035
}
10401036

10411037
/// Given a Type, resolve it using the def_map
1042-
fn resolve_type(t: &Type) -> Type {
1038+
fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
1039+
id: ast::NodeId) -> Type {
10431040
use syntax::ast::*;
10441041

1045-
let (path, tpbs, id) = match t {
1046-
&Unresolved(ref path, ref tbps, id) => (path, tbps, id),
1047-
_ => return (*t).clone(),
1048-
};
1049-
10501042
let dm = local_data::get(super::ctxtkey, |x| *x.unwrap()).tycx.def_map;
10511043
debug!("searching for %? in defmap", id);
10521044
let d = match dm.find(&id) {

src/librustdoc/passes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use std::num;
1212
use std::uint;
1313

14+
use syntax::ast;
15+
1416
use clean;
1517
use clean::Item;
1618
use plugins;

0 commit comments

Comments
 (0)