]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Correctly distinguish enums and types
authorP1start <rewi-github@whanau.org>
Mon, 15 Sep 2014 21:13:00 +0000 (09:13 +1200)
committerP1start <rewi-github@whanau.org>
Wed, 17 Sep 2014 06:53:54 +0000 (18:53 +1200)
This is done by adding a new field to the `DefTy` variant of `middle::def::Def`,
which also clarifies an error message in the process.

Closes #16712.

17 files changed:
src/librustc/metadata/decoder.rs
src/librustc/middle/astencode.rs
src/librustc/middle/def.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/privacy.rs
src/librustc/middle/resolve.rs
src/librustc/middle/save/mod.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/infer/error_reporting.rs
src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/html/item_type.rs
src/librustdoc/html/render.rs
src/librustdoc/html/static/main.js
src/test/auxiliary/static_priv_by_default.rs
src/test/compile-fail/xcrate-private-by-default.rs

index c7af7b249398af0519bb88bc866ab5b4aea0d941..748e59b75ed63edee5858d2859b4dbe474c6b54a 100644 (file)
@@ -325,7 +325,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
             };
             DlDef(def::DefStaticMethod(did, provenance, fn_style))
         }
-        Type | ForeignType => DlDef(def::DefTy(did)),
+        Type | ForeignType => DlDef(def::DefTy(did, false)),
         Mod => DlDef(def::DefMod(did)),
         ForeignMod => DlDef(def::DefForeignMod(did)),
         StructVariant => {
@@ -337,7 +337,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
             DlDef(def::DefVariant(enum_did, did, false))
         }
         Trait => DlDef(def::DefTrait(did)),
-        Enum => DlDef(def::DefTy(did)),
+        Enum => DlDef(def::DefTy(did, true)),
         Impl => DlImpl(did),
         PublicField | InheritedField => DlField,
     }
index 272b7111fb88f40923c48add61ccf2570c998996..880445ff38d324fffd2f1abcb2cb8efa5a90d2f4 100644 (file)
@@ -454,7 +454,7 @@ fn tr(&self, dcx: &DecodeContext) -> def::Def {
             def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
           },
           def::DefTrait(did) => def::DefTrait(did.tr(dcx)),
-          def::DefTy(did) => def::DefTy(did.tr(dcx)),
+          def::DefTy(did, is_enum) => def::DefTy(did.tr(dcx), is_enum),
           def::DefPrimTy(p) => def::DefPrimTy(p),
           def::DefTyParam(s, did, v) => def::DefTyParam(s, did.tr(dcx), v),
           def::DefBinding(nid, bm) => def::DefBinding(dcx.tr_id(nid), bm),
