1use std::borrow::Cow;
10use std::collections::hash_map::Entry;
11use std::debug_assert_matches;
12use std::mem::{replace, swap, take};
13use std::ops::{ControlFlow, Range};
14
15use rustc_ast::attr::AttributeExt;
16use rustc_ast::visit::{
17 AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, try_visit, visit_opt, walk_list,
18};
19use rustc_ast::*;
20use rustc_attr_ir::target::Target;
21use rustc_data_structures::either::Either;
22use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
23use rustc_data_structures::unord::{UnordMap, UnordSet};
24use rustc_errors::codes::*;
25use rustc_errors::{
26 Applicability, Diag, DiagArgValue, Diagnostic, ErrorGuaranteed, IntoDiagArg, MultiSpan,
27 Suggestions, elided_lifetime_in_path_suggestion, pluralize,
28};
29use rustc_hir::def::Namespace::{self, *};
30use rustc_hir::def::{CtorKind, DefKind, NonMacroAttrKind, PerNS};
31use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId};
32use rustc_hir::{MissingLifetimeKind, PrimTy};
33use rustc_lint_defs::builtin::{ELIDED_LIFETIMES_IN_PATHS, UNUSED_LABELS};
34use rustc_middle::middle::resolve::{
35 DelegationInfo, DelegationInherentFnKind, DelegationResolution, LifetimeRes, PartialRes,
36};
37use rustc_middle::middle::resolve_bound_vars::Set1;
38use rustc_middle::ty::{AssocTag, Visibility};
39use rustc_session::config::ResolveDocLinks;
40use rustc_session::diagnostics::feature_err;
41use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Spanned, Symbol, bug, kw, respan, span_bug, sym};
42use rustc_structures::CrateType;
43use smallvec::{SmallVec, smallvec};
44use thin_vec::ThinVec;
45use tracing::{debug, instrument, trace};
46
47use crate::{
48 BindingError, BindingKey, Decl, DelegationFnSig, Finalize, IdentKey, LateDecl, LocalModule,
49 Module, ModuleOrUniformRoot, ParentScope, PathResult, Res, ResolutionError, Resolver, Segment,
50 Stage, TyCtxt, UseError, Used, path_names_to_string, rustdoc, with_owner,
51};
52
53mod diagnostics;
54mod lang_items;
55pub(super) mod weak_lang_items;
56
57use diagnostics::{ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime};
58pub(super) use lang_items::{Duplicate, collect_item};
59
60#[derive(#[automatically_derived]impl ::core::marker::Copy for BindingInfo { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for BindingInfo {
}
#[automatically_derived]impl ::core::clone::Clone for BindingInfo {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<BindingMode>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for BindingInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"BindingInfo span annotation", &self.span, &&self.annotation)
}
}Debug)]
61struct BindingInfo {
62 span: Span,
63 annotation: BindingMode,
64}
65
66#[derive(#[automatically_derived]impl ::core::marker::Copy for PatternSource { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for PatternSource {
}
#[automatically_derived]impl ::core::clone::Clone for PatternSource {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
PatternSource {
}
#[automatically_derived]impl ::core::cmp::PartialEq for PatternSource {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for PatternSource { }Eq, #[automatically_derived]impl ::core::fmt::Debug for PatternSource {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
PatternSource::Match => "Match",
PatternSource::Let => "Let",
PatternSource::For => "For",
PatternSource::FnParam => "FnParam",
})
}
}Debug)]
67pub(crate) enum PatternSource {
68 Match,
69 Let,
70 For,
71 FnParam,
72}
73
74#[derive(#[automatically_derived]impl ::core::marker::Copy for IsRepeatExpr { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for IsRepeatExpr {
}
#[automatically_derived]impl ::core::clone::Clone for IsRepeatExpr {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for IsRepeatExpr {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
IsRepeatExpr::No => "No",
IsRepeatExpr::Yes => "Yes",
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
IsRepeatExpr {
}
#[automatically_derived]impl ::core::cmp::PartialEq for IsRepeatExpr {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for IsRepeatExpr { }Eq)]
75enum IsRepeatExpr {
76 No,
77 Yes,
78}
79
80struct IsNeverPattern;
81
82#[derive(#[automatically_derived]impl ::core::marker::Copy for AnonConstKind { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AnonConstKind {
}
#[automatically_derived]impl ::core::clone::Clone for AnonConstKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<IsRepeatExpr>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for AnonConstKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::EnumDiscriminant =>
::core::fmt::Formatter::write_str(f, "EnumDiscriminant"),
Self::FieldDefaultValue =>
::core::fmt::Formatter::write_str(f, "FieldDefaultValue"),
Self::InlineConst =>
::core::fmt::Formatter::write_str(f, "InlineConst"),
Self::ConstArg(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ConstArg", &__self_0),
Self::ArrayLength =>
::core::fmt::Formatter::write_str(f, "ArrayLength"),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
AnonConstKind {
}
#[automatically_derived]impl ::core::cmp::PartialEq for AnonConstKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::ConstArg(__self_0), Self::ConstArg(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for AnonConstKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<IsRepeatExpr>;
}
}Eq)]
85enum AnonConstKind {
86 EnumDiscriminant,
87 FieldDefaultValue,
88 InlineConst,
89 ConstArg(IsRepeatExpr),
90 ArrayLength,
91}
92
93impl PatternSource {
94 fn descr(self) -> &'static str {
95 match self {
96 PatternSource::Match => "match binding",
97 PatternSource::Let => "let binding",
98 PatternSource::For => "for binding",
99 PatternSource::FnParam => "function parameter",
100 }
101 }
102}
103
104impl IntoDiagArg for PatternSource {
105 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
106 DiagArgValue::Str(Cow::Borrowed(self.descr()))
107 }
108}
109
110#[derive(#[automatically_derived]impl ::core::marker::StructuralPartialEq for
PatBoundCtx {
}
#[automatically_derived]impl ::core::cmp::PartialEq for PatBoundCtx {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq)]
114enum PatBoundCtx {
115 Product,
117 Or,
119}
120
121type PatternBindings = SmallVec<[(PatBoundCtx, FxIndexMap<Ident, Res>); 1]>;
133
134#[derive(#[automatically_derived]impl ::core::marker::Copy for HasGenericParams { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for HasGenericParams {
}
#[automatically_derived]impl ::core::clone::Clone for HasGenericParams {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for HasGenericParams {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Yes(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Yes",
&__self_0),
Self::No => ::core::fmt::Formatter::write_str(f, "No"),
}
}
}Debug)]
136pub(crate) enum HasGenericParams {
137 Yes(Span),
138 No,
139}
140
141#[derive(#[automatically_derived]impl ::core::marker::Copy for ConstantHasGenerics { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ConstantHasGenerics {
}
#[automatically_derived]impl ::core::clone::Clone for ConstantHasGenerics {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NoConstantGenericsReason>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ConstantHasGenerics {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Yes => ::core::fmt::Formatter::write_str(f, "Yes"),
Self::No(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "No",
&__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::cmp::Eq for ConstantHasGenerics {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NoConstantGenericsReason>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ConstantHasGenerics {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ConstantHasGenerics {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::No(__self_0), Self::No(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
143pub(crate) enum ConstantHasGenerics {
144 Yes,
145 No(NoConstantGenericsReason),
146}
147
148#[derive(#[automatically_derived]impl ::core::marker::Copy for ConstantRequiresType { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ConstantRequiresType {
}
#[automatically_derived]impl ::core::clone::Clone for ConstantRequiresType {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ConstantRequiresType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ConstantRequiresType::Usize => "Usize",
ConstantRequiresType::No => "No",
})
}
}Debug)]
150pub(crate) enum ConstantRequiresType {
151 Usize,
152 No,
153}
154
155impl ConstantHasGenerics {
156 fn force_yes_if(self, b: bool) -> Self {
157 if b { Self::Yes } else { self }
158 }
159}
160
161#[derive(#[automatically_derived]impl ::core::marker::Copy for NoConstantGenericsReason
{
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for NoConstantGenericsReason {
}
#[automatically_derived]impl ::core::clone::Clone for NoConstantGenericsReason
{
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for NoConstantGenericsReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
NoConstantGenericsReason::NonTrivialConstArg =>
"NonTrivialConstArg",
NoConstantGenericsReason::IsEnumDiscriminant =>
"IsEnumDiscriminant",
})
}
}Debug, #[automatically_derived]impl ::core::cmp::Eq for NoConstantGenericsReason { }Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
NoConstantGenericsReason {
}
#[automatically_derived]impl ::core::cmp::PartialEq for
NoConstantGenericsReason {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq)]
163pub(crate) enum NoConstantGenericsReason {
164 NonTrivialConstArg,
171 IsEnumDiscriminant,
180}
181
182#[derive(#[automatically_derived]impl ::core::marker::Copy for ConstantItemKind { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ConstantItemKind {
}
#[automatically_derived]impl ::core::clone::Clone for ConstantItemKind {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ConstantItemKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ConstantItemKind::Const => "Const",
ConstantItemKind::Static => "Static",
})
}
}Debug, #[automatically_derived]impl ::core::cmp::Eq for ConstantItemKind { }Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ConstantItemKind {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ConstantItemKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq)]
183pub(crate) enum ConstantItemKind {
184 Const,
185 Static,
186}
187
188impl ConstantItemKind {
189 pub(crate) fn as_str(&self) -> &'static str {
190 match self {
191 Self::Const => "const",
192 Self::Static => "static",
193 }
194 }
195}
196
197#[derive(#[automatically_derived]impl ::core::fmt::Debug for RecordPartialRes {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RecordPartialRes::Yes => "Yes",
RecordPartialRes::No => "No",
})
}
}Debug, #[automatically_derived]impl ::core::marker::Copy for RecordPartialRes { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for RecordPartialRes {
}
#[automatically_derived]impl ::core::clone::Clone for RecordPartialRes {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
RecordPartialRes {
}
#[automatically_derived]impl ::core::cmp::PartialEq for RecordPartialRes {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for RecordPartialRes { }Eq)]
198enum RecordPartialRes {
199 Yes,
200 No,
201}
202
203#[derive(#[automatically_derived]impl<'ra> ::core::marker::Copy for RibKind<'ra> { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'ra>
::core::clone::TrivialClone for RibKind<'ra> {
}
#[automatically_derived]impl<'ra> ::core::clone::Clone for RibKind<'ra> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Option<LocalModule<'ra>>>;
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<HasGenericParams>;
let _: ::core::clone::AssertParamIsClone<DefKind>;
let _: ::core::clone::AssertParamIsClone<ConstantHasGenerics>;
let _:
::core::clone::AssertParamIsClone<Option<(Ident,
ConstantItemKind)>>;
let _: ::core::clone::AssertParamIsClone<ConstantRequiresType>;
let _: ::core::clone::AssertParamIsClone<LocalModule<'ra>>;
let _: ::core::clone::AssertParamIsClone<DefId>;
let _:
::core::clone::AssertParamIsClone<ForwardGenericParamBanReason>;
*self
}
}Clone, #[automatically_derived]impl<'ra> ::core::fmt::Debug for RibKind<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Normal => ::core::fmt::Formatter::write_str(f, "Normal"),
Self::Block(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Block",
&__self_0),
Self::AssocItem =>
::core::fmt::Formatter::write_str(f, "AssocItem"),
Self::FnOrCoroutine =>
::core::fmt::Formatter::write_str(f, "FnOrCoroutine"),
Self::MoveExpr {
first_rib: __self_0,
move_expr_span: __self_1,
scope_span: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"MoveExpr first_rib move_expr_span scope_span", __self_0,
__self_1, &__self_2),
Self::Item(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Item",
__self_0, &__self_1),
Self::ConstantItem(__self_0, __self_1, __self_2) =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"ConstantItem", __self_0, __self_1, &__self_2),
Self::Module(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Module", &__self_0),
Self::MacroDefinition(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"MacroDefinition", &__self_0),
Self::ForwardGenericParamBan(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ForwardGenericParamBan", &__self_0),
Self::ConstParamTy =>
::core::fmt::Formatter::write_str(f, "ConstParamTy"),
Self::InlineAsmSym =>
::core::fmt::Formatter::write_str(f, "InlineAsmSym"),
}
}
}Debug)]
206pub(crate) enum RibKind<'ra> {
207 Normal,
209
210 Block(Option<LocalModule<'ra>>),
216
217 AssocItem,
222
223 FnOrCoroutine,
225
226 MoveExpr {
227 first_rib: usize,
228 move_expr_span: Span,
229 scope_span: Span,
230 },
231
232 Item(HasGenericParams, DefKind),
234
235 ConstantItem(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>, ConstantRequiresType),
242
243 Module(LocalModule<'ra>),
245
246 MacroDefinition(DefId),
248
249 ForwardGenericParamBan(ForwardGenericParamBanReason),
253
254 ConstParamTy,
257
258 InlineAsmSym,
261}
262
263#[derive(#[automatically_derived]impl ::core::marker::Copy for
ForwardGenericParamBanReason {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ForwardGenericParamBanReason {
}
#[automatically_derived]impl ::core::clone::Clone for
ForwardGenericParamBanReason {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ForwardGenericParamBanReason {
}
#[automatically_derived]impl ::core::cmp::PartialEq for
ForwardGenericParamBanReason {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ForwardGenericParamBanReason
{
}Eq, #[automatically_derived]impl ::core::fmt::Debug for
ForwardGenericParamBanReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ForwardGenericParamBanReason::Default => "Default",
ForwardGenericParamBanReason::ConstParamTy => "ConstParamTy",
})
}
}Debug)]
264pub(crate) enum ForwardGenericParamBanReason {
265 Default,
266 ConstParamTy,
267}
268
269impl RibKind<'_> {
270 pub(crate) fn contains_params(&self) -> bool {
273 match self {
274 RibKind::Normal
275 | RibKind::Block(..)
276 | RibKind::FnOrCoroutine
277 | RibKind::MoveExpr { .. }
278 | RibKind::ConstantItem(..)
279 | RibKind::Module(_)
280 | RibKind::MacroDefinition(_)
281 | RibKind::InlineAsmSym => false,
282 RibKind::ConstParamTy
283 | RibKind::AssocItem
284 | RibKind::Item(..)
285 | RibKind::ForwardGenericParamBan(_) => true,
286 }
287 }
288
289 fn is_label_barrier(self) -> bool {
291 match self {
292 RibKind::Normal | RibKind::MacroDefinition(..) => false,
293 RibKind::FnOrCoroutine | RibKind::ConstantItem(..) => true,
294 kind => ::rustc_span::macros::bug_impl(None,
format_args!("unexpected rib kind: {0:?}", kind), Location::caller())bug!("unexpected rib kind: {kind:?}"),
295 }
296 }
297}
298
299#[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 patterns_with_skipped_bindings kind",
&self.bindings, &self.patterns_with_skipped_bindings, &&self.kind)
}
}Debug)]
312pub(crate) struct Rib<'ra, R = Res> {
313 pub bindings: FxIndexMap<Ident, R>,
314 pub patterns_with_skipped_bindings:
315 UnordMap<DefId, Vec<(Span, Option<Span>, Result<(), ErrorGuaranteed>)>>,
316 pub kind: RibKind<'ra>,
317}
318
319impl<'ra, R> Rib<'ra, R> {
320 fn new(kind: RibKind<'ra>) -> Rib<'ra, R> {
321 Rib {
322 bindings: Default::default(),
323 patterns_with_skipped_bindings: Default::default(),
324 kind,
325 }
326 }
327}
328
329#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for LifetimeUseSet {
}
#[automatically_derived]impl ::core::clone::Clone for LifetimeUseSet {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<visit::LifetimeCtxt>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for LifetimeUseSet { }Copy, #[automatically_derived]impl ::core::fmt::Debug for LifetimeUseSet {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::One { use_span: __self_0, use_ctxt: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"One use_span use_ctxt", __self_0, &__self_1),
Self::Many => ::core::fmt::Formatter::write_str(f, "Many"),
}
}
}Debug)]
330enum LifetimeUseSet {
331 One { use_span: Span, use_ctxt: visit::LifetimeCtxt },
332 Many,
333}
334
335#[derive(#[automatically_derived]impl ::core::marker::Copy for LifetimeRibKind { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for LifetimeRibKind {
}
#[automatically_derived]impl ::core::clone::Clone for LifetimeRibKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<LifetimeBinderKind>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<LifetimeRes>;
let _: ::core::clone::AssertParamIsClone<NoConstantGenericsReason>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for LifetimeRibKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Generics { binder: __self_0, span: __self_1, kind: __self_2
} =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Generics binder span kind", __self_0, __self_1, &__self_2),
Self::AnonymousCreateParameter {
binder: __self_0, report_in_path: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"AnonymousCreateParameter binder report_in_path", __self_0,
&__self_1),
Self::Elided { res: __self_0, error_in_path: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Elided res error_in_path", __self_0, &__self_1),
Self::AnonymousReportError =>
::core::fmt::Formatter::write_str(f, "AnonymousReportError"),
Self::ElisionFailure =>
::core::fmt::Formatter::write_str(f, "ElisionFailure"),
Self::ConstParamTy =>
::core::fmt::Formatter::write_str(f, "ConstParamTy"),
Self::ConcreteAnonConst(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ConcreteAnonConst", &__self_0),
Self::Item => ::core::fmt::Formatter::write_str(f, "Item"),
Self::ImplTrait =>
::core::fmt::Formatter::write_str(f, "ImplTrait"),
}
}
}Debug)]
336enum LifetimeRibKind {
337 Generics { binder: NodeId, span: Span, kind: LifetimeBinderKind },
342
343 AnonymousCreateParameter { binder: NodeId, report_in_path: bool },
360
361 Elided {
363 res: LifetimeRes,
364 error_in_path: bool,
366 },
367
368 AnonymousReportError,
374
375 ElisionFailure,
377
378 ConstParamTy,
383
384 ConcreteAnonConst(NoConstantGenericsReason),
390
391 Item,
393
394 ImplTrait,
396}
397impl LifetimeRibKind {
398 fn elided(res: LifetimeRes) -> LifetimeRibKind {
400 LifetimeRibKind::Elided { res, error_in_path: false }
401 }
402}
403
404#[derive(#[automatically_derived]impl ::core::marker::Copy for LifetimeBinderKind { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for LifetimeBinderKind {
}
#[automatically_derived]impl ::core::clone::Clone for LifetimeBinderKind {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for LifetimeBinderKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"FnPtrType PolyTrait WhereBound Item ConstItem Function Closure ImplBlock ImplAssocType",
match self {
LifetimeBinderKind::FnPtrType => 0usize,
LifetimeBinderKind::PolyTrait => 10usize,
LifetimeBinderKind::WhereBound => 20usize,
LifetimeBinderKind::Item => 31usize,
LifetimeBinderKind::ConstItem => 36usize,
LifetimeBinderKind::Function => 46usize,
LifetimeBinderKind::Closure => 55usize,
LifetimeBinderKind::ImplBlock => 63usize,
LifetimeBinderKind::ImplAssocType => 73usize,
})
}
}Debug)]
405enum LifetimeBinderKind {
406 FnPtrType,
407 PolyTrait,
408 WhereBound,
409 Item,
412 ConstItem,
413 Function,
414 Closure,
415 ImplBlock,
416 ImplAssocType,
418}
419
420impl LifetimeBinderKind {
421 fn descr(self) -> &'static str {
422 use LifetimeBinderKind::*;
423 match self {
424 FnPtrType => "type",
425 PolyTrait => "bound",
426 WhereBound => "bound",
427 Item | ConstItem => "item",
428 ImplAssocType => "associated type",
429 ImplBlock => "impl block",
430 Function => "function",
431 Closure => "closure",
432 }
433 }
434}
435
436#[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 bindings", &self.kind, &&self.bindings)
}
}Debug)]
437struct LifetimeRib {
438 kind: LifetimeRibKind,
439 bindings: FxIndexMap<Ident, (NodeId, LifetimeRes)>,
441}
442
443impl LifetimeRib {
444 fn new(kind: LifetimeRibKind) -> LifetimeRib {
445 LifetimeRib { bindings: Default::default(), kind }
446 }
447}
448
449#[derive(#[automatically_derived]impl ::core::marker::Copy for AliasPossibility { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AliasPossibility {
}
#[automatically_derived]impl ::core::clone::Clone for AliasPossibility {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
AliasPossibility {
}
#[automatically_derived]impl ::core::cmp::PartialEq for AliasPossibility {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for AliasPossibility { }Eq, #[automatically_derived]impl ::core::fmt::Debug for AliasPossibility {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AliasPossibility::No => "No",
AliasPossibility::Maybe => "Maybe",
})
}
}Debug)]
450pub(crate) enum AliasPossibility {
451 No,
452 Maybe,
453}
454
455#[derive(#[automatically_derived]impl<'a, 'ast, 'ra> ::core::marker::Copy for
PathSource<'a, 'ast, 'ra> {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'a, 'ast, 'ra>
::core::clone::TrivialClone for PathSource<'a, 'ast, 'ra> {
}
#[automatically_derived]impl<'a, 'ast, 'ra> ::core::clone::Clone for
PathSource<'a, 'ast, 'ra> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<AliasPossibility>;
let _: ::core::clone::AssertParamIsClone<Option<&'ast Expr>>;
let _: ::core::clone::AssertParamIsClone<Option<&'a Expr>>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<&'ra [Span]>;
let _: ::core::clone::AssertParamIsClone<Namespace>;
let _:
::core::clone::AssertParamIsClone<&'a PathSource<'a, 'ast,
'ra>>;
*self
}
}Clone, #[automatically_derived]impl<'a, 'ast, 'ra> ::core::fmt::Debug for
PathSource<'a, 'ast, 'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Type => ::core::fmt::Formatter::write_str(f, "Type"),
Self::TypeParam =>
::core::fmt::Formatter::write_str(f, "TypeParam"),
Self::Trait(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Trait",
&__self_0),
Self::Expr(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Expr",
&__self_0),
Self::Pat => ::core::fmt::Formatter::write_str(f, "Pat"),
Self::Struct(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Struct", &__self_0),
Self::TupleStruct(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"TupleStruct", __self_0, &__self_1),
Self::TraitItem(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"TraitItem", __self_0, &__self_1),
Self::Delegation =>
::core::fmt::Formatter::write_str(f, "Delegation"),
Self::ExternItemImpl =>
::core::fmt::Formatter::write_str(f, "ExternItemImpl"),
Self::PreciseCapturingArg(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"PreciseCapturingArg", &__self_0),
Self::ReturnTypeNotation =>
::core::fmt::Formatter::write_str(f, "ReturnTypeNotation"),
Self::DefineOpaques =>
::core::fmt::Formatter::write_str(f, "DefineOpaques"),
Self::Macro => ::core::fmt::Formatter::write_str(f, "Macro"),
Self::Module => ::core::fmt::Formatter::write_str(f, "Module"),
}
}
}Debug)]
456pub(crate) enum PathSource<'a, 'ast, 'ra> {
457 Type,
459 TypeParam,
461 Trait(AliasPossibility),
463 Expr(Option<&'ast Expr>),
465 Pat,
467 Struct(Option<&'a Expr>),
469 TupleStruct(Span, &'ra [Span]),
471 TraitItem(Namespace, &'a PathSource<'a, 'ast, 'ra>),
476 Delegation,
478 ExternItemImpl,
480 PreciseCapturingArg(Namespace),
482 ReturnTypeNotation,
484 DefineOpaques,
486 Macro,
488 Module,
490}
491
492impl PathSource<'_, '_, '_> {
493 fn namespace(self) -> Namespace {
494 match self {
495 PathSource::Type
496 | PathSource::TypeParam
497 | PathSource::Trait(_)
498 | PathSource::Struct(_)
499 | PathSource::DefineOpaques
500 | PathSource::Module => TypeNS,
501 PathSource::Expr(..)
502 | PathSource::Pat
503 | PathSource::TupleStruct(..)
504 | PathSource::Delegation
505 | PathSource::ExternItemImpl
506 | PathSource::ReturnTypeNotation => ValueNS,
507 PathSource::TraitItem(ns, _) => ns,
508 PathSource::PreciseCapturingArg(ns) => ns,
509 PathSource::Macro => MacroNS,
510 }
511 }
512
513 fn defer_to_typeck(self) -> bool {
514 match self {
515 PathSource::Type
516 | PathSource::TypeParam
517 | PathSource::Expr(..)
518 | PathSource::Pat
519 | PathSource::Struct(_)
520 | PathSource::TupleStruct(..)
521 | PathSource::Delegation
522 | PathSource::ReturnTypeNotation => true,
523 PathSource::Trait(_)
524 | PathSource::TraitItem(..)
525 | PathSource::DefineOpaques
526 | PathSource::ExternItemImpl
527 | PathSource::PreciseCapturingArg(..)
528 | PathSource::Macro
529 | PathSource::Module => false,
530 }
531 }
532
533 fn descr_expected(self) -> &'static str {
534 match &self {
535 PathSource::DefineOpaques => "type alias or associated type with opaqaue types",
536 PathSource::Type => "type",
537 PathSource::TypeParam => "type or constant",
538 PathSource::Trait(_) => "trait",
539 PathSource::Pat => "unit struct, unit variant or constant",
540 PathSource::Struct(_) => "struct, variant or union type",
541 PathSource::TraitItem(ValueNS, PathSource::TupleStruct(..))
542 | PathSource::TupleStruct(..) => "tuple struct or tuple variant",
543 PathSource::TraitItem(ns, _) => match ns {
544 TypeNS => "associated type",
545 ValueNS => "method or associated constant",
546 MacroNS => ::rustc_span::macros::bug_impl(None, format_args!("associated macro"),
Location::caller())bug!("associated macro"),
547 },
548 PathSource::Expr(parent) => match parent.as_ref().map(|p| &p.kind) {
549 Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {
552 ExprKind::Path(_, path)
554 if let [segment, _] = path.segments.as_slice()
555 && segment.ident.name == kw::PathRoot =>
556 {
557 "external crate"
558 }
559 ExprKind::Path(_, path)
560 if let Some(segment) = path.segments.last()
561 && let Some(c) = segment.ident.to_string().chars().next()
562 && c.is_uppercase() =>
563 {
564 "function, tuple struct or tuple variant"
565 }
566 _ => "function",
567 },
568 _ => "value",
569 },
570 PathSource::ReturnTypeNotation | PathSource::Delegation => "function",
571 PathSource::ExternItemImpl => "function or static",
572 PathSource::PreciseCapturingArg(..) => "type or const parameter",
573 PathSource::Macro => "macro",
574 PathSource::Module => "module",
575 }
576 }
577
578 fn is_call(self) -> bool {
579 #[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(..), .. })))
580 }
581
582 pub(crate) fn is_expected(self, res: Res) -> bool {
583 match self {
584 PathSource::DefineOpaques => {
585 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum |
DefKind::TyAlias | DefKind::AssocTy, _) | Res::SelfTyAlias { .. } =>
true,
_ => false,
}matches!(
586 res,
587 Res::Def(
588 DefKind::Struct
589 | DefKind::Union
590 | DefKind::Enum
591 | DefKind::TyAlias
592 | DefKind::AssocTy,
593 _
594 ) | Res::SelfTyAlias { .. }
595 )
596 }
597 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!(
598 res,
599 Res::Def(
600 DefKind::Struct
601 | DefKind::Union
602 | DefKind::Enum
603 | DefKind::Trait
604 | DefKind::TraitAlias
605 | DefKind::TyAlias
606 | DefKind::AssocTy
607 | DefKind::TyParam
608 | DefKind::OpaqueTy
609 | DefKind::ForeignTy,
610 _,
611 ) | Res::PrimTy(..)
612 | Res::SelfTyParam { .. }
613 | Res::SelfTyAlias { .. }
614 ),
615 PathSource::TypeParam => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait
| DefKind::TraitAlias | DefKind::TyAlias | DefKind::AssocTy |
DefKind::TyParam | DefKind::OpaqueTy | DefKind::AnonConst |
DefKind::AssocConst | DefKind::Const | DefKind::ConstParam |
DefKind::ForeignTy, _) | Res::PrimTy(..) | Res::SelfTyParam { .. } |
Res::SelfTyAlias { .. } => true,
_ => false,
}matches!(
616 res,
617 Res::Def(
618 DefKind::Struct
619 | DefKind::Union
620 | DefKind::Enum
621 | DefKind::Trait
622 | DefKind::TraitAlias
623 | DefKind::TyAlias
624 | DefKind::AssocTy
625 | DefKind::TyParam
626 | DefKind::OpaqueTy
627 | DefKind::AnonConst
628 | DefKind::AssocConst
629 | DefKind::Const
630 | DefKind::ConstParam
631 | DefKind::ForeignTy,
632 _,
633 ) | Res::PrimTy(..)
634 | Res::SelfTyParam { .. }
635 | Res::SelfTyAlias { .. }
636 ),
637 PathSource::Trait(AliasPossibility::No) => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Trait, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Trait, _)),
638 PathSource::Trait(AliasPossibility::Maybe) => {
639 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Trait | DefKind::TraitAlias, _))
640 }
641 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!(
642 res,
643 Res::Def(
644 DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
645 | DefKind::Const
646 | DefKind::Static { .. }
647 | DefKind::Fn
648 | DefKind::AssocFn
649 | DefKind::AssocConst
650 | DefKind::ConstParam,
651 _,
652 ) | Res::Local(..)
653 | Res::SelfCtor(..)
654 ),
655 PathSource::Pat => {
656 res.expected_in_unit_struct_pat()
657 || #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Const | DefKind::AssocConst, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))
658 }
659 PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(),
660 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!(
661 res,
662 Res::Def(
663 DefKind::Struct
664 | DefKind::Union
665 | DefKind::Variant
666 | DefKind::TyAlias
667 | DefKind::AssocTy,
668 _,
669 ) | Res::SelfTyParam { .. }
670 | Res::SelfTyAlias { .. }
671 ),
672 PathSource::TraitItem(ns, _) => match res {
673 Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
674 Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true,
675 _ => false,
676 },
677 PathSource::ReturnTypeNotation => match res {
678 Res::Def(DefKind::AssocFn, _) => true,
679 _ => false,
680 },
681 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, _)),
682 PathSource::ExternItemImpl => {
683 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) |
DefKind::Static { .. }, _) => true,
_ => false,
}matches!(
684 res,
685 Res::Def(
686 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Static { .. },
687 _
688 )
689 )
690 }
691 PathSource::PreciseCapturingArg(ValueNS) => {
692 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::ConstParam, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::ConstParam, _))
693 }
694 PathSource::PreciseCapturingArg(TypeNS) => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } |
Res::SelfTyAlias { .. } => true,
_ => false,
}matches!(
696 res,
697 Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }
698 ),
699 PathSource::PreciseCapturingArg(MacroNS) => false,
700 PathSource::Macro => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Macro(_), _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Macro(_), _)),
701 PathSource::Module => #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Mod, _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Mod, _)),
702 }
703 }
704
705 fn error_code(self, has_unexpected_resolution: bool) -> ErrCode {
706 match (self, has_unexpected_resolution) {
707 (PathSource::Trait(_), true) => E0404,
708 (PathSource::Trait(_), false) => E0405,
709 (PathSource::Type | PathSource::DefineOpaques | PathSource::TypeParam, true) => E0573,
710 (PathSource::Type | PathSource::DefineOpaques | PathSource::TypeParam, false) => E0425,
711 (PathSource::Struct(_), true) => E0574,
712 (PathSource::Struct(_), false) => E0422,
713 (PathSource::Expr(..), true)
714 | (PathSource::Delegation, true)
715 | (PathSource::ExternItemImpl, true) => E0423,
716 (PathSource::Expr(..), false)
717 | (PathSource::Delegation, false)
718 | (PathSource::ExternItemImpl, false) => E0425,
719 (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532,
720 (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531,
721 (PathSource::TraitItem(..) | PathSource::ReturnTypeNotation, true) => E0575,
722 (PathSource::TraitItem(..) | PathSource::ReturnTypeNotation, false) => E0576,
723 (PathSource::PreciseCapturingArg(..), true) => E0799,
724 (PathSource::PreciseCapturingArg(..), false) => E0800,
725 (PathSource::Macro, _) => E0425,
726 (PathSource::Module, true) => E0577,
731 (PathSource::Module, false) => E0433,
732 }
733 }
734}
735
736#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl<'a>
::core::clone::TrivialClone for MaybeExported<'a> {
}
#[automatically_derived]impl<'a> ::core::clone::Clone for MaybeExported<'a> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<Option<DefId>>;
let _:
::core::clone::AssertParamIsClone<Result<DefId,
&'a ast::Visibility>>;
let _: ::core::clone::AssertParamIsClone<&'a ast::Visibility>;
*self
}
}Clone, #[automatically_derived]impl<'a> ::core::marker::Copy for MaybeExported<'a> {
}Copy)]
740enum MaybeExported<'a> {
741 Ok(NodeId),
742 Impl(Option<DefId>),
743 ImplItem(Result<DefId, &'a ast::Visibility>),
744 NestedUse(&'a ast::Visibility),
745}
746
747impl MaybeExported<'_> {
748 fn eval(self, r: &Resolver<'_, '_>) -> bool {
749 let def_id = match self {
750 MaybeExported::Ok(node_id) => Some(if r.current_owner.id == node_id {
751 r.current_owner.def_id
752 } else {
753 r.current_owner.node_id_to_def_id[&node_id]
754 }),
755 MaybeExported::Impl(Some(trait_def_id)) | MaybeExported::ImplItem(Ok(trait_def_id)) => {
756 trait_def_id.as_local()
757 }
758 MaybeExported::Impl(None) => return true,
759 MaybeExported::ImplItem(Err(vis)) | MaybeExported::NestedUse(vis) => {
760 return vis.kind.is_pub();
761 }
762 };
763 def_id.is_none_or(|def_id| r.effective_visibilities.is_exported(def_id))
764 }
765}
766
767#[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 node_id path_span removal_span",
&self.decl, &self.node_id, &self.path_span, &&self.removal_span)
}
}Debug)]
769pub(crate) struct UnnecessaryQualification<'ra> {
770 pub decl: LateDecl<'ra>,
771 pub node_id: NodeId,
772 pub path_span: Span,
773 pub removal_span: Span,
774}
775
776#[derive(#[automatically_derived]impl<'ast> ::core::default::Default for
DiagMetadata<'ast> {
#[inline]
fn default() -> Self {
DiagMetadata {
current_trait_assoc_items: ::core::default::Default::default(),
current_self_type: ::core::default::Default::default(),
current_self_item: ::core::default::Default::default(),
current_item: ::core::default::Default::default(),
currently_processing_generic_args: ::core::default::Default::default(),
current_function: ::core::default::Default::default(),
unused_labels: ::core::default::Default::default(),
current_let_binding: ::core::default::Default::default(),
current_pat: ::core::default::Default::default(),
in_if_condition: ::core::default::Default::default(),
in_assignment: ::core::default::Default::default(),
is_assign_rhs: ::core::default::Default::default(),
in_non_gat_assoc_type: ::core::default::Default::default(),
in_range: ::core::default::Default::default(),
current_trait_object: ::core::default::Default::default(),
current_where_predicate: ::core::default::Default::default(),
in_assoc_ty_binding: ::core::default::Default::default(),
current_type_path: ::core::default::Default::default(),
current_impl_items: ::core::default::Default::default(),
current_impl_item: ::core::default::Default::default(),
currently_processing_impl_trait: ::core::default::Default::default(),
current_elision_failures: ::core::default::Default::default(),
}
}
}Default, #[automatically_derived]impl<'ast> ::core::fmt::Debug for DiagMetadata<'ast> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
"DiagMetadata 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, names, values)
}
}Debug)]
777pub(crate) struct DiagMetadata<'ast> {
778 current_trait_assoc_items: Option<&'ast [Box<AssocItem>]>,
780
781 pub(crate) current_self_type: Option<&'ast Ty>,
783
784 current_self_item: Option<NodeId>,
786
787 pub(crate) current_item: Option<&'ast Item>,
789
790 currently_processing_generic_args: bool,
793
794 current_function: Option<(FnKind<'ast>, Span)>,
796
797 unused_labels: FxIndexMap<NodeId, Span>,
800
801 current_let_binding: Option<(Span, Option<Span>, Option<Span>)>,
803
804 current_pat: Option<&'ast Pat>,
805
806 in_if_condition: Option<&'ast Expr>,
808
809 in_assignment: Option<&'ast Expr>,
811 is_assign_rhs: bool,
812
813 in_non_gat_assoc_type: Option<bool>,
815
816 in_range: Option<(&'ast Expr, &'ast Expr)>,
818
819 current_trait_object: Option<&'ast [ast::GenericBound]>,
822
823 current_where_predicate: Option<&'ast WherePredicate>,
825
826 in_assoc_ty_binding: bool,
828
829 current_type_path: Option<&'ast Ty>,
830
831 current_impl_items: Option<&'ast [Box<AssocItem>]>,
833
834 current_impl_item: Option<&'ast AssocItem>,
836
837 currently_processing_impl_trait: Option<(&'ast TraitRef, &'ast Ty)>,
839
840 current_elision_failures: Vec<(MissingLifetime, Either<NodeId, Range<NodeId>>)>,
843}
844
845struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
846 r: &'a mut Resolver<'ra, 'tcx>,
847
848 parent_scope: ParentScope<'ra>,
850
851 ribs: PerNS<Vec<Rib<'ra>>>,
853
854 move_expr_scopes: Vec<Option<(usize, Span)>>,
855
856 last_block_rib: Option<Rib<'ra>>,
858
859 label_ribs: Vec<Rib<'ra, NodeId>>,
861
862 lifetime_ribs: Vec<LifetimeRib>,
864
865 lifetime_elision_candidates: Option<Vec<(LifetimeRes, LifetimeElisionCandidate)>>,
871
872 current_trait_ref: Option<(Module<'ra>, &'ast TraitRef)>,
874
875 diag_metadata: Box<DiagMetadata<'ast>>,
877
878 in_func_body: bool,
884
885 lifetime_uses: FxHashMap<LocalDefId, LifetimeUseSet>,
887
888 use_injections: Vec<UseError<'tcx>>,
890
891 use_items: Vec<&'ast Item>,
893}
894
895impl<'ra, 'tcx> AsRef<Resolver<'ra, 'tcx>> for LateResolutionVisitor<'_, '_, 'ra, 'tcx> {
896 fn as_ref(&self) -> &Resolver<'ra, 'tcx> {
897 &self.r
898 }
899}
900impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for LateResolutionVisitor<'_, '_, 'ra, 'tcx> {
901 fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> {
902 &mut self.r
903 }
904}
905
906impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
908 fn visit_attribute(&mut self, _: &'ast Attribute) {
909 }
912 fn visit_item(&mut self, item: &'ast Item) {
913 let prev = replace(&mut self.diag_metadata.current_item, Some(item));
914 let old_ignore = replace(&mut self.in_func_body, false);
916 with_owner(self, item.id, |this| {
917 this.with_move_expr_scope(None, |this| {
918 this.with_lifetime_rib(LifetimeRibKind::Item, |this| this.resolve_item(item))
919 })
920 });
921 self.in_func_body = old_ignore;
922 self.diag_metadata.current_item = prev;
923 }
924 fn visit_arm(&mut self, arm: &'ast Arm) {
925 self.resolve_arm(arm);
926 }
927 fn visit_block(&mut self, block: &'ast Block) {
928 let old_macro_rules = self.parent_scope.macro_rules;
929 self.resolve_block(block);
930 self.parent_scope.macro_rules = old_macro_rules;
931 }
932 fn visit_anon_const(&mut self, constant: &'ast AnonConst) {
933 ::rustc_span::macros::bug_impl(None,
format_args!("encountered anon const without a manual call to `resolve_anon_const`: {0:#?}",
constant), Location::caller());bug!("encountered anon const without a manual call to `resolve_anon_const`: {constant:#?}");
934 }
935 fn visit_expr(&mut self, expr: &'ast Expr) {
936 self.resolve_expr(expr, None);
937 }
938 fn visit_pat(&mut self, p: &'ast Pat) {
939 let prev = self.diag_metadata.current_pat;
940 self.diag_metadata.current_pat = Some(p);
941
942 if let PatKind::Guard(subpat, _) = &p.kind {
943 self.visit_pat(subpat);
945 } else {
946 visit::walk_pat(self, p);
947 }
948
949 self.diag_metadata.current_pat = prev;
950 }
951 fn visit_local(&mut self, local: &'ast Local) {
952 let local_spans = match local.pat.kind {
953 PatKind::Wild => None,
955 _ => Some((
956 local.pat.span,
957 local.ty.as_ref().map(|ty| ty.span),
958 local.kind.init().map(|init| init.span),
959 )),
960 };
961 let original = replace(&mut self.diag_metadata.current_let_binding, local_spans);
962 self.resolve_local(local);
963 self.diag_metadata.current_let_binding = original;
964 }
965 fn visit_ty(&mut self, ty: &'ast Ty) {
966 let prev = self.diag_metadata.current_trait_object;
967 let prev_ty = self.diag_metadata.current_type_path;
968 match &ty.kind {
969 TyKind::Ref(None, ..) | TyKind::PinnedRef(None, ..) => {
970 let span = self.r.tcx.sess.source_map().start_point(ty.span);
974 self.resolve_elided_lifetime(ty.id, span);
975 visit::walk_ty(self, ty);
976 }
977 TyKind::Path(qself, path) => {
978 self.diag_metadata.current_type_path = Some(ty);
979
980 let source = if let Some(seg) = path.segments.last()
984 && let Some(args) = &seg.args
985 && #[allow(non_exhaustive_omitted_patterns)] match **args {
GenericArgs::ParenthesizedElided(..) => true,
_ => false,
}matches!(**args, GenericArgs::ParenthesizedElided(..))
986 {
987 PathSource::ReturnTypeNotation
988 } else {
989 PathSource::Type
990 };
991
992 self.smart_resolve_path(ty.id, qself, path, source);
993
994 if qself.is_none()
996 && let Some(partial_res) = self.r.partial_res_map.get(&ty.id)
997 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) =
998 partial_res.full_res()
999 {
1000 let span = ty.span.shrink_to_lo().to(path.span.shrink_to_lo());
1004 self.with_generic_param_rib(
1005 &[],
1006 RibKind::Normal,
1007 ty.id,
1008 LifetimeBinderKind::PolyTrait,
1009 span,
1010 |this| this.visit_path(path),
1011 );
1012 } else {
1013 visit::walk_ty(self, ty)
1014 }
1015 }
1016 TyKind::ImplicitSelf => {
1017 let self_ty = Ident::with_dummy_span(kw::SelfUpper);
1018 let res = self
1019 .resolve_ident_in_lexical_scope(
1020 self_ty,
1021 TypeNS,
1022 Some(Finalize::new(ty.id, ty.span)),
1023 None,
1024 )
1025 .map_or(Res::Err, |d| d.res());
1026 self.r.record_partial_res(ty.id, PartialRes::new(res));
1027 visit::walk_ty(self, ty)
1028 }
1029 TyKind::ImplTrait(..) => {
1030 let candidates = self.lifetime_elision_candidates.take();
1031 self.with_lifetime_rib(LifetimeRibKind::ImplTrait, |this| visit::walk_ty(this, ty));
1032 self.lifetime_elision_candidates = candidates;
1033 }
1034 TyKind::TraitObject(bounds, ..) => {
1035 self.diag_metadata.current_trait_object = Some(&bounds[..]);
1036 visit::walk_ty(self, ty)
1037 }
1038 TyKind::FnPtr(fn_ptr) => {
1039 let span = ty.span.shrink_to_lo().to(fn_ptr.decl_span.shrink_to_lo());
1040 self.with_generic_param_rib(
1041 &fn_ptr.generic_params,
1042 RibKind::Normal,
1043 ty.id,
1044 LifetimeBinderKind::FnPtrType,
1045 span,
1046 |this| {
1047 this.visit_generic_params(&fn_ptr.generic_params, false);
1048 this.resolve_fn_signature(
1049 ty.id,
1050 false,
1051 fn_ptr.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
1054 &fn_ptr.decl.output,
1055 false,
1056 )
1057 },
1058 )
1059 }
1060 TyKind::UnsafeBinder(unsafe_binder) => {
1061 let span = ty.span.shrink_to_lo().to(unsafe_binder.inner_ty.span.shrink_to_lo());
1062 self.with_generic_param_rib(
1063 &unsafe_binder.generic_params,
1064 RibKind::Normal,
1065 ty.id,
1066 LifetimeBinderKind::FnPtrType,
1067 span,
1068 |this| {
1069 this.visit_generic_params(&unsafe_binder.generic_params, false);
1070 this.with_lifetime_rib(
1071 LifetimeRibKind::AnonymousReportError,
1074 |this| this.visit_ty(&unsafe_binder.inner_ty),
1075 );
1076 },
1077 )
1078 }
1079 TyKind::Array(element_ty, length) => {
1080 self.visit_ty(element_ty);
1081 self.resolve_anon_const(length, AnonConstKind::ArrayLength);
1082 }
1083 TyKind::GcaMacro(expr) => self.resolve_anon_const_manual(
1084 true,
1085 AnonConstKind::ConstArg(IsRepeatExpr::No),
1086 |this| this.resolve_expr(expr, None),
1087 ),
1088 _ => visit::walk_ty(self, ty),
1089 }
1090 self.diag_metadata.current_trait_object = prev;
1091 self.diag_metadata.current_type_path = prev_ty;
1092 }
1093
1094 fn visit_ty_pat(&mut self, t: &'ast TyPat) -> Self::Result {
1095 match &t.kind {
1096 TyPatKind::Range(start, end, _) => {
1097 if let Some(start) = start {
1098 self.resolve_anon_const(start, AnonConstKind::ConstArg(IsRepeatExpr::No));
1099 }
1100 if let Some(end) = end {
1101 self.resolve_anon_const(end, AnonConstKind::ConstArg(IsRepeatExpr::No));
1102 }
1103 }
1104 TyPatKind::Or(patterns) => {
1105 for pat in patterns {
1106 self.visit_ty_pat(pat)
1107 }
1108 }
1109 TyPatKind::NotNull | TyPatKind::Err(_) => {}
1110 }
1111 }
1112
1113 fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef) {
1114 let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
1115 self.with_generic_param_rib(
1116 &tref.bound_generic_params,
1117 RibKind::Normal,
1118 tref.trait_ref.ref_id,
1119 LifetimeBinderKind::PolyTrait,
1120 span,
1121 |this| {
1122 this.visit_generic_params(&tref.bound_generic_params, false);
1123 this.smart_resolve_path(
1124 tref.trait_ref.ref_id,
1125 &None,
1126 &tref.trait_ref.path,
1127 PathSource::Trait(AliasPossibility::Maybe),
1128 );
1129 this.visit_trait_ref(&tref.trait_ref);
1130 },
1131 );
1132 }
1133 fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
1134 with_owner(self, foreign_item.id, |this| {
1135 this.resolve_doc_links(&foreign_item.attrs, MaybeExported::Ok(foreign_item.id));
1136 let def_kind = this.r.tcx.def_kind(this.r.current_owner.def_id);
1137 this.check_for_lang(
1138 Target::from_foreign_item_kind(&foreign_item.kind),
1139 this.r.current_owner.def_id,
1140 &foreign_item.attrs,
1141 foreign_item.span,
1142 None,
1143 );
1144 match foreign_item.kind {
1145 ForeignItemKind::TyAlias(TyAlias { ref generics, .. }) => {
1146 this.with_generic_param_rib(
1147 &generics.params,
1148 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
1149 foreign_item.id,
1150 LifetimeBinderKind::Item,
1151 generics.span,
1152 |this| visit::walk_item(this, foreign_item),
1153 );
1154 }
1155 ForeignItemKind::Fn(Fn { ref generics, .. }) => {
1156 this.with_generic_param_rib(
1157 &generics.params,
1158 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
1159 foreign_item.id,
1160 LifetimeBinderKind::Function,
1161 generics.span,
1162 |this| visit::walk_item(this, foreign_item),
1163 );
1164 }
1165 ForeignItemKind::Static(..) => {
1166 this.with_static_rib(def_kind, |this| visit::walk_item(this, foreign_item))
1167 }
1168 ForeignItemKind::MacCall(..) => {
1169 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
1170 }
1171 }
1172 })
1173 }
1174 fn visit_fn(&mut self, fn_kind: FnKind<'ast>, _: &AttrVec, sp: Span, fn_id: NodeId) {
1175 let previous_value = self.diag_metadata.current_function;
1176 match fn_kind {
1177 FnKind::Fn(FnCtxt::Foreign, _, Fn { sig, ident, generics, .. })
1180 | FnKind::Fn(_, _, Fn { sig, ident, generics, body: None, .. }) => {
1181 self.visit_fn_header(&sig.header);
1182 self.visit_ident(ident);
1183 self.visit_generics(generics);
1184 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1186 for param in &sig.decl.inputs {
1187 if !param.is_const_param() {
1188 continue;
1189 }
1190 this.resolve_const_param_type(¶m.ty);
1191 }
1192 });
1193
1194 self.resolve_fn_signature(
1197 fn_id,
1198 sig.decl.has_self(),
1199 sig.decl
1200 .inputs
1201 .iter()
1202 .filter(|param| !param.is_const_param())
1203 .map(|Param { ty, .. }| (None, &**ty)),
1204 &sig.decl.output,
1205 false,
1206 );
1207 return;
1208 }
1209 FnKind::Fn(..) => {
1210 self.diag_metadata.current_function = Some((fn_kind, sp));
1211 }
1212 FnKind::Closure(..) => {}
1214 };
1215 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1215",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1215u32),
::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");
1216
1217 if let FnKind::Fn(_, _, f) = fn_kind {
1218 self.resolve_eii(f.eii_impl.as_deref());
1219 }
1220
1221 self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
1223 this.with_label_rib(RibKind::FnOrCoroutine, |this| {
1225 match fn_kind {
1226 FnKind::Fn(_, _, Fn { sig, generics, contract, body, .. }) => {
1227 this.visit_generics(generics);
1228 this.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1229 for param in &sig.decl.inputs {
1230 if !param.is_const_param() {
1231 continue;
1232 }
1233 this.resolve_const_param_type(¶m.ty);
1234 }
1235 });
1236
1237 let declaration = &sig.decl;
1238 this.resolve_fn_signature(
1239 fn_id,
1240 declaration.has_self(),
1241 declaration
1242 .inputs
1243 .iter()
1244 .filter(|param| !param.is_const_param())
1245 .map(|Param { pat, ty, .. }| (Some(&**pat), &**ty)),
1246 &declaration.output,
1247 sig.header.coroutine_marker.is_some(),
1248 );
1249
1250 if let Some(contract) = contract {
1251 this.visit_contract(contract);
1252 }
1253
1254 if let Some(body) = body {
1255 let previous_state = replace(&mut this.in_func_body, true);
1258 this.last_block_rib = None;
1260 this.with_lifetime_rib(
1263 LifetimeRibKind::elided(LifetimeRes::Infer),
1264 |this| this.visit_block(body),
1265 );
1266
1267 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1267",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1267u32),
::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");
1268 this.in_func_body = previous_state;
1269 }
1270 }
1271 FnKind::Closure(binder, _, declaration, body) => {
1272 this.visit_closure_binder(binder);
1273
1274 this.with_lifetime_rib(
1275 match binder {
1276 ClosureBinder::NotPresent => {
1278 LifetimeRibKind::AnonymousCreateParameter {
1279 binder: fn_id,
1280 report_in_path: false,
1281 }
1282 }
1283 ClosureBinder::For { .. } => LifetimeRibKind::AnonymousReportError,
1284 },
1285 |this| this.resolve_params(&declaration.inputs),
1287 );
1288 this.with_lifetime_rib(
1289 match binder {
1290 ClosureBinder::NotPresent => {
1291 LifetimeRibKind::elided(LifetimeRes::Infer)
1292 }
1293 ClosureBinder::For { .. } => LifetimeRibKind::AnonymousReportError,
1294 },
1295 |this| visit::walk_fn_ret_ty(this, &declaration.output),
1296 );
1297
1298 let previous_state = replace(&mut this.in_func_body, true);
1301 this.with_lifetime_rib(
1303 LifetimeRibKind::elided(LifetimeRes::Infer),
1304 |this| this.visit_expr(body),
1305 );
1306
1307 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1307",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1307u32),
::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");
1308 this.in_func_body = previous_state;
1309 }
1310 }
1311 })
1312 });
1313 self.diag_metadata.current_function = previous_value;
1314 }
1315
1316 fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::LifetimeCtxt) {
1317 self.resolve_lifetime(lifetime, use_ctxt)
1318 }
1319
1320 fn visit_precise_capturing_arg(&mut self, arg: &'ast PreciseCapturingArg) {
1321 match arg {
1322 PreciseCapturingArg::Lifetime(_) => {}
1325
1326 PreciseCapturingArg::Arg(path, id) => {
1327 let mut check_ns = |ns| {
1334 self.maybe_resolve_ident_in_lexical_scope(path.segments[0].ident, ns).is_some()
1335 };
1336 if !check_ns(TypeNS) && check_ns(ValueNS) {
1338 self.smart_resolve_path(
1339 *id,
1340 &None,
1341 path,
1342 PathSource::PreciseCapturingArg(ValueNS),
1343 );
1344 } else {
1345 self.smart_resolve_path(
1346 *id,
1347 &None,
1348 path,
1349 PathSource::PreciseCapturingArg(TypeNS),
1350 );
1351 }
1352 }
1353 }
1354
1355 visit::walk_precise_capturing_arg(self, arg)
1356 }
1357
1358 fn visit_generics(&mut self, generics: &'ast Generics) {
1359 self.visit_generic_params(&generics.params, self.diag_metadata.current_self_item.is_some());
1360 for p in &generics.where_clause.predicates {
1361 self.visit_where_predicate(p);
1362 }
1363 }
1364
1365 fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) {
1366 match b {
1367 ClosureBinder::NotPresent => {}
1368 ClosureBinder::For { generic_params, .. } => {
1369 self.visit_generic_params(
1370 generic_params,
1371 self.diag_metadata.current_self_item.is_some(),
1372 );
1373 }
1374 }
1375 }
1376
1377 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1377u32),
::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))]
1378 fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
1379 let prev = replace(&mut self.diag_metadata.currently_processing_generic_args, true);
1380 match arg {
1381 GenericArg::Type(ty) => {
1382 if let TyKind::Path(None, ref path) = ty.kind
1391 && let Some(ident) = path.as_single_argless_ident()
1392 && self.maybe_resolve_ident_in_lexical_scope(ident, TypeNS).is_none()
1393 && self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS).is_some()
1394 {
1395 self.resolve_anon_const_manual(
1396 true,
1397 AnonConstKind::ConstArg(IsRepeatExpr::No),
1398 |this| {
1399 this.smart_resolve_path(ty.id, &None, path, PathSource::Expr(None));
1400 this.visit_path(path);
1401 },
1402 )
1403 } else {
1404 self.visit_ty(ty)
1405 }
1406 }
1407 GenericArg::Lifetime(lt) => self.visit_lifetime(lt, visit::LifetimeCtxt::GenericArg),
1408 GenericArg::Const(ct) => {
1409 self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No))
1410 }
1411 }
1412 self.diag_metadata.currently_processing_generic_args = prev;
1413 }
1414
1415 fn visit_assoc_item_constraint(&mut self, constraint: &'ast AssocItemConstraint) {
1416 self.visit_ident(&constraint.ident);
1417 if let Some(ref gen_args) = constraint.gen_args {
1418 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1420 this.visit_generic_args(gen_args)
1421 });
1422 }
1423 match constraint.kind {
1424 AssocItemConstraintKind::Equality { ref term } => match term {
1425 Term::Ty(ty) => {
1426 let prev = replace(&mut self.diag_metadata.in_assoc_ty_binding, true);
1427 self.visit_ty(ty);
1428 self.diag_metadata.in_assoc_ty_binding = prev;
1429 }
1430 Term::Const(c) => {
1431 self.resolve_anon_const(c, AnonConstKind::ConstArg(IsRepeatExpr::No))
1432 }
1433 },
1434 AssocItemConstraintKind::Bound { ref bounds } => {
1435 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);
1436 }
1437 }
1438 }
1439
1440 fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
1441 let Some(ref args) = path_segment.args else {
1442 return;
1443 };
1444
1445 match &**args {
1446 GenericArgs::AngleBracketed(..) => visit::walk_generic_args(self, args),
1447 GenericArgs::Parenthesized(p_args) => {
1448 for rib in self.lifetime_ribs.iter().rev() {
1450 match rib.kind {
1451 LifetimeRibKind::Generics {
1454 binder,
1455 kind: LifetimeBinderKind::PolyTrait,
1456 ..
1457 } => {
1458 self.resolve_fn_signature(
1459 binder,
1460 false,
1461 p_args.inputs.iter().map(|param| (None, &*param.ty)),
1462 &p_args.output,
1463 false,
1464 );
1465 break;
1466 }
1467 LifetimeRibKind::Item | LifetimeRibKind::Generics { .. } => {
1470 visit::walk_generic_args(self, args);
1471 break;
1472 }
1473 LifetimeRibKind::AnonymousCreateParameter { .. }
1474 | LifetimeRibKind::AnonymousReportError
1475 | LifetimeRibKind::ImplTrait
1476 | LifetimeRibKind::Elided { .. }
1477 | LifetimeRibKind::ElisionFailure
1478 | LifetimeRibKind::ConcreteAnonConst(_)
1479 | LifetimeRibKind::ConstParamTy => {}
1480 }
1481 }
1482 }
1483 GenericArgs::ParenthesizedElided(_) => {}
1484 }
1485 }
1486
1487 fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
1488 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1488",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1488u32),
::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);
1489 let previous_value = replace(&mut self.diag_metadata.current_where_predicate, Some(p));
1490 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1491 if let WherePredicateKind::BoundPredicate(WhereBoundPredicate {
1492 bounded_ty,
1493 bounds,
1494 bound_generic_params,
1495 ..
1496 }) = &p.kind
1497 {
1498 let span = p.span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
1499 this.with_generic_param_rib(
1500 bound_generic_params,
1501 RibKind::Normal,
1502 bounded_ty.id,
1503 LifetimeBinderKind::WhereBound,
1504 span,
1505 |this| {
1506 this.visit_generic_params(bound_generic_params, false);
1507 this.visit_ty(bounded_ty);
1508 for bound in bounds {
1509 this.visit_param_bound(bound, BoundKind::Bound)
1510 }
1511 },
1512 );
1513 } else {
1514 visit::walk_where_predicate(this, p);
1515 }
1516 });
1517 self.diag_metadata.current_where_predicate = previous_value;
1518 }
1519
1520 fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) {
1521 for (op, _) in &asm.operands {
1522 match op {
1523 InlineAsmOperand::In { expr, .. }
1524 | InlineAsmOperand::Out { expr: Some(expr), .. }
1525 | InlineAsmOperand::InOut { expr, .. } => self.visit_expr(expr),
1526 InlineAsmOperand::Out { expr: None, .. } => {}
1527 InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1528 self.visit_expr(in_expr);
1529 if let Some(out_expr) = out_expr {
1530 self.visit_expr(out_expr);
1531 }
1532 }
1533 InlineAsmOperand::Const { anon_const, .. } => {
1534 self.resolve_anon_const(anon_const, AnonConstKind::InlineConst);
1537 }
1538 InlineAsmOperand::Sym { sym } => self.visit_inline_asm_sym(sym),
1539 InlineAsmOperand::Label { block } => self.visit_block(block),
1540 }
1541 }
1542 }
1543
1544 fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
1545 self.with_rib(ValueNS, RibKind::InlineAsmSym, |this| {
1547 this.with_rib(TypeNS, RibKind::InlineAsmSym, |this| {
1548 this.with_label_rib(RibKind::InlineAsmSym, |this| {
1549 this.smart_resolve_path(sym.id, &sym.qself, &sym.path, PathSource::Expr(None));
1550 visit::walk_inline_asm_sym(this, sym);
1551 });
1552 })
1553 });
1554 }
1555
1556 fn visit_variant(&mut self, v: &'ast Variant) {
1557 self.resolve_doc_links(&v.attrs, MaybeExported::Ok(v.id));
1558 self.visit_id(v.id);
1559 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);
1560 self.visit_vis(&v.vis);
1561 self.visit_ident(&v.ident);
1562 self.visit_variant_data(&v.data);
1563 self.check_for_lang(
1564 Target::Variant,
1565 self.r.current_owner.node_id_to_def_id[&v.id],
1566 &v.attrs,
1567 v.span,
1568 None,
1569 );
1570 if let Some(discr) = &v.disr_expr {
1571 self.resolve_anon_const(discr, AnonConstKind::EnumDiscriminant);
1572 }
1573 }
1574
1575 fn visit_field_def(&mut self, f: &'ast FieldDef) {
1576 self.resolve_doc_links(&f.attrs, MaybeExported::Ok(f.id));
1577 let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _, extras: _ } = f;
1578 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);
1579 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));
1580 self.resolve_restriction_path(&f.mut_restriction().kind);
1581 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);
1582 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));
1583 if let Some(v) = f.default_value() {
1584 self.resolve_anon_const(v, AnonConstKind::FieldDefaultValue);
1585 }
1586 }
1587
1588 fn visit_test_binder_forall(&mut self, forall: &'ast TestBinderForall) {
1589 self.with_generic_param_rib(
1590 &forall.generics.params,
1591 RibKind::Normal,
1592 forall.node_id,
1593 LifetimeBinderKind::WhereBound,
1594 forall.span,
1595 |this| {
1596 this.visit_generics(&forall.generics);
1597 this.visit_test_binder_body(&forall.body)
1598 },
1599 );
1600 if let Some(assert_on_exit) = &forall.assert_on_exit {
1602 for constraint in assert_on_exit {
1603 self.visit_test_binder_constraint(constraint);
1604 }
1605 }
1606 }
1607
1608 fn visit_test_binder_exists(&mut self, exists: &'ast TestBinderExists) {
1609 self.with_generic_param_rib(
1610 &exists.params,
1611 RibKind::Normal,
1612 exists.node_id,
1613 LifetimeBinderKind::WhereBound,
1614 exists.span,
1615 |this| visit::walk_test_binder_exists(this, exists),
1616 );
1617 }
1618
1619 fn visit_test_binder_bound_type_constraint(
1620 &mut self,
1621 bound_type: &'ast TestBinderBoundTypeConstraint,
1622 ) {
1623 self.with_generic_param_rib(
1624 &bound_type.params,
1625 RibKind::Normal,
1626 bound_type.node_id,
1627 LifetimeBinderKind::WhereBound,
1628 bound_type.lhs.span.to(bound_type.rhs.ident.span),
1629 |this| visit::walk_test_binder_bound_type_constraint(this, bound_type),
1630 );
1631 }
1632}
1633
1634impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1635 fn new(resolver: &'a mut Resolver<'ra, 'tcx>) -> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1636 let graph_root = resolver.graph_root;
1639 let parent_scope = ParentScope::module(graph_root, resolver.arenas);
1640 let start_rib_kind = RibKind::Module(graph_root);
1641 LateResolutionVisitor {
1642 r: resolver,
1643 parent_scope,
1644 ribs: PerNS {
1645 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)],
1646 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)],
1647 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)],
1648 },
1649 move_expr_scopes: Vec::new(),
1650 last_block_rib: None,
1651 label_ribs: Vec::new(),
1652 lifetime_ribs: Vec::new(),
1653 lifetime_elision_candidates: None,
1654 current_trait_ref: None,
1655 diag_metadata: Default::default(),
1656 in_func_body: false,
1658 lifetime_uses: Default::default(),
1659 use_injections: Vec::new(),
1660 use_items: Vec::new(),
1661 }
1662 }
1663
1664 fn maybe_resolve_ident_in_lexical_scope(
1665 &mut self,
1666 ident: Ident,
1667 ns: Namespace,
1668 ) -> Option<LateDecl<'ra>> {
1669 self.r.resolve_ident_in_lexical_scope(
1670 ident,
1671 ns,
1672 &self.parent_scope,
1673 None,
1674 &self.ribs[ns],
1675 None,
1676 Some(&self.diag_metadata),
1677 )
1678 }
1679
1680 fn resolve_ident_in_lexical_scope(
1681 &mut self,
1682 ident: Ident,
1683 ns: Namespace,
1684 finalize: Option<Finalize>,
1685 ignore_decl: Option<Decl<'ra>>,
1686 ) -> Option<LateDecl<'ra>> {
1687 self.r.resolve_ident_in_lexical_scope(
1688 ident,
1689 ns,
1690 &self.parent_scope,
1691 finalize,
1692 &self.ribs[ns],
1693 ignore_decl,
1694 Some(&self.diag_metadata),
1695 )
1696 }
1697
1698 fn resolve_path(
1699 &mut self,
1700 path: &[Segment],
1701 opt_ns: Option<Namespace>, finalize: Option<Finalize>,
1703 source: PathSource<'_, 'ast, 'ra>,
1704 ) -> PathResult<'ra> {
1705 self.r.cm_mut().resolve_path_with_ribs(
1706 path,
1707 opt_ns,
1708 &self.parent_scope,
1709 Some(source),
1710 finalize.map(|finalize| Finalize { stage: Stage::Late, ..finalize }),
1711 Some(&self.ribs),
1712 None,
1713 None,
1714 Some(&self.diag_metadata),
1715 )
1716 }
1717
1718 fn with_rib<T>(
1738 &mut self,
1739 ns: Namespace,
1740 kind: RibKind<'ra>,
1741 work: impl FnOnce(&mut Self) -> T,
1742 ) -> T {
1743 self.ribs[ns].push(Rib::new(kind));
1744 let ret = work(self);
1745 self.ribs[ns].pop();
1746 ret
1747 }
1748
1749 fn resolve_const_param_type(&mut self, ty: &'ast Ty) {
1750 if self.r.features.generic_const_parameter_types() {
1751 self.visit_ty(ty)
1752 } else {
1753 self.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTy));
1754 self.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTy));
1755 self.with_lifetime_rib(LifetimeRibKind::ConstParamTy, |this| this.visit_ty(ty));
1756 self.ribs[TypeNS].pop().unwrap();
1757 self.ribs[ValueNS].pop().unwrap();
1758 }
1759 }
1760
1761 fn with_move_expr_scope<T>(
1762 &mut self,
1763 scope_span: Option<Span>,
1764 work: impl FnOnce(&mut Self) -> T,
1765 ) -> T {
1766 if !self.r.features.move_expr() {
1767 return work(self);
1768 }
1769 let scope = scope_span.map(|span| (self.ribs[ValueNS].len(), span));
1770 self.move_expr_scopes.push(scope);
1771 let result = work(self);
1772 self.move_expr_scopes.pop();
1773 result
1774 }
1775
1776 fn with_move_expr_initializer<T>(
1777 &mut self,
1778 move_expr_span: Span,
1779 work: impl FnOnce(&mut Self) -> T,
1780 ) -> T {
1781 let Some(Some((first_rib, scope_span))) = self.move_expr_scopes.last().copied() else {
1782 return work(self);
1783 };
1784 self.move_expr_scopes.pop();
1785 let result = self.with_rib(
1786 ValueNS,
1787 RibKind::MoveExpr { first_rib, move_expr_span, scope_span },
1788 work,
1789 );
1790 self.move_expr_scopes.push(Some((first_rib, scope_span)));
1791 result
1792 }
1793
1794 fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) {
1795 let mut forward_ty_ban_rib =
1801 Rib::new(RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::Default));
1802 let mut forward_const_ban_rib =
1803 Rib::new(RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::Default));
1804 for param in params.iter() {
1805 match param.kind {
1806 GenericParamKind::Type { .. } => {
1807 forward_ty_ban_rib
1808 .bindings
1809 .insert(Ident::with_dummy_span(param.ident.name), Res::Err);
1810 }
1811 GenericParamKind::Const { .. } => {
1812 forward_const_ban_rib
1813 .bindings
1814 .insert(Ident::with_dummy_span(param.ident.name), Res::Err);
1815 }
1816 GenericParamKind::Lifetime => {}
1817 }
1818 }
1819
1820 if add_self_upper {
1830 forward_ty_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
1832 }
1833
1834 let mut forward_ty_ban_rib_const_param_ty = Rib {
1837 bindings: forward_ty_ban_rib.bindings.clone(),
1838 patterns_with_skipped_bindings: Default::default(),
1839 kind: RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::ConstParamTy),
1840 };
1841 let mut forward_const_ban_rib_const_param_ty = Rib {
1842 bindings: forward_const_ban_rib.bindings.clone(),
1843 patterns_with_skipped_bindings: Default::default(),
1844 kind: RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::ConstParamTy),
1845 };
1846 if !self.r.features.generic_const_parameter_types() {
1849 forward_ty_ban_rib_const_param_ty.bindings.clear();
1850 forward_const_ban_rib_const_param_ty.bindings.clear();
1851 }
1852
1853 self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1854 for param in params {
1855 match param.kind {
1856 GenericParamKind::Lifetime => {
1857 for bound in ¶m.bounds {
1858 this.visit_param_bound(bound, BoundKind::Bound);
1859 }
1860 }
1861 GenericParamKind::Type { ref default } => {
1862 for bound in ¶m.bounds {
1863 this.visit_param_bound(bound, BoundKind::Bound);
1864 }
1865
1866 if let Some(ty) = default {
1867 this.ribs[TypeNS].push(forward_ty_ban_rib);
1868 this.ribs[ValueNS].push(forward_const_ban_rib);
1869 this.visit_ty(ty);
1870 forward_const_ban_rib = this.ribs[ValueNS].pop().unwrap();
1871 forward_ty_ban_rib = this.ribs[TypeNS].pop().unwrap();
1872 }
1873
1874 let i = &Ident::with_dummy_span(param.ident.name);
1876 forward_ty_ban_rib.bindings.swap_remove(i);
1877 forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i);
1878 }
1879 GenericParamKind::Const { ref ty, span: _, ref default } => {
1880 if !param.bounds.is_empty() {
::core::panicking::panic("assertion failed: param.bounds.is_empty()")
};assert!(param.bounds.is_empty());
1882
1883 this.ribs[TypeNS].push(forward_ty_ban_rib_const_param_ty);
1884 this.ribs[ValueNS].push(forward_const_ban_rib_const_param_ty);
1885 this.resolve_const_param_type(ty);
1886 forward_const_ban_rib_const_param_ty = this.ribs[ValueNS].pop().unwrap();
1887 forward_ty_ban_rib_const_param_ty = this.ribs[TypeNS].pop().unwrap();
1888
1889 if let Some(expr) = default {
1890 this.ribs[TypeNS].push(forward_ty_ban_rib);
1891 this.ribs[ValueNS].push(forward_const_ban_rib);
1892 this.resolve_anon_const(
1893 expr,
1894 AnonConstKind::ConstArg(IsRepeatExpr::No),
1895 );
1896 forward_const_ban_rib = this.ribs[ValueNS].pop().unwrap();
1897 forward_ty_ban_rib = this.ribs[TypeNS].pop().unwrap();
1898 }
1899
1900 let i = &Ident::with_dummy_span(param.ident.name);
1902 forward_const_ban_rib.bindings.swap_remove(i);
1903 forward_const_ban_rib_const_param_ty.bindings.swap_remove(i);
1904 }
1905 }
1906 }
1907 })
1908 }
1909
1910 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1910u32),
::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))]
1911 fn with_lifetime_rib<T>(
1912 &mut self,
1913 kind: LifetimeRibKind,
1914 work: impl FnOnce(&mut Self) -> T,
1915 ) -> T {
1916 self.lifetime_ribs.push(LifetimeRib::new(kind));
1917 let outer_elision_candidates = self.lifetime_elision_candidates.take();
1918 let ret = work(self);
1919 self.lifetime_elision_candidates = outer_elision_candidates;
1920 self.lifetime_ribs.pop();
1921 ret
1922 }
1923
1924 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1924u32),
::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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1950",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1950u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("First use of {0:?} at {1:?}",
res, ident.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let use_set =
self.lifetime_ribs.iter().rev().find_map(|rib|
match rib.kind {
LifetimeRibKind::Item |
LifetimeRibKind::AnonymousReportError |
LifetimeRibKind::ElisionFailure =>
Some(LifetimeUseSet::Many),
LifetimeRibKind::AnonymousCreateParameter {
binder: anon_binder, .. } =>
Some(if binder == anon_binder {
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
} else { LifetimeUseSet::Many }),
LifetimeRibKind::Elided { res: r, error_in_path } => {
Some(if res == r && !error_in_path {
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
} else { LifetimeUseSet::Many })
}
LifetimeRibKind::Generics { .. } |
LifetimeRibKind::ConstParamTy => None,
LifetimeRibKind::ConcreteAnonConst(_) => {
::rustc_span::macros::bug_impl(Some(ident.span),
format_args!("unexpected rib kind: {0:?}", rib.kind),
Location::caller())
}
LifetimeRibKind::ImplTrait => {
if self.r.features.anonymous_lifetime_in_impl_trait() {
None
} else { Some(LifetimeUseSet::Many) }
}
}).unwrap_or(LifetimeUseSet::Many);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1995",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1995u32),
::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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:1999",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(1999u32),
::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))]
1925 fn resolve_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::LifetimeCtxt) {
1926 let ident = lifetime.ident;
1927
1928 if ident.name == kw::StaticLifetime {
1929 self.record_lifetime_use(
1930 lifetime.id,
1931 LifetimeRes::Static,
1932 LifetimeElisionCandidate::Ignore,
1933 );
1934 return;
1935 }
1936
1937 if ident.name == kw::UnderscoreLifetime {
1938 return self.resolve_anonymous_lifetime(lifetime, lifetime.id, false);
1939 }
1940
1941 let mut lifetime_rib_iter = self.lifetime_ribs.iter().rev();
1942 while let Some(rib) = lifetime_rib_iter.next() {
1943 let normalized_ident = ident.normalize_to_macros_2_0();
1944 if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
1945 self.record_lifetime_use(lifetime.id, res, LifetimeElisionCandidate::Ignore);
1946
1947 if let LifetimeRes::Param { param, binder } = res {
1948 match self.lifetime_uses.entry(param) {
1949 Entry::Vacant(v) => {
1950 debug!("First use of {:?} at {:?}", res, ident.span);
1951 let use_set = self
1952 .lifetime_ribs
1953 .iter()
1954 .rev()
1955 .find_map(|rib| match rib.kind {
1956 LifetimeRibKind::Item
1959 | LifetimeRibKind::AnonymousReportError
1960 | LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
1961 LifetimeRibKind::AnonymousCreateParameter {
1964 binder: anon_binder,
1965 ..
1966 } => Some(if binder == anon_binder {
1967 LifetimeUseSet::One { use_span: ident.span, use_ctxt }
1968 } else {
1969 LifetimeUseSet::Many
1970 }),
1971 LifetimeRibKind::Elided { res: r, error_in_path } => {
1974 Some(if res == r && !error_in_path {
1975 LifetimeUseSet::One { use_span: ident.span, use_ctxt }
1976 } else {
1977 LifetimeUseSet::Many
1978 })
1979 }
1980 LifetimeRibKind::Generics { .. }
1981 | LifetimeRibKind::ConstParamTy => None,
1982 LifetimeRibKind::ConcreteAnonConst(_) => {
1983 span_bug!(ident.span, "unexpected rib kind: {:?}", rib.kind)
1984 }
1985
1986 LifetimeRibKind::ImplTrait => {
1987 if self.r.features.anonymous_lifetime_in_impl_trait() {
1988 None
1989 } else {
1990 Some(LifetimeUseSet::Many)
1991 }
1992 }
1993 })
1994 .unwrap_or(LifetimeUseSet::Many);
1995 debug!(?use_ctxt, ?use_set);
1996 v.insert(use_set);
1997 }
1998 Entry::Occupied(mut o) => {
1999 debug!("Many uses of {:?} at {:?}", res, ident.span);
2000 *o.get_mut() = LifetimeUseSet::Many;
2001 }
2002 }
2003 }
2004 return;
2005 }
2006
2007 match rib.kind {
2008 LifetimeRibKind::Item => break,
2009 LifetimeRibKind::ConstParamTy => {
2010 let guar = self.emit_non_static_lt_in_const_param_ty_error(lifetime);
2011 self.record_lifetime_err(lifetime.id, guar);
2012 return;
2013 }
2014 LifetimeRibKind::ConcreteAnonConst(cause) => {
2015 let guar = self.emit_forbidden_non_static_lifetime_error(cause, lifetime);
2016 self.record_lifetime_err(lifetime.id, guar);
2017 return;
2018 }
2019 LifetimeRibKind::AnonymousCreateParameter { .. }
2020 | LifetimeRibKind::Elided { .. }
2021 | LifetimeRibKind::Generics { .. }
2022 | LifetimeRibKind::ElisionFailure
2023 | LifetimeRibKind::AnonymousReportError
2024 | LifetimeRibKind::ImplTrait => {}
2025 }
2026 }
2027
2028 let normalized_ident = ident.normalize_to_macros_2_0();
2029 let outer_res = lifetime_rib_iter
2030 .find_map(|rib| rib.bindings.get_key_value(&normalized_ident).map(|(&outer, _)| outer));
2031
2032 let guar = self.emit_undeclared_lifetime_error(lifetime, outer_res);
2033 self.record_lifetime_err(lifetime.id, guar);
2034 }
2035
2036 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2036u32),
::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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2056",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2056u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rib.kind")
}> =
::tracing::__macro_support::FieldName::new("rib.kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rib.kind)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match rib.kind {
LifetimeRibKind::AnonymousCreateParameter { binder, .. } =>
{
let res =
self.create_fresh_lifetime(lifetime.ident, binder, kind);
self.record_lifetime_use(lifetime.id, res,
elision_candidate);
return;
}
LifetimeRibKind::AnonymousReportError => {
let guar =
if elided {
let suggestion =
if self.diag_metadata.in_assoc_ty_binding {
None
} else {
self.lifetime_ribs[i..].iter().rev().find_map(|rib|
{
if let LifetimeRibKind::Generics {
span,
kind: LifetimeBinderKind::PolyTrait |
LifetimeBinderKind::WhereBound, .. } = rib.kind {
Some(crate::diagnostics::ElidedAnonymousLifetimeReportErrorSuggestion {
lo: span.shrink_to_lo(),
hi: lifetime.ident.span.shrink_to_hi(),
})
} else { None }
})
};
if !self.in_func_body &&
let Some((module, _)) = self.current_trait_ref &&
let Some(ty) = self.diag_metadata.current_self_type &&
Some(true) == self.diag_metadata.in_non_gat_assoc_type &&
let crate::ModuleKind::Def(DefKind::Trait, trait_id, _, _) =
module.kind {
if def_id_matches_path(self.r.tcx, trait_id,
&["core", "iter", "traits", "iterator", "Iterator"]) {
self.r.dcx().emit_err(crate::diagnostics::LendingIteratorReportError {
lifetime: lifetime.ident.span,
ty: ty.span,
})
} else {
let decl =
if !trait_id.is_local() &&
let Some(assoc) = self.diag_metadata.current_impl_item &&
let AssocItemKind::Type(_) = assoc.kind &&
let assocs = self.r.tcx.associated_items(trait_id) &&
let Some(ident) = assoc.kind.ident() &&
let Some(assoc) =
assocs.find_by_ident_and_kind(self.r.tcx, ident,
AssocTag::Type, trait_id) {
let mut decl: MultiSpan =
self.r.tcx.def_span(assoc.def_id).into();
decl.push_span_label(self.r.tcx.def_span(trait_id),
String::new());
decl
} else { DUMMY_SP.into() };
let mut err =
self.r.dcx().create_err(crate::diagnostics::AnonymousLifetimeNonGatReportError {
lifetime: lifetime.ident.span,
decl,
});
self.point_at_impl_lifetimes(&mut err, i,
lifetime.ident.span);
err.emit_err()
}
} else if self.diag_metadata.in_assoc_ty_binding {
let mut err =
self.r.dcx().create_err(crate::diagnostics::ElidedAnonymousLifetimeReportError {
span: lifetime.ident.span,
suggestion,
});
self.suggest_introducing_lifetime_for_assoc_ty_binding(&mut err,
lifetime.ident.span);
err.emit_err()
} else {
self.r.dcx().emit_err(crate::diagnostics::ElidedAnonymousLifetimeReportError {
span: lifetime.ident.span,
suggestion,
})
}
} else {
self.r.dcx().emit_err(crate::diagnostics::ExplicitAnonymousLifetimeReportError {
span: lifetime.ident.span,
})
};
self.record_lifetime_err(lifetime.id, guar);
return;
}
LifetimeRibKind::Elided { res, .. } => {
self.record_lifetime_use(lifetime.id, res,
elision_candidate);
return;
}
LifetimeRibKind::ElisionFailure => {
self.diag_metadata.current_elision_failures.push((missing_lifetime,
Either::Left(lifetime.id)));
return;
}
LifetimeRibKind::Item => break,
LifetimeRibKind::Generics { .. } |
LifetimeRibKind::ConstParamTy | LifetimeRibKind::ImplTrait
=> {}
LifetimeRibKind::ConcreteAnonConst(_) => {
::rustc_span::macros::bug_impl(Some(lifetime.ident.span),
format_args!("unexpected rib kind: {0:?}", rib.kind),
Location::caller())
}
}
}
let guar =
self.report_missing_lifetime_specifiers([&missing_lifetime],
None);
self.record_lifetime_err(lifetime.id, guar);
}
}
}#[instrument(level = "debug", skip(self))]
2037 fn resolve_anonymous_lifetime(
2038 &mut self,
2039 lifetime: &Lifetime,
2040 id_for_lint: NodeId,
2041 elided: bool,
2042 ) {
2043 debug_assert_eq!(lifetime.ident.name, kw::UnderscoreLifetime);
2044
2045 let kind =
2046 if elided { MissingLifetimeKind::Ampersand } else { MissingLifetimeKind::Underscore };
2047 let missing_lifetime = MissingLifetime {
2048 id: lifetime.id,
2049 span: lifetime.ident.span,
2050 kind,
2051 count: 1,
2052 id_for_lint,
2053 };
2054 let elision_candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
2055 for (i, rib) in self.lifetime_ribs.iter().enumerate().rev() {
2056 debug!(?rib.kind);
2057 match rib.kind {
2058 LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
2059 let res = self.create_fresh_lifetime(lifetime.ident, binder, kind);
2060 self.record_lifetime_use(lifetime.id, res, elision_candidate);
2061 return;
2062 }
2063 LifetimeRibKind::AnonymousReportError => {
2064 let guar = if elided {
2065 let suggestion = if self.diag_metadata.in_assoc_ty_binding {
2066 None
2072 } else {
2073 self.lifetime_ribs[i..].iter().rev().find_map(|rib| {
2074 if let LifetimeRibKind::Generics {
2078 span,
2079 kind:
2080 LifetimeBinderKind::PolyTrait
2081 | LifetimeBinderKind::WhereBound,
2082 ..
2083 } = rib.kind
2084 {
2085 Some(crate::diagnostics::ElidedAnonymousLifetimeReportErrorSuggestion {
2086 lo: span.shrink_to_lo(),
2087 hi: lifetime.ident.span.shrink_to_hi(),
2088 })
2089 } else {
2090 None
2091 }
2092 })
2093 };
2094 if !self.in_func_body
2097 && let Some((module, _)) = self.current_trait_ref
2098 && let Some(ty) = self.diag_metadata.current_self_type
2099 && Some(true) == self.diag_metadata.in_non_gat_assoc_type
2100 && let crate::ModuleKind::Def(DefKind::Trait, trait_id, _, _) =
2101 module.kind
2102 {
2103 if def_id_matches_path(
2104 self.r.tcx,
2105 trait_id,
2106 &["core", "iter", "traits", "iterator", "Iterator"],
2107 ) {
2108 self.r.dcx().emit_err(
2109 crate::diagnostics::LendingIteratorReportError {
2110 lifetime: lifetime.ident.span,
2111 ty: ty.span,
2112 },
2113 )
2114 } else {
2115 let decl = if !trait_id.is_local()
2116 && let Some(assoc) = self.diag_metadata.current_impl_item
2117 && let AssocItemKind::Type(_) = assoc.kind
2118 && let assocs = self.r.tcx.associated_items(trait_id)
2119 && let Some(ident) = assoc.kind.ident()
2120 && let Some(assoc) = assocs.find_by_ident_and_kind(
2121 self.r.tcx,
2122 ident,
2123 AssocTag::Type,
2124 trait_id,
2125 ) {
2126 let mut decl: MultiSpan =
2127 self.r.tcx.def_span(assoc.def_id).into();
2128 decl.push_span_label(
2129 self.r.tcx.def_span(trait_id),
2130 String::new(),
2131 );
2132 decl
2133 } else {
2134 DUMMY_SP.into()
2135 };
2136 let mut err = self.r.dcx().create_err(
2137 crate::diagnostics::AnonymousLifetimeNonGatReportError {
2138 lifetime: lifetime.ident.span,
2139 decl,
2140 },
2141 );
2142 self.point_at_impl_lifetimes(&mut err, i, lifetime.ident.span);
2143 err.emit_err()
2144 }
2145 } else if self.diag_metadata.in_assoc_ty_binding {
2146 let mut err = self.r.dcx().create_err(
2151 crate::diagnostics::ElidedAnonymousLifetimeReportError {
2152 span: lifetime.ident.span,
2153 suggestion,
2154 },
2155 );
2156 self.suggest_introducing_lifetime_for_assoc_ty_binding(
2157 &mut err,
2158 lifetime.ident.span,
2159 );
2160 err.emit_err()
2161 } else {
2162 self.r.dcx().emit_err(
2163 crate::diagnostics::ElidedAnonymousLifetimeReportError {
2164 span: lifetime.ident.span,
2165 suggestion,
2166 },
2167 )
2168 }
2169 } else {
2170 self.r.dcx().emit_err(
2171 crate::diagnostics::ExplicitAnonymousLifetimeReportError {
2172 span: lifetime.ident.span,
2173 },
2174 )
2175 };
2176 self.record_lifetime_err(lifetime.id, guar);
2177 return;
2178 }
2179 LifetimeRibKind::Elided { res, .. } => {
2180 self.record_lifetime_use(lifetime.id, res, elision_candidate);
2181 return;
2182 }
2183 LifetimeRibKind::ElisionFailure => {
2184 self.diag_metadata
2185 .current_elision_failures
2186 .push((missing_lifetime, Either::Left(lifetime.id)));
2187 return;
2188 }
2189 LifetimeRibKind::Item => break,
2190 LifetimeRibKind::Generics { .. }
2191 | LifetimeRibKind::ConstParamTy
2192 | LifetimeRibKind::ImplTrait => {}
2193 LifetimeRibKind::ConcreteAnonConst(_) => {
2194 span_bug!(lifetime.ident.span, "unexpected rib kind: {:?}", rib.kind)
2196 }
2197 }
2198 }
2199 let guar = self.report_missing_lifetime_specifiers([&missing_lifetime], None);
2200 self.record_lifetime_err(lifetime.id, guar);
2201 }
2202
2203 fn point_at_impl_lifetimes(&mut self, err: &mut Diag<'_>, i: usize, lifetime: Span) {
2204 let Some((rib, span)) =
2205 self.lifetime_ribs[..i].iter().rev().find_map(|rib| match rib.kind {
2206 LifetimeRibKind::Generics { span, kind: LifetimeBinderKind::ImplBlock, .. } => {
2207 Some((rib, span))
2208 }
2209 _ => None,
2210 })
2211 else {
2212 return;
2213 };
2214 if !rib.bindings.is_empty() {
2215 err.span_label(
2216 span,
2217 ::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!(
2218 "there {} named lifetime{} specified on the impl block you could use",
2219 if rib.bindings.len() == 1 { "is a" } else { "are" },
2220 pluralize!(rib.bindings.len()),
2221 ),
2222 );
2223 if rib.bindings.len() == 1 {
2224 err.span_suggestion_verbose(
2225 lifetime.shrink_to_hi(),
2226 "consider using the lifetime from the impl block",
2227 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} ",
rib.bindings.keys().next().unwrap()))
})format!("{} ", rib.bindings.keys().next().unwrap()),
2228 Applicability::MaybeIncorrect,
2229 );
2230 }
2231 } else {
2232 struct AnonRefFinder;
2233 impl<'ast> Visitor<'ast> for AnonRefFinder {
2234 type Result = ControlFlow<Span>;
2235
2236 fn visit_ty(&mut self, ty: &'ast ast::Ty) -> Self::Result {
2237 if let ast::TyKind::Ref(None, inner_ty, _) = &ty.kind {
2238 return ControlFlow::Break(inner_ty.span.shrink_to_lo());
2239 }
2240 visit::walk_ty(self, ty)
2241 }
2242
2243 fn visit_lifetime(
2244 &mut self,
2245 lt: &'ast ast::Lifetime,
2246 _cx: visit::LifetimeCtxt,
2247 ) -> Self::Result {
2248 if lt.ident.name == kw::UnderscoreLifetime {
2249 return ControlFlow::Break(lt.ident.span);
2250 }
2251 visit::walk_lifetime(self, lt)
2252 }
2253 }
2254
2255 if let Some(ty) = &self.diag_metadata.current_self_type
2256 && let ControlFlow::Break(sp) = AnonRefFinder.visit_ty(ty)
2257 {
2258 err.multipart_suggestion(
2259 "add a lifetime to the impl block and use it in the self type and associated \
2260 type",
2261 ::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![
2262 (span, "<'a>".to_string()),
2263 (sp, "'a ".to_string()),
2264 (lifetime.shrink_to_hi(), "'a ".to_string()),
2265 ],
2266 Applicability::MaybeIncorrect,
2267 );
2268 } else if let Some(item) = &self.diag_metadata.current_item
2269 && let ItemKind::Impl(impl_) = &item.kind
2270 && let Some(of_trait) = &impl_.of_trait
2271 && let ControlFlow::Break(sp) = AnonRefFinder.visit_trait_ref(&of_trait.trait_ref)
2272 {
2273 err.multipart_suggestion(
2274 "add a lifetime to the impl block and use it in the trait and associated type",
2275 ::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![
2276 (span, "<'a>".to_string()),
2277 (sp, "'a".to_string()),
2278 (lifetime.shrink_to_hi(), "'a ".to_string()),
2279 ],
2280 Applicability::MaybeIncorrect,
2281 );
2282 } else {
2283 err.span_label(
2284 span,
2285 "you could add a lifetime on the impl block, if the trait or the self type \
2286 could have one",
2287 );
2288 }
2289 }
2290 }
2291
2292 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2292u32),
::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))]
2293 fn resolve_elided_lifetime(&mut self, anchor_id: NodeId, span: Span) {
2294 let id = self.r.next_node_id();
2295 let lt = Lifetime { id, ident: Ident::new(kw::UnderscoreLifetime, span) };
2296
2297 self.record_lifetime_use(
2298 anchor_id,
2299 LifetimeRes::ElidedAnchor { start: id, end: id + 1 },
2300 LifetimeElisionCandidate::Ignore,
2301 );
2302 self.resolve_anonymous_lifetime(<, anchor_id, true);
2303 }
2304
2305 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2305u32),
::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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2313",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2313u32),
::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))]
2306 fn create_fresh_lifetime(
2307 &mut self,
2308 ident: Ident,
2309 binder: NodeId,
2310 kind: MissingLifetimeKind,
2311 ) -> LifetimeRes {
2312 debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
2313 debug!(?ident.span);
2314
2315 let param = self.r.next_node_id();
2317 let res = LifetimeRes::Fresh { param, kind };
2318 self.record_lifetime_def(param, res);
2319
2320 self.r
2322 .current_owner
2323 .extra_lifetime_params_map
2324 .entry(binder)
2325 .or_insert_with(Vec::new)
2326 .push((ident, param, kind));
2327 res
2328 }
2329
2330 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2330u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("partial_res")
}> =
::tracing::__macro_support::FieldName::new("partial_res");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path_span")
}> =
::tracing::__macro_support::FieldName::new("path_span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&partial_res)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path_span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let proj_start = path.len() - partial_res.unresolved_segments();
for (i, segment) in path.iter().enumerate() {
if segment.has_lifetime_args { continue; }
let Some(segment_id) = segment.id else { continue; };
let type_def_id =
match partial_res.base_res() {
Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start =>
{
self.r.tcx.parent(def_id)
}
Res::Def(DefKind::Variant, def_id) if
i + 2 == proj_start && segment.has_generic_args => {
self.r.tcx.parent(def_id)
}
Res::Def(DefKind::Variant, def_id) if
i + 1 == proj_start &&
!i.checked_sub(1).is_some_and(|i| path[i].has_generic_args)
=> {
self.r.tcx.parent(def_id)
}
Res::Def(DefKind::Struct, def_id) |
Res::Def(DefKind::Union, def_id) |
Res::Def(DefKind::Enum, def_id) |
Res::Def(DefKind::TyAlias, def_id) |
Res::Def(DefKind::Trait, def_id) if i + 1 == proj_start => {
def_id
}
_ => continue,
};
let expected_lifetimes =
self.r.item_generics_num_lifetimes(type_def_id);
if expected_lifetimes == 0 { continue; }
let node_ids = self.r.next_node_ids(expected_lifetimes);
self.record_lifetime_use(segment_id,
LifetimeRes::ElidedAnchor {
start: node_ids.start,
end: node_ids.end,
}, LifetimeElisionCandidate::Ignore);
let inferred =
match source {
PathSource::Trait(..) | PathSource::TraitItem(..) |
PathSource::Type | PathSource::TypeParam |
PathSource::PreciseCapturingArg(..) |
PathSource::ReturnTypeNotation | PathSource::Macro |
PathSource::Module => false,
PathSource::Expr(..) | PathSource::Pat |
PathSource::Struct(_) | PathSource::TupleStruct(..) |
PathSource::DefineOpaques | PathSource::Delegation |
PathSource::ExternItemImpl => true,
};
if inferred {
for id in node_ids {
self.record_lifetime_use(id, LifetimeRes::Infer,
LifetimeElisionCandidate::Ignore);
}
continue;
}
let elided_lifetime_span =
if segment.has_generic_args {
segment.args_span.with_hi(segment.args_span.lo() +
BytePos(1))
} else {
segment.ident.span.find_ancestor_inside(path_span).unwrap_or(path_span)
};
let ident =
Ident::new(kw::UnderscoreLifetime, elided_lifetime_span);
let kind =
if segment.has_generic_args {
MissingLifetimeKind::Comma
} else { MissingLifetimeKind::Brackets };
let missing_lifetime =
MissingLifetime {
id: node_ids.start,
id_for_lint: segment_id,
span: elided_lifetime_span,
kind,
count: expected_lifetimes,
};
let mut should_lint = true;
for rib in self.lifetime_ribs.iter().rev() {
match rib.kind {
LifetimeRibKind::AnonymousCreateParameter {
report_in_path: true, .. } | LifetimeRibKind::Elided {
error_in_path: true, .. } => {
let sess = self.r.tcx.sess;
let subdiag =
elided_lifetime_in_path_suggestion(sess.source_map(),
expected_lifetimes, path_span, !segment.has_generic_args,
elided_lifetime_span);
let guar =
self.r.dcx().emit_err(crate::diagnostics::ImplicitElidedLifetimeNotAllowedHere {
span: path_span,
subdiag,
});
should_lint = false;
for id in node_ids { self.record_lifetime_err(id, guar); }
break;
}
LifetimeRibKind::AnonymousCreateParameter { binder, .. } =>
{
let mut candidate =
LifetimeElisionCandidate::Missing(missing_lifetime);
for id in node_ids {
let res = self.create_fresh_lifetime(ident, binder, kind);
self.record_lifetime_use(id, res,
replace(&mut candidate, LifetimeElisionCandidate::Ignore));
}
break;
}
LifetimeRibKind::Elided { res, error_in_path: false } => {
let mut candidate =
LifetimeElisionCandidate::Missing(missing_lifetime);
for id in node_ids {
self.record_lifetime_use(id, res,
replace(&mut candidate, LifetimeElisionCandidate::Ignore));
}
break;
}
LifetimeRibKind::ElisionFailure => {
self.diag_metadata.current_elision_failures.push((missing_lifetime,
Either::Right(node_ids)));
break;
}
LifetimeRibKind::AnonymousReportError |
LifetimeRibKind::Item => {
let guar =
self.report_missing_lifetime_specifiers([&missing_lifetime],
None);
for id in node_ids { self.record_lifetime_err(id, guar); }
break;
}
LifetimeRibKind::Generics { .. } |
LifetimeRibKind::ConstParamTy | LifetimeRibKind::ImplTrait
=> {}
LifetimeRibKind::ConcreteAnonConst(_) => {
::rustc_span::macros::bug_impl(Some(elided_lifetime_span),
format_args!("unexpected rib kind: {0:?}", rib.kind),
Location::caller())
}
}
}
if should_lint {
let include_angle_bracket = !segment.has_generic_args;
self.r.lint_buffer.dyn_buffer_lint_any(ELIDED_LIFETIMES_IN_PATHS,
segment_id, elided_lifetime_span,
move |dcx, level, sess|
{
let source_map =
sess.downcast_ref::<rustc_session::Session>().expect("expected a `Session`").source_map();
crate::diagnostics::ElidedLifetimesInPaths {
subdiag: elided_lifetime_in_path_suggestion(source_map,
expected_lifetimes, path_span, include_angle_bracket,
elided_lifetime_span),
}.into_diag(dcx, level)
});
}
}
}
}
}#[instrument(level = "debug", skip(self))]
2331 fn resolve_elided_lifetimes_in_path(
2332 &mut self,
2333 partial_res: PartialRes,
2334 path: &[Segment],
2335 source: PathSource<'_, 'ast, 'ra>,
2336 path_span: Span,
2337 ) {
2338 let proj_start = path.len() - partial_res.unresolved_segments();
2339 for (i, segment) in path.iter().enumerate() {
2340 if segment.has_lifetime_args {
2341 continue;
2342 }
2343 let Some(segment_id) = segment.id else {
2344 continue;
2345 };
2346
2347 let type_def_id = match partial_res.base_res() {
2350 Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start => {
2351 self.r.tcx.parent(def_id)
2352 }
2353 Res::Def(DefKind::Variant, def_id)
2354 if i + 2 == proj_start && segment.has_generic_args =>
2355 {
2356 self.r.tcx.parent(def_id)
2357 }
2358 Res::Def(DefKind::Variant, def_id)
2359 if i + 1 == proj_start
2360 && !i.checked_sub(1).is_some_and(|i| path[i].has_generic_args) =>
2361 {
2362 self.r.tcx.parent(def_id)
2363 }
2364 Res::Def(DefKind::Struct, def_id)
2365 | Res::Def(DefKind::Union, def_id)
2366 | Res::Def(DefKind::Enum, def_id)
2367 | Res::Def(DefKind::TyAlias, def_id)
2368 | Res::Def(DefKind::Trait, def_id)
2369 if i + 1 == proj_start =>
2370 {
2371 def_id
2372 }
2373 _ => continue,
2374 };
2375
2376 let expected_lifetimes = self.r.item_generics_num_lifetimes(type_def_id);
2377 if expected_lifetimes == 0 {
2378 continue;
2379 }
2380
2381 let node_ids = self.r.next_node_ids(expected_lifetimes);
2382 self.record_lifetime_use(
2383 segment_id,
2384 LifetimeRes::ElidedAnchor { start: node_ids.start, end: node_ids.end },
2385 LifetimeElisionCandidate::Ignore,
2386 );
2387
2388 let inferred = match source {
2389 PathSource::Trait(..)
2390 | PathSource::TraitItem(..)
2391 | PathSource::Type
2392 | PathSource::TypeParam
2393 | PathSource::PreciseCapturingArg(..)
2394 | PathSource::ReturnTypeNotation
2395 | PathSource::Macro
2396 | PathSource::Module => false,
2397 PathSource::Expr(..)
2398 | PathSource::Pat
2399 | PathSource::Struct(_)
2400 | PathSource::TupleStruct(..)
2401 | PathSource::DefineOpaques
2402 | PathSource::Delegation
2403 | PathSource::ExternItemImpl => true,
2404 };
2405 if inferred {
2406 for id in node_ids {
2409 self.record_lifetime_use(
2410 id,
2411 LifetimeRes::Infer,
2412 LifetimeElisionCandidate::Ignore,
2413 );
2414 }
2415 continue;
2416 }
2417
2418 let elided_lifetime_span = if segment.has_generic_args {
2419 segment.args_span.with_hi(segment.args_span.lo() + BytePos(1))
2421 } else {
2422 segment.ident.span.find_ancestor_inside(path_span).unwrap_or(path_span)
2426 };
2427 let ident = Ident::new(kw::UnderscoreLifetime, elided_lifetime_span);
2428
2429 let kind = if segment.has_generic_args {
2430 MissingLifetimeKind::Comma
2431 } else {
2432 MissingLifetimeKind::Brackets
2433 };
2434 let missing_lifetime = MissingLifetime {
2435 id: node_ids.start,
2436 id_for_lint: segment_id,
2437 span: elided_lifetime_span,
2438 kind,
2439 count: expected_lifetimes,
2440 };
2441 let mut should_lint = true;
2442 for rib in self.lifetime_ribs.iter().rev() {
2443 match rib.kind {
2444 LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
2451 | LifetimeRibKind::Elided { error_in_path: true, .. } => {
2452 let sess = self.r.tcx.sess;
2453 let subdiag = elided_lifetime_in_path_suggestion(
2454 sess.source_map(),
2455 expected_lifetimes,
2456 path_span,
2457 !segment.has_generic_args,
2458 elided_lifetime_span,
2459 );
2460 let guar = self.r.dcx().emit_err(
2461 crate::diagnostics::ImplicitElidedLifetimeNotAllowedHere {
2462 span: path_span,
2463 subdiag,
2464 },
2465 );
2466 should_lint = false;
2467
2468 for id in node_ids {
2469 self.record_lifetime_err(id, guar);
2470 }
2471 break;
2472 }
2473 LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
2475 let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
2477 for id in node_ids {
2478 let res = self.create_fresh_lifetime(ident, binder, kind);
2479 self.record_lifetime_use(
2480 id,
2481 res,
2482 replace(&mut candidate, LifetimeElisionCandidate::Ignore),
2483 );
2484 }
2485 break;
2486 }
2487 LifetimeRibKind::Elided { res, error_in_path: false } => {
2488 let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
2489 for id in node_ids {
2490 self.record_lifetime_use(
2491 id,
2492 res,
2493 replace(&mut candidate, LifetimeElisionCandidate::Ignore),
2494 );
2495 }
2496 break;
2497 }
2498 LifetimeRibKind::ElisionFailure => {
2499 self.diag_metadata
2500 .current_elision_failures
2501 .push((missing_lifetime, Either::Right(node_ids)));
2502 break;
2503 }
2504 LifetimeRibKind::AnonymousReportError | LifetimeRibKind::Item => {
2509 let guar =
2510 self.report_missing_lifetime_specifiers([&missing_lifetime], None);
2511 for id in node_ids {
2512 self.record_lifetime_err(id, guar);
2513 }
2514 break;
2515 }
2516 LifetimeRibKind::Generics { .. }
2517 | LifetimeRibKind::ConstParamTy
2518 | LifetimeRibKind::ImplTrait => {}
2519 LifetimeRibKind::ConcreteAnonConst(_) => {
2520 span_bug!(elided_lifetime_span, "unexpected rib kind: {:?}", rib.kind)
2522 }
2523 }
2524 }
2525
2526 if should_lint {
2527 let include_angle_bracket = !segment.has_generic_args;
2528 self.r.lint_buffer.dyn_buffer_lint_any(
2529 ELIDED_LIFETIMES_IN_PATHS,
2530 segment_id,
2531 elided_lifetime_span,
2532 move |dcx, level, sess| {
2533 let source_map = sess
2534 .downcast_ref::<rustc_session::Session>()
2535 .expect("expected a `Session`")
2536 .source_map();
2537 crate::diagnostics::ElidedLifetimesInPaths {
2538 subdiag: elided_lifetime_in_path_suggestion(
2539 source_map,
2540 expected_lifetimes,
2541 path_span,
2542 include_angle_bracket,
2543 elided_lifetime_span,
2544 ),
2545 }
2546 .into_diag(dcx, level)
2547 },
2548 );
2549 }
2550 }
2551 }
2552
2553 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2554u32),
::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))]
2555 fn record_lifetime_use(
2556 &mut self,
2557 id: NodeId,
2558 res: LifetimeRes,
2559 candidate: LifetimeElisionCandidate,
2560 ) {
2561 self.record_lifetime_def(id, res);
2562
2563 match res {
2564 LifetimeRes::Param { .. } | LifetimeRes::Fresh { .. } | LifetimeRes::Static { .. } => {
2565 if let Some(ref mut candidates) = self.lifetime_elision_candidates {
2566 candidates.push((res, candidate));
2567 }
2568 }
2569 LifetimeRes::Infer | LifetimeRes::Error(..) | LifetimeRes::ElidedAnchor { .. } => {}
2570 }
2571 }
2572
2573 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2575u32),
::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))]
2576 fn record_lifetime_err(&mut self, id: NodeId, guar: ErrorGuaranteed) {
2577 self.record_lifetime_def(id, LifetimeRes::Error(guar));
2578 }
2579
2580 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2581u32),
::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))]
2582 fn record_lifetime_def(&mut self, id: NodeId, res: LifetimeRes) {
2583 if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) {
2584 panic!(
2585 "lifetime parameter {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)"
2586 )
2587 }
2588 }
2589
2590 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2591u32),
::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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2607",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2607u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("elision_lifetime")
}> =
::tracing::__macro_support::FieldName::new("elision_lifetime");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&elision_lifetime)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let outer_failures =
take(&mut this.diag_metadata.current_elision_failures);
let output_rib =
if let Ok(res) = elision_lifetime.as_ref() {
if fn_id == this.r.current_owner.id {
this.r.current_owner.lifetime_elision_allowed = true;
}
LifetimeRibKind::elided(*res)
} else { LifetimeRibKind::ElisionFailure };
this.with_lifetime_rib(output_rib,
|this| visit::walk_fn_ret_ty(this, output_ty));
let elision_failures =
replace(&mut this.diag_metadata.current_elision_failures,
outer_failures);
if !elision_failures.is_empty() {
let Err(failure_info) =
elision_lifetime else {
::rustc_span::macros::bug_impl(None,
format_args!("impossible case reached"), Location::caller())
};
let guar =
this.report_missing_lifetime_specifiers(elision_failures.iter().map(|(missing_lifetime,
..)| missing_lifetime), Some(failure_info));
let mut record_res =
|lifetime| this.record_lifetime_err(lifetime, guar);
for (_, nodes) in elision_failures {
match nodes {
Either::Left(node_id) => record_res(node_id),
Either::Right(node_ids) => {
for lifetime in node_ids { record_res(lifetime) }
}
}
}
}
});
}
}
}#[instrument(level = "debug", skip(self, inputs))]
2592 fn resolve_fn_signature(
2593 &mut self,
2594 fn_id: NodeId,
2595 has_self: bool,
2596 inputs: impl Iterator<Item = (Option<&'ast Pat>, &'ast Ty)> + Clone,
2597 output_ty: &'ast FnRetTy,
2598 report_elided_lifetimes_in_path: bool,
2599 ) {
2600 let rib = LifetimeRibKind::AnonymousCreateParameter {
2601 binder: fn_id,
2602 report_in_path: report_elided_lifetimes_in_path,
2603 };
2604 self.with_lifetime_rib(rib, |this| {
2605 let elision_lifetime = this.resolve_fn_params(has_self, inputs);
2607 debug!(?elision_lifetime);
2608
2609 let outer_failures = take(&mut this.diag_metadata.current_elision_failures);
2610 let output_rib = if let Ok(res) = elision_lifetime.as_ref() {
2611 if fn_id == this.r.current_owner.id {
2612 this.r.current_owner.lifetime_elision_allowed = true;
2613 }
2614 LifetimeRibKind::elided(*res)
2615 } else {
2616 LifetimeRibKind::ElisionFailure
2617 };
2618 this.with_lifetime_rib(output_rib, |this| visit::walk_fn_ret_ty(this, output_ty));
2619 let elision_failures =
2620 replace(&mut this.diag_metadata.current_elision_failures, outer_failures);
2621 if !elision_failures.is_empty() {
2622 let Err(failure_info) = elision_lifetime else { bug!() };
2623 let guar = this.report_missing_lifetime_specifiers(
2624 elision_failures.iter().map(|(missing_lifetime, ..)| missing_lifetime),
2625 Some(failure_info),
2626 );
2627 let mut record_res = |lifetime| this.record_lifetime_err(lifetime, guar);
2628 for (_, nodes) in elision_failures {
2629 match nodes {
2630 Either::Left(node_id) => record_res(node_id),
2631 Either::Right(node_ids) => {
2632 for lifetime in node_ids {
2633 record_res(lifetime)
2634 }
2635 }
2636 }
2637 }
2638 }
2639 });
2640 }
2641
2642 fn resolve_fn_params(
2646 &mut self,
2647 has_self: bool,
2648 inputs: impl Iterator<Item = (Option<&'ast Pat>, &'ast Ty)> + Clone,
2649 ) -> Result<LifetimeRes, (Vec<MissingLifetime>, Vec<ElisionFnParameter>)> {
2650 enum Elision {
2651 None,
2653 Self_(LifetimeRes),
2655 Param(LifetimeRes),
2657 Err,
2659 }
2660
2661 let outer_candidates = self.lifetime_elision_candidates.take();
2663
2664 let mut elision_lifetime = Elision::None;
2666 let mut parameter_info = Vec::new();
2668 let mut all_candidates = Vec::new();
2669
2670 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())];
2672 for (pat, _) in inputs.clone() {
2673 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2673",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2673u32),
::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:?}");
2674 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
2675 if let Some(pat) = pat {
2676 this.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
2677 }
2678 });
2679 }
2680 self.apply_pattern_bindings(bindings);
2681
2682 for (index, (pat, ty)) in inputs.enumerate() {
2683 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2683",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2683u32),
::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:?}");
2684 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);
2686 self.lifetime_elision_candidates = Some(Default::default());
2687 self.visit_ty(ty);
2688 let local_candidates = self.lifetime_elision_candidates.take();
2689
2690 if let Some(candidates) = local_candidates {
2691 let distinct: UnordSet<_> = candidates.iter().map(|(res, _)| *res).collect();
2692 let lifetime_count = distinct.len();
2693 if lifetime_count != 0 {
2694 parameter_info.push(ElisionFnParameter {
2695 index,
2696 ident: if let Some(pat) = pat
2697 && let PatKind::Ident(_, ident, _) = pat.kind
2698 {
2699 Some(ident)
2700 } else {
2701 None
2702 },
2703 lifetime_count,
2704 span: ty.span,
2705 });
2706 all_candidates.extend(candidates.into_iter().filter_map(|(_, candidate)| {
2707 match candidate {
2708 LifetimeElisionCandidate::Ignore => None,
2709 LifetimeElisionCandidate::Missing(missing) => Some(missing),
2710 }
2711 }));
2712 }
2713 if !distinct.is_empty() {
2714 match elision_lifetime {
2715 Elision::None => {
2717 if let Some(res) = distinct.get_only() {
2718 elision_lifetime = Elision::Param(*res)
2720 } else {
2721 elision_lifetime = Elision::Err;
2723 }
2724 }
2725 Elision::Param(_) => elision_lifetime = Elision::Err,
2727 Elision::Self_(_) | Elision::Err => {}
2729 }
2730 }
2731 }
2732
2733 if index == 0 && has_self {
2735 let self_lifetime = self.find_lifetime_for_self(ty);
2736 elision_lifetime = match self_lifetime {
2737 Set1::One(lifetime) => Elision::Self_(lifetime),
2739 Set1::Many => Elision::Err,
2744 Set1::Empty => Elision::None,
2747 }
2748 }
2749 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2749",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2749u32),
::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");
2750 }
2751
2752 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);
2754 self.lifetime_elision_candidates = outer_candidates;
2755
2756 if let Elision::Param(res) | Elision::Self_(res) = elision_lifetime {
2757 return Ok(res);
2758 }
2759
2760 Err((all_candidates, parameter_info))
2762 }
2763
2764 fn find_lifetime_for_self(&self, ty: &'ast Ty) -> Set1<LifetimeRes> {
2766 struct FindReferenceVisitor<'a, 'ra, 'tcx> {
2770 r: &'a Resolver<'ra, 'tcx>,
2771 impl_self: Option<Res>,
2772 lifetime: Set1<LifetimeRes>,
2773 }
2774
2775 impl<'ra> Visitor<'ra> for FindReferenceVisitor<'_, '_, '_> {
2776 fn visit_ty(&mut self, ty: &'ra Ty) {
2777 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2777",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2777u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("FindReferenceVisitor considering ty={0:?}",
ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("FindReferenceVisitor considering ty={:?}", ty);
2778 if let TyKind::Ref(lt, ..) | TyKind::PinnedRef(lt, ..) = ty.kind {
2779 let mut visitor =
2781 SelfVisitor { r: self.r, impl_self: self.impl_self, self_found: false };
2782 visitor.visit_ty(ty);
2783 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2783",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2783u32),
::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);
2784 if visitor.self_found {
2785 let lt_id = if let Some(lt) = lt {
2786 lt.id
2787 } else {
2788 let res = self.r.current_owner.lifetimes_res_map[&ty.id];
2789 let LifetimeRes::ElidedAnchor { start, .. } = res else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
Location::caller())bug!() };
2790 start
2791 };
2792 let lt_res = self.r.current_owner.lifetimes_res_map[<_id];
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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2793",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/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::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);
2794 self.lifetime.insert(lt_res);
2795 }
2796 }
2797 visit::walk_ty(self, ty)
2798 }
2799
2800 fn visit_expr(&mut self, _: &'ra Expr) {}
2803 }
2804
2805 struct SelfVisitor<'a, 'ra, 'tcx> {
2808 r: &'a Resolver<'ra, 'tcx>,
2809 impl_self: Option<Res>,
2810 self_found: bool,
2811 }
2812
2813 impl SelfVisitor<'_, '_, '_> {
2814 fn is_self_ty(&self, ty: &Ty) -> bool {
2816 match ty.kind {
2817 TyKind::ImplicitSelf => true,
2818 TyKind::Path(None, _) => {
2819 let path_res = self.r.partial_res_map[&ty.id].full_res();
2820 if let Some(Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }) = path_res {
2821 return true;
2822 }
2823 self.impl_self.is_some() && path_res == self.impl_self
2824 }
2825 _ => false,
2826 }
2827 }
2828 }
2829
2830 impl<'ra> Visitor<'ra> for SelfVisitor<'_, '_, '_> {
2831 fn visit_ty(&mut self, ty: &'ra Ty) {
2832 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2832",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2832u32),
::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);
2833 if self.is_self_ty(ty) {
2834 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2834",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2834u32),
::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");
2835 self.self_found = true;
2836 }
2837 visit::walk_ty(self, ty)
2838 }
2839
2840 fn visit_expr(&mut self, _: &'ra Expr) {}
2843 }
2844
2845 let impl_self = self
2846 .diag_metadata
2847 .current_self_type
2848 .and_then(|ty| {
2849 if let TyKind::Path(None, _) = ty.kind {
2850 self.r.partial_res_map.get(&ty.id)
2851 } else {
2852 None
2853 }
2854 })
2855 .and_then(|res| res.full_res())
2856 .filter(|res| {
2857 #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum, _) |
Res::PrimTy(_) => true,
_ => false,
}matches!(
2861 res,
2862 Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum, _,) | Res::PrimTy(_)
2863 )
2864 });
2865 let mut visitor = FindReferenceVisitor { r: self.r, impl_self, lifetime: Set1::Empty };
2866 visitor.visit_ty(ty);
2867 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2867",
"rustc_resolve::late", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2867u32),
::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);
2868 visitor.lifetime
2869 }
2870
2871 fn resolve_label(&self, mut label: Ident) -> Result<(NodeId, Span), ResolutionError<'ra>> {
2874 let mut suggestion = None;
2875
2876 for i in (0..self.label_ribs.len()).rev() {
2877 let rib = &self.label_ribs[i];
2878
2879 if let RibKind::MacroDefinition(def) = rib.kind
2880 && def == self.r.macro_def(label.span.ctxt())
2883 {
2884 label.span.remove_mark();
2885 }
2886
2887 let ident = label.normalize_to_macro_rules();
2888 if let Some((ident, id)) = rib.bindings.get_key_value(&ident) {
2889 let definition_span = ident.span;
2890 return if self.is_label_valid_from_rib(i) {
2891 Ok((*id, definition_span))
2892 } else {
2893 Err(ResolutionError::UnreachableLabel {
2894 name: label.name,
2895 definition_span,
2896 suggestion,
2897 })
2898 };
2899 }
2900
2901 suggestion = suggestion.or_else(|| self.suggestion_for_label_in_rib(i, label));
2904 }
2905
2906 Err(ResolutionError::UndeclaredLabel { name: label.name, suggestion })
2907 }
2908
2909 fn is_label_valid_from_rib(&self, rib_index: usize) -> bool {
2911 let ribs = &self.label_ribs[rib_index + 1..];
2912 ribs.iter().all(|rib| !rib.kind.is_label_barrier())
2913 }
2914
2915 fn resolve_adt(&mut self, item: &'ast Item, generics: &'ast Generics) {
2916 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:2916",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(2916u32),
::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");
2917 let kind = self.r.tcx.def_kind(self.r.current_owner.def_id);
2918 self.with_current_self_item(item, |this| {
2919 this.with_generic_param_rib(
2920 &generics.params,
2921 RibKind::Item(HasGenericParams::Yes(generics.span), kind),
2922 item.id,
2923 LifetimeBinderKind::Item,
2924 generics.span,
2925 |this| {
2926 let item_def_id = this.r.current_owner.def_id.to_def_id();
2927 this.with_self_rib(
2928 Res::SelfTyAlias { alias_to: item_def_id, is_trait_impl: false },
2929 |this| {
2930 visit::walk_item(this, item);
2931 },
2932 );
2933 },
2934 );
2935 });
2936 }
2937
2938 fn future_proof_import(&mut self, use_tree: &UseTree) {
2939 if let [segment, rest @ ..] = use_tree.prefix.segments.as_slice() {
2940 let ident = segment.ident;
2941 if ident.is_path_segment_keyword() || ident.span.is_rust_2015() {
2942 return;
2943 }
2944
2945 let nss = match use_tree.kind {
2946 UseTreeKind::Simple(..) if rest.is_empty() => &[TypeNS, ValueNS][..],
2947 _ => &[TypeNS],
2948 };
2949 let report_error = |this: &Self, ns| {
2950 if this.should_report_errs() {
2951 let what = if ns == TypeNS { "type parameters" } else { "local variables" };
2952 this.r.dcx().emit_err(crate::diagnostics::ImportsCannotReferTo {
2953 span: ident.span,
2954 what,
2955 });
2956 }
2957 };
2958
2959 for &ns in nss {
2960 match self.maybe_resolve_ident_in_lexical_scope(ident, ns) {
2961 Some(LateDecl::RibDef(..)) => {
2962 report_error(self, ns);
2963 }
2964 Some(LateDecl::Decl(binding)) => {
2965 if let Some(LateDecl::RibDef(..)) =
2966 self.resolve_ident_in_lexical_scope(ident, ns, None, Some(binding))
2967 {
2968 report_error(self, ns);
2969 }
2970 }
2971 None => {}
2972 }
2973 }
2974 } else if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
2975 for use_tree in items {
2976 self.future_proof_import(&use_tree.inner);
2977 }
2978 }
2979 }
2980
2981 fn resolve_item(&mut self, item: &'ast Item) {
2982 let mut mod_inner_attrs_start = None;
2983 match item.kind {
2984 ItemKind::Mod(..) => {
2985 let attrs = if let Some(pos) = item.attrs.iter().position(|a| {
2988 a.doc_resolution_scope().is_some_and(|style| style == AttrStyle::Inner)
2989 || #[allow(non_exhaustive_omitted_patterns)] match a.kind {
AttrKind::Normal(ref n) if
n.item.name() == Some(sym::deprecated) && a.style == AttrStyle::Inner
=> true,
_ => false,
}matches!(
2990 a.kind,
2991 AttrKind::Normal(ref n)
2992 if n.item.name() == Some(sym::deprecated) && a.style == AttrStyle::Inner)
2993 }) {
2994 mod_inner_attrs_start = Some(pos);
2995 &item.attrs[..pos]
2996 } else {
2997 &item.attrs
2998 };
2999 self.resolve_doc_links(attrs, MaybeExported::Ok(item.id));
3000 }
3001 ItemKind::Impl(..) | ItemKind::Use(..) => {}
3002 _ => {
3003 self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
3004 }
3005 }
3006
3007 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3007",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3007u32),
::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);
3008
3009 let def_kind = self.r.tcx.def_kind(self.r.current_owner.def_id);
3010
3011 self.check_for_lang(
3012 Target::from_ast_item(item),
3013 self.r.current_owner.def_id,
3014 &item.attrs,
3015 item.span,
3016 item.opt_generics(),
3017 );
3018
3019 match &item.kind {
3020 ItemKind::TyAlias(TyAlias { generics, .. }) => {
3021 self.with_generic_param_rib(
3022 &generics.params,
3023 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
3024 item.id,
3025 LifetimeBinderKind::Item,
3026 generics.span,
3027 |this| visit::walk_item(this, item),
3028 );
3029 }
3030
3031 ItemKind::Fn(Fn { generics, define_opaque, sig, .. }) => {
3032 self.with_const_and_generic_param_rib(
3033 &generics.params,
3034 &sig.decl.inputs,
3035 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
3036 item.id,
3037 LifetimeBinderKind::Function,
3038 generics.span,
3039 |this| visit::walk_item(this, item),
3040 );
3041 self.resolve_define_opaques(define_opaque);
3042 }
3043
3044 ItemKind::Enum(_, generics, _)
3045 | ItemKind::Struct(_, generics, _)
3046 | ItemKind::Union(_, generics, _) => {
3047 self.resolve_adt(item, generics);
3048 }
3049
3050 ItemKind::Impl(Impl { generics, of_trait, self_ty, items: impl_items, .. }) => {
3051 self.diag_metadata.current_impl_items = Some(impl_items);
3052 self.resolve_implementation(
3053 &item.attrs,
3054 generics,
3055 of_trait.as_deref(),
3056 self_ty,
3057 item.id,
3058 impl_items,
3059 );
3060 self.diag_metadata.current_impl_items = None;
3061 }
3062
3063 ItemKind::Trait(Trait { generics, bounds, items, impl_restriction, .. }) => {
3064 self.resolve_restriction_path(&impl_restriction.kind);
3066
3067 self.with_generic_param_rib(
3069 &generics.params,
3070 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
3071 item.id,
3072 LifetimeBinderKind::Item,
3073 generics.span,
3074 |this| {
3075 let local_def_id = this.r.current_owner.def_id.to_def_id();
3076 this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
3077 this.visit_generics(generics);
3078 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);
3079 this.resolve_trait_items(items);
3080 });
3081 },
3082 );
3083 }
3084
3085 ItemKind::TraitAlias(TraitAlias { generics, bounds, .. }) => {
3086 self.with_generic_param_rib(
3088 &generics.params,
3089 RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
3090 item.id,
3091 LifetimeBinderKind::Item,
3092 generics.span,
3093 |this| {
3094 let local_def_id = this.r.current_owner.def_id.to_def_id();
3095 this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
3096 this.visit_generics(generics);
3097 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);
3098 });
3099 },
3100 );
3101 }
3102
3103 ItemKind::Mod(..) => {
3104 let module = self.r.expect_module(self.r.current_owner.def_id.to_def_id());
3105 let orig_module = replace(&mut self.parent_scope.module, module);
3106 self.with_rib(ValueNS, RibKind::Module(module.expect_local()), |this| {
3107 this.with_rib(TypeNS, RibKind::Module(module.expect_local()), |this| {
3108 let attrs = if let Some(pos) = mod_inner_attrs_start {
3111 &item.attrs[pos..]
3112 } else {
3113 &[]
3114 };
3115 this.resolve_doc_links(attrs, MaybeExported::Ok(item.id));
3116 let old_macro_rules = this.parent_scope.macro_rules;
3117 visit::walk_item(this, item);
3118 if item.attrs.iter().all(|attr| {
3121 !attr.has_name(sym::macro_use) && !attr.has_name(sym::macro_escape)
3122 }) {
3123 this.parent_scope.macro_rules = old_macro_rules;
3124 }
3125 })
3126 });
3127 self.parent_scope.module = orig_module;
3128 }
3129
3130 ItemKind::Static(ast::StaticItem {
3131 ident, ty, expr, define_opaque, eii_impl, ..
3132 }) => {
3133 self.with_static_rib(def_kind, |this| {
3134 this.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Static), |this| {
3135 this.visit_ty(ty);
3136 });
3137 if let Some(expr) = expr {
3138 this.resolve_static_body(expr, Some((*ident, ConstantItemKind::Static)));
3141 }
3142 });
3143 self.resolve_define_opaques(define_opaque);
3144 self.resolve_eii(eii_impl.as_deref());
3145 }
3146
3147 ItemKind::Const(ast::ConstItem {
3148 ident,
3149 generics,
3150 ty,
3151 body,
3152 define_opaque,
3153 defaultness: _,
3154 }) => {
3155 self.with_generic_param_rib(
3156 &generics.params,
3157 RibKind::Item(
3158 if self.r.features.generic_const_items() {
3159 HasGenericParams::Yes(generics.span)
3160 } else {
3161 HasGenericParams::No
3162 },
3163 def_kind,
3164 ),
3165 item.id,
3166 LifetimeBinderKind::ConstItem,
3167 generics.span,
3168 |this| {
3169 this.visit_generics(generics);
3170
3171 this.with_lifetime_rib(
3172 LifetimeRibKind::elided(LifetimeRes::Static),
3173 |this: &mut LateResolutionVisitor<'a, 'ast, 'ra, 'tcx>| {
3174 this.visit_ty(ty)
3175 },
3176 );
3177
3178 this.resolve_const_item_rhs(body, Some((*ident, ConstantItemKind::Const)));
3179 },
3180 );
3181 self.resolve_define_opaques(define_opaque);
3182 }
3183 ItemKind::ConstBlock(ConstBlockItem { id: _, span: _, block }) => self
3184 .with_generic_param_rib(
3185 &[],
3186 RibKind::Item(HasGenericParams::No, def_kind),
3187 item.id,
3188 LifetimeBinderKind::ConstItem,
3189 DUMMY_SP,
3190 |this| {
3191 this.with_lifetime_rib(
3192 LifetimeRibKind::elided(LifetimeRes::Infer),
3193 |this| {
3194 this.with_constant_rib(
3195 IsRepeatExpr::No,
3196 ConstantHasGenerics::Yes,
3197 ConstantRequiresType::No,
3198 Some((ConstBlockItem::IDENT, ConstantItemKind::Const)),
3199 |this| this.resolve_labeled_block(None, block.id, block),
3200 )
3201 },
3202 );
3203 },
3204 ),
3205
3206 ItemKind::Use(use_tree) => {
3207 self.use_items.push(item);
3208 let maybe_exported = match use_tree.kind {
3209 UseTreeKind::Simple(_) | UseTreeKind::Glob(_) => MaybeExported::Ok(item.id),
3210 UseTreeKind::Nested { .. } => MaybeExported::NestedUse(&item.vis),
3211 };
3212 self.resolve_doc_links(&item.attrs, maybe_exported);
3213
3214 self.future_proof_import(use_tree);
3215 }
3216
3217 ItemKind::MacroDef(_, macro_def) => {
3218 if macro_def.macro_rules {
3221 let def_id = self.r.current_owner.def_id;
3222 self.parent_scope.macro_rules = self.r.macro_rules_scopes[&def_id];
3223 }
3224
3225 if let Some(EiiDecl { foreign_item: extern_item_path, impl_unsafe: _ }) =
3226 ¯o_def.eii_declaration
3227 {
3228 self.smart_resolve_path(
3229 item.id,
3230 &None,
3231 extern_item_path,
3232 PathSource::ExternItemImpl,
3233 );
3234 }
3235 }
3236
3237 ItemKind::ForeignMod(_) | ItemKind::GlobalAsm(_) => {
3238 visit::walk_item(self, item);
3239 }
3240
3241 ItemKind::Delegation(delegation) => {
3242 let span = delegation.path.segments.last().unwrap().ident.span;
3243 self.with_generic_param_rib(
3244 &[],
3245 RibKind::Item(HasGenericParams::Yes(span), def_kind),
3246 item.id,
3247 LifetimeBinderKind::Function,
3248 span,
3249 |this| this.resolve_delegation(delegation, item.id, false),
3250 );
3251 }
3252
3253 ItemKind::ExternCrate(..) => self.use_items.push(item),
3254
3255 ItemKind::MacCall(_) | ItemKind::DelegationMac(..) => {
3256 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
3257 }
3258
3259 ItemKind::TestBinderConstraints(constraints) => {
3260 self.resolve_test_binder_constraints(constraints, item.id);
3261 }
3262 }
3263 }
3264
3265 fn with_const_and_generic_param_rib<F>(
3268 &mut self,
3269 params: &[GenericParam],
3270 fn_inputs: &[Param],
3271 kind: RibKind<'ra>,
3272 binder: NodeId,
3273 generics_kind: LifetimeBinderKind,
3274 generics_span: Span,
3275 f: F,
3276 ) where
3277 F: FnOnce(&mut Self),
3278 {
3279 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3279",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3279u32),
::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");
3280 let lifetime_kind =
3281 LifetimeRibKind::Generics { binder, span: generics_span, kind: generics_kind };
3282
3283 let mut function_type_rib = Rib::new(kind);
3284 let mut function_value_rib = Rib::new(kind);
3285 let mut function_lifetime_rib = LifetimeRib::new(lifetime_kind);
3286
3287 let const_params =
3288 fn_inputs.iter().filter(|param| param.is_const_param()).collect::<Vec<_>>();
3289
3290 if !params.is_empty() || !const_params.is_empty() {
3292 let mut seen_bindings = FxHashMap::default();
3293 let mut seen_lifetimes = FxHashSet::default();
3295
3296 for ns in [ValueNS, TypeNS] {
3298 for parent_rib in self.ribs[ns].iter().rev() {
3299 if #[allow(non_exhaustive_omitted_patterns)] match parent_rib.kind {
RibKind::Module(..) | RibKind::Block(..) => true,
_ => false,
}matches!(parent_rib.kind, RibKind::Module(..) | RibKind::Block(..)) {
3302 break;
3303 }
3304
3305 seen_bindings
3306 .extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
3307 }
3308 }
3309
3310 for rib in self.lifetime_ribs.iter().rev() {
3312 seen_lifetimes.extend(rib.bindings.iter().map(|(ident, _)| *ident));
3313 if let LifetimeRibKind::Item = rib.kind {
3314 break;
3315 }
3316 }
3317
3318 for param in params {
3319 let ident = param.ident.normalize_to_macros_2_0();
3320 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3320",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3320u32),
::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);
3321
3322 if let GenericParamKind::Lifetime = param.kind
3323 && let Some(&original) = seen_lifetimes.get(&ident)
3324 {
3325 let guar = diagnostics::signal_lifetime_shadowing(
3326 self.r.tcx.sess,
3327 original,
3328 param.ident,
3329 );
3330 self.record_lifetime_err(param.id, guar);
3332 continue;
3333 }
3334
3335 match seen_bindings.entry(ident) {
3336 Entry::Occupied(entry) => {
3337 let span = *entry.get();
3338 let err = ResolutionError::NameAlreadyUsedInParameterList(ident, span);
3339 let guar = self.r.report_error(param.ident.span, err);
3340 let rib = match param.kind {
3341 GenericParamKind::Lifetime => {
3342 self.record_lifetime_err(param.id, guar);
3344 continue;
3345 }
3346 GenericParamKind::Type { .. } => &mut function_type_rib,
3347 GenericParamKind::Const { .. } => &mut function_value_rib,
3348 };
3349
3350 self.r.record_partial_res(param.id, PartialRes::new(Res::Err));
3352 rib.bindings.insert(ident, Res::Err);
3353 continue;
3354 }
3355 Entry::Vacant(entry) => {
3356 entry.insert(param.ident.span);
3357 }
3358 }
3359
3360 if param.ident.name == kw::UnderscoreLifetime {
3361 let is_raw_underscore_lifetime = self
3364 .r
3365 .tcx
3366 .sess
3367 .psess
3368 .raw_identifier_spans
3369 .iter()
3370 .any(|span| span == param.span());
3371
3372 let guar = self
3373 .r
3374 .dcx()
3375 .create_err(crate::diagnostics::UnderscoreLifetimeIsReserved {
3376 span: param.ident.span,
3377 })
3378 .emit_err_unless_delay(is_raw_underscore_lifetime);
3379 self.record_lifetime_err(param.id, guar);
3381 continue;
3382 }
3383
3384 if param.ident.name == kw::StaticLifetime {
3385 let guar =
3386 self.r.dcx().emit_err(crate::diagnostics::StaticLifetimeIsReserved {
3387 span: param.ident.span,
3388 lifetime: param.ident,
3389 });
3390 self.record_lifetime_err(param.id, guar);
3392 continue;
3393 }
3394
3395 let def_id = self.r.local_def_id(param.id);
3396
3397 let (rib, def_kind) = match param.kind {
3399 GenericParamKind::Type { .. } => (&mut function_type_rib, DefKind::TyParam),
3400 GenericParamKind::Const { .. } => {
3401 (&mut function_value_rib, DefKind::ConstParam)
3402 }
3403 GenericParamKind::Lifetime => {
3404 let res = LifetimeRes::Param { param: def_id, binder };
3405 self.record_lifetime_def(param.id, res);
3406 function_lifetime_rib.bindings.insert(ident, (param.id, res));
3407 continue;
3408 }
3409 };
3410
3411 let res = match kind {
3412 RibKind::Item(..) | RibKind::AssocItem => {
3413 Res::Def(def_kind, def_id.to_def_id())
3414 }
3415 RibKind::Normal => {
3416 if self.r.features.non_lifetime_binders()
3419 && #[allow(non_exhaustive_omitted_patterns)] match param.kind {
GenericParamKind::Type { .. } => true,
_ => false,
}matches!(param.kind, GenericParamKind::Type { .. })
3420 {
3421 Res::Def(def_kind, def_id.to_def_id())
3422 } else {
3423 Res::Err
3424 }
3425 }
3426 _ => ::rustc_span::macros::bug_impl(Some(param.ident.span),
format_args!("Unexpected rib kind {0:?}", kind), Location::caller())span_bug!(param.ident.span, "Unexpected rib kind {:?}", kind),
3427 };
3428 self.r.record_partial_res(param.id, PartialRes::new(res));
3429 rib.bindings.insert(ident, res);
3430 }
3431
3432 for param in const_params {
3433 let const_ident = param.const_param_ident().unwrap();
3434 let ident = const_ident.normalize_to_macros_2_0();
3435 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3435",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3435u32),
::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);
3436
3437 match seen_bindings.entry(ident) {
3438 Entry::Occupied(entry) => {
3439 let span = *entry.get();
3440 let err = ResolutionError::NameAlreadyUsedInParameterList(ident, span);
3441 self.r.report_error(const_ident.span, err);
3442 self.r.record_partial_res(param.id, PartialRes::new(Res::Err));
3444 function_value_rib.bindings.insert(ident, Res::Err);
3445 continue;
3446 }
3447 Entry::Vacant(entry) => {
3448 entry.insert(const_ident.span);
3449 }
3450 }
3451 let def_id = self.r.local_def_id(param.id);
3452 let res = match kind {
3453 RibKind::Item(..) | RibKind::AssocItem => {
3454 Res::Def(DefKind::ConstParam, def_id.to_def_id())
3455 }
3456 _ => ::rustc_span::macros::bug_impl(Some(const_ident.span),
format_args!("Unexpected rib kind {0:?}", kind), Location::caller())span_bug!(const_ident.span, "Unexpected rib kind {:?}", kind),
3457 };
3458 self.r.record_partial_res(param.id, PartialRes::new(res));
3459 function_value_rib.bindings.insert(ident, res);
3460 }
3461 }
3462
3463 self.lifetime_ribs.push(function_lifetime_rib);
3464 self.ribs[ValueNS].push(function_value_rib);
3465 self.ribs[TypeNS].push(function_type_rib);
3466
3467 f(self);
3468
3469 self.ribs[TypeNS].pop();
3470 self.ribs[ValueNS].pop();
3471 let function_lifetime_rib = self.lifetime_ribs.pop().unwrap();
3472
3473 if let Some(ref mut candidates) = self.lifetime_elision_candidates {
3475 for (_, res) in function_lifetime_rib.bindings.values() {
3476 candidates.retain(|(r, _)| r != res);
3477 }
3478 }
3479
3480 if let LifetimeBinderKind::FnPtrType
3481 | LifetimeBinderKind::WhereBound
3482 | LifetimeBinderKind::Function
3483 | LifetimeBinderKind::ImplBlock = generics_kind
3484 {
3485 self.maybe_report_lifetime_uses(generics_span, params)
3486 }
3487 }
3488
3489 fn with_generic_param_rib<F>(
3490 &mut self,
3491 params: &[GenericParam],
3492 kind: RibKind<'ra>,
3493 binder: NodeId,
3494 generics_kind: LifetimeBinderKind,
3495 generics_span: Span,
3496 f: F,
3497 ) where
3498 F: FnOnce(&mut Self),
3499 {
3500 self.with_const_and_generic_param_rib(
3501 params,
3502 &[],
3503 kind,
3504 binder,
3505 generics_kind,
3506 generics_span,
3507 f,
3508 );
3509 }
3510
3511 fn with_label_rib(&mut self, kind: RibKind<'ra>, f: impl FnOnce(&mut Self)) {
3512 self.label_ribs.push(Rib::new(kind));
3513 f(self);
3514 self.label_ribs.pop();
3515 }
3516
3517 fn with_static_rib(&mut self, def_kind: DefKind, f: impl FnOnce(&mut Self)) {
3518 let kind = RibKind::Item(HasGenericParams::No, def_kind);
3519 self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
3520 }
3521
3522 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3530u32),
::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))]
3531 fn with_constant_rib(
3532 &mut self,
3533 is_repeat: IsRepeatExpr,
3534 may_use_generics: ConstantHasGenerics,
3535 requires_type: ConstantRequiresType,
3536 item: Option<(Ident, ConstantItemKind)>,
3537 f: impl FnOnce(&mut Self),
3538 ) {
3539 let f = |this: &mut Self| {
3540 this.with_rib(
3541 ValueNS,
3542 RibKind::ConstantItem(may_use_generics, item, requires_type),
3543 |this| {
3544 this.with_rib(
3545 TypeNS,
3546 RibKind::ConstantItem(
3547 may_use_generics.force_yes_if(is_repeat == IsRepeatExpr::Yes),
3548 item,
3549 requires_type,
3550 ),
3551 |this| {
3552 this.with_label_rib(
3553 RibKind::ConstantItem(may_use_generics, item, requires_type),
3554 f,
3555 );
3556 },
3557 )
3558 },
3559 )
3560 };
3561
3562 if let ConstantHasGenerics::No(cause) = may_use_generics {
3563 self.with_lifetime_rib(LifetimeRibKind::ConcreteAnonConst(cause), f)
3564 } else {
3565 f(self)
3566 }
3567 }
3568
3569 fn with_current_self_type<T>(
3570 &mut self,
3571 self_type: &'ast Ty,
3572 f: impl FnOnce(&mut Self) -> T,
3573 ) -> T {
3574 let previous_value = replace(&mut self.diag_metadata.current_self_type, Some(self_type));
3576 let result = f(self);
3577 self.diag_metadata.current_self_type = previous_value;
3578 result
3579 }
3580
3581 fn with_current_self_item<T>(&mut self, self_item: &Item, f: impl FnOnce(&mut Self) -> T) -> T {
3582 let previous_value = replace(&mut self.diag_metadata.current_self_item, Some(self_item.id));
3583 let result = f(self);
3584 self.diag_metadata.current_self_item = previous_value;
3585 result
3586 }
3587
3588 fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) {
3590 let trait_assoc_items =
3591 replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
3592
3593 for item in trait_items {
3594 with_owner(self, item.id, |this| this.resolve_trait_item(item));
3595 }
3596
3597 self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
3598 }
3599
3600 fn resolve_trait_item(&mut self, item: &'ast Item<AssocItemKind>) {
3601 let walk_assoc_item = |this: &mut Self,
3602 generics: &Generics,
3603 kind,
3604 item: &'ast AssocItem,
3605 fn_inputs: &[Param]| {
3606 this.with_const_and_generic_param_rib(
3607 &generics.params,
3608 fn_inputs,
3609 RibKind::AssocItem,
3610 item.id,
3611 kind,
3612 generics.span,
3613 |this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
3614 );
3615 };
3616
3617 self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
3618 self.check_for_lang(
3619 Target::from_assoc_item_kind(&item.kind, AssocCtxt::Trait),
3620 self.r.current_owner.def_id,
3621 &item.attrs,
3622 item.span,
3623 item.opt_generics(),
3624 );
3625 match &item.kind {
3626 AssocItemKind::Const(ast::ConstItem { generics, ty, body, define_opaque, .. }) => {
3627 self.with_generic_param_rib(
3628 &generics.params,
3629 RibKind::AssocItem,
3630 item.id,
3631 LifetimeBinderKind::ConstItem,
3632 generics.span,
3633 |this| {
3634 this.with_lifetime_rib(
3635 LifetimeRibKind::Elided {
3636 res: LifetimeRes::Static,
3637 error_in_path: true,
3638 },
3639 |this| {
3640 this.visit_generics(generics);
3641 this.visit_ty(ty);
3642 this.resolve_const_item_rhs(body, None);
3651 },
3652 )
3653 },
3654 );
3655
3656 self.resolve_define_opaques(define_opaque);
3657 }
3658 AssocItemKind::Fn(Fn { generics, define_opaque, sig, .. }) => {
3659 walk_assoc_item(
3660 self,
3661 generics,
3662 LifetimeBinderKind::Function,
3663 item,
3664 &sig.decl.inputs,
3665 );
3666
3667 self.resolve_define_opaques(define_opaque);
3668 }
3669 AssocItemKind::Delegation(delegation) => {
3670 self.with_generic_param_rib(
3671 &[],
3672 RibKind::AssocItem,
3673 item.id,
3674 LifetimeBinderKind::Function,
3675 delegation.path.segments.last().unwrap().ident.span,
3676 |this| this.resolve_delegation(delegation, item.id, false),
3677 );
3678 }
3679 AssocItemKind::Type(TyAlias { generics, .. }) => self
3680 .with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
3681 walk_assoc_item(this, generics, LifetimeBinderKind::Item, item, &[])
3682 }),
3683 AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
3684 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
3685 }
3686 };
3687 }
3688
3689 fn with_optional_trait_ref<T>(
3691 &mut self,
3692 opt_trait_ref: Option<&'ast TraitRef>,
3693 self_type: &'ast Ty,
3694 f: impl FnOnce(&mut Self, Option<DefId>) -> T,
3695 ) -> T {
3696 let mut new_val = None;
3697 let mut new_id = None;
3698 if let Some(trait_ref) = opt_trait_ref {
3699 let path: Vec<_> = Segment::from_path(&trait_ref.path);
3700 self.diag_metadata.currently_processing_impl_trait = Some((trait_ref, self_type));
3701 let res = self.smart_resolve_path_fragment(
3702 &None,
3703 &path,
3704 PathSource::Trait(AliasPossibility::No),
3705 Finalize::new(trait_ref.ref_id, trait_ref.path.span),
3706 RecordPartialRes::Yes,
3707 None,
3708 );
3709 self.diag_metadata.currently_processing_impl_trait = None;
3710 if let Some(def_id) = res.expect_full_res().opt_def_id() {
3711 new_id = Some(def_id);
3712 new_val = Some((self.r.expect_module(def_id), trait_ref));
3713 }
3714 }
3715 let original_trait_ref = replace(&mut self.current_trait_ref, new_val);
3716 let result = f(self, new_id);
3717 self.current_trait_ref = original_trait_ref;
3718 result
3719 }
3720
3721 fn with_self_rib_ns(&mut self, ns: Namespace, self_res: Res, f: impl FnOnce(&mut Self)) {
3722 let mut self_type_rib = Rib::new(RibKind::Normal);
3723
3724 self_type_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), self_res);
3726 self.ribs[ns].push(self_type_rib);
3727 f(self);
3728 self.ribs[ns].pop();
3729 }
3730
3731 fn with_self_rib(&mut self, self_res: Res, f: impl FnOnce(&mut Self)) {
3732 self.with_self_rib_ns(TypeNS, self_res, f)
3733 }
3734
3735 fn resolve_implementation(
3736 &mut self,
3737 attrs: &[ast::Attribute],
3738 generics: &'ast Generics,
3739 of_trait: Option<&'ast ast::TraitImplHeader>,
3740 self_type: &'ast Ty,
3741 item_id: NodeId,
3742 impl_items: &'ast [Box<AssocItem>],
3743 ) {
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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3744",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/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")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation");
3745 self.with_generic_param_rib(
3747 &generics.params,
3748 RibKind::Item(HasGenericParams::Yes(generics.span), self.r.tcx.def_kind(self.r.current_owner.def_id)),
3749 item_id,
3750 LifetimeBinderKind::ImplBlock,
3751 generics.span,
3752 |this| {
3753 this.with_self_rib(Res::SelfTyParam { trait_: LOCAL_CRATE.as_def_id() }, |this| {
3755 this.with_lifetime_rib(
3756 LifetimeRibKind::AnonymousCreateParameter {
3757 binder: item_id,
3758 report_in_path: true
3759 },
3760 |this| {
3761 this.with_optional_trait_ref(
3763 of_trait.map(|t| &t.trait_ref),
3764 self_type,
3765 |this, trait_id| {
3766 this.resolve_doc_links(attrs, MaybeExported::Impl(trait_id));
3767
3768 let item_def_id = this.r.current_owner.def_id;
3769
3770 if let Some(trait_id) = trait_id {
3772 this.r
3773 .trait_impls
3774 .entry(trait_id)
3775 .or_default()
3776 .push(item_def_id);
3777 }
3778
3779 let item_def_id = item_def_id.to_def_id();
3780 let res = Res::SelfTyAlias {
3781 alias_to: item_def_id,
3782 is_trait_impl: trait_id.is_some(),
3783 };
3784 this.with_self_rib(res, |this| {
3785 if let Some(of_trait) = of_trait {
3786 visit::walk_trait_ref(this, &of_trait.trait_ref);
3788 }
3789 this.visit_ty(self_type);
3791 this.visit_generics(generics);
3793
3794 this.with_current_self_type(self_type, |this| {
3796 this.with_self_rib_ns(ValueNS, Res::SelfCtor(item_def_id), |this| {
3797 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3797",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3797u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::late"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_implementation with_self_rib_ns(ValueNS, ...)")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_implementation with_self_rib_ns(ValueNS, ...)");
3798 let mut seen_trait_items = Default::default();
3799 for item in impl_items {
3800 with_owner(this, item.id, |this| {
3801 this.resolve_impl_item(
3802 &**item,
3803 &mut seen_trait_items,
3804 trait_id,
3805 of_trait.is_some(),
3806 self_type.id,
3807 );
3808 })
3809 }
3810 });
3811 });
3812 });
3813 },
3814 )
3815 },
3816 );
3817 });
3818 },
3819 );
3820 }
3821
3822 fn resolve_test_binder_constraints(
3823 &mut self,
3824 constraints: &'ast TestBinderConstraints,
3825 item_id: NodeId,
3826 ) {
3827 let generics = &constraints.generics;
3828 self.with_generic_param_rib(
3829 &generics.params,
3830 RibKind::Item(
3831 HasGenericParams::Yes(generics.span),
3832 self.r.tcx.def_kind(self.r.current_owner.def_id),
3833 ),
3834 item_id,
3835 LifetimeBinderKind::ImplBlock,
3836 generics.span,
3837 |this| {
3838 this.visit_generics(generics);
3839 this.visit_test_binder_body(&constraints.body);
3840 },
3841 );
3842 }
3843
3844 fn resolve_impl_item(
3845 &mut self,
3846 item: &'ast AssocItem,
3847 seen_trait_items: &mut FxHashMap<DefId, Span>,
3848 trait_id: Option<DefId>,
3849 is_in_trait_impl: bool,
3850 self_type_id: NodeId,
3851 ) {
3852 use crate::ResolutionError::*;
3853 self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis)));
3854 let prev = self.diag_metadata.current_impl_item.take();
3855 self.diag_metadata.current_impl_item = Some(&item);
3856 self.check_for_lang(
3857 Target::from_assoc_item_kind(
3858 &item.kind,
3859 AssocCtxt::Impl { of_trait: is_in_trait_impl },
3860 ),
3861 self.r.current_owner.def_id,
3862 &item.attrs,
3863 item.span,
3864 item.opt_generics(),
3865 );
3866 match &item.kind {
3867 AssocItemKind::Const(ast::ConstItem {
3868 ident,
3869 generics,
3870 ty,
3871 body,
3872 define_opaque,
3873 ..
3874 }) => {
3875 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3875",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3875u32),
::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");
3876 self.with_generic_param_rib(
3877 &generics.params,
3878 RibKind::AssocItem,
3879 item.id,
3880 LifetimeBinderKind::ConstItem,
3881 generics.span,
3882 |this| {
3883 this.with_lifetime_rib(
3884 LifetimeRibKind::Elided {
3885 res: LifetimeRes::Static,
3886 error_in_path: true,
3887 },
3888 |this| {
3889 this.check_trait_item(
3892 item.id,
3893 *ident,
3894 *ident,
3895 &item.kind,
3896 ValueNS,
3897 item.span,
3898 seen_trait_items,
3899 |i, s, c| ConstNotMemberOfTrait(i, s, c),
3900 );
3901
3902 this.visit_generics(generics);
3903 this.visit_ty(ty);
3904 this.resolve_const_item_rhs(body, None);
3910 },
3911 )
3912 },
3913 );
3914 self.resolve_define_opaques(define_opaque);
3915 }
3916 AssocItemKind::Fn(fn_kind @ Fn { ident, generics, define_opaque, sig, .. }) => {
3917 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3917",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3917u32),
::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");
3918 self.with_const_and_generic_param_rib(
3920 &generics.params,
3921 &sig.decl.inputs,
3922 RibKind::AssocItem,
3923 item.id,
3924 LifetimeBinderKind::Function,
3925 generics.span,
3926 |this| {
3927 let effective_ident = if is_in_trait_impl && fn_kind.is_pin_drop_sugar() {
3928 Ident::new(sym::pin_drop, ident.span)
3929 } else {
3930 *ident
3931 };
3932 this.check_trait_item(
3935 item.id,
3936 effective_ident,
3937 *ident,
3938 &item.kind,
3939 ValueNS,
3940 item.span,
3941 seen_trait_items,
3942 |i, s, c| MethodNotMemberOfTrait(i, s, c),
3943 );
3944
3945 visit::walk_assoc_item(this, item, AssocCtxt::Impl { of_trait: true })
3946 },
3947 );
3948
3949 if !is_in_trait_impl {
3950 self.fill_delegation_inherent_fn_map(self_type_id, ident);
3951 }
3952
3953 self.resolve_define_opaques(define_opaque);
3954 }
3955 AssocItemKind::Type(TyAlias { ident, generics, .. }) => {
3956 self.diag_metadata.in_non_gat_assoc_type = Some(generics.params.is_empty());
3957 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3957",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3957u32),
::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");
3958 self.with_generic_param_rib(
3960 &generics.params,
3961 RibKind::AssocItem,
3962 item.id,
3963 LifetimeBinderKind::ImplAssocType,
3964 generics.span,
3965 |this| {
3966 this.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
3967 this.check_trait_item(
3970 item.id,
3971 *ident,
3972 *ident,
3973 &item.kind,
3974 TypeNS,
3975 item.span,
3976 seen_trait_items,
3977 |i, s, c| TypeNotMemberOfTrait(i, s, c),
3978 );
3979
3980 visit::walk_assoc_item(this, item, AssocCtxt::Impl { of_trait: true })
3981 });
3982 },
3983 );
3984 self.diag_metadata.in_non_gat_assoc_type = None;
3985 }
3986 AssocItemKind::Delegation(delegation) => {
3987 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:3987",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(3987u32),
::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");
3988 self.with_generic_param_rib(
3989 &[],
3990 RibKind::AssocItem,
3991 item.id,
3992 LifetimeBinderKind::Function,
3993 delegation.path.segments.last().unwrap().ident.span,
3994 |this| {
3995 if !is_in_trait_impl {
3996 this.fill_delegation_inherent_fn_map(
3997 self_type_id,
3998 &delegation.ident,
4000 );
4001 }
4002
4003 this.check_trait_item(
4004 item.id,
4005 delegation.ident,
4006 delegation.ident,
4007 &item.kind,
4008 ValueNS,
4009 item.span,
4010 seen_trait_items,
4011 |i, s, c| MethodNotMemberOfTrait(i, s, c),
4012 );
4013
4014 this.resolve_delegation(delegation, item.id, is_in_trait_impl);
4017 },
4018 );
4019 }
4020 AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
4021 {
::core::panicking::panic_fmt(format_args!("unexpanded macro in resolve!"));
}panic!("unexpanded macro in resolve!")
4022 }
4023 }
4024 self.diag_metadata.current_impl_item = prev;
4025 }
4026
4027 fn fill_delegation_inherent_fn_map(&mut self, self_type_id: NodeId, ident: &Ident) {
4033 let res = self.r.partial_res_map.get(&self_type_id);
4034
4035 let Some(self_type_def_id) = res.and_then(|res| {
4036 res.full_res().and_then(|r| r.opt_def_id()).and_then(|id| id.as_local())
4037 }) else {
4038 return;
4039 };
4040
4041 let map = self.r.delegation_inherent_fn_map.entry(self_type_def_id).or_default();
4043
4044 match map.get(ident) {
4045 None => {
4046 map.insert(*ident, DelegationInherentFnKind::Single(self.r.current_owner.def_id));
4047 }
4048 Some(DelegationInherentFnKind::Single(..)) => {
4049 map.insert(*ident, DelegationInherentFnKind::Ambig);
4050 }
4051 _ => {}
4052 };
4053 }
4054
4055 fn check_trait_item<F>(
4056 &mut self,
4057 id: NodeId,
4058 mut ident: Ident,
4059 mut reported_ident: Ident,
4060 kind: &AssocItemKind,
4061 ns: Namespace,
4062 span: Span,
4063 seen_trait_items: &mut FxHashMap<DefId, Span>,
4064 err: F,
4065 ) where
4066 F: FnOnce(Ident, String, Option<Symbol>) -> ResolutionError<'ra>,
4067 {
4068 let Some((module, _)) = self.current_trait_ref else {
4070 return;
4071 };
4072 ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
4073 reported_ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
4074 let key = BindingKey::new(IdentKey::new(ident), ns);
4075 let mut decl = self.r.resolution(module, key).and_then(|r| r.best_decl());
4076 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:4076",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(4076u32),
::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);
4077 if decl.is_none() {
4078 let ns = match ns {
4081 ValueNS => TypeNS,
4082 TypeNS => ValueNS,
4083 _ => ns,
4084 };
4085 let key = BindingKey::new(IdentKey::new(ident), ns);
4086 decl = self.r.resolution(module, key).and_then(|r| r.best_decl());
4087 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:4087",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(4087u32),
::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);
4088 }
4089
4090 let feed_visibility = |this: &mut Self, def_id| {
4091 let vis = this.r.tcx.visibility(def_id);
4092 let vis = if vis.is_visible_locally() {
4093 vis.expect_local()
4094 } else {
4095 this.r.dcx().span_delayed_bug(
4096 span,
4097 "error should be emitted when an unexpected trait item is used",
4098 );
4099 Visibility::Public
4100 };
4101 this.r.tcx.feed_visibility_for_trait_impl_item(this.r.current_owner.def_id, vis);
4105 };
4106
4107 let Some(decl) = decl else {
4108 let candidate = self.find_similarly_named_assoc_item(reported_ident.name, kind);
4110 let path = &self.current_trait_ref.unwrap().1.path;
4111 let path_names = path_names_to_string(path);
4112 self.report_error(span, err(reported_ident, path_names, candidate));
4113 feed_visibility(self, module.def_id());
4114 return;
4115 };
4116
4117 let res = decl.res();
4118 let Res::Def(def_kind, id_in_trait) = res else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
Location::caller())bug!() };
4119 feed_visibility(self, id_in_trait);
4120
4121 match seen_trait_items.entry(id_in_trait) {
4122 Entry::Occupied(entry) => {
4123 let trait_span = decl.parent_module.unwrap().span.shrink_to_lo();
4124 let impl_span = self.current_trait_ref.unwrap().1.path.span;
4125 self.report_error(
4126 span,
4127 ResolutionError::TraitImplDuplicate {
4128 name: ident,
4129 old_span: *entry.get(),
4130 trait_item_span: decl.span,
4131 trait_span,
4132 impl_span,
4133 },
4134 );
4135 return;
4136 }
4137 Entry::Vacant(entry) => {
4138 entry.insert(span);
4139 }
4140 };
4141
4142 match (def_kind, kind) {
4143 (DefKind::AssocTy, AssocItemKind::Type(..))
4144 | (DefKind::AssocFn, AssocItemKind::Fn(..))
4145 | (DefKind::AssocConst, AssocItemKind::Const(..))
4146 | (DefKind::AssocFn, AssocItemKind::Delegation(..)) => {
4147 self.r.record_partial_res(id, PartialRes::new(res));
4148 return;
4149 }
4150 _ => {}
4151 }
4152
4153 let path = &self.current_trait_ref.unwrap().1.path;
4155 let (code, kind) = match kind {
4156 AssocItemKind::Const(..) => (E0323, "const"),
4157 AssocItemKind::Fn(..) => (E0324, "method"),
4158 AssocItemKind::Type(..) => (E0325, "type"),
4159 AssocItemKind::Delegation(..) => (E0324, "method"),
4160 AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
4161 ::rustc_span::macros::bug_impl(Some(span), format_args!("unexpanded macro"),
Location::caller())span_bug!(span, "unexpanded macro")
4162 }
4163 };
4164 let trait_path = path_names_to_string(path);
4165 let trait_span = decl.parent_module.unwrap().span.shrink_to_lo();
4166 let impl_span = self.current_trait_ref.unwrap().1.path.span;
4167 self.report_error(
4168 span,
4169 ResolutionError::TraitImplMismatch {
4170 name: ident,
4171 kind,
4172 code,
4173 trait_path,
4174 trait_item_span: decl.span,
4175 trait_span,
4176 impl_span,
4177 },
4178 );
4179 }
4180
4181 fn resolve_static_body(&mut self, expr: &'ast Expr, item: Option<(Ident, ConstantItemKind)>) {
4182 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4183 this.with_constant_rib(
4184 IsRepeatExpr::No,
4185 ConstantHasGenerics::Yes,
4186 ConstantRequiresType::No,
4187 item,
4188 |this| this.visit_expr(expr),
4189 );
4190 })
4191 }
4192
4193 fn resolve_const_item_rhs(
4194 &mut self,
4195 body: &'ast Option<Box<Expr>>,
4196 item: Option<(Ident, ConstantItemKind)>,
4197 ) {
4198 if let Some(body) = body {
4199 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4200 this.with_constant_rib(
4201 IsRepeatExpr::No,
4202 ConstantHasGenerics::Yes,
4203 ConstantRequiresType::No,
4204 item,
4205 |this| this.visit_expr(body),
4206 )
4207 })
4208 }
4209 }
4210
4211 fn resolve_delegation(
4212 &mut self,
4213 delegation: &'ast Delegation,
4214 item_id: NodeId,
4215 is_in_trait_impl: bool,
4216 ) {
4217 self.smart_resolve_path(
4218 delegation.id,
4219 &delegation.qself,
4220 &delegation.path,
4221 PathSource::Delegation,
4222 );
4223
4224 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4227 if let Some(qself) = &delegation.qself {
4228 this.visit_ty(&qself.ty);
4229 }
4230
4231 this.visit_path(&delegation.path);
4232 });
4233
4234 let resolution_node_id = if is_in_trait_impl { item_id } else { delegation.id };
4235 let resolution = self
4236 .r
4237 .partial_res_map
4238 .get(&resolution_node_id)
4239 .map(|r| match r.full_res().and_then(|r| r.opt_def_id()) {
4240 None => {
4241 if !!is_in_trait_impl {
::core::panicking::panic("assertion failed: !is_in_trait_impl")
};assert!(!is_in_trait_impl);
4243 DelegationResolution::Partial
4244 }
4245 Some(def_id) => {
4246 if is_in_trait_impl {
4250 let path_res = self.r.partial_res_map[&delegation.id];
4251
4252 if path_res.full_res().and_then(|r| r.opt_def_id()).is_none() {
4253 return DelegationResolution::PartialCall(def_id);
4254 }
4255 }
4256
4257 DelegationResolution::Full(def_id)
4258 }
4259 })
4260 .unwrap_or_else(|| {
4261 DelegationResolution::Error(self.r.tcx.dcx().span_delayed_bug(
4262 delegation.path.span,
4263 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("bad resolution for delegation {0:?}",
item_id))
})format!("bad resolution for delegation {item_id:?}"),
4264 ))
4265 });
4266
4267 let info = DelegationInfo { resolution };
4268 self.r.delegation_infos.insert(self.r.current_owner.def_id, info);
4269
4270 let Some(body) = &delegation.body else { return };
4271 self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
4272 let ident = Ident::new(kw::SelfLower, body.span.normalize_to_macro_rules());
4273 let res = Res::Local(delegation.id);
4274 this.innermost_rib_bindings(ValueNS).insert(ident, res);
4275
4276 this.with_label_rib(RibKind::FnOrCoroutine, |this| {
4278 this.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4279 this.visit_block(body);
4280 });
4281 });
4282 });
4283 }
4284
4285 fn resolve_params(&mut self, params: &'ast [Param]) {
4286 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())];
4287 self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
4288 for Param { pat, .. } in params {
4289 this.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
4290 }
4291 this.apply_pattern_bindings(bindings);
4292 });
4293 for Param { ty, .. } in params {
4294 self.visit_ty(ty);
4295 }
4296 }
4297
4298 fn resolve_local(&mut self, local: &'ast Local) {
4299 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:4299",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(4299u32),
::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);
4300 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);
4302
4303 if let Some((init, els)) = local.kind.init_else_opt() {
4305 self.visit_expr(init);
4306
4307 if let Some(els) = els {
4309 self.visit_block(els);
4310 }
4311 }
4312
4313 self.resolve_pattern_top(&local.pat, PatternSource::Let);
4315 }
4316
4317 fn compute_and_check_binding_map(
4336 &mut self,
4337 pat: &Pat,
4338 ) -> Result<FxIndexMap<Ident, BindingInfo>, IsNeverPattern> {
4339 let mut binding_map = FxIndexMap::default();
4340 let mut is_never_pat = false;
4341
4342 pat.walk(&mut |pat| {
4343 match pat.kind {
4344 PatKind::Ident(annotation, ident, ref sub_pat)
4345 if sub_pat.is_some() || self.is_base_res_local(pat.id) =>
4346 {
4347 binding_map.insert(ident, BindingInfo { span: ident.span, annotation });
4348 }
4349 PatKind::Or(ref ps) => {
4350 match self.compute_and_check_or_pat_binding_map(ps) {
4353 Ok(bm) => binding_map.extend(bm),
4354 Err(IsNeverPattern) => is_never_pat = true,
4355 }
4356 return false;
4357 }
4358 PatKind::Never => is_never_pat = true,
4359 _ => {}
4360 }
4361
4362 true
4363 });
4364
4365 if is_never_pat {
4366 for (_, binding) in binding_map {
4367 self.report_error(binding.span, ResolutionError::BindingInNeverPattern);
4368 }
4369 Err(IsNeverPattern)
4370 } else {
4371 Ok(binding_map)
4372 }
4373 }
4374
4375 fn is_base_res_local(&self, nid: NodeId) -> bool {
4376 #[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!(
4377 self.r.partial_res_map.get(&nid).map(|res| res.expect_full_res()),
4378 Some(Res::Local(..))
4379 )
4380 }
4381
4382 fn compute_and_check_or_pat_binding_map(
4401 &mut self,
4402 pats: &[Pat],
4403 ) -> Result<FxIndexMap<Ident, BindingInfo>, IsNeverPattern> {
4404 let mut missing_vars = FxIndexMap::default();
4405 let mut inconsistent_vars = FxIndexMap::default();
4406
4407 let not_never_pats = pats
4409 .iter()
4410 .filter_map(|pat| {
4411 let binding_map = self.compute_and_check_binding_map(pat).ok()?;
4412 Some((binding_map, pat))
4413 })
4414 .collect::<Vec<_>>();
4415
4416 for &(ref map_outer, pat_outer) in not_never_pats.iter() {
4418 let inners = not_never_pats.iter().filter(|(_, pat)| pat.id != pat_outer.id);
4420
4421 for &(ref map, pat) in inners {
4422 for (&name, binding_inner) in map {
4423 match map_outer.get(&name) {
4424 None => {
4425 let binding_error =
4427 missing_vars.entry(name).or_insert_with(|| BindingError {
4428 name,
4429 origin: Default::default(),
4430 target: Default::default(),
4431 could_be_path: name.as_str().starts_with(char::is_uppercase),
4432 });
4433 binding_error.origin.push((binding_inner.span, pat.clone()));
4434 binding_error.target.push(pat_outer.clone());
4435 }
4436 Some(binding_outer) => {
4437 if binding_outer.annotation != binding_inner.annotation {
4438 inconsistent_vars
4440 .entry(name)
4441 .or_insert((binding_inner.span, binding_outer.span));
4442 }
4443 }
4444 }
4445 }
4446 }
4447 }
4448
4449 for (name, mut v) in missing_vars {
4451 if inconsistent_vars.contains_key(&name) {
4452 v.could_be_path = false;
4453 }
4454 self.report_error(
4455 v.origin.first().unwrap().0,
4456 ResolutionError::VariableNotBoundInPattern(v, self.parent_scope),
4457 );
4458 }
4459
4460 for (name, v) in inconsistent_vars {
4462 self.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(name, v.1));
4463 }
4464
4465 if not_never_pats.is_empty() {
4467 Err(IsNeverPattern)
4469 } else {
4470 let mut binding_map = FxIndexMap::default();
4471 for (bm, _) in not_never_pats {
4472 binding_map.extend(bm);
4473 }
4474 Ok(binding_map)
4475 }
4476 }
4477
4478 fn check_consistent_bindings(&mut self, pat: &'ast Pat) {
4480 let mut is_or_or_never = false;
4481 pat.walk(&mut |pat| match pat.kind {
4482 PatKind::Or(..) | PatKind::Never => {
4483 is_or_or_never = true;
4484 false
4485 }
4486 _ => true,
4487 });
4488 if is_or_or_never {
4489 let _ = self.compute_and_check_binding_map(pat);
4490 }
4491 }
4492
4493 fn resolve_arm(&mut self, arm: &'ast Arm) {
4494 self.with_rib(ValueNS, RibKind::Normal, |this| {
4495 this.resolve_pattern_top(&arm.pat, PatternSource::Match);
4496 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));
4497 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);
4498 });
4499 }
4500
4501 fn resolve_pattern_top(&mut self, pat: &'ast Pat, pat_src: PatternSource) {
4503 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())];
4504 self.resolve_pattern(pat, pat_src, &mut bindings);
4505 self.apply_pattern_bindings(bindings);
4506 }
4507
4508 fn apply_pattern_bindings(&mut self, mut pat_bindings: PatternBindings) {
4510 let rib_bindings = self.innermost_rib_bindings(ValueNS);
4511 let Some((_, pat_bindings)) = pat_bindings.pop() else {
4512 ::rustc_span::macros::bug_impl(None,
format_args!("tried applying nonexistent bindings from pattern"),
Location::caller());bug!("tried applying nonexistent bindings from pattern");
4513 };
4514
4515 if rib_bindings.is_empty() {
4516 *rib_bindings = pat_bindings;
4519 } else {
4520 rib_bindings.extend(pat_bindings);
4521 }
4522 }
4523
4524 fn resolve_pattern(
4527 &mut self,
4528 pat: &'ast Pat,
4529 pat_src: PatternSource,
4530 bindings: &mut PatternBindings,
4531 ) {
4532 self.visit_pat(pat);
4538 self.resolve_pattern_inner(pat, pat_src, bindings);
4539 self.check_consistent_bindings(pat);
4541 }
4542
4543 {}
#[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/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(4562u32),
::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")]
4563 fn resolve_pattern_inner(
4564 &mut self,
4565 pat: &'ast Pat,
4566 pat_src: PatternSource,
4567 bindings: &mut PatternBindings,
4568 ) {
4569 pat.walk(&mut |pat| {
4571 match pat.kind {
4572 PatKind::Ident(bmode, ident, ref sub) => {
4573 let has_sub = sub.is_some();
4576 let res = self
4577 .try_resolve_as_non_binding(pat_src, bmode, ident, has_sub)
4578 .unwrap_or_else(|| self.fresh_binding(ident, pat.id, pat_src, bindings));
4579 self.r.record_partial_res(pat.id, PartialRes::new(res));
4580 self.r.record_pat_span(pat.id, pat.span);
4581 }
4582 PatKind::TupleStruct(ref qself, ref path, ref sub_patterns) => {
4583 self.smart_resolve_path(
4584 pat.id,
4585 qself,
4586 path,
4587 PathSource::TupleStruct(
4588 pat.span,
4589 self.r.arenas.alloc_pattern_spans(sub_patterns.iter().map(|p| p.span)),
4590 ),
4591 );
4592 }
4593 PatKind::Path(ref qself, ref path) => {
4594 self.smart_resolve_path(pat.id, qself, path, PathSource::Pat);
4595 }
4596 PatKind::Struct(ref qself, ref path, ref _fields, ref rest) => {
4597 self.smart_resolve_path(pat.id, qself, path, PathSource::Struct(None));
4598 self.record_patterns_with_skipped_bindings(pat, rest);
4599 }
4600 PatKind::Or(ref ps) => {
4601 bindings.push((PatBoundCtx::Or, Default::default()));
4605 for p in ps {
4606 bindings.push((PatBoundCtx::Product, Default::default()));
4610 self.resolve_pattern_inner(p, pat_src, bindings);
4611 let collected = bindings.pop().unwrap().1;
4614 bindings.last_mut().unwrap().1.extend(collected);
4615 }
4616 let collected = bindings.pop().unwrap().1;
4620 bindings.last_mut().unwrap().1.extend(collected);
4621
4622 return false;
4624 }
4625 PatKind::Guard(ref subpat, ref guard) => {
4626 bindings.push((PatBoundCtx::Product, Default::default()));
4628 let binding_ctx_stack_len = bindings.len();
4631 self.resolve_pattern_inner(subpat, pat_src, bindings);
4632 assert_eq!(bindings.len(), binding_ctx_stack_len);
4633 let subpat_bindings = bindings.pop().unwrap().1;
4636 self.with_rib(ValueNS, RibKind::Normal, |this| {
4637 *this.innermost_rib_bindings(ValueNS) = subpat_bindings.clone();
4638 this.resolve_expr(&guard.cond, None);
4639 });
4640 bindings.last_mut().unwrap().1.extend(subpat_bindings);
4647 return false;
4649 }
4650 _ => {}
4651 }
4652 true
4653 });
4654 }
4655
4656 fn record_patterns_with_skipped_bindings(&mut self, pat: &Pat, rest: &ast::PatFieldsRest) {
4657 match rest {
4658 ast::PatFieldsRest::Rest(_) | ast::PatFieldsRest::Recovered(_) => {
4659 if let Some(partial_res) = self.r.partial_res_map.get(&pat.id)
4661 && let Some(res) = partial_res.full_res()
4662 && let Some(def_id) = res.opt_def_id()
4663 {
4664 self.ribs[ValueNS]
4665 .last_mut()
4666 .unwrap()
4667 .patterns_with_skipped_bindings
4668 .entry(def_id)
4669 .or_default()
4670 .push((
4671 pat.span,
4672 match rest {
4673 ast::PatFieldsRest::Rest(span) => Some(*span),
4674 _ => None,
4675 },
4676 match rest {
4677 ast::PatFieldsRest::Recovered(guar) => Err(*guar),
4678 _ => Ok(()),
4679 },
4680 ));
4681 }
4682 }
4683 ast::PatFieldsRest::None => {}
4684 }
4685 }
4686
4687 fn fresh_binding(
4688 &mut self,
4689 ident: Ident,
4690 pat_id: NodeId,
4691 pat_src: PatternSource,
4692 bindings: &mut PatternBindings,
4693 ) -> Res {
4694 let ident = ident.normalize_to_macro_rules();
4698
4699 let already_bound_and = bindings
4701 .iter()
4702 .any(|(ctx, map)| *ctx == PatBoundCtx::Product && map.contains_key(&ident));
4703 if already_bound_and {
4704 use ResolutionError::*;
4706 let error = match pat_src {
4707 PatternSource::FnParam => IdentifierBoundMoreThanOnceInParameterList,
4709 _ => IdentifierBoundMoreThanOnceInSamePattern,
4711 };
4712 self.report_error(ident.span, error(ident));
4713 }
4714
4715 let already_bound_or = bindings
4718 .iter()
4719 .find_map(|(ctx, map)| if *ctx == PatBoundCtx::Or { map.get(&ident) } else { None });
4720 let res = if let Some(&res) = already_bound_or {
4721 res
4724 } else {
4725 Res::Local(pat_id)
4727 };
4728
4729 bindings.last_mut().unwrap().1.insert(ident, res);
4731 res
4732 }
4733
4734 fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap<Ident, Res> {
4735 &mut self.ribs[ns].last_mut().unwrap().bindings
4736 }
4737
4738 fn try_resolve_as_non_binding(
4739 &mut self,
4740 pat_src: PatternSource,
4741 ann: BindingMode,
4742 ident: Ident,
4743 has_sub: bool,
4744 ) -> Option<Res> {
4745 let is_syntactic_ambiguity = !has_sub && ann == BindingMode::NONE;
4749
4750 let ls_binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS)?;
4751 let (res, binding) = match ls_binding {
4752 LateDecl::Decl(binding)
4753 if is_syntactic_ambiguity && binding.is_ambiguity_recursive() =>
4754 {
4755 self.r.record_use(ident, binding, Used::Other);
4760 return None;
4761 }
4762 LateDecl::Decl(binding) => (binding.res(), Some(binding)),
4763 LateDecl::RibDef(res) => (res, None),
4764 };
4765
4766 match res {
4767 Res::SelfCtor(_) | Res::Def(
4769 DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst | DefKind::ConstParam,
4770 _,
4771 ) if is_syntactic_ambiguity => {
4772 if let Some(binding) = binding {
4774 self.r.record_use(ident, binding, Used::Other);
4775 }
4776 Some(res)
4777 }
4778 Res::Def(
4779 DefKind::Ctor(..)
4780 | DefKind::Const
4781 | DefKind::AssocConst
4782 | DefKind::Static { .. },
4783 _,
4784 ) => {
4785 let binding = binding.expect("no binding for a ctor or static");
4791 self.report_error(
4792 ident.span,
4793 ResolutionError::BindingShadowsSomethingUnacceptable {
4794 shadowing_binding: pat_src,
4795 name: ident.name,
4796 participle: if binding.is_import() { "imported" } else { "defined" },
4797 article: binding.res().article(),
4798 shadowed_binding: binding.res(),
4799 shadowed_binding_span: binding.span,
4800 },
4801 );
4802 None
4803 }
4804 Res::Def(DefKind::ConstParam, def_id) => {
4805 self.report_error(
4808 ident.span,
4809 ResolutionError::BindingShadowsSomethingUnacceptable {
4810 shadowing_binding: pat_src,
4811 name: ident.name,
4812 participle: "defined",
4813 article: res.article(),
4814 shadowed_binding: res,
4815 shadowed_binding_span: self.r.def_span(def_id),
4816 },
4817 );
4818 None
4819 }
4820 Res::Def(DefKind::Fn | DefKind::AssocFn, _) | Res::Local(..) | Res::Err => {
4821 None
4823 }
4824 Res::SelfCtor(_) => {
4825 self.r.dcx().span_delayed_bug(
4828 ident.span,
4829 "unexpected `SelfCtor` in pattern, expected identifier",
4830 );
4831 None
4832 }
4833 _ => ::rustc_span::macros::bug_impl(Some(ident.span),
format_args!("unexpected resolution for an identifier in pattern: {0:?}",
res), Location::caller())span_bug!(
4834 ident.span,
4835 "unexpected resolution for an identifier in pattern: {:?}",
4836 res,
4837 ),
4838 }
4839 }
4840
4841 fn resolve_restriction_path(&mut self, restriction: &'ast ast::RestrictionKind) {
4842 match &restriction {
4843 ast::RestrictionKind::Unrestricted => (),
4844 ast::RestrictionKind::Restricted { path, id, shorthand: _ } => {
4845 self.smart_resolve_path(*id, &None, path, PathSource::Module);
4846 }
4847 }
4848 }
4849
4850 fn smart_resolve_path(
4856 &mut self,
4857 id: NodeId,
4858 qself: &Option<Box<QSelf>>,
4859 path: &Path,
4860 source: PathSource<'_, 'ast, 'ra>,
4861 ) {
4862 self.smart_resolve_path_fragment(
4863 qself,
4864 &Segment::from_path(path),
4865 source,
4866 Finalize::new(id, path.span),
4867 RecordPartialRes::Yes,
4868 None,
4869 );
4870 }
4871
4872 fn smart_resolve_path_fragment(
4873 &mut self,
4874 qself: &Option<Box<QSelf>>,
4875 path: &[Segment],
4876 source: PathSource<'_, 'ast, 'ra>,
4877 finalize: Finalize,
4878 record_partial_res: RecordPartialRes,
4879 parent_qself: Option<&QSelf>,
4880 ) -> PartialRes {
4881 let ns = source.namespace();
4882
4883 let Finalize { node_id, path_span, .. } = finalize;
4884 let report_errors = |this: &mut Self, res: Option<Res>| {
4885 if this.should_report_errs() {
4886 let (mut err, candidates) = this.smart_resolve_report_errors(
4887 path,
4888 None,
4889 path_span,
4890 source,
4891 res,
4892 parent_qself,
4893 );
4894
4895 let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
4896 let instead = res.is_some();
4897 let (suggestion, const_err) = if let Some((start, end)) =
4898 this.diag_metadata.in_range
4899 && path[0].ident.span.lo() == end.span.lo()
4900 && !#[allow(non_exhaustive_omitted_patterns)] match start.kind {
ExprKind::Lit(_) => true,
_ => false,
}matches!(start.kind, ExprKind::Lit(_))
4901 {
4902 let mut sugg = ".";
4903 let mut span = start.span.between(end.span);
4904 if span.lo() + BytePos(2) == span.hi() {
4905 span = span.with_lo(span.lo() + BytePos(1));
4908 sugg = "";
4909 }
4910 (
4911 Some((
4912 span,
4913 "you might have meant to write `.` instead of `..`",
4914 sugg.to_string(),
4915 Applicability::MaybeIncorrect,
4916 )),
4917 None,
4918 )
4919 } else if res.is_none()
4920 && let PathSource::Type
4921 | PathSource::Expr(_)
4922 | PathSource::PreciseCapturingArg(..) = source
4923 {
4924 this.suggest_adding_generic_parameter(path, source)
4925 } else {
4926 (None, None)
4927 };
4928
4929 if let Some(const_err) = const_err {
4930 err.cancel();
4931 err = const_err;
4932 }
4933
4934 let ue = UseError {
4935 err,
4936 candidates,
4937 node_id,
4938 instead,
4939 suggestion,
4940 path: path.into(),
4941 is_call: source.is_call(),
4942 };
4943
4944 this.use_injections.push(ue);
4945 }
4946
4947 PartialRes::new(Res::Err)
4948 };
4949
4950 let report_errors_for_call =
4956 |this: &mut Self, parent_err: Spanned<ResolutionError<'ra>>| {
4957 let (following_seg, prefix_path) = match path.split_last() {
4961 Some((last, path)) if !path.is_empty() => (Some(last), path),
4962 _ => return Some(parent_err),
4963 };
4964
4965 let (mut err, candidates) = this.smart_resolve_report_errors(
4966 prefix_path,
4967 following_seg,
4968 path_span,
4969 PathSource::Type,
4970 None,
4971 parent_qself,
4972 );
4973
4974 let failed_to_resolve = match parent_err.node {
4989 ResolutionError::FailedToResolve { .. } => true,
4990 _ => false,
4991 };
4992 let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
4993
4994 err.messages = take(&mut parent_err.messages);
4996 err.code = take(&mut parent_err.code);
4997 swap(&mut err.span, &mut parent_err.span);
4998 if failed_to_resolve {
4999 err.children = take(&mut parent_err.children);
5000 } else {
5001 err.children.append(&mut parent_err.children);
5002 }
5003 err.is_lint = parent_err.is_lint.clone();
5004
5005 match &mut err.suggestions {
5007 Suggestions::Enabled(typo_suggestions) => match &mut parent_err.suggestions {
5008 Suggestions::Enabled(parent_suggestions) => {
5009 typo_suggestions.append(parent_suggestions)
5011 }
5012 Suggestions::Sealed(_) | Suggestions::Disabled => {
5013 err.suggestions = std::mem::take(&mut parent_err.suggestions);
5018 }
5019 },
5020 Suggestions::Sealed(_) | Suggestions::Disabled => (),
5021 }
5022
5023 parent_err.cancel();
5024
5025 let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
5026
5027 if this.should_report_errs() {
5028 if candidates.is_empty() {
5029 if path.len() == 2
5030 && let [segment] = prefix_path
5031 {
5032 err.stash(segment.ident.span, rustc_errors::StashKey::CallAssocMethod);
5038 } else {
5039 err.emit();
5044 }
5045 } else {
5046 this.use_injections.push(UseError {
5048 err,
5049 candidates,
5050 node_id,
5051 instead: false,
5052 suggestion: None,
5053 path: prefix_path.into(),
5054 is_call: source.is_call(),
5055 });
5056 }
5057 } else {
5058 err.cancel();
5059 }
5060
5061 None
5064 };
5065
5066 let partial_res = match self.resolve_qpath_anywhere(
5067 qself,
5068 path,
5069 ns,
5070 source.defer_to_typeck(),
5071 finalize,
5072 source,
5073 ) {
5074 Ok(Some(partial_res)) if let Some(res) = partial_res.full_res() => {
5075 if let Some(items) = self.diag_metadata.current_trait_assoc_items
5077 && let [Segment { ident, .. }] = path
5078 && items.iter().any(|item| {
5079 if let AssocItemKind::Type(alias) = &item.kind
5080 && alias.ident == *ident
5081 {
5082 true
5083 } else {
5084 false
5085 }
5086 })
5087 {
5088 self.r.paths_matching_assoc_types.insert(path_span.with_parent(None));
5089 }
5090
5091 if source.is_expected(res) || res == Res::Err {
5092 partial_res
5093 } else {
5094 report_errors(self, Some(res))
5095 }
5096 }
5097
5098 Ok(Some(partial_res)) if source.defer_to_typeck() => {
5099 if ns == ValueNS {
5103 let item_name = path.last().unwrap().ident;
5104 self.record_traits_in_scope(node_id, item_name);
5105 }
5106
5107 if PrimTy::from_name(path[0].ident.name).is_some() {
5108 let mut std_path = Vec::with_capacity(1 + path.len());
5109
5110 std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
5111 std_path.extend(path);
5112 if let PathResult::Module(_) | PathResult::NonModule(_) =
5113 self.resolve_path(&std_path, Some(ns), None, source)
5114 {
5115 let item_span = path.last().map_or(path_span, |segment| segment.ident.span);
5117
5118 self.r.confused_type_with_std_module.insert(item_span, path_span);
5119 self.r.confused_type_with_std_module.insert(path_span, path_span);
5120 }
5121 }
5122
5123 partial_res
5124 }
5125
5126 Err(err) => {
5127 if let Some(err) = report_errors_for_call(self, err) {
5128 self.report_error(err.span, err.node);
5129 }
5130
5131 PartialRes::new(Res::Err)
5132 }
5133
5134 _ => report_errors(self, None),
5135 };
5136
5137 if record_partial_res == RecordPartialRes::Yes {
5138 self.r.record_partial_res(node_id, partial_res);
5140 self.resolve_elided_lifetimes_in_path(partial_res, path, source, path_span);
5141 self.lint_unused_qualifications(path, ns, finalize);
5142 }
5143
5144 partial_res
5145 }
5146
5147 fn self_type_is_available(&mut self) -> bool {
5148 let binding = self
5149 .maybe_resolve_ident_in_lexical_scope(Ident::with_dummy_span(kw::SelfUpper), TypeNS);
5150 if let Some(LateDecl::RibDef(res)) = binding { res != Res::Err } else { false }
5151 }
5152
5153 fn self_value_is_available(&mut self, self_span: Span) -> bool {
5154 let ident = Ident::new(kw::SelfLower, self_span);
5155 let binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS);
5156 if let Some(LateDecl::RibDef(res)) = binding { res != Res::Err } else { false }
5157 }
5158
5159 fn report_error(&mut self, span: Span, resolution_error: ResolutionError<'ra>) {
5163 if self.should_report_errs() {
5164 self.r.report_error(span, resolution_error);
5165 }
5166 }
5167
5168 #[inline]
5169 fn should_report_errs(&self) -> bool {
5173 !(self.r.tcx.sess.opts.actually_rustdoc && self.in_func_body)
5174 && !self.r.glob_error.is_some()
5175 }
5176
5177 fn resolve_qpath_anywhere(
5179 &mut self,
5180 qself: &Option<Box<QSelf>>,
5181 path: &[Segment],
5182 primary_ns: Namespace,
5183 defer_to_typeck: bool,
5184 finalize: Finalize,
5185 source: PathSource<'_, 'ast, 'ra>,
5186 ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
5187 let mut fin_res = None;
5188
5189 for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {
5190 if i == 0 || ns != primary_ns {
5191 match self.resolve_qpath(qself, path, ns, finalize, source)? {
5192 Some(partial_res)
5193 if partial_res.unresolved_segments() == 0 || defer_to_typeck =>
5194 {
5195 return Ok(Some(partial_res));
5196 }
5197 partial_res => {
5198 if fin_res.is_none() {
5199 fin_res = partial_res;
5200 }
5201 }
5202 }
5203 }
5204 }
5205
5206 if !(primary_ns != MacroNS) {
::core::panicking::panic("assertion failed: primary_ns != MacroNS")
};assert!(primary_ns != MacroNS);
5207 if qself.is_none()
5208 && let PathResult::NonModule(res) =
5209 self.r.cm().maybe_resolve_path(path, Some(MacroNS), &self.parent_scope, None)
5210 {
5211 return Ok(Some(res));
5212 }
5213
5214 Ok(fin_res)
5215 }
5216
5217 {}
#[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_qpath",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5218u32),
::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("qself")
}> =
::tracing::__macro_support::FieldName::new("qself");
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("ns")
}> =
::tracing::__macro_support::FieldName::new("ns");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("finalize")
}> =
::tracing::__macro_support::FieldName::new("finalize");
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(&qself)
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(&ns)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&finalize)
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:
Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> =
loop {};
return __tracing_attr_fake_return;
}
{
if let Some(qself) = qself {
if qself.position == 0 {
return Ok(Some(PartialRes::with_unresolved_segments(Res::Def(DefKind::Mod,
CRATE_DEF_ID.to_def_id()), path.len())));
}
let num_privacy_errors = self.r.privacy_errors.len();
let trait_res =
self.smart_resolve_path_fragment(&None,
&path[..qself.position],
PathSource::Trait(AliasPossibility::No),
Finalize::new(finalize.node_id, qself.path_span),
RecordPartialRes::No, Some(&qself));
if trait_res.expect_full_res() == Res::Err {
return Ok(Some(trait_res));
}
self.r.privacy_errors.truncate(num_privacy_errors);
let ns =
if qself.position + 1 == path.len() { ns } else { TypeNS };
let partial_res =
self.smart_resolve_path_fragment(&None,
&path[..=qself.position],
PathSource::TraitItem(ns, &source),
Finalize::with_root_span(finalize.node_id,
finalize.path_span, qself.path_span), RecordPartialRes::No,
Some(&qself));
return Ok(Some(PartialRes::with_unresolved_segments(partial_res.base_res(),
partial_res.unresolved_segments() + path.len() -
qself.position - 1)));
}
let result =
match self.resolve_path(path, Some(ns), Some(finalize),
source) {
PathResult::NonModule(path_res) => path_res,
PathResult::Module(ModuleOrUniformRoot::Module(module)) if
!module.is_normal() => {
PartialRes::new(module.res().unwrap())
}
PathResult::Failed { error_implied_by_parse_error: true, ..
} => {
PartialRes::new(Res::Err)
}
PathResult::Module(ModuleOrUniformRoot::Module(_)) |
PathResult::Failed { .. } if
(ns == TypeNS || path.len() > 1) &&
PrimTy::from_name(path[0].ident.name).is_some() => {
let prim = PrimTy::from_name(path[0].ident.name).unwrap();
let tcx = self.r.tcx();
let gate_err_sym_msg =
match prim {
PrimTy::Float(FloatTy::F16) if !self.r.features.f16() => {
Some((sym::f16, "the type `f16` is unstable"))
}
PrimTy::Float(FloatTy::F128) if !self.r.features.f128() => {
Some((sym::f128, "the type `f128` is unstable"))
}
_ => None,
};
if let Some((sym, msg)) = gate_err_sym_msg {
let span = path[0].ident.span;
if !span.allows_unstable(sym) {
feature_err(tcx.sess, sym, span, msg).emit();
}
};
if let Some(id) = path[0].id {
self.r.partial_res_map.insert(id,
PartialRes::new(Res::PrimTy(prim)));
}
PartialRes::with_unresolved_segments(Res::PrimTy(prim),
path.len() - 1)
}
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
PartialRes::new(module.res().unwrap())
}
PathResult::Failed {
is_error_from_last_segment: false,
span,
label,
suggestion,
help,
module,
segment,
error_implied_by_parse_error: _,
message,
note: _ } => {
return Err(respan(span,
ResolutionError::FailedToResolve {
segment: segment.name,
label,
suggestion,
help,
module,
message,
}));
}
PathResult::Module(..) | PathResult::Failed { .. } =>
return Ok(None),
PathResult::Indeterminate =>
::rustc_span::macros::bug_impl(None,
format_args!("indeterminate path result in resolve_qpath"),
Location::caller()),
};
Ok(Some(result))
}
}
}#[tracing::instrument(skip(self, source), level = "debug")]
5219 fn resolve_qpath(
5220 &mut self,
5221 qself: &Option<Box<QSelf>>,
5222 path: &[Segment],
5223 ns: Namespace,
5224 finalize: Finalize,
5225 source: PathSource<'_, 'ast, 'ra>,
5226 ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
5227 if let Some(qself) = qself {
5228 if qself.position == 0 {
5229 return Ok(Some(PartialRes::with_unresolved_segments(
5233 Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id()),
5234 path.len(),
5235 )));
5236 }
5237
5238 let num_privacy_errors = self.r.privacy_errors.len();
5239 let trait_res = self.smart_resolve_path_fragment(
5241 &None,
5242 &path[..qself.position],
5243 PathSource::Trait(AliasPossibility::No),
5244 Finalize::new(finalize.node_id, qself.path_span),
5245 RecordPartialRes::No,
5246 Some(&qself),
5247 );
5248
5249 if trait_res.expect_full_res() == Res::Err {
5250 return Ok(Some(trait_res));
5251 }
5252
5253 self.r.privacy_errors.truncate(num_privacy_errors);
5256
5257 let ns = if qself.position + 1 == path.len() { ns } else { TypeNS };
5265 let partial_res = self.smart_resolve_path_fragment(
5266 &None,
5267 &path[..=qself.position],
5268 PathSource::TraitItem(ns, &source),
5269 Finalize::with_root_span(finalize.node_id, finalize.path_span, qself.path_span),
5270 RecordPartialRes::No,
5271 Some(&qself),
5272 );
5273
5274 return Ok(Some(PartialRes::with_unresolved_segments(
5278 partial_res.base_res(),
5279 partial_res.unresolved_segments() + path.len() - qself.position - 1,
5280 )));
5281 }
5282
5283 let result = match self.resolve_path(path, Some(ns), Some(finalize), source) {
5284 PathResult::NonModule(path_res) => path_res,
5285 PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
5286 PartialRes::new(module.res().unwrap())
5287 }
5288 PathResult::Failed { error_implied_by_parse_error: true, .. } => {
5292 PartialRes::new(Res::Err)
5293 }
5294 PathResult::Module(ModuleOrUniformRoot::Module(_)) | PathResult::Failed { .. }
5307 if (ns == TypeNS || path.len() > 1)
5308 && PrimTy::from_name(path[0].ident.name).is_some() =>
5309 {
5310 let prim = PrimTy::from_name(path[0].ident.name).unwrap();
5311 let tcx = self.r.tcx();
5312
5313 let gate_err_sym_msg = match prim {
5314 PrimTy::Float(FloatTy::F16) if !self.r.features.f16() => {
5315 Some((sym::f16, "the type `f16` is unstable"))
5316 }
5317 PrimTy::Float(FloatTy::F128) if !self.r.features.f128() => {
5318 Some((sym::f128, "the type `f128` is unstable"))
5319 }
5320 _ => None,
5321 };
5322
5323 if let Some((sym, msg)) = gate_err_sym_msg {
5324 let span = path[0].ident.span;
5325 if !span.allows_unstable(sym) {
5326 feature_err(tcx.sess, sym, span, msg).emit();
5327 }
5328 };
5329
5330 if let Some(id) = path[0].id {
5332 self.r.partial_res_map.insert(id, PartialRes::new(Res::PrimTy(prim)));
5333 }
5334
5335 PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
5336 }
5337 PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
5338 PartialRes::new(module.res().unwrap())
5339 }
5340 PathResult::Failed {
5341 is_error_from_last_segment: false,
5342 span,
5343 label,
5344 suggestion,
5345 help,
5346 module,
5347 segment,
5348 error_implied_by_parse_error: _,
5349 message,
5350 note: _,
5351 } => {
5352 return Err(respan(
5353 span,
5354 ResolutionError::FailedToResolve {
5355 segment: segment.name,
5356 label,
5357 suggestion,
5358 help,
5359 module,
5360 message,
5361 },
5362 ));
5363 }
5364 PathResult::Module(..) | PathResult::Failed { .. } => return Ok(None),
5365 PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),
5366 };
5367
5368 Ok(Some(result))
5369 }
5370
5371 fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) {
5372 if let Some(label) = label {
5373 if label.ident.as_str().as_bytes()[1] != b'_' {
5374 self.diag_metadata.unused_labels.insert(id, label.ident.span);
5375 }
5376
5377 if let Ok((_, orig_span)) = self.resolve_label(label.ident) {
5378 diagnostics::signal_label_shadowing(self.r.tcx.sess, orig_span, label.ident)
5379 }
5380
5381 self.with_label_rib(RibKind::Normal, |this| {
5382 let ident = label.ident.normalize_to_macro_rules();
5383 this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
5384 f(this);
5385 });
5386 } else {
5387 f(self);
5388 }
5389 }
5390
5391 fn resolve_labeled_block(&mut self, label: Option<Label>, id: NodeId, block: &'ast Block) {
5392 self.with_resolved_label(label, id, |this| this.visit_block(block));
5393 }
5394
5395 fn resolve_block(&mut self, block: &'ast Block) {
5396 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:5396",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5396u32),
::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");
5397 let orig_module = self.parent_scope.module;
5399 let anonymous_module = self.r.block_map.get(&block.id).copied();
5400
5401 let mut num_macro_definition_ribs = 0;
5402 if let Some(anonymous_module) = anonymous_module {
5403 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:5403",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5403u32),
::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");
5404 self.ribs[ValueNS].push(Rib::new(RibKind::Block(Some(anonymous_module))));
5405 self.ribs[TypeNS].push(Rib::new(RibKind::Block(Some(anonymous_module))));
5406 self.parent_scope.module = anonymous_module.to_module();
5407 } else {
5408 self.ribs[ValueNS].push(Rib::new(RibKind::Block(None)));
5409 }
5410
5411 for stmt in &block.stmts {
5413 if let StmtKind::Item(ref item) = stmt.kind
5414 && let ItemKind::MacroDef(..) = item.kind
5415 {
5416 num_macro_definition_ribs += 1;
5417 let res = self.r.owner_def_id(item.id).to_def_id();
5418 self.ribs[ValueNS].push(Rib::new(RibKind::MacroDefinition(res)));
5419 self.label_ribs.push(Rib::new(RibKind::MacroDefinition(res)));
5420 }
5421
5422 self.visit_stmt(stmt);
5423 }
5424
5425 self.parent_scope.module = orig_module;
5427 for _ in 0..num_macro_definition_ribs {
5428 self.ribs[ValueNS].pop();
5429 self.label_ribs.pop();
5430 }
5431 self.last_block_rib = self.ribs[ValueNS].pop();
5432 if anonymous_module.is_some() {
5433 self.ribs[TypeNS].pop();
5434 }
5435 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:5435",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5435u32),
::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");
5436 }
5437
5438 fn resolve_anon_const(&mut self, constant: &'ast AnonConst, anon_const_kind: AnonConstKind) {
5439 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:5439",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5439u32),
::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!(
5440 "resolve_anon_const(constant: {:?}, anon_const_kind: {:?})",
5441 constant, anon_const_kind
5442 );
5443
5444 let is_trivial_const_arg = constant.value.is_potential_trivial_const_arg();
5445 self.resolve_anon_const_manual(is_trivial_const_arg, anon_const_kind, |this| {
5446 this.resolve_expr(&constant.value, None)
5447 })
5448 }
5449
5450 fn resolve_anon_const_manual(
5457 &mut self,
5458 is_trivial_const_arg: bool,
5459 anon_const_kind: AnonConstKind,
5460 resolve_expr: impl FnOnce(&mut Self),
5461 ) {
5462 let is_repeat_expr = match anon_const_kind {
5463 AnonConstKind::ConstArg(is_repeat_expr) => is_repeat_expr,
5464 _ => IsRepeatExpr::No,
5465 };
5466
5467 let may_use_generics = match anon_const_kind {
5468 AnonConstKind::EnumDiscriminant => {
5469 ConstantHasGenerics::No(NoConstantGenericsReason::IsEnumDiscriminant)
5470 }
5471 AnonConstKind::FieldDefaultValue => ConstantHasGenerics::Yes,
5472 AnonConstKind::InlineConst => ConstantHasGenerics::Yes,
5473 AnonConstKind::ConstArg(_) | AnonConstKind::ArrayLength => {
5474 if self.r.features.generic_const_exprs()
5475 || self.r.features.gca()
5476 || is_trivial_const_arg
5477 {
5478 ConstantHasGenerics::Yes
5479 } else {
5480 ConstantHasGenerics::No(NoConstantGenericsReason::NonTrivialConstArg)
5481 }
5482 }
5483 };
5484
5485 let requires_type = match anon_const_kind {
5486 AnonConstKind::ArrayLength | AnonConstKind::ConstArg(IsRepeatExpr::Yes) => {
5487 ConstantRequiresType::Usize
5488 }
5489 _ => ConstantRequiresType::No,
5490 };
5491
5492 self.with_constant_rib(is_repeat_expr, may_use_generics, requires_type, None, |this| {
5493 this.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
5494 resolve_expr(this);
5495 });
5496 });
5497 }
5498
5499 fn resolve_expr_field(&mut self, f: &'ast ExprField, e: &'ast Expr) {
5500 self.resolve_expr(&f.expr, Some(e));
5501 self.visit_ident(&f.ident);
5502 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());
5503 }
5504
5505 fn resolve_expr(&mut self, expr: &'ast Expr, parent: Option<&'ast Expr>) {
5506 self.record_candidate_traits_for_expr_if_necessary(expr);
5510
5511 match expr.kind {
5513 ExprKind::Path(ref qself, ref path) => {
5514 self.smart_resolve_path(expr.id, qself, path, PathSource::Expr(parent));
5515 visit::walk_expr(self, expr);
5516 }
5517
5518 ExprKind::Struct(ref se) => {
5519 self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct(parent));
5520 if let Some(qself) = &se.qself {
5524 self.visit_ty(&qself.ty);
5525 }
5526 self.visit_path(&se.path);
5527 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);
5528 match &se.rest {
5529 StructRest::Base(expr) => self.visit_expr(expr),
5530 StructRest::Rest(_span) => {}
5531 StructRest::None | StructRest::NoneWithError(_) => {}
5532 }
5533 }
5534
5535 ExprKind::Break(Some(label), _) | ExprKind::Continue(Some(label)) => {
5536 match self.resolve_label(label.ident) {
5537 Ok((node_id, _)) => {
5538 self.r.current_owner.label_res_map.insert(expr.id, node_id);
5540 self.diag_metadata.unused_labels.swap_remove(&node_id);
5541 }
5542 Err(error) => {
5543 self.report_error(label.ident.span, error);
5544 }
5545 }
5546
5547 visit::walk_expr(self, expr);
5549 }
5550
5551 ExprKind::Break(None, Some(ref e)) => {
5552 self.resolve_expr(e, Some(expr));
5555 }
5556
5557 ExprKind::Let(ref pat, ref scrutinee, _, Recovered::No) => {
5558 self.visit_expr(scrutinee);
5559 self.resolve_pattern_top(pat, PatternSource::Let);
5560 }
5561
5562 ExprKind::Let(ref pat, ref scrutinee, _, Recovered::Yes(_)) => {
5563 self.visit_expr(scrutinee);
5564 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())];
5566 self.resolve_pattern(pat, PatternSource::Let, &mut bindings);
5567 for (_, bindings) in &mut bindings {
5572 for (_, binding) in bindings {
5573 *binding = Res::Err;
5574 }
5575 }
5576 self.apply_pattern_bindings(bindings);
5577 }
5578
5579 ExprKind::If(ref cond, ref then, ref opt_else) => {
5580 self.with_rib(ValueNS, RibKind::Normal, |this| {
5581 let old = this.diag_metadata.in_if_condition.replace(cond);
5582 this.visit_expr(cond);
5583 this.diag_metadata.in_if_condition = old;
5584 this.visit_block(then);
5585 });
5586 if let Some(expr) = opt_else {
5587 self.visit_expr(expr);
5588 }
5589 }
5590
5591 ExprKind::Loop(ref block, label, _) => {
5592 self.resolve_labeled_block(label, expr.id, block)
5593 }
5594
5595 ExprKind::While(ref cond, ref block, label) => {
5596 self.with_resolved_label(label, expr.id, |this| {
5597 this.with_rib(ValueNS, RibKind::Normal, |this| {
5598 let old = this.diag_metadata.in_if_condition.replace(cond);
5599 this.visit_expr(cond);
5600 this.diag_metadata.in_if_condition = old;
5601 this.visit_block(block);
5602 })
5603 });
5604 }
5605
5606 ExprKind::ForLoop(ForLoop { ref pat, ref iter, ref body, label, kind: _ }) => {
5607 self.visit_expr(iter);
5608 self.with_rib(ValueNS, RibKind::Normal, |this| {
5609 this.resolve_pattern_top(pat, PatternSource::For);
5610 this.resolve_labeled_block(label, expr.id, body);
5611 });
5612 }
5613
5614 ExprKind::Block(ref block, label) => self.resolve_labeled_block(label, block.id, block),
5615
5616 ExprKind::Field(ref subexpression, _) => {
5618 self.resolve_expr(subexpression, Some(expr));
5619 }
5620 ExprKind::MethodCall(MethodCall { ref seg, ref receiver, ref args, .. }) => {
5621 self.resolve_expr(receiver, Some(expr));
5622 for arg in args {
5623 self.resolve_expr(arg, None);
5624 }
5625 self.visit_path_segment(seg);
5626 self.detect_missing_turbofish(&args);
5627 }
5628
5629 ExprKind::Call(ref callee, ref arguments) => {
5630 self.resolve_expr(callee, Some(expr));
5631 let const_args = self.r.legacy_const_generic_args(callee).unwrap_or_default();
5632 for (idx, argument) in arguments.iter().enumerate() {
5633 if const_args.contains(&idx) {
5636 let is_trivial_const_arg = argument.is_potential_trivial_const_arg();
5639 self.resolve_anon_const_manual(
5640 is_trivial_const_arg,
5641 AnonConstKind::ConstArg(IsRepeatExpr::No),
5642 |this| this.resolve_expr(argument, None),
5643 );
5644 } else {
5645 self.resolve_expr(argument, None);
5646 }
5647 }
5648 self.detect_missing_turbofish(&arguments);
5649 }
5650 ExprKind::FormatArgs(ref args) => {
5651 for arg in args.arguments.all_args() {
5652 let parent =
5654 #[allow(non_exhaustive_omitted_patterns)] match arg.kind {
FormatArgumentKind::Captured(_) => true,
_ => false,
}matches!(arg.kind, FormatArgumentKind::Captured(_)).then_some(expr);
5655 self.resolve_expr(&arg.expr, parent);
5656 }
5657 }
5658 ExprKind::Type(ref _type_expr, ref _ty) => {
5659 visit::walk_expr(self, expr);
5660 }
5661 ExprKind::Move(..) => {
5662 self.with_move_expr_initializer(expr.span, |this| visit::walk_expr(this, expr));
5663 }
5664 ExprKind::Closure(ast::Closure {
5666 binder: ClosureBinder::For { ref generic_params, span },
5667 fn_decl_span,
5668 ..
5669 }) => {
5670 self.with_move_expr_scope(Some(fn_decl_span), |this| {
5671 this.with_generic_param_rib(
5672 generic_params,
5673 RibKind::Normal,
5674 expr.id,
5675 LifetimeBinderKind::Closure,
5676 span,
5677 |this| visit::walk_expr(this, expr),
5678 );
5679 });
5680 }
5681 ExprKind::Closure(ref closure) => {
5682 self.with_move_expr_scope(Some(closure.fn_decl_span), |this| {
5683 visit::walk_expr(this, expr)
5684 });
5685 }
5686 ExprKind::Gen(_, _, _, decl_span) => {
5687 self.with_move_expr_scope(Some(decl_span), |this| {
5688 this.with_label_rib(RibKind::FnOrCoroutine, |this| {
5689 visit::walk_expr(this, expr)
5690 });
5691 });
5692 }
5693 ExprKind::Repeat(ref elem, ref ct) => {
5694 self.visit_expr(elem);
5695 self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::Yes));
5696 }
5697 ExprKind::ConstBlock(ref ct) => {
5698 self.with_move_expr_scope(None, |this| {
5699 this.resolve_anon_const(ct, AnonConstKind::InlineConst);
5700 });
5701 }
5702 ExprKind::Index(ref elem, ref idx, _) => {
5703 self.resolve_expr(elem, Some(expr));
5704 self.visit_expr(idx);
5705 }
5706 ExprKind::Assign(ref lhs, ref rhs, _) => {
5707 if !self.diag_metadata.is_assign_rhs {
5708 self.diag_metadata.in_assignment = Some(expr);
5709 }
5710 self.visit_expr(lhs);
5711 self.diag_metadata.is_assign_rhs = true;
5712 self.diag_metadata.in_assignment = None;
5713 self.visit_expr(rhs);
5714 self.diag_metadata.is_assign_rhs = false;
5715 }
5716 ExprKind::Range(Some(ref start), Some(ref end), RangeLimits::HalfOpen) => {
5717 self.diag_metadata.in_range = Some((start, end));
5718 self.resolve_expr(start, Some(expr));
5719 self.resolve_expr(end, Some(expr));
5720 self.diag_metadata.in_range = None;
5721 }
5722 _ => {
5723 visit::walk_expr(self, expr);
5724 }
5725 }
5726 }
5727
5728 fn record_candidate_traits_for_expr_if_necessary(&mut self, expr: &'ast Expr) {
5729 match expr.kind {
5730 ExprKind::Field(_, ident) => {
5731 self.record_traits_in_scope(expr.id, ident);
5736 }
5737 ExprKind::MethodCall(ref call) => {
5738 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs:5738",
"rustc_resolve::late", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_resolve/src/late.rs"),
::tracing_core::__macro_support::Option::Some(5738u32),
::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);
5739 self.record_traits_in_scope(expr.id, call.seg.ident);
5740 }
5741 _ => {
5742 }
5744 }
5745 }
5746
5747 fn record_traits_in_scope(&mut self, node_id: NodeId, ident: Ident) {
5748 let traits = self.r.traits_in_scope(
5749 self.current_trait_ref.map(|(module, _)| module),
5750 &self.parent_scope,
5751 ident.span,
5752 Some((ident.name, ValueNS)),
5753 );
5754 self.r.current_owner.trait_map.insert(node_id, traits);
5755 }
5756
5757 fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option<Res> {
5758 let mut doc_link_resolutions = std::mem::take(&mut self.r.doc_link_resolutions);
5762 let res = *doc_link_resolutions
5763 .entry(self.parent_scope.module.nearest_parent_mod().expect_local())
5764 .or_default()
5765 .entry((Symbol::intern(path_str), ns))
5766 .or_insert_with_key(|(path, ns)| {
5767 let res = self.r.resolve_rustdoc_path(path.as_str(), *ns, self.parent_scope);
5768 if let Some(res) = res
5769 && let Some(def_id) = res.opt_def_id()
5770 && self.is_invalid_proc_macro_item_for_doc(def_id)
5771 {
5772 return None;
5775 }
5776 res
5777 });
5778 self.r.doc_link_resolutions = doc_link_resolutions;
5779 res
5780 }
5781
5782 fn is_invalid_proc_macro_item_for_doc(&self, did: DefId) -> bool {
5783 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)
5784 || !self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
5785 {
5786 return false;
5787 }
5788 let Some(local_did) = did.as_local() else { return true };
5789 !self.r.proc_macros.contains(&local_did)
5790 }
5791
5792 fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
5793 match self.r.tcx.sess.opts.resolve_doc_links {
5794 ResolveDocLinks::None => return,
5795 ResolveDocLinks::ExportedMetadata
5796 if !self.r.tcx.crate_types().iter().copied().any(CrateType::has_metadata)
5797 || !maybe_exported.eval(self.r) =>
5798 {
5799 return;
5800 }
5801 ResolveDocLinks::Exported
5802 if !maybe_exported.eval(self.r)
5803 && !rustdoc::has_primitive_or_keyword_or_attribute_docs_ast(attrs) =>
5804 {
5805 return;
5806 }
5807 ResolveDocLinks::ExportedMetadata
5808 | ResolveDocLinks::Exported
5809 | ResolveDocLinks::All => {}
5810 }
5811
5812 if !attrs.iter().any(|attr| attr.may_have_doc_links()) {
5813 return;
5814 }
5815
5816 let mut need_traits_in_scope = false;
5817 for path_str in rustdoc::attrs_to_preprocessed_links(attrs) {
5818 let mut any_resolved = false;
5820 let mut need_assoc = false;
5821 for ns in [TypeNS, ValueNS, MacroNS] {
5822 if let Some(res) = self.resolve_and_cache_rustdoc_path(&path_str, ns) {
5823 any_resolved = !#[allow(non_exhaustive_omitted_patterns)] match res {
Res::NonMacroAttr(NonMacroAttrKind::Tool) => true,
_ => false,
}matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Tool));
5826 } else if ns != MacroNS {
5827 need_assoc = true;
5828 }
5829 }
5830
5831 if need_assoc || !any_resolved {
5833 let mut path = &path_str[..];
5834 while let Some(idx) = path.rfind("::") {
5835 path = &path[..idx];
5836 need_traits_in_scope = true;
5837 for ns in [TypeNS, ValueNS, MacroNS] {
5838 self.resolve_and_cache_rustdoc_path(path, ns);
5839 }
5840 }
5841 }
5842 }
5843
5844 if need_traits_in_scope {
5845 let mut doc_link_traits_in_scope = std::mem::take(&mut self.r.doc_link_traits_in_scope);
5847 doc_link_traits_in_scope
5848 .entry(self.parent_scope.module.nearest_parent_mod().expect_local())
5849 .or_insert_with(|| {
5850 self.r
5851 .traits_in_scope(None, &self.parent_scope, DUMMY_SP, None)
5852 .into_iter()
5853 .filter_map(|tr| {
5854 if self.is_invalid_proc_macro_item_for_doc(tr.def_id) {
5855 return None;
5858 }
5859 Some(tr.def_id)
5860 })
5861 .collect()
5862 });
5863 self.r.doc_link_traits_in_scope = doc_link_traits_in_scope;
5864 }
5865 }
5866
5867 fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finalize: Finalize) {
5868 if let Some(seg) = path.first()
5870 && seg.ident.name == kw::PathRoot
5871 {
5872 return;
5873 }
5874
5875 if finalize.path_span.from_expansion()
5876 || path.iter().any(|seg| seg.ident.span.from_expansion())
5877 {
5878 return;
5879 }
5880
5881 let end_pos =
5882 path.iter().position(|seg| seg.has_generic_args).map_or(path.len(), |pos| pos + 1);
5883 let unqualified = path[..end_pos].iter().enumerate().skip(1).rev().find_map(|(i, seg)| {
5884 let ns = if i + 1 == path.len() { ns } else { TypeNS };
5893 let res = self.r.partial_res_map.get(&seg.id?)?.full_res()?;
5894 let binding = self.resolve_ident_in_lexical_scope(seg.ident, ns, None, None)?;
5895 if let LateDecl::Decl(binding) = binding
5898 && binding.descent_to_ambiguity().is_some()
5899 {
5900 return None;
5901 }
5902 (res == binding.res()).then_some((seg, binding))
5903 });
5904
5905 if let Some((seg, decl)) = unqualified {
5906 self.r.potentially_unnecessary_qualifications.push(UnnecessaryQualification {
5907 decl,
5908 node_id: finalize.node_id,
5909 path_span: finalize.path_span,
5910 removal_span: path[0].ident.span.until(seg.ident.span),
5911 });
5912 }
5913 }
5914
5915 fn resolve_define_opaques(&mut self, define_opaque: &Option<ThinVec<(NodeId, Path)>>) {
5916 if let Some(define_opaque) = define_opaque {
5917 for (id, path) in define_opaque {
5918 self.smart_resolve_path(*id, &None, path, PathSource::DefineOpaques);
5919 }
5920 }
5921 }
5922
5923 fn resolve_eii(&mut self, eii_impl: Option<&EiiImpl>) {
5924 if let Some(EiiImpl { node_id, eii_macro_path, known_eii_macro_resolution, .. }) = eii_impl
5925 {
5926 if let Some(target) = known_eii_macro_resolution {
5929 self.smart_resolve_path(*node_id, &None, target, PathSource::ExternItemImpl);
5930 } else {
5931 self.smart_resolve_path(*node_id, &None, &eii_macro_path, PathSource::Macro);
5932 }
5933 }
5934 }
5935}
5936
5937struct ItemInfoCollector<'a, 'ra, 'tcx> {
5941 r: &'a mut Resolver<'ra, 'tcx>,
5942}
5943
5944impl ItemInfoCollector<'_, '_, '_> {
5945 fn collect_fn_info(&mut self, decl: &FnDecl, id: NodeId) {
5946 self.r
5947 .delegation_fn_sigs
5948 .insert(self.r.owner_def_id(id), DelegationFnSig { has_self: decl.has_self() });
5949 }
5950}
5951
5952fn required_generic_args_suggestion(generics: &ast::Generics) -> Option<String> {
5953 let required = generics
5954 .params
5955 .iter()
5956 .filter_map(|param| match ¶m.kind {
5957 ast::GenericParamKind::Lifetime => Some("'_"),
5958 ast::GenericParamKind::Type { default } => {
5959 if default.is_none() {
5960 Some("_")
5961 } else {
5962 None
5963 }
5964 }
5965 ast::GenericParamKind::Const { default, .. } => {
5966 if default.is_none() {
5967 Some("_")
5968 } else {
5969 None
5970 }
5971 }
5972 })
5973 .collect::<Vec<_>>();
5974
5975 if required.is_empty() { None } else { Some(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", required.join(", ")))
})format!("<{}>", required.join(", "))) }
5976}
5977
5978impl Visitor<'_> for ItemInfoCollector<'_, '_, '_> {
5979 fn visit_item(&mut self, item: &Item) {
5980 if let Some(generics) = item.opt_generics() {
5981 let def_id = self.r.owner_def_id(item.id);
5982 let count = generics
5983 .params
5984 .iter()
5985 .filter(|param| #[allow(non_exhaustive_omitted_patterns)] match param.kind {
ast::GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
5986 .count();
5987 self.r.item_generics_num_lifetimes.insert(def_id, count);
5988 }
5989
5990 match &item.kind {
5991 ItemKind::Fn(Fn { sig, .. }) => {
5992 self.collect_fn_info(&sig.decl, item.id);
5993 }
5994
5995 ItemKind::ForeignMod(ForeignMod { items, .. }) => {
5996 for foreign_item in items {
5997 if let ForeignItemKind::Fn(Fn { sig, .. }) = &foreign_item.kind {
5998 self.collect_fn_info(&sig.decl, foreign_item.id);
5999 }
6000 }
6001 }
6002
6003 ItemKind::Mod(..)
6004 | ItemKind::Static(..)
6005 | ItemKind::ConstBlock(..)
6006 | ItemKind::MacroDef(..)
6007 | ItemKind::GlobalAsm(..)
6008 | ItemKind::MacCall(..)
6009 | ItemKind::Use(..)
6010 | ItemKind::ExternCrate(..)
6011 | ItemKind::DelegationMac(..)
6012 | ItemKind::TyAlias(..)
6013 | ItemKind::Const(..)
6014 | ItemKind::Enum(..)
6015 | ItemKind::Struct(..)
6016 | ItemKind::Union(..)
6017 | ItemKind::Impl(..)
6018 | ItemKind::Trait(..)
6019 | ItemKind::TraitAlias(..)
6020 | ItemKind::TestBinderConstraints(..) => {}
6021 ItemKind::Delegation(..) => {
6022 }
6027 }
6028 visit::walk_item(self, item)
6029 }
6030
6031 fn visit_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
6032 if let AssocItemKind::Fn(Fn { sig, .. }) = &item.kind {
6033 self.collect_fn_info(&sig.decl, item.id);
6034 }
6035
6036 if let AssocItemKind::Type(ast::TyAlias { generics, .. }) = &item.kind {
6037 let def_id = self.r.owner_def_id(item.id);
6038 if let Some(suggestion) = required_generic_args_suggestion(generics) {
6039 self.r.item_required_generic_args_suggestions.insert(def_id, suggestion);
6040 }
6041 }
6042 visit::walk_assoc_item(self, item, ctxt);
6043 }
6044}
6045
6046impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
6047 pub(crate) fn late_resolve_crate<'ast>(
6049 &mut self,
6050 krate: &'ast Crate,
6051 ) -> (Vec<&'ast Item>, Vec<UseError<'tcx>>) {
6052 with_owner(self, CRATE_NODE_ID, |this| {
6053 let mut info_collector = ItemInfoCollector { r: this };
6054 visit::walk_crate(&mut info_collector, krate);
6055 let mut late_resolution_visitor = LateResolutionVisitor::new(this);
6056 late_resolution_visitor
6057 .resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID));
6058 visit::walk_crate(&mut late_resolution_visitor, krate);
6059 let LateResolutionVisitor { use_injections, diag_metadata, use_items, .. } =
6060 late_resolution_visitor;
6061 for (id, span) in diag_metadata.unused_labels.iter() {
6062 this.lint_buffer.buffer_lint(
6063 UNUSED_LABELS,
6064 *id,
6065 *span,
6066 crate::diagnostics::UnusedLabel,
6067 );
6068 }
6069 (use_items, use_injections)
6070 })
6071 }
6072}
6073
6074fn def_id_matches_path(tcx: TyCtxt<'_>, mut def_id: DefId, expected_path: &[&str]) -> bool {
6076 let mut path = expected_path.iter().rev();
6077 while let (Some(parent), Some(next_step)) = (tcx.opt_parent(def_id), path.next()) {
6078 if !tcx.opt_item_name(def_id).is_some_and(|n| n.as_str() == *next_step) {
6079 return false;
6080 }
6081 def_id = parent;
6082 }
6083 true
6084}