Skip to content

Commit

Permalink
Add a useful comment about InferOk.
Browse files Browse the repository at this point in the history
Prompted by #131134, which tried to remove `InferOk<'tcx, ()>`
occurrences.
  • Loading branch information
nnethercote committed Oct 8, 2024
1 parent abf212c commit 27dad00
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ pub mod resolve;
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> {
Expand Down

0 comments on commit 27dad00

Please sign in to comment.