From e7fa081c18880a78c968a402367289a550bd5cb1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 24 Sep 2013 13:53:09 -0700 Subject: [PATCH] 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. --- src/librustdoc/clean.rs | 36 ++++++++++++++---------------------- src/librustdoc/passes.rs | 2 ++ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 291476c1390..ae7cbf76bcc 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -471,8 +471,7 @@ fn clean(&self) -> Item { impl Clean for ast::trait_ref { fn clean(&self) -> Type { - let t = Unresolved(self.path.clean(), None, self.ref_id); - resolve_type(&t) + resolve_type(self.path.clean(), None, self.ref_id) } } @@ -517,9 +516,6 @@ fn clean(&self) -> TraitMethod { /// it does not preserve mutability or boxes. #[deriving(Clone, Encodable, Decodable)] pub enum Type { - /// Most types start out as "Unresolved". It serves as an intermediate stage between cleaning - /// and type resolution. - Unresolved(Path, Option<~[TyParamBound]>, ast::NodeId), /// structs/enums/traits (anything that'd be an ast::ty_path) ResolvedPath { path: Path, typarams: Option<~[TyParamBound]>, id: ast::NodeId }, /// Reference to an item in an external crate (fully qualified path) @@ -558,25 +554,25 @@ fn clean(&self) -> Type { debug!("cleaning type `%?`", self); let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess.codemap; debug!("span corresponds to `%s`", codemap.span_to_str(self.span)); - let t = match self.node { + match self.node { ty_nil => Unit, - ty_ptr(ref m) => RawPointer(m.mutbl.clean(), ~resolve_type(&m.ty.clean())), + ty_ptr(ref m) => RawPointer(m.mutbl.clean(), ~m.ty.clean()), ty_rptr(ref l, ref m) => BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(), - type_: ~resolve_type(&m.ty.clean())}, - ty_box(ref m) => Managed(m.mutbl.clean(), ~resolve_type(&m.ty.clean())), - ty_uniq(ref m) => Unique(~resolve_type(&m.ty.clean())), - ty_vec(ref m) => Vector(~resolve_type(&m.ty.clean())), - ty_fixed_length_vec(ref m, ref e) => FixedVector(~resolve_type(&m.ty.clean()), + type_: ~m.ty.clean()}, + ty_box(ref m) => Managed(m.mutbl.clean(), ~m.ty.clean()), + ty_uniq(ref m) => Unique(~m.ty.clean()), + ty_vec(ref m) => Vector(~m.ty.clean()), + ty_fixed_length_vec(ref m, ref e) => FixedVector(~m.ty.clean(), e.span.to_src()), - ty_tup(ref tys) => Tuple(tys.iter().map(|x| resolve_type(&x.clean())).collect()), - ty_path(ref p, ref tpbs, id) => Unresolved(p.clean(), tpbs.clean(), id), + ty_tup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()), + ty_path(ref p, ref tpbs, id) => + resolve_type(p.clean(), tpbs.clean(), id), ty_closure(ref c) => Closure(~c.clean()), ty_bare_fn(ref barefn) => BareFunction(~barefn.clean()), ty_bot => Bottom, ref x => fail!("Unimplemented type %?", x), - }; - resolve_type(&t) + } } } @@ -1039,14 +1035,10 @@ fn remove_comment_tags(s: &str) -> ~str { } /// Given a Type, resolve it using the def_map -fn resolve_type(t: &Type) -> Type { +fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>, + id: ast::NodeId) -> Type { use syntax::ast::*; - let (path, tpbs, id) = match t { - &Unresolved(ref path, ref tbps, id) => (path, tbps, id), - _ => return (*t).clone(), - }; - let dm = local_data::get(super::ctxtkey, |x| *x.unwrap()).tycx.def_map; debug!("searching for %? in defmap", id); let d = match dm.find(&id) { diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 8376fa52882..4c83954f43c 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -11,6 +11,8 @@ use std::num; use std::uint; +use syntax::ast; + use clean; use clean::Item; use plugins; -- GitLab