Skip to content

Commit dc628b4

Browse files
cleanup
1 parent 6bce61c commit dc628b4

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/librustc_typeck/collect.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
11331133
checked_type_of(tcx, def_id, true).unwrap()
11341134
}
11351135

1136+
/// Same as [`type_of`] but returns [`Option`] instead of failing.
1137+
///
1138+
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
1139+
/// you'd better just call [`type_of`] directly.
11361140
pub fn checked_type_of<'a, 'tcx>(
11371141
tcx: TyCtxt<'a, 'tcx, 'tcx>,
11381142
def_id: DefId,
@@ -1382,14 +1386,14 @@ pub fn checked_type_of<'a, 'tcx>(
13821386
for param in &generics.params {
13831387
if let ty::GenericParamDefKind::Const = param.kind {
13841388
if param_index == arg_index {
1385-
return tcx.type_of(param.def_id);
1389+
return Some(tcx.type_of(param.def_id));
13861390
}
13871391
param_index += 1;
13881392
}
13891393
}
13901394
// This is no generic parameter associated with the arg. This is
13911395
// probably from an extra arg where one is not needed.
1392-
return tcx.types.err;
1396+
return Some(tcx.types.err);
13931397
}
13941398
Def::Err => tcx.types.err,
13951399
x => {

src/librustdoc/clean/mod.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ impl GenericParamDefKind {
14741474
}
14751475
}
14761476

1477-
pub fn get_type(&self, cx: &DocContext<'_, '_, '_>) -> Option<Type> {
1477+
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
14781478
match *self {
14791479
GenericParamDefKind::Type { did, .. } => {
14801480
rustc_typeck::checked_type_of(cx.tcx, did, false).map(|t| t.clean(cx))
@@ -1505,7 +1505,7 @@ impl GenericParamDef {
15051505
self.kind.is_type()
15061506
}
15071507

1508-
pub fn get_type(&self, cx: &DocContext<'_, '_, '_>) -> Option<Type> {
1508+
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
15091509
self.kind.get_type(cx)
15101510
}
15111511

@@ -1750,12 +1750,16 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
17501750
}
17511751
}
17521752

1753-
// The point is to replace bounds with types.
1753+
/// The point of this function is to replace bounds with types.
1754+
///
1755+
/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return
1756+
/// `[Display, Option]` (we just returns the list of the types, we don't care about the
1757+
/// wrapped types in here).
17541758
fn get_real_types(
17551759
generics: &Generics,
17561760
arg: &Type,
1757-
cx: &DocContext<'_, '_, '_>,
1758-
) -> Vec<Type> {
1761+
cx: &DocContext<'_>,
1762+
) -> FxHashSet<Type> {
17591763
let arg_s = arg.to_string();
17601764
let mut res = Vec::new();
17611765
if arg.is_full_generic() {
@@ -1776,7 +1780,7 @@ fn get_real_types(
17761780
if let Some(ty) = x.get_type(cx) {
17771781
let mut adds = get_real_types(generics, &ty, cx);
17781782
if !adds.is_empty() {
1779-
res.append(&mut adds);
1783+
res.extend(adds);
17801784
} else if !ty.is_full_generic() {
17811785
res.push(ty);
17821786
}
@@ -1794,7 +1798,7 @@ fn get_real_types(
17941798
if let Some(ty) = bound.get_trait_type() {
17951799
let mut adds = get_real_types(generics, &ty, cx);
17961800
if !adds.is_empty() {
1797-
res.append(&mut adds);
1801+
res.extend(adds);
17981802
} else if !ty.is_full_generic() {
17991803
res.push(ty.clone());
18001804
}
@@ -1808,7 +1812,7 @@ fn get_real_types(
18081812
if gen.is_full_generic() {
18091813
let mut adds = get_real_types(generics, gen, cx);
18101814
if !adds.is_empty() {
1811-
res.append(&mut adds);
1815+
res.extend(adds);
18121816
}
18131817
} else {
18141818
res.push(gen.clone());
@@ -1819,10 +1823,14 @@ fn get_real_types(
18191823
res
18201824
}
18211825

1826+
/// Return the full list of types when bounds have been resolved.
1827+
///
1828+
/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return
1829+
/// `[u32, Display, Option]`.
18221830
pub fn get_all_types(
18231831
generics: &Generics,
18241832
decl: &FnDecl,
1825-
cx: &DocContext<'_, '_, '_>,
1833+
cx: &DocContext<'_>,
18261834
) -> (Vec<Type>, Vec<Type>) {
18271835
let mut all_types = Vec::new();
18281836
for arg in decl.inputs.values.iter() {
@@ -1831,7 +1839,7 @@ pub fn get_all_types(
18311839
}
18321840
let mut args = get_real_types(generics, &arg.type_, cx);
18331841
if !args.is_empty() {
1834-
all_types.append(&mut args);
1842+
all_types.extend(args);
18351843
} else {
18361844
all_types.push(arg.type_.clone());
18371845
}

src/librustdoc/html/render.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5052,7 +5052,6 @@ fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
50525052
Some(output)
50535053
};
50545054

5055-
println!("===> {:?}", output);
50565055
Some(IndexItemFunctionType { inputs, output })
50575056
}
50585057

0 commit comments

Comments
 (0)