Skip to content

Commit a553672

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

File tree

1 file changed

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

1 file changed

+6
-0
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ 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 around
72+
// `Vec<PredicateObligation<'tcx>>`, but it has one important property: because
73+
// `InferOk` is marked with `#[must_use]`, if you have a method `InferCtxt::f`
74+
// that returns `InferResult<'tcx, ()>` and you call it with `infcx.f()?;`
75+
// you'll get a warning about the obligations being discarded without use,
76+
// which is probably unintentional and has been a source of bugs in the past.
7177
#[must_use]
7278
#[derive(Debug)]
7379
pub struct InferOk<'tcx, T> {

0 commit comments

Comments
 (0)