Skip to content

Commit 6516aaa

Browse files
committed
Add a useful comment about InferOk.
Prompted by #131134, which tried to remove `InferOk<'tcx, ()>` occurrences.
1 parent 4dc6a55 commit 6516aaa

File tree

1 file changed

+7
-0
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+7
-0
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ pub mod resolve;
6868
pub(crate) mod snapshot;
6969
mod type_variable;
7070

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

0 commit comments

Comments
 (0)