use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_index::vec::{Idx, IndexVec};
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
-use rustc_middle::bug;
use rustc_middle::middle::resolve_lifetime as rl;
use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{self, AdtKind, Lift, Ty, TyCtxt};
+use rustc_middle::{bug, span_bug};
use rustc_mir::const_eval::{is_const_fn, is_unstable_const_fn};
use rustc_span::hygiene::{AstPass, MacroKind};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
// determine if we should display the inner contents or
// the outer `mod` item for the source code.
let span = Span::from_rustc_span({
+ let where_outer = self.where_outer(cx.tcx);
let sm = cx.sess().source_map();
- let outer = sm.lookup_char_pos(self.where_outer.lo());
+ let outer = sm.lookup_char_pos(where_outer.lo());
let inner = sm.lookup_char_pos(self.where_inner.lo());
if outer.file.start_pos == inner.file.start_pos {
// mod foo { ... }
- self.where_outer
+ where_outer
} else {
// mod foo; (and a separate SourceFile for the contents)
self.where_inner
impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
fn clean(&self, cx: &mut DocContext<'_>) -> Type {
let (trait_ref, bounds) = *self;
- inline::record_extern_fqn(cx, trait_ref.def_id, ItemType::Trait);
+ let kind = cx.tcx.def_kind(trait_ref.def_id).into();
+ if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
+ span_bug!(
+ cx.tcx.def_span(trait_ref.def_id),
+ "`TraitRef` had unexpected kind {:?}",
+ kind
+ );
+ }
+ inline::record_extern_fqn(cx, trait_ref.def_id, kind);
let path = external_path(
cx,
cx.tcx.item_name(trait_ref.def_id),
match param.kind {
GenericParamDefKind::Lifetime => unreachable!(),
GenericParamDefKind::Type { did, ref bounds, .. } => {
- cx.impl_trait_bounds.insert(did.into(), bounds.clone());
+ cx.impl_trait_bounds
+ .insert(FakeDefId::new_real(did).into(), bounds.clone());
}
GenericParamDefKind::Const { .. } => unreachable!(),
}
.collect::<Vec<GenericParamDef>>();
// param index -> [(DefId of trait, associated type name, type)]
- let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, Symbol, Ty<'tcx>)>>::default();
+ let mut impl_trait_proj = FxHashMap::<u32, Vec<(FakeDefId, Symbol, Ty<'tcx>)>>::default();
let where_predicates = preds
.predicates
if let Some(((_, trait_did, name), rhs)) =
proj.as_ref().and_then(|(lhs, rhs)| Some((lhs.projection()?, rhs)))
{
- impl_trait_proj
- .entry(param_idx)
- .or_default()
- .push((trait_did, name, rhs));
+ impl_trait_proj.entry(param_idx).or_default().push((
+ trait_did.into(),
+ name,
+ rhs,
+ ));
}
return None;
if let Some(proj) = impl_trait_proj.remove(&idx) {
for (trait_did, name, rhs) in proj {
let rhs = rhs.clean(cx);
- simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs);
+ simplify::merge_bounds(
+ cx,
+ &mut bounds,
+ trait_did.expect_real(),
+ name,
+ &rhs,
+ );
}
}
} else {
if let Some(new_ty) = cx.ty_substs.get(&did).cloned() {
return new_ty;
}
- if let Some(bounds) = cx.impl_trait_bounds.remove(&did.into()) {
+ if let Some(bounds) = cx.impl_trait_bounds.remove(&FakeDefId::new_real(did).into())
+ {
return ImplTrait(bounds);
}
}
build_deref_target_impls(cx, &items, &mut ret);
}
- let provided: FxHashSet<Symbol> = trait_
- .def_id()
- .map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect())
- .unwrap_or_default();
-
let for_ = impl_.self_ty.clean(cx);
let type_alias = for_.def_id().and_then(|did| match tcx.def_kind(did) {
DefKind::TyAlias => Some(tcx.type_of(did).clean(cx)),
span: types::rustc_span(tcx.hir().local_def_id(hir_id).to_def_id(), tcx),
unsafety: impl_.unsafety,
generics: impl_.generics.clean(cx),
- provided_trait_methods: provided.clone(),
trait_,
for_,
items,
vec![Item {
name: Some(name),
attrs: box attrs.clean(cx),
- def_id: crate_def_id,
+ def_id: crate_def_id.into(),
visibility: krate.vis.clean(cx),
kind: box ExternCrateItem { src: orig_name },
cfg: attrs.cfg(cx.sess()),