Skip to content

Commit 9e528ff

Browse files
committed
Revert "Greatly improve generics handling in rustdoc search"
This reverts commit 64382f4.
1 parent 9b19cc0 commit 9e528ff

File tree

3 files changed

+22
-64
lines changed

3 files changed

+22
-64
lines changed

src/librustc_typeck/collect.rs

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,10 +1142,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
11421142
);
11431143
}
11441144

1145-
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1146-
checked_type_of(tcx, def_id, true).unwrap()
1147-
}
1148-
11491145
fn infer_placeholder_type(
11501146
tcx: TyCtxt<'_>,
11511147
def_id: DefId,
@@ -1189,26 +1185,14 @@ fn infer_placeholder_type(
11891185
ty
11901186
}
11911187

1192-
/// Same as [`type_of`] but returns [`Option`] instead of failing.
1193-
///
1194-
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
1195-
/// you'd better just call [`type_of`] directly.
1196-
pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<'_>> {
1188+
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
11971189
use rustc::hir::*;
11981190

1199-
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
1200-
Some(hir_id) => hir_id,
1201-
None => {
1202-
if !fail {
1203-
return None;
1204-
}
1205-
bug!("invalid node");
1206-
}
1207-
};
1191+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
12081192

12091193
let icx = ItemCtxt::new(tcx, def_id);
12101194

1211-
Some(match tcx.hir().get(hir_id) {
1195+
match tcx.hir().get(hir_id) {
12121196
Node::TraitItem(item) => match item.kind {
12131197
TraitItemKind::Method(..) => {
12141198
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<
12251209
},
12261210
TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
12271211
TraitItemKind::Type(_, None) => {
1228-
if !fail {
1229-
return None;
1230-
}
12311212
span_bug!(item.span, "associated type missing default");
12321213
}
12331214
},
@@ -1321,9 +1302,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
13211302
| ItemKind::GlobalAsm(..)
13221303
| ItemKind::ExternCrate(..)
13231304
| ItemKind::Use(..) => {
1324-
if !fail {
1325-
return None;
1326-
}
13271305
span_bug!(
13281306
item.span,
13291307
"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<
13611339
..
13621340
}) => {
13631341
if gen.is_some() {
1364-
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
1342+
return tcx.typeck_tables_of(def_id).node_type(hir_id);
13651343
}
13661344

13671345
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<
14361414
.map(|(index, _)| index)
14371415
.next()
14381416
})
1439-
.or_else(|| {
1440-
if !fail {
1441-
None
1442-
} else {
1443-
bug!("no arg matching AnonConst in path")
1444-
}
1445-
})?;
1417+
.unwrap_or_else(|| {
1418+
bug!("no arg matching AnonConst in path");
1419+
});
14461420

14471421
// We've encountered an `AnonConst` in some path, so we need to
14481422
// 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<
14521426
tcx.generics_of(tcx.parent(def_id).unwrap())
14531427
}
14541428
Res::Def(_, def_id) => tcx.generics_of(def_id),
1455-
Res::Err => return Some(tcx.types.err),
1456-
_ if !fail => return None,
1429+
Res::Err => return tcx.types.err,
14571430
res => {
14581431
tcx.sess.delay_span_bug(
14591432
DUMMY_SP,
@@ -1462,7 +1435,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14621435
res,
14631436
),
14641437
);
1465-
return Some(tcx.types.err);
1438+
return tcx.types.err;
14661439
}
14671440
};
14681441

@@ -1480,24 +1453,18 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14801453
// probably from an extra arg where one is not needed.
14811454
.unwrap_or(tcx.types.err)
14821455
} else {
1483-
if !fail {
1484-
return None;
1485-
}
14861456
tcx.sess.delay_span_bug(
14871457
DUMMY_SP,
14881458
&format!(
14891459
"unexpected const parent path {:?}",
14901460
parent_node,
14911461
),
14921462
);
1493-
return Some(tcx.types.err);
1463+
return tcx.types.err;
14941464
}
14951465
}
14961466

14971467
x => {
1498-
if !fail {
1499-
return None;
1500-
}
15011468
tcx.sess.delay_span_bug(
15021469
DUMMY_SP,
15031470
&format!(
@@ -1547,21 +1514,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
15471514
}
15481515
ty
15491516
}
1550-
x => {
1551-
if !fail {
1552-
return None;
1553-
}
1554-
bug!("unexpected non-type Node::GenericParam: {:?}", x)
1555-
},
1517+
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
15561518
},
15571519

15581520
x => {
1559-
if !fail {
1560-
return None;
1561-
}
15621521
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
15631522
}
1564-
})
1523+
}
15651524
}
15661525

15671526
fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {

src/librustc_typeck/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ use util::common::time;
109109
use std::iter;
110110

111111
use astconv::{AstConv, Bounds};
112-
pub use collect::checked_type_of;
113-
114112
pub struct TypeAndSubsts<'tcx> {
115113
substs: SubstsRef<'tcx>,
116114
ty: Ty<'tcx>,

src/librustdoc/clean/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,12 +1491,13 @@ impl GenericParamDefKind {
14911491
}
14921492
}
14931493

1494-
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
1495-
match *self {
1496-
GenericParamDefKind::Type { did, .. } => {
1497-
rustc_typeck::checked_type_of(cx.tcx, did, false).map(|t| t.clean(cx))
1498-
}
1499-
GenericParamDefKind::Const { ref ty, .. } => Some(ty.clone()),
1494+
// FIXME(eddyb) this either returns the default of a type parameter, or the
1495+
// type of a `const` parameter. It seems that the intention is to *visit*
1496+
// any embedded types, but `get_type` seems to be the wrong name for that.
1497+
pub fn get_type(&self) -> Option<Type> {
1498+
match self {
1499+
GenericParamDefKind::Type { default, .. } => default.clone(),
1500+
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
15001501
GenericParamDefKind::Lifetime => None,
15011502
}
15021503
}
@@ -1522,8 +1523,8 @@ impl GenericParamDef {
15221523
self.kind.is_type()
15231524
}
15241525

1525-
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
1526-
self.kind.get_type(cx)
1526+
pub fn get_type(&self) -> Option<Type> {
1527+
self.kind.get_type()
15271528
}
15281529

15291530
pub fn get_bounds(&self) -> Option<&[GenericBound]> {
@@ -1891,7 +1892,7 @@ fn get_real_types(
18911892
if !x.is_type() {
18921893
continue
18931894
}
1894-
if let Some(ty) = x.get_type(cx) {
1895+
if let Some(ty) = x.get_type() {
18951896
let adds = get_real_types(generics, &ty, cx, recurse + 1);
18961897
if !adds.is_empty() {
18971898
res.extend(adds);

0 commit comments

Comments
 (0)