Skip to content

Commit 84ffdeb

Browse files
authored
Rollup merge of #37688 - eddyb:lazy-8, r=petrochenkov
[8/n] rustc: clean up lookup_item_type and remove TypeScheme. _This is part of a series ([prev](rust-lang/rust#37676) | [next]()) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well. If any motivation is unclear, please ask for additional PR description clarifications or code comments._ <hr> * `tcx.tcache` -> `tcx.item_types` * `TypeScheme` (grouping `Ty` and `ty::Generics`) is removed * `tcx.item_types` entries no longer duplicated in `tcx.tables.node_types` * `tcx.lookup_item_type(def_id).ty` -> `tcx.item_type(def_id)` * `tcx.lookup_item_type(def_id).generics` -> `tcx.item_generics(def_id)` * `tcx.lookup_generics(def_id)` -> `tcx.item_generics(def_id)` * `tcx.lookup_{super_,}predicates(def_id)` -> `tcx.item_{super_,}predicates(def_id)`
2 parents ecbaf3b + 985fe22 commit 84ffdeb

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

clean/inline.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tc
164164
did: DefId) -> clean::Trait {
165165
let def = tcx.lookup_trait_def(did);
166166
let trait_items = tcx.associated_items(did).map(|item| item.clean(cx)).collect();
167-
let predicates = tcx.lookup_predicates(did);
167+
let predicates = tcx.item_predicates(did);
168168
let generics = (def.generics, &predicates).clean(cx);
169169
let generics = filter_non_trait_generics(did, generics);
170170
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
@@ -178,8 +178,8 @@ pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tc
178178

179179
fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
180180
did: DefId) -> clean::Function {
181-
let t = tcx.lookup_item_type(did);
182-
let (decl, style, abi) = match t.ty.sty {
181+
let ty = tcx.item_type(did);
182+
let (decl, style, abi) = match ty.sty {
183183
ty::TyFnDef(.., ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
184184
_ => panic!("bad function"),
185185
};
@@ -190,10 +190,10 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx
190190
hir::Constness::NotConst
191191
};
192192

193-
let predicates = tcx.lookup_predicates(did);
193+
let predicates = tcx.item_predicates(did);
194194
clean::Function {
195195
decl: decl,
196-
generics: (t.generics, &predicates).clean(cx),
196+
generics: (tcx.item_generics(did), &predicates).clean(cx),
197197
unsafety: style,
198198
constness: constness,
199199
abi: abi,
@@ -202,20 +202,18 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx
202202

203203
fn build_enum<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
204204
did: DefId) -> clean::Enum {
205-
let t = tcx.lookup_item_type(did);
206-
let predicates = tcx.lookup_predicates(did);
205+
let predicates = tcx.item_predicates(did);
207206

208207
clean::Enum {
209-
generics: (t.generics, &predicates).clean(cx),
208+
generics: (tcx.item_generics(did), &predicates).clean(cx),
210209
variants_stripped: false,
211210
variants: tcx.lookup_adt_def(did).variants.clean(cx),
212211
}
213212
}
214213

215214
fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
216215
did: DefId) -> clean::Struct {
217-
let t = tcx.lookup_item_type(did);
218-
let predicates = tcx.lookup_predicates(did);
216+
let predicates = tcx.item_predicates(did);
219217
let variant = tcx.lookup_adt_def(did).struct_variant();
220218

221219
clean::Struct {
@@ -224,34 +222,32 @@ fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
224222
CtorKind::Fn => doctree::Tuple,
225223
CtorKind::Const => doctree::Unit,
226224
},
227-
generics: (t.generics, &predicates).clean(cx),
225+
generics: (tcx.item_generics(did), &predicates).clean(cx),
228226
fields: variant.fields.clean(cx),
229227
fields_stripped: false,
230228
}
231229
}
232230

233231
fn build_union<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
234232
did: DefId) -> clean::Union {
235-
let t = tcx.lookup_item_type(did);
236-
let predicates = tcx.lookup_predicates(did);
233+
let predicates = tcx.item_predicates(did);
237234
let variant = tcx.lookup_adt_def(did).struct_variant();
238235

239236
clean::Union {
240237
struct_type: doctree::Plain,
241-
generics: (t.generics, &predicates).clean(cx),
238+
generics: (tcx.item_generics(did), &predicates).clean(cx),
242239
fields: variant.fields.clean(cx),
243240
fields_stripped: false,
244241
}
245242
}
246243

247244
fn build_type_alias<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
248245
did: DefId) -> clean::Typedef {
249-
let t = tcx.lookup_item_type(did);
250-
let predicates = tcx.lookup_predicates(did);
246+
let predicates = tcx.item_predicates(did);
251247

252248
clean::Typedef {
253-
type_: t.ty.clean(cx),
254-
generics: (t.generics, &predicates).clean(cx),
249+
type_: tcx.item_type(did).clean(cx),
250+
generics: (tcx.item_generics(did), &predicates).clean(cx),
255251
}
256252
}
257253

@@ -354,8 +350,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
354350
});
355351
}
356352

357-
let ty = tcx.lookup_item_type(did);
358-
let for_ = ty.ty.clean(cx);
353+
let for_ = tcx.item_type(did).clean(cx);
359354

360355
// Only inline impl if the implementing type is
361356
// reachable in rustdoc generated documentation
@@ -365,11 +360,10 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
365360
}
366361
}
367362

