Skip to content

Commit 141b0a4

Browse files
authored
Rollup merge of #97874 - lcnr:combine-comment, r=davidtwco
rewrite combine doc comment it was from 2014 and somewhat outdated
2 parents 5d81f91 + 36a4490 commit 141b0a4

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

compiler/rustc_infer/src/infer/combine.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
///////////////////////////////////////////////////////////////////////////
2-
// # Type combining
3-
//
4-
// There are four type combiners: equate, sub, lub, and glb. Each
5-
// implements the trait `Combine` and contains methods for combining
6-
// two instances of various things and yielding a new instance. These
7-
// combiner methods always yield a `Result<T>`. There is a lot of
8-
// common code for these operations, implemented as default methods on
9-
// the `Combine` trait.
10-
//
11-
// Each operation may have side-effects on the inference context,
12-
// though these can be unrolled using snapshots. On success, the
13-
// LUB/GLB operations return the appropriate bound. The Eq and Sub
14-
// operations generally return the first operand.
15-
//
16-
// ## Contravariance
17-
//
18-
// When you are relating two things which have a contravariant
19-
// relationship, you should use `contratys()` or `contraregions()`,
20-
// rather than inversing the order of arguments! This is necessary
21-
// because the order of arguments is not relevant for LUB and GLB. It
22-
// is also useful to track which value is the "expected" value in
23-
// terms of error reporting.
1+
//! There are four type combiners: [Equate], [Sub], [Lub], and [Glb].
2+
//! Each implements the trait [TypeRelation] and contains methods for
3+
//! combining two instances of various things and yielding a new instance.
4+
//! These combiner methods always yield a `Result<T>`. To relate two
5+
//! types, you can use `infcx.at(cause, param_env)` which then allows
6+
//! you to use the relevant methods of [At](super::at::At).
7+
//!
8+
//! Combiners mostly do their specific behavior and then hand off the
9+
//! bulk of the work to [InferCtxt::super_combine_tys] and
10+
//! [InferCtxt::super_combine_consts].
11+
//!
12+
//! Combining two types may have side-effects on the inference contexts
13+
//! which can be undone by using snapshots. You probably want to use
14+
//! either [InferCtxt::commit_if_ok] or [InferCtxt::probe].
15+
//!
16+
//! On success, the LUB/GLB operations return the appropriate bound. The
17+
//! return value of `Equate` or `Sub` shouldn't really be used.
18+
//!
19+
//! ## Contravariance
20+
//!
21+
//! We explicitly track which argument is expected using
22+
//! [TypeRelation::a_is_expected], so when dealing with contravariance
23+
//! this should be correctly updated.
2424
2525
use super::equate::Equate;
2626
use super::glb::Glb;

0 commit comments

Comments
 (0)