1
Fork 0

Revert "Greatly improve generics handling in rustdoc search"

This reverts commit 64382f4b78.
This commit is contained in:
Eduard-Mihai Burtescu 2019-04-08 09:54:26 +03:00
parent 9b19cc0c21
commit 9e528ffe9c
3 changed files with 22 additions and 64 deletions

View file

@ -1142,10 +1142,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
);
}
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
checked_type_of(tcx, def_id, true).unwrap()
}
fn infer_placeholder_type(
tcx: TyCtxt<'_>,
def_id: DefId,
@ -1189,26 +1185,14 @@ fn infer_placeholder_type(
ty
}
/// Same as [`type_of`] but returns [`Option`] instead of failing.
///
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
/// you'd better just call [`type_of`] directly.
pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<'_>> {
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
use rustc::hir::*;
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
Some(hir_id) => hir_id,
None => {
if !fail {
return None;
}
bug!("invalid node");
}
};
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let icx = ItemCtxt::new(tcx, def_id);
Some(match tcx.hir().get(hir_id) {
match tcx.hir().get(hir_id) {
Node::TraitItem(item) => match item.kind {
TraitItemKind::Method(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
@ -1225,9 +1209,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
},
TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
TraitItemKind::Type(_, None) => {
if !fail {
return None;
}
span_bug!(item.span, "associated type missing default");
}
},
@ -1321,9 +1302,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
| ItemKind::GlobalAsm(..)
| ItemKind::ExternCrate(..)
| ItemKind::Use(..) => {
if !fail {
return None;
}
span_bug!(
item.span,
"compute_type_of_item: unexpected item type: {:?}",
@ -1361,7 +1339,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
..
}) => {
if gen.is_some() {
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
return tcx.typeck_tables_of(def_id).node_type(hir_id);
}
let substs = InternalSubsts::identity_for_item(tcx, def_id);
@ -1436,13 +1414,9 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
.map(|(index, _)| index)
.next()
})
.or_else(|| {
if !fail {
None
} else {
bug!("no arg matching AnonConst in path")
}
})?;
.unwrap_or_else(|| {
bug!("no arg matching AnonConst in path");
});
// We've encountered an `AnonConst` in some path, so we need to
// figure out which generic parameter it corresponds to and return
@ -1452,8 +1426,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
tcx.generics_of(tcx.parent(def_id).unwrap())
}
Res::Def(_, def_id) => tcx.generics_of(def_id),
Res::Err => return Some(tcx.types.err),
_ if !fail => return None,
Res::Err => return tcx.types.err,
res => {
tcx.sess.delay_span_bug(
DUMMY_SP,
@ -1462,7 +1435,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
res,
),
);
return Some(tcx.types.err);
return tcx.types.err;
}
};
@ -1480,9 +1453,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
// probably from an extra arg where one is not needed.
.unwrap_or(tcx.types.err)
} else {
if !fail {
return None;
}
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
@ -1490,14 +1460,11 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
parent_node,
),
);
return Some(tcx.types.err);
return tcx.types.err;
}
}
x => {
if !fail {
return None;
}
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
@ -1547,21 +1514,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
}
ty
}
x => {
if !fail {
return None;
}
bug!("unexpected non-type Node::GenericParam: {:?}", x)
},
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
},
x => {
if !fail {
return None;
}
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
}
})
}
}
fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {

View file

@ -109,8 +109,6 @@ use util::common::time;
use std::iter;
use astconv::{AstConv, Bounds};
pub use collect::checked_type_of;
pub struct TypeAndSubsts<'tcx> {
substs: SubstsRef<'tcx>,
ty: Ty<'tcx>,

View file

@ -1491,12 +1491,13 @@ impl GenericParamDefKind {
}
}
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
match *self {
GenericParamDefKind::Type { did, .. } => {
rustc_typeck::checked_type_of(cx.tcx, did, false).map(|t| t.clean(cx))
}
GenericParamDefKind::Const { ref ty, .. } => Some(ty.clone()),
// FIXME(eddyb) this either returns the default of a type parameter, or the
// type of a `const` parameter. It seems that the intention is to *visit*
// any embedded types, but `get_type` seems to be the wrong name for that.
pub fn get_type(&self) -> Option<Type> {
match self {
GenericParamDefKind::Type { default, .. } => default.clone(),
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
GenericParamDefKind::Lifetime => None,
}
}
@ -1522,8 +1523,8 @@ impl GenericParamDef {
self.kind.is_type()
}
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
self.kind.get_type(cx)
pub fn get_type(&self) -> Option<Type> {
self.kind.get_type()
}
pub fn get_bounds(&self) -> Option<&[GenericBound]> {
@ -1891,7 +1892,7 @@ fn get_real_types(
if !x.is_type() {
continue
}
if let Some(ty) = x.get_type(cx) {
if let Some(ty) = x.get_type() {
let adds = get_real_types(generics, &ty, cx, recurse + 1);
if !adds.is_empty() {
res.extend(adds);