Skip to content

Commit ae3703b

Browse files
committed
Revert "Greatly improve generics handling in rustdoc search"
This reverts commit 64382f4.
1 parent 3c420c0 commit ae3703b

File tree

3 files changed

+19
-70
lines changed

3 files changed

+19
-70
lines changed

src/librustc_typeck/collect.rs

+9-59
Original file line numberDiff line numberDiff line change
@@ -1134,43 +1134,20 @@ fn report_assoc_ty_on_inherent_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span:
11341134
}
11351135

11361136
fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
1137-
checked_type_of(tcx, def_id, true).unwrap()
1138-
}
1139-
1140-
/// Same as [`type_of`] but returns [`Option`] instead of failing.
1141-
///
1142-
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
1143-
/// you'd better just call [`type_of`] directly.
1144-
pub fn checked_type_of<'a, 'tcx>(
1145-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1146-
def_id: DefId,
1147-
fail: bool,
1148-
) -> Option<Ty<'tcx>> {
11491137
use rustc::hir::*;
11501138

1151-
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
1152-
Some(hir_id) => hir_id,
1153-
None => {
1154-
if !fail {
1155-
return None;
1156-
}
1157-
bug!("invalid node");
1158-
}
1159-
};
1139+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
11601140

11611141
let icx = ItemCtxt::new(tcx, def_id);
11621142

1163-
Some(match tcx.hir().get_by_hir_id(hir_id) {
1143+
match tcx.hir().get_by_hir_id(hir_id) {
11641144
Node::TraitItem(item) => match item.node {
11651145
TraitItemKind::Method(..) => {
11661146
let substs = InternalSubsts::identity_for_item(tcx, def_id);
11671147
tcx.mk_fn_def(def_id, substs)
11681148
}
11691149
TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
11701150
TraitItemKind::Type(_, None) => {
1171-
if !fail {
1172-
return None;
1173-
}
11741151
span_bug!(item.span, "associated type missing default");
11751152
}
11761153
},
@@ -1252,9 +1229,6 @@ pub fn checked_type_of<'a, 'tcx>(
12521229
| ItemKind::GlobalAsm(..)
12531230
| ItemKind::ExternCrate(..)
12541231
| ItemKind::Use(..) => {
1255-
if !fail {
1256-
return None;
1257-
}
12581232
span_bug!(
12591233
item.span,
12601234
"compute_type_of_item: unexpected item type: {:?}",
@@ -1293,7 +1267,7 @@ pub fn checked_type_of<'a, 'tcx>(
12931267
..
12941268
}) => {
12951269
if gen.is_some() {
1296-
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
1270+
return tcx.typeck_tables_of(def_id).node_type(hir_id);
12971271
}
12981272

12991273
let substs = ty::ClosureSubsts {
@@ -1371,9 +1345,6 @@ pub fn checked_type_of<'a, 'tcx>(
13711345
}
13721346
// Sanity check to make sure everything is as expected.
13731347
if !found_const {
1374-
if !fail {
1375-
return None;
1376-
}
13771348
bug!("no arg matching AnonConst in path")
13781349
}
13791350
match path.def {
@@ -1389,37 +1360,24 @@ pub fn checked_type_of<'a, 'tcx>(
13891360
for param in &generics.params {
13901361
if let ty::GenericParamDefKind::Const = param.kind {
13911362
if param_index == arg_index {
1392-
return Some(tcx.type_of(param.def_id));
1363+
return tcx.type_of(param.def_id);
13931364
}
13941365
param_index += 1;
13951366
}
13961367
}
13971368
// This is no generic parameter associated with the arg. This is
13981369
// probably from an extra arg where one is not needed.
1399-
return Some(tcx.types.err);
1370+
return tcx.types.err;
14001371
}
14011372
Def::Err => tcx.types.err,
1402-
x => {
1403-
if !fail {
1404-
return None;
1405-
}
1406-
bug!("unexpected const parent path def {:?}", x);
1407-
}
1408-
}
1409-
}
1410-
x => {
1411-
if !fail {
1412-
return None;
1373+
x => bug!("unexpected const parent path def {:?}", x),
14131374
}
1414-
bug!("unexpected const parent path {:?}", x);
14151375
}
1376+
x => bug!("unexpected const parent path {:?}", x),
14161377
}
14171378
}
14181379

14191380
x => {
1420-
if !fail {
1421-
return None;
1422-
}
14231381
bug!("unexpected const parent in type_of_def_id(): {:?}", x);
14241382
}
14251383
}
@@ -1430,21 +1388,13 @@ pub fn checked_type_of<'a, 'tcx>(
14301388
hir::GenericParamKind::Const { ref ty, .. } => {
14311389
icx.to_ty(ty)
14321390
}
1433-
x => {
1434-
if !fail {
1435-
return None;
1436-
}
1437-
bug!("unexpected non-type Node::GenericParam: {:?}", x)
1438-
},
1391+
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
14391392
},
14401393

14411394
x => {
1442-
if !fail {
1443-
return None;
1444-
}
14451395
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
14461396
}
1447-
})
1397+
}
14481398
}
14491399

14501400
fn find_existential_constraints<'a, 'tcx>(

src/librustc_typeck/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ use util::common::time;
115115

116116
use std::iter;
117117

118-
pub use collect::checked_type_of;
119-
120118
pub struct TypeAndSubsts<'tcx> {
121119
substs: SubstsRef<'tcx>,
122120
ty: Ty<'tcx>,

src/librustdoc/clean/mod.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1483,12 +1483,13 @@ impl GenericParamDefKind {
14831483
}
14841484
}
14851485

1486-
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
1487-
match *self {
1488-
GenericParamDefKind::Type { did, .. } => {
1489-
rustc_typeck::checked_type_of(cx.tcx, did, false).map(|t| t.clean(cx))
1490-
}
1491-
GenericParamDefKind::Const { ref ty, .. } => Some(ty.clone()),
1486+
// FIXME(eddyb) this either returns the default of a type parameter, or the
1487+
// type of a `const` parameter. It seems that the intention is to *visit*
1488+
// any embedded types, but `get_type` seems to be the wrong name for that.
1489+
pub fn get_type(&self) -> Option<Type> {
1490+
match self {
1491+
GenericParamDefKind::Type { default, .. } => default.clone(),
1492+
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
14921493
GenericParamDefKind::Lifetime => None,
14931494
}
14941495
}
@@ -1514,8 +1515,8 @@ impl GenericParamDef {
15141515
self.kind.is_type()
15151516
}
15161517

1517-
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
1518-
self.kind.get_type(cx)
1518+
pub fn get_type(&self) -> Option<Type> {
1519+
self.kind.get_type()
15191520
}
15201521

15211522
pub fn get_bounds(&self) -> Option<&[GenericBound]> {
@@ -1791,7 +1792,7 @@ fn get_real_types(
17911792
if !x.is_type() {
17921793
continue
17931794
}
1794-
if let Some(ty) = x.get_type(cx) {
1795+
if let Some(ty) = x.get_type() {
17951796
let adds = get_real_types(generics, &ty, cx, recurse + 1);
17961797
if !adds.is_empty() {
17971798
res.extend(adds);

0 commit comments

Comments
 (0)