Skip to content

Commit c502d33

Browse files
committed
better document various functions around resolve
1 parent 8175444 commit c502d33

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

  • compiler/rustc_infer/src/infer

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,25 @@ impl<'tcx> InferCtxt<'tcx> {
12421242
}
12431243
}
12441244

1245+
/// Resolve a type variable. Resolving means the following:
1246+
///
1247+
/// - If a `Ty` is a rigid type (like, an integer, or some ADT), do nothing.
1248+
/// - If a `Ty` is a type infer variable, but has been equated with an actual type,
1249+
/// return that type.
1250+
/// - If a `Ty` is an int or float infer variable, and has been equated with an integer
1251+
/// or floating point type, return that type.
1252+
/// - If a `Ty` is any kind of infer variable that has been equated, but not yet with a rigid
1253+
/// type, then this set of equated variables forms an equivalence class. One of the variables
1254+
/// in that equivalent class is said to be the root variable, and resolving makes sure to
1255+
/// consistently return this root variable. This is beneficial for caching.
1256+
/// This behavior, of returning roots, changed in <https://github.com/rust-lang/rust/pull/158447>.
1257+
///
1258+
/// Otherwise, resolving simply does nothing.
1259+
///
1260+
/// The "shallow" part of the name refers to the fact that types may themselves contain more
1261+
/// type variables. e.g. The field types of a struct. `shallow_resolve` does not recurse into
1262+
/// these nested variables. If that's what you want, use [`deeply_resolve_ignoring_regions`](Self::deeply_resolve_ignoring_regions),
1263+
/// or better [`deeply_resolve`](rustc_type_ir::deeply_resolve), if you can, which *does* resolve regions.
12451264
pub fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
12461265
if let ty::Infer(v) = *ty.kind() {
12471266
match v {
@@ -1307,6 +1326,8 @@ impl<'tcx> InferCtxt<'tcx> {
13071326
}
13081327
}
13091328

1329+
/// See docs on [`shallow_resolve`](Self::shallow_resolve) for more explanation.
1330+
/// It's the same, but for consts.
13101331
pub fn shallow_resolve_const(&self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
13111332
match ct.kind() {
13121333
ty::ConstKind::Infer(infer_ct) => match infer_ct {
@@ -1333,6 +1354,8 @@ impl<'tcx> InferCtxt<'tcx> {
13331354
}
13341355
}
13351356

1357+
/// See docs on [`shallow_resolve`](Self::shallow_resolve) for more explanation.
1358+
/// It's the same, but for terms (types or consts).
13361359
pub fn shallow_resolve_term(&self, term: ty::Term<'tcx>) -> ty::Term<'tcx> {
13371360
match term.kind() {
13381361
ty::TermKind::Ty(ty) => self.shallow_resolve(ty).into(),
@@ -1399,7 +1422,7 @@ impl<'tcx> InferCtxt<'tcx> {
13991422
}
14001423
}
14011424

1402-
/// Resolves a float var to a rigid int type, if it was constrained to one,
1425+
/// Resolves a float var to a rigid type, if it was constrained to one,
14031426
/// or else the root float var in the unification table.
14041427
pub fn shallow_resolve_float_var(&self, vid: ty::FloatVid) -> Ty<'tcx> {
14051428
let mut inner = self.inner.borrow_mut();

0 commit comments

Comments
 (0)