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, VisitorExt};
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_middle::{bug, span_bug};
29use rustc_span::def_id::{DefId, LocalDefId};
30use rustc_span::{Ident, Span, sym};
31use tracing::{debug, debug_span, instrument};
32
33use crate::diagnostics;
34use crate::hir::definitions::PerParentDisambiguatorState;
35
36impl RegionExt 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 RegionExt)]
37impl ResolvedArg {
38 fn early(param: &GenericParam<'_>) -> ResolvedArg {
39 ResolvedArg::EarlyBound(param.def_id)
40 }
41
42 fn late(idx: u32, param: &GenericParam<'_>) -> ResolvedArg {
43 ResolvedArg::LateBound(ty::INNERMOST, idx, param.def_id)
44 }
45
46 fn id(&self) -> Option<LocalDefId> {
47 match *self {
48 ResolvedArg::StaticLifetime | ResolvedArg::Error(_) => None,
49
50 ResolvedArg::EarlyBound(id)
51 | ResolvedArg::LateBound(_, _, id)
52 | ResolvedArg::Free(_, id) => Some(id),
53 }
54 }
55
56 fn shifted(self, amount: u32) -> ResolvedArg {
57 match self {
58 ResolvedArg::LateBound(debruijn, idx, id) => {
59 ResolvedArg::LateBound(debruijn.shifted_in(amount), idx, id)
60 }
61 _ => self,
62 }
63 }
64}
65
66struct BoundVarContext<'a, 'tcx> {
67 tcx: TyCtxt<'tcx>,
68 rbv: &'a mut ResolveBoundVars<'tcx>,
69 disambiguators: &'a mut LocalDefIdMap<PerParentDisambiguatorState>,
70 scope: ScopeRef<'a, 'tcx>,
71 opaque_capture_errors: RefCell<Option<OpaqueHigherRankedLifetimeCaptureErrors>>,
72}
73
74struct OpaqueHigherRankedLifetimeCaptureErrors {
75 bad_place: &'static str,
76 capture_spans: Vec<Span>,
77 decl_spans: Vec<Span>,
78}
79
80#[derive(#[automatically_derived]
impl<'a, 'tcx> ::core::fmt::Debug for Scope<'a, 'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Scope::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", __self_0, "scope_type", __self_1,
"hir_id", __self_2, "s", __self_3, "where_bound_origin",
&__self_4),
Scope::Body { id: __self_0, s: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Body",
"id", __self_0, "s", &__self_1),
Scope::ObjectLifetimeDefault { lifetime: __self_0, s: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ObjectLifetimeDefault", "lifetime", __self_0, "s",
&__self_1),
Scope::Supertrait { bound_vars: __self_0, s: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Supertrait", "bound_vars", __self_0, "s", &__self_1),
Scope::TraitRefBoundary { s: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TraitRefBoundary", "s", &__self_0),
Scope::Opaque { def_id: __self_0, captures: __self_1, s: __self_2
} =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Opaque", "def_id", __self_0, "captures", __self_1, "s",
&__self_2),
Scope::LateBoundary {
s: __self_0, what: __self_1, deny_late_regions: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"LateBoundary", "s", __self_0, "what", __self_1,
"deny_late_regions", &__self_2),
Scope::Root { opt_parent_item: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Root",
"opt_parent_item", &__self_0),
}
}
}Debug)]
81enum Scope<'a, 'tcx> {
82 Binder {
87 bound_vars: FxIndexMap<LocalDefId, ResolvedArg>,
90
91 scope_type: BinderScopeType,
92
93 hir_id: HirId,
98
99 s: ScopeRef<'a, 'tcx>,
100
101 where_bound_origin: Option<hir::PredicateOrigin>,
107 },
108
109 Body {
114 id: hir::BodyId,
115 s: ScopeRef<'a, 'tcx>,
116 },
117
118 ObjectLifetimeDefault {
122 lifetime: Option<ResolvedArg>,
123 s: ScopeRef<'a, 'tcx>,
124 },
125
126 Supertrait {
131 bound_vars: Vec<ty::BoundVariableKind<'tcx>>,
132 s: ScopeRef<'a, 'tcx>,
133 },
134
135 TraitRefBoundary {
136 s: ScopeRef<'a, 'tcx>,
137 },
138
139 Opaque {
148 def_id: LocalDefId,
150 captures: &'a RefCell<FxIndexMap<ResolvedArg, LocalDefId>>,
152
153 s: ScopeRef<'a, 'tcx>,
154 },
155
156 LateBoundary {
162 s: ScopeRef<'a, 'tcx>,
163 what: &'static str,
164 deny_late_regions: bool,
165 },
166
167 Root {
168 opt_parent_item: Option<LocalDefId>,
169 },
170}
171
172impl<'a, 'tcx> Scope<'a, 'tcx> {
173 fn debug_truncated(&self) -> impl fmt::Debug {
175 fmt::from_fn(move |f| match self {
176 Self::Binder { bound_vars, scope_type, hir_id, where_bound_origin, s: _ } => f
177 .debug_struct("Binder")
178 .field("bound_vars", bound_vars)
179 .field("scope_type", scope_type)
180 .field("hir_id", hir_id)
181 .field("where_bound_origin", where_bound_origin)
182 .field("s", &"..")
183 .finish(),
184 Self::Opaque { captures, def_id, s: _ } => f
185 .debug_struct("Opaque")
186 .field("def_id", def_id)
187 .field("captures", &captures.borrow())
188 .field("s", &"..")
189 .finish(),
190 Self::Body { id, s: _ } => {
191 f.debug_struct("Body").field("id", id).field("s", &"..").finish()
192 }
193 Self::ObjectLifetimeDefault { lifetime, s: _ } => f
194 .debug_struct("ObjectLifetimeDefault")
195 .field("lifetime", lifetime)
196 .field("s", &"..")
197 .finish(),
198 Self::Supertrait { bound_vars, s: _ } => f
199 .debug_struct("Supertrait")
200 .field("bound_vars", bound_vars)
201 .field("s", &"..")
202 .finish(),
203 Self::TraitRefBoundary { s: _ } => f.debug_struct("TraitRefBoundary").finish(),
204 Self::LateBoundary { s: _, what, deny_late_regions } => f
205 .debug_struct("LateBoundary")
206 .field("what", what)
207 .field("deny_late_regions", deny_late_regions)
208 .finish(),
209 Self::Root { opt_parent_item } => {
210 f.debug_struct("Root").field("opt_parent_item", &opt_parent_item).finish()
211 }
212 })
213 }
214}
215
216#[derive(#[automatically_derived]
impl ::core::marker::Copy for BinderScopeType { }Copy, #[automatically_derived]
impl ::core::clone::Clone for BinderScopeType {
#[inline]
fn clone(&self) -> BinderScopeType { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for BinderScopeType {
#[inline]
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)]
217enum BinderScopeType {
218 Normal,
220 Concatenating,
230}
231
232type ScopeRef<'a, 'tcx> = &'a Scope<'a, 'tcx>;
233
234pub(crate) fn provide(providers: &mut Providers) {
236 *providers = Providers {
237 resolve_bound_vars,
238
239 named_variable_map: |tcx, id| &tcx.resolve_bound_vars(id).defs,
240 is_late_bound_map,
241 object_lifetime_default,
242 late_bound_vars_map: |tcx, id| &tcx.resolve_bound_vars(id).late_bound_vars,
243 opaque_captured_lifetimes: |tcx, id| {
244 &tcx.resolve_bound_vars(tcx.local_def_id_to_hir_id(id).owner)
245 .opaque_captured_lifetimes
246 .get(&id)
247 .map_or(&[][..], |x| &x[..])
248 },
249
250 ..*providers
251 };
252}
253
254#[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(257u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["local_def_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&local_def_id)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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::panic("internal error: entered unreachable code"),
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event 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("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(&["rbv.defs"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&rbv.defs)
as &dyn Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event 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("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(&["rbv.late_bound_vars"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&rbv.late_bound_vars)
as &dyn Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:288",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(288u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["rbv.opaque_captured_lifetimes"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&rbv.opaque_captured_lifetimes)
as &dyn Value))])
});
} else { ; }
};
rbv
}
}
}#[instrument(level = "debug", skip(tcx))]
258fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBoundVars<'_> {
259 let mut rbv = ResolveBoundVars::default();
260 let mut visitor = BoundVarContext {
261 tcx,
262 rbv: &mut rbv,
263 scope: &Scope::Root { opt_parent_item: None },
264 disambiguators: &mut Default::default(),
265 opaque_capture_errors: RefCell::new(None),
266 };
267 match tcx.hir_owner_node(local_def_id) {
268 hir::OwnerNode::Item(item) => visitor.visit_item(item),
269 hir::OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
270 hir::OwnerNode::TraitItem(item) => {
271 let scope =
272 Scope::Root { opt_parent_item: Some(tcx.local_parent(item.owner_id.def_id)) };
273 visitor.scope = &scope;
274 visitor.visit_trait_item(item)
275 }
276 hir::OwnerNode::ImplItem(item) => {
277 let scope =
278 Scope::Root { opt_parent_item: Some(tcx.local_parent(item.owner_id.def_id)) };
279 visitor.scope = &scope;
280 visitor.visit_impl_item(item)
281 }
282 hir::OwnerNode::Crate(_) => {}
283 hir::OwnerNode::Synthetic => unreachable!(),
284 }
285
286 debug!(?rbv.defs);
287 debug!(?rbv.late_bound_vars);
288 debug!(?rbv.opaque_captured_lifetimes);
289 rbv
290}
291
292fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableKind<'tcx> {
293 let def_id = param.def_id.to_def_id();
294 match param.kind {
295 GenericParamKind::Lifetime { .. } => {
296 ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
297 }
298 GenericParamKind::Type { .. } => ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)),
299 GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
300 }
301}
302
303fn generic_param_def_as_bound_arg<'tcx>(
307 param: &ty::GenericParamDef,
308) -> ty::BoundVariableKind<'tcx> {
309 match param.kind {
310 ty::GenericParamDefKind::Lifetime => {
311 ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id))
312 }
313 ty::GenericParamDefKind::Type { .. } => {
314 ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id))
315 }
316 ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
317 }
318}
319
320fn opaque_captures_all_in_scope_lifetimes<'tcx>(opaque: &'tcx hir::OpaqueTy<'tcx>) -> bool {
324 match opaque.origin {
325 _ if opaque.bounds.iter().any(|bound| #[allow(non_exhaustive_omitted_patterns)] match bound {
hir::GenericBound::Use(..) => true,
_ => false,
}matches!(bound, hir::GenericBound::Use(..))) => false,
328 hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => true,
329 _ if opaque.span.at_least_rust_2024() => true,
330 hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => in_trait_or_impl.is_some(),
331 }
332}
333
334impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
335 fn poly_trait_ref_binder_info(
337 &mut self,
338 ) -> (Vec<ty::BoundVariableKind<'tcx>>, BinderScopeType) {
339 let mut scope = self.scope;
340 let mut supertrait_bound_vars = ::alloc::vec::Vec::new()vec![];
341 loop {
342 match scope {
343 Scope::Body { .. } | Scope::Root { .. } => {
344 break (::alloc::vec::Vec::new()vec![], BinderScopeType::Normal);
345 }
346
347 Scope::Opaque { s, .. }
348 | Scope::ObjectLifetimeDefault { s, .. }
349 | Scope::LateBoundary { s, .. } => {
350 scope = s;
351 }
352
353 Scope::Supertrait { s, bound_vars } => {
354 supertrait_bound_vars = bound_vars.clone();
355 scope = s;
356 }
357
358 Scope::TraitRefBoundary { .. } => {
359 if !supertrait_bound_vars.is_empty() {
363 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!(
364 "found supertrait lifetimes without a binder to append \
365 them to: {supertrait_bound_vars:?}"
366 ));
367 }
368 break (::alloc::vec::Vec::new()vec![], BinderScopeType::Normal);
369 }
370
371 Scope::Binder { hir_id, .. } => {
372 let mut full_binders: Vec<ty::BoundVariableKind<'tcx>> =
374 self.rbv.late_bound_vars.get_mut_or_insert_default(hir_id.local_id).clone();
375 full_binders.extend(supertrait_bound_vars);
376 break (full_binders, BinderScopeType::Concatenating);
377 }
378 }
379 }
380 }
381
382 fn visit_poly_trait_ref_inner(
383 &mut self,
384 trait_ref: &'tcx hir::PolyTraitRef<'tcx>,
385 non_lifetime_binder_allowed: NonLifetimeBinderAllowed,
386 ) {
387 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:387",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(387u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("visit_poly_trait_ref(trait_ref={0:?})",
trait_ref) as &dyn Value))])
});
} else { ; }
};debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
388
389 let (mut binders, scope_type) = self.poly_trait_ref_binder_info();
390
391 let initial_bound_vars = binders.len() as u32;
392 let mut bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = FxIndexMap::default();
393 let binders_iter =
394 trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
395 let arg = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
396 bound_vars.insert(param.def_id, arg);
397 late_arg_as_bound_arg(param)
398 });
399 binders.extend(binders_iter);
400
401 if let NonLifetimeBinderAllowed::Deny(where_) = non_lifetime_binder_allowed {
402 deny_non_region_late_bound(self.tcx, &mut bound_vars, where_);
403 }
404
405 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:405",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(405u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["binders"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&binders) as
&dyn Value))])
});
} else { ; }
};debug!(?binders);
406 self.record_late_bound_vars(trait_ref.trait_ref.hir_ref_id, binders);
407
408 let scope = Scope::Binder {
413 hir_id: trait_ref.trait_ref.hir_ref_id,
414 bound_vars,
415 s: self.scope,
416 scope_type,
417 where_bound_origin: None,
418 };
419 self.with(scope, |this| {
420 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);
421 this.visit_trait_ref(&trait_ref.trait_ref);
422 });
423 }
424}
425
426enum NonLifetimeBinderAllowed {
427 Deny(&'static str),
428 Allow,
429}
430
431impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
432 type NestedFilter = nested_filter::OnlyBodies;
433
434 fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
435 self.tcx
436 }
437
438 fn visit_nested_body(&mut self, body: hir::BodyId) {
439 let body = self.tcx.hir_body(body);
440 self.with(Scope::Body { id: body.id(), s: self.scope }, |this| {
441 this.visit_body(body);
442 });
443 }
444
445 fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
446 if let hir::ExprKind::Closure(hir::Closure {
447 binder, bound_generic_params, fn_decl, ..
448 }) = e.kind
449 {
450 if let &hir::ClosureBinder::For { span: for_sp, .. } = binder {
451 fn span_of_infer(ty: &hir::Ty<'_>) -> Option<Span> {
452 struct FindInferInClosureWithBinder;
455 impl<'v> Visitor<'v> for FindInferInClosureWithBinder {
456 type Result = ControlFlow<Span>;
457
458 fn visit_infer(
459 &mut self,
460 _inf_id: HirId,
461 inf_span: Span,
462 _kind: InferKind<'v>,
463 ) -> Self::Result {
464 ControlFlow::Break(inf_span)
465 }
466 }
467 FindInferInClosureWithBinder.visit_ty_unambig(ty).break_value()
468 }
469
470 let infer_in_rt_sp = match fn_decl.output {
471 hir::FnRetTy::DefaultReturn(sp) => Some(sp),
472 hir::FnRetTy::Return(ty) => span_of_infer(ty),
473 };
474
475 let infer_spans = fn_decl
476 .inputs
477 .into_iter()
478 .filter_map(span_of_infer)
479 .chain(infer_in_rt_sp)
480 .collect::<Vec<_>>();
481
482 if !infer_spans.is_empty() {
483 self.tcx
484 .dcx()
485 .emit_err(diagnostics::ClosureImplicitHrtb { spans: infer_spans, for_sp });
486 }
487 }
488
489 let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
490 bound_generic_params
491 .iter()
492 .enumerate()
493 .map(|(late_bound_idx, param)| {
494 (
495 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
496 late_arg_as_bound_arg(param),
497 )
498 })
499 .unzip();
500
501 deny_non_region_late_bound(self.tcx, &mut bound_vars, "closures");
502
503 self.record_late_bound_vars(e.hir_id, binders);
504 let scope = Scope::Binder {
505 hir_id: e.hir_id,
506 bound_vars,
507 s: self.scope,
508 scope_type: BinderScopeType::Normal,
509 where_bound_origin: None,
510 };
511
512 self.with(scope, |this| {
513 intravisit::walk_expr(this, e)
516 });
517 } else {
518 intravisit::walk_expr(self, e)
519 }
520 }
521
522 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(527u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["opaque"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opaque)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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_middle::util::bug::bug_fmt(format_args!("{0:?}",
scope))
}
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 compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:617",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(617u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["captures"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&captures)
as &dyn Value))])
});
} else { ; }
};
self.rbv.opaque_captured_lifetimes.insert(opaque.def_id,
captures);
}
}
}#[instrument(level = "debug", skip(self))]
528 fn visit_opaque_ty(&mut self, opaque: &'tcx rustc_hir::OpaqueTy<'tcx>) {
529 let captures = RefCell::new(FxIndexMap::default());
530
531 let capture_all_in_scope_lifetimes = opaque_captures_all_in_scope_lifetimes(opaque);
532 if capture_all_in_scope_lifetimes {
533 let tcx = self.tcx;
534 let lifetime_ident = |def_id: LocalDefId| {
535 let name = tcx.item_name(def_id.to_def_id());
536 let span = tcx.def_span(def_id);
537 Ident::new(name, span)
538 };
539
540 let mut late_depth = 0;
544 let mut scope = self.scope;
545 let mut opaque_capture_scopes = vec![(opaque.def_id, &captures)];
546 loop {
547 match *scope {
548 Scope::Binder { ref bound_vars, scope_type, s, .. } => {
549 for (&original_lifetime, &def) in bound_vars.iter().rev() {
550 if let DefKind::LifetimeParam = self.tcx.def_kind(original_lifetime) {
551 let def = def.shifted(late_depth);
552 let ident = lifetime_ident(original_lifetime);
553 self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
554 }
555 }
556 match scope_type {
557 BinderScopeType::Normal => late_depth += 1,
558 BinderScopeType::Concatenating => {}
559 }
560 scope = s;
561 }
562
563 Scope::Root { mut opt_parent_item } => {
564 while let Some(parent_item) = opt_parent_item {
565 let parent_generics = self.tcx.generics_of(parent_item);
566 for param in parent_generics.own_params.iter().rev() {
567 if let ty::GenericParamDefKind::Lifetime = param.kind {
568 let def = ResolvedArg::EarlyBound(param.def_id.expect_local());
569 let ident = lifetime_ident(param.def_id.expect_local());
570 self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
571 }
572 }
573 opt_parent_item = parent_generics.parent.and_then(DefId::as_local);
574 }
575 break;
576 }
577
578 Scope::Opaque { captures, def_id, s } => {
579 opaque_capture_scopes.push((def_id, captures));
580 late_depth = 0;
581 scope = s;
582 }
583
584 Scope::Body { .. } => {
585 bug!("{:?}", scope)
586 }
587
588 Scope::ObjectLifetimeDefault { s, .. }
589 | Scope::Supertrait { s, .. }
590 | Scope::TraitRefBoundary { s, .. }
591 | Scope::LateBoundary { s, .. } => {
592 scope = s;
593 }
594 }
595 }
596 captures.borrow_mut().reverse();
597 }
598
599 let scope = Scope::Opaque { captures: &captures, def_id: opaque.def_id, s: self.scope };
600 self.with(scope, |this| {
601 let scope = Scope::TraitRefBoundary { s: this.scope };
602 this.with(scope, |this| {
603 let scope = Scope::LateBoundary {
604 s: this.scope,
605 what: "nested `impl Trait`",
606 deny_late_regions: false,
609 };
610 this.with(scope, |this| intravisit::walk_opaque_ty(this, opaque))
611 })
612 });
613
614 self.emit_opaque_capture_errors();
615
616 let captures = captures.into_inner().into_iter().collect();
617 debug!(?captures);
618 self.rbv.opaque_captured_lifetimes.insert(opaque.def_id, captures);
619 }
620
621 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(621u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["item"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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));
}
}
}
}
}#[instrument(level = "debug", skip(self))]
622 fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
623 if let hir::ItemKind::Impl(impl_) = item.kind
624 && let Some(of_trait) = impl_.of_trait
625 {
626 self.record_late_bound_vars(of_trait.trait_ref.hir_ref_id, Vec::default());
627 }
628 match item.kind {
629 hir::ItemKind::Fn { generics, .. } => {
630 self.visit_early_late(item.hir_id(), generics, |this| {
631 intravisit::walk_item(this, item);
632 });
633 }
634
635 hir::ItemKind::ExternCrate(..)
636 | hir::ItemKind::Use(..)
637 | hir::ItemKind::Macro(..)
638 | hir::ItemKind::Mod(..)
639 | hir::ItemKind::ForeignMod { .. }
640 | hir::ItemKind::Static(..)
641 | hir::ItemKind::GlobalAsm { .. } => {
642 intravisit::walk_item(self, item);
644 }
645 hir::ItemKind::TyAlias(_, generics, _)
646 | hir::ItemKind::Const(_, generics, _, _)
647 | hir::ItemKind::Enum(_, generics, _)
648 | hir::ItemKind::Struct(_, generics, _)
649 | hir::ItemKind::Union(_, generics, _)
650 | hir::ItemKind::Trait { generics, .. }
651 | hir::ItemKind::TraitAlias(_, _, generics, ..)
652 | hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
653 self.visit_early(item.hir_id(), generics, |this| intravisit::walk_item(this, item));
655 }
656 }
657 }
658
659 fn visit_precise_capturing_arg(
660 &mut self,
661 arg: &'tcx hir::PreciseCapturingArg<'tcx>,
662 ) -> Self::Result {
663 match *arg {
664 hir::PreciseCapturingArg::Lifetime(lt) => match lt.kind {
665 LifetimeKind::Param(def_id) => {
666 self.resolve_lifetime_ref(def_id, lt);
667 }
668 LifetimeKind::Error(..) => {}
669 LifetimeKind::ImplicitObjectLifetimeDefault
670 | LifetimeKind::Infer
671 | LifetimeKind::Static => {
672 self.tcx.dcx().emit_err(diagnostics::BadPreciseCapture {
673 span: lt.ident.span,
674 kind: "lifetime",
675 found: ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", lt.ident.name))
})format!("`{}`", lt.ident.name),
676 });
677 }
678 },
679 hir::PreciseCapturingArg::Param(param) => match param.res {
680 Res::Def(DefKind::TyParam | DefKind::ConstParam, def_id)
681 | Res::SelfTyParam { trait_: def_id } => {
682 self.resolve_type_ref(def_id.expect_local(), param.hir_id);
683 }
684 Res::SelfTyAlias { alias_to, .. } => {
685 self.tcx.dcx().emit_err(diagnostics::PreciseCaptureSelfAlias {
686 span: param.ident.span,
687 self_span: self.tcx.def_span(alias_to),
688 what: self.tcx.def_descr(alias_to),
689 });
690 }
691 res => {
692 self.tcx.dcx().span_delayed_bug(
693 param.ident.span,
694 ::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:?}"),
695 );
696 }
697 },
698 }
699 }
700
701 fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
702 match item.kind {
703 hir::ForeignItemKind::Fn(_, _, generics) => {
704 self.visit_early_late(item.hir_id(), generics, |this| {
705 intravisit::walk_foreign_item(this, item);
706 })
707 }
708 hir::ForeignItemKind::Static(..) => {
709 intravisit::walk_foreign_item(self, item);
710 }
711 hir::ForeignItemKind::Type => {
712 intravisit::walk_foreign_item(self, item);
713 }
714 }
715 }
716
717 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(717u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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 compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:780",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(780u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["message", "bounds",
"lifetime"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("TraitObject")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&bounds) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&lifetime)
as &dyn 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 mt) => {
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(mt.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))]
718 fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
719 match ty.kind {
720 hir::TyKind::FnPtr(c) => {
721 let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) = c
722 .generic_params
723 .iter()
724 .enumerate()
725 .map(|(late_bound_idx, param)| {
726 (
727 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
728 late_arg_as_bound_arg(param),
729 )
730 })
731 .unzip();
732
733 deny_non_region_late_bound(self.tcx, &mut bound_vars, "function pointer types");
734
735 self.record_late_bound_vars(ty.hir_id, binders);
736 let scope = Scope::Binder {
737 hir_id: ty.hir_id,
738 bound_vars,
739 s: self.scope,
740 scope_type: BinderScopeType::Normal,
741 where_bound_origin: None,
742 };
743 self.with(scope, |this| {
744 intravisit::walk_ty(this, ty);
746 });
747 }
748 hir::TyKind::UnsafeBinder(binder) => {
749 let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
750 binder
751 .generic_params
752 .iter()
753 .enumerate()
754 .map(|(late_bound_idx, param)| {
755 (
756 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
757 late_arg_as_bound_arg(param),
758 )
759 })
760 .unzip();
761
762 deny_non_region_late_bound(self.tcx, &mut bound_vars, "function pointer types");
763
764 self.record_late_bound_vars(ty.hir_id, binders);
765 let scope = Scope::Binder {
766 hir_id: ty.hir_id,
767 bound_vars,
768 s: self.scope,
769 scope_type: BinderScopeType::Normal,
770 where_bound_origin: None,
771 };
772 self.with(scope, |this| {
773 intravisit::walk_ty(this, ty);
775 });
776 }
777 hir::TyKind::TraitObject(bounds, lifetime) => {
778 let lifetime = lifetime.pointer();
779
780 debug!(?bounds, ?lifetime, "TraitObject");
781 let scope = Scope::TraitRefBoundary { s: self.scope };
782 self.with(scope, |this| {
783 for bound in bounds {
784 this.visit_poly_trait_ref_inner(
785 bound,
786 NonLifetimeBinderAllowed::Deny("trait object types"),
787 );
788 }
789 });
790 match lifetime.kind {
791 LifetimeKind::ImplicitObjectLifetimeDefault => {
792 self.resolve_object_lifetime_default(&*lifetime);
796 }
797 LifetimeKind::Infer => {
798 }
804 LifetimeKind::Param(..) | LifetimeKind::Static => {
805 self.visit_lifetime(&*lifetime);
807 }
808 LifetimeKind::Error(..) => {}
809 }
810 }
811 hir::TyKind::Ref(lifetime_ref, ref mt) => {
812 self.visit_lifetime(lifetime_ref);
813 let scope = Scope::ObjectLifetimeDefault {
814 lifetime: self.rbv.defs.get(&lifetime_ref.hir_id.local_id).copied(),
815 s: self.scope,
816 };
817 self.with(scope, |this| this.visit_ty_unambig(mt.ty));
818 }
819 hir::TyKind::TraitAscription(bounds) => {
820 let scope = Scope::TraitRefBoundary { s: self.scope };
821 self.with(scope, |this| {
822 let scope = Scope::LateBoundary {
823 s: this.scope,
824 what: "`impl Trait` in binding",
825 deny_late_regions: true,
826 };
827 this.with(scope, |this| {
828 for bound in bounds {
829 this.visit_param_bound(bound);
830 }
831 })
832 });
833 }
834 _ => intravisit::walk_ty(self, ty),
835 }
836 }
837
838 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(838u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["p"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&p)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{ intravisit::walk_ty_pat(self, p) }
}
}#[instrument(level = "debug", skip(self))]
839 fn visit_pattern_type_pattern(&mut self, p: &'tcx hir::TyPat<'tcx>) {
840 intravisit::walk_ty_pat(self, p)
841 }
842
843 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(843u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["trait_item"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_item)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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))]
844 fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
845 use self::hir::TraitItemKind::*;
846 match trait_item.kind {
847 Fn(_, _) => {
848 self.visit_early_late(trait_item.hir_id(), trait_item.generics, |this| {
849 intravisit::walk_trait_item(this, trait_item)
850 });
851 }
852 Type(bounds, ty) => {
853 self.visit_early(trait_item.hir_id(), trait_item.generics, |this| {
854 this.visit_generics(trait_item.generics);
855 for bound in bounds {
856 this.visit_param_bound(bound);
857 }
858 if let Some(ty) = ty {
859 this.visit_ty_unambig(ty);
860 }
861 })
862 }
863 Const(_, _) => self.visit_early(trait_item.hir_id(), trait_item.generics, |this| {
864 intravisit::walk_trait_item(this, trait_item)
865 }),
866 }
867 }
868
869 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(869u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["impl_item"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_item)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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))]
870 fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
871 use self::hir::ImplItemKind::*;
872 match impl_item.kind {
873 Fn(..) => self.visit_early_late(impl_item.hir_id(), impl_item.generics, |this| {
874 intravisit::walk_impl_item(this, impl_item)
875 }),
876 Type(ty) => self.visit_early(impl_item.hir_id(), impl_item.generics, |this| {
877 this.visit_generics(impl_item.generics);
878 this.visit_ty_unambig(ty);
879 }),
880 Const(_, _) => self.visit_early(impl_item.hir_id(), impl_item.generics, |this| {
881 intravisit::walk_impl_item(this, impl_item)
882 }),
883 }
884 }
885
886 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(886u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["lifetime_ref"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime_ref)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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))]
887 fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
888 match lifetime_ref.kind {
889 hir::LifetimeKind::Static => {
890 self.insert_lifetime(lifetime_ref, ResolvedArg::StaticLifetime)
891 }
892 hir::LifetimeKind::Param(param_def_id) => {
893 self.resolve_lifetime_ref(param_def_id, lifetime_ref)
894 }
895 hir::LifetimeKind::Error(guar) => {
897 self.insert_lifetime(lifetime_ref, ResolvedArg::Error(guar))
898 }
899 hir::LifetimeKind::ImplicitObjectLifetimeDefault | hir::LifetimeKind::Infer => {}
901 }
902 }
903
904 fn visit_qpath(&mut self, qpath: &'tcx hir::QPath<'tcx>, id: HirId, _: Span) {
905 match qpath {
906 hir::QPath::Resolved(maybe_qself, path) => {
907 self.visit_path(path, id);
911 if let Some(qself) = maybe_qself {
912 let container =
913 self.eligible_container(path, RevSegIdx(1).reverse(path.segments));
914
915 let object_lifetime_defaults =
916 container.map_or(Vec::new(), |(def_id, segs)| {
917 let generics = self.tcx.generics_of(def_id);
918 self.compute_object_lifetime_defaults(generics, segs)
919 });
920
921 if let Some(<) = object_lifetime_defaults.first() {
922 let scope = Scope::ObjectLifetimeDefault { lifetime: lt, s: self.scope };
923 self.with(scope, |this| this.visit_ty_unambig(qself));
924 } else {
925 self.visit_ty_unambig(qself);
926 }
927 }
928 }
929 hir::QPath::TypeRelative(qself, segment) => {
930 let scope = Scope::ObjectLifetimeDefault { lifetime: None, s: self.scope };
940 self.with(scope, |this| {
941 this.visit_ty_unambig(qself);
942 this.visit_path_segment(segment)
943 });
944 }
945 }
946 }
947
948 fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) {
949 for (index, segment) in path.segments.iter().enumerate() {
950 if let Some(args) = segment.args {
951 self.visit_path_segment_args(args, SegIdx(index), path);
952 }
953 }
954 if let Res::Def(DefKind::TyParam | DefKind::ConstParam, param_def_id) = path.res {
955 self.resolve_type_ref(param_def_id.expect_local(), hir_id);
956 }
957 }
958
959 fn visit_fn(
960 &mut self,
961 fk: intravisit::FnKind<'tcx>,
962 fd: &'tcx hir::FnDecl<'tcx>,
963 body_id: hir::BodyId,
964 _: Span,
965 def_id: LocalDefId,
966 ) {
967 let output = match fd.output {
968 hir::FnRetTy::DefaultReturn(_) => None,
969 hir::FnRetTy::Return(ty) => Some(ty),
970 };
971 if let Some(ty) = output
972 && let hir::TyKind::InferDelegation(hir::InferDelegation::Sig(sig_id, _)) = ty.kind
973 {
974 let bound_vars: Vec<_> =
975 self.tcx.fn_sig(sig_id).skip_binder().bound_vars().iter().collect();
976 let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
977 self.rbv.late_bound_vars.insert(hir_id.local_id, bound_vars);
978 }
979 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));
980 intravisit::walk_fn_kind(self, fk);
981 self.visit_nested_body(body_id)
982 }
983
984 fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
985 let scope = Scope::TraitRefBoundary { s: self.scope };
986 self.with(scope, |this| {
987 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);
988 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);
989 })
990 }
991
992 fn visit_where_predicate(&mut self, predicate: &'tcx hir::WherePredicate<'tcx>) {
993 let hir_id = predicate.hir_id;
994 match predicate.kind {
995 &hir::WherePredicateKind::BoundPredicate(hir::WhereBoundPredicate {
996 bounded_ty,
997 bounds,
998 bound_generic_params,
999 origin,
1000 ..
1001 }) => {
1002 let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
1003 bound_generic_params
1004 .iter()
1005 .enumerate()
1006 .map(|(late_bound_idx, param)| {
1007 (
1008 (param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
1009 late_arg_as_bound_arg(param),
1010 )
1011 })
1012 .unzip();
1013
1014 self.record_late_bound_vars(hir_id, binders);
1015
1016 self.try_append_return_type_notation_params(hir_id, bounded_ty);
1018
1019 let scope = Scope::Binder {
1024 hir_id,
1025 bound_vars,
1026 s: self.scope,
1027 scope_type: BinderScopeType::Normal,
1028 where_bound_origin: Some(origin),
1029 };
1030 self.with(scope, |this| {
1031 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);
1032 this.visit_ty_unambig(bounded_ty);
1033 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);
1034 })
1035 }
1036 &hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
1037 lifetime,
1038 bounds,
1039 ..
1040 }) => {
1041 self.visit_lifetime(lifetime);
1042 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);
1043 }
1044 }
1045 }
1046
1047 fn visit_poly_trait_ref(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) {
1048 self.visit_poly_trait_ref_inner(trait_ref, NonLifetimeBinderAllowed::Allow);
1049 }
1050
1051 fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
1052 self.with(
1053 Scope::LateBoundary { s: self.scope, what: "constant", deny_late_regions: true },
1054 |this| {
1055 intravisit::walk_anon_const(this, c);
1056 },
1057 );
1058 }
1059
1060 fn visit_generic_param(&mut self, p: &'tcx GenericParam<'tcx>) {
1061 match p.kind {
1062 GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1063 self.resolve_type_ref(p.def_id, p.hir_id);
1064 }
1065 GenericParamKind::Lifetime { .. } => {
1066 }
1069 }
1070
1071 match p.kind {
1072 GenericParamKind::Lifetime { .. } => {}
1073 GenericParamKind::Type { default, .. } => {
1074 if let Some(ty) = default {
1075 self.visit_ty_unambig(ty);
1076 }
1077 }
1078 GenericParamKind::Const { ty, default, .. } => {
1079 self.visit_ty_unambig(ty);
1080 if let Some(default) = default {
1081 self.visit_const_arg_unambig(default);
1082 }
1083 }
1084 }
1085 }
1086}
1087
1088fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectLifetimeDefault {
1089 let Ok((generics, bounds)) = (match tcx.hir_node_by_def_id(param_def_id) {
1093 hir::Node::GenericParam(param) => match param.source {
1094 hir::GenericParamSource::Generics => match param.kind {
1095 GenericParamKind::Type { .. } => {
1096 Ok((tcx.hir_get_generics(tcx.local_parent(param_def_id)).unwrap(), &[][..]))
1097 }
1098 _ => Err(()),
1099 },
1100 hir::GenericParamSource::Binder => return ObjectLifetimeDefault::Empty,
1101 },
1102 hir::Node::Item(&hir::Item {
1104 kind: hir::ItemKind::Trait { generics, bounds, .. }, ..
1105 }) => Ok((generics, bounds)),
1106 _ => Err(()),
1107 }) else {
1108 ::rustc_middle::util::bug::bug_fmt(format_args!("`object_lifetime_default` must only be called on type parameters"))bug!("`object_lifetime_default` must only be called on type parameters")
1109 };
1110
1111 let mut set = Set1::Empty;
1112
1113 let mut add_outlives_bounds = |bounds: &[hir::GenericBound<'_>]| {
1114 for bound in bounds {
1115 if let hir::GenericBound::Outlives(lifetime) = bound {
1116 set.insert(lifetime.kind);
1117 }
1118 }
1119 };
1120
1121 add_outlives_bounds(bounds);
1122
1123 for bound in generics.bounds_for_param(param_def_id) {
1125 if bound.bound_generic_params.is_empty() {
1128 add_outlives_bounds(&bound.bounds);
1129 }
1130 }
1131
1132 match set {
1133 Set1::Empty => ObjectLifetimeDefault::Empty,
1134 Set1::One(hir::LifetimeKind::Static) => ObjectLifetimeDefault::Static,
1135 Set1::One(hir::LifetimeKind::Param(param_def_id)) => {
1136 ObjectLifetimeDefault::Param(param_def_id.to_def_id())
1137 }
1138 _ => ObjectLifetimeDefault::Ambiguous,
1139 }
1140}
1141
1142impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1143 fn with<F>(&mut self, wrap_scope: Scope<'_, 'tcx>, f: F)
1144 where
1145 F: for<'b> FnOnce(&mut BoundVarContext<'b, 'tcx>),
1146 {
1147 let BoundVarContext { tcx, rbv, disambiguators, .. } = self;
1148 let nested_errors = RefCell::new(self.opaque_capture_errors.borrow_mut().take());
1149 let mut this = BoundVarContext {
1150 tcx: *tcx,
1151 rbv,
1152 disambiguators,
1153 scope: &wrap_scope,
1154 opaque_capture_errors: nested_errors,
1155 };
1156 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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1156u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["scope"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() } &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&this.scope.debug_truncated())
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
}debug_span!("scope", scope = ?this.scope.debug_truncated());
1157 {
1158 let _enter = span.enter();
1159 f(&mut this);
1160 }
1161 *self.opaque_capture_errors.borrow_mut() = this.opaque_capture_errors.into_inner();
1162 }
1163
1164 fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind<'tcx>>) {
1165 if let Some(old) = self.rbv.late_bound_vars.insert(hir_id.local_id, binder) {
1166 ::rustc_middle::util::bug::bug_fmt(format_args!("overwrote bound vars for {1:?}:\nold={2:?}\nnew={0:?}",
self.rbv.late_bound_vars[&hir_id.local_id], hir_id, old))bug!(
1167 "overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
1168 self.rbv.late_bound_vars[&hir_id.local_id]
1169 )
1170 }
1171 }
1172
1173 fn visit_early_late<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1192 where
1193 F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
1194 {
1195 let mut named_late_bound_vars = 0;
1196 let bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = generics
1197 .params
1198 .iter()
1199 .map(|param| {
1200 (
1201 param.def_id,
1202 match param.kind {
1203 GenericParamKind::Lifetime { .. } => {
1204 if self.tcx.is_late_bound(param.hir_id) {
1205 let late_bound_idx = named_late_bound_vars;
1206 named_late_bound_vars += 1;
1207 ResolvedArg::late(late_bound_idx, param)
1208 } else {
1209 ResolvedArg::early(param)
1210 }
1211 }
1212 GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1213 ResolvedArg::early(param)
1214 }
1215 },
1216 )
1217 })
1218 .collect();
1219
1220 let binders: Vec<_> = generics
1221 .params
1222 .iter()
1223 .filter(|param| {
1224 #[allow(non_exhaustive_omitted_patterns)] match param.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(param.kind, GenericParamKind::Lifetime { .. })
1225 && self.tcx.is_late_bound(param.hir_id)
1226 })
1227 .map(|param| late_arg_as_bound_arg(param))
1228 .collect();
1229 self.record_late_bound_vars(hir_id, binders);
1230 let scope = Scope::Binder {
1231 hir_id,
1232 bound_vars,
1233 s: self.scope,
1234 scope_type: BinderScopeType::Normal,
1235 where_bound_origin: None,
1236 };
1237 self.with(scope, walk);
1238 }
1239
1240 fn visit_early<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1241 where
1242 F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
1243 {
1244 let bound_vars =
1245 generics.params.iter().map(|param| (param.def_id, ResolvedArg::early(param))).collect();
1246 self.record_late_bound_vars(hir_id, ::alloc::vec::Vec::new()vec![]);
1247 let scope = Scope::Binder {
1248 hir_id,
1249 bound_vars,
1250 s: self.scope,
1251 scope_type: BinderScopeType::Normal,
1252 where_bound_origin: None,
1253 };
1254 self.with(scope, |this| {
1255 let scope = Scope::TraitRefBoundary { s: this.scope };
1256 this.with(scope, walk)
1257 });
1258 }
1259
1260 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1260u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["region_def_id",
"lifetime_ref"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(®ion_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime_ref)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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::errors::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_middle::util::bug::span_bug_fmt(use_span,
format_args!("did not expect to resolve lifetime to {0}",
kind.descr(param_def_id.to_def_id()))),
};
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))]
1261 fn resolve_lifetime_ref(
1262 &mut self,
1263 region_def_id: LocalDefId,
1264 lifetime_ref: &'tcx hir::Lifetime,
1265 ) {
1266 let mut late_depth = 0;
1271 let mut scope = self.scope;
1272 let mut outermost_body = None;
1273 let mut crossed_late_boundary = None;
1274 let mut opaque_capture_scopes = vec![];
1275 let result = loop {
1276 match *scope {
1277 Scope::Body { id, s } => {
1278 outermost_body = Some(id);
1279 scope = s;
1280 }
1281
1282 Scope::Root { opt_parent_item } => {
1283 if let Some(parent_item) = opt_parent_item
1284 && let parent_generics = self.tcx.generics_of(parent_item)
1285 && parent_generics
1286 .param_def_id_to_index(self.tcx, region_def_id.to_def_id())
1287 .is_some()
1288 {
1289 break Some(ResolvedArg::EarlyBound(region_def_id));
1290 }
1291 break None;
1292 }
1293
1294 Scope::Binder { ref bound_vars, scope_type, s, where_bound_origin, .. } => {
1295 if let Some(&def) = bound_vars.get(®ion_def_id) {
1296 break Some(def.shifted(late_depth));
1297 }
1298 match scope_type {
1299 BinderScopeType::Normal => late_depth += 1,
1300 BinderScopeType::Concatenating => {}
1301 }
1302 if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
1305 && let hir::LifetimeKind::Param(param_id) = lifetime_ref.kind
1306 && let Some(generics) =
1307 self.tcx.hir_get_generics(self.tcx.local_parent(param_id))
1308 && let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
1309 && param.is_elided_lifetime()
1310 && !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
1311 && !self.tcx.features().anonymous_lifetime_in_impl_trait()
1312 {
1313 let mut diag: rustc_errors::Diag<'_> = rustc_session::errors::feature_err(
1314 &self.tcx.sess,
1315 sym::anonymous_lifetime_in_impl_trait,
1316 lifetime_ref.ident.span,
1317 "anonymous lifetimes in `impl Trait` are unstable",
1318 );
1319
1320 if let Some(generics) =
1321 self.tcx.hir_get_generics(lifetime_ref.hir_id.owner.def_id)
1322 {
1323 let new_param_sugg =
1324 if let Some(span) = generics.span_for_lifetime_suggestion() {
1325 (span, "'a, ".to_owned())
1326 } else {
1327 (generics.span, "<'a>".to_owned())
1328 };
1329
1330 let lifetime_sugg = lifetime_ref.suggestion("'a");
1331 let suggestions = vec![lifetime_sugg, new_param_sugg];
1332
1333 diag.span_label(
1334 lifetime_ref.ident.span,
1335 "expected named lifetime parameter",
1336 );
1337 diag.multipart_suggestion(
1338 "consider introducing a named lifetime parameter",
1339 suggestions,
1340 rustc_errors::Applicability::MaybeIncorrect,
1341 );
1342 }
1343
1344 diag.emit();
1345 return;
1346 }
1347 scope = s;
1348 }
1349
1350 Scope::Opaque { captures, def_id, s } => {
1351 opaque_capture_scopes.push((def_id, captures));
1352 late_depth = 0;
1353 scope = s;
1354 }
1355
1356 Scope::ObjectLifetimeDefault { s, .. }
1357 | Scope::Supertrait { s, .. }
1358 | Scope::TraitRefBoundary { s, .. } => {
1359 scope = s;
1360 }
1361
1362 Scope::LateBoundary { s, what, deny_late_regions } => {
1363 if deny_late_regions {
1364 crossed_late_boundary = Some(what);
1365 }
1366 scope = s;
1367 }
1368 }
1369 };
1370
1371 if let Some(mut def) = result {
1372 def = self.remap_opaque_captures(&opaque_capture_scopes, def, lifetime_ref.ident);
1373
1374 if let ResolvedArg::EarlyBound(..) = def {
1375 } else if let ResolvedArg::LateBound(_, _, param_def_id) = def
1377 && let Some(what) = crossed_late_boundary
1378 {
1379 let use_span = lifetime_ref.ident.span;
1380 let def_span = self.tcx.def_span(param_def_id);
1381 let guar = match self.tcx.def_kind(param_def_id) {
1382 DefKind::LifetimeParam => {
1383 self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Lifetime {
1384 use_span,
1385 def_span,
1386 what,
1387 })
1388 }
1389 kind => span_bug!(
1390 use_span,
1391 "did not expect to resolve lifetime to {}",
1392 kind.descr(param_def_id.to_def_id())
1393 ),
1394 };
1395 def = ResolvedArg::Error(guar);
1396 } else if let Some(body_id) = outermost_body {
1397 let fn_id = self.tcx.hir_body_owner(body_id);
1398 match self.tcx.hir_node(fn_id) {
1399 Node::Item(hir::Item { owner_id, kind: hir::ItemKind::Fn { .. }, .. })
1400 | Node::TraitItem(hir::TraitItem {
1401 owner_id,
1402 kind: hir::TraitItemKind::Fn(..),
1403 ..
1404 })
1405 | Node::ImplItem(hir::ImplItem {
1406 owner_id,
1407 kind: hir::ImplItemKind::Fn(..),
1408 ..
1409 }) => {
1410 def = ResolvedArg::Free(owner_id.def_id, def.id().unwrap());
1411 }
1412 Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) => {
1413 def = ResolvedArg::Free(closure.def_id, def.id().unwrap());
1414 }
1415 _ => {}
1416 }
1417 }
1418
1419 self.insert_lifetime(lifetime_ref, def);
1420 return;
1421 }
1422
1423 let mut scope = self.scope;
1433 loop {
1434 match *scope {
1435 Scope::Binder {
1436 where_bound_origin: Some(hir::PredicateOrigin::ImplTrait), ..
1437 } => {
1438 self.tcx.dcx().emit_err(diagnostics::LateBoundInApit::Lifetime {
1439 span: lifetime_ref.ident.span,
1440 param_span: self.tcx.def_span(region_def_id),
1441 });
1442 return;
1443 }
1444 Scope::Root { .. } => break,
1445 Scope::Binder { s, .. }
1446 | Scope::Body { s, .. }
1447 | Scope::Opaque { s, .. }
1448 | Scope::ObjectLifetimeDefault { s, .. }
1449 | Scope::Supertrait { s, .. }
1450 | Scope::TraitRefBoundary { s, .. }
1451 | Scope::LateBoundary { s, .. } => {
1452 scope = s;
1453 }
1454 }
1455 }
1456
1457 self.tcx.dcx().span_delayed_bug(
1458 lifetime_ref.ident.span,
1459 format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
1460 );
1461 }
1462
1463 fn check_lifetime_is_capturable(
1468 &self,
1469 opaque_def_id: LocalDefId,
1470 lifetime: ResolvedArg,
1471 capture_span: Span,
1472 ) -> Result<(), ErrorGuaranteed> {
1473 let ResolvedArg::LateBound(_, _, lifetime_def_id) = lifetime else { return Ok(()) };
1474 let lifetime_hir_id = self.tcx.local_def_id_to_hir_id(lifetime_def_id);
1475 let bad_place = match self.tcx.hir_node(self.tcx.parent_hir_id(lifetime_hir_id)) {
1476 hir::Node::OpaqueTy(_) => "higher-ranked lifetime from outer `impl Trait`",
1479 hir::Node::Item(_) | hir::Node::TraitItem(_) | hir::Node::ImplItem(_) => return Ok(()),
1481 hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(_), .. }) => {
1482 "higher-ranked lifetime from function pointer"
1483 }
1484 hir::Node::Ty(hir::Ty { kind: hir::TyKind::TraitObject(..), .. }) => {
1485 "higher-ranked lifetime from `dyn` type"
1486 }
1487 _ => "higher-ranked lifetime",
1488 };
1489
1490 let decl_span = self.tcx.def_span(lifetime_def_id);
1491 let opaque_span = self.tcx.def_span(opaque_def_id);
1492
1493 let mut errors = self.opaque_capture_errors.borrow_mut();
1494 let error_info = errors.get_or_insert_with(|| OpaqueHigherRankedLifetimeCaptureErrors {
1495 bad_place,
1496 capture_spans: Vec::new(),
1497 decl_spans: Vec::new(),
1498 });
1499
1500 if error_info.capture_spans.is_empty() {
1501 error_info.capture_spans.push(opaque_span);
1502 }
1503
1504 if capture_span != decl_span && capture_span != opaque_span {
1505 error_info.capture_spans.push(capture_span);
1506 }
1507
1508 if !error_info.decl_spans.contains(&decl_span) {
1509 error_info.decl_spans.push(decl_span);
1510 }
1511
1512 Err(self.tcx.dcx().span_delayed_bug(capture_span, "opaque capture error not emitted"))
1514 }
1515
1516 fn emit_opaque_capture_errors(&self) -> Option<ErrorGuaranteed> {
1517 let errors = self.opaque_capture_errors.borrow_mut().take()?;
1518 if errors.capture_spans.is_empty() {
1519 return None;
1520 }
1521
1522 let mut span = rustc_errors::MultiSpan::from_span(errors.capture_spans[0]);
1523 for &capture_span in &errors.capture_spans[1..] {
1524 span.push_span_label(capture_span, "");
1525 }
1526 let decl_span = rustc_errors::MultiSpan::from_spans(errors.decl_spans);
1527
1528 let guar = self.tcx.dcx().emit_err(diagnostics::OpaqueCapturesHigherRankedLifetime {
1530 span,
1531 label: Some(errors.capture_spans[0]),
1532 decl_span,
1533 bad_place: errors.bad_place,
1534 });
1535
1536 Some(guar)
1537 }
1538
1539 x;#[instrument(level = "trace", skip(self, opaque_capture_scopes), ret)]
1540 fn remap_opaque_captures(
1541 &mut self,
1542 opaque_capture_scopes: &Vec<(LocalDefId, &RefCell<FxIndexMap<ResolvedArg, LocalDefId>>)>,
1543 mut lifetime: ResolvedArg,
1544 ident: Ident,
1545 ) -> ResolvedArg {
1546 if let Some(&(opaque_def_id, _)) = opaque_capture_scopes.last() {
1547 if let Err(guar) =
1548 self.check_lifetime_is_capturable(opaque_def_id, lifetime, ident.span)
1549 {
1550 lifetime = ResolvedArg::Error(guar);
1551 }
1552 }
1553
1554 for &(opaque_def_id, captures) in opaque_capture_scopes.iter().rev() {
1555 let mut captures = captures.borrow_mut();
1556 let remapped = *captures.entry(lifetime).or_insert_with(|| {
1557 let feed = self.tcx.create_def(
1562 opaque_def_id,
1563 None,
1564 DefKind::LifetimeParam,
1565 Some(DefPathData::OpaqueLifetime(ident.name)),
1566 self.disambiguators.get_or_create(opaque_def_id),
1567 );
1568 feed.def_span(ident.span);
1569 feed.def_ident_span(Some(ident.span));
1570 feed.def_id()
1571 });
1572 lifetime = ResolvedArg::EarlyBound(remapped);
1573 }
1574 lifetime
1575 }
1576
1577 fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: HirId) {
1578 let mut late_depth = 0;
1583 let mut scope = self.scope;
1584 let mut crossed_late_boundary = None;
1585
1586 let result = loop {
1587 match *scope {
1588 Scope::Body { s, .. } => {
1589 scope = s;
1590 }
1591
1592 Scope::Root { opt_parent_item } => {
1593 if let Some(parent_item) = opt_parent_item
1594 && let parent_generics = self.tcx.generics_of(parent_item)
1595 && parent_generics
1596 .param_def_id_to_index(self.tcx, param_def_id.to_def_id())
1597 .is_some()
1598 {
1599 break Some(ResolvedArg::EarlyBound(param_def_id));
1600 }
1601 break None;
1602 }
1603
1604 Scope::Binder { ref bound_vars, scope_type, s, .. } => {
1605 if let Some(&def) = bound_vars.get(¶m_def_id) {
1606 break Some(def.shifted(late_depth));
1607 }
1608 match scope_type {
1609 BinderScopeType::Normal => late_depth += 1,
1610 BinderScopeType::Concatenating => {}
1611 }
1612 scope = s;
1613 }
1614
1615 Scope::ObjectLifetimeDefault { s, .. }
1616 | Scope::Opaque { s, .. }
1617 | Scope::Supertrait { s, .. }
1618 | Scope::TraitRefBoundary { s, .. } => {
1619 scope = s;
1620 }
1621
1622 Scope::LateBoundary { s, what, deny_late_regions: _ } => {
1623 crossed_late_boundary = Some(what);
1624 scope = s;
1625 }
1626 }
1627 };
1628
1629 if let Some(def) = result {
1630 if let ResolvedArg::LateBound(..) = def
1631 && let Some(what) = crossed_late_boundary
1632 {
1633 let use_span = self.tcx.hir_span(hir_id);
1634 let def_span = self.tcx.def_span(param_def_id);
1635 let guar = match self.tcx.def_kind(param_def_id) {
1636 DefKind::ConstParam => {
1637 self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Const {
1638 use_span,
1639 def_span,
1640 what,
1641 })
1642 }
1643 DefKind::TyParam => {
1644 self.tcx.dcx().emit_err(diagnostics::CannotCaptureLateBound::Type {
1645 use_span,
1646 def_span,
1647 what,
1648 })
1649 }
1650 kind => ::rustc_middle::util::bug::span_bug_fmt(use_span,
format_args!("did not expect to resolve non-lifetime param to {0}",
kind.descr(param_def_id.to_def_id())))span_bug!(
1651 use_span,
1652 "did not expect to resolve non-lifetime param to {}",
1653 kind.descr(param_def_id.to_def_id())
1654 ),
1655 };
1656 self.rbv.defs.insert(hir_id.local_id, ResolvedArg::Error(guar));
1657 } else {
1658 self.rbv.defs.insert(hir_id.local_id, def);
1659 }
1660 return;
1661 }
1662
1663 let mut scope = self.scope;
1673 loop {
1674 match *scope {
1675 Scope::Binder {
1676 where_bound_origin: Some(hir::PredicateOrigin::ImplTrait), ..
1677 } => {
1678 let guar = self.tcx.dcx().emit_err(match self.tcx.def_kind(param_def_id) {
1679 DefKind::TyParam => diagnostics::LateBoundInApit::Type {
1680 span: self.tcx.hir_span(hir_id),
1681 param_span: self.tcx.def_span(param_def_id),
1682 },
1683 DefKind::ConstParam => diagnostics::LateBoundInApit::Const {
1684 span: self.tcx.hir_span(hir_id),
1685 param_span: self.tcx.def_span(param_def_id),
1686 },
1687 kind => {
1688 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected def-kind: {0}",
kind.descr(param_def_id.to_def_id())))bug!("unexpected def-kind: {}", kind.descr(param_def_id.to_def_id()))
1689 }
1690 });
1691 self.rbv.defs.insert(hir_id.local_id, ResolvedArg::Error(guar));
1692 return;
1693 }
1694 Scope::Root { .. } => break,
1695 Scope::Binder { s, .. }
1696 | Scope::Body { s, .. }
1697 | Scope::Opaque { s, .. }
1698 | Scope::ObjectLifetimeDefault { s, .. }
1699 | Scope::Supertrait { s, .. }
1700 | Scope::TraitRefBoundary { s, .. }
1701 | Scope::LateBoundary { s, .. } => {
1702 scope = s;
1703 }
1704 }
1705 }
1706
1707 self.tcx
1708 .dcx()
1709 .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:?}"));
1710 }
1711
1712 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1712u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["generic_args",
"seg_idx", "path"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generic_args)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&seg_idx)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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 compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1733",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(1733u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["container"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&container)
as &dyn 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 compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1743",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("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(&["object_lifetime_defaults"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&object_lifetime_defaults)
as &dyn 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)));
bound_vars.extend(self.tcx.fn_sig(assoc_fn.def_id).instantiate_identity().skip_norm_wip().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))]
1713 fn visit_path_segment_args(
1714 &mut self,
1715 generic_args: &'tcx hir::GenericArgs<'tcx>,
1716 seg_idx: SegIdx,
1717 path: &hir::Path<'tcx>,
1718 ) {
1719 if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
1720 self.visit_fn_like_elision(inputs, Some(output), false);
1721 return;
1722 }
1723
1724 for arg in generic_args.args {
1727 if let hir::GenericArg::Lifetime(lt) = arg {
1728 self.visit_lifetime(lt);
1729 }
1730 }
1731
1732 let container = self.eligible_container(path, seg_idx);
1733 debug!(?container);
1734
1735 let (has_self, object_lifetime_defaults) = container
1736 .map(|(def_id, segs)| {
1737 let generics = self.tcx.generics_of(def_id);
1738 let defaults = self.compute_object_lifetime_defaults(generics, segs);
1739 (generics.has_own_self(), defaults)
1740 })
1741 .unwrap_or_default();
1742
1743 debug!(?object_lifetime_defaults);
1744
1745 let mut i = has_self as usize;
1746 for arg in generic_args.args {
1747 match arg {
1748 GenericArg::Lifetime(_) => {}
1750 GenericArg::Type(ty) => {
1751 if let Some(<) = object_lifetime_defaults.get(i) {
1752 let scope = Scope::ObjectLifetimeDefault { lifetime: lt, s: self.scope };
1753 self.with(scope, |this| this.visit_ty(ty));
1754 } else {
1755 self.visit_ty(ty);
1756 }
1757 i += 1;
1758 }
1759 GenericArg::Const(ct) => {
1760 self.visit_const_arg(ct);
1761 i += 1;
1762 }
1763 GenericArg::Infer(inf) => {
1764 self.visit_id(inf.hir_id);
1765 i += 1;
1766 }
1767 }
1768 }
1769
1770 let has_lifetime_args = generic_args.has_lifetime_args();
1771
1772 for constraint in generic_args.constraints {
1773 let scope = Scope::ObjectLifetimeDefault {
1774 lifetime: if has_lifetime_args || constraint.gen_args.has_lifetime_args() {
1807 None
1808 } else {
1809 Some(ResolvedArg::StaticLifetime)
1810 },
1811 s: self.scope,
1812 };
1813 if constraint.gen_args.parenthesized == hir::GenericArgsParentheses::ReturnTypeNotation
1827 {
1828 let bound_vars = if let Some((container_def_id, _)) = container
1829 && let DefKind::Trait | DefKind::TraitAlias =
1830 self.tcx.def_kind(container_def_id)
1831 && let Some((mut bound_vars, assoc_fn)) = BoundVarContext::supertrait_hrtb_vars(
1832 self.tcx,
1833 container_def_id,
1834 constraint.ident,
1835 ty::AssocTag::Fn,
1836 ) {
1837 bound_vars.extend(
1838 self.tcx
1839 .generics_of(assoc_fn.def_id)
1840 .own_params
1841 .iter()
1842 .map(|param| generic_param_def_as_bound_arg(param)),
1843 );
1844 bound_vars.extend(
1845 self.tcx
1846 .fn_sig(assoc_fn.def_id)
1847 .instantiate_identity()
1848 .skip_norm_wip()
1849 .bound_vars(),
1850 );
1851 bound_vars
1852 } else {
1853 self.tcx
1854 .dcx()
1855 .span_delayed_bug(constraint.ident.span, "bad return type notation here");
1856 vec![]
1857 };
1858 self.with(scope, |this| {
1859 let scope = Scope::Supertrait { bound_vars, s: this.scope };
1860 this.with(scope, |this| {
1861 let (bound_vars, _) = this.poly_trait_ref_binder_info();
1862 this.record_late_bound_vars(constraint.hir_id, bound_vars);
1863 this.visit_assoc_item_constraint(constraint)
1864 });
1865 });
1866 } else if let Some((container_def_id, _)) = container {
1867 let bound_vars = BoundVarContext::supertrait_hrtb_vars(
1868 self.tcx,
1869 container_def_id,
1870 constraint.ident,
1871 ty::AssocTag::Type,
1872 )
1873 .map(|(bound_vars, _)| bound_vars);
1874 self.with(scope, |this| {
1875 let scope = Scope::Supertrait {
1876 bound_vars: bound_vars.unwrap_or_default(),
1877 s: this.scope,
1878 };
1879 this.with(scope, |this| this.visit_assoc_item_constraint(constraint));
1880 });
1881 } else {
1882 self.with(scope, |this| this.visit_assoc_item_constraint(constraint));
1883 }
1884 }
1885 }
1886
1887 fn eligible_container<'b>(
1893 &self,
1894 path: &'b hir::Path<'tcx>,
1895 seg_idx: SegIdx,
1896 ) -> Option<(DefId, &'b [hir::PathSegment<'tcx>])> {
1897 let RevSegIdx(rev_seg_idx) = seg_idx.reverse(path.segments);
1898 let SegIdx(seg_idx) = seg_idx;
1899
1900 let (kind, def_id) = match path.res {
1907 Res::Def(kind, def_id) => (kind, def_id),
1908 Res::PrimTy(..)
1909 | Res::SelfTyParam { .. }
1910 | Res::SelfTyAlias { .. }
1911 | Res::SelfCtor(_)
1912 | Res::Local(_)
1913 | Res::ToolMod
1914 | Res::OpenMod(_)
1915 | Res::NonMacroAttr(_)
1916 | Res::Err => return None, };
1918
1919 match kind {
1920 DefKind::AssocTy => match rev_seg_idx {
1921 0 => Some((def_id, path.segments)),
1922 1 => Some((self.tcx.parent(def_id), &path.segments[..=seg_idx])),
1925 _ => None,
1926 },
1927 DefKind::Variant => match rev_seg_idx {
1928 0 => Some((self.tcx.parent(def_id), path.segments)),
1932 1 => Some((self.tcx.parent(def_id), &path.segments[..=seg_idx])),
1934 _ => None,
1935 },
1936 DefKind::Enum
1937 | DefKind::Struct
1938 | DefKind::Trait
1939 | DefKind::TraitAlias
1940 | DefKind::TyAlias
1941 | DefKind::Union => match rev_seg_idx {
1942 0 => Some((def_id, path.segments)),
1943 _ => None,
1944 },
1945 DefKind::AnonConst
1946 | DefKind::AssocConst { .. }
1947 | DefKind::AssocFn
1948 | DefKind::Closure
1949 | DefKind::Const { .. }
1950 | DefKind::ConstParam
1951 | DefKind::Ctor(..)
1952 | DefKind::ExternCrate
1953 | DefKind::Field
1954 | DefKind::Fn
1955 | DefKind::ForeignMod
1956 | DefKind::ForeignTy
1957 | DefKind::GlobalAsm
1958 | DefKind::Impl { .. }
1959 | DefKind::InlineConst
1960 | DefKind::LifetimeParam
1961 | DefKind::Macro(_)
1962 | DefKind::Mod
1963 | DefKind::OpaqueTy
1964 | DefKind::Static { .. }
1965 | DefKind::SyntheticCoroutineBody
1966 | DefKind::TyParam
1967 | DefKind::Use => None, }
1969 }
1970
1971 fn compute_object_lifetime_defaults(
1988 &self,
1989 generics: &ty::Generics,
1990 segments: &[hir::PathSegment<'_>],
1991 ) -> Vec<Option<ResolvedArg>> {
1992 let in_body = {
1993 let mut scope = self.scope;
1994 loop {
1995 match *scope {
1996 Scope::Root { .. } => break false,
1997
1998 Scope::Body { .. } => break true,
1999
2000 Scope::Binder { s, .. }
2001 | Scope::ObjectLifetimeDefault { s, .. }
2002 | Scope::Opaque { s, .. }
2003 | Scope::Supertrait { s, .. }
2004 | Scope::TraitRefBoundary { s, .. }
2005 | Scope::LateBoundary { s, .. } => {
2006 scope = s;
2007 }
2008 }
2009 }
2010 };
2011
2012 let set_to_region = |set: ObjectLifetimeDefault| match set {
2013 ObjectLifetimeDefault::Empty => {
2014 if in_body {
2015 None
2016 } else {
2017 Some(ResolvedArg::StaticLifetime)
2018 }
2019 }
2020 ObjectLifetimeDefault::Static => Some(ResolvedArg::StaticLifetime),
2021 ObjectLifetimeDefault::Param(param_def_id) => {
2022 struct ArgIdx(usize);
2023
2024 fn resolve_param(
2025 param_def_id: DefId,
2026 generics: &ty::Generics,
2027 tcx: TyCtxt<'_>,
2028 ) -> (RevSegIdx, ArgIdx) {
2029 if let Some(&index) = generics.param_def_id_to_index.get(¶m_def_id) {
2030 let has_self = generics.has_own_self();
2031 let index = index as usize - generics.parent_count - has_self as usize;
2032 (RevSegIdx(0), ArgIdx(index))
2033 } else if let Some(parent) = generics.parent {
2034 let parent_generics = tcx.generics_of(parent);
2035 let (RevSegIdx(rev_seg_idx), arg_idx) =
2036 resolve_param(param_def_id, parent_generics, tcx);
2037 (RevSegIdx(rev_seg_idx + 1), arg_idx)
2038 } else {
2039 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
2040 }
2041 }
2042
2043 let (rev_seg_idx, ArgIdx(arg_idx)) =
2044 resolve_param(param_def_id, generics, self.tcx);
2045
2046 let SegIdx(seg_idx) = rev_seg_idx.reverse(segments);
2047
2048 segments[seg_idx].args.and_then(|args| args.args.get(arg_idx)).and_then(|arg| {
2049 match arg {
2050 GenericArg::Lifetime(lt) => self.rbv.defs.get(<.hir_id.local_id).copied(),
2051 _ => None,
2052 }
2053 })
2054 }
2055 ObjectLifetimeDefault::Ambiguous => None,
2056 };
2057 generics
2058 .own_params
2059 .iter()
2060 .filter_map(|param| {
2061 match self.tcx.def_kind(param.def_id) {
2074 DefKind::TyParam | DefKind::Trait => {
2075 Some(self.tcx.object_lifetime_default(param.def_id))
2076 }
2077 DefKind::ConstParam | DefKind::TraitAlias => Some(ObjectLifetimeDefault::Empty),
2078 DefKind::LifetimeParam => None,
2079 kind => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected def kind {0:?}",
kind))bug!("unexpected def kind {kind:?}"),
2080 }
2081 })
2082 .map(set_to_region)
2083 .collect()
2084 }
2085
2086 fn supertrait_hrtb_vars(
2099 tcx: TyCtxt<'tcx>,
2100 def_id: DefId,
2101 assoc_ident: Ident,
2102 assoc_tag: ty::AssocTag,
2103 ) -> Option<(Vec<ty::BoundVariableKind<'tcx>>, &'tcx ty::AssocItem)> {
2104 let trait_defines_associated_item_named = |trait_def_id: DefId| {
2105 tcx.associated_items(trait_def_id).find_by_ident_and_kind(
2106 tcx,
2107 assoc_ident,
2108 assoc_tag,
2109 trait_def_id,
2110 )
2111 };
2112
2113 use smallvec::{SmallVec, smallvec};
2114 let mut stack: SmallVec<[(DefId, SmallVec<[ty::BoundVariableKind<'tcx>; 8]>); 8]> =
2115 {
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![])];
2116 let mut visited: FxHashSet<DefId> = FxHashSet::default();
2117 loop {
2118 let Some((def_id, bound_vars)) = stack.pop() else {
2119 break None;
2120 };
2121 match tcx.def_kind(def_id) {
2124 DefKind::Trait | DefKind::TraitAlias | DefKind::Impl { .. } => {}
2125 _ => break None,
2126 }
2127
2128 if let Some(assoc_item) = trait_defines_associated_item_named(def_id) {
2129 break Some((bound_vars.into_iter().collect(), assoc_item));
2130 }
2131 let predicates = tcx.explicit_supertraits_containing_assoc_item((def_id, assoc_ident));
2132 let obligations = predicates
2133 .iter_identity_copied()
2134 .map(Unnormalized::skip_norm_wip)
2135 .filter_map(|(pred, _)| {
2136 let bound_predicate = pred.kind();
2137 match bound_predicate.skip_binder() {
2138 ty::ClauseKind::Trait(data) => {
2139 let pred_bound_vars = bound_predicate.bound_vars();
2142 let mut all_bound_vars = bound_vars.clone();
2143 all_bound_vars.extend(pred_bound_vars.iter());
2144 let super_def_id = data.trait_ref.def_id;
2145 Some((super_def_id, all_bound_vars))
2146 }
2147 _ => None,
2148 }
2149 });
2150
2151 let obligations = obligations.filter(|o| visited.insert(o.0));
2152 stack.extend(obligations);
2153 }
2154 }
2155
2156 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2156u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["inputs", "output",
"in_closure"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&inputs)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&in_closure as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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))]
2157 fn visit_fn_like_elision(
2158 &mut self,
2159 inputs: &'tcx [hir::Ty<'tcx>],
2160 output: Option<&'tcx hir::Ty<'tcx>>,
2161 in_closure: bool,
2162 ) {
2163 self.with(
2164 Scope::ObjectLifetimeDefault {
2165 lifetime: Some(ResolvedArg::StaticLifetime),
2166 s: self.scope,
2167 },
2168 |this| {
2169 for input in inputs {
2170 this.visit_ty_unambig(input);
2171 }
2172 if !in_closure && let Some(output) = output {
2173 this.visit_ty_unambig(output);
2174 }
2175 },
2176 );
2177 if in_closure && let Some(output) = output {
2178 self.visit_ty_unambig(output);
2179 }
2180 }
2181
2182 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2182u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["lifetime_ref"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime_ref)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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))]
2183 fn resolve_object_lifetime_default(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
2184 let mut late_depth = 0;
2185 let mut scope = self.scope;
2186 let mut opaque_capture_scopes = vec![];
2187 let mut lifetime = loop {
2188 match *scope {
2189 Scope::Binder { s, scope_type, .. } => {
2190 match scope_type {
2191 BinderScopeType::Normal => late_depth += 1,
2192 BinderScopeType::Concatenating => {}
2193 }
2194 scope = s;
2195 }
2196
2197 Scope::Root { .. } => break ResolvedArg::StaticLifetime,
2198
2199 Scope::Body { .. } | Scope::ObjectLifetimeDefault { lifetime: None, .. } => return,
2200
2201 Scope::ObjectLifetimeDefault { lifetime: Some(l), .. } => {
2202 break l.shifted(late_depth);
2203 }
2204
2205 Scope::Opaque { captures, def_id, s } => {
2206 opaque_capture_scopes.push((def_id, captures));
2207 late_depth = 0;
2208 scope = s;
2209 }
2210
2211 Scope::Supertrait { s, .. }
2212 | Scope::TraitRefBoundary { s, .. }
2213 | Scope::LateBoundary { s, .. } => {
2214 scope = s;
2215 }
2216 }
2217 };
2218
2219 lifetime = self.remap_opaque_captures(&opaque_capture_scopes, lifetime, lifetime_ref.ident);
2220
2221 self.insert_lifetime(lifetime_ref, lifetime);
2222 }
2223
2224 #[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("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2224u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["lifetime_ref",
"def"], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime_ref)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2226",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("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(&["span"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&lifetime_ref.ident.span)
as &dyn Value))])
});
} else { ; }
};
self.rbv.defs.insert(lifetime_ref.hir_id.local_id, def);
}
}
}#[instrument(level = "debug", skip(self))]
2225 fn insert_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime, def: ResolvedArg) {
2226 debug!(span = ?lifetime_ref.ident.span);
2227 self.rbv.defs.insert(lifetime_ref.hir_id.local_id, def);
2228 }
2229
2230 fn try_append_return_type_notation_params(
2249 &mut self,
2250 hir_id: HirId,
2251 hir_ty: &'tcx hir::Ty<'tcx>,
2252 ) {
2253 let hir::TyKind::Path(qpath) = hir_ty.kind else {
2254 return;
2258 };
2259
2260 let (mut bound_vars, item_def_id, item_segment) = match qpath {
2261 hir::QPath::Resolved(_, path)
2263 if let [.., item_segment] = &path.segments[..]
2264 && item_segment.args.is_some_and(|args| {
2265 #[allow(non_exhaustive_omitted_patterns)] match args.parenthesized {
hir::GenericArgsParentheses::ReturnTypeNotation => true,
_ => false,
}matches!(
2266 args.parenthesized,
2267 hir::GenericArgsParentheses::ReturnTypeNotation
2268 )
2269 }) =>
2270 {
2271 match path.res {
2272 Res::Err => return,
2273 Res::Def(DefKind::AssocFn, item_def_id) => (::alloc::vec::Vec::new()vec![], item_def_id, item_segment),
2274 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("only expected method resolution for fully qualified RTN"))bug!("only expected method resolution for fully qualified RTN"),
2275 }
2276 }
2277
2278 hir::QPath::TypeRelative(qself, item_segment)
2280 if item_segment.args.is_some_and(|args| {
2281 #[allow(non_exhaustive_omitted_patterns)] match args.parenthesized {
hir::GenericArgsParentheses::ReturnTypeNotation => true,
_ => false,
}matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
2282 }) =>
2283 {
2284 let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = qself.kind else {
2287 return;
2288 };
2289 match path.res {
2290 Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { trait_: _ } => {
2291 let mut bounds =
2292 self.for_each_trait_bound_on_res(path.res).filter_map(|trait_def_id| {
2293 BoundVarContext::supertrait_hrtb_vars(
2294 self.tcx,
2295 trait_def_id,
2296 item_segment.ident,
2297 ty::AssocTag::Fn,
2298 )
2299 });
2300
2301 let Some((bound_vars, assoc_item)) = bounds.next() else {
2302 self.tcx
2304 .dcx()
2305 .span_delayed_bug(path.span, "no resolution for RTN path");
2306 return;
2307 };
2308
2309 for (second_vars, second_assoc_item) in bounds {
2312 if second_vars != bound_vars || second_assoc_item != assoc_item {
2313 self.tcx.dcx().span_delayed_bug(
2315 path.span,
2316 "ambiguous resolution for RTN path",
2317 );
2318 return;
2319 }
2320 }
2321
2322 (bound_vars, assoc_item.def_id, item_segment)
2323 }
2324 Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. } => {
2327 let hir::ItemKind::Impl(hir::Impl { of_trait: Some(of_trait), .. }) = self
2328 .tcx
2329 .hir_node_by_def_id(impl_def_id.expect_local())
2330 .expect_item()
2331 .kind
2332 else {
2333 return;
2334 };
2335 let Some(trait_def_id) = of_trait.trait_ref.trait_def_id() else {
2336 return;
2337 };
2338 let Some((bound_vars, assoc_item)) = BoundVarContext::supertrait_hrtb_vars(
2339 self.tcx,
2340 trait_def_id,
2341 item_segment.ident,
2342 ty::AssocTag::Fn,
2343 ) else {
2344 return;
2345 };
2346 (bound_vars, assoc_item.def_id, item_segment)
2347 }
2348 _ => return,
2349 }
2350 }
2351
2352 _ => return,
2353 };
2354
2355 bound_vars.extend(
2359 self.tcx
2360 .generics_of(item_def_id)
2361 .own_params
2362 .iter()
2363 .map(|param| generic_param_def_as_bound_arg(param)),
2364 );
2365 bound_vars.extend(
2366 self.tcx.fn_sig(item_def_id).instantiate_identity().skip_norm_wip().bound_vars(),
2367 );
2368
2369 let existing_bound_vars = self.rbv.late_bound_vars.get_mut(&hir_id.local_id).unwrap();
2385 let existing_bound_vars_saved = existing_bound_vars.clone();
2386 existing_bound_vars.extend(bound_vars);
2387 self.record_late_bound_vars(item_segment.hir_id, existing_bound_vars_saved);
2388 }
2389
2390 fn for_each_trait_bound_on_res(&self, expected_res: Res) -> impl Iterator<Item = DefId> {
2393 gen move {
2394 let mut scope = self.scope;
2395 loop {
2396 let hir_id = match *scope {
2397 Scope::Binder { hir_id, .. } => Some(hir_id),
2398 Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2399 Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2400 }
2401 Scope::Body { .. }
2402 | Scope::ObjectLifetimeDefault { .. }
2403 | Scope::Supertrait { .. }
2404 | Scope::TraitRefBoundary { .. }
2405 | Scope::LateBoundary { .. }
2406 | Scope::Opaque { .. }
2407 | Scope::Root { opt_parent_item: None } => None,
2408 };
2409
2410 if let Some(hir_id) = hir_id {
2411 let node = self.tcx.hir_node(hir_id);
2412 if let Res::SelfTyParam { trait_: _ } = expected_res
2416 && let hir::Node::Item(item) = node
2417 && let hir::ItemKind::Trait { .. } = item.kind
2418 {
2419 yield item.owner_id.def_id.to_def_id();
2422 } else if let Some(generics) = node.generics() {
2423 for pred in generics.predicates {
2424 let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind else {
2425 continue;
2426 };
2427 let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2428 pred.bounded_ty.kind
2429 else {
2430 continue;
2431 };
2432 if bounded_path.res != expected_res {
2434 continue;
2435 }
2436 for pred in pred.bounds {
2437 match pred {
2438 hir::GenericBound::Trait(poly_trait_ref) => {
2439 if let Some(def_id) =
2440 poly_trait_ref.trait_ref.trait_def_id()
2441 {
2442 yield def_id;
2443 }
2444 }
2445 hir::GenericBound::Outlives(_)
2446 | hir::GenericBound::Use(_, _) => {}
2447 }
2448 }
2449 }
2450 }
2451 }
2452
2453 match *scope {
2454 Scope::Binder { s, .. }
2455 | Scope::Body { s, .. }
2456 | Scope::ObjectLifetimeDefault { s, .. }
2457 | Scope::Supertrait { s, .. }
2458 | Scope::TraitRefBoundary { s }
2459 | Scope::LateBoundary { s, .. }
2460 | Scope::Opaque { s, .. } => {
2461 scope = s;
2462 }
2463 Scope::Root { .. } => break,
2464 }
2465 }
2466 }
2467 }
2468}
2469
2470fn is_late_bound_map(
2481 tcx: TyCtxt<'_>,
2482 owner_id: hir::OwnerId,
2483) -> Option<&FxIndexSet<hir::ItemLocalId>> {
2484 let sig = tcx.hir_fn_sig_by_hir_id(owner_id.into())?;
2485 let generics = tcx.hir_get_generics(owner_id.def_id)?;
2486
2487 let mut late_bound = FxIndexSet::default();
2488
2489 let mut constrained_by_input = ConstrainedCollector { regions: Default::default(), tcx };
2490 for arg_ty in sig.decl.inputs {
2491 constrained_by_input.visit_ty_unambig(arg_ty);
2492 }
2493
2494 let mut appears_in_output =
2495 AllCollector { has_fully_capturing_opaque: false, regions: Default::default() };
2496 intravisit::walk_fn_ret_ty(&mut appears_in_output, &sig.decl.output);
2497 if appears_in_output.has_fully_capturing_opaque {
2498 appears_in_output.regions.extend(generics.params.iter().map(|param| param.def_id));
2499 }
2500
2501 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2501",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2501u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["constrained_by_input.regions"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&constrained_by_input.regions)
as &dyn Value))])
});
} else { ; }
};debug!(?constrained_by_input.regions);
2502
2503 let mut appears_in_where_clause =
2508 AllCollector { has_fully_capturing_opaque: true, regions: Default::default() };
2509 appears_in_where_clause.visit_generics(generics);
2510 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2510",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2510u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["appears_in_where_clause.regions"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&appears_in_where_clause.regions)
as &dyn Value))])
});
} else { ; }
};debug!(?appears_in_where_clause.regions);
2511
2512 for param in generics.params {
2517 match param.kind {
2518 hir::GenericParamKind::Lifetime { .. } => { }
2519
2520 hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => continue,
2522 }
2523
2524 if appears_in_where_clause.regions.contains(¶m.def_id) {
2526 continue;
2527 }
2528
2529 if !constrained_by_input.regions.contains(¶m.def_id)
2531 && appears_in_output.regions.contains(¶m.def_id)
2532 {
2533 continue;
2534 }
2535
2536 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2536",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2536u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("lifetime {0:?} with id {1:?} is late-bound",
param.name.ident(), param.def_id) as &dyn Value))])
});
} else { ; }
};debug!("lifetime {:?} with id {:?} is late-bound", param.name.ident(), param.def_id);
2537
2538 let inserted = late_bound.insert(param.hir_id.local_id);
2539 if !inserted {
{
::core::panicking::panic_fmt(format_args!("visited lifetime {0:?} twice",
param.def_id));
}
};assert!(inserted, "visited lifetime {:?} twice", param.def_id);
2540 }
2541
2542 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2542",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2542u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::resolve_bound_vars"),
::tracing_core::field::FieldSet::new(&["late_bound"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&late_bound)
as &dyn Value))])
});
} else { ; }
};debug!(?late_bound);
2543 return Some(tcx.arena.alloc(late_bound));
2544
2545 struct ConstrainedCollectorPostHirTyLowering {
2567 arg_is_constrained: Box<[bool]>,
2568 }
2569
2570 use ty::Ty;
2571 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostHirTyLowering {
2572 fn visit_ty(&mut self, t: Ty<'tcx>) {
2573 match t.kind() {
2574 ty::Param(param_ty) => {
2575 self.arg_is_constrained[param_ty.index as usize] = true;
2576 }
2577 ty::Alias(ty::AliasTy {
2578 kind: ty::Projection { .. } | ty::Inherent { .. },
2579 ..
2580 }) => return,
2581 _ => (),
2582 }
2583 t.super_visit_with(self)
2584 }
2585
2586 fn visit_const(&mut self, _: ty::Const<'tcx>) {}
2587
2588 fn visit_region(&mut self, r: ty::Region<'tcx>) {
2589 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2589",
"rustc_hir_analysis::collect::resolve_bound_vars",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs"),
::tracing_core::__macro_support::Option::Some(2589u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("r={0:?}",
r.kind()) as &dyn Value))])
});
} else { ; }
};debug!("r={:?}", r.kind());
2590 if let ty::RegionKind::ReEarlyParam(region) = r.kind() {
2591 self.arg_is_constrained[region.index as usize] = true;
2592 }
2593 }
2594 }
2595
2596 struct ConstrainedCollector<'tcx> {
2597 tcx: TyCtxt<'tcx>,
2598 regions: FxHashSet<LocalDefId>,
2599 }
2600
2601 impl<'v> Visitor<'v> for ConstrainedCollector<'_> {
2602 fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
2603 match ty.kind {
2604 hir::TyKind::Path(
2605 hir::QPath::Resolved(Some(_), _) | hir::QPath::TypeRelative(..),
2606 ) => {
2607 }
2611
2612 hir::TyKind::Path(hir::QPath::Resolved(
2613 None,
2614 hir::Path { res: Res::Def(DefKind::TyAlias, alias_def), segments, span },
2615 )) => {
2616 let generics = self.tcx.generics_of(*alias_def);
2619 let mut walker = ConstrainedCollectorPostHirTyLowering {
2620 arg_is_constrained: ::alloc::vec::from_elem(false, generics.own_params.len())vec![false; generics.own_params.len()]
2621 .into_boxed_slice(),
2622 };
2623 walker.visit_ty(
2624 self.tcx.type_of(*alias_def).instantiate_identity().skip_norm_wip(),
2625 );
2626
2627 match segments.last() {
2628 Some(hir::PathSegment { args: Some(args), .. }) => {
2629 let tcx = self.tcx;
2630 for constrained_arg in
2631 args.args.iter().enumerate().flat_map(|(n, arg)| {
2632 match walker.arg_is_constrained.get(n) {
2633 Some(true) => Some(arg),
2634 Some(false) => None,
2635 None => {
2636 tcx.dcx().span_delayed_bug(
2637 *span,
2638 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Incorrect generic arg count for alias {0:?}",
alias_def))
})format!(
2639 "Incorrect generic arg count for alias {alias_def:?}"
2640 ),
2641 );
2642 None
2643 }
2644 }
2645 })
2646 {
2647 self.visit_generic_arg(constrained_arg);
2648 }
2649 }
2650 Some(_) => (),
2651 None => ::rustc_middle::util::bug::bug_fmt(format_args!("Path with no segments or self type"))bug!("Path with no segments or self type"),
2652 }
2653 }
2654
2655 hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
2656 if let Some(last_segment) = path.segments.last() {
2662 self.visit_path_segment(last_segment);
2663 }
2664 }
2665
2666 _ => {
2667 intravisit::walk_ty(self, ty);
2668 }
2669 }
2670 }
2671
2672 fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
2673 if let hir::LifetimeKind::Param(def_id) = lifetime_ref.kind {
2674 self.regions.insert(def_id);
2675 }
2676 }
2677 }
2678
2679 struct AllCollector {
2680 has_fully_capturing_opaque: bool,
2681 regions: FxHashSet<LocalDefId>,
2682 }
2683
2684 impl<'tcx> Visitor<'tcx> for AllCollector {
2685 fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
2686 if let hir::LifetimeKind::Param(def_id) = lifetime_ref.kind {
2687 self.regions.insert(def_id);
2688 }
2689 }
2690
2691 fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
2692 if !self.has_fully_capturing_opaque {
2693 self.has_fully_capturing_opaque = opaque_captures_all_in_scope_lifetimes(opaque);
2694 }
2695 intravisit::walk_opaque_ty(self, opaque);
2696 }
2697 }
2698}
2699
2700fn deny_non_region_late_bound(
2701 tcx: TyCtxt<'_>,
2702 bound_vars: &mut FxIndexMap<LocalDefId, ResolvedArg>,
2703 where_: &str,
2704) {
2705 let mut first = true;
2706
2707 for (var, arg) in bound_vars {
2708 let Node::GenericParam(param) = tcx.hir_node_by_def_id(*var) else {
2709 ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(*var),
format_args!("expected bound-var def-id to resolve to param"));span_bug!(tcx.def_span(*var), "expected bound-var def-id to resolve to param");
2710 };
2711
2712 let what = match param.kind {
2713 hir::GenericParamKind::Type { .. } => "type",
2714 hir::GenericParamKind::Const { .. } => "const",
2715 hir::GenericParamKind::Lifetime { .. } => continue,
2716 };
2717
2718 let diag = tcx.dcx().struct_span_err(
2719 param.span,
2720 ::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_}"),
2721 );
2722
2723 let guar = diag.emit_unless_delay(!tcx.features().non_lifetime_binders() || !first);
2724
2725 first = false;
2726 *arg = ResolvedArg::Error(guar);
2727 }
2728}
2729
2730#[derive(#[automatically_derived]
impl ::core::clone::Clone for SegIdx {
#[inline]
fn clone(&self) -> SegIdx {
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]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "SegIdx",
&&self.0)
}
}Debug)]
2732struct SegIdx(usize);
2733
2734impl SegIdx {
2735 fn reverse(self, segments: &[hir::PathSegment<'_>]) -> RevSegIdx {
2736 let SegIdx(seg_idx) = self;
2737 RevSegIdx(segments.len() - seg_idx - 1)
2738 }
2739}
2740
2741struct RevSegIdx(usize);
2746
2747impl RevSegIdx {
2748 fn reverse(self, segments: &[hir::PathSegment<'_>]) -> SegIdx {
2749 let RevSegIdx(rev_seg_idx) = self;
2750 SegIdx(segments.len() - rev_seg_idx - 1)
2751 }
2752}