Skip to content

Commit 27dad00

Browse files
committed
Add a useful comment about InferOk.
Prompted by rust-lang#131134, which tried to remove `InferOk<'tcx, ()>` occurrences.
1 parent abf212c commit 27dad00

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
@@ -67,6 +67,13 @@ pub mod resolve;
6767
pub(crate) mod snapshot;
6868
mod type_variable;
6969

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

0 commit comments

Comments
 (0)