diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-10-03 09:25:41 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-10-08 16:27:44 +1100 |
| commit | 27dad009c61e6a21fc7cb438a08597cf0ec0b1c8 (patch) | |
| tree | 98b9aad1bb6c42b98549f448208556e1ebeaf6f2 | |
| parent | abf212c16cbc2fdef9dc4b515165f144c716f3d3 (diff) | |
| download | rust-27dad009c61e6a21fc7cb438a08597cf0ec0b1c8.tar.gz rust-27dad009c61e6a21fc7cb438a08597cf0ec0b1c8.zip | |
Add a useful comment about `InferOk`.
Prompted by #131134, which tried to remove `InferOk<'tcx, ()>` occurrences.
| -rw-r--r-- | compiler/rustc_infer/src/infer/mod.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index cb60d9f286b..29936fadc57 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -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> { |
