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