index 914cf451ebe29380878c029370b34a4f2547e5ae..70a9b6c533772988d18108473b5bf5d8d1c222fd 100644 (file)
@@ -25,7 +25,7 @@ pub enum Def {
     DefArg(ast::NodeId, ast::BindingMode),
     DefLocal(ast::NodeId, ast::BindingMode),
     DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
-    DefTy(ast::DefId),
+    DefTy(ast::DefId, bool /* is_enum */),
     DefTrait(ast::DefId),
     DefPrimTy(ast::PrimTy),
     DefTyParam(ParamSpace, ast::DefId, uint),
@@ -62,7 +62,7 @@ pub fn def_id(&self) -> ast::DefId {
         match *self {
             DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) |
             DefForeignMod(id) | DefStatic(id, _) |
-            DefVariant(_, id, _) | DefTy(id) | DefTyParam(_, id, _) |
+            DefVariant(_, id, _) | DefTy(id, _) | DefTyParam(_, id, _) |
             DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => {
                 id
             }
index 3e42ee9187c4258227906d706f1b56362ecbb049..4f9cc9c080f9bcab89cd1ba09a8cca16a6e49baf 100644 (file)
@@ -531,7 +531,7 @@ pub fn cat_def(&self,
                 Ok(self.cat_rvalue_node(id, span, expr_ty))
           }
           def::DefMod(_) | def::DefForeignMod(_) | def::DefUse(_) |
-          def::DefTrait(_) | def::DefTy(_) | def::DefPrimTy(_) |
+          def::DefTrait(_) | def::DefTy(..) | def::DefPrimTy(_) |
           def::DefTyParam(..) | def::DefTyParamBinder(..) | def::DefRegion(_) |
           def::DefLabel(_) | def::DefSelfTy(..) | def::DefMethod(..) => {
               Ok(Rc::new(cmt_ {
index 56c785d3c2592845c1a07bd550f10a71a5b62378..0eb684fe18e1061a5bbb472a210e9526b21fd508 100644 (file)
@@ -771,7 +771,8 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
             def::DefFn(..) => ck("function"),
             def::DefStatic(..) => ck("static"),
             def::DefVariant(..) => ck("variant"),
-            def::DefTy(..) => ck("type"),
+            def::DefTy(_, false) => ck("type"),
+            def::DefTy(_, true) => ck("enum"),
             def::DefTrait(..) => ck("trait"),
             def::DefStruct(..) => ck("struct"),
             def::DefMethod(_, Some(..)) => ck("trait method"),
index ded4883350ff2c6cc1ec1e7debd7646209b31475..191f7113cc90d05a904053baad03401d136a832c 100644 (file)
@@ -1252,7 +1252,7 @@ fn build_reduced_graph_for_item(&mut self,
                                    sp);
 
                 name_bindings.define_type
-                    (DefTy(local_def(item.id)), sp, is_public);
+                    (DefTy(local_def(item.id), false), sp, is_public);
                 parent
             }
 
@@ -1264,7 +1264,7 @@ fn build_reduced_graph_for_item(&mut self,
                                    sp);
 
                 name_bindings.define_type
-                    (DefTy(local_def(item.id)), sp, is_public);
+                    (DefTy(local_def(item.id), true), sp, is_public);
 
                 for variant in (*enum_definition).variants.iter() {
                     self.build_reduced_graph_for_variant(
@@ -1287,7 +1287,7 @@ fn build_reduced_graph_for_item(&mut self,
                 let name_bindings = self.add_child(ident, parent.clone(), forbid, sp);
 
                 // Define a name in the type namespace.
-                name_bindings.define_type(DefTy(local_def(item.id)), sp, is_public);
+                name_bindings.define_type(DefTy(local_def(item.id), false), sp, is_public);
 
                 // If this is a newtype or unit-like struct, define a name
                 // in the value namespace as well
@@ -1732,7 +1732,7 @@ fn handle_external_def(&mut self,
 
         match def {
           DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
-          DefTy(def_id) => {
+          DefTy(def_id, _) => {
             let type_def = child_name_bindings.type_def.borrow().clone();
             match type_def {
               Some(TypeNsDef { module_def: Some(module_def), .. }) => {
@@ -1823,7 +1823,7 @@ fn handle_external_def(&mut self,
                                                   is_public,
                                                   DUMMY_SP)
           }
-          DefTy(_) => {
+          DefTy(..) => {
               debug!("(building reduced graph for external \
                       crate) building type {}", final_ident);
 
@@ -4320,7 +4320,7 @@ fn resolve_trait_reference(&mut self,
 
                         // If it's a typedef, give a note
                         match def {
-                            DefTy(_) => {
+                            DefTy(..) => {
                                 self.session.span_note(
                                                 trait_reference.path.span,
                                                 format!("`type` aliases cannot \
@@ -4381,7 +4381,7 @@ fn resolve_struct(&mut self,
                 Some(ref t) => match t.node {
                     TyPath(ref path, None, path_id) => {
                         match this.resolve_path(id, path, TypeNS, true) {
-                            Some((DefTy(def_id), lp)) if this.structs.contains_key(&def_id) => {
+                            Some((DefTy(def_id, _), lp)) if this.structs.contains_key(&def_id) => {
                                 let def = DefStruct(def_id);
                                 debug!("(resolving struct) resolved `{}` to type {:?}",
                                        token::get_ident(path.segments
@@ -5440,7 +5440,7 @@ fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident])
         if allowed == Everything {
             // Look for a field with the same name in the current self_type.
             match self.def_map.borrow().find(&node_id) {
-                 Some(&DefTy(did))
+                 Some(&DefTy(did, _))
                 | Some(&DefStruct(did))
                 | Some(&DefVariant(_, did, _)) => match self.structs.find(&did) {
                     None => {}
@@ -5582,7 +5582,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
                         // structs, which wouldn't result in this error.)
                         match self.with_no_errors(|this|
                             this.resolve_path(expr.id, path, TypeNS, false)) {
-                            Some((DefTy(struct_id), _))
+                            Some((DefTy(struct_id, _), _))
                               if self.structs.contains_key(&struct_id) => {
                                 self.resolve_error(expr.span,
                                         format!("`{}` is a structure name, but \
index fe066c732ddc68ae1d21ac6fdd0c75a37c6f46f6..37ba3b75f8917ad024b7f5a6332ec8e35b34ec96 100644 (file)
@@ -226,7 +226,7 @@ fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
             def::DefMod(_) |
             def::DefForeignMod(_) => Some(recorder::ModRef),
             def::DefStruct(_) => Some(recorder::StructRef),
-            def::DefTy(_) |
+            def::DefTy(..) |
             def::DefTrait(_) => Some(recorder::TypeRef),
             def::DefStatic(_, _) |
             def::DefBinding(_, _) |
index cb449f80ed4a49f7905523ec9134e9f37625117c..a9b633d483b6a72c47178166335d828cce447e12 100644 (file)
@@ -438,7 +438,7 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
             // FIXME(#12938): This is a hack until we have full support for
             // DST.
             match a_def {
-                def::DefTy(did) | def::DefStruct(did)
+                def::DefTy(did, _) | def::DefStruct(did)
                         if Some(did) == this.tcx().lang_items.owned_box() => {
                     if path.segments
                            .iter()
@@ -462,7 +462,7 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
                               "not enough type parameters supplied to `Box<T>`");
                     Some(ty::mk_err())
                 }
-                def::DefTy(did) | def::DefStruct(did)
+                def::DefTy(did, _) | def::DefStruct(did)
                         if Some(did) == this.tcx().lang_items.gc() => {
                     if path.segments
                            .iter()
@@ -833,7 +833,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
                                      result.substs.clone(),
                                      bounds)
                     }
-                    def::DefTy(did) | def::DefStruct(did) => {
+                    def::DefTy(did, _) | def::DefStruct(did) => {
                         ast_path_to_ty(this, rscope, did, path).ty
                     }
                     def::DefTyParam(space, id, n) => {
index 20fe8186adf40fe50100022eb2ae24fae60d0cf8..3bda07e92070e33fb7eac6e0dfc5f593e7ec5666 100644 (file)
@@ -4937,7 +4937,7 @@ pub fn polytype_for_def(fcx: &FnCtxt,
         return polytype_for_def(fcx, sp, *inner);
       }
       def::DefTrait(_) |
-      def::DefTy(_) |
+      def::DefTy(..) |
       def::DefPrimTy(_) |
       def::DefTyParam(..)=> {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value, found type");
index 499740a78ef3926747504ad20dfaa04a60cd6b84..af670f25e5626cac3a89387896b8a9f59250a29a 100644 (file)
@@ -1235,7 +1235,7 @@ fn rebuild_arg_ty_or_output(&self,
                         Some(&d) => d
                     };
                     match a_def {
-                        def::DefTy(did) | def::DefStruct(did) => {
+                        def::DefTy(did, _) | def::DefStruct(did) => {
                             let generics = ty::lookup_item_type(self.tcx, did).generics;
 
                             let expected =
index ccff8afc50b03ff9ac808a0168e271df45cd3cc1..ccb01ca620eb77d5291dd77d90154ff178f05e5a 100644 (file)
@@ -87,7 +87,12 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
             ret.extend(build_impls(cx, tcx, did).into_iter());
             clean::StructItem(build_struct(cx, tcx, did))
         }
-        def::DefTy(did) => {
+        def::DefTy(did, false) => {
+            record_extern_fqn(cx, did, clean::TypeTypedef);
+            ret.extend(build_impls(cx, tcx, did).into_iter());
+            build_type(cx, tcx, did)
+        }
+        def::DefTy(did, true) => {
             record_extern_fqn(cx, did, clean::TypeEnum);
             ret.extend(build_impls(cx, tcx, did).into_iter());
             build_type(cx, tcx, did)
index c42d8c79144dcbdf512f6035dca0f03dffc0f7aa..c03c56cd22312c8f2c2912e578c2bd4cefbdb53e 100644 (file)
@@ -1094,6 +1094,7 @@ pub enum TypeKind {
     TypeStruct,
     TypeTrait,
     TypeVariant,
+    TypeTypedef,
 }
 
 impl Primitive {
@@ -2049,7 +2050,8 @@ fn resolve_type(cx: &DocContext, path: Path,
 fn register_def(cx: &DocContext, def: def::Def) -> ast::DefId {
     let (did, kind) = match def {
         def::DefFn(i, _) => (i, TypeFunction),
-        def::DefTy(i) => (i, TypeEnum),
+        def::DefTy(i, false) => (i, TypeTypedef),
+        def::DefTy(i, true) => (i, TypeEnum),
         def::DefTrait(i) => (i, TypeTrait),
         def::DefStruct(i) => (i, TypeStruct),
         def::DefMod(i) => (i, TypeModule),
index f36c81f8f8d8d507923794e9db6c9a55a5131b94..6e240b0d8d4a6a2e17c4589a3d9c3d7a3bed0e27 100644 (file)
@@ -45,7 +45,7 @@ pub fn to_static_str(&self) -> &'static str {
         match *self {
             Module          => "mod",
             Struct          => "struct",
-            Enum            => "type",
+            Enum            => "enum",
             Function        => "fn",
             Typedef         => "type",
             Static          => "static",
index 169446b0ac077ab9282cacff64338170a1bb0f95..a0c4283711e689ce04568bc18b23d6fcda462dde 100644 (file)
@@ -308,6 +308,7 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
                 clean::TypeModule => item_type::Module,
                 clean::TypeStatic => item_type::Static,
                 clean::TypeVariant => item_type::Variant,
+                clean::TypeTypedef => item_type::Typedef,
             }))
         }).collect()
     }).unwrap_or(HashMap::new());
index 93bf8d115b3a07c73fb4a7108e2c826840cd7000..dc18a08a4f862efdea2da621d3fad98e2baa31fa 100644 (file)
         // `rustdoc::html::item_type::ItemType` type in Rust.
         var itemTypes = ["mod",
                          "struct",
-                         "type",
+                         "enum",
                          "fn",
                          "type",
                          "static",
index b756eb2b582f70076b6dfb7f6189437e23a228d1..6951ed729b27bb162c50b6a83e106dad3db99c06 100644 (file)
@@ -24,6 +24,7 @@ mod foo {
     pub fn b() {}
     pub struct c;
     pub enum d {}
+    pub type e = int;
 
     pub struct A(());
 
@@ -36,6 +37,7 @@ fn foo() {}
     pub fn reexported_b() {}
     pub struct reexported_c;
     pub enum reexported_d {}
+    pub type reexported_e = int;
 }
 
 pub mod bar {
@@ -43,14 +45,17 @@ pub mod bar {
     pub use foo::reexported_b as f;
     pub use foo::reexported_c as g;
     pub use foo::reexported_d as h;
+    pub use foo::reexported_e as i;
 }
 
 pub static a: int = 0;
 pub fn b() {}
 pub struct c;
 pub enum d {}
+pub type e = int;
 
-static i: int = 0;
-fn j() {}
-struct k;
-enum l {}
+static j: int = 0;
+fn k() {}
+struct l;
+enum m {}
+type n = int;
index 70b2ea87ac180ae583b55d1ae9ded8a566ebd215..43be96965d01f05bfd0736e5313da04e45311fc7 100644 (file)
@@ -20,22 +20,26 @@ fn main() {
     static_priv_by_default::b;
     static_priv_by_default::c;
     foo::<static_priv_by_default::d>();
+    foo::<static_priv_by_default::e>();
 
     // publicly re-exported items should be available
     static_priv_by_default::bar::e;
     static_priv_by_default::bar::f;
     static_priv_by_default::bar::g;
     foo::<static_priv_by_default::bar::h>();
+    foo::<static_priv_by_default::bar::i>();
 
     // private items at the top should be inaccessible
-    static_priv_by_default::i;
-    //~^ ERROR: static `i` is private
     static_priv_by_default::j;
-    //~^ ERROR: function `j` is private
+    //~^ ERROR: static `j` is private
     static_priv_by_default::k;
-    //~^ ERROR: struct `k` is private
-    foo::<static_priv_by_default::l>();
-    //~^ ERROR: type `l` is private
+    //~^ ERROR: function `k` is private
+    static_priv_by_default::l;
+    //~^ ERROR: struct `l` is private
+    foo::<static_priv_by_default::m>();
+    //~^ ERROR: enum `m` is private
+    foo::<static_priv_by_default::n>();
+    //~^ ERROR: type `n` is private
 
     // public items in a private mod should be inaccessible
     static_priv_by_default::foo::a;
@@ -45,5 +49,7 @@ fn main() {
     static_priv_by_default::foo::c;
     //~^ ERROR: struct `c` is private
     foo::<static_priv_by_default::foo::d>();
-    //~^ ERROR: type `d` is private
+    //~^ ERROR: enum `d` is private
+    foo::<static_priv_by_default::foo::e>();
+    //~^ ERROR: type `e` is private
 }