Skip to content

Commit b2d64ee

Browse files
authored
Rollup merge of rust-lang#72983 - Lezzz:rename-typeck, r=nikomatsakis
Rename TypeckTables to TypeckResults. Originally suggested by @eddyb.
2 parents de3ae44 + e3cbb62 commit b2d64ee

File tree

224 files changed

+2538
-2206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+2538
-2206
lines changed

src/librustc_driver/pretty.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ where
8080
PpmTyped => {
8181
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);
8282

83-
let empty_tables = ty::TypeckTables::empty(None);
84-
let annotation = TypedAnnotation { tcx, tables: Cell::new(&empty_tables) };
83+
let empty_typeck_results = ty::TypeckResults::empty(None);
84+
let annotation =
85+
TypedAnnotation { tcx, typeck_results: Cell::new(&empty_typeck_results) };
8586
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
8687
}
8788
_ => panic!("Should use call_with_pp_support"),
@@ -306,7 +307,7 @@ impl<'a> pprust::PpAnn for HygieneAnnotation<'a> {
306307

307308
struct TypedAnnotation<'a, 'tcx> {
308309
tcx: TyCtxt<'tcx>,
309-
tables: Cell<&'a ty::TypeckTables<'tcx>>,
310+
typeck_results: Cell<&'a ty::TypeckResults<'tcx>>,
310311
}
311312

312313
impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
@@ -329,13 +330,13 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
329330

330331
impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> {
331332
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
332-
let old_tables = self.tables.get();
333+
let old_typeck_results = self.typeck_results.get();
333334
if let pprust_hir::Nested::Body(id) = nested {
334-
self.tables.set(self.tcx.body_tables(id));
335+
self.typeck_results.set(self.tcx.typeck_body(id));
335336
}
336337
let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>);
337338
pprust_hir::PpAnn::nested(pp_ann, state, nested);
338-
self.tables.set(old_tables);
339+
self.typeck_results.set(old_typeck_results);
339340
}
340341
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
341342
if let pprust_hir::AnnNode::Expr(_) = node {
@@ -347,7 +348,7 @@ impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> {
347348
s.s.space();
348349
s.s.word("as");
349350
s.s.space();
350-
s.s.word(self.tables.get().expr_ty(expr).to_string());
351+
s.s.word(self.typeck_results.get().expr_ty(expr).to_string());
351352
s.pclose();
352353
}
353354
}

src/librustc_hir/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ pub enum ExprKind<'hir> {
15711571
/// To resolve the called method to a `DefId`, call [`type_dependent_def_id`] with
15721572
/// the `hir_id` of the `MethodCall` node itself.
15731573
///
1574-
/// [`type_dependent_def_id`]: ../ty/struct.TypeckTables.html#method.type_dependent_def_id
1574+
/// [`type_dependent_def_id`]: ../ty/struct.TypeckResults.html#method.type_dependent_def_id
15751575
MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>], Span),
15761576
/// A tuple (e.g., `(a, b, c, d)`).
15771577
Tup(&'hir [Expr<'hir>]),
@@ -1659,7 +1659,7 @@ pub enum ExprKind<'hir> {
16591659
///
16601660
/// To resolve the path to a `DefId`, call [`qpath_res`].
16611661
///
1662-
/// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckTables.html#method.qpath_res
1662+
/// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckResults.html#method.qpath_res
16631663
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
16641664
pub enum QPath<'hir> {
16651665
/// Path to a definition, optionally "fully-qualified" with a `Self`

src/librustc_incremental/persist/dirty_clean.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! we will compare the fingerprint from the current and from the previous
44
//! compilation session as appropriate:
55
//!
6-
//! - `#[rustc_clean(cfg="rev2", except="typeck_tables_of")]` if we are
6+
//! - `#[rustc_clean(cfg="rev2", except="typeck")]` if we are
77
//! in `#[cfg(rev2)]`, then the fingerprints associated with
8-
//! `DepNode::typeck_tables_of(X)` must be DIFFERENT (`X` is the `DefId` of the
8+
//! `DepNode::typeck(X)` must be DIFFERENT (`X` is the `DefId` of the
99
//! current node).
1010
//! - `#[rustc_clean(cfg="rev2")]` same as above, except that the
1111
//! fingerprints must be the SAME (along with all other fingerprints).
@@ -48,7 +48,7 @@ const BASE_FN: &[&str] = &[
4848
label_strs::type_of,
4949
// And a big part of compilation (that we eventually want to cache) is type inference
5050
// information:
51-
label_strs::typeck_tables_of,
51+
label_strs::typeck,
5252
];
5353

