diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index c4d6ff43eff08..208a5d810922a 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -73,33 +73,33 @@ fn try_inline_def<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>, let did = def.def_id(); let inner = match def { Def::Trait(did) => { - record_extern_fqn(cx, did, clean::TypeTrait); + record_extern_fqn(cx, did, clean::TypeKind::Trait); ret.extend(build_impls(cx, tcx, did)); clean::TraitItem(build_external_trait(cx, tcx, did)) } Def::Fn(did) => { - record_extern_fqn(cx, did, clean::TypeFunction); + record_extern_fqn(cx, did, clean::TypeKind::Function); clean::FunctionItem(build_external_function(cx, tcx, did)) } Def::Struct(did) // If this is a struct constructor, we skip it if tcx.def_key(did).disambiguated_data.data != DefPathData::StructCtor => { - record_extern_fqn(cx, did, clean::TypeStruct); + record_extern_fqn(cx, did, clean::TypeKind::Struct); ret.extend(build_impls(cx, tcx, did)); clean::StructItem(build_struct(cx, tcx, did)) } Def::Union(did) => { - record_extern_fqn(cx, did, clean::TypeUnion); + record_extern_fqn(cx, did, clean::TypeKind::Union); ret.extend(build_impls(cx, tcx, did)); clean::UnionItem(build_union(cx, tcx, did)) } Def::TyAlias(did) => { - record_extern_fqn(cx, did, clean::TypeTypedef); + record_extern_fqn(cx, did, clean::TypeKind::Typedef); ret.extend(build_impls(cx, tcx, did)); clean::TypedefItem(build_type_alias(cx, tcx, did), false) } Def::Enum(did) => { - record_extern_fqn(cx, did, clean::TypeEnum); + record_extern_fqn(cx, did, clean::TypeKind::Enum); ret.extend(build_impls(cx, tcx, did)); clean::EnumItem(build_enum(cx, tcx, did)) } @@ -107,15 +107,15 @@ fn try_inline_def<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>, // variants don't show up in documentation specially. Def::Variant(..) => return Some(Vec::new()), Def::Mod(did) => { - record_extern_fqn(cx, did, clean::TypeModule); + record_extern_fqn(cx, did, clean::TypeKind::Module); clean::ModuleItem(build_module(cx, tcx, did)) } Def::Static(did, mtbl) => { - record_extern_fqn(cx, did, clean::TypeStatic); + record_extern_fqn(cx, did, clean::TypeKind::Static); clean::StaticItem(build_static(cx, tcx, did, mtbl)) } Def::Const(did) | Def::AssociatedConst(did) => { - record_extern_fqn(cx, did, clean::TypeConst); + record_extern_fqn(cx, did, clean::TypeKind::Const); clean::ConstantItem(build_const(cx, tcx, did)) } _ => return None, @@ -577,7 +577,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) _ => true, } }); - return g; + g } /// Supertrait bounds for a trait are also listed in the generics coming from diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c1ee4e61c5c72..cf20572510b5c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -12,10 +12,7 @@ //! that clean them. pub use self::Type::*; -pub use self::TypeKind::*; -pub use self::VariantKind::*; pub use self::Mutability::*; -pub use self::Import::*; pub use self::ItemEnum::*; pub use self::Attribute::*; pub use self::TyParamBound::*; @@ -319,7 +316,7 @@ impl Item { match self.inner { StructItem(ref _struct) => Some(_struct.fields_stripped), UnionItem(ref union) => Some(union.fields_stripped), - VariantItem(Variant { kind: StructVariant(ref vstruct)} ) => { + VariantItem(Variant { kind: VariantKind::Struct(ref vstruct)} ) => { Some(vstruct.fields_stripped) }, _ => None, @@ -688,7 +685,7 @@ impl Clean for ty::BuiltinBound { (tcx.lang_items.sync_trait().unwrap(), external_path(cx, "Sync", None, false, vec![], empty)), }; - inline::record_extern_fqn(cx, did, TypeTrait); + inline::record_extern_fqn(cx, did, TypeKind::Trait); TraitBound(PolyTrait { trait_: ResolvedPath { path: path, @@ -707,7 +704,7 @@ impl<'tcx> Clean for ty::TraitRef<'tcx> { Some(tcx) => tcx, None => return RegionBound(Lifetime::statik()) }; - inline::record_extern_fqn(cx, self.def_id, TypeTrait); + inline::record_extern_fqn(cx, self.def_id, TypeKind::Trait); let path = external_path(cx, &tcx.item_name(self.def_id).as_str(), Some(self.def_id), true, vec![], self.substs); @@ -765,7 +762,7 @@ impl Lifetime { pub fn get_ref<'a>(&'a self) -> &'a str { let Lifetime(ref s) = *self; let s: &'a str = s; - return s; + s } pub fn statik() -> Lifetime { @@ -1130,7 +1127,7 @@ pub struct FnDecl { impl FnDecl { pub fn has_self(&self) -> bool { - return self.inputs.values.len() > 0 && self.inputs.values[0].name == "self"; + self.inputs.values.len() > 0 && self.inputs.values[0].name == "self" } pub fn self_type(&self) -> Option { @@ -1480,16 +1477,16 @@ pub enum PrimitiveType { #[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)] pub enum TypeKind { - TypeEnum, - TypeFunction, - TypeModule, - TypeConst, - TypeStatic, - TypeStruct, - TypeUnion, - TypeTrait, - TypeVariant, - TypeTypedef, + Enum, + Function, + Module, + Const, + Static, + Struct, + Union, + Trait, + Variant, + Typedef, } pub trait GetDefId { @@ -1572,7 +1569,7 @@ impl PrimitiveType { None } - pub fn to_string(&self) -> &'static str { + pub fn as_str(&self) -> &'static str { match *self { PrimitiveType::Isize => "isize", PrimitiveType::I8 => "i8", @@ -1597,7 +1594,7 @@ impl PrimitiveType { } pub fn to_url_str(&self) -> &'static str { - self.to_string() + self.as_str() } /// Creates a rustdoc-specific node id for primitive types. @@ -1795,9 +1792,9 @@ impl<'tcx> Clean for ty::Ty<'tcx> { ty::TyAdt(def, substs) => { let did = def.did; let kind = match def.adt_kind() { - AdtKind::Struct => TypeStruct, - AdtKind::Union => TypeUnion, - AdtKind::Enum => TypeEnum, + AdtKind::Struct => TypeKind::Struct, + AdtKind::Union => TypeKind::Union, + AdtKind::Enum => TypeKind::Enum, }; inline::record_extern_fqn(cx, did, kind); let path = external_path(cx, &cx.tcx().item_name(did).as_str(), @@ -1811,7 +1808,7 @@ impl<'tcx> Clean for ty::Ty<'tcx> { } ty::TyTrait(ref obj) => { let did = obj.principal.def_id(); - inline::record_extern_fqn(cx, did, TypeTrait); + inline::record_extern_fqn(cx, did, TypeKind::Trait); let mut typarams = vec![]; obj.region_bound.clean(cx).map(|b| typarams.push(RegionBound(b))); @@ -2027,7 +2024,7 @@ impl Clean for doctree::Variant { deprecation: self.depr.clean(cx), def_id: cx.map.local_def_id(self.def.id()), inner: VariantItem(Variant { - kind: struct_def_to_variant_kind(&self.def, cx), + kind: self.def.clean(cx), }), } } @@ -2036,14 +2033,14 @@ impl Clean for doctree::Variant { impl<'tcx> Clean for ty::VariantDefData<'tcx, 'static> { fn clean(&self, cx: &DocContext) -> Item { let kind = match self.kind { - ty::VariantKind::Unit => CLikeVariant, + ty::VariantKind::Unit => VariantKind::CLike, ty::VariantKind::Tuple => { - TupleVariant( + VariantKind::Tuple( self.fields.iter().map(|f| f.unsubst_ty().clean(cx)).collect() ) } ty::VariantKind::Struct => { - StructVariant(VariantStruct { + VariantKind::Struct(VariantStruct { struct_type: doctree::Plain, fields_stripped: false, fields: self.fields.iter().map(|field| { @@ -2076,18 +2073,20 @@ impl<'tcx> Clean for ty::VariantDefData<'tcx, 'static> { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum VariantKind { - CLikeVariant, - TupleVariant(Vec), - StructVariant(VariantStruct), + CLike, + Tuple(Vec), + Struct(VariantStruct), } -fn struct_def_to_variant_kind(struct_def: &hir::VariantData, cx: &DocContext) -> VariantKind { - if struct_def.is_struct() { - StructVariant(struct_def.clean(cx)) - } else if struct_def.is_unit() { - CLikeVariant - } else { - TupleVariant(struct_def.fields().iter().map(|x| x.ty.clean(cx)).collect()) +impl Clean for hir::VariantData { + fn clean(&self, cx: &DocContext) -> VariantKind { + if self.is_struct() { + VariantKind::Struct(self.clean(cx)) + } else if self.is_unit() { + VariantKind::CLike + } else { + VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect()) + } } } @@ -2526,7 +2525,7 @@ impl Clean> for doctree::Import { }); let (mut ret, inner) = match self.node { hir::ViewPathGlob(ref p) => { - (vec![], GlobImport(resolve_use_source(cx, p.clean(cx), self.id))) + (vec![], Import::Glob(resolve_use_source(cx, p.clean(cx), self.id))) } hir::ViewPathList(ref p, ref list) => { // Attempt to inline all reexported items, but be sure @@ -2552,8 +2551,7 @@ impl Clean> for doctree::Import { if remaining.is_empty() { return ret; } - (ret, ImportList(resolve_use_source(cx, p.clean(cx), self.id), - remaining)) + (ret, Import::List(resolve_use_source(cx, p.clean(cx), self.id), remaining)) } hir::ViewPathSimple(name, ref p) => { if !denied { @@ -2561,8 +2559,8 @@ impl Clean> for doctree::Import { return items; } } - (vec![], SimpleImport(name.clean(cx), - resolve_use_source(cx, p.clean(cx), self.id))) + (vec![], Import::Simple(name.clean(cx), + resolve_use_source(cx, p.clean(cx), self.id))) } }; ret.push(Item { @@ -2582,11 +2580,11 @@ impl Clean> for doctree::Import { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum Import { // use source as str; - SimpleImport(String, ImportSource), + Simple(String, ImportSource), // use source::*; - GlobImport(ImportSource), + Glob(ImportSource), // use source::{a, b, c}; - ImportList(ImportSource, Vec), + List(ImportSource, Vec), } #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] @@ -2761,16 +2759,16 @@ fn register_def(cx: &DocContext, def: Def) -> DefId { let tcx = cx.tcx(); let (did, kind) = match def { - Def::Fn(i) => (i, TypeFunction), - Def::TyAlias(i) => (i, TypeTypedef), - Def::Enum(i) => (i, TypeEnum), - Def::Trait(i) => (i, TypeTrait), - Def::Struct(i) => (i, TypeStruct), - Def::Union(i) => (i, TypeUnion), - Def::Mod(i) => (i, TypeModule), - Def::Static(i, _) => (i, TypeStatic), - Def::Variant(i) => (tcx.parent_def_id(i).unwrap(), TypeEnum), - Def::SelfTy(Some(def_id), _) => (def_id, TypeTrait), + Def::Fn(i) => (i, TypeKind::Function), + Def::TyAlias(i) => (i, TypeKind::Typedef), + Def::Enum(i) => (i, TypeKind::Enum), + Def::Trait(i) => (i, TypeKind::Trait), + Def::Struct(i) => (i, TypeKind::Struct), + Def::Union(i) => (i, TypeKind::Union), + Def::Mod(i) => (i, TypeKind::Module), + Def::Static(i, _) => (i, TypeKind::Static), + Def::Variant(i) => (tcx.parent_def_id(i).unwrap(), TypeKind::Enum), + Def::SelfTy(Some(def_id), _) => (def_id, TypeKind::Trait), Def::SelfTy(_, Some(impl_def_id)) => { return impl_def_id } @@ -2778,7 +2776,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId { }; if did.is_local() { return did } inline::record_extern_fqn(cx, did, kind); - if let TypeTrait = kind { + if let TypeKind::Trait = kind { let t = inline::build_external_trait(cx, tcx, did); cx.external_traits.borrow_mut().insert(did, t); } @@ -2966,7 +2964,7 @@ fn lang_struct(cx: &DocContext, did: Option, Some(did) => did, None => return fallback(box t.clean(cx)), }; - inline::record_extern_fqn(cx, did, TypeStruct); + inline::record_extern_fqn(cx, did, TypeKind::Struct); ResolvedPath { typarams: None, did: did, diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 7ae177439064f..15e042f8c0809 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -141,7 +141,7 @@ pub fn ty_params(mut params: Vec) -> Vec { for param in &mut params { param.bounds = ty_bounds(mem::replace(&mut param.bounds, Vec::new())); } - return params; + params } fn ty_bounds(bounds: Vec) -> Vec { diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index 8d6ab221c4fce..e269d940bfabf 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -74,12 +74,12 @@ pub trait DocFolder : Sized { VariantItem(i) => { let i2 = i.clone(); // this clone is small match i.kind { - StructVariant(mut j) => { + VariantKind::Struct(mut j) => { let num_fields = j.fields.len(); j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); j.fields_stripped |= num_fields != j.fields.len() || j.fields.iter().any(|f| f.is_stripped()); - VariantItem(Variant {kind: StructVariant(j), ..i2}) + VariantItem(Variant {kind: VariantKind::Struct(j), ..i2}) }, _ => VariantItem(i2) } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index adcdc7aaab400..3f7f01a9a3b51 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -457,7 +457,7 @@ impl fmt::Display for clean::Type { tybounds(f, typarams) } clean::Infer => write!(f, "_"), - clean::Primitive(prim) => primitive_link(f, prim, prim.to_string()), + clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()), clean::BareFunction(ref decl) => { write!(f, "{}{}fn{}{}", UnsafetySpace(decl.unsafety), @@ -708,17 +708,17 @@ impl fmt::Display for ConstnessSpace { impl fmt::Display for clean::Import { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - clean::SimpleImport(ref name, ref src) => { + clean::Import::Simple(ref name, ref src) => { if *name == src.path.last_name() { write!(f, "use {};", *src) } else { write!(f, "use {} as {};", *src, *name) } } - clean::GlobImport(ref src) => { + clean::Import::Glob(ref src) => { write!(f, "use {}::*;", *src) } - clean::ImportList(ref src, ref names) => { + clean::Import::List(ref src, ref names) => { write!(f, "use {}::{{", *src)?; for (i, n) in names.iter().enumerate() { if i > 0 { diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index b93dc17dbdd7d..f584c4e2f4d9c 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -90,16 +90,16 @@ impl<'a> From<&'a clean::Item> for ItemType { impl From for ItemType { fn from(kind: clean::TypeKind) -> ItemType { match kind { - clean::TypeStruct => ItemType::Struct, - clean::TypeUnion => ItemType::Union, - clean::TypeEnum => ItemType::Enum, - clean::TypeFunction => ItemType::Function, - clean::TypeTrait => ItemType::Trait, - clean::TypeModule => ItemType::Module, - clean::TypeStatic => ItemType::Static, - clean::TypeConst => ItemType::Constant, - clean::TypeVariant => ItemType::Variant, - clean::TypeTypedef => ItemType::Typedef, + clean::TypeKind::Struct => ItemType::Struct, + clean::TypeKind::Union => ItemType::Union, + clean::TypeKind::Enum => ItemType::Enum, + clean::TypeKind::Function => ItemType::Function, + clean::TypeKind::Trait => ItemType::Trait, + clean::TypeKind::Module => ItemType::Module, + clean::TypeKind::Static => ItemType::Static, + clean::TypeKind::Const => ItemType::Constant, + clean::TypeKind::Variant => ItemType::Variant, + clean::TypeKind::Typedef => ItemType::Typedef, } } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 46461226381a3..5a6e167188226 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -722,7 +722,7 @@ fn write_shared(cx: &Context, ret.push(line.to_string()); } } - return Ok(ret); + Ok(ret) } // Update the search index @@ -1208,7 +1208,7 @@ impl DocFolder for Cache { self.seen_mod = orig_seen_mod; self.stripped_mod = orig_stripped_mod; self.parent_is_trait_impl = orig_parent_is_trait_impl; - return ret; + ret } } @@ -1249,7 +1249,7 @@ impl Context { self.dst = prev; self.current.pop().unwrap(); - return ret; + ret } /// Main method for rendering a crate. @@ -1450,7 +1450,7 @@ impl Context { for (_, items) in &mut map { items.sort(); } - return map; + map } } @@ -1647,7 +1647,7 @@ fn full_path(cx: &Context, item: &clean::Item) -> String { let mut s = cx.current.join("::"); s.push_str("::"); s.push_str(item.name.as_ref().unwrap()); - return s + s } fn shorter<'a>(s: Option<&'a str>) -> String { @@ -2378,8 +2378,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, match v.inner { clean::VariantItem(ref var) => { match var.kind { - clean::CLikeVariant => write!(w, "{}", name)?, - clean::TupleVariant(ref tys) => { + clean::VariantKind::CLike => write!(w, "{}", name)?, + clean::VariantKind::Tuple(ref tys) => { write!(w, "{}(", name)?; for (i, ty) in tys.iter().enumerate() { if i > 0 { @@ -2389,7 +2389,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } write!(w, ")")?; } - clean::StructVariant(ref s) => { + clean::VariantKind::Struct(ref s) => { render_struct(w, v, None, @@ -2429,7 +2429,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, ns_id = ns_id, name = variant.name.as_ref().unwrap())?; if let clean::VariantItem(ref var) = variant.inner { - if let clean::TupleVariant(ref tys) = var.kind { + if let clean::VariantKind::Tuple(ref tys) = var.kind { write!(w, "(")?; for (i, ty) in tys.iter().enumerate() { if i > 0 { @@ -2443,8 +2443,10 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "")?; document(w, cx, variant)?; - use clean::{Variant, StructVariant}; - if let clean::VariantItem( Variant { kind: StructVariant(ref s) } ) = variant.inner { + use clean::{Variant, VariantKind}; + if let clean::VariantItem(Variant { + kind: VariantKind::Struct(ref s) + }) = variant.inner { write!(w, "

Fields

\n ")?; for field in &s.fields { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1ff84b95da6a4..006dda7d66199 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -288,15 +288,14 @@ pub fn main_args(args: &[String]) -> isize { passes.into_iter().collect(), css_file_extension, renderinfo) - .expect("failed to generate documentation") + .expect("failed to generate documentation"); + 0 } Some(s) => { println!("unknown output format: {}", s); - return 1; + 1 } } - - return 0; } /// Looks inside the command line arguments to extract the relevant input format diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index a1b330e9b8423..1cc4f9371cb68 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -131,7 +131,7 @@ impl<'a> fold::DocFolder for Stripper<'a> { clean::ImplItem(ref imp) if imp.trait_.is_some() => true, // Struct variant fields have inherited visibility clean::VariantItem(clean::Variant { - kind: clean::StructVariant(..) + kind: clean::VariantKind::Struct(..) }) => true, _ => false, }; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 02f0916de0ef3..ed9efca77e7a9 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -169,7 +169,7 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions { } } - return opts; + opts } fn runtest(test: &str, cratename: &str, cfgs: Vec, libs: SearchPaths, @@ -264,9 +264,9 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec, libs: SearchPaths, Ok(r) => { match r { Err(count) => { - if count > 0 && compile_fail == false { + if count > 0 && !compile_fail { sess.fatal("aborting due to previous error(s)") - } else if count == 0 && compile_fail == true { + } else if count == 0 && compile_fail { panic!("test compiled while it wasn't supposed to") } if count > 0 && error_codes.len() > 0 { @@ -279,7 +279,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec, libs: SearchPaths, } } Err(_) => { - if compile_fail == false { + if !compile_fail { panic!("couldn't compile the test"); } if error_codes.len() > 0 { @@ -363,7 +363,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool, info!("final test program: {}", prog); - return prog + prog } fn partition_source(s: &str) -> (String, String) { @@ -387,7 +387,7 @@ fn partition_source(s: &str) -> (String, String) { } } - return (before, after); + (before, after) } pub struct Collector { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index a29566f7a0717..4d1af1622724a 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -328,7 +328,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { _ => false, }; self.view_item_stack.remove(&def_node_id); - return ret; + ret } pub fn visit_item(&mut self, item: &hir::Item,