@@ -55,6 +55,9 @@ use crate::{
5555} ;
5656
5757impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
58+ /// Check an expr with an expectation type, and also demand that the expr's
59+ /// evaluated type is a subtype of the expectation at the end. This is a
60+ /// *hard* requirement.
5861 pub ( crate ) fn check_expr_has_type_or_error (
5962 & self ,
6063 expr : & ' tcx hir:: Expr < ' tcx > ,
@@ -97,6 +100,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
97100 ty
98101 }
99102
103+ /// Check an expr with an expectation type, and also demand that the expr's
104+ /// evaluated type is a coercible to the expectation at the end. This is a
105+ /// *hard* requirement.
100106 pub ( super ) fn check_expr_coercible_to_type (
101107 & self ,
102108 expr : & ' tcx hir:: Expr < ' tcx > ,
@@ -108,6 +114,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
108114 self . demand_coerce ( expr, ty, expected, expected_ty_expr, AllowTwoPhase :: No )
109115 }
110116
117+ /// Check an expr with an expectation type. Don't actually enforce that expectation
118+ /// is related to the expr's evaluated type via subtyping or coercion. This is
119+ /// usually called because we want to do that subtype/coerce call manually for better
120+ /// diagnostics.
111121 pub ( super ) fn check_expr_with_hint (
112122 & self ,
113123 expr : & ' tcx hir:: Expr < ' tcx > ,
@@ -116,6 +126,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
116126 self . check_expr_with_expectation ( expr, ExpectHasType ( expected) )
117127 }
118128
129+ /// Check an expr with an expectation type, and also [`Needs`] which will
130+ /// prompt typeck to convert any implicit immutable derefs to mutable derefs.
119131 fn check_expr_with_expectation_and_needs (
120132 & self ,
121133 expr : & ' tcx hir:: Expr < ' tcx > ,
@@ -133,10 +145,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133145 ty
134146 }
135147
148+ /// Check an expr with no expectations.
136149 pub ( super ) fn check_expr ( & self , expr : & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > {
137150 self . check_expr_with_expectation ( expr, NoExpectation )
138151 }
139152
153+ /// Check an expr with no expectations, but with [`Needs`] which will
154+ /// prompt typeck to convert any implicit immutable derefs to mutable derefs.
140155 pub ( super ) fn check_expr_with_needs (
141156 & self ,
142157 expr : & ' tcx hir:: Expr < ' tcx > ,
@@ -145,16 +160,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
145160 self . check_expr_with_expectation_and_needs ( expr, NoExpectation , needs)
146161 }
147162
148- /// Invariant:
149- /// If an expression has any sub-expressions that result in a type error,
150- /// inspecting that expression's type with `ty.references_error()` will return
151- /// true. Likewise, if an expression is known to diverge, inspecting its
152- /// type with `ty::type_is_bot` will return true (n.b.: since Rust is
153- /// strict, _|_ can appear in the type of an expression that does not,
154- /// itself, diverge: for example, fn() -> _|_.)
155- /// Note that inspecting a type's structure *directly* may expose the fact
156- /// that there are actually multiple representations for `Error`, so avoid
157- /// that when err needs to be handled differently.
163+ /// Check an expr with an expectation type which may be used to eagerly
164+ /// guide inference when evaluating that expr.
158165 #[ instrument( skip( self , expr) , level = "debug" ) ]
159166 pub ( super ) fn check_expr_with_expectation (
160167 & self ,
@@ -164,8 +171,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
164171 self . check_expr_with_expectation_and_args ( expr, expected, None )
165172 }
166173
167- /// Same as `check_expr_with_expectation`, but allows us to pass in the arguments of a
168- /// `ExprKind::Call` when evaluating its callee when it is an `ExprKind::Path`.
174+ /// Same as [`Self::check_expr_with_expectation`], but allows us to pass in
175+ /// the arguments of a [`ExprKind::Call`] when evaluating its callee that
176+ /// is an [`ExprKind::Path`]. We use this to refine the spans for certain
177+ /// well-formedness guarantees for the path expr.
169178 pub ( super ) fn check_expr_with_expectation_and_args (
170179 & self ,
171180 expr : & ' tcx hir:: Expr < ' tcx > ,
0 commit comments