summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/clean/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/clean/types.rs')
-rw-r--r--src/librustdoc/clean/types.rs77
1 files changed, 39 insertions, 38 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index e9ccea2cf..26139d527 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -42,7 +42,6 @@ use crate::formats::item_type::ItemType;
use crate::html::render::Context;
use crate::passes::collect_intra_doc_links::UrlFragment;
-pub(crate) use self::FnRetTy::*;
pub(crate) use self::ItemKind::*;
pub(crate) use self::SelfTy::*;
pub(crate) use self::Type::{
@@ -359,15 +358,15 @@ fn is_field_vis_inherited(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
impl Item {
pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
- self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
+ self.def_id().and_then(|did| tcx.lookup_stability(did))
}
pub(crate) fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
- self.item_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
+ self.def_id().and_then(|did| tcx.lookup_const_stability(did))
}
pub(crate) fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {
- self.item_id.as_def_id().and_then(|did| tcx.lookup_deprecation(did))
+ self.def_id().and_then(|did| tcx.lookup_deprecation(did))
}
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
@@ -392,7 +391,7 @@ impl Item {
panic!("blanket impl item has non-blanket ID")
}
}
- _ => self.item_id.as_def_id().map(|did| rustc_span(did, tcx)),
+ _ => self.def_id().map(|did| rustc_span(did, tcx)),
}
}
@@ -502,7 +501,7 @@ impl Item {
}
pub(crate) fn is_crate(&self) -> bool {
- self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.is_crate_root())
+ self.is_mod() && self.def_id().map_or(false, |did| did.is_crate_root())
}
pub(crate) fn is_mod(&self) -> bool {
self.type_() == ItemType::Module
@@ -639,11 +638,11 @@ impl Item {
}
let header = match *self.kind {
ItemKind::ForeignFunctionItem(_) => {
- let def_id = self.item_id.as_def_id().unwrap();
+ let def_id = self.def_id().unwrap();
let abi = tcx.fn_sig(def_id).skip_binder().abi();
hir::FnHeader {
unsafety: if abi == Abi::RustIntrinsic {
- intrinsic_operation_unsafety(tcx, self.item_id.as_def_id().unwrap())
+ intrinsic_operation_unsafety(tcx, self.def_id().unwrap())
} else {
hir::Unsafety::Unsafe
},
@@ -660,7 +659,7 @@ impl Item {
}
}
ItemKind::FunctionItem(_) | ItemKind::MethodItem(_, _) | ItemKind::TyMethodItem(_) => {
- let def_id = self.item_id.as_def_id().unwrap();
+ let def_id = self.def_id().unwrap();
build_fn_header(def_id, tcx, tcx.asyncness(def_id))
}
_ => return None,
@@ -739,7 +738,7 @@ impl Item {
}
})
.collect();
- if let Some(def_id) = self.item_id.as_def_id() &&
+ if let Some(def_id) = self.def_id() &&
!def_id.is_local() &&
// This check is needed because `adt_def` will panic if not a compatible type otherwise...
matches!(self.type_(), ItemType::Struct | ItemType::Enum | ItemType::Union)
@@ -784,6 +783,14 @@ impl Item {
}
attrs
}
+
+ pub fn is_doc_hidden(&self) -> bool {
+ self.attrs.is_doc_hidden()
+ }
+
+ pub fn def_id(&self) -> Option<DefId> {
+ self.item_id.as_def_id()
+ }
}
#[derive(Clone, Debug)]
@@ -949,6 +956,8 @@ pub(crate) trait AttributesExt {
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
} else if doc_auto_cfg_active {
+ // If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
+ // `doc(cfg())` overrides `cfg()`).
self.iter()
.filter(|attr| attr.has_name(sym::cfg))
.filter_map(|attr| single(attr.meta_item_list()?))
@@ -1130,6 +1139,10 @@ impl Attributes {
false
}
+ fn is_doc_hidden(&self) -> bool {
+ self.has_doc_flag(sym::hidden)
+ }
+
pub(crate) fn from_ast(attrs: &[ast::Attribute]) -> Attributes {
Attributes::from_ast_iter(attrs.iter().map(|attr| (attr, None)), false)
}
@@ -1353,7 +1366,7 @@ pub(crate) struct Function {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct FnDecl {
pub(crate) inputs: Arguments,
- pub(crate) output: FnRetTy,
+ pub(crate) output: Type,
pub(crate) c_variadic: bool,
}
@@ -1371,18 +1384,16 @@ impl FnDecl {
///
/// This function will panic if the return type does not match the expected sugaring for async
/// functions.
- pub(crate) fn sugared_async_return_type(&self) -> FnRetTy {
- match &self.output {
- FnRetTy::Return(Type::ImplTrait(bounds)) => match &bounds[0] {
- GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => {
- let bindings = trait_.bindings().unwrap();
- let ret_ty = bindings[0].term();
- let ty = ret_ty.ty().expect("Unexpected constant return term");
- FnRetTy::Return(ty.clone())
- }
- _ => panic!("unexpected desugaring of async function"),
- },
- _ => panic!("unexpected desugaring of async function"),
+ pub(crate) fn sugared_async_return_type(&self) -> Type {
+ if let Type::ImplTrait(v) = &self.output &&
+ let [GenericBound::TraitBound(PolyTrait { trait_, .. }, _ )] = &v[..]
+ {
+ let bindings = trait_.bindings().unwrap();
+ let ret_ty = bindings[0].term();
+ let ty = ret_ty.ty().expect("Unexpected constant return term");
+ ty.clone()
+ } else {
+ panic!("unexpected desugaring of async function")
}
}
}
@@ -1425,21 +1436,6 @@ impl Argument {
}
}
-#[derive(Clone, PartialEq, Eq, Debug, Hash)]
-pub(crate) enum FnRetTy {
- Return(Type),
- DefaultReturn,
-}
-
-impl FnRetTy {
- pub(crate) fn as_return(&self) -> Option<&Type> {
- match self {
- Return(ret) => Some(ret),
- DefaultReturn => None,
- }
- }
-}
-
#[derive(Clone, Debug)]
pub(crate) struct Trait {
pub(crate) def_id: DefId,
@@ -1641,6 +1637,10 @@ impl Type {
matches!(self, Type::ImplTrait(_))
}
+ pub(crate) fn is_unit(&self) -> bool {
+ matches!(self, Type::Tuple(v) if v.is_empty())
+ }
+
pub(crate) fn projection(&self) -> Option<(&Type, DefId, PathSegment)> {
if let QPath(box QPathData { self_type, trait_, assoc, .. }) = self {
Some((self_type, trait_.as_ref()?.def_id(), assoc.clone()))
@@ -2389,6 +2389,7 @@ impl ImplKind {
#[derive(Clone, Debug)]
pub(crate) struct Import {
pub(crate) kind: ImportKind,
+ /// The item being re-exported.
pub(crate) source: ImportSource,
pub(crate) should_be_displayed: bool,
}