1use std::borrow::Cow;
10use std::collections::hash_map::Entry;
11use std::debug_assert_matches;
12use std::mem::{replace, swap, take};
13use std::ops::{ControlFlow, Range};
14
15use rustc_ast::attr::AttributeExt;
16use rustc_ast::visit::{
17 AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, try_visit, visit_opt, walk_list,
18};
19use rustc_ast::*;
20use rustc_data_structures::either::Either;
21use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
22use rustc_data_structures::unord::{UnordMap, UnordSet};
23use rustc_errors::codes::*;
24use rustc_errors::{
25 Applicability, Diag, DiagArgValue, Diagnostic, ErrorGuaranteed, IntoDiagArg, MultiSpan,
26 Suggestions, elided_lifetime_in_path_suggestion, pluralize,
27};
28use rustc_hir::def::Namespace::{self, *};
29use rustc_hir::def::{CtorKind, DefKind, NonMacroAttrKind, PerNS};
30use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId};
31use rustc_hir::{MissingLifetimeKind, PrimTy};
32use rustc_lint_defs::builtin::{ELIDED_LIFETIMES_IN_PATHS, UNUSED_LABELS};
33use rustc_middle::middle::resolve::{
34 DelegationInfo, DelegationInherentFnKind, DelegationResolution, LifetimeRes, PartialRes,
35};
36use rustc_middle::middle::resolve_bound_vars::Set1;
37use rustc_middle::ty::{AssocTag, Visibility};
38use rustc_session::config::ResolveDocLinks;
39use rustc_session::diagnostics::feature_err;
40use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Spanned, Symbol, bug, kw, respan, span_bug, sym};
41use rustc_structures::CrateType;
42use smallvec::{SmallVec, smallvec};
43use thin_vec::ThinVec;
44use tracing::{debug, instrument, trace};
45
46use crate::{
47 BindingError, BindingKey, Decl, DelegationFnSig, Finalize, IdentKey, LateDecl, LocalModule,
48 Module, ModuleOrUniformRoot, ParentScope, PathResult, Res, ResolutionError, Resolver, Segment,
49 Stage, TyCtxt, UseError, Used, path_names_to_string, rustdoc, with_owner,
50};
51
52mod diagnostics;
53
54use diagnostics::{ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime};
55
56#[derive(#[automatically_derived]
impl ::core::marker::Copy for BindingInfo { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for BindingInfo { }
#[automatically_derived]
impl ::core::clone::Clone for BindingInfo {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<BindingMode>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for BindingInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "BindingInfo",
"span", &self.span, "annotation", &&self.annotation)
}
}Debug)]
57struct BindingInfo {
58 span: Span,
59 annotation: BindingMode,
60}
61
62#[derive(#[automatically_derived]
impl ::core::marker::Copy for PatternSource { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for PatternSource { }
#[automatically_derived]
impl ::core::clone::Clone for PatternSource {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for PatternSource { }
#[automatically_derived]
impl ::core::cmp::PartialEq for PatternSource {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for PatternSource { }Eq, #[automatically_derived]
impl ::core::fmt::Debug for PatternSource {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
PatternSource::Match => "Match",
PatternSource::Let => "Let",
PatternSource::For => "For",
PatternSource::FnParam => "FnParam",
})
}
}Debug)]
63pub(crate) enum PatternSource {
64 Match,
65 Let,
66 For,
67 FnParam,
68}
69
70#[derive(#[automatically_derived]
impl ::core::marker::Copy for IsRepeatExpr { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for IsRepeatExpr { }
#[automatically_derived]
impl ::core::clone::Clone for IsRepeatExpr {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for IsRepeatExpr {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
IsRepeatExpr::No => "No",
IsRepeatExpr::Yes => "Yes",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for IsRepeatExpr { }
#[automatically_derived]
impl ::core::cmp::PartialEq for IsRepeatExpr {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IsRepeatExpr { }Eq)]
71enum IsRepeatExpr {
72 No,
73 Yes,
74}
75
76struct IsNeverPattern;
77
78#[derive(#[automatically_derived]
impl ::core::marker::Copy for AnonConstKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AnonConstKind { }
#[automatically_derived]
impl ::core::clone::Clone for AnonConstKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<IsRepeatExpr>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AnonConstKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::EnumDiscriminant =>
::core::fmt::Formatter::write_str(f, "EnumDiscriminant"),
Self::FieldDefaultValue =>
::core::fmt::Formatter::write_str(f, "FieldDefaultValue"),
Self::InlineConst =>
::core::fmt::Formatter::write_str(f, "InlineConst"),
Self::ConstArg(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ConstArg", &__self_0),
Self::ArrayLength =>
::core::fmt::Formatter::write_str(f, "ArrayLength"),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AnonConstKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AnonConstKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::ConstArg(__self_0), Self::ConstArg(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AnonConstKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<IsRepeatExpr>;
}
}Eq)]
81enum AnonConstKind {
82 EnumDiscriminant,
83 FieldDefaultValue,
84 InlineConst,
85 ConstArg(IsRepeatExpr),
86 ArrayLength,
87}
88
89impl PatternSource {
90 fn descr(self) -> &'static str {
91 match self {
92 PatternSource::Match => "match binding",
93 PatternSource::Let => "let binding",
94 PatternSource::For => "for binding",
95 PatternSource::FnParam => "function parameter",
96 }
97 }
98}
99
100impl IntoDiagArg for PatternSource {
101 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
102 DiagArgValue::Str(Cow::Borrowed(self.descr()))
103 }
104}
105
106#[derive(#[automatically_derived]
impl ::core::marker::StructuralPartialEq for PatBoundCtx { }
#[automatically_derived]
impl ::core::cmp::PartialEq for PatBoundCtx {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq)]
110enum PatBoundCtx {
111 Product,
113 Or,
115}
116
117type PatternBindings = SmallVec<[(PatBoundCtx, FxIndexMap<Ident, Res>); 1]>;
129
130#[derive(#[automatically_derived]
impl ::core::marker::Copy for HasGenericParams { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for HasGenericParams { }
#[automatically_derived]
impl ::core::clone::Clone for HasGenericParams {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for HasGenericParams {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Yes(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Yes",
&__self_0),
Self::No => ::core::fmt::Formatter::write_str(f, "No"),
}
}
}Debug)]
132pub(crate) enum HasGenericParams {
133 Yes(Span),
134 No,
135}
136
137#[derive(#[automatically_derived]
impl ::core::marker::Copy for ConstantHasGenerics { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ConstantHasGenerics { }
#[automatically_derived]
impl ::core::clone::Clone for ConstantHasGenerics {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NoConstantGenericsReason>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ConstantHasGenerics {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Yes => ::core::fmt::Formatter::write_str(f, "Yes"),
Self::No(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "No",
&__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for ConstantHasGenerics {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NoConstantGenericsReason>;
}
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ConstantHasGenerics { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ConstantHasGenerics {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::No(__self_0), Self::No(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
139pub(crate) enum ConstantHasGenerics {
140 Yes,
141 No(NoConstantGenericsReason),
142}
143
144#[derive(#[automatically_derived]
impl ::core::marker::Copy for ConstantRequiresType { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ConstantRequiresType { }
#[automatically_derived]
impl ::core::clone::Clone for ConstantRequiresType {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ConstantRequiresType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ConstantRequiresType::Usize => "Usize",
ConstantRequiresType::No => "No",
})
}
}Debug)]
146pub(crate) enum ConstantRequiresType {
147 Usize,
148 No,
149}
150
151impl ConstantHasGenerics {
152 fn force_yes_if(self, b: bool) -> Self {
153 if b { Self::Yes } else { self }
154 }
155}
156
157#[derive(#[automatically_derived]
impl ::core::marker::Copy for NoConstantGenericsReason { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for NoConstantGenericsReason { }
#[automatically_derived]
impl ::core::clone::Clone for NoConstantGenericsReason {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for NoConstantGenericsReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
NoConstantGenericsReason::NonTrivialConstArg =>
"NonTrivialConstArg",
NoConstantGenericsReason::IsEnumDiscriminant =>
"IsEnumDiscriminant",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for NoConstantGenericsReason { }Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for NoConstantGenericsReason { }
#[automatically_derived]
impl ::core::cmp::PartialEq for NoConstantGenericsReason {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq)]
159pub(crate) enum NoConstantGenericsReason {
160 NonTrivialConstArg,
167 IsEnumDiscriminant,
176}
177
178#[derive(#[automatically_derived]
impl ::core::marker::Copy for ConstantItemKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ConstantItemKind { }
#[automatically_derived]
impl ::core::clone::Clone for ConstantItemKind {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ConstantItemKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ConstantItemKind::Const => "Const",
ConstantItemKind::Static => "Static",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for ConstantItemKind { }Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ConstantItemKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ConstantItemKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq)]
179pub(crate) enum ConstantItemKind {
180 Const,
181 Static,
182}
183
184impl ConstantItemKind {
185 pub(crate) fn as_str(&self) -> &'static str {
186 match self {
187 Self::Const => "const",
188 Self::Static => "static",
189 }
190 }
191}
192
193#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RecordPartialRes {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RecordPartialRes::Yes => "Yes",
RecordPartialRes::No => "No",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for RecordPartialRes { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for RecordPartialRes { }
#[automatically_derived]
impl ::core::clone::Clone for RecordPartialRes {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for RecordPartialRes { }
#[automatically_derived]
impl ::core::cmp::PartialEq for RecordPartialRes {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for RecordPartialRes { }Eq)]
194enum RecordPartialRes {
195 Yes,
196 No,
197}
198
199#[derive(#[automatically_derived]
impl<'ra> ::core::marker::Copy for RibKind<'ra> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for RibKind<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for RibKind<'ra> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Option<LocalModule<'ra>>>;
let _: ::core::clone::AssertParamIsClone<HasGenericParams>;
let _: ::core::clone::AssertParamIsClone<DefKind>;
let _: ::core::clone::AssertParamIsClone<ConstantHasGenerics>;
let _:
::core::clone::AssertParamIsClone<Option<(Ident,
ConstantItemKind)>>;
let _: ::core::clone::AssertParamIsClone<ConstantRequiresType>;
let _: ::core::clone::AssertParamIsClone<LocalModule<'ra>>;
let _: ::core::clone::AssertParamIsClone<DefId>;
let _:
::core::clone::AssertParamIsClone<ForwardGenericParamBanReason>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::fmt::Debug for RibKind<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Normal => ::core::fmt::Formatter::write_str(f, "Normal"),
Self::Block(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Block",
&__self_0),
Self::AssocItem =>
::core::fmt::Formatter::write_str(f, "AssocItem"),
Self::FnOrCoroutine =>
::core::fmt::Formatter::write_str(f, "FnOrCoroutine"),
Self::Item(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Item",
__self_0, &__self_1),
Self::ConstantItem(__self_0, __self_1, __self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"ConstantItem", __self_0, __self_1, &__self_2),
Self::Module(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Module",
&__self_0),
Self::MacroDefinition(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MacroDefinition", &__self_0),
Self::ForwardGenericParamBan(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ForwardGenericParamBan", &__self_0),
Self::ConstParamTy =>
::core::fmt::Formatter::write_str(f, "ConstParamTy"),
Self::InlineAsmSym =>
::core::fmt::Formatter::write_str(f, "InlineAsmSym"),
}
}
}Debug)]
202pub(crate) enum RibKind<'ra> {
203 Normal,
205
206 Block(Option<LocalModule<'ra>>),
212
213 AssocItem,
218
219 FnOrCoroutine,
221
222 Item(HasGenericParams, DefKind),
224
225 ConstantItem(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>, ConstantRequiresType),
232
233 Module(LocalModule<'ra>),
235
236 MacroDefinition(DefId),
238
239 ForwardGenericParamBan(ForwardGenericParamBanReason),
243
244 ConstParamTy,
247
248 InlineAsmSym,
251}
252
253#[derive(#[automatically_derived]
impl ::core::marker::Copy for ForwardGenericParamBanReason { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ForwardGenericParamBanReason { }
#[automatically_derived]
impl ::core::clone::Clone for ForwardGenericParamBanReason {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ForwardGenericParamBanReason { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ForwardGenericParamBanReason {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ForwardGenericParamBanReason { }Eq, #[automatically_derived]
impl ::core::fmt::Debug for ForwardGenericParamBanReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ForwardGenericParamBanReason::Default => "Default",
ForwardGenericParamBanReason::ConstParamTy => "ConstParamTy",
})
}
}Debug)]
254pub(crate) enum ForwardGenericParamBanReason {
255 Default,
256 ConstParamTy,
257}
258
259impl RibKind<'_> {
260 pub(crate) fn contains_params(&self) -> bool {
263 match self {
264 RibKind::Normal
265 | RibKind::Block(..)
266 | RibKind::FnOrCoroutine
267 | RibKind::ConstantItem(..)
268 | RibKind::Module(_)
269 | RibKind::MacroDefinition(_)
270 | RibKind::InlineAsmSym => false,
271 RibKind::ConstParamTy
272 | RibKind::AssocItem
273 | RibKind::Item(..)
274 | RibKind::ForwardGenericParamBan(_) => true,
275 }
276 }
277
278 fn is_label_barrier(self) -> bool {
280 match self {
281 RibKind::Normal | RibKind::MacroDefinition(..) => false,
282 RibKind::FnOrCoroutine | RibKind::ConstantItem(..) => true,
283 kind => ::rustc_span::macros::bug_impl(None,
format_args!("unexpected rib kind: {0:?}", kind), Location::caller())bug!("unexpected rib kind: {kind:?}"),
284 }
285 }
286}
287
288#[derive(#[automatically_derived]
impl<'ra, R: ::core::fmt::Debug> ::core::fmt::Debug for Rib<'ra, R> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "Rib",
"bindings", &self.bindings, "patterns_with_skipped_bindings",
&self.patterns_with_skipped_bindings, "kind", &&self.kind)
}
}Debug)]
301pub(crate) struct Rib<'ra, R = Res> {
302 pub bindings: FxIndexMap<Ident, R>,
303 pub patterns_with_skipped_bindings:
304 UnordMap<DefId, Vec<(Span, Option<Span>, Result<(), ErrorGuaranteed>)>>,
305 pub kind: RibKind<'ra>,
306}
307
308impl<'ra, R> Rib<'ra, R> {
309 fn new(kind: RibKind<'ra>) -> Rib<'ra, R> {
310 Rib {
311 bindings: Default::default(),
312 patterns_with_skipped_bindings: Default::default(),
313 kind,
314 }
315 }
316}
317
318#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LifetimeUseSet { }
#[automatically_derived]
impl ::core::clone::Clone for LifetimeUseSet {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<visit::LifetimeCtxt>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LifetimeUseSet { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for LifetimeUseSet {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::One { use_span: __self_0, use_ctxt: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "One",
"use_span", __self_0, "use_ctxt", &__self_1),
Self::Many => ::core::fmt::Formatter::write_str(f, "Many"),
}
}
}Debug)]
319enum LifetimeUseSet {
320 One { use_span: Span, use_ctxt: visit::LifetimeCtxt },
321 Many,
322}
323
324#[derive(#[automatically_derived]
impl ::core::marker::Copy for LifetimeRibKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LifetimeRibKind { }
#[automatically_derived]
impl ::core::clone::Clone for LifetimeRibKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<LifetimeBinderKind>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<LifetimeRes>;
let _: ::core::clone::AssertParamIsClone<NoConstantGenericsReason>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for LifetimeRibKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Generics { binder: __self_0, span: __self_1, kind: __self_2
} =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Generics", "binder", __self_0, "span", __self_1, "kind",
&__self_2),
Self::AnonymousCreateParameter {
binder: __self_0, report_in_path: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"AnonymousCreateParameter", "binder", __self_0,
"report_in_path", &__self_1),
Self::Elided { res: __self_0, error_in_path: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Elided", "res", __self_0, "error_in_path", &__self_1),
Self::AnonymousReportError =>
::core::fmt::Formatter::write_str(f, "AnonymousReportError"),
Self::ElisionFailure =>
::core::fmt::Formatter::write_str(f, "ElisionFailure"),
Self::ConstParamTy =>
::core::fmt::Formatter::write_str(f, "ConstParamTy"),
Self::ConcreteAnonConst(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ConcreteAnonConst", &__self_0),
Self::Item => ::core::fmt::Formatter::write_str(f, "Item"),
Self::ImplTrait =>
::core::fmt::Formatter::write_str(f, "ImplTrait"),
}
}
}Debug)]
325enum LifetimeRibKind {
326 Generics { binder: NodeId, span: Span, kind: LifetimeBinderKind },
331
332 AnonymousCreateParameter { binder: NodeId, report_in_path: bool },
349
350 Elided {
352 res: LifetimeRes,
353 error_in_path: bool,
355 },
356
357 AnonymousReportError,
363
364 ElisionFailure,
366
367 ConstParamTy,
372
373 ConcreteAnonConst(NoConstantGenericsReason),
379
380 Item,
382
383 ImplTrait,
385}
386impl LifetimeRibKind {
387 fn elided(res: LifetimeRes) -> LifetimeRibKind {
389 LifetimeRibKind::Elided { res, error_in_path: false }
390 }
391}
392
393#[derive(#[automatically_derived]
impl ::core::marker::Copy for LifetimeBinderKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LifetimeBinderKind { }
#[automatically_derived]
impl ::core::clone::Clone for LifetimeBinderKind {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for LifetimeBinderKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
LifetimeBinderKind::FnPtrType => "FnPtrType",
LifetimeBinderKind::PolyTrait => "PolyTrait",
LifetimeBinderKind::WhereBound => "WhereBound",
LifetimeBinderKind::Item => "Item",
LifetimeBinderKind::ConstItem => "ConstItem",
LifetimeBinderKind::Function => "Function",
LifetimeBinderKind::Closure => "Closure",
LifetimeBinderKind::ImplBlock => "ImplBlock",
LifetimeBinderKind::ImplAssocType => "ImplAssocType",
})
}
}Debug)]
394enum LifetimeBinderKind {
395 FnPtrType,
396 PolyTrait,
397 WhereBound,
398 Item,
401 ConstItem,
402 Function,
403 Closure,
404 ImplBlock,
405 ImplAssocType,
407}
408
409impl LifetimeBinderKind {
410 fn descr(self) -> &'static str {
411 use LifetimeBinderKind::*;
412 match self {
413 FnPtrType => "type",
414 PolyTrait => "bound",
415 WhereBound => "bound",
416 Item | ConstItem => "item",
417 ImplAssocType => "associated type",
418 ImplBlock => "impl block",
419 Function => "function",
420 Closure => "closure",
421 }
422 }
423}
424
425#[derive(#[automatically_derived]
impl ::core::fmt::Debug for LifetimeRib {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "LifetimeRib",
"kind", &self.kind, "bindings", &&self.bindings)
}
}Debug)]
426struct LifetimeRib {
427 kind: LifetimeRibKind,
428 bindings: FxIndexMap<Ident, (NodeId, LifetimeRes)>,
430}
431
432impl LifetimeRib {
433 fn new(kind: LifetimeRibKind) -> LifetimeRib {
434 LifetimeRib { bindings: Default::default(), kind }
435 }
436}
437
438#[derive(#[automatically_derived]
impl ::core::marker::Copy for AliasPossibility { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AliasPossibility { }
#[automatically_derived]
impl ::core::clone::Clone for AliasPossibility {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AliasPossibility { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AliasPossibility {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AliasPossibility { }Eq, #[automatically_derived]
impl ::core::fmt::Debug for AliasPossibility {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AliasPossibility::No => "No",
AliasPossibility::Maybe => "Maybe",
})
}
}Debug)]
439pub(crate) enum AliasPossibility {
440 No,
441 Maybe,
442}
443
444#[derive(#[automatically_derived]
impl<'a, 'ast, 'ra> ::core::marker::Copy for PathSource<'a, 'ast, 'ra> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'a, 'ast, 'ra> ::core::clone::TrivialClone for
PathSource<'a, 'ast, 'ra> {
}
#[automatically_derived]
impl<'a, 'ast, 'ra> ::core::clone::Clone for PathSource<'a, 'ast, 'ra> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<AliasPossibility>;
let _: ::core::clone::AssertParamIsClone<Option<&'ast Expr>>;
let _: ::core::clone::AssertParamIsClone<Option<&'a Expr>>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<&'ra [Span]>;
let _: ::core::clone::AssertParamIsClone<Namespace>;
let _:
::core::clone::AssertParamIsClone<&'a PathSource<'a, 'ast,
'ra>>;
*self
}
}Clone, #[automatically_derived]
impl<'a, 'ast, 'ra> ::core::fmt::Debug for PathSource<'a, 'ast, 'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Type => ::core::fmt::Formatter::write_str(f, "Type"),
Self::TypeParam =>
::core::fmt::Formatter::write_str(f, "TypeParam"),
Self::Trait(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Trait",
&__self_0),
Self::Expr(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Expr",
&__self_0),
Self::Pat => ::core::fmt::Formatter::write_str(f, "Pat"),
Self::Struct(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Struct",
&__self_0),
Self::TupleStruct(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"TupleStruct", __self_0, &__self_1),
Self::TraitItem(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"TraitItem", __self_0, &__self_1),
Self::Delegation =>
::core::fmt::Formatter::write_str(f, "Delegation"),
Self::ExternItemImpl =>
::core::fmt::Formatter::write_str(f, "ExternItemImpl"),
Self::PreciseCapturingArg(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"PreciseCapturingArg", &__self_0),
Self::ReturnTypeNotation =>
::core::fmt::Formatter::write_str(f, "ReturnTypeNotation"),
Self::DefineOpaques =>
::core::fmt::Formatter::write_str(f, "DefineOpaques"),
Self::Macro => ::core::fmt::Formatter::write_str(f, "Macro"),
Self::Module => ::core::fmt::Formatter::write_str(f, "Module"),
}
}
}Debug)]
445pub(crate) enum PathSource<'a, 'ast, 'ra> {
446 Type,
448 TypeParam,
450 Trait(AliasPossibility),
452 Expr(Option<&'ast Expr>),
454 Pat,
456 Struct(Option<&'a Expr>),
458 TupleStruct(Span, &'ra [Span]),
460 TraitItem(Namespace, &'a PathSource<'a, 'ast, 'ra>),
465 Delegation,
467 ExternItemImpl,
469 PreciseCapturingArg(Namespace),
471 ReturnTypeNotation,
473 DefineOpaques,
475 Macro,
477 Module,
479}
480
481impl PathSource<'_, '_, '_> {
482 fn namespace(self) -> Namespace {
483 match self {
484 PathSource::Type
485 | PathSource::TypeParam
486 | PathSource::Trait(_)
487 | PathSource::Struct(_)
488 | PathSource::DefineOpaques
489 | PathSource::Module => TypeNS,
490 PathSource::Expr(..)
491 | PathSource::Pat
492 | PathSource::TupleStruct(..)
493 | PathSource::Delegation
494 | PathSource::ExternItemImpl
495 | PathSource::ReturnTypeNotation => ValueNS,
496 PathSource::TraitItem(ns, _) => ns,
497 PathSource::PreciseCapturingArg(ns) => ns,
498 PathSource::Macro => MacroNS,
499 }
500 }
501
502 fn defer_to_typeck(self) -> bool {
503 match self {
504 PathSource::Type
505 | PathSource::TypeParam
506 | PathSource::Expr(..)
507 | PathSource::Pat
508 | PathSource::Struct(_)
509 | PathSource::TupleStruct(..)
510 | PathSource::Delegation
511 | PathSource::ReturnTypeNotation => true,
512 PathSource::Trait(_)
513 | PathSource::TraitItem(..)
514 | PathSource::DefineOpaques
515 | PathSource::ExternItemImpl
516 | PathSource::PreciseCapturingArg(..)
517 | PathSource::Macro
518 | PathSource::Module => false,
519 }
520 }
521
522 fn descr_expected(self) -> &'static str {
523 match &self {
524 PathSource::DefineOpaques => "type alias or associated type with opaqaue types",
525 PathSource::Type => "type",
526 PathSource::TypeParam => "type or constant",
527 PathSource::Trait(_) => "trait",
528 PathSource::Pat => "unit struct, unit variant or constant",
529 PathSource::Struct(_) => "struct, variant or union type",
530 PathSource::TraitItem(ValueNS, PathSource::TupleStruct(..))
531 | PathSource::TupleStruct(..) => "tuple struct or tuple variant",
532 PathSource::TraitItem(ns, _) => match ns {
533 TypeNS => "associated type",
534 ValueNS => "method or associated constant",
535 MacroNS => ::rustc_span::macros::bug_impl(None, format_args!("associated macro"),
Location::caller())bug!("associated macro"),
536 },
537 PathSource::Expr(parent) => match parent.as_ref().map(|p| &p.kind) {
538 Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {
541 ExprKind::Path(_, path)
543 if let [segment, _] = path.segments.as_slice()
544 && segment.ident.name == kw::PathRoot =>
545 {
546 "external crate"
547 }
548 ExprKind::Path(_, path)
549 if let Some(segment) = path.segments.last()
550 && let Some(c) = segment.ident.to_string().chars().next()
551 && c.is_uppercase() =>
552 {
553 "function, tuple struct or tuple variant"
554 }
555 _ => "function",
556 },
557 _ => "value",
558 },
559 PathSource::ReturnTypeNotation | PathSource::Delegation => "function",
560 PathSource::ExternItemImpl => "function or static",
561 PathSource::PreciseCapturingArg(..) => "type or const parameter",
562 PathSource::Macro => "macro",
563 PathSource::Module => "module",
564 }
565 }
566
567 fn is_call(self) -> bool {
568 #[allow(non_exhaustive_omitted_patterns)] match self {
PathSource::Expr(Some(&Expr { kind: ExprKind::Call(..), .. })) => true,
_ => false,
}matches!(self, PathSource::Expr(Some(&Expr { kind: ExprKind::Call(..), .. })))
569 }
570
571 pub(crate) fn is_expected(self, res: Res) -> bool {
572 match self {
573 PathSource::DefineOpaques => {
574 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum |
DefKind::TyAlias | DefKind::AssocTy, _) | Res::SelfTyAlias { .. } =>
true,
_ => false,
}matches!(
575 res,
576 Res::Def(
577 DefKind::Struct
578 | DefKind::Union
579 | DefKind::Enum
580 | DefKind::TyAlias
581 | DefKind::AssocTy,
582 _
583 ) | Res::SelfTyAlias { .. }
584 )
585 }
586 PathSource::Type => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait
| DefKind::TraitAlias | DefKind::TyAlias | DefKind::AssocTy |
DefKind::TyParam | DefKind::OpaqueTy | DefKind::ForeignTy, _) |
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } =>
true,
_ => false,
}matches!(
587 res,
588 Res::Def(
589 DefKind::Struct
590 | DefKind::Union
591 | DefKind::Enum
592 | DefKind::Trait
593 | DefKind::TraitAlias
594 | DefKind::TyAlias
595 | DefKind::AssocTy
596 | DefKind::TyParam
597 | DefKind::OpaqueTy
598 | DefKind::ForeignTy,
599 _,
600 ) | Res::PrimTy(..)
601 | Res::SelfTyParam { .. }
602 | Res::SelfTyAlias { .. }
603 ),
604 PathSource::TypeParam => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait
| DefKind::TraitAlias | DefKind::TyAlias | DefKind::AssocTy |
DefKind::TyParam | DefKind::OpaqueTy | DefKind::AnonConst |
DefKind::AssocConst | DefKind::Const | DefKind::ConstParam |
DefKind::ForeignTy, _) | Res::PrimTy(..) | Res::SelfTyParam { .. } |
Res::SelfTyAlias { .. } => true,
_ => false,
}matches!(
605 res,
606 Res::Def(
607 DefKind::Struct
608 | DefKind::Union
609 | DefKind::Enum
610 | DefKind::Trait
611 | DefKind::TraitAlias
612 | DefKind::TyAlias
613 | DefKind::AssocTy
614 | DefKind::TyParam
615 | DefKind::OpaqueTy
616 | DefKind::AnonConst
617 | DefKind::AssocConst
618 | DefKind::Const
619 | DefKind::ConstParam
620 | DefKind::ForeignTy,
621 _,
622 ) | Res::PrimTy(..)
623 | Res::SelfTyParam { .. }
624 | Res::SelfTyAlias { .. }
625 ),
626 PathSource::Trait(AliasPossibility::No) => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Trait, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Trait, _)),
627 PathSource::Trait(AliasPossibility::Maybe) => {
628 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Trait | DefKind::TraitAlias, _))
629 }
630 PathSource::Expr(..) => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn) | DefKind::Const
| DefKind::Static { .. } | DefKind::Fn | DefKind::AssocFn |
DefKind::AssocConst | DefKind::ConstParam, _) | Res::Local(..) |
Res::SelfCtor(..) => true,
_ => false,
}matches!(
631 res,
632 Res::Def(
633 DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
634 | DefKind::Const
635 | DefKind::Static { .. }
636 | DefKind::Fn
637 | DefKind::AssocFn
638 | DefKind::AssocConst
639 | DefKind::ConstParam,
640 _,
641 ) | Res::Local(..)
642 | Res::SelfCtor(..)
643 ),
644 PathSource::Pat => {
645 res.expected_in_unit_struct_pat()
646 || #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Const | DefKind::AssocConst, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))
647 }
648 PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(),
649 PathSource::Struct(_) => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Variant |
DefKind::TyAlias | DefKind::AssocTy, _) | Res::SelfTyParam { .. } |
Res::SelfTyAlias { .. } => true,
_ => false,
}matches!(
650 res,
651 Res::Def(
652 DefKind::Struct
653 | DefKind::Union
654 | DefKind::Variant
655 | DefKind::TyAlias
656 | DefKind::AssocTy,
657 _,
658 ) | Res::SelfTyParam { .. }
659 | Res::SelfTyAlias { .. }
660 ),
661 PathSource::TraitItem(ns, _) => match res {
662 Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
663 Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true,
664 _ => false,
665 },
666 PathSource::ReturnTypeNotation => match res {
667 Res::Def(DefKind::AssocFn, _) => true,
668 _ => false,
669 },
670 PathSource::Delegation => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Fn | DefKind::AssocFn, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)),
671 PathSource::ExternItemImpl => {
672 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) |
DefKind::Static { .. }, _) => true,
_ => false,
}matches!(
673 res,
674 Res::Def(
675 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Static { .. },
676 _
677 )
678 )
679 }
680 PathSource::PreciseCapturingArg(ValueNS) => {
681 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::ConstParam, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::ConstParam, _))
682 }
683 PathSource::PreciseCapturingArg(TypeNS) => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } |
Res::SelfTyAlias { .. } => true,
_ => false,
}matches!(
685 res,
686 Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }
687 ),
688 PathSource::PreciseCapturingArg(MacroNS) => false,
689 PathSource::Macro => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Macro(_), _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Macro(_), _)),
690 PathSource::Module => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Mod, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Mod, _)),
691 }
692 }
693
694 fn error_code(self, has_unexpected_resolution: bool) -> ErrCode {
695 match (self, has_unexpected_resolution) {
696 (PathSource::Trait(_), true) => E0404,
697 (PathSource::Trait(_), false) => E0405,
698 (PathSource::Type | PathSource::DefineOpaques | PathSource::TypeParam, true) => E0573,
699 (PathSource::Type | PathSource::DefineOpaques | PathSource::TypeParam, false) => E0425,
700 (PathSource::Struct(_), true) => E0574,
701 (PathSource::Struct(_), false) => E0422,
702 (PathSource::Expr(..), true)
703 | (PathSource::Delegation, true)
704 | (PathSource::ExternItemImpl, true) => E0423,
705 (PathSource::Expr(..), false)
706 | (PathSource::Delegation, false)
707 | (PathSource::ExternItemImpl, false) => E0425,
708 (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532,
709 (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531,
710 (PathSource::TraitItem(..) | PathSource::ReturnTypeNotation, true) => E0575,
711 (PathSource::TraitItem(..) | PathSource::ReturnTypeNotation, false) => E0576,
712 (PathSource::PreciseCapturingArg(..), true) => E0799,
713 (PathSource::PreciseCapturingArg(..), false) => E0800,
714 (PathSource::Macro, _) => E0425,
715 (PathSource::Module, true) => E0577,
720 (PathSource::Module, false) => E0433,
721 }
722 }
723}
724
725#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'a> ::core::clone::TrivialClone for MaybeExported<'a> { }
#[automatically_derived]
impl<'a> ::core::clone::Clone for MaybeExported<'a> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<Option<DefId>>;
let _:
::core::clone::AssertParamIsClone<Result<DefId,
&'a ast::Visibility>>;
let _: ::core::clone::AssertParamIsClone<&'a ast::Visibility>;
*self
}
}Clone, #[automatically_derived]
impl<'a> ::core::marker::Copy for MaybeExported<'a> { }Copy)]
729enum MaybeExported<'a> {
730 Ok(NodeId),
731 Impl(Option<DefId>),
732 ImplItem(Result<DefId, &'a ast::Visibility>),
733 NestedUse(&'a ast::Visibility),
734}
735
736impl MaybeExported<'_> {
737 fn eval(self, r: &Resolver<'_, '_>) -> bool {
738 let def_id = match self {
739 MaybeExported::Ok(node_id) => Some(if r.current_owner.id == node_id {
740 r.current_owner.def_id
741 } else {
742 r.current_owner.node_id_to_def_id[&node_id]
743 }),
744 MaybeExported::Impl(Some(trait_def_id)) | MaybeExported::ImplItem(Ok(trait_def_id)) => {
745 trait_def_id.as_local()
746 }
747 MaybeExported::Impl(None) => return true,
748 MaybeExported::ImplItem(Err(vis)) | MaybeExported::NestedUse(vis) => {
749 return vis.kind.is_pub();
750 }
751 };
752 def_id.is_none_or(|def_id| r.effective_visibilities.is_exported(def_id))
753 }
754}
755
756#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for UnnecessaryQualification<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"UnnecessaryQualification", "decl", &self.decl, "node_id",
&self.node_id, "path_span", &self.path_span, "removal_span",
&&self.removal_span)
}
}Debug)]
758pub(crate) struct UnnecessaryQualification<'ra> {
759 pub decl: LateDecl<'ra>,
760 pub node_id: NodeId,
761 pub path_span: Span,
762 pub removal_span: Span,
763}
764
765#[derive(#[automatically_derived]
impl<'ast> ::core::default::Default for DiagMetadata<'ast> {
#[inline]
fn default() -> Self {
DiagMetadata {
current_trait_assoc_items: ::core::default::Default::default(),
current_self_type: ::core::default::Default::default(),
current_self_item: ::core::default::Default::default(),
current_item: ::core::default::Default::default(),
currently_processing_generic_args: ::core::default::Default::default(),
current_function: ::core::default::Default::default(),
unused_labels: ::core::default::Default::default(),
current_let_binding: ::core::default::Default::default(),
current_pat: ::core::default::Default::default(),
in_if_condition: ::core::default::Default::default(),
in_assignment: ::core::default::Default::default(),
is_assign_rhs: ::core::default::Default::default(),
in_non_gat_assoc_type: ::core::default::Default::default(),
in_range: ::core::default::Default::default(),
current_trait_object: ::core::default::Default::default(),
current_where_predicate: ::core::default::Default::default(),
in_assoc_ty_binding: ::core::default::Default::default(),
current_type_path: ::core::default::Default::default(),
current_impl_items: ::core::default::Default::default(),
current_impl_item: ::core::default::Default::default(),
currently_processing_impl_trait: ::core::default::Default::default(),
current_elision_failures: ::core::default::Default::default(),
}
}
}Default, #[automatically_derived]
impl<'ast> ::core::fmt::Debug for DiagMetadata<'ast> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["current_trait_assoc_items", "current_self_type",
"current_self_item", "current_item",
"currently_processing_generic_args", "current_function",
"unused_labels", "current_let_binding", "current_pat",
"in_if_condition", "in_assignment", "is_assign_rhs",
"in_non_gat_assoc_type", "in_range", "current_trait_object",
"current_where_predicate", "in_assoc_ty_binding",
"current_type_path", "current_impl_items",
"current_impl_item", "currently_processing_impl_trait",
"current_elision_failures"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.current_trait_assoc_items, &self.current_self_type,
&self.current_self_item, &self.current_item,
&self.currently_processing_generic_args,
&self.current_function, &self.unused_labels,
&self.current_let_binding, &self.current_pat,
&self.in_if_condition, &self.in_assignment,
&self.is_assign_rhs, &self.in_non_gat_assoc_type,
&self.in_range, &self.current_trait_object,
&self.current_where_predicate, &self.in_assoc_ty_binding,
&self.current_type_path, &self.current_impl_items,
&self.current_impl_item,
&self.currently_processing_impl_trait,
&&self.current_elision_failures];
::core::fmt::Formatter::debug_struct_fields_finish(f, "DiagMetadata",
names, values)
}
}Debug)]
766pub(crate) struct DiagMetadata<'ast> {
767 current_trait_assoc_items: Option<&'ast [Box<AssocItem>]>,
769
770 pub(crate) current_self_type: Option<&'ast Ty>,
772
773 current_self_item: Option<NodeId>,
775
776 pub(crate) current_item: Option<&'ast Item>,
778
779 currently_processing_generic_args: bool,
782
783 current_function: Option<(FnKind<'ast>, Span)>,
785
786 unused_labels: FxIndexMap<NodeId, Span>,
789
790 current_let_binding: Option<(Span, Option<Span>, Option<Span>)>,
792
793 current_pat: Option<&'ast Pat>,
794
795 in_if_condition: Option<&'ast Expr>,
797
798 in_assignment: Option<&'ast Expr>,
800 is_assign_rhs: bool,
801
802 in_non_gat_assoc_type: Option<bool>,
804
805 in_range: Option<(&'ast Expr, &'ast Expr)>,
807
808 current_trait_object: Option<&'ast [ast::GenericBound]>,
811
812 current_where_predicate: Option<&'ast WherePredicate>,
814
815 in_assoc_ty_binding: bool,
817
818 current_type_path: Option<&'ast Ty>,
819
820 current_impl_items: Option<&'ast [Box<AssocItem>]>,
822
823 current_impl_item: Option<&'ast AssocItem>,
825
826 currently_processing_impl_trait: Option<(TraitRef, Ty)>,
828
829 current_elision_failures: Vec<(MissingLifetime, Either<NodeId, Range<NodeId>>)>,
832}
833
834struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
835 r: &'a mut Resolver<'ra, 'tcx>,
836
837 parent_scope: ParentScope<'ra>,
839
840 ribs: PerNS<Vec<Rib<'ra>>>,
842
843 last_block_rib: Option<Rib<'ra>>,
845
846 label_ribs: Vec<Rib<'ra, NodeId>>,
848
849 lifetime_ribs: Vec<LifetimeRib>,
851
852 lifetime_elision_candidates: Option<Vec<(LifetimeRes, LifetimeElisionCandidate)>>,
858
859 current_trait_ref: Option<(Module<'ra>, TraitRef)>,
861
862 diag_metadata: Box<DiagMetadata<'ast>>,
864
865 in_func_body: bool,
871
872 lifetime_uses: FxHashMap<LocalDefId, LifetimeUseSet>,
874
875 use_injections: Vec<UseError<'tcx>>,
877
878 use_items: Vec<&'ast Item>,
880}
881
882impl<'ra, 'tcx> AsRef<Resolver<'ra, 'tcx>> for LateResolutionVisitor<'_, '_, 'ra, 'tcx> {
883 fn as_ref(&self) -> &Resolver<'ra, 'tcx> {
884 &self.r
885 }
886}
887impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for LateResolutionVisitor<'_, '_, 'ra, 'tcx> {
888 fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> {
889 &mut self.r
890 }
891}
892
893impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
895 fn visit_attribute(&mut self, _: &'ast Attribute) {
896 }
899 fn visit_item(&mut self, item: &'ast Item) {
900 let prev = replace(&mut self.diag_metadata.current_item, Some(item));
901 let old_ignore = replace(&mut self.in_func_body, false);
903 with_owner(self, item.id, |this| {
904 this.with_lifetime_rib(LifetimeRibKind::Item, |this| this.resolve_item(item))
905 });
906 self.in_func_body = old_ignore;
907 self.diag_metadata.current_item = prev;
908 }
909 fn visit_arm(&mut self, arm: &'ast Arm) {
910 self.resolve_arm(arm);
911 }
912 fn visit_block(&mut self, block: &'ast Block) {
913 let old_macro_rules = self.parent_scope.macro_rules;
914 self.resolve_block(block);
915 self.parent_scope.macro_rules = old_macro_rules;
916 }
917 fn visit_anon_const(&mut self, constant: &'ast AnonConst) {
918 ::rustc_span::macros::bug_impl(None,
format_args!("encountered anon const without a manual call to `resolve_anon_const`: {0:#?}",
constant), Location::caller());bug!("encountered anon const without a manual call to `resolve_anon_const`: {constant:#?}");
919 }
920 fn visit_expr(&mut self, expr: &'ast Expr) {
921 self.resolve_expr(expr, None);
922 }
923 fn visit_pat(&mut self, p: &'ast Pat) {
924 let prev = self.diag_metadata.current_pat;
925 self.diag_metadata.current_pat = Some(p);
926
927 if let PatKind::Guard(subpat, _) = &p.kind {
928 self.visit_pat(subpat);
930 } else {
931 visit::walk_pat(self, p);
932 }
933
934 self.diag_metadata.current_pat = prev;
935 }
936 fn visit_local(&mut self, local: &'ast Local) {
937 let local_spans = match local.pat.kind {
938 PatKind::Wild => None,
940 _ => Some((
941 local.pat.span,
942 local.ty.as_ref().map(|ty| ty.span),
943 local.kind.init().map(|init| init.span),
944 )),
945 };
946 let original = replace(&mut self.diag_metadata.current_let_binding, local_spans);
947 self.resolve_local(local);
948 self.diag_metadata.current_let_binding = original;
949 }
950 fn visit_ty(&mut self, ty: &'ast Ty) {
951 let prev = self.diag_metadata.current_trait_object;
952 let prev_ty = self.diag_metadata.current_type_path;
953 match &ty.kind {
954 TyKind::Ref(None, ..) | TyKind::PinnedRef(None, ..) => {
955 let span = self.r.tcx.sess.source_map().start_point(ty.span);
959 self.resolve_elided_lifetime(ty.id, span);
960 visit::walk_ty(self, ty);
961 }
962 TyKind::Path(qself, path) => {
963 self.diag_metadata.current_type_path = Some(ty);
964
965 let source = if let Some(seg) = path.segments.last()
969 && let Some(args) = &seg.args
970 && #[allow(non_exhaustive_omitted_patterns)] match **args {
GenericArgs::ParenthesizedElided(..) => true,
_ => false,
}matches!(**args, GenericArgs::ParenthesizedElided(..))
971 {
972 PathSource::ReturnTypeNotation
973 } else {
974 PathSource::Type
975 };
976
977 self.smart_resolve_path(ty.id, qself, path, source);
978
979 if qself.is_none()
981 && let Some(partial_res) = self.r.partial_res_map.get(&ty.id)
982 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) =
983 partial_res.full_res()
984 {
985 let span = ty.span.shrink_to_lo().to(path.span.shrink_to_lo());
989 self.with_generic_param_rib(
990 &[],
991 RibKind::Normal,
992 ty.id,
993 LifetimeBinderKind::PolyTrait,
994 span,
995 |this| this.visit_path(path),
996 );
997 } else {
998 visit::walk_ty(self, ty)
999 }
1000 }
1001 TyKind::ImplicitSelf => {
1002 let self_ty = Ident::with_dummy_span(kw::SelfUpper);
1003 let res = self
1004 .resolve_ident_in_lexical_scope(
1005 self_ty,
1006 TypeNS,
1007 Some(Finalize::new(ty.id, ty.span)),
1008 None,
1009 )
1010 .map_or(Res::Err, |d| d.res());
1011 self.r.record_partial_res(ty.id, PartialRes::new(res));
1012 visit::walk_ty(self, ty)
1013 }
1014 TyKind::ImplTrait(..) => {
1015 let candidates = self.lifetime_elision_candidates.take();
1016 self.with_lifetime_rib(LifetimeRibKind::ImplTrait, |this| visit::walk_ty(this, ty));
1017 self.lifetime_elision_candidates = candidates;
1018 }
1019 TyKind::TraitObject(bounds, ..) => {
1020 self.diag_metadata.current_trait_object = Some(&bounds[..]);
1021 visit::walk_ty(self, ty)
1022 }
1023 TyKind::FnPtr(fn_ptr) => {
1024 let span = ty.span.shrink_to_lo().to(fn_ptr.decl_span.shrink_to_lo());
1025 self.with_generic_param_rib(
1026 &fn_ptr.generic_params,
1027 RibKind::Normal,
1028 ty.id,
1029 LifetimeBinderKind::FnPtrType,
1030 span,
1031 |this| {
1032 this.visit_generic_params(&fn_ptr.generic_params, false);
1033 this.resolve_fn_signature(
1034 ty.id,
1035 false,
1036 fn_ptr.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
1039 &fn_ptr.decl.output,
1040 false,
1041 )
1042 },
1043 )
1044 }
1045 TyKind::UnsafeBinder(unsafe_binder) => {
1046 let span = ty.span.shrink_to_lo().to(unsafe_binder.inner_ty.span.shrink_to_lo());
1047 self.with_generic_param_rib(
1048 &unsafe_binder.generic_params,
1049 RibKind::Normal,
1050 ty.id,
1051 LifetimeBinderKind::FnPtrType,
1052 span,
1053 |this| {
1054 this.visit_generic_params(&unsafe_binder.generic_params, false);
1055 this.with_lifetime_rib(
1056 LifetimeRibKind::AnonymousReportError,
1059 |this| this.visit_ty(&unsafe_binder.inner_ty),
1060 );
1061 },
1062 )
1063 }
1064 TyKind::Array(element_ty, length) => {
1065 self.visit_ty(element_ty);
1066 self.resolve_anon_const(length, AnonConstKind::ArrayLength);
1067 }
1068 TyKind::GcaMacro(expr) => self.resolve_anon_const_manual(
1069 true,
1070 AnonConstKind::ConstArg(IsRepeatExpr::No),
1071 |this| this.resolve_expr(expr, None),
1072 ),
1073 _ => visit::walk_ty(self, ty),
1074 }
1075 self.diag_metadata.current_trait_object = prev;
1076 self.diag_metadata.current_type_path = prev_ty;
1077 }
1078
1079 fn visit_ty_pat(&mut self, t: &'ast TyPat) -> Self::Result {
1080 match &t.kind {
1081 TyPatKind::Range(start, end, _) => {
1082 if let Some(start) = start {
1083 self.resolve_anon_const(start, AnonConstKind::ConstArg(IsRepeatExpr::No));
1084 }
1085 if let Some(end) = end {
1086 self.resolve_anon_const(end, AnonConstKind::ConstArg(IsRepeatExpr::No));
1087 }
1088 }
1089 TyPatKind::Or(patterns) => {
1090 for pat in patterns {
1091 self.visit_ty_pat(pat)
1092 }
1093 }
1094 TyPatKind::NotNull | TyPatKind::Err(_) => {}
1095 }
1096 }
1097
1098 fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef) {
1099 let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
1100 self.with_generic_param_rib(
1101 &tref.bound_generic_params,
1102 RibKind::Normal,
1103 tref.trait_ref.ref_id,
1104 LifetimeBinderKind::PolyTrait,
1105 span,
1106 |this| {
1107 this.visit_generic_params(&tref.bound_generic_params, false);
1108 this.smart_resolve_path(
1109 tref.trait_ref.ref_id,
1110 &None,
1111 &tref.trait_ref.path,
1112 PathSource::Trait(AliasPossibility::Maybe),
1113 );
1114 this.visit_trait_ref(&tref.trait_ref);
1115 },
1116 );
1117 }
1118 fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
1119 with_owner(self, foreign_item.id, |this| {
1120 this.resolve_doc_links(&foreign_item.attrs, MaybeExported::Ok(foreign_item.id));
1121 let def_kind = this.r.tcx.def_kind(this.r.current_owner.def_id);
1122 match foreign_item.kind {
1123 ForeignItemKind::TyAlias(TyAlias { ref generics, .. }) => {
1124 this.with_generic_param_rib(
1125 &generics.params,
1126 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
1127 foreign_item.id,
1128 LifetimeBinderKind::Item,
1129 generics.span,
1130 |this| visit::walk_item(this, foreign_item),
1131 );
1132 }
1133 ForeignItemKind::Fn(Fn { ref generics, .. }) => {
1134 this.with_generic_param_rib(
1135 &generics.params,
1136 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
1137 foreign_item.id,
1138 LifetimeBinderKind::Function,
1139 generics.span,
1140 |this| visit::walk_item(this, foreign_item),
1141 );
1142 }
1143 ForeignItemKind::Static(..) => {
1144 this.with_static_rib(def_kind, |this| visit::walk_item(this, foreign_item))
1145 }
1146 ForeignItemKind::MacCall(..) => {
1147 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
1148 }
1149 }
1150 })
1151 }
1152 fn visit_fn(&mut self, fn_kind: FnKind<'ast>, _: &AttrVec, sp: Span, fn_id: NodeId) {
1153 let previous_value = self.diag_metadata.current_function;
1154 match fn_kind {
1155 FnKind::Fn(FnCtxt::Foreign, _, Fn { sig, ident, generics, .. })
1158 | FnKind::Fn(_, _, Fn { sig, ident, generics, body: None, .. }) => {
1159 self.visit_fn_header(&sig.header);
1160 self.visit_ident(ident);
1161 self.visit_generics(generics);
1162 self.resolve_fn_signature(
1163 fn_id,
1164 sig.decl.has_self(),
1165 sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
1166 &sig.decl.output,
1167 false,
1168 );
1169 return;
1170 }
1171 FnKind::Fn(..) => {
1172 self.diag_metadata.current_function = Some((fn_kind, sp));
1173 }
1174 FnKind::Closure(..) => {}
1176 };
1177 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1177",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1177u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving function) entering function")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving function) entering function");
1178
1179 if let FnKind::Fn(_, _, f) = fn_kind {
1180 self.resolve_eii(f.eii_impl.as_deref());
1181 }
1182
1183 self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
1185 this.with_label_rib(RibKind::FnOrCoroutine, |this| {
1187 match fn_kind {
1188 FnKind::Fn(_, _, Fn { sig, generics, contract, body, .. }) => {
1189 this.visit_generics(generics);
1190
1191 let declaration = &sig.decl;
1192 this.resolve_fn_signature(
1193 fn_id,
1194 declaration.has_self(),
1195 declaration
1196 .inputs
1197 .iter()
1198 .map(|Param { pat, ty, .. }| (Some(&**pat), &**ty)),
1199 &declaration.output,
1200 sig.header.coroutine_marker.is_some(),
1201 );
1202
1203 if let Some(contract) = contract {
1204 this.visit_contract(contract);
1205 }
1206
1207 if let Some(body) = body {
1208 let previous_state = replace(&mut this.in_func_body, true);
1211 this.last_block_rib = None;
1213 this.with_lifetime_rib(
1216 LifetimeRibKind::elided(LifetimeRes::Infer),
1217 |this| this.visit_block(body),
1218 );
1219
1220 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1220",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1220u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving function) leaving function")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving function) leaving function");
1221 this.in_func_body = previous_state;
1222 }
1223 }
1224 FnKind::Closure(binder, _, declaration, body) => {
1225 this.visit_closure_binder(binder);
1226
1227 this.with_lifetime_rib(
1228 match binder {
1229 ClosureBinder::NotPresent => {
1231 LifetimeRibKind::AnonymousCreateParameter {
1232 binder: fn_id,
1233 report_in_path: false,
1234 }
1235 }
1236 ClosureBinder::For { .. } => LifetimeRibKind::AnonymousReportError,
1237 },
1238 |this| this.resolve_params(&declaration.inputs),
1240 );
1241 this.with_lifetime_rib(
1242 match binder {
1243 ClosureBinder::NotPresent => {
1244 LifetimeRibKind::elided(LifetimeRes::Infer)
1245 }
1246 ClosureBinder::For { .. } => LifetimeRibKind::AnonymousReportError,
1247 },
1248 |this| visit::walk_fn_ret_ty(this, &declaration.output),
1249 );
1250
1251 let previous_state = replace(&mut this.in_func_body, true);
1254 this.with_lifetime_rib(
1256 LifetimeRibKind::elided(LifetimeRes::Infer),
1257 |this| this.visit_expr(body),
1258 );
1259
1260 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1260",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1260u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving function) leaving function")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving function) leaving function");
1261 this.in_func_body = previous_state;
1262 }
1263 }
1264 })
1265 });
1266 self.diag_metadata.current_function = previous_value;
1267 }
1268
1269 fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::LifetimeCtxt) {
1270 self.resolve_lifetime(lifetime, use_ctxt)
1271 }
1272
1273 fn visit_precise_capturing_arg(&mut self, arg: &'ast PreciseCapturingArg) {
1274 match arg {
1275 PreciseCapturingArg::Lifetime(_) => {}
1278
1279 PreciseCapturingArg::Arg(path, id) => {
1280 let mut check_ns = |ns| {
1287 self.maybe_resolve_ident_in_lexical_scope(path.segments[0].ident, ns).is_some()
1288 };
1289 if !check_ns(TypeNS) && check_ns(ValueNS) {
1291 self.smart_resolve_path(
1292 *id,
1293 &None,
1294 path,
1295 PathSource::PreciseCapturingArg(ValueNS),
1296 );
1297 } else {
1298 self.smart_resolve_path(
1299 *id,
1300 &None,
1301 path,
1302 PathSource::PreciseCapturingArg(TypeNS),
1303 );
1304 }
1305 }
1306 }
1307
1308 visit::walk_precise_capturing_arg(self, arg)
1309 }
1310
1311 fn visit_generics(&mut self, generics: &'ast Generics) {
1312 self.visit_generic_params(&generics.params, self.diag_metadata.current_self_item.is_some());
1313 for p in &generics.where_clause.predicates {
1314 self.visit_where_predicate(p);
1315 }
1316 }
1317
1318 fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) {
1319 match b {
1320 ClosureBinder::NotPresent => {}
1321 ClosureBinder::For { generic_params, .. } => {
1322 self.visit_generic_params(
1323 generic_params,
1324 self.diag_metadata.current_self_item.is_some(),
1325 );
1326 }
1327 }
1328 }
1329
1330 {}
#[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_generic_arg",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1330u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("arg")
}> =
::tracing::__macro_support::FieldName::new("arg");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let prev =
replace(&mut self.diag_metadata.currently_processing_generic_args,
true);
match arg {
GenericArg::Type(ty) => {
if let TyKind::Path(None, ref path) = ty.kind &&
let Some(ident) = path.as_single_argless_ident() &&
self.maybe_resolve_ident_in_lexical_scope(ident,
TypeNS).is_none() &&
self.maybe_resolve_ident_in_lexical_scope(ident,
ValueNS).is_some() {
self.resolve_anon_const_manual(true,
AnonConstKind::ConstArg(IsRepeatExpr::No),
|this|
{
this.smart_resolve_path(ty.id, &None, path,
PathSource::Expr(None));
this.visit_path(path);
})
} else { self.visit_ty(ty) }
}
GenericArg::Lifetime(lt) =>
self.visit_lifetime(lt, visit::LifetimeCtxt::GenericArg),
GenericArg::Const(ct) => {
self.resolve_anon_const(ct,
AnonConstKind::ConstArg(IsRepeatExpr::No))
}
}
self.diag_metadata.currently_processing_generic_args = prev;
}
}
}#[instrument(level = "debug", skip(self))]
1331 fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
1332 let prev = replace(&mut self.diag_metadata.currently_processing_generic_args, true);
1333 match arg {
1334 GenericArg::Type(ty) => {
1335 if let TyKind::Path(None, ref path) = ty.kind
1344 && let Some(ident) = path.as_single_argless_ident()
1345 && self.maybe_resolve_ident_in_lexical_scope(ident, TypeNS).is_none()
1346 && self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS).is_some()
1347 {
1348 self.resolve_anon_const_manual(
1349 true,
1350 AnonConstKind::ConstArg(IsRepeatExpr::No),
1351 |this| {
1352 this.smart_resolve_path(ty.id, &None, path, PathSource::Expr(None));
1353 this.visit_path(path);
1354 },
1355 )
1356 } else {
1357 self.visit_ty(ty)
1358 }
1359 }
1360 GenericArg::Lifetime(lt) => self.visit_lifetime(lt, visit::LifetimeCtxt::GenericArg),
1361 GenericArg::Const(ct) => {
1362 self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No))
1363 }
1364 }
1365 self.diag_metadata.currently_processing_generic_args = prev;
1366 }
1367
1368 fn visit_assoc_item_constraint(&mut self, constraint: &'ast AssocItemConstraint) {
1369 self.visit_ident(&constraint.ident);
1370 if let Some(ref gen_args) = constraint.gen_args {
1371 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1373 this.visit_generic_args(gen_args)
1374 });
1375 }
1376 match constraint.kind {
1377 AssocItemConstraintKind::Equality { ref term } => match term {
1378 Term::Ty(ty) => {
1379 let prev = replace(&mut self.diag_metadata.in_assoc_ty_binding, true);
1380 self.visit_ty(ty);
1381 self.diag_metadata.in_assoc_ty_binding = prev;
1382 }
1383 Term::Const(c) => {
1384 self.resolve_anon_const(c, AnonConstKind::ConstArg(IsRepeatExpr::No))
1385 }
1386 },
1387 AssocItemConstraintKind::Bound { ref bounds } => {
1388 for elem in bounds {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_param_bound(elem,
BoundKind::Bound)) {
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, BoundKind::Bound);
1389 }
1390 }
1391 }
1392
1393 fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
1394 let Some(ref args) = path_segment.args else {
1395 return;
1396 };
1397
1398 match &**args {
1399 GenericArgs::AngleBracketed(..) => visit::walk_generic_args(self, args),
1400 GenericArgs::Parenthesized(p_args) => {
1401 for rib in self.lifetime_ribs.iter().rev() {
1403 match rib.kind {
1404 LifetimeRibKind::Generics {
1407 binder,
1408 kind: LifetimeBinderKind::PolyTrait,
1409 ..
1410 } => {
1411 self.resolve_fn_signature(
1412 binder,
1413 false,
1414 p_args.inputs.iter().map(|param| (None, &*param.ty)),
1415 &p_args.output,
1416 false,
1417 );
1418 break;
1419 }
1420 LifetimeRibKind::Item | LifetimeRibKind::Generics { .. } => {
1423 visit::walk_generic_args(self, args);
1424 break;
1425 }
1426 LifetimeRibKind::AnonymousCreateParameter { .. }
1427 | LifetimeRibKind::AnonymousReportError
1428 | LifetimeRibKind::ImplTrait
1429 | LifetimeRibKind::Elided { .. }
1430 | LifetimeRibKind::ElisionFailure
1431 | LifetimeRibKind::ConcreteAnonConst(_)
1432 | LifetimeRibKind::ConstParamTy => {}
1433 }
1434 }
1435 }
1436 GenericArgs::ParenthesizedElided(_) => {}
1437 }
1438 }
1439
1440 fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
1441 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1441",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1441u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit_where_predicate {0:?}",
p) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("visit_where_predicate {:?}", p);
1442 let previous_value = replace(&mut self.diag_metadata.current_where_predicate, Some(p));
1443 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1444 if let WherePredicateKind::BoundPredicate(WhereBoundPredicate {
1445 bounded_ty,
1446 bounds,
1447 bound_generic_params,
1448 ..
1449 }) = &p.kind
1450 {
1451 let span = p.span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
1452 this.with_generic_param_rib(
1453 bound_generic_params,
1454 RibKind::Normal,
1455 bounded_ty.id,
1456 LifetimeBinderKind::WhereBound,
1457 span,
1458 |this| {
1459 this.visit_generic_params(bound_generic_params, false);
1460 this.visit_ty(bounded_ty);
1461 for bound in bounds {
1462 this.visit_param_bound(bound, BoundKind::Bound)
1463 }
1464 },
1465 );
1466 } else {
1467 visit::walk_where_predicate(this, p);
1468 }
1469 });
1470 self.diag_metadata.current_where_predicate = previous_value;
1471 }
1472
1473 fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) {
1474 for (op, _) in &asm.operands {
1475 match op {
1476 InlineAsmOperand::In { expr, .. }
1477 | InlineAsmOperand::Out { expr: Some(expr), .. }
1478 | InlineAsmOperand::InOut { expr, .. } => self.visit_expr(expr),
1479 InlineAsmOperand::Out { expr: None, .. } => {}
1480 InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1481 self.visit_expr(in_expr);
1482 if let Some(out_expr) = out_expr {
1483 self.visit_expr(out_expr);
1484 }
1485 }
1486 InlineAsmOperand::Const { anon_const, .. } => {
1487 self.resolve_anon_const(anon_const, AnonConstKind::InlineConst);
1490 }
1491 InlineAsmOperand::Sym { sym } => self.visit_inline_asm_sym(sym),
1492 InlineAsmOperand::Label { block } => self.visit_block(block),
1493 }
1494 }
1495 }
1496
1497 fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
1498 self.with_rib(ValueNS, RibKind::InlineAsmSym, |this| {
1500 this.with_rib(TypeNS, RibKind::InlineAsmSym, |this| {
1501 this.with_label_rib(RibKind::InlineAsmSym, |this| {
1502 this.smart_resolve_path(sym.id, &sym.qself, &sym.path, PathSource::Expr(None));
1503 visit::walk_inline_asm_sym(this, sym);
1504 });
1505 })
1506 });
1507 }
1508
1509 fn visit_variant(&mut self, v: &'ast Variant) {
1510 self.resolve_doc_links(&v.attrs, MaybeExported::Ok(v.id));
1511 self.visit_id(v.id);
1512 for elem in &v.attrs {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_attribute(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_attribute, &v.attrs);
1513 self.visit_vis(&v.vis);
1514 self.visit_ident(&v.ident);
1515 self.visit_variant_data(&v.data);
1516 if let Some(discr) = &v.disr_expr {
1517 self.resolve_anon_const(discr, AnonConstKind::EnumDiscriminant);
1518 }
1519 }
1520
1521 fn visit_field_def(&mut self, f: &'ast FieldDef) {
1522 self.resolve_doc_links(&f.attrs, MaybeExported::Ok(f.id));
1523 let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _, extras: _ } = f;
1524 for elem in attrs {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_attribute(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_attribute, attrs);
1525 match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_vis(vis)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(self.visit_vis(vis));
1526 self.resolve_restriction_path(&f.mut_restriction().kind);
1527 if let Some(x) = ident {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_ident(x)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};visit_opt!(self, visit_ident, ident);
1528 match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_ty(ty)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(self.visit_ty(ty));
1529 if let Some(v) = f.default_value() {
1530 self.resolve_anon_const(v, AnonConstKind::FieldDefaultValue);
1531 }
1532 }
1533
1534 fn visit_test_binder_forall(&mut self, forall: &'ast TestBinderForall) {
1535 self.with_generic_param_rib(
1536 &forall.generics.params,
1537 RibKind::Normal,
1538 forall.node_id,
1539 LifetimeBinderKind::WhereBound,
1540 forall.span,
1541 |this| {
1542 this.visit_generics(&forall.generics);
1543 this.visit_test_binder_body(&forall.body)
1544 },
1545 );
1546 if let Some(assert_on_exit) = &forall.assert_on_exit {
1548 for constraint in assert_on_exit {
1549 self.visit_test_binder_constraint(constraint);
1550 }
1551 }
1552 }
1553
1554 fn visit_test_binder_exists(&mut self, exists: &'ast TestBinderExists) {
1555 self.with_generic_param_rib(
1556 &exists.params,
1557 RibKind::Normal,
1558 exists.node_id,
1559 LifetimeBinderKind::WhereBound,
1560 exists.span,
1561 |this| visit::walk_test_binder_exists(this, exists),
1562 );
1563 }
1564
1565 fn visit_test_binder_bound_type_constraint(
1566 &mut self,
1567 bound_type: &'ast TestBinderBoundTypeConstraint,
1568 ) {
1569 self.with_generic_param_rib(
1570 &bound_type.params,
1571 RibKind::Normal,
1572 bound_type.node_id,
1573 LifetimeBinderKind::WhereBound,
1574 bound_type.lhs.span.to(bound_type.rhs.ident.span),
1575 |this| visit::walk_test_binder_bound_type_constraint(this, bound_type),
1576 );
1577 }
1578}
1579
1580impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1581 fn new(resolver: &'a mut Resolver<'ra, 'tcx>) -> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1582 let graph_root = resolver.graph_root;
1585 let parent_scope = ParentScope::module(graph_root, resolver.arenas);
1586 let start_rib_kind = RibKind::Module(graph_root);
1587 LateResolutionVisitor {
1588 r: resolver,
1589 parent_scope,
1590 ribs: PerNS {
1591 value_ns: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[Rib::new(start_rib_kind)]))vec![Rib::new(start_rib_kind)],
1592 type_ns: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[Rib::new(start_rib_kind)]))vec![Rib::new(start_rib_kind)],
1593 macro_ns: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[Rib::new(start_rib_kind)]))vec![Rib::new(start_rib_kind)],
1594 },
1595 last_block_rib: None,
1596 label_ribs: Vec::new(),
1597 lifetime_ribs: Vec::new(),
1598 lifetime_elision_candidates: None,
1599 current_trait_ref: None,
1600 diag_metadata: Default::default(),
1601 in_func_body: false,
1603 lifetime_uses: Default::default(),
1604 use_injections: Vec::new(),
1605 use_items: Vec::new(),
1606 }
1607 }
1608
1609 fn maybe_resolve_ident_in_lexical_scope(
1610 &mut self,
1611 ident: Ident,
1612 ns: Namespace,
1613 ) -> Option<LateDecl<'ra>> {
1614 self.r.resolve_ident_in_lexical_scope(
1615 ident,
1616 ns,
1617 &self.parent_scope,
1618 None,
1619 &self.ribs[ns],
1620 None,
1621 Some(&self.diag_metadata),
1622 )
1623 }
1624
1625 fn resolve_ident_in_lexical_scope(
1626 &mut self,
1627 ident: Ident,
1628 ns: Namespace,
1629 finalize: Option<Finalize>,
1630 ignore_decl: Option<Decl<'ra>>,
1631 ) -> Option<LateDecl<'ra>> {
1632 self.r.resolve_ident_in_lexical_scope(
1633 ident,
1634 ns,
1635 &self.parent_scope,
1636 finalize,
1637 &self.ribs[ns],
1638 ignore_decl,
1639 Some(&self.diag_metadata),
1640 )
1641 }
1642
1643 fn resolve_path(
1644 &mut self,
1645 path: &[Segment],
1646 opt_ns: Option<Namespace>, finalize: Option<Finalize>,
1648 source: PathSource<'_, 'ast, 'ra>,
1649 ) -> PathResult<'ra> {
1650 self.r.cm_mut().resolve_path_with_ribs(
1651 path,
1652 opt_ns,
1653 &self.parent_scope,
1654 Some(source),
1655 finalize.map(|finalize| Finalize { stage: Stage::Late, ..finalize }),
1656 Some(&self.ribs),
1657 None,
1658 None,
1659 Some(&self.diag_metadata),
1660 )
1661 }
1662
1663 fn with_rib<T>(
1683 &mut self,
1684 ns: Namespace,
1685 kind: RibKind<'ra>,
1686 work: impl FnOnce(&mut Self) -> T,
1687 ) -> T {
1688 self.ribs[ns].push(Rib::new(kind));
1689 let ret = work(self);
1690 self.ribs[ns].pop();
1691 ret
1692 }
1693
1694 fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) {
1695 let mut forward_ty_ban_rib =
1701 Rib::new(RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::Default));
1702 let mut forward_const_ban_rib =
1703 Rib::new(RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::Default));
1704 for param in params.iter() {
1705 match param.kind {
1706 GenericParamKind::Type { .. } => {
1707 forward_ty_ban_rib
1708 .bindings
1709 .insert(Ident::with_dummy_span(param.ident.name), Res::Err);
1710 }
1711 GenericParamKind::Const { .. } => {
1712 forward_const_ban_rib
1713 .bindings
1714 .insert(Ident::with_dummy_span(param.ident.name), Res::Err);
1715 }
1716 GenericParamKind::Lifetime => {}
1717 }
1718 }
1719
1720 if add_self_upper {
1730 forward_ty_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
1732 }
1733
1734 let mut forward_ty_ban_rib_const_param_ty = Rib {
1737 bindings: forward_ty_ban_rib.bindings.clone(),
1738 patterns_with_skipped_bindings: Default::default(),
1739 kind: RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::ConstParamTy),
1740 };
1741 let mut forward_const_ban_rib_const_param_ty = Rib {
1742 bindings: forward_const_ban_rib.bindings.clone(),
1743 patterns_with_skipped_bindings: Default::default(),
1744 kind: RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::ConstParamTy),
1745 };
1746 if !self.r.features.generic_const_parameter_types() {
1749 forward_ty_ban_rib_const_param_ty.bindings.clear();
1750 forward_const_ban_rib_const_param_ty.bindings.clear();
1751 }
1752
1753 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1754 for param in params {
1755 match param.kind {
1756 GenericParamKind::Lifetime => {
1757 for bound in ¶m.bounds {
1758 this.visit_param_bound(bound, BoundKind::Bound);
1759 }
1760 }
1761 GenericParamKind::Type { ref default } => {
1762 for bound in ¶m.bounds {
1763 this.visit_param_bound(bound, BoundKind::Bound);
1764 }
1765
1766 if let Some(ty) = default {
1767 this.ribs[TypeNS].push(forward_ty_ban_rib);
1768 this.ribs[ValueNS].push(forward_const_ban_rib);
1769 this.visit_ty(ty);
1770 forward_const_ban_rib = this.ribs[ValueNS].pop().unwrap();
1771 forward_ty_ban_rib = this.ribs[TypeNS].pop().unwrap();
1772 }
1773
1774 let i = &Ident::with_dummy_span(param.ident.name);
1776 forward_ty_ban_rib.bindings.swap_remove(i);
1777 forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i);
1778 }
1779 GenericParamKind::Const { ref ty, span: _, ref default } => {
1780 if !param.bounds.is_empty() {
::core::panicking::panic("assertion failed: param.bounds.is_empty()")
};assert!(param.bounds.is_empty());
1782
1783 this.ribs[TypeNS].push(forward_ty_ban_rib_const_param_ty);
1784 this.ribs[ValueNS].push(forward_const_ban_rib_const_param_ty);
1785 if this.r.features.generic_const_parameter_types() {
1786 this.visit_ty(ty)
1787 } else {
1788 this.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTy));
1789 this.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTy));
1790 this.with_lifetime_rib(LifetimeRibKind::ConstParamTy, |this| {
1791 this.visit_ty(ty)
1792 });
1793 this.ribs[TypeNS].pop().unwrap();
1794 this.ribs[ValueNS].pop().unwrap();
1795 }
1796 forward_const_ban_rib_const_param_ty = this.ribs[ValueNS].pop().unwrap();
1797 forward_ty_ban_rib_const_param_ty = this.ribs[TypeNS].pop().unwrap();
1798
1799 if let Some(expr) = default {
1800 this.ribs[TypeNS].push(forward_ty_ban_rib);
1801 this.ribs[ValueNS].push(forward_const_ban_rib);
1802 this.resolve_anon_const(
1803 expr,
1804 AnonConstKind::ConstArg(IsRepeatExpr::No),
1805 );
1806 forward_const_ban_rib = this.ribs[ValueNS].pop().unwrap();
1807 forward_ty_ban_rib = this.ribs[TypeNS].pop().unwrap();
1808 }
1809
1810 let i = &Ident::with_dummy_span(param.ident.name);
1812 forward_const_ban_rib.bindings.swap_remove(i);
1813 forward_const_ban_rib_const_param_ty.bindings.swap_remove(i);
1814 }
1815 }
1816 }
1817 })
1818 }
1819
1820 {}
#[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("with_lifetime_rib",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1820u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: T = loop {};
return __tracing_attr_fake_return;
}
{
self.lifetime_ribs.push(LifetimeRib::new(kind));
let outer_elision_candidates =
self.lifetime_elision_candidates.take();
let ret = work(self);
self.lifetime_elision_candidates = outer_elision_candidates;
self.lifetime_ribs.pop();
ret
}
}
}#[instrument(level = "debug", skip(self, work))]
1821 fn with_lifetime_rib<T>(
1822 &mut self,
1823 kind: LifetimeRibKind,
1824 work: impl FnOnce(&mut Self) -> T,
1825 ) -> T {
1826 self.lifetime_ribs.push(LifetimeRib::new(kind));
1827 let outer_elision_candidates = self.lifetime_elision_candidates.take();
1828 let ret = work(self);
1829 self.lifetime_elision_candidates = outer_elision_candidates;
1830 self.lifetime_ribs.pop();
1831 ret
1832 }
1833
1834 {}
#[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",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1834u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime")
}> =
::tracing::__macro_support::FieldName::new("lifetime");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("use_ctxt")
}> =
::tracing::__macro_support::FieldName::new("use_ctxt");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&use_ctxt)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let ident = lifetime.ident;
if ident.name == kw::StaticLifetime {
self.record_lifetime_use(lifetime.id, LifetimeRes::Static,
LifetimeElisionCandidate::Ignore);
return;
}
if ident.name == kw::UnderscoreLifetime {
return self.resolve_anonymous_lifetime(lifetime, lifetime.id,
false);
}
let mut lifetime_rib_iter = self.lifetime_ribs.iter().rev();
while let Some(rib) = lifetime_rib_iter.next() {
let normalized_ident = ident.normalize_to_macros_2_0();
if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
self.record_lifetime_use(lifetime.id, res,
LifetimeElisionCandidate::Ignore);
if let LifetimeRes::Param { param, binder } = res {
match self.lifetime_uses.entry(param) {
Entry::Vacant(v) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1860",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1860u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("First use of {0:?} at {1:?}",
res, ident.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let use_set =
self.lifetime_ribs.iter().rev().find_map(|rib|
match rib.kind {
LifetimeRibKind::Item |
LifetimeRibKind::AnonymousReportError |
LifetimeRibKind::ElisionFailure =>
Some(LifetimeUseSet::Many),
LifetimeRibKind::AnonymousCreateParameter {
binder: anon_binder, .. } =>
Some(if binder == anon_binder {
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
} else { LifetimeUseSet::Many }),
LifetimeRibKind::Elided { res: r, error_in_path } => {
Some(if res == r && !error_in_path {
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
} else { LifetimeUseSet::Many })
}
LifetimeRibKind::Generics { .. } |
LifetimeRibKind::ConstParamTy => None,
LifetimeRibKind::ConcreteAnonConst(_) => {
::rustc_span::macros::bug_impl(Some(ident.span),
format_args!("unexpected rib kind: {0:?}", rib.kind),
Location::caller())
}
LifetimeRibKind::ImplTrait => {
if self.r.features.anonymous_lifetime_in_impl_trait() {
None
} else { Some(LifetimeUseSet::Many) }
}
}).unwrap_or(LifetimeUseSet::Many);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1905",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1905u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("use_ctxt")
}> =
::tracing::__macro_support::FieldName::new("use_ctxt");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("use_set")
}> =
::tracing::__macro_support::FieldName::new("use_set");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&use_ctxt)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&use_set)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
v.insert(use_set);
}
Entry::Occupied(mut o) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1909",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1909u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Many uses of {0:?} at {1:?}",
res, ident.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
*o.get_mut() = LifetimeUseSet::Many;
}
}
}
return;
}
match rib.kind {
LifetimeRibKind::Item => break,
LifetimeRibKind::ConstParamTy => {
let guar =
self.emit_non_static_lt_in_const_param_ty_error(lifetime);
self.record_lifetime_err(lifetime.id, guar);
return;
}
LifetimeRibKind::ConcreteAnonConst(cause) => {
let guar =
self.emit_forbidden_non_static_lifetime_error(cause,
lifetime);
self.record_lifetime_err(lifetime.id, guar);
return;
}
LifetimeRibKind::AnonymousCreateParameter { .. } |
LifetimeRibKind::Elided { .. } | LifetimeRibKind::Generics {
.. } | LifetimeRibKind::ElisionFailure |
LifetimeRibKind::AnonymousReportError |
LifetimeRibKind::ImplTrait => {}
}
}
let normalized_ident = ident.normalize_to_macros_2_0();
let outer_res =
lifetime_rib_iter.find_map(|rib|
rib.bindings.get_key_value(&normalized_ident).map(|(&outer,
_)| outer));
let guar =
self.emit_undeclared_lifetime_error(lifetime, outer_res);
self.record_lifetime_err(lifetime.id, guar);
}
}
}#[instrument(level = "debug", skip(self))]
1835 fn resolve_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::LifetimeCtxt) {
1836 let ident = lifetime.ident;
1837
1838 if ident.name == kw::StaticLifetime {
1839 self.record_lifetime_use(
1840 lifetime.id,
1841 LifetimeRes::Static,
1842 LifetimeElisionCandidate::Ignore,
1843 );
1844 return;
1845 }
1846
1847 if ident.name == kw::UnderscoreLifetime {
1848 return self.resolve_anonymous_lifetime(lifetime, lifetime.id, false);
1849 }
1850
1851 let mut lifetime_rib_iter = self.lifetime_ribs.iter().rev();
1852 while let Some(rib) = lifetime_rib_iter.next() {
1853 let normalized_ident = ident.normalize_to_macros_2_0();
1854 if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
1855 self.record_lifetime_use(lifetime.id, res, LifetimeElisionCandidate::Ignore);
1856
1857 if let LifetimeRes::Param { param, binder } = res {
1858 match self.lifetime_uses.entry(param) {
1859 Entry::Vacant(v) => {
1860 debug!("First use of {:?} at {:?}", res, ident.span);
1861 let use_set = self
1862 .lifetime_ribs
1863 .iter()
1864 .rev()
1865 .find_map(|rib| match rib.kind {
1866 LifetimeRibKind::Item
1869 | LifetimeRibKind::AnonymousReportError
1870 | LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
1871 LifetimeRibKind::AnonymousCreateParameter {
1874 binder: anon_binder,
1875 ..
1876 } => Some(if binder == anon_binder {
1877 LifetimeUseSet::One { use_span: ident.span, use_ctxt }
1878 } else {
1879 LifetimeUseSet::Many
1880 }),
1881 LifetimeRibKind::Elided { res: r, error_in_path } => {
1884 Some(if res == r && !error_in_path {
1885 LifetimeUseSet::One { use_span: ident.span, use_ctxt }
1886 } else {
1887 LifetimeUseSet::Many
1888 })
1889 }
1890 LifetimeRibKind::Generics { .. }
1891 | LifetimeRibKind::ConstParamTy => None,
1892 LifetimeRibKind::ConcreteAnonConst(_) => {
1893 span_bug!(ident.span, "unexpected rib kind: {:?}", rib.kind)
1894 }
1895
1896 LifetimeRibKind::ImplTrait => {
1897 if self.r.features.anonymous_lifetime_in_impl_trait() {
1898 None
1899 } else {
1900 Some(LifetimeUseSet::Many)
1901 }
1902 }
1903 })
1904 .unwrap_or(LifetimeUseSet::Many);
1905 debug!(?use_ctxt, ?use_set);
1906 v.insert(use_set);
1907 }
1908 Entry::Occupied(mut o) => {
1909 debug!("Many uses of {:?} at {:?}", res, ident.span);
1910 *o.get_mut() = LifetimeUseSet::Many;
1911 }
1912 }
1913 }
1914 return;
1915 }
1916
1917 match rib.kind {
1918 LifetimeRibKind::Item => break,
1919 LifetimeRibKind::ConstParamTy => {
1920 let guar = self.emit_non_static_lt_in_const_param_ty_error(lifetime);
1921 self.record_lifetime_err(lifetime.id, guar);
1922 return;
1923 }
1924 LifetimeRibKind::ConcreteAnonConst(cause) => {
1925 let guar = self.emit_forbidden_non_static_lifetime_error(cause, lifetime);
1926 self.record_lifetime_err(lifetime.id, guar);
1927 return;
1928 }
1929 LifetimeRibKind::AnonymousCreateParameter { .. }
1930 | LifetimeRibKind::Elided { .. }
1931 | LifetimeRibKind::Generics { .. }
1932 | LifetimeRibKind::ElisionFailure
1933 | LifetimeRibKind::AnonymousReportError
1934 | LifetimeRibKind::ImplTrait => {}
1935 }
1936 }
1937
1938 let normalized_ident = ident.normalize_to_macros_2_0();
1939 let outer_res = lifetime_rib_iter
1940 .find_map(|rib| rib.bindings.get_key_value(&normalized_ident).map(|(&outer, _)| outer));
1941
1942 let guar = self.emit_undeclared_lifetime_error(lifetime, outer_res);
1943 self.record_lifetime_err(lifetime.id, guar);
1944 }
1945
1946 {}
#[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_anonymous_lifetime",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1946u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime")
}> =
::tracing::__macro_support::FieldName::new("lifetime");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id_for_lint")
}> =
::tracing::__macro_support::FieldName::new("id_for_lint");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("elided")
}> =
::tracing::__macro_support::FieldName::new("elided");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id_for_lint)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&elided as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if true {
{
match (&lifetime.ident.name, &kw::UnderscoreLifetime) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
let kind =
if elided {
MissingLifetimeKind::Ampersand
} else { MissingLifetimeKind::Underscore };
let missing_lifetime =
MissingLifetime {
id: lifetime.id,
span: lifetime.ident.span,
kind,
count: 1,
id_for_lint,
};
let elision_candidate =
LifetimeElisionCandidate::Missing(missing_lifetime);
for (i, rib) in self.lifetime_ribs.iter().enumerate().rev() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:1966",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1966u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rib.kind")
}> =
::tracing::__macro_support::FieldName::new("rib.kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rib.kind)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match rib.kind {
LifetimeRibKind::AnonymousCreateParameter { binder, .. } =>
{
let res =
self.create_fresh_lifetime(lifetime.ident, binder, kind);
self.record_lifetime_use(lifetime.id, res,
elision_candidate);
return;
}
LifetimeRibKind::AnonymousReportError => {
let guar =
if elided {
let suggestion =
if self.diag_metadata.in_assoc_ty_binding {
None
} else {
self.lifetime_ribs[i..].iter().rev().find_map(|rib|
{
if let LifetimeRibKind::Generics {
span,
kind: LifetimeBinderKind::PolyTrait |
LifetimeBinderKind::WhereBound, .. } = rib.kind {
Some(crate::diagnostics::ElidedAnonymousLifetimeReportErrorSuggestion {
lo: span.shrink_to_lo(),
hi: lifetime.ident.span.shrink_to_hi(),
})
} else { None }
})
};
if !self.in_func_body &&
let Some((module, _)) = &self.current_trait_ref &&
let Some(ty) = &self.diag_metadata.current_self_type &&
Some(true) == self.diag_metadata.in_non_gat_assoc_type &&
let crate::ModuleKind::Def(DefKind::Trait, trait_id, _, _) =
module.kind {
if def_id_matches_path(self.r.tcx, trait_id,
&["core", "iter", "traits", "iterator", "Iterator"]) {
self.r.dcx().emit_err(crate::diagnostics::LendingIteratorReportError {
lifetime: lifetime.ident.span,
ty: ty.span,
})
} else {
let decl =
if !trait_id.is_local() &&
let Some(assoc) = self.diag_metadata.current_impl_item &&
let AssocItemKind::Type(_) = assoc.kind &&
let assocs = self.r.tcx.associated_items(trait_id) &&
let Some(ident) = assoc.kind.ident() &&
let Some(assoc) =
assocs.find_by_ident_and_kind(self.r.tcx, ident,
AssocTag::Type, trait_id) {
let mut decl: MultiSpan =
self.r.tcx.def_span(assoc.def_id).into();
decl.push_span_label(self.r.tcx.def_span(trait_id),
String::new());
decl
} else { DUMMY_SP.into() };
let mut err =
self.r.dcx().create_err(crate::diagnostics::AnonymousLifetimeNonGatReportError {
lifetime: lifetime.ident.span,
decl,
});
self.point_at_impl_lifetimes(&mut err, i,
lifetime.ident.span);
err.emit_err()
}
} else if self.diag_metadata.in_assoc_ty_binding {
let mut err =
self.r.dcx().create_err(crate::diagnostics::ElidedAnonymousLifetimeReportError {
span: lifetime.ident.span,
suggestion,
});
self.suggest_introducing_lifetime_for_assoc_ty_binding(&mut err,
lifetime.ident.span);
err.emit_err()
} else {
self.r.dcx().emit_err(crate::diagnostics::ElidedAnonymousLifetimeReportError {
span: lifetime.ident.span,
suggestion,
})
}
} else {
self.r.dcx().emit_err(crate::diagnostics::ExplicitAnonymousLifetimeReportError {
span: lifetime.ident.span,
})
};
self.record_lifetime_err(lifetime.id, guar);
return;
}
LifetimeRibKind::Elided { res, .. } => {
self.record_lifetime_use(lifetime.id, res,
elision_candidate);
return;
}
LifetimeRibKind::ElisionFailure => {
self.diag_metadata.current_elision_failures.push((missing_lifetime,
Either::Left(lifetime.id)));
return;
}
LifetimeRibKind::Item => break,
LifetimeRibKind::Generics { .. } |
LifetimeRibKind::ConstParamTy | LifetimeRibKind::ImplTrait
=> {}
LifetimeRibKind::ConcreteAnonConst(_) => {
::rustc_span::macros::bug_impl(Some(lifetime.ident.span),
format_args!("unexpected rib kind: {0:?}", rib.kind),
Location::caller())
}
}
}
let guar =
self.report_missing_lifetime_specifiers([&missing_lifetime],
None);
self.record_lifetime_err(lifetime.id, guar);
}
}
}#[instrument(level = "debug", skip(self))]
1947 fn resolve_anonymous_lifetime(
1948 &mut self,
1949 lifetime: &Lifetime,
1950 id_for_lint: NodeId,
1951 elided: bool,
1952 ) {
1953 debug_assert_eq!(lifetime.ident.name, kw::UnderscoreLifetime);
1954
1955 let kind =
1956 if elided { MissingLifetimeKind::Ampersand } else { MissingLifetimeKind::Underscore };
1957 let missing_lifetime = MissingLifetime {
1958 id: lifetime.id,
1959 span: lifetime.ident.span,
1960 kind,
1961 count: 1,
1962 id_for_lint,
1963 };
1964 let elision_candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
1965 for (i, rib) in self.lifetime_ribs.iter().enumerate().rev() {
1966 debug!(?rib.kind);
1967 match rib.kind {
1968 LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
1969 let res = self.create_fresh_lifetime(lifetime.ident, binder, kind);
1970 self.record_lifetime_use(lifetime.id, res, elision_candidate);
1971 return;
1972 }
1973 LifetimeRibKind::AnonymousReportError => {
1974 let guar = if elided {
1975 let suggestion = if self.diag_metadata.in_assoc_ty_binding {
1976 None
1982 } else {
1983 self.lifetime_ribs[i..].iter().rev().find_map(|rib| {
1984 if let LifetimeRibKind::Generics {
1988 span,
1989 kind:
1990 LifetimeBinderKind::PolyTrait
1991 | LifetimeBinderKind::WhereBound,
1992 ..
1993 } = rib.kind
1994 {
1995 Some(crate::diagnostics::ElidedAnonymousLifetimeReportErrorSuggestion {
1996 lo: span.shrink_to_lo(),
1997 hi: lifetime.ident.span.shrink_to_hi(),
1998 })
1999 } else {
2000 None
2001 }
2002 })
2003 };
2004 if !self.in_func_body
2007 && let Some((module, _)) = &self.current_trait_ref
2008 && let Some(ty) = &self.diag_metadata.current_self_type
2009 && Some(true) == self.diag_metadata.in_non_gat_assoc_type
2010 && let crate::ModuleKind::Def(DefKind::Trait, trait_id, _, _) =
2011 module.kind
2012 {
2013 if def_id_matches_path(
2014 self.r.tcx,
2015 trait_id,
2016 &["core", "iter", "traits", "iterator", "Iterator"],
2017 ) {
2018 self.r.dcx().emit_err(
2019 crate::diagnostics::LendingIteratorReportError {
2020 lifetime: lifetime.ident.span,
2021 ty: ty.span,
2022 },
2023 )
2024 } else {
2025 let decl = if !trait_id.is_local()
2026 && let Some(assoc) = self.diag_metadata.current_impl_item
2027 && let AssocItemKind::Type(_) = assoc.kind
2028 && let assocs = self.r.tcx.associated_items(trait_id)
2029 && let Some(ident) = assoc.kind.ident()
2030 && let Some(assoc) = assocs.find_by_ident_and_kind(
2031 self.r.tcx,
2032 ident,
2033 AssocTag::Type,
2034 trait_id,
2035 ) {
2036 let mut decl: MultiSpan =
2037 self.r.tcx.def_span(assoc.def_id).into();
2038 decl.push_span_label(
2039 self.r.tcx.def_span(trait_id),
2040 String::new(),
2041 );
2042 decl
2043 } else {
2044 DUMMY_SP.into()
2045 };
2046 let mut err = self.r.dcx().create_err(
2047 crate::diagnostics::AnonymousLifetimeNonGatReportError {
2048 lifetime: lifetime.ident.span,
2049 decl,
2050 },
2051 );
2052 self.point_at_impl_lifetimes(&mut err, i, lifetime.ident.span);
2053 err.emit_err()
2054 }
2055 } else if self.diag_metadata.in_assoc_ty_binding {
2056 let mut err = self.r.dcx().create_err(
2061 crate::diagnostics::ElidedAnonymousLifetimeReportError {
2062 span: lifetime.ident.span,
2063 suggestion,
2064 },
2065 );
2066 self.suggest_introducing_lifetime_for_assoc_ty_binding(
2067 &mut err,
2068 lifetime.ident.span,
2069 );
2070 err.emit_err()
2071 } else {
2072 self.r.dcx().emit_err(
2073 crate::diagnostics::ElidedAnonymousLifetimeReportError {
2074 span: lifetime.ident.span,
2075 suggestion,
2076 },
2077 )
2078 }
2079 } else {
2080 self.r.dcx().emit_err(
2081 crate::diagnostics::ExplicitAnonymousLifetimeReportError {
2082 span: lifetime.ident.span,
2083 },
2084 )
2085 };
2086 self.record_lifetime_err(lifetime.id, guar);
2087 return;
2088 }
2089 LifetimeRibKind::Elided { res, .. } => {
2090 self.record_lifetime_use(lifetime.id, res, elision_candidate);
2091 return;
2092 }
2093 LifetimeRibKind::ElisionFailure => {
2094 self.diag_metadata
2095 .current_elision_failures
2096 .push((missing_lifetime, Either::Left(lifetime.id)));
2097 return;
2098 }
2099 LifetimeRibKind::Item => break,
2100 LifetimeRibKind::Generics { .. }
2101 | LifetimeRibKind::ConstParamTy
2102 | LifetimeRibKind::ImplTrait => {}
2103 LifetimeRibKind::ConcreteAnonConst(_) => {
2104 span_bug!(lifetime.ident.span, "unexpected rib kind: {:?}", rib.kind)
2106 }
2107 }
2108 }
2109 let guar = self.report_missing_lifetime_specifiers([&missing_lifetime], None);
2110 self.record_lifetime_err(lifetime.id, guar);
2111 }
2112
2113 fn point_at_impl_lifetimes(&mut self, err: &mut Diag<'_>, i: usize, lifetime: Span) {
2114 let Some((rib, span)) =
2115 self.lifetime_ribs[..i].iter().rev().find_map(|rib| match rib.kind {
2116 LifetimeRibKind::Generics { span, kind: LifetimeBinderKind::ImplBlock, .. } => {
2117 Some((rib, span))
2118 }
2119 _ => None,
2120 })
2121 else {
2122 return;
2123 };
2124 if !rib.bindings.is_empty() {
2125 err.span_label(
2126 span,
2127 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("there {0} named lifetime{1} specified on the impl block you could use",
if rib.bindings.len() == 1 { "is a" } else { "are" },
if rib.bindings.len() == 1 { "" } else { "s" }))
})format!(
2128 "there {} named lifetime{} specified on the impl block you could use",
2129 if rib.bindings.len() == 1 { "is a" } else { "are" },
2130 pluralize!(rib.bindings.len()),
2131 ),
2132 );
2133 if rib.bindings.len() == 1 {
2134 err.span_suggestion_verbose(
2135 lifetime.shrink_to_hi(),
2136 "consider using the lifetime from the impl block",
2137 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} ",
rib.bindings.keys().next().unwrap()))
})format!("{} ", rib.bindings.keys().next().unwrap()),
2138 Applicability::MaybeIncorrect,
2139 );
2140 }
2141 } else {
2142 struct AnonRefFinder;
2143 impl<'ast> Visitor<'ast> for AnonRefFinder {
2144 type Result = ControlFlow<Span>;
2145
2146 fn visit_ty(&mut self, ty: &'ast ast::Ty) -> Self::Result {
2147 if let ast::TyKind::Ref(None, inner_ty, _) = &ty.kind {
2148 return ControlFlow::Break(inner_ty.span.shrink_to_lo());
2149 }
2150 visit::walk_ty(self, ty)
2151 }
2152
2153 fn visit_lifetime(
2154 &mut self,
2155 lt: &'ast ast::Lifetime,
2156 _cx: visit::LifetimeCtxt,
2157 ) -> Self::Result {
2158 if lt.ident.name == kw::UnderscoreLifetime {
2159 return ControlFlow::Break(lt.ident.span);
2160 }
2161 visit::walk_lifetime(self, lt)
2162 }
2163 }
2164
2165 if let Some(ty) = &self.diag_metadata.current_self_type
2166 && let ControlFlow::Break(sp) = AnonRefFinder.visit_ty(ty)
2167 {
2168 err.multipart_suggestion(
2169 "add a lifetime to the impl block and use it in the self type and associated \
2170 type",
2171 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(span, "<'a>".to_string()), (sp, "'a ".to_string()),
(lifetime.shrink_to_hi(), "'a ".to_string())]))vec![
2172 (span, "<'a>".to_string()),
2173 (sp, "'a ".to_string()),
2174 (lifetime.shrink_to_hi(), "'a ".to_string()),
2175 ],
2176 Applicability::MaybeIncorrect,
2177 );
2178 } else if let Some(item) = &self.diag_metadata.current_item
2179 && let ItemKind::Impl(impl_) = &item.kind
2180 && let Some(of_trait) = &impl_.of_trait
2181 && let ControlFlow::Break(sp) = AnonRefFinder.visit_trait_ref(&of_trait.trait_ref)
2182 {
2183 err.multipart_suggestion(
2184 "add a lifetime to the impl block and use it in the trait and associated type",
2185 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(span, "<'a>".to_string()), (sp, "'a".to_string()),
(lifetime.shrink_to_hi(), "'a ".to_string())]))vec![
2186 (span, "<'a>".to_string()),
2187 (sp, "'a".to_string()),
2188 (lifetime.shrink_to_hi(), "'a ".to_string()),
2189 ],
2190 Applicability::MaybeIncorrect,
2191 );
2192 } else {
2193 err.span_label(
2194 span,
2195 "you could add a lifetime on the impl block, if the trait or the self type \
2196 could have one",
2197 );
2198 }
2199 }
2200 }
2201
2202 {}
#[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_elided_lifetime",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2202u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("anchor_id")
}> =
::tracing::__macro_support::FieldName::new("anchor_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&anchor_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let id = self.r.next_node_id();
let lt =
Lifetime {
id,
ident: Ident::new(kw::UnderscoreLifetime, span),
};
self.record_lifetime_use(anchor_id,
LifetimeRes::ElidedAnchor { start: id, end: id + 1 },
LifetimeElisionCandidate::Ignore);
self.resolve_anonymous_lifetime(<, anchor_id, true);
}
}
}#[instrument(level = "debug", skip(self))]
2203 fn resolve_elided_lifetime(&mut self, anchor_id: NodeId, span: Span) {
2204 let id = self.r.next_node_id();
2205 let lt = Lifetime { id, ident: Ident::new(kw::UnderscoreLifetime, span) };
2206
2207 self.record_lifetime_use(
2208 anchor_id,
2209 LifetimeRes::ElidedAnchor { start: id, end: id + 1 },
2210 LifetimeElisionCandidate::Ignore,
2211 );
2212 self.resolve_anonymous_lifetime(<, anchor_id, true);
2213 }
2214
2215 {}
#[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("create_fresh_lifetime",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2215u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ident")
}> =
::tracing::__macro_support::FieldName::new("ident");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("binder")
}> =
::tracing::__macro_support::FieldName::new("binder");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&binder)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: LifetimeRes = loop {};
return __tracing_attr_fake_return;
}
{
if true {
{
match (&ident.name, &kw::UnderscoreLifetime) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2223",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2223u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ident.span")
}> =
::tracing::__macro_support::FieldName::new("ident.span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident.span)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let param = self.r.next_node_id();
let res = LifetimeRes::Fresh { param, kind };
self.record_lifetime_def(param, res);
self.r.current_owner.extra_lifetime_params_map.entry(binder).or_insert_with(Vec::new).push((ident,
param, kind));
res
}
}
}#[instrument(level = "debug", skip(self))]
2216 fn create_fresh_lifetime(
2217 &mut self,
2218 ident: Ident,
2219 binder: NodeId,
2220 kind: MissingLifetimeKind,
2221 ) -> LifetimeRes {
2222 debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
2223 debug!(?ident.span);
2224
2225 let param = self.r.next_node_id();
2227 let res = LifetimeRes::Fresh { param, kind };
2228 self.record_lifetime_def(param, res);
2229
2230 self.r
2232 .current_owner
2233 .extra_lifetime_params_map
2234 .entry(binder)
2235 .or_insert_with(Vec::new)
2236 .push((ident, param, kind));
2237 res
2238 }
2239
2240 {}
#[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_elided_lifetimes_in_path",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2240u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("partial_res")
}> =
::tracing::__macro_support::FieldName::new("partial_res");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path_span")
}> =
::tracing::__macro_support::FieldName::new("path_span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&partial_res)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path_span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let proj_start = path.len() - partial_res.unresolved_segments();
for (i, segment) in path.iter().enumerate() {
if segment.has_lifetime_args { continue; }
let Some(segment_id) = segment.id else { continue; };
let type_def_id =
match partial_res.base_res() {
Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start =>
{
self.r.tcx.parent(def_id)
}
Res::Def(DefKind::Variant, def_id) if
i + 2 == proj_start && segment.has_generic_args => {
self.r.tcx.parent(def_id)
}
Res::Def(DefKind::Variant, def_id) if
i + 1 == proj_start &&
!i.checked_sub(1).is_some_and(|i| path[i].has_generic_args)
=> {
self.r.tcx.parent(def_id)
}
Res::Def(DefKind::Struct, def_id) |
Res::Def(DefKind::Union, def_id) |
Res::Def(DefKind::Enum, def_id) |
Res::Def(DefKind::TyAlias, def_id) |
Res::Def(DefKind::Trait, def_id) if i + 1 == proj_start => {
def_id
}
_ => continue,
};
let expected_lifetimes =
self.r.item_generics_num_lifetimes(type_def_id);
if expected_lifetimes == 0 { continue; }
let node_ids = self.r.next_node_ids(expected_lifetimes);
self.record_lifetime_use(segment_id,
LifetimeRes::ElidedAnchor {
start: node_ids.start,
end: node_ids.end,
}, LifetimeElisionCandidate::Ignore);
let inferred =
match source {
PathSource::Trait(..) | PathSource::TraitItem(..) |
PathSource::Type | PathSource::TypeParam |
PathSource::PreciseCapturingArg(..) |
PathSource::ReturnTypeNotation | PathSource::Macro |
PathSource::Module => false,
PathSource::Expr(..) | PathSource::Pat |
PathSource::Struct(_) | PathSource::TupleStruct(..) |
PathSource::DefineOpaques | PathSource::Delegation |
PathSource::ExternItemImpl => true,
};
if inferred {
for id in node_ids {
self.record_lifetime_use(id, LifetimeRes::Infer,
LifetimeElisionCandidate::Ignore);
}
continue;
}
let elided_lifetime_span =
if segment.has_generic_args {
segment.args_span.with_hi(segment.args_span.lo() +
BytePos(1))
} else {
segment.ident.span.find_ancestor_inside(path_span).unwrap_or(path_span)
};
let ident =
Ident::new(kw::UnderscoreLifetime, elided_lifetime_span);
let kind =
if segment.has_generic_args {
MissingLifetimeKind::Comma
} else { MissingLifetimeKind::Brackets };
let missing_lifetime =
MissingLifetime {
id: node_ids.start,
id_for_lint: segment_id,
span: elided_lifetime_span,
kind,
count: expected_lifetimes,
};
let mut should_lint = true;
for rib in self.lifetime_ribs.iter().rev() {
match rib.kind {
LifetimeRibKind::AnonymousCreateParameter {
report_in_path: true, .. } | LifetimeRibKind::Elided {
error_in_path: true, .. } => {
let sess = self.r.tcx.sess;
let subdiag =
elided_lifetime_in_path_suggestion(sess.source_map(),
expected_lifetimes, path_span, !segment.has_generic_args,
elided_lifetime_span);
let guar =
self.r.dcx().emit_err(crate::diagnostics::ImplicitElidedLifetimeNotAllowedHere {
span: path_span,
subdiag,
});
should_lint = false;
for id in node_ids { self.record_lifetime_err(id, guar); }
break;
}
LifetimeRibKind::AnonymousCreateParameter { binder, .. } =>
{
let mut candidate =
LifetimeElisionCandidate::Missing(missing_lifetime);
for id in node_ids {
let res = self.create_fresh_lifetime(ident, binder, kind);
self.record_lifetime_use(id, res,
replace(&mut candidate, LifetimeElisionCandidate::Ignore));
}
break;
}
LifetimeRibKind::Elided { res, error_in_path: false } => {
let mut candidate =
LifetimeElisionCandidate::Missing(missing_lifetime);
for id in node_ids {
self.record_lifetime_use(id, res,
replace(&mut candidate, LifetimeElisionCandidate::Ignore));
}
break;
}
LifetimeRibKind::ElisionFailure => {
self.diag_metadata.current_elision_failures.push((missing_lifetime,
Either::Right(node_ids)));
break;
}
LifetimeRibKind::AnonymousReportError |
LifetimeRibKind::Item => {
let guar =
self.report_missing_lifetime_specifiers([&missing_lifetime],
None);
for id in node_ids { self.record_lifetime_err(id, guar); }
break;
}
LifetimeRibKind::Generics { .. } |
LifetimeRibKind::ConstParamTy | LifetimeRibKind::ImplTrait
=> {}
LifetimeRibKind::ConcreteAnonConst(_) => {
::rustc_span::macros::bug_impl(Some(elided_lifetime_span),
format_args!("unexpected rib kind: {0:?}", rib.kind),
Location::caller())
}
}
}
if should_lint {
let include_angle_bracket = !segment.has_generic_args;
self.r.lint_buffer.dyn_buffer_lint_any(ELIDED_LIFETIMES_IN_PATHS,
segment_id, elided_lifetime_span,
move |dcx, level, sess|
{
let source_map =
sess.downcast_ref::<rustc_session::Session>().expect("expected a `Session`").source_map();
crate::diagnostics::ElidedLifetimesInPaths {
subdiag: elided_lifetime_in_path_suggestion(source_map,
expected_lifetimes, path_span, include_angle_bracket,
elided_lifetime_span),
}.into_diag(dcx, level)
});
}
}
}
}
}#[instrument(level = "debug", skip(self))]
2241 fn resolve_elided_lifetimes_in_path(
2242 &mut self,
2243 partial_res: PartialRes,
2244 path: &[Segment],
2245 source: PathSource<'_, 'ast, 'ra>,
2246 path_span: Span,
2247 ) {
2248 let proj_start = path.len() - partial_res.unresolved_segments();
2249 for (i, segment) in path.iter().enumerate() {
2250 if segment.has_lifetime_args {
2251 continue;
2252 }
2253 let Some(segment_id) = segment.id else {
2254 continue;
2255 };
2256
2257 let type_def_id = match partial_res.base_res() {
2260 Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start => {
2261 self.r.tcx.parent(def_id)
2262 }
2263 Res::Def(DefKind::Variant, def_id)
2264 if i + 2 == proj_start && segment.has_generic_args =>
2265 {
2266 self.r.tcx.parent(def_id)
2267 }
2268 Res::Def(DefKind::Variant, def_id)
2269 if i + 1 == proj_start
2270 && !i.checked_sub(1).is_some_and(|i| path[i].has_generic_args) =>
2271 {
2272 self.r.tcx.parent(def_id)
2273 }
2274 Res::Def(DefKind::Struct, def_id)
2275 | Res::Def(DefKind::Union, def_id)
2276 | Res::Def(DefKind::Enum, def_id)
2277 | Res::Def(DefKind::TyAlias, def_id)
2278 | Res::Def(DefKind::Trait, def_id)
2279 if i + 1 == proj_start =>
2280 {
2281 def_id
2282 }
2283 _ => continue,
2284 };
2285
2286 let expected_lifetimes = self.r.item_generics_num_lifetimes(type_def_id);
2287 if expected_lifetimes == 0 {
2288 continue;
2289 }
2290
2291 let node_ids = self.r.next_node_ids(expected_lifetimes);
2292 self.record_lifetime_use(
2293 segment_id,
2294 LifetimeRes::ElidedAnchor { start: node_ids.start, end: node_ids.end },
2295 LifetimeElisionCandidate::Ignore,
2296 );
2297
2298 let inferred = match source {
2299 PathSource::Trait(..)
2300 | PathSource::TraitItem(..)
2301 | PathSource::Type
2302 | PathSource::TypeParam
2303 | PathSource::PreciseCapturingArg(..)
2304 | PathSource::ReturnTypeNotation
2305 | PathSource::Macro
2306 | PathSource::Module => false,
2307 PathSource::Expr(..)
2308 | PathSource::Pat
2309 | PathSource::Struct(_)
2310 | PathSource::TupleStruct(..)
2311 | PathSource::DefineOpaques
2312 | PathSource::Delegation
2313 | PathSource::ExternItemImpl => true,
2314 };
2315 if inferred {
2316 for id in node_ids {
2319 self.record_lifetime_use(
2320 id,
2321 LifetimeRes::Infer,
2322 LifetimeElisionCandidate::Ignore,
2323 );
2324 }
2325 continue;
2326 }
2327
2328 let elided_lifetime_span = if segment.has_generic_args {
2329 segment.args_span.with_hi(segment.args_span.lo() + BytePos(1))
2331 } else {
2332 segment.ident.span.find_ancestor_inside(path_span).unwrap_or(path_span)
2336 };
2337 let ident = Ident::new(kw::UnderscoreLifetime, elided_lifetime_span);
2338
2339 let kind = if segment.has_generic_args {
2340 MissingLifetimeKind::Comma
2341 } else {
2342 MissingLifetimeKind::Brackets
2343 };
2344 let missing_lifetime = MissingLifetime {
2345 id: node_ids.start,
2346 id_for_lint: segment_id,
2347 span: elided_lifetime_span,
2348 kind,
2349 count: expected_lifetimes,
2350 };
2351 let mut should_lint = true;
2352 for rib in self.lifetime_ribs.iter().rev() {
2353 match rib.kind {
2354 LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
2361 | LifetimeRibKind::Elided { error_in_path: true, .. } => {
2362 let sess = self.r.tcx.sess;
2363 let subdiag = elided_lifetime_in_path_suggestion(
2364 sess.source_map(),
2365 expected_lifetimes,
2366 path_span,
2367 !segment.has_generic_args,
2368 elided_lifetime_span,
2369 );
2370 let guar = self.r.dcx().emit_err(
2371 crate::diagnostics::ImplicitElidedLifetimeNotAllowedHere {
2372 span: path_span,
2373 subdiag,
2374 },
2375 );
2376 should_lint = false;
2377
2378 for id in node_ids {
2379 self.record_lifetime_err(id, guar);
2380 }
2381 break;
2382 }
2383 LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
2385 let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
2387 for id in node_ids {
2388 let res = self.create_fresh_lifetime(ident, binder, kind);
2389 self.record_lifetime_use(
2390 id,
2391 res,
2392 replace(&mut candidate, LifetimeElisionCandidate::Ignore),
2393 );
2394 }
2395 break;
2396 }
2397 LifetimeRibKind::Elided { res, error_in_path: false } => {
2398 let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
2399 for id in node_ids {
2400 self.record_lifetime_use(
2401 id,
2402 res,
2403 replace(&mut candidate, LifetimeElisionCandidate::Ignore),
2404 );
2405 }
2406 break;
2407 }
2408 LifetimeRibKind::ElisionFailure => {
2409 self.diag_metadata
2410 .current_elision_failures
2411 .push((missing_lifetime, Either::Right(node_ids)));
2412 break;
2413 }
2414 LifetimeRibKind::AnonymousReportError | LifetimeRibKind::Item => {
2419 let guar =
2420 self.report_missing_lifetime_specifiers([&missing_lifetime], None);
2421 for id in node_ids {
2422 self.record_lifetime_err(id, guar);
2423 }
2424 break;
2425 }
2426 LifetimeRibKind::Generics { .. }
2427 | LifetimeRibKind::ConstParamTy
2428 | LifetimeRibKind::ImplTrait => {}
2429 LifetimeRibKind::ConcreteAnonConst(_) => {
2430 span_bug!(elided_lifetime_span, "unexpected rib kind: {:?}", rib.kind)
2432 }
2433 }
2434 }
2435
2436 if should_lint {
2437 let include_angle_bracket = !segment.has_generic_args;
2438 self.r.lint_buffer.dyn_buffer_lint_any(
2439 ELIDED_LIFETIMES_IN_PATHS,
2440 segment_id,
2441 elided_lifetime_span,
2442 move |dcx, level, sess| {
2443 let source_map = sess
2444 .downcast_ref::<rustc_session::Session>()
2445 .expect("expected a `Session`")
2446 .source_map();
2447 crate::diagnostics::ElidedLifetimesInPaths {
2448 subdiag: elided_lifetime_in_path_suggestion(
2449 source_map,
2450 expected_lifetimes,
2451 path_span,
2452 include_angle_bracket,
2453 elided_lifetime_span,
2454 ),
2455 }
2456 .into_diag(dcx, level)
2457 },
2458 );
2459 }
2460 }
2461 }
2462
2463 {}
#[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("record_lifetime_use",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2464u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
self.record_lifetime_def(id, res);
match res {
LifetimeRes::Param { .. } | LifetimeRes::Fresh { .. } |
LifetimeRes::Static { .. } => {
if let Some(ref mut candidates) =
self.lifetime_elision_candidates {
candidates.push((res, candidate));
}
}
LifetimeRes::Infer | LifetimeRes::Error(..) |
LifetimeRes::ElidedAnchor { .. } => {}
}
}
}
}#[instrument(level = "debug", skip(self))]
2465 fn record_lifetime_use(
2466 &mut self,
2467 id: NodeId,
2468 res: LifetimeRes,
2469 candidate: LifetimeElisionCandidate,
2470 ) {
2471 self.record_lifetime_def(id, res);
2472
2473 match res {
2474 LifetimeRes::Param { .. } | LifetimeRes::Fresh { .. } | LifetimeRes::Static { .. } => {
2475 if let Some(ref mut candidates) = self.lifetime_elision_candidates {
2476 candidates.push((res, candidate));
2477 }
2478 }
2479 LifetimeRes::Infer | LifetimeRes::Error(..) | LifetimeRes::ElidedAnchor { .. } => {}
2480 }
2481 }
2482
2483 {}
#[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("record_lifetime_err",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2485u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("guar")
}> =
::tracing::__macro_support::FieldName::new("guar");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&guar)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{ self.record_lifetime_def(id, LifetimeRes::Error(guar)); }
}
}#[instrument(level = "debug", skip(self))]
2486 fn record_lifetime_err(&mut self, id: NodeId, guar: ErrorGuaranteed) {
2487 self.record_lifetime_def(id, LifetimeRes::Error(guar));
2488 }
2489
2490 {}
#[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("record_lifetime_def",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2491u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(prev_res) =
self.r.current_owner.lifetimes_res_map.insert(id, res) {
{
::core::panicking::panic_fmt(format_args!("lifetime parameter {0:?} resolved multiple times ({1:?} before, {2:?} now)",
id, prev_res, res));
}
}
}
}
}#[instrument(level = "debug", skip(self))]
2492 fn record_lifetime_def(&mut self, id: NodeId, res: LifetimeRes) {
2493 if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) {
2494 panic!(
2495 "lifetime parameter {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)"
2496 )
2497 }
2498 }
2499
2500 {}
#[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_fn_signature",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2501u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_id")
}> =
::tracing::__macro_support::FieldName::new("fn_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("has_self")
}> =
::tracing::__macro_support::FieldName::new("has_self");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("output_ty")
}> =
::tracing::__macro_support::FieldName::new("output_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("report_elided_lifetimes_in_path")
}> =
::tracing::__macro_support::FieldName::new("report_elided_lifetimes_in_path");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&has_self as
&dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&report_elided_lifetimes_in_path
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let rib =
LifetimeRibKind::AnonymousCreateParameter {
binder: fn_id,
report_in_path: report_elided_lifetimes_in_path,
};
self.with_lifetime_rib(rib,
|this|
{
let elision_lifetime =
this.resolve_fn_params(has_self, inputs);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2517",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2517u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("elision_lifetime")
}> =
::tracing::__macro_support::FieldName::new("elision_lifetime");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&elision_lifetime)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let outer_failures =
take(&mut this.diag_metadata.current_elision_failures);
let output_rib =
if let Ok(res) = elision_lifetime.as_ref() {
if fn_id == this.r.current_owner.id {
this.r.current_owner.lifetime_elision_allowed = true;
}
LifetimeRibKind::elided(*res)
} else { LifetimeRibKind::ElisionFailure };
this.with_lifetime_rib(output_rib,
|this| visit::walk_fn_ret_ty(this, output_ty));
let elision_failures =
replace(&mut this.diag_metadata.current_elision_failures,
outer_failures);
if !elision_failures.is_empty() {
let Err(failure_info) =
elision_lifetime else {
::rustc_span::macros::bug_impl(None,
format_args!("impossible case reached"), Location::caller())
};
let guar =
this.report_missing_lifetime_specifiers(elision_failures.iter().map(|(missing_lifetime,
..)| missing_lifetime), Some(failure_info));
let mut record_res =
|lifetime| this.record_lifetime_err(lifetime, guar);
for (_, nodes) in elision_failures {
match nodes {
Either::Left(node_id) => record_res(node_id),
Either::Right(node_ids) => {
for lifetime in node_ids { record_res(lifetime) }
}
}
}
}
});
}
}
}#[instrument(level = "debug", skip(self, inputs))]
2502 fn resolve_fn_signature(
2503 &mut self,
2504 fn_id: NodeId,
2505 has_self: bool,
2506 inputs: impl Iterator<Item = (Option<&'ast Pat>, &'ast Ty)> + Clone,
2507 output_ty: &'ast FnRetTy,
2508 report_elided_lifetimes_in_path: bool,
2509 ) {
2510 let rib = LifetimeRibKind::AnonymousCreateParameter {
2511 binder: fn_id,
2512 report_in_path: report_elided_lifetimes_in_path,
2513 };
2514 self.with_lifetime_rib(rib, |this| {
2515 let elision_lifetime = this.resolve_fn_params(has_self, inputs);
2517 debug!(?elision_lifetime);
2518
2519 let outer_failures = take(&mut this.diag_metadata.current_elision_failures);
2520 let output_rib = if let Ok(res) = elision_lifetime.as_ref() {
2521 if fn_id == this.r.current_owner.id {
2522 this.r.current_owner.lifetime_elision_allowed = true;
2523 }
2524 LifetimeRibKind::elided(*res)
2525 } else {
2526 LifetimeRibKind::ElisionFailure
2527 };
2528 this.with_lifetime_rib(output_rib, |this| visit::walk_fn_ret_ty(this, output_ty));
2529 let elision_failures =
2530 replace(&mut this.diag_metadata.current_elision_failures, outer_failures);
2531 if !elision_failures.is_empty() {
2532 let Err(failure_info) = elision_lifetime else { bug!() };
2533 let guar = this.report_missing_lifetime_specifiers(
2534 elision_failures.iter().map(|(missing_lifetime, ..)| missing_lifetime),
2535 Some(failure_info),
2536 );
2537 let mut record_res = |lifetime| this.record_lifetime_err(lifetime, guar);
2538 for (_, nodes) in elision_failures {
2539 match nodes {
2540 Either::Left(node_id) => record_res(node_id),
2541 Either::Right(node_ids) => {
2542 for lifetime in node_ids {
2543 record_res(lifetime)
2544 }
2545 }
2546 }
2547 }
2548 }
2549 });
2550 }
2551
2552 fn resolve_fn_params(
2556 &mut self,
2557 has_self: bool,
2558 inputs: impl Iterator<Item = (Option<&'ast Pat>, &'ast Ty)> + Clone,
2559 ) -> Result<LifetimeRes, (Vec<MissingLifetime>, Vec<ElisionFnParameter>)> {
2560 enum Elision {
2561 None,
2563 Self_(LifetimeRes),
2565 Param(LifetimeRes),
2567 Err,
2569 }
2570
2571 let outer_candidates = self.lifetime_elision_candidates.take();
2573
2574 let mut elision_lifetime = Elision::None;
2576 let mut parameter_info = Vec::new();
2578 let mut all_candidates = Vec::new();
2579
2580 let mut bindings = {
let count = 0usize + 1usize;
let mut vec = ::smallvec::SmallVec::new();
if count <= vec.inline_size() {
vec.push((PatBoundCtx::Product, Default::default()));
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(),
[(PatBoundCtx::Product, Default::default())])))
}
}smallvec![(PatBoundCtx::Product, Default::default())];
2582 for (pat, _) in inputs.clone() {
2583 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2583",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2583u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolving bindings in pat = {0:?}",
pat) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolving bindings in pat = {pat:?}");
2584 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
2585 if let Some(pat) = pat {
2586 this.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
2587 }
2588 });
2589 }
2590 self.apply_pattern_bindings(bindings);
2591
2592 for (index, (pat, ty)) in inputs.enumerate() {
2593 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2593",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2593u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolving type for pat = {0:?}, ty = {1:?}",
pat, ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolving type for pat = {pat:?}, ty = {ty:?}");
2594 if true {
{
match self.lifetime_elision_candidates {
None => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val, "None",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.lifetime_elision_candidates, None);
2596 self.lifetime_elision_candidates = Some(Default::default());
2597 self.visit_ty(ty);
2598 let local_candidates = self.lifetime_elision_candidates.take();
2599
2600 if let Some(candidates) = local_candidates {
2601 let distinct: UnordSet<_> = candidates.iter().map(|(res, _)| *res).collect();
2602 let lifetime_count = distinct.len();
2603 if lifetime_count != 0 {
2604 parameter_info.push(ElisionFnParameter {
2605 index,
2606 ident: if let Some(pat) = pat
2607 && let PatKind::Ident(_, ident, _) = pat.kind
2608 {
2609 Some(ident)
2610 } else {
2611 None
2612 },
2613 lifetime_count,
2614 span: ty.span,
2615 });
2616 all_candidates.extend(candidates.into_iter().filter_map(|(_, candidate)| {
2617 match candidate {
2618 LifetimeElisionCandidate::Ignore => None,
2619 LifetimeElisionCandidate::Missing(missing) => Some(missing),
2620 }
2621 }));
2622 }
2623 if !distinct.is_empty() {
2624 match elision_lifetime {
2625 Elision::None => {
2627 if let Some(res) = distinct.get_only() {
2628 elision_lifetime = Elision::Param(*res)
2630 } else {
2631 elision_lifetime = Elision::Err;
2633 }
2634 }
2635 Elision::Param(_) => elision_lifetime = Elision::Err,
2637 Elision::Self_(_) | Elision::Err => {}
2639 }
2640 }
2641 }
2642
2643 if index == 0 && has_self {
2645 let self_lifetime = self.find_lifetime_for_self(ty);
2646 elision_lifetime = match self_lifetime {
2647 Set1::One(lifetime) => Elision::Self_(lifetime),
2649 Set1::Many => Elision::Err,
2654 Set1::Empty => Elision::None,
2657 }
2658 }
2659 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2659",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2659u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving function / closure) recorded parameter")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving function / closure) recorded parameter");
2660 }
2661
2662 if true {
{
match self.lifetime_elision_candidates {
None => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val, "None",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.lifetime_elision_candidates, None);
2664 self.lifetime_elision_candidates = outer_candidates;
2665
2666 if let Elision::Param(res) | Elision::Self_(res) = elision_lifetime {
2667 return Ok(res);
2668 }
2669
2670 Err((all_candidates, parameter_info))
2672 }
2673
2674 fn find_lifetime_for_self(&self, ty: &'ast Ty) -> Set1<LifetimeRes> {
2676 struct FindReferenceVisitor<'a, 'ra, 'tcx> {
2680 r: &'a Resolver<'ra, 'tcx>,
2681 impl_self: Option<Res>,
2682 lifetime: Set1<LifetimeRes>,
2683 }
2684
2685 impl<'ra> Visitor<'ra> for FindReferenceVisitor<'_, '_, '_> {
2686 fn visit_ty(&mut self, ty: &'ra Ty) {
2687 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2687",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2687u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("FindReferenceVisitor considering ty={0:?}",
ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("FindReferenceVisitor considering ty={:?}", ty);
2688 if let TyKind::Ref(lt, ..) | TyKind::PinnedRef(lt, ..) = ty.kind {
2689 let mut visitor =
2691 SelfVisitor { r: self.r, impl_self: self.impl_self, self_found: false };
2692 visitor.visit_ty(ty);
2693 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2693",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2693u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("FindReferenceVisitor: SelfVisitor self_found={0:?}",
visitor.self_found) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("FindReferenceVisitor: SelfVisitor self_found={:?}", visitor.self_found);
2694 if visitor.self_found {
2695 let lt_id = if let Some(lt) = lt {
2696 lt.id
2697 } else {
2698 let res = self.r.current_owner.lifetimes_res_map[&ty.id];
2699 let LifetimeRes::ElidedAnchor { start, .. } = res else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
Location::caller())bug!() };
2700 start
2701 };
2702 let lt_res = self.r.current_owner.lifetimes_res_map[<_id];
2703 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2703",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2703u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("FindReferenceVisitor inserting res={0:?}",
lt_res) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("FindReferenceVisitor inserting res={:?}", lt_res);
2704 self.lifetime.insert(lt_res);
2705 }
2706 }
2707 visit::walk_ty(self, ty)
2708 }
2709
2710 fn visit_expr(&mut self, _: &'ra Expr) {}
2713 }
2714
2715 struct SelfVisitor<'a, 'ra, 'tcx> {
2718 r: &'a Resolver<'ra, 'tcx>,
2719 impl_self: Option<Res>,
2720 self_found: bool,
2721 }
2722
2723 impl SelfVisitor<'_, '_, '_> {
2724 fn is_self_ty(&self, ty: &Ty) -> bool {
2726 match ty.kind {
2727 TyKind::ImplicitSelf => true,
2728 TyKind::Path(None, _) => {
2729 let path_res = self.r.partial_res_map[&ty.id].full_res();
2730 if let Some(Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }) = path_res {
2731 return true;
2732 }
2733 self.impl_self.is_some() && path_res == self.impl_self
2734 }
2735 _ => false,
2736 }
2737 }
2738 }
2739
2740 impl<'ra> Visitor<'ra> for SelfVisitor<'_, '_, '_> {
2741 fn visit_ty(&mut self, ty: &'ra Ty) {
2742 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2742",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2742u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("SelfVisitor considering ty={0:?}",
ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("SelfVisitor considering ty={:?}", ty);
2743 if self.is_self_ty(ty) {
2744 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2744",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2744u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("SelfVisitor found Self")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("SelfVisitor found Self");
2745 self.self_found = true;
2746 }
2747 visit::walk_ty(self, ty)
2748 }
2749
2750 fn visit_expr(&mut self, _: &'ra Expr) {}
2753 }
2754
2755 let impl_self = self
2756 .diag_metadata
2757 .current_self_type
2758 .and_then(|ty| {
2759 if let TyKind::Path(None, _) = ty.kind {
2760 self.r.partial_res_map.get(&ty.id)
2761 } else {
2762 None
2763 }
2764 })
2765 .and_then(|res| res.full_res())
2766 .filter(|res| {
2767 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum, _) |
Res::PrimTy(_) => true,
_ => false,
}matches!(
2771 res,
2772 Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum, _,) | Res::PrimTy(_)
2773 )
2774 });
2775 let mut visitor = FindReferenceVisitor { r: self.r, impl_self, lifetime: Set1::Empty };
2776 visitor.visit_ty(ty);
2777 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2777",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2777u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("FindReferenceVisitor found={0:?}",
visitor.lifetime) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("FindReferenceVisitor found={:?}", visitor.lifetime);
2778 visitor.lifetime
2779 }
2780
2781 fn resolve_label(&self, mut label: Ident) -> Result<(NodeId, Span), ResolutionError<'ra>> {
2784 let mut suggestion = None;
2785
2786 for i in (0..self.label_ribs.len()).rev() {
2787 let rib = &self.label_ribs[i];
2788
2789 if let RibKind::MacroDefinition(def) = rib.kind
2790 && def == self.r.macro_def(label.span.ctxt())
2793 {
2794 label.span.remove_mark();
2795 }
2796
2797 let ident = label.normalize_to_macro_rules();
2798 if let Some((ident, id)) = rib.bindings.get_key_value(&ident) {
2799 let definition_span = ident.span;
2800 return if self.is_label_valid_from_rib(i) {
2801 Ok((*id, definition_span))
2802 } else {
2803 Err(ResolutionError::UnreachableLabel {
2804 name: label.name,
2805 definition_span,
2806 suggestion,
2807 })
2808 };
2809 }
2810
2811 suggestion = suggestion.or_else(|| self.suggestion_for_label_in_rib(i, label));
2814 }
2815
2816 Err(ResolutionError::UndeclaredLabel { name: label.name, suggestion })
2817 }
2818
2819 fn is_label_valid_from_rib(&self, rib_index: usize) -> bool {
2821 let ribs = &self.label_ribs[rib_index + 1..];
2822 ribs.iter().all(|rib| !rib.kind.is_label_barrier())
2823 }
2824
2825 fn resolve_adt(&mut self, item: &'ast Item, generics: &'ast Generics) {
2826 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2826",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2826u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_adt")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_adt");
2827 let kind = self.r.tcx.def_kind(self.r.current_owner.def_id);
2828 self.with_current_self_item(item, |this| {
2829 this.with_generic_param_rib(
2830 &generics.params,
2831 RibKind::Item(HasGenericParams::Yes(generics.span), kind),
2832 item.id,
2833 LifetimeBinderKind::Item,
2834 generics.span,
2835 |this| {
2836 let item_def_id = this.r.current_owner.def_id.to_def_id();
2837 this.with_self_rib(
2838 Res::SelfTyAlias { alias_to: item_def_id, is_trait_impl: false },
2839 |this| {
2840 visit::walk_item(this, item);
2841 },
2842 );
2843 },
2844 );
2845 });
2846 }
2847
2848 fn future_proof_import(&mut self, use_tree: &UseTree) {
2849 if let [segment, rest @ ..] = use_tree.prefix.segments.as_slice() {
2850 let ident = segment.ident;
2851 if ident.is_path_segment_keyword() || ident.span.is_rust_2015() {
2852 return;
2853 }
2854
2855 let nss = match use_tree.kind {
2856 UseTreeKind::Simple(..) if rest.is_empty() => &[TypeNS, ValueNS][..],
2857 _ => &[TypeNS],
2858 };
2859 let report_error = |this: &Self, ns| {
2860 if this.should_report_errs() {
2861 let what = if ns == TypeNS { "type parameters" } else { "local variables" };
2862 this.r.dcx().emit_err(crate::diagnostics::ImportsCannotReferTo {
2863 span: ident.span,
2864 what,
2865 });
2866 }
2867 };
2868
2869 for &ns in nss {
2870 match self.maybe_resolve_ident_in_lexical_scope(ident, ns) {
2871 Some(LateDecl::RibDef(..)) => {
2872 report_error(self, ns);
2873 }
2874 Some(LateDecl::Decl(binding)) => {
2875 if let Some(LateDecl::RibDef(..)) =
2876 self.resolve_ident_in_lexical_scope(ident, ns, None, Some(binding))
2877 {
2878 report_error(self, ns);
2879 }
2880 }
2881 None => {}
2882 }
2883 }
2884 } else if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
2885 for use_tree in items {
2886 self.future_proof_import(&use_tree.inner);
2887 }
2888 }
2889 }
2890
2891 fn resolve_item(&mut self, item: &'ast Item) {
2892 let mut mod_inner_attrs_start = None;
2893 match item.kind {
2894 ItemKind::Mod(..) => {
2895 let attrs = if let Some(pos) = item.attrs.iter().position(|a| {
2897 a.doc_resolution_scope().is_some_and(|style| style == AttrStyle::Inner)
2898 }) {
2899 mod_inner_attrs_start = Some(pos);
2900 &item.attrs[..pos]
2901 } else {
2902 &item.attrs
2903 };
2904 self.resolve_doc_links(attrs, MaybeExported::Ok(item.id));
2905 }
2906 ItemKind::Impl(..) | ItemKind::Use(..) => {}
2907 _ => {
2908 self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
2909 }
2910 }
2911
2912 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:2912",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2912u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving item) resolving {0:?} ({1:?})",
item.kind.ident(), item.kind) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving item) resolving {:?} ({:?})", item.kind.ident(), item.kind);
2913
2914 let def_kind = self.r.tcx.def_kind(self.r.current_owner.def_id);
2915 match &item.kind {
2916 ItemKind::TyAlias(TyAlias { generics, .. }) => {
2917 self.with_generic_param_rib(
2918 &generics.params,
2919 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2920 item.id,
2921 LifetimeBinderKind::Item,
2922 generics.span,
2923 |this| visit::walk_item(this, item),
2924 );
2925 }
2926
2927 ItemKind::Fn(Fn { generics, define_opaque, .. }) => {
2928 self.with_generic_param_rib(
2929 &generics.params,
2930 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2931 item.id,
2932 LifetimeBinderKind::Function,
2933 generics.span,
2934 |this| visit::walk_item(this, item),
2935 );
2936 self.resolve_define_opaques(define_opaque);
2937 }
2938
2939 ItemKind::Enum(_, generics, _)
2940 | ItemKind::Struct(_, generics, _)
2941 | ItemKind::Union(_, generics, _) => {
2942 self.resolve_adt(item, generics);
2943 }
2944
2945 ItemKind::Impl(Impl { generics, of_trait, self_ty, items: impl_items, .. }) => {
2946 self.diag_metadata.current_impl_items = Some(impl_items);
2947 self.resolve_implementation(
2948 &item.attrs,
2949 generics,
2950 of_trait.as_deref(),
2951 self_ty,
2952 item.id,
2953 impl_items,
2954 );
2955 self.diag_metadata.current_impl_items = None;
2956 }
2957
2958 ItemKind::Trait(Trait { generics, bounds, items, impl_restriction, .. }) => {
2959 self.resolve_restriction_path(&impl_restriction.kind);
2961
2962 self.with_generic_param_rib(
2964 &generics.params,
2965 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2966 item.id,
2967 LifetimeBinderKind::Item,
2968 generics.span,
2969 |this| {
2970 let local_def_id = this.r.current_owner.def_id.to_def_id();
2971 this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
2972 this.visit_generics(generics);
2973 for elem in bounds {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_param_bound(elem,
BoundKind::SuperTraits)) {
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, BoundKind::SuperTraits);
2974 this.resolve_trait_items(items);
2975 });
2976 },
2977 );
2978 }
2979
2980 ItemKind::TraitAlias(TraitAlias { generics, bounds, .. }) => {
2981 self.with_generic_param_rib(
2983 &generics.params,
2984 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2985 item.id,
2986 LifetimeBinderKind::Item,
2987 generics.span,
2988 |this| {
2989 let local_def_id = this.r.current_owner.def_id.to_def_id();
2990 this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
2991 this.visit_generics(generics);
2992 for elem in bounds {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_param_bound(elem,
BoundKind::Bound)) {
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, BoundKind::Bound);
2993 });
2994 },
2995 );
2996 }
2997
2998 ItemKind::Mod(..) => {
2999 let module = self.r.expect_module(self.r.current_owner.def_id.to_def_id());
3000 let orig_module = replace(&mut self.parent_scope.module, module);
3001 self.with_rib(ValueNS, RibKind::Module(module.expect_local()), |this| {
3002 this.with_rib(TypeNS, RibKind::Module(module.expect_local()), |this| {
3003 let attrs = if let Some(pos) = mod_inner_attrs_start {
3006 &item.attrs[pos..]
3007 } else {
3008 &[]
3009 };
3010 this.resolve_doc_links(attrs, MaybeExported::Ok(item.id));
3011 let old_macro_rules = this.parent_scope.macro_rules;
3012 visit::walk_item(this, item);
3013 if item.attrs.iter().all(|attr| {
3016 !attr.has_name(sym::macro_use) && !attr.has_name(sym::macro_escape)
3017 }) {
3018 this.parent_scope.macro_rules = old_macro_rules;
3019 }
3020 })
3021 });
3022 self.parent_scope.module = orig_module;
3023 }
3024
3025 ItemKind::Static(ast::StaticItem {
3026 ident, ty, expr, define_opaque, eii_impl, ..
3027 }) => {
3028 self.with_static_rib(def_kind, |this| {
3029 this.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Static), |this| {
3030 this.visit_ty(ty);
3031 });
3032 if let Some(expr) = expr {
3033 this.resolve_static_body(expr, Some((*ident, ConstantItemKind::Static)));
3036 }
3037 });
3038 self.resolve_define_opaques(define_opaque);
3039 self.resolve_eii(eii_impl.as_deref());
3040 }
3041
3042 ItemKind::Const(ast::ConstItem {
3043 ident,
3044 generics,
3045 ty,
3046 body,
3047 define_opaque,
3048 defaultness: _,
3049 }) => {
3050 self.with_generic_param_rib(
3051 &generics.params,
3052 RibKind::Item(
3053 if self.r.features.generic_const_items() {
3054 HasGenericParams::Yes(generics.span)
3055 } else {
3056 HasGenericParams::No
3057 },
3058 def_kind,
3059 ),
3060 item.id,
3061 LifetimeBinderKind::ConstItem,
3062 generics.span,
3063 |this| {
3064 this.visit_generics(generics);
3065
3066 this.with_lifetime_rib(
3067 LifetimeRibKind::elided(LifetimeRes::Static),
3068 |this: &mut LateResolutionVisitor<'a, 'ast, 'ra, 'tcx>| {
3069 this.visit_ty(ty)
3070 },
3071 );
3072
3073 this.resolve_const_item_rhs(body, Some((*ident, ConstantItemKind::Const)));
3074 },
3075 );
3076 self.resolve_define_opaques(define_opaque);
3077 }
3078 ItemKind::ConstBlock(ConstBlockItem { id: _, span: _, block }) => self
3079 .with_generic_param_rib(
3080 &[],
3081 RibKind::Item(HasGenericParams::No, def_kind),
3082 item.id,
3083 LifetimeBinderKind::ConstItem,
3084 DUMMY_SP,
3085 |this| {
3086 this.with_lifetime_rib(
3087 LifetimeRibKind::elided(LifetimeRes::Infer),
3088 |this| {
3089 this.with_constant_rib(
3090 IsRepeatExpr::No,
3091 ConstantHasGenerics::Yes,
3092 ConstantRequiresType::No,
3093 Some((ConstBlockItem::IDENT, ConstantItemKind::Const)),
3094 |this| this.resolve_labeled_block(None, block.id, block),
3095 )
3096 },
3097 );
3098 },
3099 ),
3100
3101 ItemKind::Use(use_tree) => {
3102 self.use_items.push(item);
3103 let maybe_exported = match use_tree.kind {
3104 UseTreeKind::Simple(_) | UseTreeKind::Glob(_) => MaybeExported::Ok(item.id),
3105 UseTreeKind::Nested { .. } => MaybeExported::NestedUse(&item.vis),
3106 };
3107 self.resolve_doc_links(&item.attrs, maybe_exported);
3108
3109 self.future_proof_import(use_tree);
3110 }
3111
3112 ItemKind::MacroDef(_, macro_def) => {
3113 if macro_def.macro_rules {
3116 let def_id = self.r.current_owner.def_id;
3117 self.parent_scope.macro_rules = self.r.macro_rules_scopes[&def_id];
3118 }
3119
3120 if let Some(EiiDecl { foreign_item: extern_item_path, impl_unsafe: _ }) =
3121 ¯o_def.eii_declaration
3122 {
3123 self.smart_resolve_path(
3124 item.id,
3125 &None,
3126 extern_item_path,
3127 PathSource::ExternItemImpl,
3128 );
3129 }
3130 }
3131
3132 ItemKind::ForeignMod(_) | ItemKind::GlobalAsm(_) => {
3133 visit::walk_item(self, item);
3134 }
3135
3136 ItemKind::Delegation(delegation) => {
3137 let span = delegation.path.segments.last().unwrap().ident.span;
3138 self.with_generic_param_rib(
3139 &[],
3140 RibKind::Item(HasGenericParams::Yes(span), def_kind),
3141 item.id,
3142 LifetimeBinderKind::Function,
3143 span,
3144 |this| this.resolve_delegation(delegation, item.id, false),
3145 );
3146 }
3147
3148 ItemKind::ExternCrate(..) => self.use_items.push(item),
3149
3150 ItemKind::MacCall(_) | ItemKind::DelegationMac(..) => {
3151 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
3152 }
3153
3154 ItemKind::TestBinderConstraints(constraints) => {
3155 self.resolve_test_binder_constraints(constraints, item.id);
3156 }
3157 }
3158 }
3159
3160 fn with_generic_param_rib<F>(
3161 &mut self,
3162 params: &[GenericParam],
3163 kind: RibKind<'ra>,
3164 binder: NodeId,
3165 generics_kind: LifetimeBinderKind,
3166 generics_span: Span,
3167 f: F,
3168 ) where
3169 F: FnOnce(&mut Self),
3170 {
3171 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3171",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3171u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("with_generic_param_rib")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("with_generic_param_rib");
3172 let lifetime_kind =
3173 LifetimeRibKind::Generics { binder, span: generics_span, kind: generics_kind };
3174
3175 let mut function_type_rib = Rib::new(kind);
3176 let mut function_value_rib = Rib::new(kind);
3177 let mut function_lifetime_rib = LifetimeRib::new(lifetime_kind);
3178
3179 if !params.is_empty() {
3181 let mut seen_bindings = FxHashMap::default();
3182 let mut seen_lifetimes = FxHashSet::default();
3184
3185 for ns in [ValueNS, TypeNS] {
3187 for parent_rib in self.ribs[ns].iter().rev() {
3188 if #[allow(non_exhaustive_omitted_patterns)] match parent_rib.kind {
RibKind::Module(..) | RibKind::Block(..) => true,
_ => false,
}matches!(parent_rib.kind, RibKind::Module(..) | RibKind::Block(..)) {
3191 break;
3192 }
3193
3194 seen_bindings
3195 .extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
3196 }
3197 }
3198
3199 for rib in self.lifetime_ribs.iter().rev() {
3201 seen_lifetimes.extend(rib.bindings.iter().map(|(ident, _)| *ident));
3202 if let LifetimeRibKind::Item = rib.kind {
3203 break;
3204 }
3205 }
3206
3207 for param in params {
3208 let ident = param.ident.normalize_to_macros_2_0();
3209 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3209",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3209u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("with_generic_param_rib: {0}",
param.id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("with_generic_param_rib: {}", param.id);
3210
3211 if let GenericParamKind::Lifetime = param.kind
3212 && let Some(&original) = seen_lifetimes.get(&ident)
3213 {
3214 let guar = diagnostics::signal_lifetime_shadowing(
3215 self.r.tcx.sess,
3216 original,
3217 param.ident,
3218 );
3219 self.record_lifetime_err(param.id, guar);
3221 continue;
3222 }
3223
3224 match seen_bindings.entry(ident) {
3225 Entry::Occupied(entry) => {
3226 let span = *entry.get();
3227 let err = ResolutionError::NameAlreadyUsedInParameterList(ident, span);
3228 let guar = self.r.report_error(param.ident.span, err);
3229 let rib = match param.kind {
3230 GenericParamKind::Lifetime => {
3231 self.record_lifetime_err(param.id, guar);
3233 continue;
3234 }
3235 GenericParamKind::Type { .. } => &mut function_type_rib,
3236 GenericParamKind::Const { .. } => &mut function_value_rib,
3237 };
3238
3239 self.r.record_partial_res(param.id, PartialRes::new(Res::Err));
3241 rib.bindings.insert(ident, Res::Err);
3242 continue;
3243 }
3244 Entry::Vacant(entry) => {
3245 entry.insert(param.ident.span);
3246 }
3247 }
3248
3249 if param.ident.name == kw::UnderscoreLifetime {
3250 let is_raw_underscore_lifetime = self
3253 .r
3254 .tcx
3255 .sess
3256 .psess
3257 .raw_identifier_spans
3258 .iter()
3259 .any(|span| span == param.span());
3260
3261 let guar = self
3262 .r
3263 .dcx()
3264 .create_err(crate::diagnostics::UnderscoreLifetimeIsReserved {
3265 span: param.ident.span,
3266 })
3267 .emit_err_unless_delay(is_raw_underscore_lifetime);
3268 self.record_lifetime_err(param.id, guar);
3270 continue;
3271 }
3272
3273 if param.ident.name == kw::StaticLifetime {
3274 let guar =
3275 self.r.dcx().emit_err(crate::diagnostics::StaticLifetimeIsReserved {
3276 span: param.ident.span,
3277 lifetime: param.ident,
3278 });
3279 self.record_lifetime_err(param.id, guar);
3281 continue;
3282 }
3283
3284 let def_id = self.r.local_def_id(param.id);
3285
3286 let (rib, def_kind) = match param.kind {
3288 GenericParamKind::Type { .. } => (&mut function_type_rib, DefKind::TyParam),
3289 GenericParamKind::Const { .. } => {
3290 (&mut function_value_rib, DefKind::ConstParam)
3291 }
3292 GenericParamKind::Lifetime => {
3293 let res = LifetimeRes::Param { param: def_id, binder };
3294 self.record_lifetime_def(param.id, res);
3295 function_lifetime_rib.bindings.insert(ident, (param.id, res));
3296 continue;
3297 }
3298 };
3299
3300 let res = match kind {
3301 RibKind::Item(..) | RibKind::AssocItem => {
3302 Res::Def(def_kind, def_id.to_def_id())
3303 }
3304 RibKind::Normal => {
3305 if self.r.features.non_lifetime_binders()
3308 && #[allow(non_exhaustive_omitted_patterns)] match param.kind {
GenericParamKind::Type { .. } => true,
_ => false,
}matches!(param.kind, GenericParamKind::Type { .. })
3309 {
3310 Res::Def(def_kind, def_id.to_def_id())
3311 } else {
3312 Res::Err
3313 }
3314 }
3315 _ => ::rustc_span::macros::bug_impl(Some(param.ident.span),
format_args!("Unexpected rib kind {0:?}", kind), Location::caller())span_bug!(param.ident.span, "Unexpected rib kind {:?}", kind),
3316 };
3317 self.r.record_partial_res(param.id, PartialRes::new(res));
3318 rib.bindings.insert(ident, res);
3319 }
3320 }
3321
3322 self.lifetime_ribs.push(function_lifetime_rib);
3323 self.ribs[ValueNS].push(function_value_rib);
3324 self.ribs[TypeNS].push(function_type_rib);
3325
3326 f(self);
3327
3328 self.ribs[TypeNS].pop();
3329 self.ribs[ValueNS].pop();
3330 let function_lifetime_rib = self.lifetime_ribs.pop().unwrap();
3331
3332 if let Some(ref mut candidates) = self.lifetime_elision_candidates {
3334 for (_, res) in function_lifetime_rib.bindings.values() {
3335 candidates.retain(|(r, _)| r != res);
3336 }
3337 }
3338
3339 if let LifetimeBinderKind::FnPtrType
3340 | LifetimeBinderKind::WhereBound
3341 | LifetimeBinderKind::Function
3342 | LifetimeBinderKind::ImplBlock = generics_kind
3343 {
3344 self.maybe_report_lifetime_uses(generics_span, params)
3345 }
3346 }
3347
3348 fn with_label_rib(&mut self, kind: RibKind<'ra>, f: impl FnOnce(&mut Self)) {
3349 self.label_ribs.push(Rib::new(kind));
3350 f(self);
3351 self.label_ribs.pop();
3352 }
3353
3354 fn with_static_rib(&mut self, def_kind: DefKind, f: impl FnOnce(&mut Self)) {
3355 let kind = RibKind::Item(HasGenericParams::No, def_kind);
3356 self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
3357 }
3358
3359 {}
#[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("with_constant_rib",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3367u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_repeat")
}> =
::tracing::__macro_support::FieldName::new("is_repeat");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("may_use_generics")
}> =
::tracing::__macro_support::FieldName::new("may_use_generics");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("requires_type")
}> =
::tracing::__macro_support::FieldName::new("requires_type");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item")
}> =
::tracing::__macro_support::FieldName::new("item");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_repeat)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&may_use_generics)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&requires_type)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let f =
|this: &mut Self|
{
this.with_rib(ValueNS,
RibKind::ConstantItem(may_use_generics, item,
requires_type),
|this|
{
this.with_rib(TypeNS,
RibKind::ConstantItem(may_use_generics.force_yes_if(is_repeat
== IsRepeatExpr::Yes), item, requires_type),
|this|
{
this.with_label_rib(RibKind::ConstantItem(may_use_generics,
item, requires_type), f);
})
})
};
if let ConstantHasGenerics::No(cause) = may_use_generics {
self.with_lifetime_rib(LifetimeRibKind::ConcreteAnonConst(cause),
f)
} else { f(self) }
}
}
}#[instrument(level = "debug", skip(self, f))]
3368 fn with_constant_rib(
3369 &mut self,
3370 is_repeat: IsRepeatExpr,
3371 may_use_generics: ConstantHasGenerics,
3372 requires_type: ConstantRequiresType,
3373 item: Option<(Ident, ConstantItemKind)>,
3374 f: impl FnOnce(&mut Self),
3375 ) {
3376 let f = |this: &mut Self| {
3377 this.with_rib(
3378 ValueNS,
3379 RibKind::ConstantItem(may_use_generics, item, requires_type),
3380 |this| {
3381 this.with_rib(
3382 TypeNS,
3383 RibKind::ConstantItem(
3384 may_use_generics.force_yes_if(is_repeat == IsRepeatExpr::Yes),
3385 item,
3386 requires_type,
3387 ),
3388 |this| {
3389 this.with_label_rib(
3390 RibKind::ConstantItem(may_use_generics, item, requires_type),
3391 f,
3392 );
3393 },
3394 )
3395 },
3396 )
3397 };
3398
3399 if let ConstantHasGenerics::No(cause) = may_use_generics {
3400 self.with_lifetime_rib(LifetimeRibKind::ConcreteAnonConst(cause), f)
3401 } else {
3402 f(self)
3403 }
3404 }
3405
3406 fn with_current_self_type<T>(
3407 &mut self,
3408 self_type: &'ast Ty,
3409 f: impl FnOnce(&mut Self) -> T,
3410 ) -> T {
3411 let previous_value = replace(&mut self.diag_metadata.current_self_type, Some(self_type));
3413 let result = f(self);
3414 self.diag_metadata.current_self_type = previous_value;
3415 result
3416 }
3417
3418 fn with_current_self_item<T>(&mut self, self_item: &Item, f: impl FnOnce(&mut Self) -> T) -> T {
3419 let previous_value = replace(&mut self.diag_metadata.current_self_item, Some(self_item.id));
3420 let result = f(self);
3421 self.diag_metadata.current_self_item = previous_value;
3422 result
3423 }
3424
3425 fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) {
3427 let trait_assoc_items =
3428 replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
3429
3430 for item in trait_items {
3431 with_owner(self, item.id, |this| this.resolve_trait_item(item));
3432 }
3433
3434 self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
3435 }
3436
3437 fn resolve_trait_item(&mut self, item: &'ast Item<AssocItemKind>) {
3438 let walk_assoc_item =
3439 |this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
3440 this.with_generic_param_rib(
3441 &generics.params,
3442 RibKind::AssocItem,
3443 item.id,
3444 kind,
3445 generics.span,
3446 |this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
3447 );
3448 };
3449
3450 self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
3451 match &item.kind {
3452 AssocItemKind::Const(ast::ConstItem { generics, ty, body, define_opaque, .. }) => {
3453 self.with_generic_param_rib(
3454 &generics.params,
3455 RibKind::AssocItem,
3456 item.id,
3457 LifetimeBinderKind::ConstItem,
3458 generics.span,
3459 |this| {
3460 this.with_lifetime_rib(
3461 LifetimeRibKind::Elided {
3462 res: LifetimeRes::Static,
3463 error_in_path: true,
3464 },
3465 |this| {
3466 this.visit_generics(generics);
3467 this.visit_ty(ty);
3468 this.resolve_const_item_rhs(body, None);
3477 },
3478 )
3479 },
3480 );
3481
3482 self.resolve_define_opaques(define_opaque);
3483 }
3484 AssocItemKind::Fn(Fn { generics, define_opaque, .. }) => {
3485 walk_assoc_item(self, generics, LifetimeBinderKind::Function, item);
3486
3487 self.resolve_define_opaques(define_opaque);
3488 }
3489 AssocItemKind::Delegation(delegation) => {
3490 self.with_generic_param_rib(
3491 &[],
3492 RibKind::AssocItem,
3493 item.id,
3494 LifetimeBinderKind::Function,
3495 delegation.path.segments.last().unwrap().ident.span,
3496 |this| this.resolve_delegation(delegation, item.id, false),
3497 );
3498 }
3499 AssocItemKind::Type(TyAlias { generics, .. }) => self
3500 .with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
3501 walk_assoc_item(this, generics, LifetimeBinderKind::Item, item)
3502 }),
3503 AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
3504 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
3505 }
3506 };
3507 }
3508
3509 fn with_optional_trait_ref<T>(
3511 &mut self,
3512 opt_trait_ref: Option<&TraitRef>,
3513 self_type: &'ast Ty,
3514 f: impl FnOnce(&mut Self, Option<DefId>) -> T,
3515 ) -> T {
3516 let mut new_val = None;
3517 let mut new_id = None;
3518 if let Some(trait_ref) = opt_trait_ref {
3519 let path: Vec<_> = Segment::from_path(&trait_ref.path);
3520 self.diag_metadata.currently_processing_impl_trait =
3521 Some((trait_ref.clone(), self_type.clone()));
3522 let res = self.smart_resolve_path_fragment(
3523 &None,
3524 &path,
3525 PathSource::Trait(AliasPossibility::No),
3526 Finalize::new(trait_ref.ref_id, trait_ref.path.span),
3527 RecordPartialRes::Yes,
3528 None,
3529 );
3530 self.diag_metadata.currently_processing_impl_trait = None;
3531 if let Some(def_id) = res.expect_full_res().opt_def_id() {
3532 new_id = Some(def_id);
3533 new_val = Some((self.r.expect_module(def_id), trait_ref.clone()));
3534 }
3535 }
3536 let original_trait_ref = replace(&mut self.current_trait_ref, new_val);
3537 let result = f(self, new_id);
3538 self.current_trait_ref = original_trait_ref;
3539 result
3540 }
3541
3542 fn with_self_rib_ns(&mut self, ns: Namespace, self_res: Res, f: impl FnOnce(&mut Self)) {
3543 let mut self_type_rib = Rib::new(RibKind::Normal);
3544
3545 self_type_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), self_res);
3547 self.ribs[ns].push(self_type_rib);
3548 f(self);
3549 self.ribs[ns].pop();
3550 }
3551
3552 fn with_self_rib(&mut self, self_res: Res, f: impl FnOnce(&mut Self)) {
3553 self.with_self_rib_ns(TypeNS, self_res, f)
3554 }
3555
3556 fn resolve_implementation(
3557 &mut self,
3558 attrs: &[ast::Attribute],
3559 generics: &'ast Generics,
3560 of_trait: Option<&'ast ast::TraitImplHeader>,
3561 self_type: &'ast Ty,
3562 item_id: NodeId,
3563 impl_items: &'ast [Box<AssocItem>],
3564 ) {
3565 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3565",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3565u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation");
3566 self.with_generic_param_rib(
3568 &generics.params,
3569 RibKind::Item(HasGenericParams::Yes(generics.span), self.r.tcx.def_kind(self.r.current_owner.def_id)),
3570 item_id,
3571 LifetimeBinderKind::ImplBlock,
3572 generics.span,
3573 |this| {
3574 this.with_self_rib(Res::SelfTyParam { trait_: LOCAL_CRATE.as_def_id() }, |this| {
3576 this.with_lifetime_rib(
3577 LifetimeRibKind::AnonymousCreateParameter {
3578 binder: item_id,
3579 report_in_path: true
3580 },
3581 |this| {
3582 this.with_optional_trait_ref(
3584 of_trait.map(|t| &t.trait_ref),
3585 self_type,
3586 |this, trait_id| {
3587 this.resolve_doc_links(attrs, MaybeExported::Impl(trait_id));
3588
3589 let item_def_id = this.r.current_owner.def_id;
3590
3591 if let Some(trait_id) = trait_id {
3593 this.r
3594 .trait_impls
3595 .entry(trait_id)
3596 .or_default()
3597 .push(item_def_id);
3598 }
3599
3600 let item_def_id = item_def_id.to_def_id();
3601 let res = Res::SelfTyAlias {
3602 alias_to: item_def_id,
3603 is_trait_impl: trait_id.is_some(),
3604 };
3605 this.with_self_rib(res, |this| {
3606 if let Some(of_trait) = of_trait {
3607 visit::walk_trait_ref(this, &of_trait.trait_ref);
3609 }
3610 this.visit_ty(self_type);
3612 this.visit_generics(generics);
3614
3615 this.with_current_self_type(self_type, |this| {
3617 this.with_self_rib_ns(ValueNS, Res::SelfCtor(item_def_id), |this| {
3618 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3618",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3618u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation with_self_rib_ns(ValueNS, ...)")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation with_self_rib_ns(ValueNS, ...)");
3619 let mut seen_trait_items = Default::default();
3620 for item in impl_items {
3621 with_owner(this, item.id, |this| {
3622 this.resolve_impl_item(
3623 &**item,
3624 &mut seen_trait_items,
3625 trait_id,
3626 of_trait.is_some(),
3627 self_type.id,
3628 );
3629 })
3630 }
3631 });
3632 });
3633 });
3634 },
3635 )
3636 },
3637 );
3638 });
3639 },
3640 );
3641 }
3642
3643 fn resolve_test_binder_constraints(
3644 &mut self,
3645 constraints: &'ast TestBinderConstraints,
3646 item_id: NodeId,
3647 ) {
3648 let generics = &constraints.generics;
3649 self.with_generic_param_rib(
3650 &generics.params,
3651 RibKind::Item(
3652 HasGenericParams::Yes(generics.span),
3653 self.r.tcx.def_kind(self.r.current_owner.def_id),
3654 ),
3655 item_id,
3656 LifetimeBinderKind::ImplBlock,
3657 generics.span,
3658 |this| {
3659 this.visit_generics(generics);
3660 this.visit_test_binder_body(&constraints.body);
3661 },
3662 );
3663 }
3664
3665 fn resolve_impl_item(
3666 &mut self,
3667 item: &'ast AssocItem,
3668 seen_trait_items: &mut FxHashMap<DefId, Span>,
3669 trait_id: Option<DefId>,
3670 is_in_trait_impl: bool,
3671 self_type_id: NodeId,
3672 ) {
3673 use crate::ResolutionError::*;
3674 self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis)));
3675 let prev = self.diag_metadata.current_impl_item.take();
3676 self.diag_metadata.current_impl_item = Some(&item);
3677 match &item.kind {
3678 AssocItemKind::Const(ast::ConstItem {
3679 ident,
3680 generics,
3681 ty,
3682 body,
3683 define_opaque,
3684 ..
3685 }) => {
3686 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3686",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3686u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation AssocItemKind::Const")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation AssocItemKind::Const");
3687 self.with_generic_param_rib(
3688 &generics.params,
3689 RibKind::AssocItem,
3690 item.id,
3691 LifetimeBinderKind::ConstItem,
3692 generics.span,
3693 |this| {
3694 this.with_lifetime_rib(
3695 LifetimeRibKind::Elided {
3696 res: LifetimeRes::Static,
3697 error_in_path: true,
3698 },
3699 |this| {
3700 this.check_trait_item(
3703 item.id,
3704 *ident,
3705 *ident,
3706 &item.kind,
3707 ValueNS,
3708 item.span,
3709 seen_trait_items,
3710 |i, s, c| ConstNotMemberOfTrait(i, s, c),
3711 );
3712
3713 this.visit_generics(generics);
3714 this.visit_ty(ty);
3715 this.resolve_const_item_rhs(body, None);
3721 },
3722 )
3723 },
3724 );
3725 self.resolve_define_opaques(define_opaque);
3726 }
3727 AssocItemKind::Fn(fn_kind @ Fn { ident, generics, define_opaque, .. }) => {
3728 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3728",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3728u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation AssocItemKind::Fn")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation AssocItemKind::Fn");
3729 self.with_generic_param_rib(
3731 &generics.params,
3732 RibKind::AssocItem,
3733 item.id,
3734 LifetimeBinderKind::Function,
3735 generics.span,
3736 |this| {
3737 let effective_ident = if is_in_trait_impl && fn_kind.is_pin_drop_sugar() {
3738 Ident::new(sym::pin_drop, ident.span)
3739 } else {
3740 *ident
3741 };
3742 this.check_trait_item(
3745 item.id,
3746 effective_ident,
3747 *ident,
3748 &item.kind,
3749 ValueNS,
3750 item.span,
3751 seen_trait_items,
3752 |i, s, c| MethodNotMemberOfTrait(i, s, c),
3753 );
3754
3755 visit::walk_assoc_item(this, item, AssocCtxt::Impl { of_trait: true })
3756 },
3757 );
3758
3759 if !is_in_trait_impl {
3760 self.fill_delegation_inherent_fn_map(self_type_id, ident);
3761 }
3762
3763 self.resolve_define_opaques(define_opaque);
3764 }
3765 AssocItemKind::Type(TyAlias { ident, generics, .. }) => {
3766 self.diag_metadata.in_non_gat_assoc_type = Some(generics.params.is_empty());
3767 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3767",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3767u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation AssocItemKind::Type")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation AssocItemKind::Type");
3768 self.with_generic_param_rib(
3770 &generics.params,
3771 RibKind::AssocItem,
3772 item.id,
3773 LifetimeBinderKind::ImplAssocType,
3774 generics.span,
3775 |this| {
3776 this.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
3777 this.check_trait_item(
3780 item.id,
3781 *ident,
3782 *ident,
3783 &item.kind,
3784 TypeNS,
3785 item.span,
3786 seen_trait_items,
3787 |i, s, c| TypeNotMemberOfTrait(i, s, c),
3788 );
3789
3790 visit::walk_assoc_item(this, item, AssocCtxt::Impl { of_trait: true })
3791 });
3792 },
3793 );
3794 self.diag_metadata.in_non_gat_assoc_type = None;
3795 }
3796 AssocItemKind::Delegation(delegation) => {
3797 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3797",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3797u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation AssocItemKind::Delegation")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation AssocItemKind::Delegation");
3798 self.with_generic_param_rib(
3799 &[],
3800 RibKind::AssocItem,
3801 item.id,
3802 LifetimeBinderKind::Function,
3803 delegation.path.segments.last().unwrap().ident.span,
3804 |this| {
3805 if !is_in_trait_impl {
3806 this.fill_delegation_inherent_fn_map(
3807 self_type_id,
3808 &delegation.ident,
3810 );
3811 }
3812
3813 this.check_trait_item(
3814 item.id,
3815 delegation.ident,
3816 delegation.ident,
3817 &item.kind,
3818 ValueNS,
3819 item.span,
3820 seen_trait_items,
3821 |i, s, c| MethodNotMemberOfTrait(i, s, c),
3822 );
3823
3824 this.resolve_delegation(delegation, item.id, is_in_trait_impl);
3827 },
3828 );
3829 }
3830 AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
3831 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
3832 }
3833 }
3834 self.diag_metadata.current_impl_item = prev;
3835 }
3836
3837 fn fill_delegation_inherent_fn_map(&mut self, self_type_id: NodeId, ident: &Ident) {
3843 let res = self.r.partial_res_map.get(&self_type_id);
3844
3845 let Some(self_type_def_id) = res.and_then(|res| {
3846 res.full_res().and_then(|r| r.opt_def_id()).and_then(|id| id.as_local())
3847 }) else {
3848 return;
3849 };
3850
3851 let map = self.r.delegation_inherent_fn_map.entry(self_type_def_id).or_default();
3853
3854 match map.get(ident) {
3855 None => {
3856 map.insert(*ident, DelegationInherentFnKind::Single(self.r.current_owner.def_id));
3857 }
3858 Some(DelegationInherentFnKind::Single(..)) => {
3859 map.insert(*ident, DelegationInherentFnKind::Ambig);
3860 }
3861 _ => {}
3862 };
3863 }
3864
3865 fn check_trait_item<F>(
3866 &mut self,
3867 id: NodeId,
3868 mut ident: Ident,
3869 mut reported_ident: Ident,
3870 kind: &AssocItemKind,
3871 ns: Namespace,
3872 span: Span,
3873 seen_trait_items: &mut FxHashMap<DefId, Span>,
3874 err: F,
3875 ) where
3876 F: FnOnce(Ident, String, Option<Symbol>) -> ResolutionError<'ra>,
3877 {
3878 let Some((module, _)) = self.current_trait_ref else {
3880 return;
3881 };
3882 ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
3883 reported_ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
3884 let key = BindingKey::new(IdentKey::new(ident), ns);
3885 let mut decl = self.r.resolution(module, key).and_then(|r| r.best_decl());
3886 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3886",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3886u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("decl")
}> =
::tracing::__macro_support::FieldName::new("decl");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?decl);
3887 if decl.is_none() {
3888 let ns = match ns {
3891 ValueNS => TypeNS,
3892 TypeNS => ValueNS,
3893 _ => ns,
3894 };
3895 let key = BindingKey::new(IdentKey::new(ident), ns);
3896 decl = self.r.resolution(module, key).and_then(|r| r.best_decl());
3897 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:3897",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3897u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("decl")
}> =
::tracing::__macro_support::FieldName::new("decl");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?decl);
3898 }
3899
3900 let feed_visibility = |this: &mut Self, def_id| {
3901 let vis = this.r.tcx.visibility(def_id);
3902 let vis = if vis.is_visible_locally() {
3903 vis.expect_local()
3904 } else {
3905 this.r.dcx().span_delayed_bug(
3906 span,
3907 "error should be emitted when an unexpected trait item is used",
3908 );
3909 Visibility::Public
3910 };
3911 this.r.tcx.feed_visibility_for_trait_impl_item(this.r.current_owner.def_id, vis);
3915 };
3916
3917 let Some(decl) = decl else {
3918 let candidate = self.find_similarly_named_assoc_item(reported_ident.name, kind);
3920 let path = &self.current_trait_ref.as_ref().unwrap().1.path;
3921 let path_names = path_names_to_string(path);
3922 self.report_error(span, err(reported_ident, path_names, candidate));
3923 feed_visibility(self, module.def_id());
3924 return;
3925 };
3926
3927 let res = decl.res();
3928 let Res::Def(def_kind, id_in_trait) = res else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
Location::caller())bug!() };
3929 feed_visibility(self, id_in_trait);
3930
3931 match seen_trait_items.entry(id_in_trait) {
3932 Entry::Occupied(entry) => {
3933 let trait_span = decl.parent_module.unwrap().span.shrink_to_lo();
3934 let impl_span = self.current_trait_ref.as_ref().unwrap().1.path.span;
3935 self.report_error(
3936 span,
3937 ResolutionError::TraitImplDuplicate {
3938 name: ident,
3939 old_span: *entry.get(),
3940 trait_item_span: decl.span,
3941 trait_span,
3942 impl_span,
3943 },
3944 );
3945 return;
3946 }
3947 Entry::Vacant(entry) => {
3948 entry.insert(span);
3949 }
3950 };
3951
3952 match (def_kind, kind) {
3953 (DefKind::AssocTy, AssocItemKind::Type(..))
3954 | (DefKind::AssocFn, AssocItemKind::Fn(..))
3955 | (DefKind::AssocConst, AssocItemKind::Const(..))
3956 | (DefKind::AssocFn, AssocItemKind::Delegation(..)) => {
3957 self.r.record_partial_res(id, PartialRes::new(res));
3958 return;
3959 }
3960 _ => {}
3961 }
3962
3963 let path = &self.current_trait_ref.as_ref().unwrap().1.path;
3965 let (code, kind) = match kind {
3966 AssocItemKind::Const(..) => (E0323, "const"),
3967 AssocItemKind::Fn(..) => (E0324, "method"),
3968 AssocItemKind::Type(..) => (E0325, "type"),
3969 AssocItemKind::Delegation(..) => (E0324, "method"),
3970 AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
3971 ::rustc_span::macros::bug_impl(Some(span), format_args!("unexpanded macro"),
Location::caller())span_bug!(span, "unexpanded macro")
3972 }
3973 };
3974 let trait_path = path_names_to_string(path);
3975 let trait_span = decl.parent_module.unwrap().span.shrink_to_lo();
3976 let impl_span = self.current_trait_ref.as_ref().unwrap().1.path.span;
3977 self.report_error(
3978 span,
3979 ResolutionError::TraitImplMismatch {
3980 name: ident,
3981 kind,
3982 code,
3983 trait_path,
3984 trait_item_span: decl.span,
3985 trait_span,
3986 impl_span,
3987 },
3988 );
3989 }
3990
3991 fn resolve_static_body(&mut self, expr: &'ast Expr, item: Option<(Ident, ConstantItemKind)>) {
3992 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
3993 this.with_constant_rib(
3994 IsRepeatExpr::No,
3995 ConstantHasGenerics::Yes,
3996 ConstantRequiresType::No,
3997 item,
3998 |this| this.visit_expr(expr),
3999 );
4000 })
4001 }
4002
4003 fn resolve_const_item_rhs(
4004 &mut self,
4005 body: &'ast Option<Box<Expr>>,
4006 item: Option<(Ident, ConstantItemKind)>,
4007 ) {
4008 if let Some(body) = body {
4009 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4010 this.with_constant_rib(
4011 IsRepeatExpr::No,
4012 ConstantHasGenerics::Yes,
4013 ConstantRequiresType::No,
4014 item,
4015 |this| this.visit_expr(body),
4016 )
4017 })
4018 }
4019 }
4020
4021 fn resolve_delegation(
4022 &mut self,
4023 delegation: &'ast Delegation,
4024 item_id: NodeId,
4025 is_in_trait_impl: bool,
4026 ) {
4027 self.smart_resolve_path(
4028 delegation.id,
4029 &delegation.qself,
4030 &delegation.path,
4031 PathSource::Delegation,
4032 );
4033
4034 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4037 if let Some(qself) = &delegation.qself {
4038 this.visit_ty(&qself.ty);
4039 }
4040
4041 this.visit_path(&delegation.path);
4042 });
4043
4044 let resolution_node_id = if is_in_trait_impl { item_id } else { delegation.id };
4045 let resolution = self
4046 .r
4047 .partial_res_map
4048 .get(&resolution_node_id)
4049 .map(|r| match r.full_res().and_then(|r| r.opt_def_id()) {
4050 None => {
4051 if !!is_in_trait_impl {
::core::panicking::panic("assertion failed: !is_in_trait_impl")
};assert!(!is_in_trait_impl);
4053 DelegationResolution::Partial
4054 }
4055 Some(def_id) => {
4056 if is_in_trait_impl {
4060 let path_res = self.r.partial_res_map[&delegation.id];
4061
4062 if path_res.full_res().and_then(|r| r.opt_def_id()).is_none() {
4063 return DelegationResolution::PartialCall(def_id);
4064 }
4065 }
4066
4067 DelegationResolution::Full(def_id)
4068 }
4069 })
4070 .unwrap_or_else(|| {
4071 DelegationResolution::Error(self.r.tcx.dcx().span_delayed_bug(
4072 delegation.path.span,
4073 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("bad resolution for delegation {0:?}",
item_id))
})format!("bad resolution for delegation {item_id:?}"),
4074 ))
4075 });
4076
4077 let info = DelegationInfo { resolution };
4078 self.r.delegation_infos.insert(self.r.current_owner.def_id, info);
4079
4080 let Some(body) = &delegation.body else { return };
4081 self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
4082 let ident = Ident::new(kw::SelfLower, body.span.normalize_to_macro_rules());
4083 let res = Res::Local(delegation.id);
4084 this.innermost_rib_bindings(ValueNS).insert(ident, res);
4085
4086 this.with_label_rib(RibKind::FnOrCoroutine, |this| {
4088 this.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4089 this.visit_block(body);
4090 });
4091 });
4092 });
4093 }
4094
4095 fn resolve_params(&mut self, params: &'ast [Param]) {
4096 let mut bindings = {
let count = 0usize + 1usize;
let mut vec = ::smallvec::SmallVec::new();
if count <= vec.inline_size() {
vec.push((PatBoundCtx::Product, Default::default()));
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(),
[(PatBoundCtx::Product, Default::default())])))
}
}smallvec![(PatBoundCtx::Product, Default::default())];
4097 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4098 for Param { pat, .. } in params {
4099 this.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
4100 }
4101 this.apply_pattern_bindings(bindings);
4102 });
4103 for Param { ty, .. } in params {
4104 self.visit_ty(ty);
4105 }
4106 }
4107
4108 fn resolve_local(&mut self, local: &'ast Local) {
4109 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:4109",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(4109u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolving local ({0:?})",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolving local ({:?})", local);
4110 if let Some(x) = &local.ty {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_ty(x)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};visit_opt!(self, visit_ty, &local.ty);
4112
4113 if let Some((init, els)) = local.kind.init_else_opt() {
4115 self.visit_expr(init);
4116
4117 if let Some(els) = els {
4119 self.visit_block(els);
4120 }
4121 }
4122
4123 self.resolve_pattern_top(&local.pat, PatternSource::Let);
4125 }
4126
4127 fn compute_and_check_binding_map(
4146 &mut self,
4147 pat: &Pat,
4148 ) -> Result<FxIndexMap<Ident, BindingInfo>, IsNeverPattern> {
4149 let mut binding_map = FxIndexMap::default();
4150 let mut is_never_pat = false;
4151
4152 pat.walk(&mut |pat| {
4153 match pat.kind {
4154 PatKind::Ident(annotation, ident, ref sub_pat)
4155 if sub_pat.is_some() || self.is_base_res_local(pat.id) =>
4156 {
4157 binding_map.insert(ident, BindingInfo { span: ident.span, annotation });
4158 }
4159 PatKind::Or(ref ps) => {
4160 match self.compute_and_check_or_pat_binding_map(ps) {
4163 Ok(bm) => binding_map.extend(bm),
4164 Err(IsNeverPattern) => is_never_pat = true,
4165 }
4166 return false;
4167 }
4168 PatKind::Never => is_never_pat = true,
4169 _ => {}
4170 }
4171
4172 true
4173 });
4174
4175 if is_never_pat {
4176 for (_, binding) in binding_map {
4177 self.report_error(binding.span, ResolutionError::BindingInNeverPattern);
4178 }
4179 Err(IsNeverPattern)
4180 } else {
4181 Ok(binding_map)
4182 }
4183 }
4184
4185 fn is_base_res_local(&self, nid: NodeId) -> bool {
4186 #[allow(non_exhaustive_omitted_patterns)] match self.r.partial_res_map.get(&nid).map(|res|
res.expect_full_res()) {
Some(Res::Local(..)) => true,
_ => false,
}matches!(
4187 self.r.partial_res_map.get(&nid).map(|res| res.expect_full_res()),
4188 Some(Res::Local(..))
4189 )
4190 }
4191
4192 fn compute_and_check_or_pat_binding_map(
4211 &mut self,
4212 pats: &[Pat],
4213 ) -> Result<FxIndexMap<Ident, BindingInfo>, IsNeverPattern> {
4214 let mut missing_vars = FxIndexMap::default();
4215 let mut inconsistent_vars = FxIndexMap::default();
4216
4217 let not_never_pats = pats
4219 .iter()
4220 .filter_map(|pat| {
4221 let binding_map = self.compute_and_check_binding_map(pat).ok()?;
4222 Some((binding_map, pat))
4223 })
4224 .collect::<Vec<_>>();
4225
4226 for &(ref map_outer, pat_outer) in not_never_pats.iter() {
4228 let inners = not_never_pats.iter().filter(|(_, pat)| pat.id != pat_outer.id);
4230
4231 for &(ref map, pat) in inners {
4232 for (&name, binding_inner) in map {
4233 match map_outer.get(&name) {
4234 None => {
4235 let binding_error =
4237 missing_vars.entry(name).or_insert_with(|| BindingError {
4238 name,
4239 origin: Default::default(),
4240 target: Default::default(),
4241 could_be_path: name.as_str().starts_with(char::is_uppercase),
4242 });
4243 binding_error.origin.push((binding_inner.span, pat.clone()));
4244 binding_error.target.push(pat_outer.clone());
4245 }
4246 Some(binding_outer) => {
4247 if binding_outer.annotation != binding_inner.annotation {
4248 inconsistent_vars
4250 .entry(name)
4251 .or_insert((binding_inner.span, binding_outer.span));
4252 }
4253 }
4254 }
4255 }
4256 }
4257 }
4258
4259 for (name, mut v) in missing_vars {
4261 if inconsistent_vars.contains_key(&name) {
4262 v.could_be_path = false;
4263 }
4264 self.report_error(
4265 v.origin.first().unwrap().0,
4266 ResolutionError::VariableNotBoundInPattern(v, self.parent_scope),
4267 );
4268 }
4269
4270 for (name, v) in inconsistent_vars {
4272 self.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(name, v.1));
4273 }
4274
4275 if not_never_pats.is_empty() {
4277 Err(IsNeverPattern)
4279 } else {
4280 let mut binding_map = FxIndexMap::default();
4281 for (bm, _) in not_never_pats {
4282 binding_map.extend(bm);
4283 }
4284 Ok(binding_map)
4285 }
4286 }
4287
4288 fn check_consistent_bindings(&mut self, pat: &'ast Pat) {
4290 let mut is_or_or_never = false;
4291 pat.walk(&mut |pat| match pat.kind {
4292 PatKind::Or(..) | PatKind::Never => {
4293 is_or_or_never = true;
4294 false
4295 }
4296 _ => true,
4297 });
4298 if is_or_or_never {
4299 let _ = self.compute_and_check_binding_map(pat);
4300 }
4301 }
4302
4303 fn resolve_arm(&mut self, arm: &'ast Arm) {
4304 self.with_rib(ValueNS, RibKind::Normal, |this| {
4305 this.resolve_pattern_top(&arm.pat, PatternSource::Match);
4306 if let Some(x) = arm.guard.as_ref().map(|g| &g.cond) {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_expr(x)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};visit_opt!(this, visit_expr, arm.guard.as_ref().map(|g| &g.cond));
4307 if let Some(x) = &arm.body {
match ::rustc_ast_ir::visit::VisitorResult::branch(this.visit_expr(x)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};visit_opt!(this, visit_expr, &arm.body);
4308 });
4309 }
4310
4311 fn resolve_pattern_top(&mut self, pat: &'ast Pat, pat_src: PatternSource) {
4313 let mut bindings = {
let count = 0usize + 1usize;
let mut vec = ::smallvec::SmallVec::new();
if count <= vec.inline_size() {
vec.push((PatBoundCtx::Product, Default::default()));
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(),
[(PatBoundCtx::Product, Default::default())])))
}
}smallvec![(PatBoundCtx::Product, Default::default())];
4314 self.resolve_pattern(pat, pat_src, &mut bindings);
4315 self.apply_pattern_bindings(bindings);
4316 }
4317
4318 fn apply_pattern_bindings(&mut self, mut pat_bindings: PatternBindings) {
4320 let rib_bindings = self.innermost_rib_bindings(ValueNS);
4321 let Some((_, pat_bindings)) = pat_bindings.pop() else {
4322 ::rustc_span::macros::bug_impl(None,
format_args!("tried applying nonexistent bindings from pattern"),
Location::caller());bug!("tried applying nonexistent bindings from pattern");
4323 };
4324
4325 if rib_bindings.is_empty() {
4326 *rib_bindings = pat_bindings;
4329 } else {
4330 rib_bindings.extend(pat_bindings);
4331 }
4332 }
4333
4334 fn resolve_pattern(
4337 &mut self,
4338 pat: &'ast Pat,
4339 pat_src: PatternSource,
4340 bindings: &mut PatternBindings,
4341 ) {
4342 self.visit_pat(pat);
4348 self.resolve_pattern_inner(pat, pat_src, bindings);
4349 self.check_consistent_bindings(pat);
4351 }
4352
4353 {}
#[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_pattern_inner",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(4372u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("pat")
}> =
::tracing::__macro_support::FieldName::new("pat");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("pat_src")
}> =
::tracing::__macro_support::FieldName::new("pat_src");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pat)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pat_src)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
pat.walk(&mut |pat|
{
match pat.kind {
PatKind::Ident(bmode, ident, ref sub) => {
let has_sub = sub.is_some();
let res =
self.try_resolve_as_non_binding(pat_src, bmode, ident,
has_sub).unwrap_or_else(||
self.fresh_binding(ident, pat.id, pat_src, bindings));
self.r.record_partial_res(pat.id, PartialRes::new(res));
self.r.record_pat_span(pat.id, pat.span);
}
PatKind::TupleStruct(ref qself, ref path, ref sub_patterns)
=> {
self.smart_resolve_path(pat.id, qself, path,
PathSource::TupleStruct(pat.span,
self.r.arenas.alloc_pattern_spans(sub_patterns.iter().map(|p|
p.span))));
}
PatKind::Path(ref qself, ref path) => {
self.smart_resolve_path(pat.id, qself, path,
PathSource::Pat);
}
PatKind::Struct(ref qself, ref path, ref _fields, ref rest)
=> {
self.smart_resolve_path(pat.id, qself, path,
PathSource::Struct(None));
self.record_patterns_with_skipped_bindings(pat, rest);
}
PatKind::Or(ref ps) => {
bindings.push((PatBoundCtx::Or, Default::default()));
for p in ps {
bindings.push((PatBoundCtx::Product, Default::default()));
self.resolve_pattern_inner(p, pat_src, bindings);
let collected = bindings.pop().unwrap().1;
bindings.last_mut().unwrap().1.extend(collected);
}
let collected = bindings.pop().unwrap().1;
bindings.last_mut().unwrap().1.extend(collected);
return false;
}
PatKind::Guard(ref subpat, ref guard) => {
bindings.push((PatBoundCtx::Product, Default::default()));
let binding_ctx_stack_len = bindings.len();
self.resolve_pattern_inner(subpat, pat_src, bindings);
{
match (&bindings.len(), &binding_ctx_stack_len) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
let subpat_bindings = bindings.pop().unwrap().1;
self.with_rib(ValueNS, RibKind::Normal,
|this|
{
*this.innermost_rib_bindings(ValueNS) =
subpat_bindings.clone();
this.resolve_expr(&guard.cond, None);
});
bindings.last_mut().unwrap().1.extend(subpat_bindings);
return false;
}
_ => {}
}
true
});
}
}
}#[tracing::instrument(skip(self, bindings), level = "debug")]
4373 fn resolve_pattern_inner(
4374 &mut self,
4375 pat: &'ast Pat,
4376 pat_src: PatternSource,
4377 bindings: &mut PatternBindings,
4378 ) {
4379 pat.walk(&mut |pat| {
4381 match pat.kind {
4382 PatKind::Ident(bmode, ident, ref sub) => {
4383 let has_sub = sub.is_some();
4386 let res = self
4387 .try_resolve_as_non_binding(pat_src, bmode, ident, has_sub)
4388 .unwrap_or_else(|| self.fresh_binding(ident, pat.id, pat_src, bindings));
4389 self.r.record_partial_res(pat.id, PartialRes::new(res));
4390 self.r.record_pat_span(pat.id, pat.span);
4391 }
4392 PatKind::TupleStruct(ref qself, ref path, ref sub_patterns) => {
4393 self.smart_resolve_path(
4394 pat.id,
4395 qself,
4396 path,
4397 PathSource::TupleStruct(
4398 pat.span,
4399 self.r.arenas.alloc_pattern_spans(sub_patterns.iter().map(|p| p.span)),
4400 ),
4401 );
4402 }
4403 PatKind::Path(ref qself, ref path) => {
4404 self.smart_resolve_path(pat.id, qself, path, PathSource::Pat);
4405 }
4406 PatKind::Struct(ref qself, ref path, ref _fields, ref rest) => {
4407 self.smart_resolve_path(pat.id, qself, path, PathSource::Struct(None));
4408 self.record_patterns_with_skipped_bindings(pat, rest);
4409 }
4410 PatKind::Or(ref ps) => {
4411 bindings.push((PatBoundCtx::Or, Default::default()));
4415 for p in ps {
4416 bindings.push((PatBoundCtx::Product, Default::default()));
4420 self.resolve_pattern_inner(p, pat_src, bindings);
4421 let collected = bindings.pop().unwrap().1;
4424 bindings.last_mut().unwrap().1.extend(collected);
4425 }
4426 let collected = bindings.pop().unwrap().1;
4430 bindings.last_mut().unwrap().1.extend(collected);
4431
4432 return false;
4434 }
4435 PatKind::Guard(ref subpat, ref guard) => {
4436 bindings.push((PatBoundCtx::Product, Default::default()));
4438 let binding_ctx_stack_len = bindings.len();
4441 self.resolve_pattern_inner(subpat, pat_src, bindings);
4442 assert_eq!(bindings.len(), binding_ctx_stack_len);
4443 let subpat_bindings = bindings.pop().unwrap().1;
4446 self.with_rib(ValueNS, RibKind::Normal, |this| {
4447 *this.innermost_rib_bindings(ValueNS) = subpat_bindings.clone();
4448 this.resolve_expr(&guard.cond, None);
4449 });
4450 bindings.last_mut().unwrap().1.extend(subpat_bindings);
4457 return false;
4459 }
4460 _ => {}
4461 }
4462 true
4463 });
4464 }
4465
4466 fn record_patterns_with_skipped_bindings(&mut self, pat: &Pat, rest: &ast::PatFieldsRest) {
4467 match rest {
4468 ast::PatFieldsRest::Rest(_) | ast::PatFieldsRest::Recovered(_) => {
4469 if let Some(partial_res) = self.r.partial_res_map.get(&pat.id)
4471 && let Some(res) = partial_res.full_res()
4472 && let Some(def_id) = res.opt_def_id()
4473 {
4474 self.ribs[ValueNS]
4475 .last_mut()
4476 .unwrap()
4477 .patterns_with_skipped_bindings
4478 .entry(def_id)
4479 .or_default()
4480 .push((
4481 pat.span,
4482 match rest {
4483 ast::PatFieldsRest::Rest(span) => Some(*span),
4484 _ => None,
4485 },
4486 match rest {
4487 ast::PatFieldsRest::Recovered(guar) => Err(*guar),
4488 _ => Ok(()),
4489 },
4490 ));
4491 }
4492 }
4493 ast::PatFieldsRest::None => {}
4494 }
4495 }
4496
4497 fn fresh_binding(
4498 &mut self,
4499 ident: Ident,
4500 pat_id: NodeId,
4501 pat_src: PatternSource,
4502 bindings: &mut PatternBindings,
4503 ) -> Res {
4504 let ident = ident.normalize_to_macro_rules();
4508
4509 let already_bound_and = bindings
4511 .iter()
4512 .any(|(ctx, map)| *ctx == PatBoundCtx::Product && map.contains_key(&ident));
4513 if already_bound_and {
4514 use ResolutionError::*;
4516 let error = match pat_src {
4517 PatternSource::FnParam => IdentifierBoundMoreThanOnceInParameterList,
4519 _ => IdentifierBoundMoreThanOnceInSamePattern,
4521 };
4522 self.report_error(ident.span, error(ident));
4523 }
4524
4525 let already_bound_or = bindings
4528 .iter()
4529 .find_map(|(ctx, map)| if *ctx == PatBoundCtx::Or { map.get(&ident) } else { None });
4530 let res = if let Some(&res) = already_bound_or {
4531 res
4534 } else {
4535 Res::Local(pat_id)
4537 };
4538
4539 bindings.last_mut().unwrap().1.insert(ident, res);
4541 res
4542 }
4543
4544 fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap<Ident, Res> {
4545 &mut self.ribs[ns].last_mut().unwrap().bindings
4546 }
4547
4548 fn try_resolve_as_non_binding(
4549 &mut self,
4550 pat_src: PatternSource,
4551 ann: BindingMode,
4552 ident: Ident,
4553 has_sub: bool,
4554 ) -> Option<Res> {
4555 let is_syntactic_ambiguity = !has_sub && ann == BindingMode::NONE;
4559
4560 let ls_binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS)?;
4561 let (res, binding) = match ls_binding {
4562 LateDecl::Decl(binding)
4563 if is_syntactic_ambiguity && binding.is_ambiguity_recursive() =>
4564 {
4565 self.r.record_use(ident, binding, Used::Other);
4570 return None;
4571 }
4572 LateDecl::Decl(binding) => (binding.res(), Some(binding)),
4573 LateDecl::RibDef(res) => (res, None),
4574 };
4575
4576 match res {
4577 Res::SelfCtor(_) | Res::Def(
4579 DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst | DefKind::ConstParam,
4580 _,
4581 ) if is_syntactic_ambiguity => {
4582 if let Some(binding) = binding {
4584 self.r.record_use(ident, binding, Used::Other);
4585 }
4586 Some(res)
4587 }
4588 Res::Def(
4589 DefKind::Ctor(..)
4590 | DefKind::Const
4591 | DefKind::AssocConst
4592 | DefKind::Static { .. },
4593 _,
4594 ) => {
4595 let binding = binding.expect("no binding for a ctor or static");
4601 self.report_error(
4602 ident.span,
4603 ResolutionError::BindingShadowsSomethingUnacceptable {
4604 shadowing_binding: pat_src,
4605 name: ident.name,
4606 participle: if binding.is_import() { "imported" } else { "defined" },
4607 article: binding.res().article(),
4608 shadowed_binding: binding.res(),
4609 shadowed_binding_span: binding.span,
4610 },
4611 );
4612 None
4613 }
4614 Res::Def(DefKind::ConstParam, def_id) => {
4615 self.report_error(
4618 ident.span,
4619 ResolutionError::BindingShadowsSomethingUnacceptable {
4620 shadowing_binding: pat_src,
4621 name: ident.name,
4622 participle: "defined",
4623 article: res.article(),
4624 shadowed_binding: res,
4625 shadowed_binding_span: self.r.def_span(def_id),
4626 },
4627 );
4628 None
4629 }
4630 Res::Def(DefKind::Fn | DefKind::AssocFn, _) | Res::Local(..) | Res::Err => {
4631 None
4633 }
4634 Res::SelfCtor(_) => {
4635 self.r.dcx().span_delayed_bug(
4638 ident.span,
4639 "unexpected `SelfCtor` in pattern, expected identifier",
4640 );
4641 None
4642 }
4643 _ => ::rustc_span::macros::bug_impl(Some(ident.span),
format_args!("unexpected resolution for an identifier in pattern: {0:?}",
res), Location::caller())span_bug!(
4644 ident.span,
4645 "unexpected resolution for an identifier in pattern: {:?}",
4646 res,
4647 ),
4648 }
4649 }
4650
4651 fn resolve_restriction_path(&mut self, restriction: &'ast ast::RestrictionKind) {
4652 match &restriction {
4653 ast::RestrictionKind::Unrestricted => (),
4654 ast::RestrictionKind::Restricted { path, id, shorthand: _ } => {
4655 self.smart_resolve_path(*id, &None, path, PathSource::Module);
4656 }
4657 }
4658 }
4659
4660 fn smart_resolve_path(
4666 &mut self,
4667 id: NodeId,
4668 qself: &Option<Box<QSelf>>,
4669 path: &Path,
4670 source: PathSource<'_, 'ast, 'ra>,
4671 ) {
4672 self.smart_resolve_path_fragment(
4673 qself,
4674 &Segment::from_path(path),
4675 source,
4676 Finalize::new(id, path.span),
4677 RecordPartialRes::Yes,
4678 None,
4679 );
4680 }
4681
4682 fn smart_resolve_path_fragment(
4683 &mut self,
4684 qself: &Option<Box<QSelf>>,
4685 path: &[Segment],
4686 source: PathSource<'_, 'ast, 'ra>,
4687 finalize: Finalize,
4688 record_partial_res: RecordPartialRes,
4689 parent_qself: Option<&QSelf>,
4690 ) -> PartialRes {
4691 let ns = source.namespace();
4692
4693 let Finalize { node_id, path_span, .. } = finalize;
4694 let report_errors = |this: &mut Self, res: Option<Res>| {
4695 if this.should_report_errs() {
4696 let (mut err, candidates) = this.smart_resolve_report_errors(
4697 path,
4698 None,
4699 path_span,
4700 source,
4701 res,
4702 parent_qself,
4703 );
4704
4705 let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
4706 let instead = res.is_some();
4707 let (suggestion, const_err) = if let Some((start, end)) =
4708 this.diag_metadata.in_range
4709 && path[0].ident.span.lo() == end.span.lo()
4710 && !#[allow(non_exhaustive_omitted_patterns)] match start.kind {
ExprKind::Lit(_) => true,
_ => false,
}matches!(start.kind, ExprKind::Lit(_))
4711 {
4712 let mut sugg = ".";
4713 let mut span = start.span.between(end.span);
4714 if span.lo() + BytePos(2) == span.hi() {
4715 span = span.with_lo(span.lo() + BytePos(1));
4718 sugg = "";
4719 }
4720 (
4721 Some((
4722 span,
4723 "you might have meant to write `.` instead of `..`",
4724 sugg.to_string(),
4725 Applicability::MaybeIncorrect,
4726 )),
4727 None,
4728 )
4729 } else if res.is_none()
4730 && let PathSource::Type
4731 | PathSource::Expr(_)
4732 | PathSource::PreciseCapturingArg(..) = source
4733 {
4734 this.suggest_adding_generic_parameter(path, source)
4735 } else {
4736 (None, None)
4737 };
4738
4739 if let Some(const_err) = const_err {
4740 err.cancel();
4741 err = const_err;
4742 }
4743
4744 let ue = UseError {
4745 err,
4746 candidates,
4747 node_id,
4748 instead,
4749 suggestion,
4750 path: path.into(),
4751 is_call: source.is_call(),
4752 };
4753
4754 this.use_injections.push(ue);
4755 }
4756
4757 PartialRes::new(Res::Err)
4758 };
4759
4760 let report_errors_for_call =
4766 |this: &mut Self, parent_err: Spanned<ResolutionError<'ra>>| {
4767 let (following_seg, prefix_path) = match path.split_last() {
4771 Some((last, path)) if !path.is_empty() => (Some(last), path),
4772 _ => return Some(parent_err),
4773 };
4774
4775 let (mut err, candidates) = this.smart_resolve_report_errors(
4776 prefix_path,
4777 following_seg,
4778 path_span,
4779 PathSource::Type,
4780 None,
4781 parent_qself,
4782 );
4783
4784 let failed_to_resolve = match parent_err.node {
4799 ResolutionError::FailedToResolve { .. } => true,
4800 _ => false,
4801 };
4802 let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
4803
4804 err.messages = take(&mut parent_err.messages);
4806 err.code = take(&mut parent_err.code);
4807 swap(&mut err.span, &mut parent_err.span);
4808 if failed_to_resolve {
4809 err.children = take(&mut parent_err.children);
4810 } else {
4811 err.children.append(&mut parent_err.children);
4812 }
4813 err.is_lint = parent_err.is_lint.clone();
4814
4815 match &mut err.suggestions {
4817 Suggestions::Enabled(typo_suggestions) => match &mut parent_err.suggestions {
4818 Suggestions::Enabled(parent_suggestions) => {
4819 typo_suggestions.append(parent_suggestions)
4821 }
4822 Suggestions::Sealed(_) | Suggestions::Disabled => {
4823 err.suggestions = std::mem::take(&mut parent_err.suggestions);
4828 }
4829 },
4830 Suggestions::Sealed(_) | Suggestions::Disabled => (),
4831 }
4832
4833 parent_err.cancel();
4834
4835 let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
4836
4837 if this.should_report_errs() {
4838 if candidates.is_empty() {
4839 if path.len() == 2
4840 && let [segment] = prefix_path
4841 {
4842 err.stash(segment.ident.span, rustc_errors::StashKey::CallAssocMethod);
4848 } else {
4849 err.emit();
4854 }
4855 } else {
4856 this.use_injections.push(UseError {
4858 err,
4859 candidates,
4860 node_id,
4861 instead: false,
4862 suggestion: None,
4863 path: prefix_path.into(),
4864 is_call: source.is_call(),
4865 });
4866 }
4867 } else {
4868 err.cancel();
4869 }
4870
4871 None
4874 };
4875
4876 let partial_res = match self.resolve_qpath_anywhere(
4877 qself,
4878 path,
4879 ns,
4880 source.defer_to_typeck(),
4881 finalize,
4882 source,
4883 ) {
4884 Ok(Some(partial_res)) if let Some(res) = partial_res.full_res() => {
4885 if let Some(items) = self.diag_metadata.current_trait_assoc_items
4887 && let [Segment { ident, .. }] = path
4888 && items.iter().any(|item| {
4889 if let AssocItemKind::Type(alias) = &item.kind
4890 && alias.ident == *ident
4891 {
4892 true
4893 } else {
4894 false
4895 }
4896 })
4897 {
4898 self.r.paths_matching_assoc_types.insert(path_span.with_parent(None));
4899 }
4900
4901 if source.is_expected(res) || res == Res::Err {
4902 partial_res
4903 } else {
4904 report_errors(self, Some(res))
4905 }
4906 }
4907
4908 Ok(Some(partial_res)) if source.defer_to_typeck() => {
4909 if ns == ValueNS {
4913 let item_name = path.last().unwrap().ident;
4914 self.record_traits_in_scope(node_id, item_name);
4915 }
4916
4917 if PrimTy::from_name(path[0].ident.name).is_some() {
4918 let mut std_path = Vec::with_capacity(1 + path.len());
4919
4920 std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
4921 std_path.extend(path);
4922 if let PathResult::Module(_) | PathResult::NonModule(_) =
4923 self.resolve_path(&std_path, Some(ns), None, source)
4924 {
4925 let item_span = path.last().map_or(path_span, |segment| segment.ident.span);
4927
4928 self.r.confused_type_with_std_module.insert(item_span, path_span);
4929 self.r.confused_type_with_std_module.insert(path_span, path_span);
4930 }
4931 }
4932
4933 partial_res
4934 }
4935
4936 Err(err) => {
4937 if let Some(err) = report_errors_for_call(self, err) {
4938 self.report_error(err.span, err.node);
4939 }
4940
4941 PartialRes::new(Res::Err)
4942 }
4943
4944 _ => report_errors(self, None),
4945 };
4946
4947 if record_partial_res == RecordPartialRes::Yes {
4948 self.r.record_partial_res(node_id, partial_res);
4950 self.resolve_elided_lifetimes_in_path(partial_res, path, source, path_span);
4951 self.lint_unused_qualifications(path, ns, finalize);
4952 }
4953
4954 partial_res
4955 }
4956
4957 fn self_type_is_available(&mut self) -> bool {
4958 let binding = self
4959 .maybe_resolve_ident_in_lexical_scope(Ident::with_dummy_span(kw::SelfUpper), TypeNS);
4960 if let Some(LateDecl::RibDef(res)) = binding { res != Res::Err } else { false }
4961 }
4962
4963 fn self_value_is_available(&mut self, self_span: Span) -> bool {
4964 let ident = Ident::new(kw::SelfLower, self_span);
4965 let binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS);
4966 if let Some(LateDecl::RibDef(res)) = binding { res != Res::Err } else { false }
4967 }
4968
4969 fn report_error(&mut self, span: Span, resolution_error: ResolutionError<'ra>) {
4973 if self.should_report_errs() {
4974 self.r.report_error(span, resolution_error);
4975 }
4976 }
4977
4978 #[inline]
4979 fn should_report_errs(&self) -> bool {
4983 !(self.r.tcx.sess.opts.actually_rustdoc && self.in_func_body)
4984 && !self.r.glob_error.is_some()
4985 }
4986
4987 fn resolve_qpath_anywhere(
4989 &mut self,
4990 qself: &Option<Box<QSelf>>,
4991 path: &[Segment],
4992 primary_ns: Namespace,
4993 defer_to_typeck: bool,
4994 finalize: Finalize,
4995 source: PathSource<'_, 'ast, 'ra>,
4996 ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
4997 let mut fin_res = None;
4998
4999 for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {
5000 if i == 0 || ns != primary_ns {
5001 match self.resolve_qpath(qself, path, ns, finalize, source)? {
5002 Some(partial_res)
5003 if partial_res.unresolved_segments() == 0 || defer_to_typeck =>
5004 {
5005 return Ok(Some(partial_res));
5006 }
5007 partial_res => {
5008 if fin_res.is_none() {
5009 fin_res = partial_res;
5010 }
5011 }
5012 }
5013 }
5014 }
5015
5016 if !(primary_ns != MacroNS) {
::core::panicking::panic("assertion failed: primary_ns != MacroNS")
};assert!(primary_ns != MacroNS);
5017 if qself.is_none()
5018 && let PathResult::NonModule(res) =
5019 self.r.cm().maybe_resolve_path(path, Some(MacroNS), &self.parent_scope, None)
5020 {
5021 return Ok(Some(res));
5022 }
5023
5024 Ok(fin_res)
5025 }
5026
5027 fn resolve_qpath(
5029 &mut self,
5030 qself: &Option<Box<QSelf>>,
5031 path: &[Segment],
5032 ns: Namespace,
5033 finalize: Finalize,
5034 source: PathSource<'_, 'ast, 'ra>,
5035 ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
5036 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:5036",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5036u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_qpath(qself={0:?}, path={1:?}, ns={2:?}, finalize={3:?})",
qself, path, ns, finalize) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
5037 "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})",
5038 qself, path, ns, finalize,
5039 );
5040
5041 if let Some(qself) = qself {
5042 if qself.position == 0 {
5043 return Ok(Some(PartialRes::with_unresolved_segments(
5047 Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id()),
5048 path.len(),
5049 )));
5050 }
5051
5052 let num_privacy_errors = self.r.privacy_errors.len();
5053 let trait_res = self.smart_resolve_path_fragment(
5055 &None,
5056 &path[..qself.position],
5057 PathSource::Trait(AliasPossibility::No),
5058 Finalize::new(finalize.node_id, qself.path_span),
5059 RecordPartialRes::No,
5060 Some(&qself),
5061 );
5062
5063 if trait_res.expect_full_res() == Res::Err {
5064 return Ok(Some(trait_res));
5065 }
5066
5067 self.r.privacy_errors.truncate(num_privacy_errors);
5070
5071 let ns = if qself.position + 1 == path.len() { ns } else { TypeNS };
5079 let partial_res = self.smart_resolve_path_fragment(
5080 &None,
5081 &path[..=qself.position],
5082 PathSource::TraitItem(ns, &source),
5083 Finalize::with_root_span(finalize.node_id, finalize.path_span, qself.path_span),
5084 RecordPartialRes::No,
5085 Some(&qself),
5086 );
5087
5088 return Ok(Some(PartialRes::with_unresolved_segments(
5092 partial_res.base_res(),
5093 partial_res.unresolved_segments() + path.len() - qself.position - 1,
5094 )));
5095 }
5096
5097 let result = match self.resolve_path(path, Some(ns), Some(finalize), source) {
5098 PathResult::NonModule(path_res) => path_res,
5099 PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
5100 PartialRes::new(module.res().unwrap())
5101 }
5102 PathResult::Failed { error_implied_by_parse_error: true, .. } => {
5106 PartialRes::new(Res::Err)
5107 }
5108 PathResult::Module(ModuleOrUniformRoot::Module(_)) | PathResult::Failed { .. }
5121 if (ns == TypeNS || path.len() > 1)
5122 && PrimTy::from_name(path[0].ident.name).is_some() =>
5123 {
5124 let prim = PrimTy::from_name(path[0].ident.name).unwrap();
5125 let tcx = self.r.tcx();
5126
5127 let gate_err_sym_msg = match prim {
5128 PrimTy::Float(FloatTy::F16) if !self.r.features.f16() => {
5129 Some((sym::f16, "the type `f16` is unstable"))
5130 }
5131 PrimTy::Float(FloatTy::F128) if !self.r.features.f128() => {
5132 Some((sym::f128, "the type `f128` is unstable"))
5133 }
5134 _ => None,
5135 };
5136
5137 if let Some((sym, msg)) = gate_err_sym_msg {
5138 let span = path[0].ident.span;
5139 if !span.allows_unstable(sym) {
5140 feature_err(tcx.sess, sym, span, msg).emit();
5141 }
5142 };
5143
5144 if let Some(id) = path[0].id {
5146 self.r.partial_res_map.insert(id, PartialRes::new(Res::PrimTy(prim)));
5147 }
5148
5149 PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
5150 }
5151 PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
5152 PartialRes::new(module.res().unwrap())
5153 }
5154 PathResult::Failed {
5155 is_error_from_last_segment: false,
5156 span,
5157 label,
5158 suggestion,
5159 help,
5160 module,
5161 segment,
5162 error_implied_by_parse_error: _,
5163 message,
5164 note: _,
5165 } => {
5166 return Err(respan(
5167 span,
5168 ResolutionError::FailedToResolve {
5169 segment: segment.name,
5170 label,
5171 suggestion,
5172 help,
5173 module,
5174 message,
5175 },
5176 ));
5177 }
5178 PathResult::Module(..) | PathResult::Failed { .. } => return Ok(None),
5179 PathResult::Indeterminate => ::rustc_span::macros::bug_impl(None,
format_args!("indeterminate path result in resolve_qpath"),
Location::caller())bug!("indeterminate path result in resolve_qpath"),
5180 };
5181
5182 Ok(Some(result))
5183 }
5184
5185 fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) {
5186 if let Some(label) = label {
5187 if label.ident.as_str().as_bytes()[1] != b'_' {
5188 self.diag_metadata.unused_labels.insert(id, label.ident.span);
5189 }
5190
5191 if let Ok((_, orig_span)) = self.resolve_label(label.ident) {
5192 diagnostics::signal_label_shadowing(self.r.tcx.sess, orig_span, label.ident)
5193 }
5194
5195 self.with_label_rib(RibKind::Normal, |this| {
5196 let ident = label.ident.normalize_to_macro_rules();
5197 this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
5198 f(this);
5199 });
5200 } else {
5201 f(self);
5202 }
5203 }
5204
5205 fn resolve_labeled_block(&mut self, label: Option<Label>, id: NodeId, block: &'ast Block) {
5206 self.with_resolved_label(label, id, |this| this.visit_block(block));
5207 }
5208
5209 fn resolve_block(&mut self, block: &'ast Block) {
5210 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:5210",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5210u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving block) entering block")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving block) entering block");
5211 let orig_module = self.parent_scope.module;
5213 let anonymous_module = self.r.block_map.get(&block.id).copied();
5214
5215 let mut num_macro_definition_ribs = 0;
5216 if let Some(anonymous_module) = anonymous_module {
5217 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:5217",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5217u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving block) found anonymous module, moving down")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving block) found anonymous module, moving down");
5218 self.ribs[ValueNS].push(Rib::new(RibKind::Block(Some(anonymous_module))));
5219 self.ribs[TypeNS].push(Rib::new(RibKind::Block(Some(anonymous_module))));
5220 self.parent_scope.module = anonymous_module.to_module();
5221 } else {
5222 self.ribs[ValueNS].push(Rib::new(RibKind::Block(None)));
5223 }
5224
5225 for stmt in &block.stmts {
5227 if let StmtKind::Item(ref item) = stmt.kind
5228 && let ItemKind::MacroDef(..) = item.kind
5229 {
5230 num_macro_definition_ribs += 1;
5231 let res = self.r.owner_def_id(item.id).to_def_id();
5232 self.ribs[ValueNS].push(Rib::new(RibKind::MacroDefinition(res)));
5233 self.label_ribs.push(Rib::new(RibKind::MacroDefinition(res)));
5234 }
5235
5236 self.visit_stmt(stmt);
5237 }
5238
5239 self.parent_scope.module = orig_module;
5241 for _ in 0..num_macro_definition_ribs {
5242 self.ribs[ValueNS].pop();
5243 self.label_ribs.pop();
5244 }
5245 self.last_block_rib = self.ribs[ValueNS].pop();
5246 if anonymous_module.is_some() {
5247 self.ribs[TypeNS].pop();
5248 }
5249 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:5249",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5249u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(resolving block) leaving block")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(resolving block) leaving block");
5250 }
5251
5252 fn resolve_anon_const(&mut self, constant: &'ast AnonConst, anon_const_kind: AnonConstKind) {
5253 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:5253",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5253u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_anon_const(constant: {0:?}, anon_const_kind: {1:?})",
constant, anon_const_kind) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
5254 "resolve_anon_const(constant: {:?}, anon_const_kind: {:?})",
5255 constant, anon_const_kind
5256 );
5257
5258 let is_trivial_const_arg = constant.value.is_potential_trivial_const_arg();
5259 self.resolve_anon_const_manual(is_trivial_const_arg, anon_const_kind, |this| {
5260 this.resolve_expr(&constant.value, None)
5261 })
5262 }
5263
5264 fn resolve_anon_const_manual(
5271 &mut self,
5272 is_trivial_const_arg: bool,
5273 anon_const_kind: AnonConstKind,
5274 resolve_expr: impl FnOnce(&mut Self),
5275 ) {
5276 let is_repeat_expr = match anon_const_kind {
5277 AnonConstKind::ConstArg(is_repeat_expr) => is_repeat_expr,
5278 _ => IsRepeatExpr::No,
5279 };
5280
5281 let may_use_generics = match anon_const_kind {
5282 AnonConstKind::EnumDiscriminant => {
5283 ConstantHasGenerics::No(NoConstantGenericsReason::IsEnumDiscriminant)
5284 }
5285 AnonConstKind::FieldDefaultValue => ConstantHasGenerics::Yes,
5286 AnonConstKind::InlineConst => ConstantHasGenerics::Yes,
5287 AnonConstKind::ConstArg(_) | AnonConstKind::ArrayLength => {
5288 if self.r.features.generic_const_exprs()
5289 || self.r.features.gca()
5290 || is_trivial_const_arg
5291 {
5292 ConstantHasGenerics::Yes
5293 } else {
5294 ConstantHasGenerics::No(NoConstantGenericsReason::NonTrivialConstArg)
5295 }
5296 }
5297 };
5298
5299 let requires_type = match anon_const_kind {
5300 AnonConstKind::ArrayLength | AnonConstKind::ConstArg(IsRepeatExpr::Yes) => {
5301 ConstantRequiresType::Usize
5302 }
5303 _ => ConstantRequiresType::No,
5304 };
5305
5306 self.with_constant_rib(is_repeat_expr, may_use_generics, requires_type, None, |this| {
5307 this.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
5308 resolve_expr(this);
5309 });
5310 });
5311 }
5312
5313 fn resolve_expr_field(&mut self, f: &'ast ExprField, e: &'ast Expr) {
5314 self.resolve_expr(&f.expr, Some(e));
5315 self.visit_ident(&f.ident);
5316 for elem in f.attrs.iter() {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_attribute(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_attribute, f.attrs.iter());
5317 }
5318
5319 fn resolve_expr(&mut self, expr: &'ast Expr, parent: Option<&'ast Expr>) {
5320 self.record_candidate_traits_for_expr_if_necessary(expr);
5324
5325 match expr.kind {
5327 ExprKind::Path(ref qself, ref path) => {
5328 self.smart_resolve_path(expr.id, qself, path, PathSource::Expr(parent));
5329 visit::walk_expr(self, expr);
5330 }
5331
5332 ExprKind::Struct(ref se) => {
5333 self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct(parent));
5334 if let Some(qself) = &se.qself {
5338 self.visit_ty(&qself.ty);
5339 }
5340 self.visit_path(&se.path);
5341 for elem in &se.fields {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.resolve_expr_field(elem,
expr)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(self, resolve_expr_field, &se.fields, expr);
5342 match &se.rest {
5343 StructRest::Base(expr) => self.visit_expr(expr),
5344 StructRest::Rest(_span) => {}
5345 StructRest::None | StructRest::NoneWithError(_) => {}
5346 }
5347 }
5348
5349 ExprKind::Break(Some(label), _) | ExprKind::Continue(Some(label)) => {
5350 match self.resolve_label(label.ident) {
5351 Ok((node_id, _)) => {
5352 self.r.current_owner.label_res_map.insert(expr.id, node_id);
5354 self.diag_metadata.unused_labels.swap_remove(&node_id);
5355 }
5356 Err(error) => {
5357 self.report_error(label.ident.span, error);
5358 }
5359 }
5360
5361 visit::walk_expr(self, expr);
5363 }
5364
5365 ExprKind::Break(None, Some(ref e)) => {
5366 self.resolve_expr(e, Some(expr));
5369 }
5370
5371 ExprKind::Let(ref pat, ref scrutinee, _, Recovered::No) => {
5372 self.visit_expr(scrutinee);
5373 self.resolve_pattern_top(pat, PatternSource::Let);
5374 }
5375
5376 ExprKind::Let(ref pat, ref scrutinee, _, Recovered::Yes(_)) => {
5377 self.visit_expr(scrutinee);
5378 let mut bindings = {
let count = 0usize + 1usize;
let mut vec = ::smallvec::SmallVec::new();
if count <= vec.inline_size() {
vec.push((PatBoundCtx::Product, Default::default()));
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(),
[(PatBoundCtx::Product, Default::default())])))
}
}smallvec![(PatBoundCtx::Product, Default::default())];
5380 self.resolve_pattern(pat, PatternSource::Let, &mut bindings);
5381 for (_, bindings) in &mut bindings {
5386 for (_, binding) in bindings {
5387 *binding = Res::Err;
5388 }
5389 }
5390 self.apply_pattern_bindings(bindings);
5391 }
5392
5393 ExprKind::If(ref cond, ref then, ref opt_else) => {
5394 self.with_rib(ValueNS, RibKind::Normal, |this| {
5395 let old = this.diag_metadata.in_if_condition.replace(cond);
5396 this.visit_expr(cond);
5397 this.diag_metadata.in_if_condition = old;
5398 this.visit_block(then);
5399 });
5400 if let Some(expr) = opt_else {
5401 self.visit_expr(expr);
5402 }
5403 }
5404
5405 ExprKind::Loop(ref block, label, _) => {
5406 self.resolve_labeled_block(label, expr.id, block)
5407 }
5408
5409 ExprKind::While(ref cond, ref block, label) => {
5410 self.with_resolved_label(label, expr.id, |this| {
5411 this.with_rib(ValueNS, RibKind::Normal, |this| {
5412 let old = this.diag_metadata.in_if_condition.replace(cond);
5413 this.visit_expr(cond);
5414 this.diag_metadata.in_if_condition = old;
5415 this.visit_block(block);
5416 })
5417 });
5418 }
5419
5420 ExprKind::ForLoop(ForLoop { ref pat, ref iter, ref body, label, kind: _ }) => {
5421 self.visit_expr(iter);
5422 self.with_rib(ValueNS, RibKind::Normal, |this| {
5423 this.resolve_pattern_top(pat, PatternSource::For);
5424 this.resolve_labeled_block(label, expr.id, body);
5425 });
5426 }
5427
5428 ExprKind::Block(ref block, label) => self.resolve_labeled_block(label, block.id, block),
5429
5430 ExprKind::Field(ref subexpression, _) => {
5432 self.resolve_expr(subexpression, Some(expr));
5433 }
5434 ExprKind::MethodCall(MethodCall { ref seg, ref receiver, ref args, .. }) => {
5435 self.resolve_expr(receiver, Some(expr));
5436 for arg in args {
5437 self.resolve_expr(arg, None);
5438 }
5439 self.visit_path_segment(seg);
5440 }
5441
5442 ExprKind::Call(ref callee, ref arguments) => {
5443 self.resolve_expr(callee, Some(expr));
5444 let const_args = self.r.legacy_const_generic_args(callee).unwrap_or_default();
5445 for (idx, argument) in arguments.iter().enumerate() {
5446 if const_args.contains(&idx) {
5449 let is_trivial_const_arg = argument.is_potential_trivial_const_arg();
5452 self.resolve_anon_const_manual(
5453 is_trivial_const_arg,
5454 AnonConstKind::ConstArg(IsRepeatExpr::No),
5455 |this| this.resolve_expr(argument, None),
5456 );
5457 } else {
5458 self.resolve_expr(argument, None);
5459 }
5460 }
5461 }
5462 ExprKind::FormatArgs(ref args) => {
5463 for arg in args.arguments.all_args() {
5464 let parent =
5466 #[allow(non_exhaustive_omitted_patterns)] match arg.kind {
FormatArgumentKind::Captured(_) => true,
_ => false,
}matches!(arg.kind, FormatArgumentKind::Captured(_)).then_some(expr);
5467 self.resolve_expr(&arg.expr, parent);
5468 }
5469 }
5470 ExprKind::Type(ref _type_expr, ref _ty) => {
5471 visit::walk_expr(self, expr);
5472 }
5473 ExprKind::Closure(ast::Closure {
5475 binder: ClosureBinder::For { ref generic_params, span },
5476 ..
5477 }) => {
5478 self.with_generic_param_rib(
5479 generic_params,
5480 RibKind::Normal,
5481 expr.id,
5482 LifetimeBinderKind::Closure,
5483 span,
5484 |this| visit::walk_expr(this, expr),
5485 );
5486 }
5487 ExprKind::Closure(..) => visit::walk_expr(self, expr),
5488 ExprKind::Gen(..) => {
5489 self.with_label_rib(RibKind::FnOrCoroutine, |this| visit::walk_expr(this, expr));
5490 }
5491 ExprKind::Repeat(ref elem, ref ct) => {
5492 self.visit_expr(elem);
5493 self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::Yes));
5494 }
5495 ExprKind::ConstBlock(ref ct) => {
5496 self.resolve_anon_const(ct, AnonConstKind::InlineConst);
5497 }
5498 ExprKind::Index(ref elem, ref idx, _) => {
5499 self.resolve_expr(elem, Some(expr));
5500 self.visit_expr(idx);
5501 }
5502 ExprKind::Assign(ref lhs, ref rhs, _) => {
5503 if !self.diag_metadata.is_assign_rhs {
5504 self.diag_metadata.in_assignment = Some(expr);
5505 }
5506 self.visit_expr(lhs);
5507 self.diag_metadata.is_assign_rhs = true;
5508 self.diag_metadata.in_assignment = None;
5509 self.visit_expr(rhs);
5510 self.diag_metadata.is_assign_rhs = false;
5511 }
5512 ExprKind::Range(Some(ref start), Some(ref end), RangeLimits::HalfOpen) => {
5513 self.diag_metadata.in_range = Some((start, end));
5514 self.resolve_expr(start, Some(expr));
5515 self.resolve_expr(end, Some(expr));
5516 self.diag_metadata.in_range = None;
5517 }
5518 _ => {
5519 visit::walk_expr(self, expr);
5520 }
5521 }
5522 }
5523
5524 fn record_candidate_traits_for_expr_if_necessary(&mut self, expr: &'ast Expr) {
5525 match expr.kind {
5526 ExprKind::Field(_, ident) => {
5527 self.record_traits_in_scope(expr.id, ident);
5532 }
5533 ExprKind::MethodCall(ref call) => {
5534 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs:5534",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6f5da406b56c2db6607202b63daee73aa8c61297/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5534u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(recording candidate traits for expr) recording traits for {0}",
expr.id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(recording candidate traits for expr) recording traits for {}", expr.id);
5535 self.record_traits_in_scope(expr.id, call.seg.ident);
5536 }
5537 _ => {
5538 }
5540 }
5541 }
5542
5543 fn record_traits_in_scope(&mut self, node_id: NodeId, ident: Ident) {
5544 let traits = self.r.traits_in_scope(
5545 self.current_trait_ref.as_ref().map(|(module, _)| *module),
5546 &self.parent_scope,
5547 ident.span,
5548 Some((ident.name, ValueNS)),
5549 );
5550 self.r.current_owner.trait_map.insert(node_id, traits);
5551 }
5552
5553 fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option<Res> {
5554 let mut doc_link_resolutions = std::mem::take(&mut self.r.doc_link_resolutions);
5558 let res = *doc_link_resolutions
5559 .entry(self.parent_scope.module.nearest_parent_mod().expect_local())
5560 .or_default()
5561 .entry((Symbol::intern(path_str), ns))
5562 .or_insert_with_key(|(path, ns)| {
5563 let res = self.r.resolve_rustdoc_path(path.as_str(), *ns, self.parent_scope);
5564 if let Some(res) = res
5565 && let Some(def_id) = res.opt_def_id()
5566 && self.is_invalid_proc_macro_item_for_doc(def_id)
5567 {
5568 return None;
5571 }
5572 res
5573 });
5574 self.r.doc_link_resolutions = doc_link_resolutions;
5575 res
5576 }
5577
5578 fn is_invalid_proc_macro_item_for_doc(&self, did: DefId) -> bool {
5579 if !#[allow(non_exhaustive_omitted_patterns)] match self.r.tcx.sess.opts.resolve_doc_links
{
ResolveDocLinks::ExportedMetadata => true,
_ => false,
}matches!(self.r.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata)
5580 || !self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
5581 {
5582 return false;
5583 }
5584 let Some(local_did) = did.as_local() else { return true };
5585 !self.r.proc_macros.contains(&local_did)
5586 }
5587
5588 fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
5589 match self.r.tcx.sess.opts.resolve_doc_links {
5590 ResolveDocLinks::None => return,
5591 ResolveDocLinks::ExportedMetadata
5592 if !self.r.tcx.crate_types().iter().copied().any(CrateType::has_metadata)
5593 || !maybe_exported.eval(self.r) =>
5594 {
5595 return;
5596 }
5597 ResolveDocLinks::Exported
5598 if !maybe_exported.eval(self.r)
5599 && !rustdoc::has_primitive_or_keyword_or_attribute_docs(attrs) =>
5600 {
5601 return;
5602 }
5603 ResolveDocLinks::ExportedMetadata
5604 | ResolveDocLinks::Exported
5605 | ResolveDocLinks::All => {}
5606 }
5607
5608 if !attrs.iter().any(|attr| attr.may_have_doc_links()) {
5609 return;
5610 }
5611
5612 let mut need_traits_in_scope = false;
5613 for path_str in rustdoc::attrs_to_preprocessed_links(attrs) {
5614 let mut any_resolved = false;
5616 let mut need_assoc = false;
5617 for ns in [TypeNS, ValueNS, MacroNS] {
5618 if let Some(res) = self.resolve_and_cache_rustdoc_path(&path_str, ns) {
5619 any_resolved = !#[allow(non_exhaustive_omitted_patterns)] match res {
Res::NonMacroAttr(NonMacroAttrKind::Tool) => true,
_ => false,
}matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Tool));
5622 } else if ns != MacroNS {
5623 need_assoc = true;
5624 }
5625 }
5626
5627 if need_assoc || !any_resolved {
5629 let mut path = &path_str[..];
5630 while let Some(idx) = path.rfind("::") {
5631 path = &path[..idx];
5632 need_traits_in_scope = true;
5633 for ns in [TypeNS, ValueNS, MacroNS] {
5634 self.resolve_and_cache_rustdoc_path(path, ns);
5635 }
5636 }
5637 }
5638 }
5639
5640 if need_traits_in_scope {
5641 let mut doc_link_traits_in_scope = std::mem::take(&mut self.r.doc_link_traits_in_scope);
5643 doc_link_traits_in_scope
5644 .entry(self.parent_scope.module.nearest_parent_mod().expect_local())
5645 .or_insert_with(|| {
5646 self.r
5647 .traits_in_scope(None, &self.parent_scope, DUMMY_SP, None)
5648 .into_iter()
5649 .filter_map(|tr| {
5650 if self.is_invalid_proc_macro_item_for_doc(tr.def_id) {
5651 return None;
5654 }
5655 Some(tr.def_id)
5656 })
5657 .collect()
5658 });
5659 self.r.doc_link_traits_in_scope = doc_link_traits_in_scope;
5660 }
5661 }
5662
5663 fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finalize: Finalize) {
5664 if let Some(seg) = path.first()
5666 && seg.ident.name == kw::PathRoot
5667 {
5668 return;
5669 }
5670
5671 if finalize.path_span.from_expansion()
5672 || path.iter().any(|seg| seg.ident.span.from_expansion())
5673 {
5674 return;
5675 }
5676
5677 let end_pos =
5678 path.iter().position(|seg| seg.has_generic_args).map_or(path.len(), |pos| pos + 1);
5679 let unqualified = path[..end_pos].iter().enumerate().skip(1).rev().find_map(|(i, seg)| {
5680 let ns = if i + 1 == path.len() { ns } else { TypeNS };
5689 let res = self.r.partial_res_map.get(&seg.id?)?.full_res()?;
5690 let binding = self.resolve_ident_in_lexical_scope(seg.ident, ns, None, None)?;
5691 (res == binding.res()).then_some((seg, binding))
5692 });
5693
5694 if let Some((seg, decl)) = unqualified {
5695 self.r.potentially_unnecessary_qualifications.push(UnnecessaryQualification {
5696 decl,
5697 node_id: finalize.node_id,
5698 path_span: finalize.path_span,
5699 removal_span: path[0].ident.span.until(seg.ident.span),
5700 });
5701 }
5702 }
5703
5704 fn resolve_define_opaques(&mut self, define_opaque: &Option<ThinVec<(NodeId, Path)>>) {
5705 if let Some(define_opaque) = define_opaque {
5706 for (id, path) in define_opaque {
5707 self.smart_resolve_path(*id, &None, path, PathSource::DefineOpaques);
5708 }
5709 }
5710 }
5711
5712 fn resolve_eii(&mut self, eii_impl: Option<&EiiImpl>) {
5713 if let Some(EiiImpl { node_id, eii_macro_path, known_eii_macro_resolution, .. }) = eii_impl
5714 {
5715 if let Some(target) = known_eii_macro_resolution {
5718 self.smart_resolve_path(*node_id, &None, target, PathSource::ExternItemImpl);
5719 } else {
5720 self.smart_resolve_path(*node_id, &None, &eii_macro_path, PathSource::Macro);
5721 }
5722 }
5723 }
5724}
5725
5726struct ItemInfoCollector<'a, 'ra, 'tcx> {
5730 r: &'a mut Resolver<'ra, 'tcx>,
5731}
5732
5733impl ItemInfoCollector<'_, '_, '_> {
5734 fn collect_fn_info(&mut self, decl: &FnDecl, id: NodeId) {
5735 self.r
5736 .delegation_fn_sigs
5737 .insert(self.r.owner_def_id(id), DelegationFnSig { has_self: decl.has_self() });
5738 }
5739}
5740
5741fn required_generic_args_suggestion(generics: &ast::Generics) -> Option<String> {
5742 let required = generics
5743 .params
5744 .iter()
5745 .filter_map(|param| match ¶m.kind {
5746 ast::GenericParamKind::Lifetime => Some("'_"),
5747 ast::GenericParamKind::Type { default } => {
5748 if default.is_none() {
5749 Some("_")
5750 } else {
5751 None
5752 }
5753 }
5754 ast::GenericParamKind::Const { default, .. } => {
5755 if default.is_none() {
5756 Some("_")
5757 } else {
5758 None
5759 }
5760 }
5761 })
5762 .collect::<Vec<_>>();
5763
5764 if required.is_empty() { None } else { Some(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", required.join(", ")))
})format!("<{}>", required.join(", "))) }
5765}
5766
5767impl Visitor<'_> for ItemInfoCollector<'_, '_, '_> {
5768 fn visit_item(&mut self, item: &Item) {
5769 if let Some(generics) = item.opt_generics() {
5770 let def_id = self.r.owner_def_id(item.id);
5771 let count = generics
5772 .params
5773 .iter()
5774 .filter(|param| #[allow(non_exhaustive_omitted_patterns)] match param.kind {
ast::GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
5775 .count();
5776 self.r.item_generics_num_lifetimes.insert(def_id, count);
5777 }
5778
5779 match &item.kind {
5780 ItemKind::Fn(Fn { sig, .. }) => {
5781 self.collect_fn_info(&sig.decl, item.id);
5782 }
5783
5784 ItemKind::ForeignMod(ForeignMod { items, .. }) => {
5785 for foreign_item in items {
5786 if let ForeignItemKind::Fn(Fn { sig, .. }) = &foreign_item.kind {
5787 self.collect_fn_info(&sig.decl, foreign_item.id);
5788 }
5789 }
5790 }
5791
5792 ItemKind::Mod(..)
5793 | ItemKind::Static(..)
5794 | ItemKind::ConstBlock(..)
5795 | ItemKind::MacroDef(..)
5796 | ItemKind::GlobalAsm(..)
5797 | ItemKind::MacCall(..)
5798 | ItemKind::Use(..)
5799 | ItemKind::ExternCrate(..)
5800 | ItemKind::DelegationMac(..)
5801 | ItemKind::TyAlias(..)
5802 | ItemKind::Const(..)
5803 | ItemKind::Enum(..)
5804 | ItemKind::Struct(..)
5805 | ItemKind::Union(..)
5806 | ItemKind::Impl(..)
5807 | ItemKind::Trait(..)
5808 | ItemKind::TraitAlias(..)
5809 | ItemKind::TestBinderConstraints(..) => {}
5810 ItemKind::Delegation(..) => {
5811 }
5816 }
5817 visit::walk_item(self, item)
5818 }
5819
5820 fn visit_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
5821 if let AssocItemKind::Fn(Fn { sig, .. }) = &item.kind {
5822 self.collect_fn_info(&sig.decl, item.id);
5823 }
5824
5825 if let AssocItemKind::Type(ast::TyAlias { generics, .. }) = &item.kind {
5826 let def_id = self.r.owner_def_id(item.id);
5827 if let Some(suggestion) = required_generic_args_suggestion(generics) {
5828 self.r.item_required_generic_args_suggestions.insert(def_id, suggestion);
5829 }
5830 }
5831 visit::walk_assoc_item(self, item, ctxt);
5832 }
5833}
5834
5835impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5836 pub(crate) fn late_resolve_crate<'ast>(
5838 &mut self,
5839 krate: &'ast Crate,
5840 ) -> (Vec<&'ast Item>, Vec<UseError<'tcx>>) {
5841 with_owner(self, CRATE_NODE_ID, |this| {
5842 let mut info_collector = ItemInfoCollector { r: this };
5843 visit::walk_crate(&mut info_collector, krate);
5844 let mut late_resolution_visitor = LateResolutionVisitor::new(this);
5845 late_resolution_visitor
5846 .resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID));
5847 visit::walk_crate(&mut late_resolution_visitor, krate);
5848 let LateResolutionVisitor { use_injections, diag_metadata, use_items, .. } =
5849 late_resolution_visitor;
5850 for (id, span) in diag_metadata.unused_labels.iter() {
5851 this.lint_buffer.buffer_lint(
5852 UNUSED_LABELS,
5853 *id,
5854 *span,
5855 crate::diagnostics::UnusedLabel,
5856 );
5857 }
5858 (use_items, use_injections)
5859 })
5860 }
5861}
5862
5863fn def_id_matches_path(tcx: TyCtxt<'_>, mut def_id: DefId, expected_path: &[&str]) -> bool {
5865 let mut path = expected_path.iter().rev();
5866 while let (Some(parent), Some(next_step)) = (tcx.opt_parent(def_id), path.next()) {
5867 if !tcx.opt_item_name(def_id).is_some_and(|n| n.as_str() == *next_step) {
5868 return false;
5869 }
5870 def_id = parent;
5871 }
5872 true
5873}