1use rustc_data_structures::fx::FxHashMap;
2use rustc_errors::ErrorGuaranteed;
3use rustc_hir::def_id::DefId;
4use rustc_infer::infer::relate::{PredicateEmittingRelation, Relate, RelateResult, TypeRelation};
5use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
6use rustc_infer::traits::Obligation;
7use rustc_infer::traits::solve::Goal;
8use rustc_middle::mir::ConstraintCategory;
9use rustc_middle::traits::ObligationCause;
10use rustc_middle::traits::query::NoSolution;
11use rustc_middle::ty::relate::combine::{combine_ty_args, super_combine_consts, super_combine_tys};
12use rustc_middle::ty::relate::relate_args_invariantly;
13use rustc_middle::ty::{self, FnMutDelegate, Ty, TyCtxt, TypeVisitableExt};
14use rustc_middle::{bug, span_bug};
15use rustc_span::{Span, Symbol, sym};
16use tracing::{debug, instrument};
17
18use crate::constraints::OutlivesConstraint;
19use crate::diagnostics::UniverseInfo;
20use crate::renumber::RegionCtxt;
21use crate::type_check::{InstantiateOpaqueType, Locations, TypeChecker};
22
23impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("relate_types",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(32u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("a")
}> =
::tracing::__macro_support::FieldName::new("a");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("v")
}> =
::tracing::__macro_support::FieldName::new("v");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("b")
}> =
::tracing::__macro_support::FieldName::new("b");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("locations")
}> =
::tracing::__macro_support::FieldName::new("locations");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("category")
}> =
::tracing::__macro_support::FieldName::new("category");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&v)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&locations)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&category)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Result<(), NoSolution> = loop {};
return __tracing_attr_fake_return;
}
{
NllTypeRelating::new(self, locations, category,
UniverseInfo::relate(a, b), v).relate(a, b)?;
Ok(())
}
}
}#[instrument(skip(self), level = "debug")]
33 pub(super) fn relate_types(
34 &mut self,
35 a: Ty<'tcx>,
36 v: ty::Variance,
37 b: Ty<'tcx>,
38 locations: Locations,
39 category: ConstraintCategory<'tcx>,
40 ) -> Result<(), NoSolution> {
41 NllTypeRelating::new(self, locations, category, UniverseInfo::relate(a, b), v)
42 .relate(a, b)?;
43 Ok(())
44 }
45
46 pub(super) fn eq_args(
48 &mut self,
49 a: ty::GenericArgsRef<'tcx>,
50 b: ty::GenericArgsRef<'tcx>,
51 locations: Locations,
52 category: ConstraintCategory<'tcx>,
53 ) -> Result<(), NoSolution> {
54 NllTypeRelating::new(self, locations, category, UniverseInfo::other(), ty::Invariant)
55 .relate(a, b)?;
56 Ok(())
57 }
58}
59
60struct NllTypeRelating<'a, 'b, 'tcx> {
61 type_checker: &'a mut TypeChecker<'b, 'tcx>,
62
63 locations: Locations,
65
66 category: ConstraintCategory<'tcx>,
68
69 universe_info: UniverseInfo<'tcx>,
72
73 ambient_variance: ty::Variance,
80
81 ambient_variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
82}
83
84impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
85 fn new(
86 type_checker: &'a mut TypeChecker<'b, 'tcx>,
87 locations: Locations,
88 category: ConstraintCategory<'tcx>,
89 universe_info: UniverseInfo<'tcx>,
90 ambient_variance: ty::Variance,
91 ) -> Self {
92 Self {
93 type_checker,
94 locations,
95 category,
96 universe_info,
97 ambient_variance,
98 ambient_variance_info: ty::VarianceDiagInfo::default(),
99 }
100 }
101
102 fn ambient_covariance(&self) -> bool {
103 match self.ambient_variance {
104 ty::Covariant | ty::Invariant => true,
105 ty::Contravariant | ty::Bivariant => false,
106 }
107 }
108
109 fn ambient_contravariance(&self) -> bool {
110 match self.ambient_variance {
111 ty::Contravariant | ty::Invariant => true,
112 ty::Covariant | ty::Bivariant => false,
113 }
114 }
115
116 fn relate_opaques(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
117 let infcx = self.type_checker.infcx;
118 if true {
if !!infcx.next_trait_solver() {
::core::panicking::panic("assertion failed: !infcx.next_trait_solver()")
};
};debug_assert!(!infcx.next_trait_solver());
119 let mut enable_subtyping = |ty, opaque_is_expected| {
127 let ty_vid = infcx.next_ty_vid(self.span());
134 let variance = if opaque_is_expected {
135 self.ambient_variance
136 } else {
137 self.ambient_variance.xform(ty::Contravariant)
138 };
139
140 self.type_checker.infcx.instantiate_ty_var(
141 self,
142 opaque_is_expected,
143 ty_vid,
144 variance,
145 ty,
146 )?;
147 Ok(infcx.resolve_vars_if_possible(Ty::new_infer(infcx.tcx, ty::TyVar(ty_vid))))
148 };
149
150 let (a, b) = match (a.kind(), b.kind()) {
151 (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
152 (a, enable_subtyping(b, true)?)
153 }
154 (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
155 (enable_subtyping(a, false)?, b)
156 }
157 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("expected at least one opaque type in `relate_opaques`, got {0} and {1}.",
a, b)));
}unreachable!(
158 "expected at least one opaque type in `relate_opaques`, got {a} and {b}."
159 ),
160 };
161 self.register_goals(infcx.handle_opaque_type(a, b, self.span(), self.param_env())?);
162 Ok(())
163 }
164
165 fn enter_forall<T, U>(
166 &mut self,
167 binder: ty::Binder<'tcx, T>,
168 f: impl FnOnce(&mut Self, T) -> U,
169 ) -> U
170 where
171 T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
172 {
173 let value = if let Some(inner) = binder.no_bound_vars() {
174 inner
175 } else {
176 let infcx = self.type_checker.infcx;
177 let mut lazy_universe = None;
178 let delegate = FnMutDelegate {
179 regions: &mut |br: ty::BoundRegion<'tcx>| {
180 let universe = lazy_universe.unwrap_or_else(|| {
184 let universe = self.create_next_universe();
185 lazy_universe = Some(universe);
186 universe
187 });
188
189 let placeholder = ty::PlaceholderRegion::new(universe, br);
190 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:190",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(190u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("placeholder")
}> =
::tracing::__macro_support::FieldName::new("placeholder");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&placeholder)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?placeholder);
191 let placeholder_reg = self.next_placeholder_region(placeholder);
192 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:192",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(192u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("placeholder_reg")
}> =
::tracing::__macro_support::FieldName::new("placeholder_reg");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&placeholder_reg)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?placeholder_reg);
193
194 placeholder_reg
195 },
196 types: &mut |_bound_ty: ty::BoundTy<'tcx>| {
197 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("we only replace regions in nll_relate, not types")));
}unreachable!("we only replace regions in nll_relate, not types")
198 },
199 consts: &mut |_bound_const: ty::BoundConst<'tcx>| {
200 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("we only replace regions in nll_relate, not consts")));
}unreachable!("we only replace regions in nll_relate, not consts")
201 },
202 };
203
204 infcx.tcx.replace_bound_vars_uncached(binder, delegate)
205 };
206
207 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:207",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(207u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("value")
}> =
::tracing::__macro_support::FieldName::new("value");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?value);
208 f(self, value)
209 }
210
211 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("instantiate_binder_with_existentials",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(211u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("binder")
}> =
::tracing::__macro_support::FieldName::new("binder");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&binder)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: T = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(inner) = binder.no_bound_vars() { return inner; }
let infcx = self.type_checker.infcx;
let mut reg_map = FxHashMap::default();
let delegate =
FnMutDelegate {
regions: &mut |br: ty::BoundRegion<'tcx>|
{
if let Some(ex_reg_var) = reg_map.get(&br) {
*ex_reg_var
} else {
let ex_reg_var =
self.next_existential_region_var(br.kind.get_name(infcx.infcx.tcx));
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:229",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(229u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ex_reg_var")
}> =
::tracing::__macro_support::FieldName::new("ex_reg_var");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ex_reg_var)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
reg_map.insert(br, ex_reg_var);
ex_reg_var
}
},
types: &mut |_bound_ty: ty::BoundTy<'tcx>|
{
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("we only replace regions in nll_relate, not types")));
}
},
consts: &mut |_bound_const: ty::BoundConst<'tcx>|
{
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("we only replace regions in nll_relate, not consts")));
}
},
};
let replaced =
infcx.tcx.replace_bound_vars_uncached(binder, delegate);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:244",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(244u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("replaced")
}> =
::tracing::__macro_support::FieldName::new("replaced");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&replaced)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
replaced
}
}
}#[instrument(skip(self), level = "debug")]
212 fn instantiate_binder_with_existentials<T>(&mut self, binder: ty::Binder<'tcx, T>) -> T
213 where
214 T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
215 {
216 if let Some(inner) = binder.no_bound_vars() {
217 return inner;
218 }
219
220 let infcx = self.type_checker.infcx;
221 let mut reg_map = FxHashMap::default();
222 let delegate = FnMutDelegate {
223 regions: &mut |br: ty::BoundRegion<'tcx>| {
224 if let Some(ex_reg_var) = reg_map.get(&br) {
225 *ex_reg_var
226 } else {
227 let ex_reg_var =
228 self.next_existential_region_var(br.kind.get_name(infcx.infcx.tcx));
229 debug!(?ex_reg_var);
230 reg_map.insert(br, ex_reg_var);
231
232 ex_reg_var
233 }
234 },
235 types: &mut |_bound_ty: ty::BoundTy<'tcx>| {
236 unreachable!("we only replace regions in nll_relate, not types")
237 },
238 consts: &mut |_bound_const: ty::BoundConst<'tcx>| {
239 unreachable!("we only replace regions in nll_relate, not consts")
240 },
241 };
242
243 let replaced = infcx.tcx.replace_bound_vars_uncached(binder, delegate);
244 debug!(?replaced);
245
246 replaced
247 }
248
249 fn create_next_universe(&mut self) -> ty::UniverseIndex {
250 let universe = self.type_checker.infcx.create_next_universe();
251 self.type_checker.constraints.universe_causes.insert(universe, self.universe_info.clone());
252 universe
253 }
254
255 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("next_existential_region_var",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(255u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("name")
}> =
::tracing::__macro_support::FieldName::new("name");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&name)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::Region<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let origin = NllRegionVariableOrigin::Existential { name };
self.type_checker.infcx.next_nll_region_var(origin,
|| RegionCtxt::Existential(name))
}
}
}#[instrument(skip(self), level = "debug")]
256 fn next_existential_region_var(&mut self, name: Option<Symbol>) -> ty::Region<'tcx> {
257 let origin = NllRegionVariableOrigin::Existential { name };
258 self.type_checker.infcx.next_nll_region_var(origin, || RegionCtxt::Existential(name))
259 }
260
261 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("next_placeholder_region",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(261u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("placeholder")
}> =
::tracing::__macro_support::FieldName::new("placeholder");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&placeholder)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::Region<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let reg =
self.type_checker.constraints.placeholder_region(self.type_checker.infcx,
placeholder);
let reg_info =
match placeholder.bound.kind {
ty::BoundRegionKind::Anon => sym::anon,
ty::BoundRegionKind::Named(def_id) =>
self.type_checker.tcx().item_name(def_id),
ty::BoundRegionKind::ClosureEnv => sym::env,
ty::BoundRegionKind::NamedForPrinting(_) =>
::rustc_middle::util::bug::bug_fmt(format_args!("only used for pretty printing")),
};
if true {
let mut var_to_origin =
self.type_checker.infcx.reg_var_to_origin.borrow_mut();
let new = RegionCtxt::Placeholder(reg_info);
let prev = var_to_origin.insert(reg.as_var(), new);
if let Some(prev) = prev {
{
match (&new, &prev) {
(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);
}
}
}
};
}
}
reg
}
}
}#[instrument(skip(self), level = "debug")]
262 fn next_placeholder_region(
263 &mut self,
264 placeholder: ty::PlaceholderRegion<'tcx>,
265 ) -> ty::Region<'tcx> {
266 let reg =
267 self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder);
268
269 let reg_info = match placeholder.bound.kind {
270 ty::BoundRegionKind::Anon => sym::anon,
271 ty::BoundRegionKind::Named(def_id) => self.type_checker.tcx().item_name(def_id),
272 ty::BoundRegionKind::ClosureEnv => sym::env,
273 ty::BoundRegionKind::NamedForPrinting(_) => bug!("only used for pretty printing"),
274 };
275
276 if cfg!(debug_assertions) {
277 let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
278 let new = RegionCtxt::Placeholder(reg_info);
279 let prev = var_to_origin.insert(reg.as_var(), new);
280 if let Some(prev) = prev {
281 assert_eq!(new, prev);
282 }
283 }
284
285 reg
286 }
287
288 fn push_outlives(
289 &mut self,
290 sup: ty::Region<'tcx>,
291 sub: ty::Region<'tcx>,
292 info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
293 ) {
294 let sub = self.type_checker.universal_regions.to_region_vid(sub);
295 let sup = self.type_checker.universal_regions.to_region_vid(sup);
296 self.type_checker.constraints.outlives_constraints.push(OutlivesConstraint {
297 sup,
298 sub,
299 locations: self.locations,
300 span: self.locations.span(self.type_checker.body),
301 category: self.category,
302 variance_info: info,
303 from_closure: false,
304 });
305 }
306}
307
308impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
309 fn cx(&self) -> TyCtxt<'tcx> {
310 self.type_checker.infcx.tcx
311 }
312
313 fn relate_ty_args(
314 &mut self,
315 a_ty: Ty<'tcx>,
316 b_ty: Ty<'tcx>,
317 def_id: DefId,
318 a_args: ty::GenericArgsRef<'tcx>,
319 b_args: ty::GenericArgsRef<'tcx>,
320 _: impl FnOnce(ty::GenericArgsRef<'tcx>) -> Ty<'tcx>,
321 ) -> RelateResult<'tcx, Ty<'tcx>> {
322 if self.ambient_variance == ty::Invariant {
323 relate_args_invariantly(self, a_args, b_args)?;
326 Ok(a_ty)
327 } else {
328 let variances = self.cx().variances_of(def_id);
329 combine_ty_args(
330 &self.type_checker.infcx.infcx,
331 self,
332 a_ty,
333 b_ty,
334 variances,
335 a_args,
336 b_args,
337 |_| a_ty,
338 )
339 }
340 }
341
342 x;#[instrument(skip(self, info), level = "trace", ret)]
343 fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
344 &mut self,
345 variance: ty::Variance,
346 info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
347 a: T,
348 b: T,
349 ) -> RelateResult<'tcx, T> {
350 let old_ambient_variance = self.ambient_variance;
351 self.ambient_variance = self.ambient_variance.xform(variance);
352 self.ambient_variance_info = self.ambient_variance_info.xform(info);
353
354 debug!(?self.ambient_variance);
355 let r = if self.ambient_variance == ty::Bivariant { Ok(a) } else { self.relate(a, b) };
357
358 self.ambient_variance = old_ambient_variance;
359
360 r
361 }
362
363 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("tys",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(363u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("a")
}> =
::tracing::__macro_support::FieldName::new("a");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("b")
}> =
::tracing::__macro_support::FieldName::new("b");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: RelateResult<'tcx, Ty<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let infcx = self.type_checker.infcx;
let a = infcx.shallow_resolve(a);
if !!b.has_non_region_infer() {
{
::core::panicking::panic_fmt(format_args!("unexpected inference var {0:?}",
b));
}
};
if a == b { return Ok(a); }
match (a.kind(), b.kind()) {
(_, &ty::Infer(ty::TyVar(_))) => {
::rustc_middle::util::bug::span_bug_fmt(self.span(),
format_args!("should not be relating type variables on the right in MIR typeck"));
}
(&ty::Infer(ty::TyVar(a_vid)), _) => {
infcx.instantiate_ty_var(self, true, a_vid,
self.ambient_variance, b)?
}
(&ty::Alias(_, ty::AliasTy {
kind: ty::Opaque { def_id: a_def_id }, .. }),
&ty::Alias(_, ty::AliasTy {
kind: ty::Opaque { def_id: b_def_id }, .. })) if
a_def_id == b_def_id || infcx.next_trait_solver() => {
super_combine_tys(&infcx.infcx, self, a,
b).map(|_|
()).or_else(|err|
{
if !!self.type_checker.infcx.next_trait_solver() {
::core::panicking::panic("assertion failed: !self.type_checker.infcx.next_trait_solver()")
};
self.cx().dcx().span_delayed_bug(self.span(),
"failure to relate an opaque to itself should result in an error later on");
if a_def_id.is_local() {
self.relate_opaques(a, b)
} else { Err(err) }
})?;
}
(&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, ..
}), _) |
(_,
&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, ..
})) if
def_id.is_local() &&
!self.type_checker.infcx.next_trait_solver() => {
self.relate_opaques(a, b)?;
}
_ => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:410",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(410u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("a")
}> =
::tracing::__macro_support::FieldName::new("a");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("b")
}> =
::tracing::__macro_support::FieldName::new("b");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self.ambient_variance")
}> =
::tracing::__macro_support::FieldName::new("self.ambient_variance");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
super_combine_tys(&self.type_checker.infcx.infcx, self, a,
b)?;
}
}
Ok(a)
}
}
}#[instrument(skip(self), level = "debug")]
364 fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
365 let infcx = self.type_checker.infcx;
366
367 let a = infcx.shallow_resolve(a);
368 assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
369
370 if a == b {
371 return Ok(a);
372 }
373
374 match (a.kind(), b.kind()) {
375 (_, &ty::Infer(ty::TyVar(_))) => {
376 span_bug!(
377 self.span(),
378 "should not be relating type variables on the right in MIR typeck"
379 );
380 }
381
382 (&ty::Infer(ty::TyVar(a_vid)), _) => {
383 infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?
384 }
385
386 (
387 &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }),
388 &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }),
389 ) if a_def_id == b_def_id || infcx.next_trait_solver() => {
390 super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| {
391 assert!(!self.type_checker.infcx.next_trait_solver());
395 self.cx().dcx().span_delayed_bug(
396 self.span(),
397 "failure to relate an opaque to itself should result in an error later on",
398 );
399 if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
400 })?;
401 }
402 (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _)
403 | (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }))
404 if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() =>
405 {
406 self.relate_opaques(a, b)?;
407 }
408
409 _ => {
410 debug!(?a, ?b, ?self.ambient_variance);
411
412 super_combine_tys(&self.type_checker.infcx.infcx, self, a, b)?;
414 }
415 }
416
417 Ok(a)
418 }
419
420 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("regions",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(420u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("a")
}> =
::tracing::__macro_support::FieldName::new("a");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("b")
}> =
::tracing::__macro_support::FieldName::new("b");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
RelateResult<'tcx, ty::Region<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:426",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(426u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self.ambient_variance")
}> =
::tracing::__macro_support::FieldName::new("self.ambient_variance");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if self.ambient_covariance() {
self.push_outlives(a, b, self.ambient_variance_info);
}
if self.ambient_contravariance() {
self.push_outlives(b, a, self.ambient_variance_info);
}
Ok(a)
}
}
}#[instrument(skip(self), level = "trace")]
421 fn regions(
422 &mut self,
423 a: ty::Region<'tcx>,
424 b: ty::Region<'tcx>,
425 ) -> RelateResult<'tcx, ty::Region<'tcx>> {
426 debug!(?self.ambient_variance);
427
428 if self.ambient_covariance() {
429 self.push_outlives(a, b, self.ambient_variance_info);
431 }
432
433 if self.ambient_contravariance() {
434 self.push_outlives(b, a, self.ambient_variance_info);
436 }
437
438 Ok(a)
439 }
440
441 fn consts(
442 &mut self,
443 a: ty::Const<'tcx>,
444 b: ty::Const<'tcx>,
445 ) -> RelateResult<'tcx, ty::Const<'tcx>> {
446 let a = self.type_checker.infcx.shallow_resolve_const(a);
447 if !!a.has_non_region_infer() {
{
::core::panicking::panic_fmt(format_args!("unexpected inference var {0:?}",
a));
}
};assert!(!a.has_non_region_infer(), "unexpected inference var {:?}", a);
448 if !!b.has_non_region_infer() {
{
::core::panicking::panic_fmt(format_args!("unexpected inference var {0:?}",
b));
}
};assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
449
450 super_combine_consts(&self.type_checker.infcx.infcx, self, a, b)
451 }
452
453 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("binders",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(453u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("a")
}> =
::tracing::__macro_support::FieldName::new("a");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("b")
}> =
::tracing::__macro_support::FieldName::new("b");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
RelateResult<'tcx, ty::Binder<'tcx, T>> = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/relate_tys.rs:481",
"rustc_borrowck::type_check::relate_tys",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
::tracing_core::__macro_support::Option::Some(481u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self.ambient_variance")
}> =
::tracing::__macro_support::FieldName::new("self.ambient_variance");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars())
{
self.relate(a, b)?;
return Ok(ty::Binder::dummy(a));
}
match self.ambient_variance {
ty::Covariant => {
self.enter_forall(b,
|this, b|
{
let a = this.instantiate_binder_with_existentials(a);
this.relate(a, b)
})?;
}
ty::Contravariant => {
self.enter_forall(a,
|this, a|
{
let b = this.instantiate_binder_with_existentials(b);
this.relate(a, b)
})?;
}
ty::Invariant => {
self.enter_forall(b,
|this, b|
{
let a = this.instantiate_binder_with_existentials(a);
this.relate(a, b)
})?;
self.enter_forall(a,
|this, a|
{
let b = this.instantiate_binder_with_existentials(b);
this.relate(a, b)
})?;
}
ty::Bivariant => {}
}
Ok(a)
}
}
}#[instrument(skip(self), level = "trace")]
454 fn binders<T>(
455 &mut self,
456 a: ty::Binder<'tcx, T>,
457 b: ty::Binder<'tcx, T>,
458 ) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
459 where
460 T: Relate<TyCtxt<'tcx>>,
461 {
462 debug!(?self.ambient_variance);
482
483 if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars()) {
484 self.relate(a, b)?;
486 return Ok(ty::Binder::dummy(a));
487 }
488
489 match self.ambient_variance {
490 ty::Covariant => {
491 self.enter_forall(b, |this, b| {
500 let a = this.instantiate_binder_with_existentials(a);
501 this.relate(a, b)
502 })?;
503 }
504
505 ty::Contravariant => {
506 self.enter_forall(a, |this, a| {
515 let b = this.instantiate_binder_with_existentials(b);
516 this.relate(a, b)
517 })?;
518 }
519
520 ty::Invariant => {
521 self.enter_forall(b, |this, b| {
530 let a = this.instantiate_binder_with_existentials(a);
531 this.relate(a, b)
532 })?;
533 self.enter_forall(a, |this, a| {
536 let b = this.instantiate_binder_with_existentials(b);
537 this.relate(a, b)
538 })?;
539 }
540
541 ty::Bivariant => {}
542 }
543
544 Ok(a)
545 }
546}
547
548impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
549 fn span(&self) -> Span {
550 self.locations.span(self.type_checker.body)
551 }
552
553 fn param_env(&self) -> ty::ParamEnv<'tcx> {
554 self.type_checker.infcx.param_env
555 }
556
557 fn register_predicates(
558 &mut self,
559 obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
560 ) {
561 let tcx = self.cx();
562 let param_env = self.param_env();
563 self.register_goals(
564 obligations.into_iter().map(|to_pred| Goal::new(tcx, param_env, to_pred)),
565 );
566 }
567
568 fn register_goals(
569 &mut self,
570 obligations: impl IntoIterator<Item = Goal<'tcx, ty::Predicate<'tcx>>>,
571 ) {
572 let _: Result<_, ErrorGuaranteed> = self.type_checker.fully_perform_op(
573 self.locations,
574 self.category,
575 InstantiateOpaqueType {
576 obligations: obligations
577 .into_iter()
578 .map(|goal| {
579 Obligation::new(
580 self.cx(),
581 ObligationCause::dummy_with_span(self.span()),
582 goal.param_env,
583 goal.predicate,
584 )
585 })
586 .collect(),
587 base_universe: None,
589 region_constraints: None,
590 },
591 );
592 }
593
594 fn ambient_variance(&self) -> ty::Variance {
595 self.ambient_variance
596 }
597}