Add a useful comment about InferOk.

Prompted by #131134, which tried to remove `InferOk<'tcx, ()>`
occurrences.
This commit is contained in:
Nicholas Nethercote 2024-10-03 09:25:41 +10:00
parent abf212c16c
commit 27dad009c6

View File

@ -67,6 +67,13 @@
pub(crate) mod snapshot;
mod type_variable;
/// `InferOk<'tcx, ()>` is used a lot. It may seem like a useless wrapper
/// around `Vec<PredicateObligation<'tcx>>`, but it has one important property:
/// because `InferOk` is marked with `#[must_use]`, if you have a method
/// `InferCtxt::f` that returns `InferResult<'tcx, ()>` and you call it with
/// `infcx.f()?;` you'll get a warning about the obligations being discarded
/// without use, which is probably unintentional and has been a source of bugs
/// in the past.
#[must_use]
#[derive(Debug)]
pub struct InferOk<'tcx, T> {