diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-06-09 19:19:57 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-09 19:19:57 +0900 |
| commit | 141b0a4d5b4860f3e7d0d775ff807d22c8101b4a (patch) | |
| tree | 9435916243566093396d95d5403a8a32776a005f | |
| parent | 5d81f91a3bbb6b26894b2b03a488321eb3665214 (diff) | |
| parent | 36a4490271f5e32c54f2a9d8e49267c2783e0586 (diff) | |
| download | rust-141b0a4d5b4860f3e7d0d775ff807d22c8101b4a.tar.gz rust-141b0a4d5b4860f3e7d0d775ff807d22c8101b4a.zip | |
Rollup merge of #97874 - lcnr:combine-comment, r=davidtwco
rewrite combine doc comment it was from 2014 and somewhat outdated
| -rw-r--r-- | compiler/rustc_infer/src/infer/combine.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 534106ac446..120e57ecebd 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -1,26 +1,26 @@ -/////////////////////////////////////////////////////////////////////////// -// # Type combining -// -// There are four type combiners: equate, sub, lub, and glb. Each -// implements the trait `Combine` and contains methods for combining -// two instances of various things and yielding a new instance. These -// combiner methods always yield a `Result<T>`. There is a lot of -// common code for these operations, implemented as default methods on -// the `Combine` trait. -// -// Each operation may have side-effects on the inference context, -// though these can be unrolled using snapshots. On success, the -// LUB/GLB operations return the appropriate bound. The Eq and Sub -// operations generally return the first operand. -// -// ## Contravariance -// -// When you are relating two things which have a contravariant -// relationship, you should use `contratys()` or `contraregions()`, -// rather than inversing the order of arguments! This is necessary -// because the order of arguments is not relevant for LUB and GLB. It -// is also useful to track which value is the "expected" value in -// terms of error reporting. +//! There are four type combiners: [Equate], [Sub], [Lub], and [Glb]. +//! Each implements the trait [TypeRelation] and contains methods for +//! combining two instances of various things and yielding a new instance. +//! These combiner methods always yield a `Result<T>`. To relate two +//! types, you can use `infcx.at(cause, param_env)` which then allows +//! you to use the relevant methods of [At](super::at::At). +//! +//! Combiners mostly do their specific behavior and then hand off the +//! bulk of the work to [InferCtxt::super_combine_tys] and +//! [InferCtxt::super_combine_consts]. +//! +//! Combining two types may have side-effects on the inference contexts +//! which can be undone by using snapshots. You probably want to use +//! either [InferCtxt::commit_if_ok] or [InferCtxt::probe]. +//! +//! On success, the LUB/GLB operations return the appropriate bound. The +//! return value of `Equate` or `Sub` shouldn't really be used. +//! +//! ## Contravariance +//! +//! We explicitly track which argument is expected using +//! [TypeRelation::a_is_expected], so when dealing with contravariance +//! this should be correctly updated. use super::equate::Equate; use super::glb::Glb; |
