1use std::cmp;
2use std::marker::PhantomData;
3use std::ops::Range;
45use rustc_data_structures::undo_log::Rollback;
6use rustc_data_structures::{snapshot_vecas sv, unifyas ut};
7use rustc_hir::def_id::DefId;
8use rustc_index::IndexVec;
9use rustc_middle::bug;
10use rustc_middle::ty::{self, Ty, TyVid};
11use rustc_span::Span;
12use tracing::debug;
1314use crate::infer::InferCtxtUndoLogs;
1516/// Represents a single undo-able action that affects a type inference variable.
17#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for UndoLog<'tcx> {
#[inline]
fn clone(&self) -> UndoLog<'tcx> {
match self {
UndoLog::EqRelation(__self_0) =>
UndoLog::EqRelation(::core::clone::Clone::clone(__self_0)),
UndoLog::SubRelation(__self_0) =>
UndoLog::SubRelation(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
18pub(crate) enum UndoLog<'tcx> {
19 EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
20 SubRelation(sv::UndoLog<ut::Delegate<TyVidSubKey>>),
21}
2223/// Convert from a specific kind of undo to the more general UndoLog
24impl<'tcx> From<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for UndoLog<'tcx> {
25fn from(l: sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>) -> Self {
26 UndoLog::EqRelation(l)
27 }
28}
2930/// Convert from a specific kind of undo to the more general UndoLog
31impl<'tcx> From<sv::UndoLog<ut::Delegate<TyVidSubKey>>> for UndoLog<'tcx> {
32fn from(l: sv::UndoLog<ut::Delegate<TyVidSubKey>>) -> Self {
33 UndoLog::SubRelation(l)
34 }
35}
3637impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for TypeVariableStorage<'tcx> {
38fn reverse(&mut self, undo: sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>) {
39self.eq_relations.reverse(undo)
40 }
41}
4243impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidSubKey>>> for TypeVariableStorage<'tcx> {
44fn reverse(&mut self, undo: sv::UndoLog<ut::Delegate<TyVidSubKey>>) {
45self.sub_unification_table.reverse(undo)
46 }
47}
4849impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx> {
50fn reverse(&mut self, undo: UndoLog<'tcx>) {
51match undo {
52 UndoLog::EqRelation(undo) => self.eq_relations.reverse(undo),
53 UndoLog::SubRelation(undo) => self.sub_unification_table.reverse(undo),
54 }
55 }
56}
5758#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for TypeVariableStorage<'tcx> {
#[inline]
fn clone(&self) -> TypeVariableStorage<'tcx> {
TypeVariableStorage {
values: ::core::clone::Clone::clone(&self.values),
eq_relations: ::core::clone::Clone::clone(&self.eq_relations),
sub_unification_table: ::core::clone::Clone::clone(&self.sub_unification_table),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::default::Default for TypeVariableStorage<'tcx> {
#[inline]
fn default() -> TypeVariableStorage<'tcx> {
TypeVariableStorage {
values: ::core::default::Default::default(),
eq_relations: ::core::default::Default::default(),
sub_unification_table: ::core::default::Default::default(),
}
}
}Default)]
59pub(crate) struct TypeVariableStorage<'tcx> {
60/// The origins of each type variable.
61values: IndexVec<TyVid, TypeVariableData>,
62/// Two variables are unified in `eq_relations` when we have a
63 /// constraint `?X == ?Y`. This table also stores, for each key,
64 /// the known value.
65eq_relations: ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
66/// Only used by `-Znext-solver` and for diagnostics. Tracks whether
67 /// type variables are related via subtyping at all, ignoring which of
68 /// the two is the subtype.
69 ///
70 /// When reporting ambiguity errors, we sometimes want to
71 /// treat all inference vars which are subtypes of each
72 /// others as if they are equal. For this case we compute
73 /// the transitive closure of our subtype obligations here.
74 ///
75 /// E.g. when encountering ambiguity errors, we want to suggest
76 /// specifying some method argument or to add a type annotation
77 /// to a local variable. Because subtyping cannot change the
78 /// shape of a type, it's fine if the cause of the ambiguity error
79 /// is only related to the suggested variable via subtyping.
80 ///
81 /// Even for something like `let x = returns_arg(); x.method();` the
82 /// type of `x` is only a supertype of the argument of `returns_arg`. We
83 /// still want to suggest specifying the type of the argument.
84sub_unification_table: ut::UnificationTableStorage<TyVidSubKey>,
85}
8687pub(crate) struct TypeVariableTable<'a, 'tcx> {
88 storage: &'a mut TypeVariableStorage<'tcx>,
8990 undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
91}
9293#[derive(#[automatically_derived]
impl ::core::marker::Copy for TypeVariableOrigin { }Copy, #[automatically_derived]
impl ::core::clone::Clone for TypeVariableOrigin {
#[inline]
fn clone(&self) -> TypeVariableOrigin {
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<Option<DefId>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for TypeVariableOrigin {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"TypeVariableOrigin", "span", &self.span, "param_def_id",
&&self.param_def_id)
}
}Debug)]
94pub struct TypeVariableOrigin {
95pub span: Span,
96/// `DefId` of the type parameter this was instantiated for, if any.
97 ///
98 /// This should only be used for diagnostics.
99pub param_def_id: Option<DefId>,
100}
101102#[derive(#[automatically_derived]
impl ::core::clone::Clone for TypeVariableData {
#[inline]
fn clone(&self) -> TypeVariableData {
TypeVariableData { origin: ::core::clone::Clone::clone(&self.origin) }
}
}Clone)]
103pub(crate) struct TypeVariableData {
104 origin: TypeVariableOrigin,
105}
106107#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TypeVariableValue<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TypeVariableValue<'tcx> {
#[inline]
fn clone(&self) -> TypeVariableValue<'tcx> {
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<ty::UniverseIndex>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for TypeVariableValue<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
TypeVariableValue::Known { value: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Known",
"value", &__self_0),
TypeVariableValue::Unknown { universe: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Unknown", "universe", &__self_0),
}
}
}Debug)]
108pub(crate) enum TypeVariableValue<'tcx> {
109 Known { value: Ty<'tcx> },
110 Unknown { universe: ty::UniverseIndex },
111}
112113impl<'tcx> TypeVariableValue<'tcx> {
114/// If this value is known, returns the type it is known to be.
115 /// Otherwise, `None`.
116pub(crate) fn known(&self) -> Option<Ty<'tcx>> {
117match *self {
118 TypeVariableValue::Unknown { .. } => None,
119 TypeVariableValue::Known { value } => Some(value),
120 }
121 }
122123pub(crate) fn is_unknown(&self) -> bool {
124match *self {
125 TypeVariableValue::Unknown { .. } => true,
126 TypeVariableValue::Known { .. } => false,
127 }
128 }
129}
130131impl<'tcx> TypeVariableStorage<'tcx> {
132#[inline]
133pub(crate) fn with_log<'a>(
134&'a mut self,
135 undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
136 ) -> TypeVariableTable<'a, 'tcx> {
137TypeVariableTable { storage: self, undo_log }
138 }
139140#[inline]
141pub(crate) fn eq_relations_ref(&self) -> &ut::UnificationTableStorage<TyVidEqKey<'tcx>> {
142&self.eq_relations
143 }
144145pub(super) fn finalize_rollback(&mut self) {
146if true {
if !(self.values.len() >= self.eq_relations.len()) {
::core::panicking::panic("assertion failed: self.values.len() >= self.eq_relations.len()")
};
};debug_assert!(self.values.len() >= self.eq_relations.len());
147self.values.truncate(self.eq_relations.len());
148 }
149}
150151impl<'tcx> TypeVariableTable<'_, 'tcx> {
152/// Returns the origin that was given when `vid` was created.
153 ///
154 /// Note that this function does not return care whether
155 /// `vid` has been unified with something else or not.
156pub(crate) fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
157self.storage.values[vid].origin
158 }
159160/// Records that `a == b`.
161 ///
162 /// Precondition: neither `a` nor `b` are known.
163pub(crate) fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
164if true {
if !self.probe(a).is_unknown() {
::core::panicking::panic("assertion failed: self.probe(a).is_unknown()")
};
};debug_assert!(self.probe(a).is_unknown());
165if true {
if !self.probe(b).is_unknown() {
::core::panicking::panic("assertion failed: self.probe(b).is_unknown()")
};
};debug_assert!(self.probe(b).is_unknown());
166self.eq_relations().union(a, b);
167self.sub_unification_table().union(a, b);
168 }
169170/// Records that `a` and `b` are related via subtyping. We don't track
171 /// which of the two is the subtype.
172 ///
173 /// Precondition: neither `a` nor `b` are known.
174pub(crate) fn sub_unify(&mut self, a: ty::TyVid, b: ty::TyVid) {
175if true {
if !self.probe(a).is_unknown() {
::core::panicking::panic("assertion failed: self.probe(a).is_unknown()")
};
};debug_assert!(self.probe(a).is_unknown());
176if true {
if !self.probe(b).is_unknown() {
::core::panicking::panic("assertion failed: self.probe(b).is_unknown()")
};
};debug_assert!(self.probe(b).is_unknown());
177self.sub_unification_table().union(a, b);
178 }
179180/// Instantiates `vid` with the type `ty`.
181 ///
182 /// Precondition: `vid` must not have been previously instantiated.
183pub(crate) fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
184let vid = self.root_var(vid);
185if true {
if !!ty.is_ty_var() {
{
::core::panicking::panic_fmt(format_args!("instantiating ty var with var: {0:?} {1:?}",
vid, ty));
}
};
};debug_assert!(!ty.is_ty_var(), "instantiating ty var with var: {vid:?} {ty:?}");
186if true {
if !self.probe(vid).is_unknown() {
::core::panicking::panic("assertion failed: self.probe(vid).is_unknown()")
};
};debug_assert!(self.probe(vid).is_unknown());
187if true {
if !self.eq_relations().probe_value(vid).is_unknown() {
{
::core::panicking::panic_fmt(format_args!("instantiating type variable `{1:?}` twice: new-value = {2:?}, old-value={0:?}",
self.eq_relations().probe_value(vid), vid, ty));
}
};
};debug_assert!(
188self.eq_relations().probe_value(vid).is_unknown(),
189"instantiating type variable `{vid:?}` twice: new-value = {ty:?}, old-value={:?}",
190self.eq_relations().probe_value(vid)
191 );
192self.eq_relations().union_value(vid, TypeVariableValue::Known { value: ty });
193 }
194195/// Creates a new type variable.
196 ///
197 /// - `diverging`: indicates if this is a "diverging" type
198 /// variable, e.g., one created as the type of a `return`
199 /// expression. The code in this module doesn't care if a
200 /// variable is diverging, but the main Rust type-checker will
201 /// sometimes "unify" such variables with the `!` or `()` types.
202 /// - `origin`: indicates *why* the type variable was created.
203 /// The code in this module doesn't care, but it can be useful
204 /// for improving error messages.
205pub(crate) fn new_var(
206&mut self,
207 universe: ty::UniverseIndex,
208 origin: TypeVariableOrigin,
209 ) -> ty::TyVid {
210let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
211212let sub_key = self.sub_unification_table().new_key(());
213if true {
match (&eq_key.vid, &sub_key.vid) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(eq_key.vid, sub_key.vid);
214215let index = self.storage.values.push(TypeVariableData { origin });
216if true {
match (&eq_key.vid, &index) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(eq_key.vid, index);
217218{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/type_variable.rs:218",
"rustc_infer::infer::type_variable",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/type_variable.rs"),
::tracing_core::__macro_support::Option::Some(218u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::type_variable"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("new_var(index={0:?}, universe={1:?}, origin={2:?})",
eq_key.vid, universe, origin) as &dyn Value))])
});
} else { ; }
};debug!("new_var(index={:?}, universe={:?}, origin={:?})", eq_key.vid, universe, origin);
219220index221 }
222223/// Returns the number of type variables created thus far.
224pub(crate) fn num_vars(&self) -> usize {
225self.storage.values.len()
226 }
227228/// Returns the "root" variable of `vid` in the `eq_relations`
229 /// equivalence table. All type variables that have been equated
230 /// will yield the same root variable (per the union-find
231 /// algorithm), so `root_var(a) == root_var(b)` implies that `a ==
232 /// b` (transitively).
233pub(crate) fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
234self.eq_relations().find(vid).vid
235 }
236237/// Returns the "root" variable of `vid` in the `sub_unification_table`
238 /// equivalence table. All type variables that have been are related via
239 /// equality or subtyping will yield the same root variable (per the
240 /// union-find algorithm), so `sub_unification_table_root_var(a)
241 /// == sub_unification_table_root_var(b)` implies that:
242 /// ```text
243 /// exists X. (a <: X || X <: a) && (b <: X || X <: b)
244 /// ```
245pub(crate) fn sub_unification_table_root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
246self.sub_unification_table().find(vid).vid
247 }
248249/// Retrieves the type to which `vid` has been instantiated, if
250 /// any.
251pub(crate) fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
252self.inlined_probe(vid)
253 }
254255/// An always-inlined variant of `probe`, for very hot call sites.
256#[inline(always)]
257pub(crate) fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
258self.eq_relations().inlined_probe_value(vid)
259 }
260261#[inline]
262fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
263self.storage.eq_relations.with_log(self.undo_log)
264 }
265266#[inline]
267fn sub_unification_table(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidSubKey> {
268self.storage.sub_unification_table.with_log(self.undo_log)
269 }
270271/// Returns a range of the type variables created during the snapshot.
272pub(crate) fn vars_since_snapshot(
273&mut self,
274 value_count: usize,
275 ) -> (Range<TyVid>, Vec<TypeVariableOrigin>) {
276let range = TyVid::from_usize(value_count)..TyVid::from_usize(self.num_vars());
277 (range.clone(), range.map(|index| self.var_origin(index)).collect())
278 }
279280/// Returns indices of all variables that are not yet
281 /// instantiated.
282pub(crate) fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
283 (0..self.num_vars())
284 .filter_map(|i| {
285let vid = ty::TyVid::from_usize(i);
286match self.probe(vid) {
287 TypeVariableValue::Unknown { .. } => Some(vid),
288 TypeVariableValue::Known { .. } => None,
289 }
290 })
291 .collect()
292 }
293}
294295///////////////////////////////////////////////////////////////////////////
296297/// These structs (a newtyped TyVid) are used as the unification key
298/// for the `eq_relations`; they carry a `TypeVariableValue` along
299/// with them.
300#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TyVidEqKey<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TyVidEqKey<'tcx> {
#[inline]
fn clone(&self) -> TyVidEqKey<'tcx> {
let _: ::core::clone::AssertParamIsClone<ty::TyVid>;
let _:
::core::clone::AssertParamIsClone<PhantomData<TypeVariableValue<'tcx>>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for TyVidEqKey<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "TyVidEqKey",
"vid", &self.vid, "phantom", &&self.phantom)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for TyVidEqKey<'tcx> {
#[inline]
fn eq(&self, other: &TyVidEqKey<'tcx>) -> bool {
self.vid == other.vid && self.phantom == other.phantom
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for TyVidEqKey<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<ty::TyVid>;
let _:
::core::cmp::AssertParamIsEq<PhantomData<TypeVariableValue<'tcx>>>;
}
}Eq)]
301pub(crate) struct TyVidEqKey<'tcx> {
302 vid: ty::TyVid,
303304// in the table, we map each ty-vid to one of these:
305phantom: PhantomData<TypeVariableValue<'tcx>>,
306}
307308impl<'tcx> From<ty::TyVid> for TyVidEqKey<'tcx> {
309#[inline] // make this function eligible for inlining - it is quite hot.
310fn from(vid: ty::TyVid) -> Self {
311TyVidEqKey { vid, phantom: PhantomData }
312 }
313}
314315impl<'tcx> ut::UnifyKeyfor TyVidEqKey<'tcx> {
316type Value = TypeVariableValue<'tcx>;
317#[inline(always)]
318fn index(&self) -> u32 {
319self.vid.as_u32()
320 }
321#[inline]
322fn from_index(i: u32) -> Self {
323TyVidEqKey::from(ty::TyVid::from_u32(i))
324 }
325fn tag() -> &'static str {
326"TyVidEqKey"
327}
328fn order_roots(a: Self, _: &Self::Value, b: Self, _: &Self::Value) -> Option<(Self, Self)> {
329if a.vid.as_u32() < b.vid.as_u32() { Some((a, b)) } else { Some((b, a)) }
330 }
331}
332333#[derive(#[automatically_derived]
impl ::core::marker::Copy for TyVidSubKey { }Copy, #[automatically_derived]
impl ::core::clone::Clone for TyVidSubKey {
#[inline]
fn clone(&self) -> TyVidSubKey {
let _: ::core::clone::AssertParamIsClone<ty::TyVid>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for TyVidSubKey {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "TyVidSubKey",
"vid", &&self.vid)
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for TyVidSubKey {
#[inline]
fn eq(&self, other: &TyVidSubKey) -> bool { self.vid == other.vid }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for TyVidSubKey {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<ty::TyVid>;
}
}Eq)]
334pub(crate) struct TyVidSubKey {
335 vid: ty::TyVid,
336}
337338impl From<ty::TyVid> for TyVidSubKey {
339#[inline] // make this function eligible for inlining - it is quite hot.
340fn from(vid: ty::TyVid) -> Self {
341TyVidSubKey { vid }
342 }
343}
344345impl ut::UnifyKeyfor TyVidSubKey {
346type Value = ();
347#[inline]
348fn index(&self) -> u32 {
349self.vid.as_u32()
350 }
351#[inline]
352fn from_index(i: u32) -> TyVidSubKey {
353TyVidSubKey { vid: ty::TyVid::from_u32(i) }
354 }
355fn tag() -> &'static str {
356"TyVidSubKey"
357}
358}
359360impl<'tcx> ut::UnifyValuefor TypeVariableValue<'tcx> {
361type Error = ut::NoError;
362363fn unify_values(value1: &Self, value2: &Self) -> Result<Self, ut::NoError> {
364match (value1, value2) {
365// We never equate two type variables, both of which
366 // have known types. Instead, we recursively equate
367 // those types.
368(&TypeVariableValue::Known { .. }, &TypeVariableValue::Known { .. }) => {
369::rustc_middle::util::bug::bug_fmt(format_args!("equating two type variables, both of which have known types"))bug!("equating two type variables, both of which have known types")370 }
371372// If one side is known, prefer that one.
373(&TypeVariableValue::Known { .. }, &TypeVariableValue::Unknown { .. }) => Ok(*value1),
374 (&TypeVariableValue::Unknown { .. }, &TypeVariableValue::Known { .. }) => Ok(*value2),
375376// If both sides are *unknown*, it hardly matters, does it?
377(
378&TypeVariableValue::Unknown { universe: universe1 },
379&TypeVariableValue::Unknown { universe: universe2 },
380 ) => {
381// If we unify two unbound variables, ?T and ?U, then whatever
382 // value they wind up taking (which must be the same value) must
383 // be nameable by both universes. Therefore, the resulting
384 // universe is the minimum of the two universes, because that is
385 // the one which contains the fewest names in scope.
386let universe = cmp::min(universe1, universe2);
387Ok(TypeVariableValue::Unknown { universe })
388 }
389 }
390 }
391}