5454
/// DepNodes for Hir, which is pretty much everything

src/librustc_infer/infer/error_reporting/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
624624
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
625625
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
626626
let arg_expr = args.first().expect("try desugaring call w/out arg");
627-
self.in_progress_tables
628-
.and_then(|tables| tables.borrow().expr_ty_opt(arg_expr))
627+
self.in_progress_typeck_results.and_then(|typeck_results| {
628+
typeck_results.borrow().expr_ty_opt(arg_expr)
629+
})
629630
} else {
630631
bug!("try desugaring w/out call expr as scrutinee");
631632
};
@@ -1683,8 +1684,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16831684
let hir = &self.tcx.hir();
16841685
// Attempt to obtain the span of the parameter so we can
16851686
// suggest adding an explicit lifetime bound to it.
1686-
let generics =
1687-
self.in_progress_tables.and_then(|table| table.borrow().hir_owner).map(|table_owner| {
1687+
let generics = self
1688+
.in_progress_typeck_results
1689+
.and_then(|table| table.borrow().hir_owner)
1690+
.map(|table_owner| {
16881691
let hir_id = hir.as_local_hir_id(table_owner);
16891692
let parent_id = hir.get_parent_item(hir_id);
16901693
(

src/librustc_infer/infer/error_reporting/need_type_info.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
4242
}
4343

4444
fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
45-
let ty_opt =
46-
self.infcx.in_progress_tables.and_then(|tables| tables.borrow().node_type_opt(hir_id));
45+
let ty_opt = self
46+
.infcx
47+
.in_progress_typeck_results
48+
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
4749
match ty_opt {
4850
Some(ty) => {
4951
let ty = self.infcx.resolve_vars_if_possible(&ty);
@@ -123,8 +125,11 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
123125
if let ExprKind::MethodCall(_, call_span, exprs, _) = expr.kind {
124126
if call_span == self.target_span
125127
&& Some(self.target)
126-
== self.infcx.in_progress_tables.and_then(|tables| {
127-
tables.borrow().node_type_opt(exprs.first().unwrap().hir_id).map(Into::into)
128+
== self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
129+
typeck_results
130+
.borrow()
131+
.node_type_opt(exprs.first().unwrap().hir_id)
132+
.map(Into::into)
128133
})
129134
{
130135
self.found_exact_method_call = Some(&expr);
@@ -580,8 +585,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
580585
e: &Expr<'_>,
581586
err: &mut DiagnosticBuilder<'_>,
582587
) {
583-
if let (Some(tables), None) = (self.in_progress_tables, &segment.args) {
584-
let borrow = tables.borrow();
588+
if let (Some(typeck_results), None) = (self.in_progress_typeck_results, &segment.args) {
589+
let borrow = typeck_results.borrow();
585590
if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) {
586591
let generics = self.tcx.generics_of(did);
587592
if !generics.params.is_empty() {

src/librustc_infer/infer/mod.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
283283
pub struct InferCtxt<'a, 'tcx> {
284284
pub tcx: TyCtxt<'tcx>,
285285

286-
/// During type-checking/inference of a body, `in_progress_tables`
287-
/// contains a reference to the tables being built up, which are
286+
/// During type-checking/inference of a body, `in_progress_typeck_results`
287+
/// contains a reference to the typeck_results being built up, which are
288288
/// used for reading closure kinds/signatures as they are inferred,
289289
/// and for error reporting logic to read arbitrary node types.
290-
pub in_progress_tables: Option<&'a RefCell<ty::TypeckTables<'tcx>>>,
290+
pub in_progress_typeck_results: Option<&'a RefCell<ty::TypeckResults<'tcx>>>,
291291

292292
pub inner: RefCell<InferCtxtInner<'tcx>>,
293293

@@ -571,7 +571,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
571571
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
572572
pub struct InferCtxtBuilder<'tcx> {
573573
tcx: TyCtxt<'tcx>,
574-
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
574+
fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>,
575575
}
576576

577577
pub trait TyCtxtInferExt<'tcx> {
@@ -580,15 +580,15 @@ pub trait TyCtxtInferExt<'tcx> {
580580

581581
impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
582582
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
583-
InferCtxtBuilder { tcx: self, fresh_tables: None }
583+
InferCtxtBuilder { tcx: self, fresh_typeck_results: None }
584584
}
585585
}
586586

587587
impl<'tcx> InferCtxtBuilder<'tcx> {
588588
/// Used only by `rustc_typeck` during body type-checking/inference,
589-
/// will initialize `in_progress_tables` with fresh `TypeckTables`.
590-
pub fn with_fresh_in_progress_tables(mut self, table_owner: LocalDefId) -> Self {
591-
self.fresh_tables = Some(RefCell::new(ty::TypeckTables::empty(Some(table_owner))));
589+
/// will initialize `in_progress_typeck_results` with fresh `TypeckResults`.
590+
pub fn with_fresh_in_progress_typeck_results(mut self, hir_owner: LocalDefId) -> Self {
591+
self.fresh_typeck_results = Some(RefCell::new(ty::TypeckResults::empty(Some(hir_owner))));
592592
self
593593
}
594594

@@ -616,11 +616,11 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
616616
}
617617

618618
pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
619-
let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
620-
let in_progress_tables = fresh_tables.as_ref();
619+
let InferCtxtBuilder { tcx, ref fresh_typeck_results } = *self;
620+
let in_progress_typeck_results = fresh_typeck_results.as_ref();
621621
f(InferCtxt {
622622
tcx,
623-
in_progress_tables,
623+
in_progress_typeck_results,
624624
inner: RefCell::new(InferCtxtInner::new()),
625625
lexical_region_resolutions: RefCell::new(None),
626626
selection_cache: Default::default(),
@@ -667,7 +667,7 @@ pub struct CombinedSnapshot<'a, 'tcx> {
667667
region_constraints_snapshot: RegionSnapshot,
668668
universe: ty::UniverseIndex,
669669
was_in_snapshot: bool,
670-
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
670+
_in_progress_typeck_results: Option<Ref<'a, ty::TypeckResults<'tcx>>>,
671671
}
672672

673673
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
@@ -789,9 +789,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
789789
region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(),
790790
universe: self.universe(),
791791
was_in_snapshot: in_snapshot,
792-
// Borrow tables "in progress" (i.e., during typeck)
792+
// Borrow typeck_results "in progress" (i.e., during typeck)
793793
// to ban writes from within a snapshot to them.
794-
_in_progress_tables: self.in_progress_tables.map(|tables| tables.borrow()),
794+
_in_progress_typeck_results: self
795+
.in_progress_typeck_results
796+
.map(|typeck_results| typeck_results.borrow()),
795797
}
796798
}
797799

@@ -802,7 +804,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
802804
region_constraints_snapshot,
803805
universe,
804806
was_in_snapshot,
805-
_in_progress_tables,
807+
_in_progress_typeck_results,
806808
} = snapshot;
807809

808810
self.in_snapshot.set(was_in_snapshot);
@@ -820,7 +822,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
820822
region_constraints_snapshot: _,
821823
universe: _,
822824
was_in_snapshot,
823-
_in_progress_tables,
825+
_in_progress_typeck_results,
824826
} = snapshot;
825827

826828
self.in_snapshot.set(was_in_snapshot);

src/librustc_lint/array_into_iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter {
3131

3232
// Check if the method call actually calls the libcore
3333
// `IntoIterator::into_iter`.
34-
let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap();
34+
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
3535
match cx.tcx.trait_of_item(def_id) {
3636
Some(trait_id) if cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_id) => {}
3737
_ => return,
@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter {
4545
// `Box` is the only thing that values can be moved out of via
4646
// method call. `Box::new([1]).into_iter()` should trigger this
4747
// lint.
48-
let mut recv_ty = cx.tables().expr_ty(receiver_arg);
48+
let mut recv_ty = cx.typeck_results().expr_ty(receiver_arg);
4949
let mut num_box_derefs = 0;
5050
while recv_ty.is_box() {
5151
num_box_derefs += 1;
@@ -60,13 +60,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter {
6060
// Make sure that there is an autoref coercion at the expected
6161
// position. The first `num_box_derefs` adjustments are the derefs
6262
// of the box.
63-
match cx.tables().expr_adjustments(receiver_arg).get(num_box_derefs) {
63+
match cx.typeck_results().expr_adjustments(receiver_arg).get(num_box_derefs) {
6464
Some(Adjustment { kind: Adjust::Borrow(_), .. }) => {}
6565
_ => return,
6666
}
6767

6868
// Emit lint diagnostic.
69-
let target = match cx.tables().expr_ty_adjusted(receiver_arg).kind {
69+
let target = match cx.typeck_results().expr_ty_adjusted(receiver_arg).kind {
7070
ty::Ref(_, ty::TyS { kind: ty::Array(..), .. }, _) => "[T; N]",
7171
ty::Ref(_, ty::TyS { kind: ty::Slice(..), .. }, _) => "[T]",
7272

src/librustc_lint/builtin.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
144144
}
145145

146146
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) {
147-
let ty = cx.tables().node_type(e.hir_id);
147+
let ty = cx.typeck_results().node_type(e.hir_id);
148148
self.check_heap_type(cx, e.span, ty);
149149
}
150150
}
@@ -161,11 +161,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
161161
fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>) {
162162
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
163163
let variant = cx
164-
.tables()
164+
.typeck_results()
165165
.pat_ty(pat)
166166
.ty_adt_def()
167167
.expect("struct pattern type is not an ADT")
168-
.variant_of_res(cx.tables().qpath_res(qpath, pat.hir_id));
168+
.variant_of_res(cx.typeck_results().qpath_res(qpath, pat.hir_id));
169169
for fieldpat in field_pats {
170170
if fieldpat.is_shorthand {
171171
continue;
@@ -178,7 +178,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
178178
}
179179
if let PatKind::Binding(binding_annot, _, ident, None) = fieldpat.pat.kind {
180180
if cx.tcx.find_field_index(ident, &variant)
181-
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables()))
181+
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.typeck_results()))
182182
{
183183
cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, |lint| {
184184
let mut err = lint
@@ -901,15 +901,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
901901
expr: &hir::Expr<'_>,
902902
) -> Option<(Ty<'tcx>, Ty<'tcx>)> {
903903
let def = if let hir::ExprKind::Path(ref qpath) = expr.kind {
904-
cx.tables().qpath_res(qpath, expr.hir_id)
904+
cx.typeck_results().qpath_res(qpath, expr.hir_id)
905905
} else {
906906
return None;
907907
};
908908
if let Res::Def(DefKind::Fn, did) = def {
909909
if !def_id_is_transmute(cx, did) {
910910
return None;
911911
}
912-
let sig = cx.tables().node_type(expr.hir_id).fn_sig(cx.tcx);
912+
let sig = cx.typeck_results().node_type(expr.hir_id).fn_sig(cx.tcx);
913913
let from = sig.inputs().skip_binder()[0];
914914
let to = sig.output().skip_binder();
915915
return Some((from, to));
@@ -1891,7 +1891,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
18911891
if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind {
18921892
// Find calls to `mem::{uninitialized,zeroed}` methods.
18931893
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
1894-
let def_id = cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
1894+
let def_id =
1895+
cx.typeck_results().qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
18951896

18961897
if cx.tcx.is_diagnostic_item(sym::mem_zeroed, def_id) {
18971898
return Some(InitKind::Zeroed);
@@ -1905,14 +1906,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
19051906
}
19061907
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
19071908
// Find problematic calls to `MaybeUninit::assume_init`.
1908-
let def_id = cx.tables().type_dependent_def_id(expr.hir_id)?;
1909+
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
19091910
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
19101911
// This is a call to *some* method named `assume_init`.
19111912
// See if the `self` parameter is one of the dangerous constructors.
19121913
if let hir::ExprKind::Call(ref path_expr, _) = args[0].kind {
19131914
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
1914-
let def_id =
1915-
cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
1915+
let def_id = cx
1916+
.typeck_results()
1917+
.qpath_res(qpath, path_expr.hir_id)
1918+
.opt_def_id()?;
19161919

19171920
if cx.tcx.is_diagnostic_item(sym::maybe_uninit_zeroed, def_id) {
19181921
return Some(InitKind::Zeroed);
@@ -2025,7 +2028,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
20252028
// This conjures an instance of a type out of nothing,
20262029
// using zeroed or uninitialized memory.
20272030
// We are extremely conservative with what we warn about.
2028-
let conjured_ty = cx.tables().expr_ty(expr);
2031+
let conjured_ty = cx.typeck_results().expr_ty(expr);
20292032
if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) {
20302033
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
20312034
let mut err = lint.build(&format!(

0 commit comments

Comments
 (0)