Skip to content

Commit 2887e03

Browse files
committed
Address review comments
1 parent 1f75142 commit 2887e03

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
2626
use std::cell::{Cell, RefCell};
2727
use std::ops::Deref;
2828

29-
/// The `FnCtxt` stores type-checking context needed to type-check function bodies,
30-
/// in contrast to [`ItemCtxt`], which is used to type-check item *signatures*.
29+
/// The `FnCtxt` stores type-checking context needed to type-check bodies of
30+
/// functions, closures, and `const`s, including performing type inference
31+
/// with [`InferCtxt`].
32+
///
33+
/// This is in contrast to [`ItemCtxt`], which is used to type-check item *signatures*
34+
/// and thus does not perform type inference.
35+
///
36+
/// See [`ItemCtxt`]'s docs for more.
37+
///
38+
/// [`ItemCtxt`]: crate::collect::ItemCtxt
39+
/// [`InferCtxt`]: infer::InferCtxt
3140
pub struct FnCtxt<'a, 'tcx> {
3241
pub(super) body_id: hir::HirId,
3342

compiler/rustc_typeck/src/collect.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,26 @@ pub fn provide(providers: &mut Providers) {
9494
///////////////////////////////////////////////////////////////////////////
9595

9696
/// Context specific to some particular item. This is what implements
97-
/// `AstConv`.
97+
/// [`AstConv`].
9898
///
99-
/// `ItemCtxt` is primarily used to type-check item signatures, in contrast to [`FnCtxt`],
100-
/// which is used to type-check function bodies.
99+
/// # `ItemCtxt` vs `FnCtxt`
101100
///
102-
/// It has information about the predicates that are defined
101+
/// `ItemCtxt` is primarily used to type-check item signatures and lower them
102+
/// from HIR to their [`ty::Ty`] representation, which is exposed using [`AstConv`].
103+
/// It's also used for the bodies of items like structs where the body (the fields)
104+
/// are just signatures.
105+
///
106+
/// This is in contrast to [`FnCtxt`], which is used to type-check bodies of
107+
/// functions, closures, and `const`s -- anywhere that expressions and statements show up.
108+
///
109+
/// An important thing to note is that `ItemCtxt` does no inference -- it has no [`InferCtxt`] --
110+
/// while `FnCtxt` does do inference.
111+
///
112+
/// [`FnCtxt`]: crate::check::fn_ctxt::FnCtxt
113+
///
114+
/// # Trait predicates
115+
///
116+
/// `ItemCtxt` has information about the predicates that are defined
103117
/// on the trait. Unfortunately, this predicate information is
104118
/// available in various different forms at various points in the
105119
/// process. So we can't just store a pointer to e.g., the AST or the

0 commit comments

Comments
 (0)