368-
let predicates = tcx.lookup_predicates(did);
363+
let predicates = tcx.item_predicates(did);
369364
let trait_items = tcx.associated_items(did).filter_map(|item| {
370365
match item.kind {
371366
ty::AssociatedKind::Const => {
372-
let type_scheme = tcx.lookup_item_type(item.def_id);
373367
let default = if item.has_value {
374368
Some(pprust::expr_to_string(
375369
lookup_const_by_id(tcx, item.def_id, None).unwrap().0))
@@ -379,7 +373,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
379373
Some(clean::Item {
380374
name: Some(item.name.clean(cx)),
381375
inner: clean::AssociatedConstItem(
382-
type_scheme.ty.clean(cx),
376+
tcx.item_type(item.def_id).clean(cx),
383377
default,
384378
),
385379
source: clean::Span::empty(),
@@ -419,7 +413,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
419413
}
420414
ty::AssociatedKind::Type => {
421415
let typedef = clean::Typedef {
422-
type_: tcx.lookup_item_type(item.def_id).ty.clean(cx),
416+
type_: tcx.item_type(item.def_id).clean(cx),
423417
generics: clean::Generics {
424418
lifetimes: vec![],
425419
type_params: vec![],
@@ -463,7 +457,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
463457
provided_trait_methods: provided,
464458
trait_: trait_,
465459
for_: for_,
466-
generics: (ty.generics, &predicates).clean(cx),
460+
generics: (tcx.item_generics(did), &predicates).clean(cx),
467461
items: trait_items,
468462
polarity: Some(polarity.clean(cx)),
469463
}),
@@ -514,7 +508,7 @@ fn build_const<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
514508
debug!("got snippet {}", sn);
515509

516510
clean::Constant {
517-
type_: ty.map(|t| t.clean(cx)).unwrap_or_else(|| tcx.lookup_item_type(did).ty.clean(cx)),
511+
type_: ty.map(|t| t.clean(cx)).unwrap_or_else(|| tcx.item_type(did).clean(cx)),
518512
expr: sn
519513
}
520514
}
@@ -523,7 +517,7 @@ fn build_static<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
523517
did: DefId,
524518
mutable: bool) -> clean::Static {
525519
clean::Static {
526-
type_: tcx.lookup_item_type(did).ty.clean(cx),
520+
type_: tcx.item_type(did).clean(cx),
527521
mutability: if mutable {clean::Mutable} else {clean::Immutable},
528522
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
529523
}

clean/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1342,13 +1342,13 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
13421342
fn clean(&self, cx: &DocContext) -> Item {
13431343
let inner = match self.kind {
13441344
ty::AssociatedKind::Const => {
1345-
let ty = cx.tcx().lookup_item_type(self.def_id).ty;
1345+
let ty = cx.tcx().item_type(self.def_id);
13461346
AssociatedConstItem(ty.clean(cx), None)
13471347
}
13481348
ty::AssociatedKind::Method => {
1349-
let generics = (cx.tcx().lookup_generics(self.def_id),
1350-
&cx.tcx().lookup_predicates(self.def_id)).clean(cx);
1351-
let fty = match cx.tcx().lookup_item_type(self.def_id).ty.sty {
1349+
let generics = (cx.tcx().item_generics(self.def_id),
1350+
&cx.tcx().item_predicates(self.def_id)).clean(cx);
1351+
let fty = match cx.tcx().item_type(self.def_id).sty {
13521352
ty::TyFnDef(_, _, f) => f,
13531353
_ => unreachable!()
13541354
};
@@ -1357,7 +1357,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
13571357
if self.method_has_self_argument {
13581358
let self_ty = match self.container {
13591359
ty::ImplContainer(def_id) => {
1360-
cx.tcx().lookup_item_type(def_id).ty
1360+
cx.tcx().item_type(def_id)
13611361
}
13621362
ty::TraitContainer(_) => cx.tcx().mk_self_type()
13631363
};
@@ -1405,7 +1405,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
14051405
// all of the generics from there and then look for bounds that are
14061406
// applied to this associated type in question.
14071407
let def = cx.tcx().lookup_trait_def(did);
1408-
let predicates = cx.tcx().lookup_predicates(did);
1408+
let predicates = cx.tcx().item_predicates(did);
14091409
let generics = (def.generics, &predicates).clean(cx);
14101410
generics.where_predicates.iter().filter_map(|pred| {
14111411
let (name, self_type, trait_, bounds) = match *pred {
@@ -1441,7 +1441,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
14411441
}
14421442

14431443
let ty = if self.has_value {
1444-
Some(cx.tcx().lookup_item_type(self.def_id).ty)
1444+
Some(cx.tcx().item_type(self.def_id))
14451445
} else {
14461446
None
14471447
};
@@ -1901,7 +1901,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
19011901
ty::TyAnon(def_id, substs) => {
19021902
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
19031903
// by looking up the projections associated with the def_id.
1904-
let item_predicates = cx.tcx().lookup_predicates(def_id);
1904+
let item_predicates = cx.tcx().item_predicates(def_id);
19051905
let substs = cx.tcx().lift(&substs).unwrap();
19061906
let bounds = item_predicates.instantiate(cx.tcx(), substs);
19071907
ImplTrait(bounds.predicates.into_iter().filter_map(|predicate| {

clean/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId,
153153
if child == trait_ {
154154
return true
155155
}
156-
let predicates = cx.tcx().lookup_super_predicates(child).predicates;
156+
let predicates = cx.tcx().item_super_predicates(child).predicates;
157157
predicates.iter().filter_map(|pred| {
158158
if let ty::Predicate::Trait(ref pred) = *pred {
159159
if pred.0.trait_ref.self_ty().is_self() {

0 commit comments

Comments
 (0)