File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
compiler/rustc_typeck/src Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
2626use std:: cell:: { Cell , RefCell } ;
2727use std:: ops:: Deref ;
2828
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
2940pub struct FnCtxt < ' a , ' tcx > {
3041 pub ( super ) body_id : hir:: HirId ,
3142
Original file line number Diff line number Diff line change @@ -94,7 +94,26 @@ pub fn provide(providers: &mut Providers) {
9494///////////////////////////////////////////////////////////////////////////
9595
9696/// Context specific to some particular item. This is what implements
97- /// `AstConv`. It has information about the predicates that are defined
97+ /// [`AstConv`].
98+ ///
99+ /// # `ItemCtxt` vs `FnCtxt`
100+ ///
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
98117/// on the trait. Unfortunately, this predicate information is
99118/// available in various different forms at various points in the
100119/// process. So we can't just store a pointer to e.g., the AST or the
You can’t perform that action at this time.
0 commit comments