From 5fea1d279bdc7863f38a7bf2b58ecf66c18ef6d7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 2 Oct 2019 14:35:01 -0400 Subject: [PATCH] document `shallow_resolve` --- src/librustc/infer/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index b06b63455ba..a7ad62d5f70 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1307,6 +1307,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } + /// Resolve any type variables found in `value` -- but only one + /// level. So, if the variable `?X` is bound to some type + /// `Foo`, then this would return `Foo` (but `?Y` may + /// itself be bound to a type). + /// + /// Useful when you only need to inspect the outermost level of + /// the type and don't care about nested types (or perhaps you + /// will be resolving them as well, e.g. in a loop). pub fn shallow_resolve(&self, value: T) -> T where T: TypeFoldable<'tcx>, @@ -1567,6 +1575,9 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> { ShallowResolver { infcx } } + /// If `typ` is a type variable of some kind, resolve it one level + /// (but do not resolve types found in the result). If `typ` is + /// not a type variable, just return it unmodified. pub fn shallow_resolve(&mut self, typ: Ty<'tcx>) -> Ty<'tcx> { match typ.kind { ty::Infer(ty::TyVar(v)) => {