diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index d7646ce7bfc5c..73a7e0e690fe9 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -35,10 +35,29 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { AdtKind::Enum => Def::Enum, AdtKind::Union => Def::Union, } - _ => panic!("Unexpected type {:?}", def_id), + ty::TyInt(_) | + ty::TyUint(_) | + ty::TyFloat(_) | + ty::TyStr | + ty::TyBool | + ty::TyChar => return self.get_auto_trait_impls(def_id, &move |_: DefId| { + match ty.sty { + ty::TyInt(x) => Def::PrimTy(hir::TyInt(x)), + ty::TyUint(x) => Def::PrimTy(hir::TyUint(x)), + ty::TyFloat(x) => Def::PrimTy(hir::TyFloat(x)), + ty::TyStr => Def::PrimTy(hir::TyStr), + ty::TyBool => Def::PrimTy(hir::TyBool), + ty::TyChar => Def::PrimTy(hir::TyChar), + _ => unreachable!(), + } + }, None), + _ => { + debug!("Unexpected type {:?}", def_id); + return Vec::new() + } }; - self.get_auto_trait_impls(def_id, def_ctor, None) + self.get_auto_trait_impls(def_id, &def_ctor, None) } pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { @@ -52,15 +71,16 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { _ => panic!("Unexpected type {:?} {:?}", item, id), }; - self.get_auto_trait_impls(did, def_ctor, Some(name)) + self.get_auto_trait_impls(did, &def_ctor, Some(name)) } - pub fn get_auto_trait_impls( + pub fn get_auto_trait_impls( &self, def_id: DefId, - def_ctor: fn(DefId) -> Def, + def_ctor: &F, name: Option, - ) -> Vec { + ) -> Vec + where F: Fn(DefId) -> Def { if self.cx .tcx .get_attrs(def_id) @@ -68,9 +88,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { .has_word("hidden") { debug!( - "get_auto_trait_impls(def_id={:?}, def_ctor={:?}): item has doc('hidden'), \ + "get_auto_trait_impls(def_id={:?}, def_ctor=...): item has doc('hidden'), \ aborting", - def_id, def_ctor + def_id ); return Vec::new(); } @@ -79,8 +99,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { let generics = self.cx.tcx.generics_of(def_id); debug!( - "get_auto_trait_impls(def_id={:?}, def_ctor={:?}, generics={:?}", - def_id, def_ctor, generics + "get_auto_trait_impls(def_id={:?}, def_ctor=..., generics={:?}", + def_id, generics ); let auto_traits: Vec<_> = self.cx .send_trait @@ -110,23 +130,24 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { auto_traits } - fn get_auto_trait_impl_for( + fn get_auto_trait_impl_for( &self, def_id: DefId, name: Option, generics: ty::Generics, - def_ctor: fn(DefId) -> Def, + def_ctor: &F, trait_def_id: DefId, - ) -> Option { + ) -> Option + where F: Fn(DefId) -> Def { if !self.cx .generated_synthetics .borrow_mut() .insert((def_id, trait_def_id)) { debug!( - "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor={:?}, \ + "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor=..., \ trait_def_id={:?}): already generated, aborting", - def_id, generics, def_ctor, trait_def_id + def_id, generics, trait_def_id ); return None; } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index a8f4848bf89f2..da04068107d3f 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -302,6 +302,14 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec = auto_impls.into_iter() + .filter(|i| renderinfo.inlined.insert(i.def_id)).collect(); + + impls.extend(new_impls); } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c233e57a8018e..6beb64dced16e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -4183,7 +4183,8 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option { } } -fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: fn(DefId) -> Def) -> hir::Path { +fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: F) -> hir::Path +where F: Fn(DefId) -> Def { struct AbsolutePathBuffer { names: Vec, } diff --git a/src/test/rustdoc/auto-impl-primitive.rs b/src/test/rustdoc/auto-impl-primitive.rs new file mode 100644 index 0000000000000..a3887b33cc2bb --- /dev/null +++ b/src/test/rustdoc/auto-impl-primitive.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] +pub use std::fs::File; + +// @has 'foo/primitive.i16.html' '//h2[@id="synthetic-implementations"]' 'Auto Trait Implementation' +#[doc(primitive = "i16")] +/// I love poneys! +mod prim {}