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