1use std::cell::RefCell;
10use std::fmt;
11use std::ops::ControlFlow;
12
13use rustc_ast::visit::walk_list;
14use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
15use rustc_errors::ErrorGuaranteed;
16use rustc_hir::def::{DefKind, Res};
17use rustc_hir::def_id::LocalDefIdMap;
18use rustc_hir::definitions::{DefPathData, PerParentDisambiguatorsMap};
19use rustc_hir::intravisit::{self, InferKind, Visitor};
20use rustc_hir::{
21 self as hir, AmbigArg, GenericArg, GenericParam, GenericParamKind, HirId, LifetimeKind, Node,
22};
23use rustc_macros::extension;
24use rustc_middle::hir::nested_filter;
25use rustc_middle::middle::resolve_bound_vars::*;
26use rustc_middle::query::Providers;
27use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor, Unnormalized};
28use rustc_span::def_id::{DefId, LocalDefId};
29use rustc_span::{Ident, Span, bug, span_bug, sym};
30use tracing::{debug, debug_span, instrument};
31
32use crate::diagnostics;
33use crate::hir::definitions::PerParentDisambiguatorState;
34
35trait ResolvedArgExt {
fn early(param: &GenericParam<'_>)
-> ResolvedArg;
fn late(idx: u32, param: &GenericParam<'_>)
-> ResolvedArg;
fn id(&self)
-> Option<LocalDefId>;
fn shifted(self, amount: u32)
-> ResolvedArg;
}
impl ResolvedArgExt for ResolvedArg {
fn early(param: &GenericParam<'_>) -> ResolvedArg {
ResolvedArg::EarlyBound(param.def_id)
}
fn late(idx: u32, param: &GenericParam<'_>) -> ResolvedArg {
ResolvedArg::LateBound(ty::INNERMOST, idx, param.def_id)
}
fn id(&self) -> Option<LocalDefId> {
match *self {
ResolvedArg::StaticLifetime | ResolvedArg::Error(_) => None,
ResolvedArg::EarlyBound(id) | ResolvedArg::LateBound(_, _, id) |
ResolvedArg::Free(_, id) => Some(id),
}
}
fn shifted(self, amount: u32) -> ResolvedArg {
match self {
ResolvedArg::LateBound(debruijn, idx, id) => {
ResolvedArg::LateBound(debruijn.shifted_in(amount), idx, id)
}
_ => self,
}
}
}#[extension(trait ResolvedArgExt)]
36impl ResolvedArg {
37 fn early(param: &GenericParam<'_>) -> ResolvedArg {
38 ResolvedArg::EarlyBound(param.def_id)
39 }
40
41 fn late(idx: u32, param: &GenericParam<'_>) -> ResolvedArg {
42 ResolvedArg::LateBound(ty::INNERMOST, idx, param.def_id)
43 }
44
45 fn id(&self) -> Option<LocalDefId> {
46 match *self {
47 ResolvedArg::StaticLifetime | ResolvedArg::Error(_) => None,
48
49 ResolvedArg::EarlyBound(id)
50 | ResolvedArg::LateBound(_, _, id)
51 | ResolvedArg::Free(_, id) => Some(id),
52 }
53 }
54
55 fn shifted(self, amount: u32) -> ResolvedArg {
56 match self {
57 ResolvedArg::LateBound(debruijn, idx, id) => {
58 ResolvedArg::LateBound(debruijn.shifted_in(amount), idx, id)
59 }
60 _ => self,
61 }
62 }
63}
64
65struct BoundVarContext<'a, 'tcx> {
66 tcx: TyCtxt<'tcx>,
67 rbv: &'a mut ResolveBoundVars<'tcx>,
68 disambiguators: &'a mut LocalDefIdMap<PerParentDisambiguatorState>,
69 scope: ScopeRef<'a, 'tcx>,
70 opaque_capture_errors: RefCell<Option<OpaqueHigherRankedLifetimeCaptureErrors>>,
71}
72
73struct OpaqueHigherRankedLifetimeCaptureErrors {
74 bad_place: &'static str,
75 capture_spans: Vec<Span>,
76 decl_spans: Vec<Span>,
77}
78
79#[derive(#[automatically_derived]impl<'a, 'tcx> ::core::fmt::Debug for Scope<'a, 'tcx>
{
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Binder {
bound_vars: __self_0,
scope_type: __self_1,
hir_id: __self_2,
s: __self_3,
where_bound_origin: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"Binder bound_vars scope_type hir_id s where_bound_origin",
__self_0, __self_1, __self_2, __self_3, &__self_4),
Self::Body { id: __self_0, s: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Body id s", __self_0, &__self_1),
Self::ObjectLifetimeDefault { lifetime: __self_0, s: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ObjectLifetimeDefault lifetime s", __self_0, &__self_1),
Self::Supertrait { bound_vars: __self_0, s: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Supertrait bound_vars s", __self_0, &__self_1),
Self::TraitRefBoundary { s: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TraitRefBoundary s", &__self_0),
Self::Opaque { def_id: __self_0, captures: __self_1, s: __self_2 }
=>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Opaque def_id captures s", __self_0, __self_1, &__self_2),
Self::LateBoundary {
s: __self_0, what: __self_1, deny_late_regions: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"LateBoundary s what deny_late_regions", __self_0, __self_1,
&__self_2),
Self::Root { opt_parent_item: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Root opt_parent_item", &__self_0),
}
}
}Debug)]
80enum Scope<'a, 'tcx> {
81 Binder {
86 bound_vars: FxIndexMap<LocalDefId, ResolvedArg>,
89
90 scope_type: BinderScopeType,
91
92 hir_id: HirId,
97
98 s: ScopeRef<'a, 'tcx>,
99
100 where_bound_origin: Option<hir::PredicateOrigin>,
106 },
107
108 Body {
113 id: hir::BodyId,
114 s: ScopeRef<'a, 'tcx>,
115 },
116
117 ObjectLifetimeDefault {
121 lifetime: Option<ResolvedArg>,
122 s: ScopeRef<'a, 'tcx>,
123 },
124
125 Supertrait {
130 bound_vars: Vec<ty::BoundVariableKind<'tcx>>,
131 s: ScopeRef<'a, 'tcx>,
132 },
133
134 TraitRefBoundary {
135 s: ScopeRef<'a, 'tcx>,
136 },
137
138 Opaque {
147 def_id: LocalDefId,
149 captures: &'a RefCell<FxIndexMap<ResolvedArg, LocalDefId>>,
151
152 s: ScopeRef<'a, 'tcx>,
153 },
154
155 LateBoundary {
161 s: ScopeRef<'a, 'tcx>,
162 what: &'static str,
163 deny_late_regions: bool,
164 },
165
166 Root {
167 opt_parent_item: Option<LocalDefId>,
168 },
169}
170
171impl<'a, 'tcx> Scope<'a, 'tcx> {
172 fn debug_truncated(&self) -> impl fmt::Debug {
174 fmt::from_fn(move |f| match self {
175 Self::Binder { bound_vars, scope_type, hir_id, where_bound_origin, s: _ } => f
176 .debug_struct("Binder")
177 .field("bound_vars", bound_vars)
178 .field("scope_type", scope_type)
179 .field("hir_id", hir_id)
180 .field("where_bound_origin", where_bound_origin)
181 .field("s", &"..")
182 .finish(),
183 Self::Opaque { captures, def_id, s: _ } => f
184 .debug_struct("Opaque")
185 .field("def_id", def_id)
186 .field("captures", &captures.borrow())
187 .field("s", &"..")
188 .finish(),
189 Self::Body { id, s: _ } => {
190 f.debug_struct("Body").field("id", id).field("s", &"..").finish()
191 }
192 Self::ObjectLifetimeDefault { lifetime, s: _ } => f
193 .debug_struct("ObjectLifetimeDefault")
194 .field("lifetime", lifetime)
195 .field("s", &"..")
196 .finish(),
197 Self::Supertrait { bound_vars, s: _ } => f
198 .debug_struct("Supertrait")
199 .field("bound_vars", bound_vars)
200 .field("s", &"..")
201 .finish(),
202 Self::TraitRefBoundary { s: _ } => f.debug_struct("TraitRefBoundary").finish(),
203 Self::LateBoundary { s: _, what, deny_late_regions } => f
204 .debug_struct("LateBoundary")
205 .field("what", what)
206 .field("deny_late_regions", deny_late_regions)
207 .finish(),
208 Self::Root { opt_parent_item } => {
209 f.debug_struct("Root").field("opt_parent_item", &opt_parent_item).finish()
210 }
211 })
212 }
213}
214
215#[derive(#[automatically_derived]impl ::core::marker::Copy for BinderScopeType { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for BinderScopeType {
}
#[automatically_derived]impl ::core::clone::Clone for BinderScopeType {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for BinderScopeType {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
BinderScopeType::Normal => "Normal",
BinderScopeType::Concatenating => "Concatenating",
})
}
}Debug)]
216enum BinderScopeType {
217 Normal,
219 Concatenating,
229}
230
231type ScopeRef<'a, 'tcx> = &'a Scope<'a, 'tcx>;
232
233pub(crate) fn provide(providers: &mut Providers) {
235 *providers = Providers {
236 resolve_bound_vars,
237
238 named_variable_map: |tcx, id| &tcx.resolve_bound_vars(id).defs,
239 is_late_bound_map,
240 object_lifetime_default,
241 late_bound_vars_map: |tcx, id| &tcx.resolve_bound_vars(id).late_bound_vars,
242 opaque_captured_lifetimes: |tcx, id| {
243 &tcx.resolve_bound_vars(tcx.local_def_id_to_hir_id(id).owner)
244 .opaque_captured_lifetimes
245 .get(&id)
246 .map_or(&[][..], |x| &x[..])
247 },
248
249 ..*providers
250 };
251}
252
253{}
#[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("resolve_bound_vars",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(256u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("local_def_id")
}> =
::tracing::__macro_support::FieldName::new("local_def_id");
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(&local_def_id)
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: ResolveBoundVars<'_> = loop {};
return __tracing_attr_fake_return;
}
{
let mut rbv = ResolveBoundVars::default();
let mut visitor =
BoundVarContext {
tcx,
rbv: &mut rbv,
scope: &Scope::Root { opt_parent_item: None },
disambiguators: &mut Default::default(),
opaque_capture_errors: RefCell::new(None),
};
match tcx.hir_owner_node(local_def_id) {
hir::OwnerNode::Item(item) => visitor.visit_item(item),
hir::OwnerNode::ForeignItem(item) =>
visitor.visit_foreign_item(item),
hir::OwnerNode::TraitItem(item) => {
let scope =
Scope::Root {
opt_parent_item: Some(tcx.local_parent(item.owner_id.def_id)),
};
visitor.scope = &scope;
visitor.visit_trait_item(item)
}
hir::OwnerNode::ImplItem(item) => {
let scope =
Scope::Root {
opt_parent_item: Some(tcx.local_parent(item.owner_id.def_id)),
};
visitor.scope = &scope;
visitor.visit_impl_item(item)
}
hir::OwnerNode::Crate(_) => {}
hir::OwnerNode::Synthetic =>
::core::panicking::unreachable_default_msg(),
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:285",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(285u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rbv.defs")
}> =
::tracing::__macro_support::FieldName::new("rbv.defs");
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(&rbv.defs)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:286",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(286u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rbv.late_bound_vars")
}> =
::tracing::__macro_support::FieldName::new("rbv.late_bound_vars");
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(&rbv.late_bound_vars)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:287",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(287u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rbv.opaque_captured_lifetimes")
}> =
::tracing::__macro_support::FieldName::new("rbv.opaque_captured_lifetimes");
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(&rbv.opaque_captured_lifetimes)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
rbv
}
}
}#[instrument(level = "debug", skip(tcx))]
257fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBoundVars<'_> {
258 let mut rbv = ResolveBoundVars::default();
259 let mut visitor = BoundVarContext {
260 tcx,
261 rbv: &mut rbv,
262 scope: &Scope::Root { opt_parent_item: None },
263 disambiguators: &mut Default::default(),
264 opaque_capture_errors: RefCell::new(None),
265 };
266 match tcx.hir_owner_node(local_def_id) {
267 hir::OwnerNode::Item(item) => visitor.visit_item(item),
268 hir::OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
269 hir::OwnerNode::TraitItem(item) => {
270 let scope =
271 Scope::Root { opt_parent_item: Some(tcx.local_parent(item.owner_id.def_id)) };
272 visitor.scope = &scope;
273 visitor.visit_trait_item(item)
274 }
275 hir::OwnerNode::ImplItem(item) => {
276 let scope =
277 Scope::Root { opt_parent_item: Some(tcx.local_parent(item.owner_id.def_id)) };
278 visitor.scope = &scope;
279 visitor.visit_impl_item(item)
280 }
281 hir::OwnerNode::Crate(_) => {}
282 hir::OwnerNode::Synthetic => unreachable!(),
283 }
284
285 debug!(?rbv.defs);
286 debug!(?rbv.late_bound_vars);
287 debug!(?rbv.opaque_captured_lifetimes);
288 rbv
289}
290
291fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableKind<'tcx> {
292 let def_id = param.def_id.to_def_id();
293 match param.kind {
294 GenericParamKind::Lifetime { .. } => {
295 ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
296 }
297 GenericParamKind::Type { .. } => ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)),
298 GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
299 }
300}
301
302fn generic_param_def_as_bound_arg<'tcx>(
306 param: &ty::GenericParamDef,
307) -> ty::BoundVariableKind<'tcx> {
308 match param.kind {
309 ty::GenericParamDefKind::Lifetime => {
310 ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id))
311 }
312 ty::GenericParamDefKind::Type { .. } => {
313 ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id))
314 }
315 ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
316 }
317}
318
319fn opaque_captures_all_in_scope_lifetimes<'tcx>(opaque: &'tcx hir::OpaqueTy<'tcx>) -> bool {
323 match opaque.origin {
324 _ if opaque.bounds.iter().any(|bound| #[allow(non_exhaustive_omitted_patterns)] match bound {
hir::GenericBound::Use(..) => true,
_ => false,
}matches!(bound, hir::GenericBound::Use(..))) => false,
327 hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => true,
328 _ if opaque.span.at_least_rust_2024() => true,
329 hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => in_trait_or_impl.is_some(),
330 }
331}
332
333impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
334 fn poly_trait_ref_binder_info(
336 &mut self,
337 ) -> (Vec<ty::BoundVariableKind<'tcx>>, BinderScopeType) {
338 let mut scope = self.scope;
339 let mut supertrait_bound_vars = ::alloc::vec::Vec::new()vec![];
340 loop {
341 match scope {
342 Scope::Body { .. } | Scope::Root { .. } => {
343 break (::alloc::vec::Vec::new()vec![], BinderScopeType::Normal);
344 }
345
346 Scope::Opaque { s, .. }
347 | Scope::ObjectLifetimeDefault { s, .. }
348 | Scope::LateBoundary { s, .. } => {
349 scope = s;
350 }
351
352 Scope::Supertrait { s, bound_vars } => {
353 supertrait_bound_vars = bound_vars.clone();
354 scope = s;
355 }
356
357 Scope::TraitRefBoundary { .. } => {
358 if !supertrait_bound_vars.is_empty() {
362 self.tcx.dcx().delayed_bug(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("found supertrait lifetimes without a binder to append them to: {0:?}",
supertrait_bound_vars))
})format!(
363 "found supertrait lifetimes without a binder to append \
364 them to: {supertrait_bound_vars:?}"
365 ));
366 }
367 break (::alloc::vec::Vec::new()vec![], BinderScopeType::Normal);
368 }
369
370 Scope::Binder { hir_id, .. } => {
371 let mut full_binders: Vec<ty::BoundVariableKind<'tcx>> =
373 self.rbv.late_bound_vars.get_mut_or_insert_default(hir_id.local_id).clone();
374 full_binders.extend(supertrait_bound_vars);
375 break (full_binders, BinderScopeType::Concatenating);
376 }
377 }
378 }
379 }
380
381 fn visit_poly_trait_ref_inner(
382 &mut self,
383 trait_ref: &'tcx hir::PolyTraitRef<'tcx>,
384 non_lifetime_binder_allowed: NonLifetimeBinderAllowed,
385 ) {
386 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:386",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(386u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit_poly_trait_ref(trait_ref={0:?})",
trait_ref) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
387
388 let (mut binders, scope_type) = self.poly_trait_ref_binder_info();
389
390 let initial_bound_vars = binders.len() as u32;
391 let mut bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = FxIndexMap::default();
392 let binders_iter =
393 trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
394 let arg = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
395 bound_vars.insert(param.def_id, arg);
396 late_arg_as_bound_arg(param)
397 });
398 binders.extend(binders_iter);
399
400 if let NonLifetimeBinderAllowed::Deny(where_) = non_lifetime_binder_allowed {
401 deny_non_region_late_bound(self.tcx, &mut bound_vars, where_);
402 }
403
404 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:404",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(404u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("binders")
}> =
::tracing::__macro_support::FieldName::new("binders");
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(&binders)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?binders);
405 self.record_late_bound_vars(trait_ref.trait_ref.hir_ref_id, binders);
406
407 let scope = Scope::Binder {
412 hir_id: trait_ref.trait_ref.hir_ref_id,
413 bound_vars,
414 s: self.scope,
415 scope_type,
416 where_bound_origin: None,
417 };
418 self.with(scope, |this| {
419 for elem in trait_ref.bound_generic_params {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_generic_param(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
420 this.visit_trait_ref(&trait_ref.trait_ref);
421 });
422 }
423}
424
425enum NonLifetimeBinderAllowed {
426 Deny(&'static str),
427 Allow,
428}
429
430impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
431 type NestedFilter = nested_filter::OnlyBodies;
432
433 fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
434 self.tcx
435 }
436
437 fn visit_nested_body(&mut self, body: hir::BodyId) {
438 let body = self.tcx.hir_body(body);
439 self.with(Scope::Body { id: body.id(), s: self.scope }, |this| {
440 this.visit_body(body);
441 });
442 }
443
444 fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
445 if let hir::ExprKind::Closure(hir::Closure {
446 binder, bound_generic_params, fn_decl, ..
447 }) = e.kind
448 {
449 if let &hir::ClosureBinder::For { span: for_sp, .. } = binder {
450 fn span_of_infer(ty: &hir::Ty<'_>) -> Option<Span> {
451 struct FindInferInClosureWithBinder;
454 impl<'v> Visitor<'v> for FindInferInClosureWithBinder {
455 type Result = ControlFlow<Span>;
456
457 fn visit_infer(
458 &mut self,
459 _inf_id: HirId,
460 inf_span: Span,
461 _kind: InferKind<'v>,
462 ) -> Self::Result {
463 ControlFlow::Break(inf_span)
464 }
465 }
466 FindInferInClosureWithBinder.visit_ty_unambig(ty).break_value()
467 }
468
469 let infer_in_rt_sp = match fn_decl.output {
470 hir::FnRetTy::DefaultReturn(sp) => Some(sp),
471 hir::FnRetTy::Return(ty) => span_of_infer(ty),
472 };
473
474 let infer_spans = fn_decl
475 .inputs
476 .into_iter()
477 .filter_map(span_of_infer)
478 .chain(infer_in_rt_sp)
479 .collect::<Vec<_>>();
480
481 if !infer_spans.is_empty() {
482 self.tcx
483 .dcx()
484 .emit_err(diagnostics::ClosureImplicitHrtb { spans: infer_spans, for_sp });
485 }
486 }
487
488 let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
489 bound_generic_params
490 .iter()
491 .enumerate()
492 .map(|(late_bound_idx, param)| {
493 (
494 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
495 late_arg_as_bound_arg(param),
496 )
497 })
498 .unzip();
499
500 deny_non_region_late_bound(self.tcx, &mut bound_vars, "closures");
501
502 self.record_late_bound_vars(e.hir_id, binders);
503 let scope = Scope::Binder {
504 hir_id: e.hir_id,
505 bound_vars,
506 s: self.scope,
507 scope_type: BinderScopeType::Normal,
508 where_bound_origin: None,
509 };
510
511 self.with(scope, |this| {
512 intravisit::walk_expr(this, e)
515 });
516 } else {
517 intravisit::walk_expr(self, e)
518 }
519 }
520
521 {}
#[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("visit_opaque_ty",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(526u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("opaque")
}> =
::tracing::__macro_support::FieldName::new("opaque");
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(&opaque)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let captures = RefCell::new(FxIndexMap::default());
let capture_all_in_scope_lifetimes =
opaque_captures_all_in_scope_lifetimes(opaque);
if capture_all_in_scope_lifetimes {
let tcx = self.tcx;
let lifetime_ident =
|def_id: LocalDefId|
{
let name = tcx.item_name(def_id.to_def_id());
let span = tcx.def_span(def_id);
Ident::new(name, span)
};
let mut late_depth = 0;
let mut scope = self.scope;
let mut opaque_capture_scopes =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(opaque.def_id, &captures)]));
loop {
match *scope {
Scope::Binder { ref bound_vars, scope_type, s, .. } => {
for (&original_lifetime, &def) in bound_vars.iter().rev() {
if let DefKind::LifetimeParam =
self.tcx.def_kind(original_lifetime) {
let def = def.shifted(late_depth);
let ident = lifetime_ident(original_lifetime);
self.remap_opaque_captures(&opaque_capture_scopes, def,
ident);
}
}
match scope_type {
BinderScopeType::Normal => late_depth += 1,
BinderScopeType::Concatenating => {}
}
scope = s;
}
Scope::Root { mut opt_parent_item } => {
while let Some(parent_item) = opt_parent_item {
let parent_generics = self.tcx.generics_of(parent_item);
for param in parent_generics.own_params.iter().rev() {
if let ty::GenericParamDefKind::Lifetime = param.kind {
let def =
ResolvedArg::EarlyBound(param.def_id.expect_local());
let ident = lifetime_ident(param.def_id.expect_local());
self.remap_opaque_captures(&opaque_capture_scopes, def,
ident);
}
}
opt_parent_item =
parent_generics.parent.and_then(DefId::as_local);
}
break;
}
Scope::Opaque { captures, def_id, s } => {
opaque_capture_scopes.push((def_id, captures));
late_depth = 0;
scope = s;
}
Scope::Body { .. } => {
::rustc_span::macros::bug_impl(None,
format_args!("{0:?}", scope), Location::caller())
}
Scope::ObjectLifetimeDefault { s, .. } | Scope::Supertrait {
s, .. } | Scope::TraitRefBoundary { s, .. } |
Scope::LateBoundary { s, .. } => {
scope = s;
}
}
}
captures.borrow_mut().reverse();
}
let scope =
Scope::Opaque {
captures: &captures,
def_id: opaque.def_id,
s: self.scope,
};
self.with(scope,
|this|
{
let scope = Scope::TraitRefBoundary { s: this.scope };
this.with(scope,
|this|
{
let scope =
Scope::LateBoundary {
s: this.scope,
what: "nested `impl Trait`",
deny_late_regions: false,
};
this.with(scope,
|this| intravisit::walk_opaque_ty(this, opaque))
})
});
self.emit_opaque_capture_errors();
let captures = captures.into_inner().into_iter().collect();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:616",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(616u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("captures")
}> =
::tracing::__macro_support::FieldName::new("captures");
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(&captures)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.rbv.opaque_captured_lifetimes.insert(opaque.def_id,
captures);
}
}
}#[instrument(level = "debug", skip(self))]
527 fn visit_opaque_ty(&mut self, opaque: &'tcx rustc_hir::OpaqueTy<'tcx>) {
528 let captures = RefCell::new(FxIndexMap::default());
529
530 let capture_all_in_scope_lifetimes = opaque_captures_all_in_scope_lifetimes(opaque);
531 if capture_all_in_scope_lifetimes {
532 let tcx = self.tcx;
533 let lifetime_ident = |def_id: LocalDefId| {
534 let name = tcx.item_name(def_id.to_def_id());
535 let span = tcx.def_span(def_id);
536 Ident::new(name, span)
537 };
538
539 let mut late_depth = 0;
543 let mut scope = self.scope;
544 let mut opaque_capture_scopes = vec![(opaque.def_id, &captures)];
545 loop {
546 match *scope {
547 Scope::Binder { ref bound_vars, scope_type, s, .. } => {
548 for (&original_lifetime, &def) in bound_vars.iter().rev() {
549 if let DefKind::LifetimeParam = self.tcx.def_kind(original_lifetime) {
550 let def = def.shifted(late_depth);
551 let ident = lifetime_ident(original_lifetime);
552 self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
553 }
554 }
555 match scope_type {
556 BinderScopeType::Normal => late_depth += 1,
557 BinderScopeType::Concatenating => {}
558 }
559 scope = s;
560 }
561
562 Scope::Root { mut opt_parent_item } => {
563 while let Some(parent_item) = opt_parent_item {
564 let parent_generics = self.tcx.generics_of(parent_item);
565 for param in parent_generics.own_params.iter().rev() {
566 if let ty::GenericParamDefKind::Lifetime = param.kind {
567 let def = ResolvedArg::EarlyBound(param.def_id.expect_local());
568 let ident = lifetime_ident(param.def_id.expect_local());
569 self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
570 }
571 }
572 opt_parent_item = parent_generics.parent.and_then(DefId::as_local);
573 }
574 break;
575 }
576
577 Scope::Opaque { captures, def_id, s } => {
578 opaque_capture_scopes.push((def_id, captures));
579 late_depth = 0;
580 scope = s;
581 }
582
583 Scope::Body { .. } => {
584 bug!("{:?}", scope)
585 }
586
587 Scope::ObjectLifetimeDefault { s, .. }
588 | Scope::Supertrait { s, .. }
589 | Scope::TraitRefBoundary { s, .. }
590 | Scope::LateBoundary { s, .. } => {
591 scope = s;
592 }
593 }
594 }
595 captures.borrow_mut().reverse();
596 }
597
598 let scope = Scope::Opaque { captures: &captures, def_id: opaque.def_id, s: self.scope };
599 self.with(scope, |this| {
600 let scope = Scope::TraitRefBoundary { s: this.scope };
601 this.with(scope, |this| {
602 let scope = Scope::LateBoundary {
603 s: this.scope,
604 what: "nested `impl Trait`",
605 deny_late_regions: false,
608 };
609 this.with(scope, |this| intravisit::walk_opaque_ty(this, opaque))
610 })
611 });
612
613 self.emit_opaque_capture_errors();
614
615 let captures = captures.into_inner().into_iter().collect();
616 debug!(?captures);
617 self.rbv.opaque_captured_lifetimes.insert(opaque.def_id, captures);
618 }
619
620 {}
#[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("visit_item",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(620u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item")
}> =
::tracing::__macro_support::FieldName::new("item");
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(&item)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
if let hir::ItemKind::Impl(impl_) = item.kind &&
let Some(of_trait) = impl_.of_trait {
self.record_late_bound_vars(of_trait.trait_ref.hir_ref_id,
Vec::default());
}
match item.kind {
hir::ItemKind::Fn { generics, .. } => {
self.visit_early_late(item.hir_id(), generics,
|this| { intravisit::walk_item(this, item); });
}
hir::ItemKind::ExternCrate(..) | hir::ItemKind::Use(..) |
hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) |
hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Static(..)
| hir::ItemKind::GlobalAsm { .. } => {
intravisit::walk_item(self, item);
}
hir::ItemKind::TyAlias(_, generics, _) |
hir::ItemKind::Const(_, generics, _, _) |
hir::ItemKind::Enum(_, generics, _) |
hir::ItemKind::Struct(_, generics, _) |
hir::ItemKind::Union(_, generics, _) |
hir::ItemKind::Trait { generics, .. } |
hir::ItemKind::TraitAlias(_, _, generics, ..) |
hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
self.visit_early(item.hir_id(), generics,
|this| intravisit::walk_item(this, item));
}
hir::ItemKind::TestBinderConstraints { generics, body } => {
self.visit_test_binder_constraints(item.hir_id(), generics,
body)
}
}
}
}
}#[instrument(level = "debug", skip(self))]
621 fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
622 if let hir::ItemKind::Impl(impl_) = item.kind
623 && let Some(of_trait) = impl_.of_trait
624 {
625 self.record_late_bound_vars(of_trait.trait_ref.hir_ref_id, Vec::default());
626 }
627 match item.kind {
628 hir::ItemKind::Fn { generics, .. } => {
629 self.visit_early_late(item.hir_id(), generics, |this| {
630 intravisit::walk_item(this, item);
631 });
632 }
633
634 hir::ItemKind::ExternCrate(..)
635 | hir::ItemKind::Use(..)
636 | hir::ItemKind::Macro(..)
637 | hir::ItemKind::Mod(..)
638 | hir::ItemKind::ForeignMod { .. }
639 | hir::ItemKind::Static(..)
640 | hir::ItemKind::GlobalAsm { .. } => {
641 intravisit::walk_item(self, item);
643 }
644 hir::ItemKind::TyAlias(_, generics, _)
645 | hir::ItemKind::Const(_, generics, _, _)
646 | hir::ItemKind::Enum(_, generics, _)
647 | hir::ItemKind::Struct(_, generics, _)
648 | hir::ItemKind::Union(_, generics, _)
649 | hir::ItemKind::Trait { generics, .. }
650 | hir::ItemKind::TraitAlias(_, _, generics, ..)
651 | hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
652 self.visit_early(item.hir_id(), generics, |this| intravisit::walk_item(this, item));
654 }
655 hir::ItemKind::TestBinderConstraints { generics, body } => {
656 self.visit_test_binder_constraints(item.hir_id(), generics, body)
657 }
658 }
659 }
660
661 fn visit_precise_capturing_arg(
662 &mut self,
663 arg: &'tcx hir::PreciseCapturingArg<'tcx>,
664 ) -> Self::Result {
665 match *arg {
666 hir::PreciseCapturingArg::Lifetime(lt) => match lt.kind {
667 LifetimeKind::Param(def_id) => {
668 self.resolve_lifetime_ref(def_id, lt);
669 }
670 LifetimeKind::Error(..) => {}
671 LifetimeKind::ImplicitObjectLifetimeDefault
672 | LifetimeKind::Infer
673 | LifetimeKind::Static => {
674 self.tcx.dcx().emit_err(diagnostics::BadPreciseCapture {
675 span: lt.ident.span,
676 kind: "lifetime",
677 found: ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", lt.ident.name))
})format!("`{}`", lt.ident.name),
678 });
679 }
680 },
681 hir::PreciseCapturingArg::Param(param) => match param.res {
682 Res::Def(DefKind::TyParam | DefKind::ConstParam, def_id)
683 | Res::SelfTyParam { trait_: def_id } => {
684 self.resolve_type_ref(def_id.expect_local(), param.hir_id);
685 }
686 Res::SelfTyAlias { alias_to, .. } => {
687 self.tcx.dcx().emit_err(diagnostics::PreciseCaptureSelfAlias {
688 span: param.ident.span,
689 self_span: self.tcx.def_span(alias_to),
690 what: self.tcx.def_descr(alias_to),
691 });
692 }
693 res => {
694 self.tcx.dcx().span_delayed_bug(
695 param.ident.span,
696 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected type or const param, found {0:?}",
res))
})format!("expected type or const param, found {res:?}"),
697 );
698 }
699 },
700 }
701 }
702
703 fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
704 match item.kind {
705 hir::ForeignItemKind::Fn(_, _, generics) => {
706 self.visit_early_late(item.hir_id(), generics, |this| {
707 intravisit::walk_foreign_item(this, item);
708 })
709 }
710 hir::ForeignItemKind::Static(..) => {
711 intravisit::walk_foreign_item(self, item);
712 }
713 hir::ForeignItemKind::Type => {
714 intravisit::walk_foreign_item(self, item);
715 }
716 }
717 }
718
719 {}
#[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("visit_ty",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(719u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
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(&ty)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
match ty.kind {
hir::TyKind::FnPtr(c) => {
let (mut bound_vars, binders):
(FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
c.generic_params.iter().enumerate().map(|(late_bound_idx,
param)|
{
((param.def_id,
ResolvedArg::late(late_bound_idx as u32, param)),
late_arg_as_bound_arg(param))
}).unzip();
deny_non_region_late_bound(self.tcx, &mut bound_vars,
"function pointer types");
self.record_late_bound_vars(ty.hir_id, binders);
let scope =
Scope::Binder {
hir_id: ty.hir_id,
bound_vars,
s: self.scope,
scope_type: BinderScopeType::Normal,
where_bound_origin: None,
};
self.with(scope, |this| { intravisit::walk_ty(this, ty); });
}
hir::TyKind::UnsafeBinder(binder) => {
let (mut bound_vars, binders):
(FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
binder.generic_params.iter().enumerate().map(|(late_bound_idx,
param)|
{
((param.def_id,
ResolvedArg::late(late_bound_idx as u32, param)),
late_arg_as_bound_arg(param))
}).unzip();
deny_non_region_late_bound(self.tcx, &mut bound_vars,
"function pointer types");
self.record_late_bound_vars(ty.hir_id, binders);
let scope =
Scope::Binder {
hir_id: ty.hir_id,
bound_vars,
s: self.scope,
scope_type: BinderScopeType::Normal,
where_bound_origin: None,
};
self.with(scope, |this| { intravisit::walk_ty(this, ty); });
}
hir::TyKind::TraitObject(bounds, lifetime) => {
let lifetime = lifetime.pointer();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:782",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(782u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bounds")
}> =
::tracing::__macro_support::FieldName::new("bounds");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime")
}> =
::tracing::__macro_support::FieldName::new("lifetime");
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(&format_args!("TraitObject")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bounds)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let scope = Scope::TraitRefBoundary { s: self.scope };
self.with(scope,
|this|
{
for bound in bounds {
this.visit_poly_trait_ref_inner(bound,
NonLifetimeBinderAllowed::Deny("trait object types"));
}
});
match lifetime.kind {
LifetimeKind::ImplicitObjectLifetimeDefault => {
self.resolve_object_lifetime_default(&*lifetime);
}
LifetimeKind::Infer => {}
LifetimeKind::Param(..) | LifetimeKind::Static => {
self.visit_lifetime(&*lifetime);
}
LifetimeKind::Error(..) => {}
}
}
hir::TyKind::Ref(lifetime_ref, ref inner_ty, _) => {
self.visit_lifetime(lifetime_ref);
let scope =
Scope::ObjectLifetimeDefault {
lifetime: self.rbv.defs.get(&lifetime_ref.hir_id.local_id).copied(),
s: self.scope,
};
self.with(scope, |this| this.visit_ty_unambig(inner_ty));
}
hir::TyKind::TraitAscription(bounds) => {
let scope = Scope::TraitRefBoundary { s: self.scope };
self.with(scope,
|this|
{
let scope =
Scope::LateBoundary {
s: this.scope,
what: "`impl Trait` in binding",
deny_late_regions: true,
};
this.with(scope,
|this|
{ for bound in bounds { this.visit_param_bound(bound); } })
});
}
_ => intravisit::walk_ty(self, ty),
}
}
}
}#[instrument(level = "debug", skip(self))]
720 fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
721 match ty.kind {
722 hir::TyKind::FnPtr(c) => {
723 let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) = c
724 .generic_params
725 .iter()
726 .enumerate()
727 .map(|(late_bound_idx, param)| {
728 (
729 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
730 late_arg_as_bound_arg(param),
731 )
732 })
733 .unzip();
734
735 deny_non_region_late_bound(self.tcx, &mut bound_vars, "function pointer types");
736
737 self.record_late_bound_vars(ty.hir_id, binders);
738 let scope = Scope::Binder {
739 hir_id: ty.hir_id,
740 bound_vars,
741 s: self.scope,
742 scope_type: BinderScopeType::Normal,
743 where_bound_origin: None,
744 };
745 self.with(scope, |this| {
746 intravisit::walk_ty(this, ty);
748 });
749 }
750 hir::TyKind::UnsafeBinder(binder) => {
751 let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
752 binder
753 .generic_params
754 .iter()
755 .enumerate()
756 .map(|(late_bound_idx, param)| {
757 (
758 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
759 late_arg_as_bound_arg(param),
760 )
761 })
762 .unzip();
763
764 deny_non_region_late_bound(self.tcx, &mut bound_vars, "function pointer types");
765
766 self.record_late_bound_vars(ty.hir_id, binders);
767 let scope = Scope::Binder {
768 hir_id: ty.hir_id,
769 bound_vars,
770 s: self.scope,
771 scope_type: BinderScopeType::Normal,
772 where_bound_origin: None,
773 };
774 self.with(scope, |this| {
775 intravisit::walk_ty(this, ty);
777 });
778 }
779 hir::TyKind::TraitObject(bounds, lifetime) => {
780 let lifetime = lifetime.pointer();
781
782 debug!(?bounds, ?lifetime, "TraitObject");
783 let scope = Scope::TraitRefBoundary { s: self.scope };
784 self.with(scope, |this| {
785 for bound in bounds {
786 this.visit_poly_trait_ref_inner(
787 bound,
788 NonLifetimeBinderAllowed::Deny("trait object types"),
789 );
790 }
791 });
792 match lifetime.kind {
793 LifetimeKind::ImplicitObjectLifetimeDefault => {
794 self.resolve_object_lifetime_default(&*lifetime);
798 }
799 LifetimeKind::Infer => {
800 }
806 LifetimeKind::Param(..) | LifetimeKind::Static => {
807 self.visit_lifetime(&*lifetime);
809 }
810 LifetimeKind::Error(..) => {}
811 }
812 }
813 hir::TyKind::Ref(lifetime_ref, ref inner_ty, _) => {
814 self.visit_lifetime(lifetime_ref);
815 let scope = Scope::ObjectLifetimeDefault {
816 lifetime: self.rbv.defs.get(&lifetime_ref.hir_id.local_id).copied(),
817 s: self.scope,
818 };
819 self.with(scope, |this| this.visit_ty_unambig(inner_ty));
820 }
821 hir::TyKind::TraitAscription(bounds) => {
822 let scope = Scope::TraitRefBoundary { s: self.scope };
823 self.with(scope, |this| {
824 let scope = Scope::LateBoundary {
825 s: this.scope,
826 what: "`impl Trait` in binding",
827 deny_late_regions: true,
828 };
829 this.with(scope, |this| {
830 for bound in bounds {
831 this.visit_param_bound(bound);
832 }
833 })
834 });
835 }
836 _ => intravisit::walk_ty(self, ty),
837 }
838 }
839
840 {}
#[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("visit_pattern_type_pattern",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(840u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("p")
}> =
::tracing::__macro_support::FieldName::new("p");
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(&p)
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: () = loop {};
return __tracing_attr_fake_return;
}
{ intravisit::walk_ty_pat(self, p) }
}
}#[instrument(level = "debug", skip(self))]
841 fn visit_pattern_type_pattern(&mut self, p: &'tcx hir::TyPat<'tcx>) {
842 intravisit::walk_ty_pat(self, p)
843 }
844
845 {}
#[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("visit_trait_item",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(845u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_item")
}> =
::tracing::__macro_support::FieldName::new("trait_item");
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(&trait_item)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
use self::hir::TraitItemKind::*;
match trait_item.kind {
Fn(_, _) => {
self.visit_early_late(trait_item.hir_id(),
trait_item.generics,
|this| { intravisit::walk_trait_item(this, trait_item) });
}
Type(bounds, ty) => {
self.visit_early(trait_item.hir_id(), trait_item.generics,
|this|
{
this.visit_generics(trait_item.generics);
for bound in bounds { this.visit_param_bound(bound); }
if let Some(ty) = ty { this.visit_ty_unambig(ty); }
})
}
Const(_, _) =>
self.visit_early(trait_item.hir_id(), trait_item.generics,
|this| { intravisit::walk_trait_item(this, trait_item) }),
}
}
}
}#[instrument(level = "debug", skip(self))]
846 fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
847 use self::hir::TraitItemKind::*;
848 match trait_item.kind {
849 Fn(_, _) => {
850 self.visit_early_late(trait_item.hir_id(), trait_item.generics, |this| {
851 intravisit::walk_trait_item(this, trait_item)
852 });
853 }
854 Type(bounds, ty) => {
855 self.visit_early(trait_item.hir_id(), trait_item.generics, |this| {
856 this.visit_generics(trait_item.generics);
857 for bound in bounds {
858 this.visit_param_bound(bound);
859 }
860 if let Some(ty) = ty {
861 this.visit_ty_unambig(ty);
862 }
863 })
864 }
865 Const(_, _) => self.visit_early(trait_item.hir_id(), trait_item.generics, |this| {
866 intravisit::walk_trait_item(this, trait_item)
867 }),
868 }
869 }
870
871 {}
#[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("visit_impl_item",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(871u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_item")
}> =
::tracing::__macro_support::FieldName::new("impl_item");
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(&impl_item)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
use self::hir::ImplItemKind::*;
match impl_item.kind {
Fn(..) =>
self.visit_early_late(impl_item.hir_id(),
impl_item.generics,
|this| { intravisit::walk_impl_item(this, impl_item) }),
Type(ty) =>
self.visit_early(impl_item.hir_id(), impl_item.generics,
|this|
{
this.visit_generics(impl_item.generics);
this.visit_ty_unambig(ty);
}),
Const(_, _) =>
self.visit_early(impl_item.hir_id(), impl_item.generics,
|this| { intravisit::walk_impl_item(this, impl_item) }),
}
}
}
}#[instrument(level = "debug", skip(self))]
872 fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
873 use self::hir::ImplItemKind::*;
874 match impl_item.kind {
875 Fn(..) => self.visit_early_late(impl_item.hir_id(), impl_item.generics, |this| {
876 intravisit::walk_impl_item(this, impl_item)
877 }),
878 Type(ty) => self.visit_early(impl_item.hir_id(), impl_item.generics, |this| {
879 this.visit_generics(impl_item.generics);
880 this.visit_ty_unambig(ty);
881 }),
882 Const(_, _) => self.visit_early(impl_item.hir_id(), impl_item.generics, |this| {
883 intravisit::walk_impl_item(this, impl_item)
884 }),
885 }
886 }
887
888 {}
#[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("visit_lifetime",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(888u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime_ref")
}> =
::tracing::__macro_support::FieldName::new("lifetime_ref");
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(&lifetime_ref)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
match lifetime_ref.kind {
hir::LifetimeKind::Static => {
self.insert_lifetime(lifetime_ref,
ResolvedArg::StaticLifetime)
}
hir::LifetimeKind::Param(param_def_id) => {
self.resolve_lifetime_ref(param_def_id, lifetime_ref)
}
hir::LifetimeKind::Error(guar) => {
self.insert_lifetime(lifetime_ref, ResolvedArg::Error(guar))
}
hir::LifetimeKind::ImplicitObjectLifetimeDefault |
hir::LifetimeKind::Infer => {}
}
}
}
}#[instrument(level = "debug", skip(self))]
889 fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
890 match lifetime_ref.kind {
891 hir::LifetimeKind::Static => {
892 self.insert_lifetime(lifetime_ref, ResolvedArg::StaticLifetime)
893 }
894 hir::LifetimeKind::Param(param_def_id) => {
895 self.resolve_lifetime_ref(param_def_id, lifetime_ref)
896 }
897 hir::LifetimeKind::Error(guar) => {
899 self.insert_lifetime(lifetime_ref, ResolvedArg::Error(guar))
900 }
901 hir::LifetimeKind::ImplicitObjectLifetimeDefault | hir::LifetimeKind::Infer => {}
903 }
904 }
905
906 fn visit_qpath(&mut self, qpath: &'tcx hir::QPath<'tcx>, id: HirId, _: Span) {
907 match qpath {
908 hir::QPath::Resolved(maybe_qself, path) => {
909 self.visit_path(path, id);
913 if let Some(qself) = maybe_qself {
914 let container =
915 self.eligible_container(path, RevSegIdx(1).reverse(path.segments));
916
917 let object_lifetime_defaults =
918 container.map_or(Vec::new(), |(def_id, segs)| {
919 let generics = self.tcx.generics_of(def_id);
920 self.compute_object_lifetime_defaults(generics, segs)
921 });
922
923 if let Some(<) = object_lifetime_defaults.first() {
924 let scope = Scope::ObjectLifetimeDefault { lifetime: lt, s: self.scope };
925 self.with(scope, |this| this.visit_ty_unambig(qself));
926 } else {
927 self.visit_ty_unambig(qself);
928 }
929 }
930 }
931 hir::QPath::TypeRelative(qself, segment) => {
932 let scope = Scope::ObjectLifetimeDefault { lifetime: None, s: self.scope };
942 self.with(scope, |this| {
943 this.visit_ty_unambig(qself);
944 this.visit_path_segment(segment)
945 });
946 }
947 }
948 }
949
950 fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) {
951 for (index, segment) in path.segments.iter().enumerate() {
952 if let Some(args) = segment.args {
953 self.visit_path_segment_args(args, SegIdx(index), path);
954 }
955 }
956 if let Res::Def(DefKind::TyParam | DefKind::ConstParam, param_def_id) = path.res {
957 self.resolve_type_ref(param_def_id.expect_local(), hir_id);
958 }
959 }
960
961 fn visit_fn(
962 &mut self,
963 fk: intravisit::FnKind<'tcx>,
964 fd: &'tcx hir::FnDecl<'tcx>,
965 body_id: hir::BodyId,
966 _: Span,
967 def_id: LocalDefId,
968 ) {
969 let output = match fd.output {
970 hir::FnRetTy::DefaultReturn(_) => None,
971 hir::FnRetTy::Return(ty) => Some(ty),
972 };
973 if let Some(ty) = output
974 && let hir::TyKind::InferDelegation(hir::InferDelegation::Sig(sig_id, _)) = ty.kind
975 {
976 let bound_vars: Vec<_> =
977 self.tcx.fn_sig(sig_id).skip_binder().bound_vars().iter().collect();
978 let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
979 self.rbv.late_bound_vars.insert(hir_id.local_id, bound_vars);
980 }
981 self.visit_fn_like_elision(fd.inputs, output, #[allow(non_exhaustive_omitted_patterns)] match fk {
intravisit::FnKind::Closure => true,
_ => false,
}matches!(fk, intravisit::FnKind::Closure));
982 intravisit::walk_fn_kind(self, fk);
983 self.visit_nested_body(body_id)
984 }
985
986 fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
987 let scope = Scope::TraitRefBoundary { s: self.scope };
988 self.with(scope, |this| {
989 for elem in generics.params {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_generic_param(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(this, visit_generic_param, generics.params);
990 for elem in generics.predicates {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_where_predicate(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(this, visit_where_predicate, generics.predicates);
991 })
992 }
993
994 fn visit_where_predicate(&mut self, predicate: &'tcx hir::WherePredicate<'tcx>) {
995 let hir_id = predicate.hir_id;
996 match predicate.kind {
997 &hir::WherePredicateKind::BoundPredicate(hir::WhereBoundPredicate {
998 bounded_ty,
999 bounds,
1000 bound_generic_params,
1001 origin,
1002 ..
1003 }) => {
1004 let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
1005 bound_generic_params
1006 .iter()
1007 .enumerate()
1008 .map(|(late_bound_idx, param)| {
1009 (
1010 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
1011 late_arg_as_bound_arg(param),
1012 )
1013 })
1014 .unzip();
1015
1016 self.record_late_bound_vars(hir_id, binders);
1017
1018 self.try_append_return_type_notation_params(hir_id, bounded_ty);
1020
1021 let scope = Scope::Binder {
1026 hir_id,
1027 bound_vars,
1028 s: self.scope,
1029 scope_type: BinderScopeType::Normal,
1030 where_bound_origin: Some(origin),
1031 };
1032 self.with(scope, |this| {
1033 for elem in bound_generic_params {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_generic_param(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(this, visit_generic_param, bound_generic_params);
1034 this.visit_ty_unambig(bounded_ty);
1035 for elem in bounds {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_param_bound(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(this, visit_param_bound, bounds);
1036 })
1037 }
1038 &hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
1039 lifetime,
1040 bounds,
1041 ..
1042 }) => {
1043 self.visit_lifetime(lifetime);
1044 for elem in bounds {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_param_bound(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(self, visit_param_bound, bounds);
1045 }
1046 }
1047 }
1048
1049 fn visit_poly_trait_ref(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) {
1050 self.visit_poly_trait_ref_inner(trait_ref, NonLifetimeBinderAllowed::Allow);
1051 }
1052
1053 fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
1054 self.with(
1055 Scope::LateBoundary { s: self.scope, what: "constant", deny_late_regions: true },
1056 |this| {
1057 intravisit::walk_anon_const(this, c);
1058 },
1059 );
1060 }
1061
1062 fn visit_generic_param(&mut self, p: &'tcx GenericParam<'tcx>) {
1063 match p.kind {
1064 GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1065 self.resolve_type_ref(p.def_id, p.hir_id);
1066 }
1067 GenericParamKind::Lifetime { .. } => {
1068 }
1071 }
1072
1073 match p.kind {
1074 GenericParamKind::Lifetime { .. } => {}
1075 GenericParamKind::Type { default, .. } => {
1076 if let Some(ty) = default {
1077 self.visit_ty_unambig(ty);
1078 }
1079 }
1080 GenericParamKind::Const { ty, default, .. } => {
1081 self.visit_ty_unambig(ty);
1082 if let Some(default) = default {
1083 self.visit_const_arg_unambig(default);
1084 }
1085 }
1086 }
1087 }
1088
1089 fn visit_test_binder_bound_type_constraint(
1090 &mut self,
1091 bound_type: &'tcx hir::TestBinderBoundTypeConstraint<'tcx>,
1092 ) -> Self::Result {
1093 let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) = bound_type
1094 .params
1095 .iter()
1096 .enumerate()
1097 .map(|(late_bound_idx, param)| {
1098 (
1099 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
1100 late_arg_as_bound_arg(param),
1101 )
1102 })
1103 .unzip();
1104 self.record_late_bound_vars(bound_type.hir_id, binders);
1105 let scope = Scope::Binder {
1106 hir_id: bound_type.hir_id,
1107 bound_vars,
1108 s: self.scope,
1109 scope_type: BinderScopeType::Normal,
1110 where_bound_origin: None,
1111 };
1112 self.with(scope, |this| {
1113 intravisit::walk_test_binder_bound_type_constraint(this, bound_type);
1114 });
1115 }
1116}
1117
1118fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectLifetimeDefault {
1119 let Ok((generics, bounds)) = (match tcx.hir_node_by_def_id(param_def_id) {
1123 hir::Node::GenericParam(param) => match param.source {
1124 hir::GenericParamSource::Generics => match param.kind {
1125 GenericParamKind::Type { .. } => {
1126 Ok((tcx.hir_get_generics(tcx.local_parent(param_def_id)).unwrap(), &[][..]))
1127 }
1128 _ => Err(()),
1129 },
1130 hir::GenericParamSource::Binder => return ObjectLifetimeDefault::Empty,
1131 },
1132 hir::Node::Item(&hir::Item {
1134 kind: hir::ItemKind::Trait { generics, bounds, .. }, ..
1135 }) => Ok((generics, bounds)),
1136 _ => Err(()),
1137 }) else {
1138 ::rustc_span::macros::bug_impl(None,
format_args!("`object_lifetime_default` must only be called on type parameters"),
Location::caller())bug!("`object_lifetime_default` must only be called on type parameters")
1139 };
1140
1141 let mut set = Set1::Empty;
1142
1143 let mut add_outlives_bounds = |bounds: &[hir::GenericBound<'_>]| {
1144 for bound in bounds {
1145 if let hir::GenericBound::Outlives(lifetime) = bound {
1146 set.insert(lifetime.kind);
1147 }
1148 }
1149 };
1150
1151 add_outlives_bounds(bounds);
1152
1153 for bound in generics.bounds_for_param(param_def_id) {
1155 if bound.bound_generic_params.is_empty() {
1158 add_outlives_bounds(&bound.bounds);
1159 }
1160 }
1161
1162 match set {
1163 Set1::Empty => ObjectLifetimeDefault::Empty,
1164 Set1::One(hir::LifetimeKind::Static) => ObjectLifetimeDefault::Static,
1165 Set1::One(hir::LifetimeKind::Param(param_def_id)) => {
1166 ObjectLifetimeDefault::Param(param_def_id.to_def_id())
1167 }
1168 _ => ObjectLifetimeDefault::Ambiguous,
1169 }
1170}
1171
1172impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1173 fn with<F>(&mut self, wrap_scope: Scope<'_, 'tcx>, f: F)
1174 where
1175 F: for<'b> FnOnce(&mut BoundVarContext<'b, 'tcx>),
1176 {
1177 let BoundVarContext { tcx, rbv, disambiguators, .. } = self;
1178 let nested_errors = RefCell::new(self.opaque_capture_errors.borrow_mut().take());
1179 let mut this = BoundVarContext {
1180 tcx: *tcx,
1181 rbv,
1182 disambiguators,
1183 scope: &wrap_scope,
1184 opaque_capture_errors: nested_errors,
1185 };
1186 let span = {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("scope",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1186u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope")
}> =
::tracing::__macro_support::FieldName::new("scope");
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(&this.scope.debug_truncated())
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
}debug_span!("scope", scope = ?this.scope.debug_truncated());
1187 {
1188 let _enter = span.enter();
1189 f(&mut this);
1190 }
1191 *self.opaque_capture_errors.borrow_mut() = this.opaque_capture_errors.into_inner();
1192 }
1193
1194 fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind<'tcx>>) {
1195 if let Some(old) = self.rbv.late_bound_vars.insert(hir_id.local_id, binder) {
1196 ::rustc_span::macros::bug_impl(None,
format_args!("overwrote bound vars for {1:?}:\nold={2:?}\nnew={0:?}",
self.rbv.late_bound_vars[&hir_id.local_id], hir_id, old),
Location::caller())bug!(
1197 "overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
1198 self.rbv.late_bound_vars[&hir_id.local_id]
1199 )
1200 }
1201 }
1202
1203 fn visit_early_late<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1222 where
1223 F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
1224 {
1225 let mut named_late_bound_vars = 0;
1226 let bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = generics
1227 .params
1228 .iter()
1229 .map(|param| {
1230 (
1231 param.def_id,
1232 match param.kind {
1233 GenericParamKind::Lifetime { .. } => {
1234 if self.tcx.is_late_bound(param.hir_id) {
1235 let late_bound_idx = named_late_bound_vars;
1236 named_late_bound_vars += 1;
1237 ResolvedArg::late(late_bound_idx, param)
1238 } else {
1239 ResolvedArg::early(param)
1240 }
1241 }
1242 GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1243 ResolvedArg::early(param)
1244 }
1245 },
1246 )
1247 })
1248 .collect();
1249
1250 let binders: Vec<_> = generics
1251 .params
1252 .iter()
1253 .filter(|param| {
1254 #[allow(non_exhaustive_omitted_patterns)] match param.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(param.kind, GenericParamKind::Lifetime { .. })
1255 && self.tcx.is_late_bound(param.hir_id)
1256 })
1257 .map(|param| late_arg_as_bound_arg(param))
1258 .collect();
1259 self.record_late_bound_vars(hir_id, binders);
1260 let scope = Scope::Binder {
1261 hir_id,
1262 bound_vars,
1263 s: self.scope,
1264 scope_type: BinderScopeType::Normal,
1265 where_bound_origin: None,
1266 };
1267 self.with(scope, walk);
1268 }
1269
1270 fn visit_early<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1271 where
1272 F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
1273 {
1274 let bound_vars =
1275 generics.params.iter().map(|param| (param.def_id, ResolvedArg::early(param))).collect();
1276 self.record_late_bound_vars(hir_id, ::alloc::vec::Vec::new()vec![]);
1277 let scope = Scope::Binder {
1278 hir_id,
1279 bound_vars,
1280 s: self.scope,
1281 scope_type: BinderScopeType::Normal,
1282 where_bound_origin: None,
1283 };
1284 self.with(scope, |this| {
1285 let scope = Scope::TraitRefBoundary { s: this.scope };
1286 this.with(scope, walk)
1287 });
1288 }
1289
1290 {}
#[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("resolve_lifetime_ref",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1290u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("region_def_id")
}> =
::tracing::__macro_support::FieldName::new("region_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime_ref")
}> =
::tracing::__macro_support::FieldName::new("lifetime_ref");
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(®ion_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime_ref)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut late_depth = 0;
let mut scope = self.scope;
let mut outermost_body = None;
let mut crossed_late_boundary = None;
let mut opaque_capture_scopes = ::alloc::vec::Vec::new();
let result =
loop {
match *scope {
Scope::Body { id, s } => {
outermost_body = Some(id);
scope = s;
}
Scope::Root { opt_parent_item } => {
if let Some(parent_item) = opt_parent_item &&
let parent_generics = self.tcx.generics_of(parent_item) &&
parent_generics.param_def_id_to_index(self.tcx,
region_def_id.to_def_id()).is_some() {
break Some(ResolvedArg::EarlyBound(region_def_id));
}
break None;
}
Scope::Binder {
ref bound_vars, scope_type, s, where_bound_origin, .. } => {
if let Some(&def) = bound_vars.get(®ion_def_id) {
break Some(def.shifted(late_depth));
}
match scope_type {
BinderScopeType::Normal => late_depth += 1,
BinderScopeType::Concatenating => {}
}
if let Some(hir::PredicateOrigin::ImplTrait) =
where_bound_origin &&
let hir::LifetimeKind::Param(param_id) = lifetime_ref.kind
&&
let Some(generics) =
self.tcx.hir_get_generics(self.tcx.local_parent(param_id))
&&
let Some(param) =
generics.params.iter().find(|p| p.def_id == param_id) &&
param.is_elided_lifetime() &&
!self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
&& !self.tcx.features().anonymous_lifetime_in_impl_trait() {
let mut diag: rustc_errors::Diag<'_> =
rustc_session::diagnostics::feature_err(&self.tcx.sess,
sym::anonymous_lifetime_in_impl_trait,
lifetime_ref.ident.span,
"anonymous lifetimes in `impl Trait` are unstable");
if let Some(generics) =
self.tcx.hir_get_generics(lifetime_ref.hir_id.owner.def_id)
{
let new_param_sugg =
if let Some(span) = generics.span_for_lifetime_suggestion()
{
(span, "'a, ".to_owned())
} else { (generics.span, "<'a>".to_owned()) };
let lifetime_sugg = lifetime_ref.suggestion("'a");
let suggestions =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[lifetime_sugg, new_param_sugg]));
diag.span_label(lifetime_ref.ident.span,
"expected named lifetime parameter");
diag.multipart_suggestion("consider introducing a named lifetime parameter",
suggestions, rustc_errors::Applicability::MaybeIncorrect);
}
diag.emit();
return;
}
scope = s;
}
Scope::Opaque { captures, def_id, s } => {
opaque_capture_scopes.push((def_id, captures));
late_depth = 0;
scope = s;
}
Scope::ObjectLifetimeDefault { s, .. } | Scope::Supertrait {
s, .. } | Scope::TraitRefBoundary { s, .. } => {
scope = s;
}
Scope::LateBoundary { s, what, deny_late_regions } => {
if deny_late_regions { crossed_late_boundary = Some(what); }
scope = s;
}
}
};
if let Some(mut def) = result {
def =
self.remap_opaque_captures(&opaque_capture_scopes, def,
lifetime_ref.ident);
if let ResolvedArg::EarlyBound(..) = def
{} else if let ResolvedArg::LateBound(_, _, param_def_id) =
def && let Some(what) = crossed_late_boundary {
let use_span = lifetime_ref.ident.span;
let def_span = self.tcx.def_span(param_def_id);
let guar =
match self.tcx.def_kind(param_def_id) {
DefKind::LifetimeParam => {
self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Lifetime {
use_span,
def_span,
what,
})
}
kind =>
::rustc_span::macros::bug_impl(Some(use_span),
format_args!("did not expect to resolve lifetime to {0}",
kind.descr(param_def_id.to_def_id())), Location::caller()),
};
def = ResolvedArg::Error(guar);
} else if let Some(body_id) = outermost_body {
let fn_id = self.tcx.hir_body_owner(body_id);
match self.tcx.hir_node(fn_id) {
Node::Item(hir::Item {
owner_id, kind: hir::ItemKind::Fn { .. }, .. }) |
Node::TraitItem(hir::TraitItem {
owner_id, kind: hir::TraitItemKind::Fn(..), .. }) |
Node::ImplItem(hir::ImplItem {
owner_id, kind: hir::ImplItemKind::Fn(..), .. }) => {
def = ResolvedArg::Free(owner_id.def_id, def.id().unwrap());
}
Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(closure), .. }) => {
def = ResolvedArg::Free(closure.def_id, def.id().unwrap());
}
_ => {}
}
}
self.insert_lifetime(lifetime_ref, def);
return;
}
let mut scope = self.scope;
loop {
match *scope {
Scope::Binder {
where_bound_origin: Some(hir::PredicateOrigin::ImplTrait),
.. } => {
self.tcx.dcx().emit_err(diagnostics::LateBoundInApit::Lifetime {
span: lifetime_ref.ident.span,
param_span: self.tcx.def_span(region_def_id),
});
return;
}
Scope::Root { .. } => break,
Scope::Binder { s, .. } | Scope::Body { s, .. } |
Scope::Opaque { s, .. } | Scope::ObjectLifetimeDefault { s,
.. } | Scope::Supertrait { s, .. } |
Scope::TraitRefBoundary { s, .. } | Scope::LateBoundary { s,
.. } => {
scope = s;
}
}
}
self.tcx.dcx().span_delayed_bug(lifetime_ref.ident.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Could not resolve {0:?} in scope {1:#?}",
lifetime_ref, self.scope))
}));
}
}
}#[instrument(level = "debug", skip(self))]
1291 fn resolve_lifetime_ref(
1292 &mut self,
1293 region_def_id: LocalDefId,
1294 lifetime_ref: &'tcx hir::Lifetime,
1295 ) {
1296 let mut late_depth = 0;
1301 let mut scope = self.scope;
1302 let mut outermost_body = None;
1303 let mut crossed_late_boundary = None;
1304 let mut opaque_capture_scopes = vec![];
1305 let result = loop {
1306 match *scope {
1307 Scope::Body { id, s } => {
1308 outermost_body = Some(id);
1309 scope = s;
1310 }
1311
1312 Scope::Root { opt_parent_item } => {
1313 if let Some(parent_item) = opt_parent_item
1314 && let parent_generics = self.tcx.generics_of(parent_item)
1315 && parent_generics
1316 .param_def_id_to_index(self.tcx, region_def_id.to_def_id())
1317 .is_some()
1318 {
1319 break Some(ResolvedArg::EarlyBound(region_def_id));
1320 }
1321 break None;
1322 }
1323
1324 Scope::Binder { ref bound_vars, scope_type, s, where_bound_origin, .. } => {
1325 if let Some(&def) = bound_vars.get(®ion_def_id) {
1326 break Some(def.shifted(late_depth));
1327 }
1328 match scope_type {
1329 BinderScopeType::Normal => late_depth += 1,
1330 BinderScopeType::Concatenating => {}
1331 }
1332 if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
1335 && let hir::LifetimeKind::Param(param_id) = lifetime_ref.kind
1336 && let Some(generics) =
1337 self.tcx.hir_get_generics(self.tcx.local_parent(param_id))
1338 && let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
1339 && param.is_elided_lifetime()
1340 && !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
1341 && !self.tcx.features().anonymous_lifetime_in_impl_trait()
1342 {
1343 let mut diag: rustc_errors::Diag<'_> =
1344 rustc_session::diagnostics::feature_err(
1345 &self.tcx.sess,
1346 sym::anonymous_lifetime_in_impl_trait,
1347 lifetime_ref.ident.span,
1348 "anonymous lifetimes in `impl Trait` are unstable",
1349 );
1350
1351 if let Some(generics) =
1352 self.tcx.hir_get_generics(lifetime_ref.hir_id.owner.def_id)
1353 {
1354 let new_param_sugg =
1355 if let Some(span) = generics.span_for_lifetime_suggestion() {
1356 (span, "'a, ".to_owned())
1357 } else {
1358 (generics.span, "<'a>".to_owned())
1359 };
1360
1361 let lifetime_sugg = lifetime_ref.suggestion("'a");
1362 let suggestions = vec![lifetime_sugg, new_param_sugg];
1363
1364 diag.span_label(
1365 lifetime_ref.ident.span,
1366 "expected named lifetime parameter",
1367 );
1368 diag.multipart_suggestion(
1369 "consider introducing a named lifetime parameter",
1370 suggestions,
1371 rustc_errors::Applicability::MaybeIncorrect,
1372 );
1373 }
1374
1375 diag.emit();
1376 return;
1377 }
1378 scope = s;
1379 }
1380
1381 Scope::Opaque { captures, def_id, s } => {
1382 opaque_capture_scopes.push((def_id, captures));
1383 late_depth = 0;
1384 scope = s;
1385 }
1386
1387 Scope::ObjectLifetimeDefault { s, .. }
1388 | Scope::Supertrait { s, .. }
1389 | Scope::TraitRefBoundary { s, .. } => {
1390 scope = s;
1391 }
1392
1393 Scope::LateBoundary { s, what, deny_late_regions } => {
1394 if deny_late_regions {
1395 crossed_late_boundary = Some(what);
1396 }
1397 scope = s;
1398 }
1399 }
1400 };
1401
1402 if let Some(mut def) = result {
1403 def = self.remap_opaque_captures(&opaque_capture_scopes, def, lifetime_ref.ident);
1404
1405 if let ResolvedArg::EarlyBound(..) = def {
1406 } else if let ResolvedArg::LateBound(_, _, param_def_id) = def
1408 && let Some(what) = crossed_late_boundary
1409 {
1410 let use_span = lifetime_ref.ident.span;
1411 let def_span = self.tcx.def_span(param_def_id);
1412 let guar = match self.tcx.def_kind(param_def_id) {
1413 DefKind::LifetimeParam => {
1414 self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Lifetime {
1415 use_span,
1416 def_span,
1417 what,
1418 })
1419 }
1420 kind => span_bug!(
1421 use_span,
1422 "did not expect to resolve lifetime to {}",
1423 kind.descr(param_def_id.to_def_id())
1424 ),
1425 };
1426 def = ResolvedArg::Error(guar);
1427 } else if let Some(body_id) = outermost_body {
1428 let fn_id = self.tcx.hir_body_owner(body_id);
1429 match self.tcx.hir_node(fn_id) {
1430 Node::Item(hir::Item { owner_id, kind: hir::ItemKind::Fn { .. }, .. })
1431 | Node::TraitItem(hir::TraitItem {
1432 owner_id,
1433 kind: hir::TraitItemKind::Fn(..),
1434 ..
1435 })
1436 | Node::ImplItem(hir::ImplItem {
1437 owner_id,
1438 kind: hir::ImplItemKind::Fn(..),
1439 ..
1440 }) => {
1441 def = ResolvedArg::Free(owner_id.def_id, def.id().unwrap());
1442 }
1443 Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) => {
1444 def = ResolvedArg::Free(closure.def_id, def.id().unwrap());
1445 }
1446 _ => {}
1447 }
1448 }
1449
1450 self.insert_lifetime(lifetime_ref, def);
1451 return;
1452 }
1453
1454 let mut scope = self.scope;
1464 loop {
1465 match *scope {
1466 Scope::Binder {
1467 where_bound_origin: Some(hir::PredicateOrigin::ImplTrait), ..
1468 } => {
1469 self.tcx.dcx().emit_err(diagnostics::LateBoundInApit::Lifetime {
1470 span: lifetime_ref.ident.span,
1471 param_span: self.tcx.def_span(region_def_id),
1472 });
1473 return;
1474 }
1475 Scope::Root { .. } => break,
1476 Scope::Binder { s, .. }
1477 | Scope::Body { s, .. }
1478 | Scope::Opaque { s, .. }
1479 | Scope::ObjectLifetimeDefault { s, .. }
1480 | Scope::Supertrait { s, .. }
1481 | Scope::TraitRefBoundary { s, .. }
1482 | Scope::LateBoundary { s, .. } => {
1483 scope = s;
1484 }
1485 }
1486 }
1487
1488 self.tcx.dcx().span_delayed_bug(
1489 lifetime_ref.ident.span,
1490 format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
1491 );
1492 }
1493
1494 fn check_lifetime_is_capturable(
1499 &self,
1500 opaque_def_id: LocalDefId,
1501 lifetime: ResolvedArg,
1502 capture_span: Span,
1503 ) -> Result<(), ErrorGuaranteed> {
1504 let ResolvedArg::LateBound(_, _, lifetime_def_id) = lifetime else { return Ok(()) };
1505 let lifetime_hir_id = self.tcx.local_def_id_to_hir_id(lifetime_def_id);
1506 let bad_place = match self.tcx.hir_node(self.tcx.parent_hir_id(lifetime_hir_id)) {
1507 hir::Node::OpaqueTy(_) => "higher-ranked lifetime from outer `impl Trait`",
1510 hir::Node::Item(_) | hir::Node::TraitItem(_) | hir::Node::ImplItem(_) => return Ok(()),
1512 hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(_), .. }) => {
1513 "higher-ranked lifetime from function pointer"
1514 }
1515 hir::Node::Ty(hir::Ty { kind: hir::TyKind::TraitObject(..), .. }) => {
1516 "higher-ranked lifetime from `dyn` type"
1517 }
1518 _ => "higher-ranked lifetime",
1519 };
1520
1521 let decl_span = self.tcx.def_span(lifetime_def_id);
1522 let opaque_span = self.tcx.def_span(opaque_def_id);
1523
1524 let mut errors = self.opaque_capture_errors.borrow_mut();
1525 let error_info = errors.get_or_insert_with(|| OpaqueHigherRankedLifetimeCaptureErrors {
1526 bad_place,
1527 capture_spans: Vec::new(),
1528 decl_spans: Vec::new(),
1529 });
1530
1531 if error_info.capture_spans.is_empty() {
1532 error_info.capture_spans.push(opaque_span);
1533 }
1534
1535 if capture_span != decl_span && capture_span != opaque_span {
1536 error_info.capture_spans.push(capture_span);
1537 }
1538
1539 if !error_info.decl_spans.contains(&decl_span) {
1540 error_info.decl_spans.push(decl_span);
1541 }
1542
1543 Err(self.tcx.dcx().span_delayed_bug(capture_span, "opaque capture error not emitted"))
1545 }
1546
1547 fn emit_opaque_capture_errors(&self) -> Option<ErrorGuaranteed> {
1548 let errors = self.opaque_capture_errors.borrow_mut().take()?;
1549 if errors.capture_spans.is_empty() {
1550 return None;
1551 }
1552
1553 let mut span = rustc_errors::MultiSpan::from_span(errors.capture_spans[0]);
1554 for &capture_span in &errors.capture_spans[1..] {
1555 span.push_span_label(capture_span, "");
1556 }
1557 let decl_span = rustc_errors::MultiSpan::from_spans(errors.decl_spans);
1558
1559 let guar = self.tcx.dcx().emit_err(diagnostics::OpaqueCapturesHigherRankedLifetime {
1561 span,
1562 label: Some(errors.capture_spans[0]),
1563 decl_span,
1564 bad_place: errors.bad_place,
1565 });
1566
1567 Some(guar)
1568 }
1569
1570 {}
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("remap_opaque_captures",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1570u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime")
}> =
::tracing::__macro_support::FieldName::new("lifetime");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ident")
}> =
::tracing::__macro_support::FieldName::new("ident");
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(&lifetime)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: ResolvedArg = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(&(opaque_def_id, _)) =
opaque_capture_scopes.last() {
if let Err(guar) =
self.check_lifetime_is_capturable(opaque_def_id, lifetime,
ident.span) {
lifetime = ResolvedArg::Error(guar);
}
}
for &(opaque_def_id, captures) in
opaque_capture_scopes.iter().rev() {
let mut captures = captures.borrow_mut();
let remapped =
*captures.entry(lifetime).or_insert_with(||
{
let feed =
self.tcx.create_def(opaque_def_id, None,
DefKind::LifetimeParam,
Some(DefPathData::OpaqueLifetime(ident.name)),
self.disambiguators.get_or_create(opaque_def_id));
feed.def_span(ident.span);
feed.def_ident_span(Some(ident.span));
feed.def_id()
});
lifetime = ResolvedArg::EarlyBound(remapped);
}
lifetime
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1570",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1570u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "trace", skip(self, opaque_capture_scopes), ret)]
1571 fn remap_opaque_captures(
1572 &mut self,
1573 opaque_capture_scopes: &Vec<(LocalDefId, &RefCell<FxIndexMap<ResolvedArg, LocalDefId>>)>,
1574 mut lifetime: ResolvedArg,
1575 ident: Ident,
1576 ) -> ResolvedArg {
1577 if let Some(&(opaque_def_id, _)) = opaque_capture_scopes.last() {
1578 if let Err(guar) =
1579 self.check_lifetime_is_capturable(opaque_def_id, lifetime, ident.span)
1580 {
1581 lifetime = ResolvedArg::Error(guar);
1582 }
1583 }
1584
1585 for &(opaque_def_id, captures) in opaque_capture_scopes.iter().rev() {
1586 let mut captures = captures.borrow_mut();
1587 let remapped = *captures.entry(lifetime).or_insert_with(|| {
1588 let feed = self.tcx.create_def(
1593 opaque_def_id,
1594 None,
1595 DefKind::LifetimeParam,
1596 Some(DefPathData::OpaqueLifetime(ident.name)),
1597 self.disambiguators.get_or_create(opaque_def_id),
1598 );
1599 feed.def_span(ident.span);
1600 feed.def_ident_span(Some(ident.span));
1601 feed.def_id()
1602 });
1603 lifetime = ResolvedArg::EarlyBound(remapped);
1604 }
1605 lifetime
1606 }
1607
1608 fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: HirId) {
1609 let mut late_depth = 0;
1614 let mut scope = self.scope;
1615 let mut crossed_late_boundary = None;
1616
1617 let result = loop {
1618 match *scope {
1619 Scope::Body { s, .. } => {
1620 scope = s;
1621 }
1622
1623 Scope::Root { opt_parent_item } => {
1624 if let Some(parent_item) = opt_parent_item
1625 && let parent_generics = self.tcx.generics_of(parent_item)
1626 && parent_generics
1627 .param_def_id_to_index(self.tcx, param_def_id.to_def_id())
1628 .is_some()
1629 {
1630 break Some(ResolvedArg::EarlyBound(param_def_id));
1631 }
1632 break None;
1633 }
1634
1635 Scope::Binder { ref bound_vars, scope_type, s, .. } => {
1636 if let Some(&def) = bound_vars.get(¶m_def_id) {
1637 break Some(def.shifted(late_depth));
1638 }
1639 match scope_type {
1640 BinderScopeType::Normal => late_depth += 1,
1641 BinderScopeType::Concatenating => {}
1642 }
1643 scope = s;
1644 }
1645
1646 Scope::ObjectLifetimeDefault { s, .. }
1647 | Scope::Opaque { s, .. }
1648 | Scope::Supertrait { s, .. }
1649 | Scope::TraitRefBoundary { s, .. } => {
1650 scope = s;
1651 }
1652
1653 Scope::LateBoundary { s, what, deny_late_regions: _ } => {
1654 crossed_late_boundary = Some(what);
1655 scope = s;
1656 }
1657 }
1658 };
1659
1660 if let Some(def) = result {
1661 if let ResolvedArg::LateBound(..) = def
1662 && let Some(what) = crossed_late_boundary
1663 {
1664 let use_span = self.tcx.hir_span(hir_id);
1665 let def_span = self.tcx.def_span(param_def_id);
1666 let guar = match self.tcx.def_kind(param_def_id) {
1667 DefKind::ConstParam => {
1668 self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Const {
1669 use_span,
1670 def_span,
1671 what,
1672 })
1673 }
1674 DefKind::TyParam => {
1675 self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Type {
1676 use_span,
1677 def_span,
1678 what,
1679 })
1680 }
1681 kind => ::rustc_span::macros::bug_impl(Some(use_span),
format_args!("did not expect to resolve non-lifetime param to {0}",
kind.descr(param_def_id.to_def_id())), Location::caller())span_bug!(
1682 use_span,
1683 "did not expect to resolve non-lifetime param to {}",
1684 kind.descr(param_def_id.to_def_id())
1685 ),
1686 };
1687 self.rbv.defs.insert(hir_id.local_id, ResolvedArg::Error(guar));
1688 } else {
1689 self.rbv.defs.insert(hir_id.local_id, def);
1690 }
1691 return;
1692 }
1693
1694 let mut scope = self.scope;
1704 loop {
1705 match *scope {
1706 Scope::Binder {
1707 where_bound_origin: Some(hir::PredicateOrigin::ImplTrait), ..
1708 } => {
1709 let guar = self.tcx.dcx().emit_err(match self.tcx.def_kind(param_def_id) {
1710 DefKind::TyParam => diagnostics::LateBoundInApit::Type {
1711 span: self.tcx.hir_span(hir_id),
1712 param_span: self.tcx.def_span(param_def_id),
1713 },
1714 DefKind::ConstParam => diagnostics::LateBoundInApit::Const {
1715 span: self.tcx.hir_span(hir_id),
1716 param_span: self.tcx.def_span(param_def_id),
1717 },
1718 kind => {
1719 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected def-kind: {0}",
kind.descr(param_def_id.to_def_id())), Location::caller())bug!("unexpected def-kind: {}", kind.descr(param_def_id.to_def_id()))
1720 }
1721 });
1722 self.rbv.defs.insert(hir_id.local_id, ResolvedArg::Error(guar));
1723 return;
1724 }
1725 Scope::Root { .. } => break,
1726 Scope::Binder { s, .. }
1727 | Scope::Body { s, .. }
1728 | Scope::Opaque { s, .. }
1729 | Scope::ObjectLifetimeDefault { s, .. }
1730 | Scope::Supertrait { s, .. }
1731 | Scope::TraitRefBoundary { s, .. }
1732 | Scope::LateBoundary { s, .. } => {
1733 scope = s;
1734 }
1735 }
1736 }
1737
1738 self.tcx
1739 .dcx()
1740 .span_bug(self.tcx.hir_span(hir_id), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("could not resolve {0:?}",
param_def_id))
})format!("could not resolve {param_def_id:?}"));
1741 }
1742
1743 {}
#[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("visit_path_segment_args",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1743u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("generic_args")
}> =
::tracing::__macro_support::FieldName::new("generic_args");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("seg_idx")
}> =
::tracing::__macro_support::FieldName::new("seg_idx");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
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(&generic_args)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&seg_idx)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
if let Some((inputs, output)) =
generic_args.paren_sugar_inputs_output() {
self.visit_fn_like_elision(inputs, Some(output), false);
return;
}
for arg in generic_args.args {
if let hir::GenericArg::Lifetime(lt) = arg {
self.visit_lifetime(lt);
}
}
let container = self.eligible_container(path, seg_idx);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1764",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1764u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("container")
}> =
::tracing::__macro_support::FieldName::new("container");
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(&container)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let (has_self, object_lifetime_defaults) =
container.map(|(def_id, segs)|
{
let generics = self.tcx.generics_of(def_id);
let defaults =
self.compute_object_lifetime_defaults(generics, segs);
(generics.has_own_self(), defaults)
}).unwrap_or_default();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1774",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1774u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("object_lifetime_defaults")
}> =
::tracing::__macro_support::FieldName::new("object_lifetime_defaults");
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(&object_lifetime_defaults)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mut i = has_self as usize;
for arg in generic_args.args {
match arg {
GenericArg::Lifetime(_) => {}
GenericArg::Type(ty) => {
if let Some(<) = object_lifetime_defaults.get(i) {
let scope =
Scope::ObjectLifetimeDefault {
lifetime: lt,
s: self.scope,
};
self.with(scope, |this| this.visit_ty(ty));
} else { self.visit_ty(ty); }
i += 1;
}
GenericArg::Const(ct) => {
self.visit_const_arg(ct);
i += 1;
}
GenericArg::Infer(inf) => {
self.visit_id(inf.hir_id);
i += 1;
}
}
}
let has_lifetime_args = generic_args.has_lifetime_args();
for constraint in generic_args.constraints {
let scope =
Scope::ObjectLifetimeDefault {
lifetime: if has_lifetime_args ||
constraint.gen_args.has_lifetime_args() {
None
} else { Some(ResolvedArg::StaticLifetime) },
s: self.scope,
};
if constraint.gen_args.parenthesized ==
hir::GenericArgsParentheses::ReturnTypeNotation {
let bound_vars =
if let Some((container_def_id, _)) = container &&
let DefKind::Trait | DefKind::TraitAlias =
self.tcx.def_kind(container_def_id) &&
let Some((mut bound_vars, assoc_fn)) =
BoundVarContext::supertrait_hrtb_vars(self.tcx,
container_def_id, constraint.ident, ty::AssocTag::Fn) {
bound_vars.extend(self.tcx.generics_of(assoc_fn.def_id).own_params.iter().map(|param|
generic_param_def_as_bound_arg(param)));
let fn_bound_vars =
if assoc_fn.def_id == constraint.hir_id.owner.to_def_id() {
let fn_hir_id =
self.tcx.local_def_id_to_hir_id(assoc_fn.def_id.expect_local());
self.rbv.late_bound_vars.get(&fn_hir_id.local_id).expect("late-bound vars for the current function were not recorded").clone()
} else {
self.tcx.fn_sig(assoc_fn.def_id).instantiate_identity().skip_norm_wip().bound_vars().to_vec()
};
bound_vars.extend(fn_bound_vars);
bound_vars
} else {
self.tcx.dcx().span_delayed_bug(constraint.ident.span,
"bad return type notation here");
::alloc::vec::Vec::new()
};
self.with(scope,
|this|
{
let scope = Scope::Supertrait { bound_vars, s: this.scope };
this.with(scope,
|this|
{
let (bound_vars, _) = this.poly_trait_ref_binder_info();
this.record_late_bound_vars(constraint.hir_id, bound_vars);
this.visit_assoc_item_constraint(constraint)
});
});
} else if let Some((container_def_id, _)) = container {
let bound_vars =
BoundVarContext::supertrait_hrtb_vars(self.tcx,
container_def_id, constraint.ident,
ty::AssocTag::Type).map(|(bound_vars, _)| bound_vars);
self.with(scope,
|this|
{
let scope =
Scope::Supertrait {
bound_vars: bound_vars.unwrap_or_default(),
s: this.scope,
};
this.with(scope,
|this| this.visit_assoc_item_constraint(constraint));
});
} else {
self.with(scope,
|this| this.visit_assoc_item_constraint(constraint));
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1744 fn visit_path_segment_args(
1745 &mut self,
1746 generic_args: &'tcx hir::GenericArgs<'tcx>,
1747 seg_idx: SegIdx,
1748 path: &hir::Path<'tcx>,
1749 ) {
1750 if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
1751 self.visit_fn_like_elision(inputs, Some(output), false);
1752 return;
1753 }
1754
1755 for arg in generic_args.args {
1758 if let hir::GenericArg::Lifetime(lt) = arg {
1759 self.visit_lifetime(lt);
1760 }
1761 }
1762
1763 let container = self.eligible_container(path, seg_idx);
1764 debug!(?container);
1765
1766 let (has_self, object_lifetime_defaults) = container
1767 .map(|(def_id, segs)| {
1768 let generics = self.tcx.generics_of(def_id);
1769 let defaults = self.compute_object_lifetime_defaults(generics, segs);
1770 (generics.has_own_self(), defaults)
1771 })
1772 .unwrap_or_default();
1773
1774 debug!(?object_lifetime_defaults);
1775
1776 let mut i = has_self as usize;
1777 for arg in generic_args.args {
1778 match arg {
1779 GenericArg::Lifetime(_) => {}
1781 GenericArg::Type(ty) => {
1782 if let Some(<) = object_lifetime_defaults.get(i) {
1783 let scope = Scope::ObjectLifetimeDefault { lifetime: lt, s: self.scope };
1784 self.with(scope, |this| this.visit_ty(ty));
1785 } else {
1786 self.visit_ty(ty);
1787 }
1788 i += 1;
1789 }
1790 GenericArg::Const(ct) => {
1791 self.visit_const_arg(ct);
1792 i += 1;
1793 }
1794 GenericArg::Infer(inf) => {
1795 self.visit_id(inf.hir_id);
1796 i += 1;
1797 }
1798 }
1799 }
1800
1801 let has_lifetime_args = generic_args.has_lifetime_args();
1802
1803 for constraint in generic_args.constraints {
1804 let scope = Scope::ObjectLifetimeDefault {
1805 lifetime: if has_lifetime_args || constraint.gen_args.has_lifetime_args() {
1838 None
1839 } else {
1840 Some(ResolvedArg::StaticLifetime)
1841 },
1842 s: self.scope,
1843 };
1844 if constraint.gen_args.parenthesized == hir::GenericArgsParentheses::ReturnTypeNotation
1858 {
1859 let bound_vars = if let Some((container_def_id, _)) = container
1860 && let DefKind::Trait | DefKind::TraitAlias =
1861 self.tcx.def_kind(container_def_id)
1862 && let Some((mut bound_vars, assoc_fn)) = BoundVarContext::supertrait_hrtb_vars(
1863 self.tcx,
1864 container_def_id,
1865 constraint.ident,
1866 ty::AssocTag::Fn,
1867 ) {
1868 bound_vars.extend(
1869 self.tcx
1870 .generics_of(assoc_fn.def_id)
1871 .own_params
1872 .iter()
1873 .map(|param| generic_param_def_as_bound_arg(param)),
1874 );
1875 let fn_bound_vars = if assoc_fn.def_id == constraint.hir_id.owner.to_def_id() {
1879 let fn_hir_id =
1880 self.tcx.local_def_id_to_hir_id(assoc_fn.def_id.expect_local());
1881 self.rbv
1882 .late_bound_vars
1883 .get(&fn_hir_id.local_id)
1884 .expect("late-bound vars for the current function were not recorded")
1885 .clone()
1886 } else {
1887 self.tcx
1888 .fn_sig(assoc_fn.def_id)
1889 .instantiate_identity()
1890 .skip_norm_wip()
1891 .bound_vars()
1892 .to_vec()
1893 };
1894 bound_vars.extend(fn_bound_vars);
1895 bound_vars
1896 } else {
1897 self.tcx
1898 .dcx()
1899 .span_delayed_bug(constraint.ident.span, "bad return type notation here");
1900 vec![]
1901 };
1902 self.with(scope, |this| {
1903 let scope = Scope::Supertrait { bound_vars, s: this.scope };
1904 this.with(scope, |this| {
1905 let (bound_vars, _) = this.poly_trait_ref_binder_info();
1906 this.record_late_bound_vars(constraint.hir_id, bound_vars);
1907 this.visit_assoc_item_constraint(constraint)
1908 });
1909 });
1910 } else if let Some((container_def_id, _)) = container {
1911 let bound_vars = BoundVarContext::supertrait_hrtb_vars(
1912 self.tcx,
1913 container_def_id,
1914 constraint.ident,
1915 ty::AssocTag::Type,
1916 )
1917 .map(|(bound_vars, _)| bound_vars);
1918 self.with(scope, |this| {
1919 let scope = Scope::Supertrait {
1920 bound_vars: bound_vars.unwrap_or_default(),
1921 s: this.scope,
1922 };
1923 this.with(scope, |this| this.visit_assoc_item_constraint(constraint));
1924 });
1925 } else {
1926 self.with(scope, |this| this.visit_assoc_item_constraint(constraint));
1927 }
1928 }
1929 }
1930
1931 fn eligible_container<'b>(
1937 &self,
1938 path: &'b hir::Path<'tcx>,
1939 seg_idx: SegIdx,
1940 ) -> Option<(DefId, &'b [hir::PathSegment<'tcx>])> {
1941 let RevSegIdx(rev_seg_idx) = seg_idx.reverse(path.segments);
1942 let SegIdx(seg_idx) = seg_idx;
1943
1944 let (kind, def_id) = match path.res {
1951 Res::Def(kind, def_id) => (kind, def_id),
1952 Res::PrimTy(..)
1953 | Res::SelfTyParam { .. }
1954 | Res::SelfTyAlias { .. }
1955 | Res::SelfCtor(_)
1956 | Res::Local(_)
1957 | Res::ToolMod
1958 | Res::OpenMod(_)
1959 | Res::NonMacroAttr(_)
1960 | Res::Err => return None, };
1962
1963 match kind {
1964 DefKind::AssocTy => match rev_seg_idx {
1965 0 => Some((def_id, path.segments)),
1966 1 => Some((self.tcx.parent(def_id), &path.segments[..=seg_idx])),
1969 _ => None,
1970 },
1971 DefKind::Variant => match rev_seg_idx {
1972 0 => Some((self.tcx.parent(def_id), path.segments)),
1976 1 => Some((self.tcx.parent(def_id), &path.segments[..=seg_idx])),
1978 _ => None,
1979 },
1980 DefKind::Enum
1981 | DefKind::Struct
1982 | DefKind::Trait
1983 | DefKind::TraitAlias
1984 | DefKind::TyAlias
1985 | DefKind::Union => match rev_seg_idx {
1986 0 => Some((def_id, path.segments)),
1987 _ => None,
1988 },
1989 DefKind::AnonConst
1990 | DefKind::AssocConst
1991 | DefKind::AssocFn
1992 | DefKind::Closure
1993 | DefKind::Const
1994 | DefKind::ConstParam
1995 | DefKind::Ctor(..)
1996 | DefKind::ExternCrate
1997 | DefKind::Field
1998 | DefKind::Fn
1999 | DefKind::ForeignMod
2000 | DefKind::ForeignTy
2001 | DefKind::GlobalAsm
2002 | DefKind::Impl { .. }
2003 | DefKind::LifetimeParam
2004 | DefKind::Macro(_)
2005 | DefKind::Mod
2006 | DefKind::OpaqueTy
2007 | DefKind::Static { .. }
2008 | DefKind::SyntheticCoroutineBody
2009 | DefKind::TyParam
2010 | DefKind::Use
2011 | DefKind::TestBinderConstraints => None, }
2013 }
2014
2015 fn compute_object_lifetime_defaults(
2032 &self,
2033 generics: &ty::Generics,
2034 segments: &[hir::PathSegment<'_>],
2035 ) -> Vec<Option<ResolvedArg>> {
2036 let in_body = {
2037 let mut scope = self.scope;
2038 loop {
2039 match *scope {
2040 Scope::Root { .. } => break false,
2041
2042 Scope::Body { .. } => break true,
2043
2044 Scope::Binder { s, .. }
2045 | Scope::ObjectLifetimeDefault { s, .. }
2046 | Scope::Opaque { s, .. }
2047 | Scope::Supertrait { s, .. }
2048 | Scope::TraitRefBoundary { s, .. }
2049 | Scope::LateBoundary { s, .. } => {
2050 scope = s;
2051 }
2052 }
2053 }
2054 };
2055
2056 let set_to_region = |set: ObjectLifetimeDefault| match set {
2057 ObjectLifetimeDefault::Empty => {
2058 if in_body {
2059 None
2060 } else {
2061 Some(ResolvedArg::StaticLifetime)
2062 }
2063 }
2064 ObjectLifetimeDefault::Static => Some(ResolvedArg::StaticLifetime),
2065 ObjectLifetimeDefault::Param(param_def_id) => {
2066 struct ArgIdx(usize);
2067
2068 fn resolve_param(
2069 param_def_id: DefId,
2070 generics: &ty::Generics,
2071 tcx: TyCtxt<'_>,
2072 ) -> (RevSegIdx, ArgIdx) {
2073 if let Some(&index) = generics.param_def_id_to_index.get(¶m_def_id) {
2074 let has_self = generics.has_own_self();
2075 let index = index as usize - generics.parent_count - has_self as usize;
2076 (RevSegIdx(0), ArgIdx(index))
2077 } else if let Some(parent) = generics.parent {
2078 let parent_generics = tcx.generics_of(parent);
2079 let (RevSegIdx(rev_seg_idx), arg_idx) =
2080 resolve_param(param_def_id, parent_generics, tcx);
2081 (RevSegIdx(rev_seg_idx + 1), arg_idx)
2082 } else {
2083 ::core::panicking::unreachable_default_msg()unreachable!()
2084 }
2085 }
2086
2087 let (rev_seg_idx, ArgIdx(arg_idx)) =
2088 resolve_param(param_def_id, generics, self.tcx);
2089
2090 let SegIdx(seg_idx) = rev_seg_idx.reverse(segments);
2091
2092 segments[seg_idx].args.and_then(|args| args.args.get(arg_idx)).and_then(|arg| {
2093 match arg {
2094 GenericArg::Lifetime(lt) => self.rbv.defs.get(<.hir_id.local_id).copied(),
2095 _ => None,
2096 }
2097 })
2098 }
2099 ObjectLifetimeDefault::Ambiguous => None,
2100 };
2101 generics
2102 .own_params
2103 .iter()
2104 .filter_map(|param| {
2105 match self.tcx.def_kind(param.def_id) {
2118 DefKind::TyParam | DefKind::Trait => {
2119 Some(self.tcx.object_lifetime_default(param.def_id))
2120 }
2121 DefKind::ConstParam | DefKind::TraitAlias => Some(ObjectLifetimeDefault::Empty),
2122 DefKind::LifetimeParam => None,
2123 kind => ::rustc_span::macros::bug_impl(None,
format_args!("unexpected def kind {0:?}", kind), Location::caller())bug!("unexpected def kind {kind:?}"),
2124 }
2125 })
2126 .map(set_to_region)
2127 .collect()
2128 }
2129
2130 fn supertrait_hrtb_vars(
2143 tcx: TyCtxt<'tcx>,
2144 def_id: DefId,
2145 assoc_ident: Ident,
2146 assoc_tag: ty::AssocTag,
2147 ) -> Option<(Vec<ty::BoundVariableKind<'tcx>>, &'tcx ty::AssocItem)> {
2148 let trait_defines_associated_item_named = |trait_def_id: DefId| {
2149 tcx.associated_items(trait_def_id).find_by_ident_and_kind(
2150 tcx,
2151 assoc_ident,
2152 assoc_tag,
2153 trait_def_id,
2154 )
2155 };
2156
2157 use smallvec::{SmallVec, smallvec};
2158 let mut stack: SmallVec<[(DefId, SmallVec<[ty::BoundVariableKind<'tcx>; 8]>); 8]> =
2159 {
let count = 0usize + 1usize;
let mut vec = ::smallvec::SmallVec::new();
if count <= vec.inline_size() {
vec.push((def_id, ::smallvec::SmallVec::new()));
vec
} else {
::smallvec::SmallVec::from_vec(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(def_id, ::smallvec::SmallVec::new())])))
}
}smallvec![(def_id, smallvec![])];
2160 let mut visited: FxHashSet<DefId> = FxHashSet::default();
2161 loop {
2162 let Some((def_id, bound_vars)) = stack.pop() else {
2163 break None;
2164 };
2165 match tcx.def_kind(def_id) {
2168 DefKind::Trait | DefKind::TraitAlias | DefKind::Impl { .. } => {}
2169 _ => break None,
2170 }
2171
2172 if let Some(assoc_item) = trait_defines_associated_item_named(def_id) {
2173 break Some((bound_vars.into_iter().collect(), assoc_item));
2174 }
2175 let predicates = tcx.explicit_supertraits_containing_assoc_item((def_id, assoc_ident));
2176 let obligations = predicates
2177 .iter_identity_copied()
2178 .map(Unnormalized::skip_norm_wip)
2179 .filter_map(|(pred, _)| {
2180 let bound_predicate = pred.kind();
2181 match bound_predicate.skip_binder() {
2182 ty::ClauseKind::Trait(data) => {
2183 let pred_bound_vars = bound_predicate.bound_vars();
2186 let mut all_bound_vars = bound_vars.clone();
2187 all_bound_vars.extend(pred_bound_vars.iter());
2188 let super_def_id = data.trait_ref.def_id;
2189 Some((super_def_id, all_bound_vars))
2190 }
2191 _ => None,
2192 }
2193 });
2194
2195 let obligations = obligations.filter(|o| visited.insert(o.0));
2196 stack.extend(obligations);
2197 }
2198 }
2199
2200 {}
#[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("visit_fn_like_elision",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2200u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("inputs")
}> =
::tracing::__macro_support::FieldName::new("inputs");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("output")
}> =
::tracing::__macro_support::FieldName::new("output");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("in_closure")
}> =
::tracing::__macro_support::FieldName::new("in_closure");
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(&inputs)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&in_closure 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: () = loop {};
return __tracing_attr_fake_return;
}
{
self.with(Scope::ObjectLifetimeDefault {
lifetime: Some(ResolvedArg::StaticLifetime),
s: self.scope,
},
|this|
{
for input in inputs { this.visit_ty_unambig(input); }
if !in_closure && let Some(output) = output {
this.visit_ty_unambig(output);
}
});
if in_closure && let Some(output) = output {
self.visit_ty_unambig(output);
}
}
}
}#[instrument(level = "debug", skip(self))]
2201 fn visit_fn_like_elision(
2202 &mut self,
2203 inputs: &'tcx [hir::Ty<'tcx>],
2204 output: Option<&'tcx hir::Ty<'tcx>>,
2205 in_closure: bool,
2206 ) {
2207 self.with(
2208 Scope::ObjectLifetimeDefault {
2209 lifetime: Some(ResolvedArg::StaticLifetime),
2210 s: self.scope,
2211 },
2212 |this| {
2213 for input in inputs {
2214 this.visit_ty_unambig(input);
2215 }
2216 if !in_closure && let Some(output) = output {
2217 this.visit_ty_unambig(output);
2218 }
2219 },
2220 );
2221 if in_closure && let Some(output) = output {
2222 self.visit_ty_unambig(output);
2223 }
2224 }
2225
2226 {}
#[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("resolve_object_lifetime_default",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2226u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime_ref")
}> =
::tracing::__macro_support::FieldName::new("lifetime_ref");
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(&lifetime_ref)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut late_depth = 0;
let mut scope = self.scope;
let mut opaque_capture_scopes = ::alloc::vec::Vec::new();
let mut lifetime =
loop {
match *scope {
Scope::Binder { s, scope_type, .. } => {
match scope_type {
BinderScopeType::Normal => late_depth += 1,
BinderScopeType::Concatenating => {}
}
scope = s;
}
Scope::Root { .. } => break ResolvedArg::StaticLifetime,
Scope::Body { .. } | Scope::ObjectLifetimeDefault {
lifetime: None, .. } => return,
Scope::ObjectLifetimeDefault { lifetime: Some(l), .. } => {
break l.shifted(late_depth);
}
Scope::Opaque { captures, def_id, s } => {
opaque_capture_scopes.push((def_id, captures));
late_depth = 0;
scope = s;
}
Scope::Supertrait { s, .. } | Scope::TraitRefBoundary { s,
.. } | Scope::LateBoundary { s, .. } => {
scope = s;
}
}
};
lifetime =
self.remap_opaque_captures(&opaque_capture_scopes, lifetime,
lifetime_ref.ident);
self.insert_lifetime(lifetime_ref, lifetime);
}
}
}#[instrument(level = "debug", skip(self))]
2227 fn resolve_object_lifetime_default(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
2228 let mut late_depth = 0;
2229 let mut scope = self.scope;
2230 let mut opaque_capture_scopes = vec![];
2231 let mut lifetime = loop {
2232 match *scope {
2233 Scope::Binder { s, scope_type, .. } => {
2234 match scope_type {
2235 BinderScopeType::Normal => late_depth += 1,
2236 BinderScopeType::Concatenating => {}
2237 }
2238 scope = s;
2239 }
2240
2241 Scope::Root { .. } => break ResolvedArg::StaticLifetime,
2242
2243 Scope::Body { .. } | Scope::ObjectLifetimeDefault { lifetime: None, .. } => return,
2244
2245 Scope::ObjectLifetimeDefault { lifetime: Some(l), .. } => {
2246 break l.shifted(late_depth);
2247 }
2248
2249 Scope::Opaque { captures, def_id, s } => {
2250 opaque_capture_scopes.push((def_id, captures));
2251 late_depth = 0;
2252 scope = s;
2253 }
2254
2255 Scope::Supertrait { s, .. }
2256 | Scope::TraitRefBoundary { s, .. }
2257 | Scope::LateBoundary { s, .. } => {
2258 scope = s;
2259 }
2260 }
2261 };
2262
2263 lifetime = self.remap_opaque_captures(&opaque_capture_scopes, lifetime, lifetime_ref.ident);
2264
2265 self.insert_lifetime(lifetime_ref, lifetime);
2266 }
2267
2268 {}
#[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("insert_lifetime",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2268u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime_ref")
}> =
::tracing::__macro_support::FieldName::new("lifetime_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def")
}> =
::tracing::__macro_support::FieldName::new("def");
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(&lifetime_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def)
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: () = 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 /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2270",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2270u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
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(&lifetime_ref.ident.span)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.rbv.defs.insert(lifetime_ref.hir_id.local_id, def);
}
}
}#[instrument(level = "debug", skip(self))]
2269 fn insert_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime, def: ResolvedArg) {
2270 debug!(span = ?lifetime_ref.ident.span);
2271 self.rbv.defs.insert(lifetime_ref.hir_id.local_id, def);
2272 }
2273
2274 fn try_append_return_type_notation_params(
2293 &mut self,
2294 hir_id: HirId,
2295 hir_ty: &'tcx hir::Ty<'tcx>,
2296 ) {
2297 let hir::TyKind::Path(qpath) = hir_ty.kind else {
2298 return;
2302 };
2303
2304 let (mut bound_vars, item_def_id, item_segment) = match qpath {
2305 hir::QPath::Resolved(_, path)
2307 if let [.., item_segment] = &path.segments[..]
2308 && item_segment.args.is_some_and(|args| {
2309 #[allow(non_exhaustive_omitted_patterns)] match args.parenthesized {
hir::GenericArgsParentheses::ReturnTypeNotation => true,
_ => false,
}matches!(
2310 args.parenthesized,
2311 hir::GenericArgsParentheses::ReturnTypeNotation
2312 )
2313 }) =>
2314 {
2315 match path.res {
2316 Res::Err => return,
2317 Res::Def(DefKind::AssocFn, item_def_id) => (::alloc::vec::Vec::new()vec![], item_def_id, item_segment),
2318 _ => ::rustc_span::macros::bug_impl(None,
format_args!("only expected method resolution for fully qualified RTN"),
Location::caller())bug!("only expected method resolution for fully qualified RTN"),
2319 }
2320 }
2321
2322 hir::QPath::TypeRelative(qself, item_segment)
2324 if item_segment.args.is_some_and(|args| {
2325 #[allow(non_exhaustive_omitted_patterns)] match args.parenthesized {
hir::GenericArgsParentheses::ReturnTypeNotation => true,
_ => false,
}matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
2326 }) =>
2327 {
2328 let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = qself.kind else {
2331 return;
2332 };
2333 match path.res {
2334 Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { trait_: _ } => {
2335 let mut bounds =
2336 self.for_each_trait_bound_on_res(path.res).filter_map(|trait_def_id| {
2337 BoundVarContext::supertrait_hrtb_vars(
2338 self.tcx,
2339 trait_def_id,
2340 item_segment.ident,
2341 ty::AssocTag::Fn,
2342 )
2343 });
2344
2345 let Some((bound_vars, assoc_item)) = bounds.next() else {
2346 self.tcx
2348 .dcx()
2349 .span_delayed_bug(path.span, "no resolution for RTN path");
2350 return;
2351 };
2352
2353 for (second_vars, second_assoc_item) in bounds {
2356 if second_vars != bound_vars || second_assoc_item != assoc_item {
2357 self.tcx.dcx().span_delayed_bug(
2359 path.span,
2360 "ambiguous resolution for RTN path",
2361 );
2362 return;
2363 }
2364 }
2365
2366 (bound_vars, assoc_item.def_id, item_segment)
2367 }
2368 Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. } => {
2371 let hir::ItemKind::Impl(hir::Impl { of_trait: Some(of_trait), .. }) = self
2372 .tcx
2373 .hir_node_by_def_id(impl_def_id.expect_local())
2374 .expect_item()
2375 .kind
2376 else {
2377 return;
2378 };
2379 let Some(trait_def_id) = of_trait.trait_ref.trait_def_id() else {
2380 return;
2381 };
2382 let Some((bound_vars, assoc_item)) = BoundVarContext::supertrait_hrtb_vars(
2383 self.tcx,
2384 trait_def_id,
2385 item_segment.ident,
2386 ty::AssocTag::Fn,
2387 ) else {
2388 return;
2389 };
2390 (bound_vars, assoc_item.def_id, item_segment)
2391 }
2392 _ => return,
2393 }
2394 }
2395
2396 _ => return,
2397 };
2398
2399 bound_vars.extend(
2403 self.tcx
2404 .generics_of(item_def_id)
2405 .own_params
2406 .iter()
2407 .map(|param| generic_param_def_as_bound_arg(param)),
2408 );
2409 bound_vars.extend(
2410 self.tcx.fn_sig(item_def_id).instantiate_identity().skip_norm_wip().bound_vars(),
2411 );
2412
2413 let existing_bound_vars = self.rbv.late_bound_vars.get_mut(&hir_id.local_id).unwrap();
2429 let existing_bound_vars_saved = existing_bound_vars.clone();
2430 existing_bound_vars.extend(bound_vars);
2431 self.record_late_bound_vars(item_segment.hir_id, existing_bound_vars_saved);
2432 }
2433
2434 fn for_each_trait_bound_on_res(&self, expected_res: Res) -> impl Iterator<Item = DefId> {
2437 gen move {
2438 let mut scope = self.scope;
2439 loop {
2440 let hir_id = match *scope {
2441 Scope::Binder { hir_id, .. } => Some(hir_id),
2442 Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2443 Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2444 }
2445 Scope::Body { .. }
2446 | Scope::ObjectLifetimeDefault { .. }
2447 | Scope::Supertrait { .. }
2448 | Scope::TraitRefBoundary { .. }
2449 | Scope::LateBoundary { .. }
2450 | Scope::Opaque { .. }
2451 | Scope::Root { opt_parent_item: None } => None,
2452 };
2453
2454 if let Some(hir_id) = hir_id {
2455 let node = self.tcx.hir_node(hir_id);
2456 if let Res::SelfTyParam { trait_: _ } = expected_res
2460 && let hir::Node::Item(item) = node
2461 && let hir::ItemKind::Trait { .. } = item.kind
2462 {
2463 yield item.owner_id.def_id.to_def_id();
2466 } else if let Some(generics) = node.generics() {
2467 for pred in generics.predicates {
2468 let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind else {
2469 continue;
2470 };
2471 let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2472 pred.bounded_ty.kind
2473 else {
2474 continue;
2475 };
2476 if bounded_path.res != expected_res {
2478 continue;
2479 }
2480 for pred in pred.bounds {
2481 match pred {
2482 hir::GenericBound::Trait(poly_trait_ref) => {
2483 if let Some(def_id) =
2484 poly_trait_ref.trait_ref.trait_def_id()
2485 {
2486 yield def_id;
2487 }
2488 }
2489 hir::GenericBound::Outlives(_)
2490 | hir::GenericBound::Use(_, _) => {}
2491 }
2492 }
2493 }
2494 }
2495 }
2496
2497 match *scope {
2498 Scope::Binder { s, .. }
2499 | Scope::Body { s, .. }
2500 | Scope::ObjectLifetimeDefault { s, .. }
2501 | Scope::Supertrait { s, .. }
2502 | Scope::TraitRefBoundary { s }
2503 | Scope::LateBoundary { s, .. }
2504 | Scope::Opaque { s, .. } => {
2505 scope = s;
2506 }
2507 Scope::Root { .. } => break,
2508 }
2509 }
2510 }
2511 }
2512
2513 fn visit_test_binder_constraints(
2514 &mut self,
2515 hir_id: HirId,
2516 generics: &'tcx hir::Generics<'tcx>,
2517 body: &'tcx hir::TestBinderBody<'tcx>,
2518 ) {
2519 fn collect_params<'a>(body: &hir::TestBinderBody<'a>, params: &mut Vec<GenericParam<'a>>) {
2520 for item in body.items {
2521 match item {
2522 hir::TestBinderItem::Forall(item) => {
2523 params.extend(item.generics.params);
2524 collect_params(&item.body, params);
2525 }
2526 hir::TestBinderItem::Exists(item) => {
2527 params.extend(item.params);
2528 collect_params(&item.body, params);
2529 }
2530 hir::TestBinderItem::RegionEquality { .. }
2531 | hir::TestBinderItem::Constraint(..)
2532 | hir::TestBinderItem::Predicate(..) => (),
2533 }
2534 }
2535 }
2536
2537 let mut params = ::alloc::vec::Vec::new()vec![];
2538 collect_params(body, &mut params);
2539
2540 let early_bound_vars =
2541 generics.params.iter().map(|param| (param.def_id, ResolvedArg::early(param))).collect();
2542
2543 let (late_bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) = params
2544 .iter()
2545 .enumerate()
2546 .map(|(late_bound_idx, param)| {
2547 (
2548 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
2549 late_arg_as_bound_arg(param),
2550 )
2551 })
2552 .unzip();
2553 self.record_late_bound_vars(hir_id, binders);
2554
2555 let early_scope = Scope::Binder {
2556 hir_id,
2557 bound_vars: early_bound_vars,
2558 s: self.scope,
2559 scope_type: BinderScopeType::Normal,
2560 where_bound_origin: None,
2561 };
2562 self.with(early_scope, |this| {
2563 this.with(Scope::TraitRefBoundary { s: this.scope }, |this| {
2564 this.visit_generics(generics);
2565 let late_scope = Scope::Binder {
2566 hir_id,
2567 bound_vars: late_bound_vars,
2568 s: this.scope,
2569 scope_type: BinderScopeType::Normal,
2570 where_bound_origin: None,
2571 };
2572 this.with(late_scope, |this| this.visit_test_binder_body(body))
2573 })
2574 })
2575 }
2576}
2577
2578fn is_late_bound_map(
2589 tcx: TyCtxt<'_>,
2590 owner_id: hir::OwnerId,
2591) -> Option<&FxIndexSet<hir::ItemLocalId>> {
2592 let sig = tcx.hir_fn_sig_by_hir_id(owner_id.into())?;
2593 let generics = tcx.hir_get_generics(owner_id.def_id)?;
2594
2595 let mut late_bound = FxIndexSet::default();
2596
2597 let mut constrained_by_input = ConstrainedCollector { regions: Default::default(), tcx };
2598 for arg_ty in sig.decl.inputs {
2599 constrained_by_input.visit_ty_unambig(arg_ty);
2600 }
2601
2602 let mut appears_in_output =
2603 AllCollector { has_fully_capturing_opaque: false, regions: Default::default() };
2604 intravisit::walk_fn_ret_ty(&mut appears_in_output, &sig.decl.output);
2605 if appears_in_output.has_fully_capturing_opaque {
2606 appears_in_output.regions.extend(generics.params.iter().map(|param| param.def_id));
2607 }
2608
2609 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2609",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2609u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("constrained_by_input.regions")
}> =
::tracing::__macro_support::FieldName::new("constrained_by_input.regions");
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(&constrained_by_input.regions)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?constrained_by_input.regions);
2610
2611 let mut appears_in_where_clause =
2616 AllCollector { has_fully_capturing_opaque: true, regions: Default::default() };
2617 appears_in_where_clause.visit_generics(generics);
2618 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2618",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2618u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("appears_in_where_clause.regions")
}> =
::tracing::__macro_support::FieldName::new("appears_in_where_clause.regions");
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(&appears_in_where_clause.regions)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?appears_in_where_clause.regions);
2619
2620 for param in generics.params {
2625 match param.kind {
2626 hir::GenericParamKind::Lifetime { .. } => { }
2627
2628 hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => continue,
2630 }
2631
2632 if appears_in_where_clause.regions.contains(¶m.def_id) {
2634 continue;
2635 }
2636
2637 if !constrained_by_input.regions.contains(¶m.def_id)
2639 && appears_in_output.regions.contains(¶m.def_id)
2640 {
2641 continue;
2642 }
2643
2644 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2644",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2644u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("lifetime {0:?} with id {1:?} is late-bound",
param.name.ident(), param.def_id) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("lifetime {:?} with id {:?} is late-bound", param.name.ident(), param.def_id);
2645
2646 let inserted = late_bound.insert(param.hir_id.local_id);
2647 if !inserted {
{
::core::panicking::panic_fmt(format_args!("visited lifetime {0:?} twice",
param.def_id));
}
};assert!(inserted, "visited lifetime {:?} twice", param.def_id);
2648 }
2649
2650 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2650",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2650u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("late_bound")
}> =
::tracing::__macro_support::FieldName::new("late_bound");
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(&late_bound)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?late_bound);
2651 return Some(tcx.arena.alloc(late_bound));
2652
2653 struct ConstrainedCollectorPostHirTyLowering {
2675 arg_is_constrained: Box<[bool]>,
2676 }
2677
2678 use ty::Ty;
2679 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostHirTyLowering {
2680 fn visit_ty(&mut self, t: Ty<'tcx>) {
2681 match t.kind() {
2682 ty::Param(param_ty) => {
2683 self.arg_is_constrained[param_ty.index as usize] = true;
2684 }
2685 ty::Alias(
2686 _,
2687 ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. },
2688 ) => return,
2689 _ => (),
2690 }
2691 t.super_visit_with(self)
2692 }
2693
2694 fn visit_const(&mut self, _: ty::Const<'tcx>) {}
2695
2696 fn visit_region(&mut self, r: ty::Region<'tcx>) {
2697 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2697",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/064405c5f7fbc7d41aa30b45da1e45a85777bd58/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2697u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("r={0:?}",
r.kind()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("r={:?}", r.kind());
2698 if let ty::RegionKind::ReEarlyParam(region) = r.kind() {
2699 self.arg_is_constrained[region.index as usize] = true;
2700 }
2701 }
2702 }
2703
2704 struct ConstrainedCollector<'tcx> {
2705 tcx: TyCtxt<'tcx>,
2706 regions: FxHashSet<LocalDefId>,
2707 }
2708
2709 impl<'v> Visitor<'v> for ConstrainedCollector<'_> {
2710 fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
2711 match ty.kind {
2712 hir::TyKind::Path(
2713 hir::QPath::Resolved(Some(_), _) | hir::QPath::TypeRelative(..),
2714 ) => {
2715 }
2719
2720 hir::TyKind::Path(hir::QPath::Resolved(
2721 None,
2722 hir::Path { res: Res::Def(DefKind::TyAlias, alias_def), segments, span },
2723 )) => {
2724 let generics = self.tcx.generics_of(*alias_def);
2727 let mut walker = ConstrainedCollectorPostHirTyLowering {
2728 arg_is_constrained: ::alloc::vec::from_elem_global(false, generics.own_params.len())vec![false; generics.own_params.len()]
2729 .into_boxed_slice(),
2730 };
2731 walker.visit_ty(
2732 self.tcx.type_of(*alias_def).instantiate_identity().skip_norm_wip(),
2733 );
2734
2735 match segments.last() {
2736 Some(hir::PathSegment { args: Some(args), .. }) => {
2737 let tcx = self.tcx;
2738 for constrained_arg in
2739 args.args.iter().enumerate().flat_map(|(n, arg)| {
2740 match walker.arg_is_constrained.get(n) {
2741 Some(true) => Some(arg),
2742 Some(false) => None,
2743 None => {
2744 tcx.dcx().span_delayed_bug(
2745 *span,
2746 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Incorrect generic arg count for alias {0:?}",
alias_def))
})format!(
2747 "Incorrect generic arg count for alias {alias_def:?}"
2748 ),
2749 );
2750 None
2751 }
2752 }
2753 })
2754 {
2755 self.visit_generic_arg(constrained_arg);
2756 }
2757 }
2758 Some(_) => (),
2759 None => ::rustc_span::macros::bug_impl(None,
format_args!("Path with no segments or self type"), Location::caller())bug!("Path with no segments or self type"),
2760 }
2761 }
2762
2763 hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
2764 if let Some(last_segment) = path.segments.last() {
2770 self.visit_path_segment(last_segment);
2771 }
2772 }
2773
2774 _ => {
2775 intravisit::walk_ty(self, ty);
2776 }
2777 }
2778 }
2779
2780 fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
2781 if let hir::LifetimeKind::Param(def_id) = lifetime_ref.kind {
2782 self.regions.insert(def_id);
2783 }
2784 }
2785 }
2786
2787 struct AllCollector {
2788 has_fully_capturing_opaque: bool,
2789 regions: FxHashSet<LocalDefId>,
2790 }
2791
2792 impl<'tcx> Visitor<'tcx> for AllCollector {
2793 fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
2794 if let hir::LifetimeKind::Param(def_id) = lifetime_ref.kind {
2795 self.regions.insert(def_id);
2796 }
2797 }
2798
2799 fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
2800 if !self.has_fully_capturing_opaque {
2801 self.has_fully_capturing_opaque = opaque_captures_all_in_scope_lifetimes(opaque);
2802 }
2803 intravisit::walk_opaque_ty(self, opaque);
2804 }
2805 }
2806}
2807
2808fn deny_non_region_late_bound(
2809 tcx: TyCtxt<'_>,
2810 bound_vars: &mut FxIndexMap<LocalDefId, ResolvedArg>,
2811 where_: &str,
2812) {
2813 let mut first = true;
2814
2815 for (var, arg) in bound_vars {
2816 let Node::GenericParam(param) = tcx.hir_node_by_def_id(*var) else {
2817 ::rustc_span::macros::bug_impl(Some(tcx.def_span(*var)),
format_args!("expected bound-var def-id to resolve to param"),
Location::caller());span_bug!(tcx.def_span(*var), "expected bound-var def-id to resolve to param");
2818 };
2819
2820 let what = match param.kind {
2821 hir::GenericParamKind::Type { .. } => "type",
2822 hir::GenericParamKind::Const { .. } => "const",
2823 hir::GenericParamKind::Lifetime { .. } => continue,
2824 };
2825
2826 let diag = tcx.dcx().struct_span_err(
2827 param.span,
2828 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("late-bound {0} parameter not allowed on {1}",
what, where_))
})format!("late-bound {what} parameter not allowed on {where_}"),
2829 );
2830
2831 let guar = diag.emit_err_unless_delay(!tcx.features().non_lifetime_binders() || !first);
2832
2833 first = false;
2834 *arg = ResolvedArg::Error(guar);
2835 }
2836}
2837
2838#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for SegIdx {
}
#[automatically_derived]impl ::core::clone::Clone for SegIdx {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for SegIdx { }Copy, #[automatically_derived]impl ::core::fmt::Debug for SegIdx {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "SegIdx",
&&self.0)
}
}Debug)]
2840struct SegIdx(usize);
2841
2842impl SegIdx {
2843 fn reverse(self, segments: &[hir::PathSegment<'_>]) -> RevSegIdx {
2844 let SegIdx(seg_idx) = self;
2845 RevSegIdx(segments.len() - seg_idx - 1)
2846 }
2847}
2848
2849struct RevSegIdx(usize);
2854
2855impl RevSegIdx {
2856 fn reverse(self, segments: &[hir::PathSegment<'_>]) -> SegIdx {
2857 let RevSegIdx(rev_seg_idx) = self;
2858 SegIdx(segments.len() - rev_seg_idx - 1)
2859 }
2860}