Skip to main content

rustc_resolve/
ident.rs

1use std::ops::ControlFlow;
2
3use Determinacy::*;
4use Namespace::*;
5use rustc_ast::{self as ast, NodeId};
6use rustc_errors::ErrorGuaranteed;
7use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PerNS};
8use rustc_lint_defs::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
9use rustc_middle::middle::resolve::PartialRes;
10use rustc_session::diagnostics::feature_err;
11use rustc_span::edition::Edition;
12use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
13use rustc_span::{Ident, Span, bug, kw, span_bug, sym};
14use smallvec::SmallVec;
15use tracing::{debug, instrument};
16
17use crate::diagnostics::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
18use crate::hygiene::Macros20NormalizedSyntaxContext;
19use crate::imports::{Import, NameResolution, cycle_detection};
20use crate::late::{
21    ConstantHasGenerics, DiagMetadata, NoConstantGenericsReason, PathSource, Rib, RibKind,
22};
23use crate::macros::{MacroRulesScope, sub_namespace_match};
24use crate::{
25    AmbiguityError, AmbiguityKind, AmbiguityWarning, BindingKey, CmResolver, Decl, DeclKind,
26    Determinacy, ExternModule, Finalize, IdentKey, ImportKind, ImportSummary, LateDecl,
27    LocalModule, Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, PrivacyError,
28    Res, ResolutionError, Resolver, Scope, ScopeSet, Segment, Stage, Symbol, Used, diagnostics,
29    module_to_string,
30};
31
32#[derive(#[automatically_derived]
impl ::core::marker::Copy for UsePrelude { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for UsePrelude { }
#[automatically_derived]
impl ::core::clone::Clone for UsePrelude {
    #[inline]
    fn clone(&self) -> Self { *self }
}Clone)]
33pub enum UsePrelude {
34    No,
35    Yes,
36}
37
38impl From<UsePrelude> for bool {
39    fn from(up: UsePrelude) -> bool {
40        #[allow(non_exhaustive_omitted_patterns)] match up {
    UsePrelude::Yes => true,
    _ => false,
}matches!(up, UsePrelude::Yes)
41    }
42}
43
44#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Shadowing {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Shadowing::Restricted => "Restricted",
                Shadowing::Unrestricted => "Unrestricted",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Shadowing { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Shadowing {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Shadowing { }
#[automatically_derived]
impl ::core::clone::Clone for Shadowing {
    #[inline]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Shadowing { }Copy)]
45enum Shadowing {
46    Restricted,
47    Unrestricted,
48}
49
50impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
51    /// A generic scope visitor.
52    /// Visits scopes in order to resolve some identifier in them or perform other actions.
53    /// If the callback returns `Some` result, we stop visiting scopes and return it.
54    pub(crate) fn visit_scopes<'r, T>(
55        mut self: CmResolver<'r, 'ra, 'tcx>,
56        scope_set: ScopeSet<'ra>,
57        parent_scope: &ParentScope<'ra>,
58        mut ctxt: Macros20NormalizedSyntaxContext,
59        orig_ident_span: Span,
60        derive_fallback_lint_id: Option<NodeId>,
61        mut visitor: impl FnMut(
62            CmResolver<'_, 'ra, 'tcx>,
63            Scope<'ra>,
64            UsePrelude,
65            Macros20NormalizedSyntaxContext,
66        ) -> ControlFlow<T>,
67    ) -> Option<T> {
68        // General principles:
69        // 1. Not controlled (user-defined) names should have higher priority than controlled names
70        //    built into the language or standard library. This way we can add new names into the
71        //    language or standard library without breaking user code.
72        // 2. "Closed set" below means new names cannot appear after the current resolution attempt.
73        // Places to search (in order of decreasing priority):
74        // (Type NS)
75        // 1. FIXME: Ribs (type parameters), there's no necessary infrastructure yet
76        //    (open set, not controlled).
77        // 2. Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
78        //    (open, not controlled).
79        // 3. Extern prelude (open, the open part is from macro expansions, not controlled).
80        // 4. Tool modules (closed, controlled right now, but not in the future).
81        // 5. Standard library prelude (de-facto closed, controlled).
82        // 6. Language prelude (closed, controlled).
83        // (Value NS)
84        // 1. FIXME: Ribs (local variables), there's no necessary infrastructure yet
85        //    (open set, not controlled).
86        // 2. Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
87        //    (open, not controlled).
88        // 3. Standard library prelude (de-facto closed, controlled).
89        // (Macro NS)
90        // 1-3. Derive helpers (open, not controlled). All ambiguities with other names
91        //    are currently reported as errors. They should be higher in priority than preludes
92        //    and probably even names in modules according to the "general principles" above. They
93        //    also should be subject to restricted shadowing because are effectively produced by
94        //    derives (you need to resolve the derive first to add helpers into scope), but they
95        //    should be available before the derive is expanded for compatibility.
96        //    It's mess in general, so we are being conservative for now.
97        // 1-3. `macro_rules` (open, not controlled), loop through `macro_rules` scopes. Have higher
98        //    priority than prelude macros, but create ambiguities with macros in modules.
99        // 1-3. Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
100        //    (open, not controlled). Have higher priority than prelude macros, but create
101        //    ambiguities with `macro_rules`.
102        // 4. `macro_use` prelude (open, the open part is from macro expansions, not controlled).
103        // 4a. User-defined prelude from macro-use
104        //    (open, the open part is from macro expansions, not controlled).
105        // 4b. "Standard library prelude" part implemented through `macro-use` (closed, controlled).
106        // 4c. Standard library prelude (de-facto closed, controlled).
107        // 6. Language prelude: builtin attributes (closed, controlled).
108
109        let (ns, macro_kind) = match scope_set {
110            ScopeSet::All(ns)
111            | ScopeSet::Module(ns, _)
112            | ScopeSet::ModuleAndExternPrelude(ns, _) => (ns, None),
113            ScopeSet::ExternPrelude => (TypeNS, None),
114            ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind)),
115        };
116        let module = match scope_set {
117            // Start with the specified module.
118            ScopeSet::Module(_, module) | ScopeSet::ModuleAndExternPrelude(_, module) => module,
119            // Jump out of trait or enum modules, they do not act as scopes.
120            _ => parent_scope.module.nearest_item_scope(),
121        };
122        let module_only = #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::Module(..) => true,
    _ => false,
}matches!(scope_set, ScopeSet::Module(..));
123        let module_and_extern_prelude = #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::ModuleAndExternPrelude(..) => true,
    _ => false,
}matches!(scope_set, ScopeSet::ModuleAndExternPrelude(..));
124        let extern_prelude = #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::ExternPrelude => true,
    _ => false,
}matches!(scope_set, ScopeSet::ExternPrelude);
125        let mut scope = match ns {
126            _ if module_only || module_and_extern_prelude => Scope::ModuleNonGlobs(module, None),
127            _ if extern_prelude => Scope::ExternPreludeItems,
128            TypeNS | ValueNS => Scope::ModuleNonGlobs(module, None),
129            MacroNS => Scope::DeriveHelpers(parent_scope.expansion),
130        };
131        let mut use_prelude = !module.no_implicit_prelude;
132
133        loop {
134            let visit = match scope {
135                // Derive helpers are not in scope when resolving derives in the same container.
136                Scope::DeriveHelpers(expn_id) => {
137                    !(expn_id == parent_scope.expansion && macro_kind == Some(MacroKind::Derive))
138                }
139                Scope::DeriveHelpersCompat => true,
140                Scope::MacroRules(macro_rules_scope) => {
141                    // Use "path compression" on `macro_rules` scope chains. This is an optimization
142                    // used to avoid long scope chains, see the comments on `MacroRulesScopeRef`.
143                    // As another consequence of this optimization visitors never observe invocation
144                    // scopes for macros that were already expanded.
145                    // We need to lock this scope, such that the compression is always final.
146                    let mut write_scope = macro_rules_scope.write();
147                    let mut scope = *write_scope;
148                    while let MacroRulesScope::Invocation(invoc_id) = scope {
149                        if let Some(next) = self.output_macro_rules_scopes.get(&invoc_id) {
150                            scope = *next.borrow();
151                            *write_scope = scope;
152                        } else {
153                            break;
154                        }
155                    }
156                    true
157                }
158                Scope::ModuleNonGlobs(..) | Scope::ModuleGlobs(..) => true,
159                Scope::MacroUsePrelude => use_prelude || orig_ident_span.is_rust_2015(),
160                Scope::BuiltinAttrs => true,
161                Scope::ExternPreludeItems | Scope::ExternPreludeFlags => {
162                    use_prelude || module_and_extern_prelude || extern_prelude
163                }
164                Scope::ToolAttributePrelude => use_prelude,
165                Scope::StdLibPrelude => use_prelude || ns == MacroNS,
166                Scope::BuiltinTypes => true,
167            };
168
169            if visit {
170                let use_prelude = if use_prelude { UsePrelude::Yes } else { UsePrelude::No };
171                if let ControlFlow::Break(break_result) =
172                    visitor(self.reborrow(), scope, use_prelude, ctxt)
173                {
174                    return Some(break_result);
175                }
176            }
177
178            scope = match scope {
179                Scope::DeriveHelpers(LocalExpnId::ROOT) => Scope::DeriveHelpersCompat,
180                Scope::DeriveHelpers(expn_id) => {
181                    // Derive helpers are not visible to code generated by bang or derive macros.
182                    let expn_data = expn_id.expn_data();
183                    match expn_data.kind {
184                        ExpnKind::Root
185                        | ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
186                            Scope::DeriveHelpersCompat
187                        }
188                        _ => Scope::DeriveHelpers(expn_data.parent.expect_local()),
189                    }
190                }
191                Scope::DeriveHelpersCompat => Scope::MacroRules(parent_scope.macro_rules),
192                Scope::MacroRules(macro_rules_scope) => match *macro_rules_scope.read() {
193                    MacroRulesScope::Def(binding) => {
194                        Scope::MacroRules(binding.parent_macro_rules_scope)
195                    }
196                    MacroRulesScope::Invocation(invoc_id) => {
197                        Scope::MacroRules(self.invocation_parent_scopes[&invoc_id].macro_rules)
198                    }
199                    MacroRulesScope::Empty => Scope::ModuleNonGlobs(module, None),
200                },
201                Scope::ModuleNonGlobs(module, lint_id) => Scope::ModuleGlobs(module, lint_id),
202                Scope::ModuleGlobs(..) if module_only => break,
203                Scope::ModuleGlobs(..) if module_and_extern_prelude => match ns {
204                    TypeNS => {
205                        ctxt.update_unchecked(|ctxt| ctxt.adjust(ExpnId::root()));
206                        Scope::ExternPreludeItems
207                    }
208                    ValueNS | MacroNS => break,
209                },
210                Scope::ModuleGlobs(module, prev_lint_id) => {
211                    use_prelude = !module.no_implicit_prelude;
212                    match self.hygienic_lexical_parent(module, &mut ctxt, derive_fallback_lint_id) {
213                        Some((parent_module, lint_id)) => {
214                            Scope::ModuleNonGlobs(parent_module, lint_id.or(prev_lint_id))
215                        }
216                        None => {
217                            ctxt.update_unchecked(|ctxt| ctxt.adjust(ExpnId::root()));
218                            match ns {
219                                TypeNS => Scope::ExternPreludeItems,
220                                ValueNS => Scope::StdLibPrelude,
221                                MacroNS => Scope::MacroUsePrelude,
222                            }
223                        }
224                    }
225                }
226                Scope::MacroUsePrelude => Scope::StdLibPrelude,
227                Scope::BuiltinAttrs => break, // nowhere else to search
228                Scope::ExternPreludeItems => Scope::ExternPreludeFlags,
229                Scope::ExternPreludeFlags if module_and_extern_prelude || extern_prelude => break,
230                Scope::ExternPreludeFlags => Scope::ToolAttributePrelude,
231                Scope::ToolAttributePrelude => Scope::StdLibPrelude,
232                Scope::StdLibPrelude => match ns {
233                    TypeNS => Scope::BuiltinTypes,
234                    ValueNS => break, // nowhere else to search
235                    MacroNS => Scope::BuiltinAttrs,
236                },
237                Scope::BuiltinTypes => break, // nowhere else to search
238            };
239        }
240
241        None
242    }
243
244    fn hygienic_lexical_parent(
245        &self,
246        module: Module<'ra>,
247        ctxt: &mut Macros20NormalizedSyntaxContext,
248        derive_fallback_lint_id: Option<NodeId>,
249    ) -> Option<(Module<'ra>, Option<NodeId>)> {
250        if !module.expansion.outer_expn_is_descendant_of(**ctxt) {
251            let expn_id = ctxt.update_unchecked(|ctxt| ctxt.remove_mark());
252            return Some((self.expn_def_scope(expn_id), None));
253        }
254
255        if let ModuleKind::Block = module.kind {
256            return Some((module.parent.unwrap().nearest_item_scope(), None));
257        }
258
259        // We need to support the next case under a deprecation warning
260        // ```
261        // struct MyStruct;
262        // ---- begin: this comes from a proc macro derive
263        // mod implementation_details {
264        //     // Note that `MyStruct` is not in scope here.
265        //     impl SomeTrait for MyStruct { ... }
266        // }
267        // ---- end
268        // ```
269        // So we have to fall back to the module's parent during lexical resolution in this case.
270        if derive_fallback_lint_id.is_some()
271            && let Some(parent) = module.parent
272            // Inner module is inside the macro
273            && module.expansion != parent.expansion
274            // Parent module is outside of the macro
275            && module.expansion.is_descendant_of(parent.expansion)
276            // The macro is a proc macro derive
277            && let Some(def_id) = module.expansion.expn_data().macro_def_id
278        {
279            let ext = self.get_macro_by_def_id(def_id);
280            if ext.builtin_name.is_none()
281                && ext.macro_kinds() == MacroKinds::DERIVE
282                && parent.expansion.outer_expn_is_descendant_of(**ctxt)
283            {
284                return Some((parent, derive_fallback_lint_id));
285            }
286        }
287
288        None
289    }
290
291    /// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.
292    /// More specifically, we proceed up the hierarchy of scopes and return the binding for
293    /// `ident` in the first scope that defines it (or None if no scopes define it).
294    ///
295    /// A block's items are above its local variables in the scope hierarchy, regardless of where
296    /// the items are defined in the block. For example,
297    /// ```rust
298    /// fn f() {
299    ///    g(); // Since there are no local variables in scope yet, this resolves to the item.
300    ///    let g = || {};
301    ///    fn g() {}
302    ///    g(); // This resolves to the local variable `g` since it shadows the item.
303    /// }
304    /// ```
305    ///
306    /// Invariant: This must only be called during main resolution, not during
307    /// import resolution.
308    {}
#[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_ident_in_lexical_scope",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(308u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::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("ns")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ns");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_scope");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("finalize")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("finalize");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_decl")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_decl");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("diag_metadata")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("diag_metadata");
                                                        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(&ns)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_scope)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&finalize)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_decl)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&diag_metadata)
                                                            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: Option<LateDecl<'ra>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let orig_ident = ident;
            let (general_span, normalized_span) =
                if ident.name == kw::SelfUpper {
                    let empty_span =
                        ident.span.with_ctxt(SyntaxContext::root());
                    (empty_span, empty_span)
                } else if ns == TypeNS {
                    let normalized_span = ident.span.normalize_to_macros_2_0();
                    (normalized_span, normalized_span)
                } else {
                    (ident.span.normalize_to_macro_rules(),
                        ident.span.normalize_to_macros_2_0())
                };
            ident.span = general_span;
            let normalized_ident = Ident { span: normalized_span, ..ident };
            for (i, rib) in 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/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs:335",
                                        "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                        ::tracing_core::__macro_support::Option::Some(335u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                        ::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!("walk rib\n{0:?}",
                                                                    rib.bindings) as &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                let rib_ident =
                    if rib.kind.contains_params() {
                        normalized_ident
                    } else { ident };
                if let Some((original_rib_ident_def, res)) =
                        rib.bindings.get_key_value(&rib_ident) {
                    return Some(LateDecl::RibDef(self.validate_res_from_ribs(i,
                                    rib_ident, *res, finalize.map(|_| general_span),
                                    *original_rib_ident_def, ribs, diag_metadata)));
                } else if let RibKind::Block(Some(module)) = rib.kind &&
                        let Ok(binding) =
                            self.cm_mut().resolve_ident_in_scope_set(ident,
                                ScopeSet::Module(ns, module.to_module()), parent_scope,
                                finalize.map(|finalize|
                                        Finalize { used: Used::Scope, ..finalize }), ignore_decl,
                                None) {
                    return Some(LateDecl::Decl(binding));
                } else if let RibKind::Module(module) = rib.kind {
                    let parent_scope =
                        &ParentScope {
                                module: module.to_module(),
                                ..*parent_scope
                            };
                    let finalize =
                        finalize.map(|f| Finalize { stage: Stage::Late, ..f });
                    return self.cm_mut().resolve_ident_in_scope_set(orig_ident,
                                    ScopeSet::All(ns), parent_scope, finalize, ignore_decl,
                                    None).ok().map(LateDecl::Decl);
                }
                if let RibKind::MacroDefinition(def) = rib.kind &&
                        def == self.macro_def(ident.span.ctxt()) {
                    ident.span.remove_mark();
                }
            }
            ::core::panicking::panic("internal error: entered unreachable code")
        }
    }
}#[instrument(level = "debug", skip(self, ribs))]
309    pub(crate) fn resolve_ident_in_lexical_scope(
310        &mut self,
311        mut ident: Ident,
312        ns: Namespace,
313        parent_scope: &ParentScope<'ra>,
314        finalize: Option<Finalize>,
315        ribs: &[Rib<'ra>],
316        ignore_decl: Option<Decl<'ra>>,
317        diag_metadata: Option<&DiagMetadata<'_>>,
318    ) -> Option<LateDecl<'ra>> {
319        let orig_ident = ident;
320        let (general_span, normalized_span) = if ident.name == kw::SelfUpper {
321            // FIXME(jseyfried) improve `Self` hygiene
322            let empty_span = ident.span.with_ctxt(SyntaxContext::root());
323            (empty_span, empty_span)
324        } else if ns == TypeNS {
325            let normalized_span = ident.span.normalize_to_macros_2_0();
326            (normalized_span, normalized_span)
327        } else {
328            (ident.span.normalize_to_macro_rules(), ident.span.normalize_to_macros_2_0())
329        };
330        ident.span = general_span;
331        let normalized_ident = Ident { span: normalized_span, ..ident };
332
333        // Walk backwards up the ribs in scope.
334        for (i, rib) in ribs.iter().enumerate().rev() {
335            debug!("walk rib\n{:?}", rib.bindings);
336            // Use the rib kind to determine whether we are resolving parameters
337            // (macro 2.0 hygiene) or local variables (`macro_rules` hygiene).
338            let rib_ident = if rib.kind.contains_params() { normalized_ident } else { ident };
339            if let Some((original_rib_ident_def, res)) = rib.bindings.get_key_value(&rib_ident) {
340                // The ident resolves to a type parameter or local variable.
341                return Some(LateDecl::RibDef(self.validate_res_from_ribs(
342                    i,
343                    rib_ident,
344                    *res,
345                    finalize.map(|_| general_span),
346                    *original_rib_ident_def,
347                    ribs,
348                    diag_metadata,
349                )));
350            } else if let RibKind::Block(Some(module)) = rib.kind
351                && let Ok(binding) = self.cm_mut().resolve_ident_in_scope_set(
352                    ident,
353                    ScopeSet::Module(ns, module.to_module()),
354                    parent_scope,
355                    finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
356                    ignore_decl,
357                    None,
358                )
359            {
360                // The ident resolves to an item in a block.
361                return Some(LateDecl::Decl(binding));
362            } else if let RibKind::Module(module) = rib.kind {
363                // Encountered a module item, abandon ribs and look into that module and preludes.
364                let parent_scope = &ParentScope { module: module.to_module(), ..*parent_scope };
365                let finalize = finalize.map(|f| Finalize { stage: Stage::Late, ..f });
366                return self
367                    .cm_mut()
368                    .resolve_ident_in_scope_set(
369                        orig_ident,
370                        ScopeSet::All(ns),
371                        parent_scope,
372                        finalize,
373                        ignore_decl,
374                        None,
375                    )
376                    .ok()
377                    .map(LateDecl::Decl);
378            }
379
380            if let RibKind::MacroDefinition(def) = rib.kind
381                && def == self.macro_def(ident.span.ctxt())
382            {
383                // If an invocation of this macro created `ident`, give up on `ident`
384                // and switch to `ident`'s source from the macro definition.
385                ident.span.remove_mark();
386            }
387        }
388
389        unreachable!()
390    }
391
392    /// Resolve an identifier in the specified set of scopes.
393    pub(crate) fn resolve_ident_in_scope_set<'r>(
394        self: CmResolver<'r, 'ra, 'tcx>,
395        orig_ident: Ident,
396        scope_set: ScopeSet<'ra>,
397        parent_scope: &ParentScope<'ra>,
398        finalize: Option<Finalize>,
399        ignore_decl: Option<Decl<'ra>>,
400        ignore_import: Option<Import<'ra>>,
401    ) -> Result<Decl<'ra>, Determinacy> {
402        self.resolve_ident_in_scope_set_inner(
403            IdentKey::new(orig_ident),
404            orig_ident.span,
405            scope_set,
406            parent_scope,
407            finalize,
408            ignore_decl,
409            ignore_import,
410        )
411    }
412
413    fn resolve_ident_in_scope_set_inner<'r>(
414        self: CmResolver<'r, 'ra, 'tcx>,
415        ident: IdentKey,
416        orig_ident_span: Span,
417        scope_set: ScopeSet<'ra>,
418        parent_scope: &ParentScope<'ra>,
419        finalize: Option<Finalize>,
420        ignore_decl: Option<Decl<'ra>>,
421        ignore_import: Option<Import<'ra>>,
422    ) -> Result<Decl<'ra>, Determinacy> {
423        // Make sure `self`, `super` etc produce an error when passed to here.
424        if ident.name.is_path_segment_keyword() {
425            return Err(Determinacy::Determined);
426        }
427
428        let (ns, macro_kind) = match scope_set {
429            ScopeSet::All(ns)
430            | ScopeSet::Module(ns, _)
431            | ScopeSet::ModuleAndExternPrelude(ns, _) => (ns, None),
432            ScopeSet::ExternPrelude => (TypeNS, None),
433            ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind)),
434        };
435        let derive_fallback_lint_id = match finalize {
436            Some(Finalize { node_id, stage: Stage::Late, .. }) => Some(node_id),
437            _ => None,
438        };
439
440        // This is *the* result, resolution from the scope closest to the resolved identifier.
441        // However, sometimes this result is "weak" because it comes from a glob import or
442        // a macro expansion, and in this case it cannot shadow names from outer scopes, e.g.
443        // mod m { ... } // solution in outer scope
444        // {
445        //     use prefix::*; // imports another `m` - innermost solution
446        //                    // weak, cannot shadow the outer `m`, need to report ambiguity error
447        //     m::mac!();
448        // }
449        // So we have to save the innermost solution and continue searching in outer scopes
450        // to detect potential ambiguities.
451        let mut innermost_results: SmallVec<[(Decl<'_>, Scope<'_>); 2]> = SmallVec::new();
452        let mut determinacy = Determinacy::Determined;
453
454        // Go through all the scopes and try to resolve the name.
455        let break_result = self.visit_scopes(
456            scope_set,
457            parent_scope,
458            ident.ctxt,
459            orig_ident_span,
460            derive_fallback_lint_id,
461            |mut this, scope, use_prelude, ctxt| {
462                let ident = IdentKey { name: ident.name, ctxt };
463                let res = match this.reborrow().resolve_ident_in_scope(
464                    ident,
465                    orig_ident_span,
466                    ns,
467                    scope,
468                    use_prelude,
469                    scope_set,
470                    parent_scope,
471                    // Shadowed decls don't need to be marked as used or non-speculatively loaded.
472                    if innermost_results.is_empty() { finalize } else { None },
473                    ignore_decl,
474                    ignore_import,
475                ) {
476                    Ok(decl) => Ok(decl),
477                    // We can break with an error at this step, it means we cannot determine the
478                    // resolution right now, but we must block and wait until we can, instead of
479                    // considering outer scopes. Although there's no need to do that if we already
480                    // have a better solution.
481                    Err(ControlFlow::Break(determinacy)) if innermost_results.is_empty() => {
482                        return ControlFlow::Break(Err(determinacy));
483                    }
484                    Err(determinacy) => Err(determinacy.into_value()),
485                };
486                match res {
487                    Ok(decl) if sub_namespace_match(decl.macro_kinds(), macro_kind) => {
488                        // Below we report various ambiguity errors.
489                        // We do not need to report them if we are either in speculative resolution,
490                        // or in late resolution when everything is already imported and expanded
491                        // and no ambiguities exist.
492                        let import = match finalize {
493                            None | Some(Finalize { stage: Stage::Late, .. }) => {
494                                return ControlFlow::Break(Ok(decl));
495                            }
496                            Some(Finalize { import, .. }) => import,
497                        };
498                        this.get_mut().maybe_push_glob_vs_glob_vis_ambiguity(
499                            ident,
500                            orig_ident_span,
501                            decl,
502                            import,
503                        );
504
505                        if let Some(&(innermost_decl, _)) = innermost_results.first() {
506                            // Found another solution, if the first one was "weak", report an error.
507                            if this.get_mut().maybe_push_ambiguity(
508                                ident,
509                                orig_ident_span,
510                                ns,
511                                scope_set,
512                                parent_scope,
513                                decl,
514                                scope,
515                                &innermost_results,
516                                import,
517                            ) {
518                                // No need to search for more potential ambiguities, one is enough.
519                                return ControlFlow::Break(Ok(innermost_decl));
520                            }
521                        }
522
523                        innermost_results.push((decl, scope));
524                    }
525                    Ok(_) | Err(Determinacy::Determined) => {}
526                    Err(Determinacy::Undetermined) => determinacy = Determinacy::Undetermined,
527                }
528
529                ControlFlow::Continue(())
530            },
531        );
532
533        // Scope visiting returned some result early.
534        if let Some(break_result) = break_result {
535            return break_result;
536        }
537
538        // Scope visiting walked all the scopes and maybe found something in one of them.
539        match innermost_results.first() {
540            Some(&(decl, ..)) => Ok(decl),
541            None => Err(determinacy),
542        }
543    }
544
545    fn resolve_ident_in_scope<'r>(
546        mut self: CmResolver<'r, 'ra, 'tcx>,
547        ident: IdentKey,
548        orig_ident_span: Span,
549        ns: Namespace,
550        scope: Scope<'ra>,
551        use_prelude: UsePrelude,
552        scope_set: ScopeSet<'ra>,
553        parent_scope: &ParentScope<'ra>,
554        finalize: Option<Finalize>,
555        ignore_decl: Option<Decl<'ra>>,
556        ignore_import: Option<Import<'ra>>,
557    ) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
558        let ret = match scope {
559            Scope::DeriveHelpers(expn_id) => {
560                if let Some(decl) = self
561                    .helper_attrs
562                    .get(&expn_id)
563                    .and_then(|attrs| attrs.iter().rfind(|(i, ..)| ident == *i).map(|(.., d)| *d))
564                {
565                    Ok(decl)
566                } else {
567                    Err(Determinacy::Determined)
568                }
569            }
570            Scope::DeriveHelpersCompat => {
571                let mut result = Err(Determinacy::Determined);
572                for derive in parent_scope.derives {
573                    let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
574                    match self.reborrow().resolve_derive_macro_path(
575                        derive,
576                        parent_scope,
577                        false,
578                        ignore_import,
579                    ) {
580                        Ok((Some(ext), _)) => {
581                            if ext.helper_attrs.contains(&ident.name) {
582                                let decl = self.arenas.new_pub_def_decl(
583                                    Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat),
584                                    derive.span,
585                                    LocalExpnId::ROOT,
586                                );
587                                result = Ok(decl);
588                                break;
589                            }
590                        }
591                        Ok(_) | Err(Determinacy::Determined) => {}
592                        Err(Determinacy::Undetermined) => result = Err(Determinacy::Undetermined),
593                    }
594                }
595                result
596            }
597            Scope::MacroRules(macro_rules_scope) => match *macro_rules_scope.read() {
598                MacroRulesScope::Def(macro_rules_def) if ident == macro_rules_def.ident => {
599                    Ok(macro_rules_def.decl)
600                }
601                MacroRulesScope::Invocation(_) => Err(Determinacy::Undetermined),
602                _ => Err(Determinacy::Determined),
603            },
604            Scope::ModuleNonGlobs(module, derive_fallback_lint_id) => {
605                let (adjusted_parent_scope, adjusted_finalize) = if #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::Module(..) | ScopeSet::ModuleAndExternPrelude(..) => true,
    _ => false,
}matches!(
606                    scope_set,
607                    ScopeSet::Module(..) | ScopeSet::ModuleAndExternPrelude(..)
608                ) {
609                    (parent_scope, finalize)
610                } else {
611                    (
612                        &ParentScope { module, ..*parent_scope },
613                        finalize.map(|f| Finalize { used: Used::Scope, ..f }),
614                    )
615                };
616                let shadowing = if #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::Module(..) => true,
    _ => false,
}matches!(scope_set, ScopeSet::Module(..)) {
617                    Shadowing::Unrestricted
618                } else {
619                    Shadowing::Restricted
620                };
621                let decl = if module.is_local() {
622                    self.reborrow().resolve_ident_in_local_module_non_globs_unadjusted(
623                        module.expect_local(),
624                        ident,
625                        orig_ident_span,
626                        ns,
627                        adjusted_parent_scope,
628                        shadowing,
629                        adjusted_finalize,
630                        ignore_decl,
631                        ignore_import,
632                    )
633                } else {
634                    self.reborrow().resolve_ident_in_extern_module_non_globs_unadjusted(
635                        module.expect_extern(),
636                        ident,
637                        orig_ident_span,
638                        ns,
639                        adjusted_parent_scope,
640                        shadowing,
641                        adjusted_finalize,
642                        ignore_decl,
643                    )
644                };
645
646                match decl {
647                    Ok(decl) => {
648                        if let Some(lint_id) = derive_fallback_lint_id {
649                            self.get_mut().lint_buffer.buffer_lint(
650                                PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
651                                lint_id,
652                                orig_ident_span,
653                                diagnostics::ProcMacroDeriveResolutionFallback {
654                                    span: orig_ident_span,
655                                    ns_descr: ns.descr(),
656                                    ident: ident.name,
657                                },
658                            );
659                        }
660                        Ok(decl)
661                    }
662                    Err(ControlFlow::Continue(determinacy)) => Err(determinacy),
663                    Err(ControlFlow::Break(..)) => return decl,
664                }
665            }
666            Scope::ModuleGlobs(module, _) if !module.is_local() => {
667                // Fast path: external module decoding only creates non-glob declarations.
668                Err(Determined)
669            }
670            Scope::ModuleGlobs(module, derive_fallback_lint_id) => {
671                let (adjusted_parent_scope, adjusted_finalize) = if #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::Module(..) | ScopeSet::ModuleAndExternPrelude(..) => true,
    _ => false,
}matches!(
672                    scope_set,
673                    ScopeSet::Module(..) | ScopeSet::ModuleAndExternPrelude(..)
674                ) {
675                    (parent_scope, finalize)
676                } else {
677                    (
678                        &ParentScope { module, ..*parent_scope },
679                        finalize.map(|f| Finalize { used: Used::Scope, ..f }),
680                    )
681                };
682                let binding = self.reborrow().resolve_ident_in_module_globs_unadjusted(
683                    module.expect_local(),
684                    ident,
685                    orig_ident_span,
686                    ns,
687                    adjusted_parent_scope,
688                    if #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::Module(..) => true,
    _ => false,
}matches!(scope_set, ScopeSet::Module(..)) {
689                        Shadowing::Unrestricted
690                    } else {
691                        Shadowing::Restricted
692                    },
693                    adjusted_finalize,
694                    ignore_decl,
695                    ignore_import,
696                );
697                match binding {
698                    Ok(binding) => {
699                        if let Some(lint_id) = derive_fallback_lint_id {
700                            self.get_mut().lint_buffer.buffer_lint(
701                                PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
702                                lint_id,
703                                orig_ident_span,
704                                diagnostics::ProcMacroDeriveResolutionFallback {
705                                    span: orig_ident_span,
706                                    ns_descr: ns.descr(),
707                                    ident: ident.name,
708                                },
709                            );
710                        }
711                        Ok(binding)
712                    }
713                    Err(ControlFlow::Continue(determinacy)) => Err(determinacy),
714                    Err(ControlFlow::Break(..)) => return binding,
715                }
716            }
717            Scope::MacroUsePrelude => match self.macro_use_prelude.get(&ident.name).cloned() {
718                Some(decl) => Ok(decl),
719                None => {
720                    Err(Determinacy::determined(!self.graph_root.has_unexpanded_invocations(&self)))
721                }
722            },
723            Scope::BuiltinAttrs => match self.builtin_attr_decls.get(&ident.name) {
724                Some(decl) => Ok(*decl),
725                None => Err(Determinacy::Determined),
726            },
727            Scope::ExternPreludeItems => {
728                match self.reborrow().extern_prelude_get_item(
729                    ident,
730                    orig_ident_span,
731                    finalize.is_some(),
732                ) {
733                    Some(decl) => Ok(decl),
734                    None => Err(Determinacy::determined(
735                        !self.graph_root.has_unexpanded_invocations(&self),
736                    )),
737                }
738            }
739            Scope::ExternPreludeFlags => {
740                match self.extern_prelude_get_flag(ident, orig_ident_span, finalize.is_some()) {
741                    Some(decl) => Ok(decl),
742                    None => Err(Determinacy::Determined),
743                }
744            }
745            Scope::ToolAttributePrelude => match self.registered_attr_tool_decls.get(&ident) {
746                Some(decl) => Ok(*decl),
747                None => Err(Determinacy::Determined),
748            },
749            Scope::StdLibPrelude => {
750                let mut result = Err(Determinacy::Determined);
751                if let Some(prelude) = self.prelude
752                    && let Ok(decl) = self.reborrow().resolve_ident_in_scope_set_inner(
753                        ident,
754                        orig_ident_span,
755                        ScopeSet::Module(ns, prelude),
756                        parent_scope,
757                        None,
758                        ignore_decl,
759                        ignore_import,
760                    )
761                    && (#[allow(non_exhaustive_omitted_patterns)] match use_prelude {
    UsePrelude::Yes => true,
    _ => false,
}matches!(use_prelude, UsePrelude::Yes) || self.is_builtin_macro(decl.res()))
762                {
763                    result = Ok(decl)
764                }
765
766                result
767            }
768            Scope::BuiltinTypes => match self.builtin_type_decls.get(&ident.name) {
769                Some(decl) => {
770                    if #[allow(non_exhaustive_omitted_patterns)] match ident.name {
    sym::f16 => true,
    _ => false,
}matches!(ident.name, sym::f16)
771                        && !self.features.f16()
772                        && !orig_ident_span.allows_unstable(sym::f16)
773                        && finalize.is_some()
774                    {
775                        feature_err(
776                            self.tcx.sess,
777                            sym::f16,
778                            orig_ident_span,
779                            "the type `f16` is unstable",
780                        )
781                        .emit();
782                    }
783                    if #[allow(non_exhaustive_omitted_patterns)] match ident.name {
    sym::f128 => true,
    _ => false,
}matches!(ident.name, sym::f128)
784                        && !self.features.f128()
785                        && !orig_ident_span.allows_unstable(sym::f128)
786                        && finalize.is_some()
787                    {
788                        feature_err(
789                            self.tcx.sess,
790                            sym::f128,
791                            orig_ident_span,
792                            "the type `f128` is unstable",
793                        )
794                        .emit();
795                    }
796                    Ok(*decl)
797                }
798                None => Err(Determinacy::Determined),
799            },
800        };
801
802        ret.map_err(ControlFlow::Continue)
803    }
804
805    fn maybe_push_glob_vs_glob_vis_ambiguity(
806        &mut self,
807        ident: IdentKey,
808        orig_ident_span: Span,
809        decl: Decl<'ra>,
810        import: Option<ImportSummary>,
811    ) {
812        let Some(import) = import else { return };
813        let vis1 = self.import_decl_vis(decl, import);
814        let vis2 = self.import_decl_vis_ext(decl, import, true);
815        if vis1 != vis2 {
816            self.ambiguity_errors.push(AmbiguityError {
817                kind: AmbiguityKind::GlobVsGlob,
818                ambig_vis: Some((vis1, vis2)),
819                ident: ident.orig(orig_ident_span),
820                b1: decl.ambiguity_vis_max.get().unwrap_or(decl),
821                b2: decl.ambiguity_vis_min.get().unwrap_or(decl),
822                scope1: Scope::ModuleGlobs(decl.parent_module.unwrap(), None),
823                scope2: Scope::ModuleGlobs(decl.parent_module.unwrap(), None),
824                warning: Some(AmbiguityWarning::GlobImport),
825            });
826        }
827    }
828
829    fn maybe_push_ambiguity(
830        &mut self,
831        ident: IdentKey,
832        orig_ident_span: Span,
833        ns: Namespace,
834        scope_set: ScopeSet<'ra>,
835        parent_scope: &ParentScope<'ra>,
836        decl: Decl<'ra>,
837        scope: Scope<'ra>,
838        innermost_results: &[(Decl<'ra>, Scope<'ra>)],
839        import: Option<ImportSummary>,
840    ) -> bool {
841        let (innermost_decl, innermost_scope) = innermost_results[0];
842        let (res, innermost_res) = (decl.res(), innermost_decl.res());
843        let ambig_vis = if res != innermost_res {
844            None
845        } else if let Some(import) = import
846            && let vis1 = self.import_decl_vis(decl, import)
847            && let vis2 = self.import_decl_vis(innermost_decl, import)
848            && vis1 != vis2
849        {
850            Some((vis1, vis2))
851        } else {
852            return false;
853        };
854
855        // FIXME: Use `scope` instead of `res` to detect built-in attrs and derive helpers,
856        // it will exclude imports, make slightly more code legal, and will require lang approval.
857        let module_only = #[allow(non_exhaustive_omitted_patterns)] match scope_set {
    ScopeSet::Module(..) => true,
    _ => false,
}matches!(scope_set, ScopeSet::Module(..));
858        let is_builtin = |res| #[allow(non_exhaustive_omitted_patterns)] match res {
    Res::NonMacroAttr(NonMacroAttrKind::Builtin(..)) => true,
    _ => false,
}matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Builtin(..)));
859        let derive_helper = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper);
860        let derive_helper_compat = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat);
861
862        let ambiguity_error_kind = if is_builtin(innermost_res) || is_builtin(res) {
863            Some(AmbiguityKind::BuiltinAttr)
864        } else if innermost_res == derive_helper_compat {
865            Some(AmbiguityKind::DeriveHelper)
866        } else if res == derive_helper_compat && innermost_res != derive_helper {
867            ::rustc_span::macros::bug_impl(Some(orig_ident_span),
    format_args!("impossible inner resolution kind"), Location::caller())span_bug!(orig_ident_span, "impossible inner resolution kind")
868        } else if #[allow(non_exhaustive_omitted_patterns)] match innermost_scope {
    Scope::MacroRules(_) => true,
    _ => false,
}matches!(innermost_scope, Scope::MacroRules(_))
869            && #[allow(non_exhaustive_omitted_patterns)] match scope {
    Scope::ModuleNonGlobs(..) | Scope::ModuleGlobs(..) => true,
    _ => false,
}matches!(scope, Scope::ModuleNonGlobs(..) | Scope::ModuleGlobs(..))
870            && !self.disambiguate_macro_rules_vs_modularized(innermost_decl, decl)
871        {
872            Some(AmbiguityKind::MacroRulesVsModularized)
873        } else if #[allow(non_exhaustive_omitted_patterns)] match scope {
    Scope::MacroRules(_) => true,
    _ => false,
}matches!(scope, Scope::MacroRules(_))
874            && #[allow(non_exhaustive_omitted_patterns)] match innermost_scope {
    Scope::ModuleNonGlobs(..) | Scope::ModuleGlobs(..) => true,
    _ => false,
}matches!(innermost_scope, Scope::ModuleNonGlobs(..) | Scope::ModuleGlobs(..))
875        {
876            // should be impossible because of visitation order in
877            // visit_scopes
878            //
879            // we visit all macro_rules scopes (e.g. textual scope macros)
880            // before we visit any modules (e.g. path-based scope macros)
881            ::rustc_span::macros::bug_impl(Some(orig_ident_span),
    format_args!("ambiguous scoped macro resolutions with path-based scope resolution as first candidate"),
    Location::caller())span_bug!(
882                orig_ident_span,
883                "ambiguous scoped macro resolutions with path-based \
884                                        scope resolution as first candidate"
885            )
886        } else if innermost_decl.is_glob_import() {
887            Some(AmbiguityKind::GlobVsOuter)
888        } else if !module_only && innermost_decl.may_appear_after(parent_scope.expansion, decl) {
889            Some(AmbiguityKind::MoreExpandedVsOuter)
890        } else if innermost_decl.expansion != LocalExpnId::ROOT
891            && (!module_only || ns == MacroNS)
892            && let Scope::ModuleGlobs(m1, _) = scope
893            && let Scope::ModuleNonGlobs(m2, _) = innermost_scope
894            && m1 == m2
895        {
896            // FIXME: this error is too conservative and technically unnecessary now when module
897            // scope is split into two scopes, at least when not resolving in `ScopeSet::Module`,
898            // remove it with lang team approval.
899            Some(AmbiguityKind::GlobVsExpanded)
900        } else {
901            None
902        };
903
904        if let Some(kind) = ambiguity_error_kind {
905            // Skip ambiguity errors for extern flag bindings "overridden"
906            // by extern item bindings.
907            // FIXME: Remove with lang team approval.
908            let issue_145575_hack = #[allow(non_exhaustive_omitted_patterns)] match scope {
    Scope::ExternPreludeFlags => true,
    _ => false,
}matches!(scope, Scope::ExternPreludeFlags)
909                && innermost_results[1..]
910                    .iter()
911                    .any(|(b, s)| #[allow(non_exhaustive_omitted_patterns)] match s {
    Scope::ExternPreludeItems => true,
    _ => false,
}matches!(s, Scope::ExternPreludeItems) && *b != innermost_decl);
912            // Skip ambiguity errors for nonglob module bindings "overridden"
913            // by glob module bindings in the same module.
914            // FIXME: Remove with lang team approval.
915            let issue_149681_hack = match scope {
916                Scope::ModuleGlobs(m1, _)
917                    if innermost_results[1..]
918                        .iter()
919                        .any(|(_, s)| #[allow(non_exhaustive_omitted_patterns)] match *s {
    Scope::ModuleNonGlobs(m2, _) if m1 == m2 => true,
    _ => false,
}matches!(*s, Scope::ModuleNonGlobs(m2, _) if m1 == m2)) =>
920                {
921                    true
922                }
923                _ => false,
924            };
925
926            if issue_145575_hack || issue_149681_hack {
927                self.issue_145575_hack_applied = true;
928            } else {
929                // Turn ambiguity errors for core vs std panic into warnings.
930                // FIXME: Remove with lang team approval.
931                let is_issue_147319_hack = orig_ident_span.edition() <= Edition::Edition2024
932                    && #[allow(non_exhaustive_omitted_patterns)] match ident.name {
    sym::panic => true,
    _ => false,
}matches!(ident.name, sym::panic)
933                    && #[allow(non_exhaustive_omitted_patterns)] match scope {
    Scope::StdLibPrelude => true,
    _ => false,
}matches!(scope, Scope::StdLibPrelude)
934                    && #[allow(non_exhaustive_omitted_patterns)] match innermost_scope {
    Scope::ModuleGlobs(_, _) => true,
    _ => false,
}matches!(innermost_scope, Scope::ModuleGlobs(_, _))
935                    && ((self.is_specific_builtin_macro(res, sym::std_panic)
936                        && self.is_specific_builtin_macro(innermost_res, sym::core_panic))
937                        || (self.is_specific_builtin_macro(res, sym::core_panic)
938                            && self.is_specific_builtin_macro(innermost_res, sym::std_panic)));
939
940                let warning = if ambig_vis.is_some() {
941                    Some(AmbiguityWarning::GlobImport)
942                } else if is_issue_147319_hack {
943                    Some(AmbiguityWarning::PanicImport)
944                } else {
945                    None
946                };
947
948                self.ambiguity_errors.push(AmbiguityError {
949                    kind,
950                    ambig_vis,
951                    ident: ident.orig(orig_ident_span),
952                    b1: innermost_decl,
953                    b2: decl,
954                    scope1: innermost_scope,
955                    scope2: scope,
956                    warning,
957                });
958                return true;
959            }
960        }
961
962        false
963    }
964
965    {}
#[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("maybe_resolve_ident_in_module",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(965u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("module")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("module");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        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("ns")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ns");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_scope");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_import")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_import");
                                                        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(&module)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
                                                            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(&parent_scope)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_import)
                                                            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<Decl<'ra>, Determinacy> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.resolve_ident_in_module(module, ident, ns, parent_scope,
                None, None, ignore_import)
        }
    }
}#[instrument(level = "debug", skip(self))]
966    pub(crate) fn maybe_resolve_ident_in_module<'r>(
967        self: CmResolver<'r, 'ra, 'tcx>,
968        module: ModuleOrUniformRoot<'ra>,
969        ident: Ident,
970        ns: Namespace,
971        parent_scope: &ParentScope<'ra>,
972        ignore_import: Option<Import<'ra>>,
973    ) -> Result<Decl<'ra>, Determinacy> {
974        self.resolve_ident_in_module(module, ident, ns, parent_scope, None, None, ignore_import)
975    }
976
977    fn resolve_super_in_module(
978        &self,
979        ident: Ident,
980        module: Option<Module<'ra>>,
981        parent_scope: &ParentScope<'ra>,
982    ) -> Option<Module<'ra>> {
983        let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
984        module
985            .unwrap_or_else(|| self.resolve_self(&mut ctxt, parent_scope.module))
986            .parent
987            .map(|parent| self.resolve_self(&mut ctxt, parent))
988    }
989
990    pub(crate) fn path_root_is_crate_root(&self, ident: Ident) -> bool {
991        ident.name == kw::PathRoot && ident.span.is_rust_2015() && self.tcx.sess.is_rust_2015()
992    }
993
994    {}
#[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_ident_in_module",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(994u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("module")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("module");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        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("ns")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ns");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_scope");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("finalize")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("finalize");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_decl")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_decl");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_import")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_import");
                                                        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(&module)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
                                                            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(&parent_scope)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&finalize)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_decl)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_import)
                                                            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<Decl<'ra>, Determinacy> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            match module {
                ModuleOrUniformRoot::Module(module) => {
                    if ns == TypeNS {
                        if ident.name == kw::SelfLower {
                            return Ok(module.self_decl.unwrap());
                        }
                        if ident.name == kw::Super &&
                                let Some(module) =
                                    self.resolve_super_in_module(ident, Some(module),
                                        parent_scope) {
                            return Ok(module.self_decl.unwrap());
                        }
                    }
                    let (ident_key, def) =
                        IdentKey::new_adjusted(ident, module.expansion);
                    let adjusted_parent_scope =
                        match def {
                            Some(def) =>
                                ParentScope {
                                    module: self.expn_def_scope(def),
                                    ..*parent_scope
                                },
                            None => *parent_scope,
                        };
                    self.resolve_ident_in_scope_set_inner(ident_key, ident.span,
                        ScopeSet::Module(ns, module), &adjusted_parent_scope,
                        finalize, ignore_decl, ignore_import)
                }
                ModuleOrUniformRoot::OpenModule(sym) => {
                    if ns != TypeNS {
                        Err(Determined)
                    } else {
                        if ident.name == kw::SelfLower {
                            let res = Res::OpenMod(sym);
                            return Ok(self.arenas.new_pub_def_decl(res, ident.span,
                                        LocalExpnId::ROOT));
                        }
                        let open_ns_name =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}::{1}", sym.as_str(),
                                            ident.name))
                                });
                        let ns_ident =
                            IdentKey::with_root_ctxt(Symbol::intern(&open_ns_name));
                        match self.extern_prelude_get_flag(ns_ident, ident.span,
                                finalize.is_some()) {
                            Some(decl) => Ok(decl),
                            None => Err(Determined),
                        }
                    }
                }
                ModuleOrUniformRoot::ModuleAndExternPrelude(module) =>
                    self.resolve_ident_in_scope_set(ident,
                        ScopeSet::ModuleAndExternPrelude(ns, module), parent_scope,
                        finalize, ignore_decl, ignore_import),
                ModuleOrUniformRoot::ExternPrelude => {
                    if ns != TypeNS {
                        Err(Determined)
                    } else {
                        self.resolve_ident_in_scope_set_inner(IdentKey::new_adjusted(ident,
                                    ExpnId::root()).0, ident.span, ScopeSet::ExternPrelude,
                            parent_scope, finalize, ignore_decl, ignore_import)
                    }
                }
                ModuleOrUniformRoot::CurrentScope => {
                    if ns == TypeNS {
                        if ident.name == kw::SelfLower {
                            let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
                            let module =
                                self.resolve_self(&mut ctxt, parent_scope.module);
                            return Ok(module.self_decl.unwrap());
                        }
                        if ident.name == kw::Super &&
                                let Some(module) =
                                    self.resolve_super_in_module(ident, None, parent_scope) {
                            return Ok(module.self_decl.unwrap());
                        }
                        if ident.name == kw::Crate || ident.name == kw::DollarCrate
                                || self.path_root_is_crate_root(ident) {
                            let module = self.resolve_crate_root(ident);
                            return Ok(module.self_decl.unwrap());
                        }
                    }
                    self.resolve_ident_in_scope_set(ident, ScopeSet::All(ns),
                        parent_scope, finalize, ignore_decl, ignore_import)
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
995    pub(crate) fn resolve_ident_in_module<'r>(
996        self: CmResolver<'r, 'ra, 'tcx>,
997        module: ModuleOrUniformRoot<'ra>,
998        ident: Ident,
999        ns: Namespace,
1000        parent_scope: &ParentScope<'ra>,
1001        finalize: Option<Finalize>,
1002        ignore_decl: Option<Decl<'ra>>,
1003        ignore_import: Option<Import<'ra>>,
1004    ) -> Result<Decl<'ra>, Determinacy> {
1005        match module {
1006            ModuleOrUniformRoot::Module(module) => {
1007                if ns == TypeNS {
1008                    if ident.name == kw::SelfLower {
1009                        return Ok(module.self_decl.unwrap());
1010                    }
1011                    if ident.name == kw::Super
1012                        && let Some(module) =
1013                            self.resolve_super_in_module(ident, Some(module), parent_scope)
1014                    {
1015                        return Ok(module.self_decl.unwrap());
1016                    }
1017                }
1018
1019                let (ident_key, def) = IdentKey::new_adjusted(ident, module.expansion);
1020                let adjusted_parent_scope = match def {
1021                    Some(def) => ParentScope { module: self.expn_def_scope(def), ..*parent_scope },
1022                    None => *parent_scope,
1023                };
1024                self.resolve_ident_in_scope_set_inner(
1025                    ident_key,
1026                    ident.span,
1027                    ScopeSet::Module(ns, module),
1028                    &adjusted_parent_scope,
1029                    finalize,
1030                    ignore_decl,
1031                    ignore_import,
1032                )
1033            }
1034            ModuleOrUniformRoot::OpenModule(sym) => {
1035                if ns != TypeNS {
1036                    Err(Determined)
1037                } else {
1038                    if ident.name == kw::SelfLower {
1039                        let res = Res::OpenMod(sym);
1040                        return Ok(self.arenas.new_pub_def_decl(
1041                            res,
1042                            ident.span,
1043                            LocalExpnId::ROOT,
1044                        ));
1045                    }
1046
1047                    let open_ns_name = format!("{}::{}", sym.as_str(), ident.name);
1048                    let ns_ident = IdentKey::with_root_ctxt(Symbol::intern(&open_ns_name));
1049                    match self.extern_prelude_get_flag(ns_ident, ident.span, finalize.is_some()) {
1050                        Some(decl) => Ok(decl),
1051                        None => Err(Determined),
1052                    }
1053                }
1054            }
1055            ModuleOrUniformRoot::ModuleAndExternPrelude(module) => self.resolve_ident_in_scope_set(
1056                ident,
1057                ScopeSet::ModuleAndExternPrelude(ns, module),
1058                parent_scope,
1059                finalize,
1060                ignore_decl,
1061                ignore_import,
1062            ),
1063            ModuleOrUniformRoot::ExternPrelude => {
1064                if ns != TypeNS {
1065                    Err(Determined)
1066                } else {
1067                    self.resolve_ident_in_scope_set_inner(
1068                        IdentKey::new_adjusted(ident, ExpnId::root()).0,
1069                        ident.span,
1070                        ScopeSet::ExternPrelude,
1071                        parent_scope,
1072                        finalize,
1073                        ignore_decl,
1074                        ignore_import,
1075                    )
1076                }
1077            }
1078            ModuleOrUniformRoot::CurrentScope => {
1079                if ns == TypeNS {
1080                    if ident.name == kw::SelfLower {
1081                        let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1082                        let module = self.resolve_self(&mut ctxt, parent_scope.module);
1083                        return Ok(module.self_decl.unwrap());
1084                    }
1085                    if ident.name == kw::Super
1086                        && let Some(module) =
1087                            self.resolve_super_in_module(ident, None, parent_scope)
1088                    {
1089                        return Ok(module.self_decl.unwrap());
1090                    }
1091                    if ident.name == kw::Crate
1092                        || ident.name == kw::DollarCrate
1093                        || self.path_root_is_crate_root(ident)
1094                    {
1095                        let module = self.resolve_crate_root(ident);
1096                        return Ok(module.self_decl.unwrap());
1097                    }
1098                }
1099
1100                self.resolve_ident_in_scope_set(
1101                    ident,
1102                    ScopeSet::All(ns),
1103                    parent_scope,
1104                    finalize,
1105                    ignore_decl,
1106                    ignore_import,
1107                )
1108            }
1109        }
1110    }
1111
1112    /// Attempts to resolve `ident` in namespace `ns` of non-glob bindings in an external `module`.
1113    fn resolve_ident_in_extern_module_non_globs_unadjusted<'r>(
1114        mut self: CmResolver<'r, 'ra, 'tcx>,
1115        module: ExternModule<'ra>,
1116        ident: IdentKey,
1117        orig_ident_span: Span,
1118        ns: Namespace,
1119        parent_scope: &ParentScope<'ra>,
1120        shadowing: Shadowing,
1121        finalize: Option<Finalize>,
1122        // This binding should be ignored during in-module resolution, so that we don't get
1123        // "self-confirming" import resolutions during import validation and checking.
1124        ignore_decl: Option<Decl<'ra>>,
1125    ) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
1126        let key = BindingKey::new(ident, ns);
1127        let resolution =
1128            &*self.resolution(module.to_module(), key).ok_or(ControlFlow::Continue(Determined))?;
1129
1130        let binding = resolution.non_glob_decl.filter(|b| Some(*b) != ignore_decl);
1131
1132        if let Some(finalize) = finalize {
1133            return self.get_mut().finalize_module_binding(
1134                ident,
1135                orig_ident_span,
1136                binding,
1137                parent_scope,
1138                finalize,
1139                shadowing,
1140            );
1141        }
1142
1143        // Items and single imports are not shadowable, if we have one, then it's determined.
1144        if let Some(binding) = binding {
1145            let accessible = self.is_accessible_from(binding.vis(), parent_scope.module);
1146            return if accessible { Ok(binding) } else { Err(ControlFlow::Break(Determined)) };
1147        }
1148        Err(ControlFlow::Continue(Determined))
1149    }
1150
1151    /// Attempts to resolve `ident` in namespace `ns` of non-glob bindings in a local `module`.
1152    fn resolve_ident_in_local_module_non_globs_unadjusted<'r>(
1153        mut self: CmResolver<'r, 'ra, 'tcx>,
1154        module: LocalModule<'ra>,
1155        ident: IdentKey,
1156        orig_ident_span: Span,
1157        ns: Namespace,
1158        parent_scope: &ParentScope<'ra>,
1159        shadowing: Shadowing,
1160        finalize: Option<Finalize>,
1161        // This binding should be ignored during in-module resolution, so that we don't get
1162        // "self-confirming" import resolutions during import validation and checking.
1163        ignore_decl: Option<Decl<'ra>>,
1164        ignore_import: Option<Import<'ra>>,
1165    ) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
1166        let key = BindingKey::new(ident, ns);
1167        let resolution = self.resolution(module.to_module(), key);
1168
1169        let binding =
1170            resolution.as_ref().and_then(|r| r.non_glob_decl).filter(|b| Some(*b) != ignore_decl);
1171
1172        if let Some(finalize) = finalize {
1173            // finalize implies that the module is fully expanded
1174            if !!module.has_unexpanded_invocations(&self) {
    ::core::panicking::panic("assertion failed: !module.has_unexpanded_invocations(&self)")
};assert!(!module.has_unexpanded_invocations(&self));
1175            return self.get_mut().finalize_module_binding(
1176                ident,
1177                orig_ident_span,
1178                binding,
1179                parent_scope,
1180                finalize,
1181                shadowing,
1182            );
1183        }
1184
1185        // Items and single imports are not shadowable, if we have one, then it's determined.
1186        if let Some(binding) = binding {
1187            let accessible = self.is_accessible_from(binding.vis(), parent_scope.module);
1188            return if accessible { Ok(binding) } else { Err(ControlFlow::Break(Determined)) };
1189        }
1190
1191        if let Some(resolution) = resolution {
1192            // We need to detect resolution cycles to avoid infinite recursion. The guard ensures
1193            // the resolution is removed when this resolve call ends.
1194            let _cycle_guard = cycle_detection::enter_cycle_detector(module, key)
1195                .map_err(|_| ControlFlow::Continue(Determined))?;
1196
1197            // Check if one of single imports can still define the name, block if it can.
1198            if self.reborrow().single_import_can_define_name(
1199                &resolution,
1200                None,
1201                ns,
1202                ignore_import,
1203                ignore_decl,
1204                parent_scope,
1205            ) {
1206                return Err(ControlFlow::Break(Undetermined));
1207            }
1208        }
1209
1210        // Check if one of unexpanded macros can still define the name.
1211        if module.has_unexpanded_invocations(&self) {
1212            return Err(ControlFlow::Continue(Undetermined));
1213        }
1214
1215        // No resolution and no one else can define the name - determinate error.
1216        Err(ControlFlow::Continue(Determined))
1217    }
1218
1219    /// Attempts to resolve `ident` in namespace `ns` of glob bindings in `module`.
1220    fn resolve_ident_in_module_globs_unadjusted<'r>(
1221        mut self: CmResolver<'r, 'ra, 'tcx>,
1222        module: LocalModule<'ra>,
1223        ident: IdentKey,
1224        orig_ident_span: Span,
1225        ns: Namespace,
1226        parent_scope: &ParentScope<'ra>,
1227        shadowing: Shadowing,
1228        finalize: Option<Finalize>,
1229        ignore_decl: Option<Decl<'ra>>,
1230        ignore_import: Option<Import<'ra>>,
1231    ) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
1232        let key = BindingKey::new(ident, ns);
1233        let resolution = self.resolution(module.to_module(), key);
1234
1235        let binding =
1236            resolution.as_ref().and_then(|r| r.glob_decl).filter(|b| Some(*b) != ignore_decl);
1237
1238        if let Some(finalize) = finalize {
1239            // finalize implies that the module is fully expanded
1240            if !!module.has_unexpanded_invocations(&self) {
    ::core::panicking::panic("assertion failed: !module.has_unexpanded_invocations(&self)")
};assert!(!module.has_unexpanded_invocations(&self));
1241            return self.get_mut().finalize_module_binding(
1242                ident,
1243                orig_ident_span,
1244                binding,
1245                parent_scope,
1246                finalize,
1247                shadowing,
1248            );
1249        }
1250
1251        // We need to detect resolution cycles to avoid infinite recursion. The guard ensures
1252        // the resolution is removed when this resolve call ends.
1253        let _cycle_guard = cycle_detection::enter_cycle_detector(module, key)
1254            .map_err(|_| ControlFlow::Continue(Determined))?;
1255
1256        // Check if one of single imports can still define the name,
1257        // if it can then our result is not determined and can be invalidated.
1258        if let Some(resolution) = resolution {
1259            if self.reborrow().single_import_can_define_name(
1260                &resolution,
1261                binding,
1262                ns,
1263                ignore_import,
1264                ignore_decl,
1265                parent_scope,
1266            ) {
1267                return Err(ControlFlow::Break(Undetermined));
1268            }
1269        }
1270
1271        // So we have a resolution that's from a glob import. This resolution is determined
1272        // if it cannot be shadowed by some new item/import expanded from a macro.
1273        // This happens either if there are no unexpanded macros, or expanded names cannot
1274        // shadow globs (that happens in macro namespace or with restricted shadowing).
1275        //
1276        // Additionally, any macro in any module can plant names in the root module if it creates
1277        // `macro_export` macros, so the root module effectively has unresolved invocations if any
1278        // module has unresolved invocations.
1279        // However, it causes resolution/expansion to stuck too often (#53144), so, to make
1280        // progress, we have to ignore those potential unresolved invocations from other modules
1281        // and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
1282        // shadowing is enabled, see `macro_expanded_macro_export_errors`).
1283        if let Some(binding) = binding {
1284            return if binding.determined(&self)
1285                || ns == MacroNS
1286                || shadowing == Shadowing::Restricted
1287            {
1288                let accessible = self.is_accessible_from(binding.vis(), parent_scope.module);
1289                if accessible { Ok(binding) } else { Err(ControlFlow::Break(Determined)) }
1290            } else {
1291                Err(ControlFlow::Break(Undetermined))
1292            };
1293        }
1294
1295        // Now we are in situation when new item/import can appear only from a glob or a macro
1296        // expansion. With restricted shadowing names from globs and macro expansions cannot
1297        // shadow names from outer scopes, so we can freely fallback from module search to search
1298        // in outer scopes. For `resolve_ident_in_scope_set` to continue search in outer
1299        // scopes we return `Undetermined` with `ControlFlow::Continue`.
1300        // Check if one of unexpanded macros can still define the name,
1301        // if it can then our "no resolution" result is not determined and can be invalidated.
1302        if module.has_unexpanded_invocations(&self) {
1303            return Err(ControlFlow::Continue(Undetermined));
1304        }
1305
1306        // Check if one of glob imports can still define the name,
1307        // if it can then our "no resolution" result is not determined and can be invalidated.
1308        for glob_import in module.globs.borrow_checked(&self).iter() {
1309            if ignore_import == Some(*glob_import) {
1310                continue;
1311            }
1312            if !self.is_accessible_from(glob_import.vis, parent_scope.module) {
1313                continue;
1314            }
1315            let module = match glob_import.imported_module.get() {
1316                Some(ModuleOrUniformRoot::Module(module)) => module,
1317                Some(_) => continue,
1318                None => return Err(ControlFlow::Continue(Undetermined)),
1319            };
1320            let tmp_parent_scope;
1321            let (mut adjusted_parent_scope, mut adjusted_ident) = (parent_scope, ident);
1322            match adjusted_ident
1323                .ctxt
1324                .update_unchecked(|ctxt| ctxt.glob_adjust(module.expansion, glob_import.span))
1325            {
1326                Some(Some(def)) => {
1327                    tmp_parent_scope =
1328                        ParentScope { module: self.expn_def_scope(def), ..*parent_scope };
1329                    adjusted_parent_scope = &tmp_parent_scope;
1330                }
1331                Some(None) => {}
1332                None => continue,
1333            };
1334            let result = self.reborrow().resolve_ident_in_scope_set_inner(
1335                adjusted_ident,
1336                orig_ident_span,
1337                ScopeSet::Module(ns, module),
1338                adjusted_parent_scope,
1339                None,
1340                ignore_decl,
1341                ignore_import,
1342            );
1343
1344            match result {
1345                Err(Determined) => continue,
1346                Ok(binding)
1347                    if !self.is_accessible_from(binding.vis(), glob_import.parent_scope.module) =>
1348                {
1349                    continue;
1350                }
1351                Ok(_) | Err(Undetermined) => return Err(ControlFlow::Continue(Undetermined)),
1352            }
1353        }
1354
1355        // No resolution and no one else can define the name - determinate error.
1356        Err(ControlFlow::Continue(Determined))
1357    }
1358
1359    fn finalize_module_binding(
1360        &mut self,
1361        ident: IdentKey,
1362        orig_ident_span: Span,
1363        binding: Option<Decl<'ra>>,
1364        parent_scope: &ParentScope<'ra>,
1365        finalize: Finalize,
1366        shadowing: Shadowing,
1367    ) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
1368        let Finalize { path_span, report_private, used, root_span, .. } = finalize;
1369
1370        let Some(binding) = binding else {
1371            return Err(ControlFlow::Continue(Determined));
1372        };
1373
1374        let ident = ident.orig(orig_ident_span);
1375        if !self.is_accessible_from(binding.vis(), parent_scope.module) {
1376            if report_private {
1377                self.privacy_errors.push(PrivacyError {
1378                    ident,
1379                    decl: binding,
1380                    dedup_span: path_span,
1381                    outermost_res: None,
1382                    source: None,
1383                    parent_scope: *parent_scope,
1384                    single_nested: path_span != root_span,
1385                });
1386            } else {
1387                return Err(ControlFlow::Break(Determined));
1388            }
1389        }
1390
1391        if shadowing == Shadowing::Unrestricted
1392            && binding.expansion != LocalExpnId::ROOT
1393            && let DeclKind::Import { import, .. } = binding.kind
1394            && #[allow(non_exhaustive_omitted_patterns)] match import.kind {
    ImportKind::MacroExport => true,
    _ => false,
}matches!(import.kind, ImportKind::MacroExport)
1395        {
1396            self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
1397        }
1398
1399        self.record_use(ident, binding, used);
1400        return Ok(binding);
1401    }
1402
1403    // Checks if a single import can define the `Ident` corresponding to `binding`.
1404    // This is used to check whether we can definitively accept a glob as a resolution.
1405    fn single_import_can_define_name<'r>(
1406        mut self: CmResolver<'r, 'ra, 'tcx>,
1407        resolution: &NameResolution<'ra>,
1408        binding: Option<Decl<'ra>>,
1409        ns: Namespace,
1410        ignore_import: Option<Import<'ra>>,
1411        ignore_decl: Option<Decl<'ra>>,
1412        parent_scope: &ParentScope<'ra>,
1413    ) -> bool {
1414        for single_import in &resolution.single_imports {
1415            if let Some(decl) = resolution.non_glob_decl
1416                && let DeclKind::Import { import, .. } = decl.kind
1417                && import == *single_import
1418            {
1419                // Single import has already defined the name and we are aware of it,
1420                // no need to block the globs.
1421                continue;
1422            }
1423            if ignore_import == Some(*single_import) {
1424                continue;
1425            }
1426            if !self.is_accessible_from(single_import.vis, parent_scope.module) {
1427                continue;
1428            }
1429            if let Some(ignored) = ignore_decl
1430                && let DeclKind::Import { import, .. } = ignored.kind
1431                && import == *single_import
1432            {
1433                continue;
1434            }
1435
1436            let Some(module) = single_import.imported_module.get() else {
1437                return true;
1438            };
1439            let ImportKind::Single { source, target, decls, .. } = &single_import.kind else {
1440                ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1441            };
1442            if source != target {
1443                if decls.iter().all(|d| d.get().decl().is_none()) {
1444                    return true;
1445                } else if decls[ns].get().decl().is_none() && binding.is_some() {
1446                    return true;
1447                }
1448            }
1449
1450            match self.reborrow().resolve_ident_in_module(
1451                module,
1452                *source,
1453                ns,
1454                &single_import.parent_scope,
1455                None,
1456                ignore_decl,
1457                None,
1458            ) {
1459                Err(Determined) => continue,
1460                Ok(binding)
1461                    if !self
1462                        .is_accessible_from(binding.vis(), single_import.parent_scope.module) =>
1463                {
1464                    continue;
1465                }
1466                Ok(_) | Err(Undetermined) => return true,
1467            }
1468        }
1469
1470        false
1471    }
1472
1473    /// Validate a local resolution (from ribs).
1474    {}
#[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("validate_res_from_ribs",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1474u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("rib_index")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("rib_index");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("rib_ident")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("rib_ident");
                                                        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("finalize")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("finalize");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("original_rib_ident_def")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("original_rib_ident_def");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("diag_metadata")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("diag_metadata");
                                                        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(&rib_index
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rib_ident)
                                                            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(&finalize)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&original_rib_ident_def)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&diag_metadata)
                                                            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: Res = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs:1485",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1485u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::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!("validate_res_from_ribs({0:?})",
                                                                res) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let ribs = &all_ribs[rib_index + 1..];
            if let RibKind::ForwardGenericParamBan(reason) =
                    all_ribs[rib_index].kind {
                if let Some(span) = finalize {
                    let res_error =
                        if rib_ident.name == kw::SelfUpper {
                            ResolutionError::ForwardDeclaredSelf(reason)
                        } else {
                            ResolutionError::ForwardDeclaredGenericParam(rib_ident.name,
                                reason)
                        };
                    self.report_error(span, res_error);
                }
                {
                    match (&res, &Res::Err) {
                        (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);
                            }
                        }
                    }
                };
                return Res::Err;
            }
            match res {
                Res::Local(_) => {
                    use ResolutionError::*;
                    let mut res_err = None;
                    let suggest_closure =
                        !ribs.iter().any(|rib|
                                    #[allow(non_exhaustive_omitted_patterns)] match rib.kind {
                                        RibKind::AssocItem => true,
                                        _ => false,
                                    });
                    for rib in ribs {
                        match rib.kind {
                            RibKind::Normal | RibKind::Block(..) |
                                RibKind::FnOrCoroutine | RibKind::Module(..) |
                                RibKind::MacroDefinition(..) |
                                RibKind::ForwardGenericParamBan(_) => {}
                            RibKind::Item(..) | RibKind::AssocItem => {
                                if let Some(span) = finalize {
                                    res_err =
                                        Some((span,
                                                CannotCaptureDynamicEnvironmentInFnItem {
                                                    suggest_closure,
                                                }));
                                }
                            }
                            RibKind::ConstantItem(_, item, requires_type) => {
                                if let Some(span) = finalize {
                                    let (span, resolution_error) =
                                        match item {
                                            None if rib_ident.name == kw::SelfLower => {
                                                (span, LowercaseSelf)
                                            }
                                            None => {
                                                let sm = self.tcx.sess.source_map();
                                                let type_span =
                                                    match sm.span_followed_by(original_rib_ident_def.span, ":")
                                                        {
                                                        None => { Some(original_rib_ident_def.span.shrink_to_hi()) }
                                                        Some(_) => None,
                                                    };
                                                (rib_ident.span,
                                                    AttemptToUseNonConstantValueInConstant {
                                                        ident: original_rib_ident_def,
                                                        suggestion: "const",
                                                        current: "let",
                                                        type_span,
                                                        requires_type,
                                                    })
                                            }
                                            Some((ident, kind)) =>
                                                (span,
                                                    AttemptToUseNonConstantValueInConstant {
                                                        ident,
                                                        suggestion: "let",
                                                        current: kind.as_str(),
                                                        type_span: None,
                                                        requires_type,
                                                    }),
                                        };
                                    self.report_error(span, resolution_error);
                                }
                                return Res::Err;
                            }
                            RibKind::ConstParamTy => {
                                if let Some(span) = finalize {
                                    self.report_error(span,
                                        ParamInTyOfConstParam { name: rib_ident.name });
                                }
                                return Res::Err;
                            }
                            RibKind::InlineAsmSym => {
                                if let Some(span) = finalize {
                                    self.report_error(span, InvalidAsmSym);
                                }
                                return Res::Err;
                            }
                        }
                    }
                    if let Some((span, res_err)) = res_err {
                        self.report_error(span, res_err);
                        return Res::Err;
                    }
                }
                Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } |
                    Res::SelfTyAlias { .. } => {
                    for rib in ribs {
                        let (has_generic_params, def_kind) =
                            match rib.kind {
                                RibKind::Normal | RibKind::Block(..) |
                                    RibKind::FnOrCoroutine | RibKind::Module(..) |
                                    RibKind::MacroDefinition(..) | RibKind::InlineAsmSym |
                                    RibKind::AssocItem | RibKind::ForwardGenericParamBan(_) => {
                                    continue;
                                }
                                RibKind::ConstParamTy => {
                                    let adt_enabled =
                                        self.features.min_adt_const_params() ||
                                            self.features.adt_const_params();
                                    let is_self =
                                        #[allow(non_exhaustive_omitted_patterns)] match res {
                                            Res::SelfTyAlias { .. } => true,
                                            _ => false,
                                        };
                                    if self.features.generic_const_parameter_types() ||
                                            (adt_enabled && is_self) {
                                        continue;
                                    } else {
                                        if let Some(span) = finalize {
                                            if #[allow(non_exhaustive_omitted_patterns)] match res {
                                                    Res::SelfTyAlias { .. } => true,
                                                    _ => false,
                                                } {
                                                self.report_error(span, ResolutionError::SelfInConstParam);
                                            } else {
                                                self.report_error(span,
                                                    ResolutionError::ParamInTyOfConstParam {
                                                        name: rib_ident.name,
                                                    });
                                            }
                                        }
                                        return Res::Err;
                                    }
                                }
                                RibKind::ConstantItem(trivial, _, _) => {
                                    if let ConstantHasGenerics::No(cause) = trivial &&
                                            !#[allow(non_exhaustive_omitted_patterns)] match res {
                                                    Res::SelfTyAlias { .. } => true,
                                                    _ => false,
                                                } {
                                        if let Some(span) = finalize {
                                            let error =
                                                match cause {
                                                    NoConstantGenericsReason::IsEnumDiscriminant => {
                                                        ResolutionError::ParamInEnumDiscriminant {
                                                            name: rib_ident.name,
                                                            param_kind: ParamKindInEnumDiscriminant::Type,
                                                        }
                                                    }
                                                    NoConstantGenericsReason::NonTrivialConstArg => {
                                                        ResolutionError::ParamInNonTrivialAnonConst {
                                                            is_gca: self.features.gca_const_items(),
                                                            name: rib_ident.name,
                                                            param_kind: ParamKindInNonTrivialAnonConst::Type,
                                                        }
                                                    }
                                                };
                                            let _: ErrorGuaranteed = self.report_error(span, error);
                                        }
                                        return Res::Err;
                                    }
                                    continue;
                                }
                                RibKind::Item(has_generic_params, def_kind) => {
                                    (has_generic_params, def_kind)
                                }
                            };
                        if let Some(span) = finalize {
                            let item =
                                if let Some(diag_metadata) = diag_metadata &&
                                        let Some(current_item) = diag_metadata.current_item {
                                    let label_span =
                                        current_item.kind.ident().map(|i|
                                                    i.span).unwrap_or(current_item.span);
                                    Some((label_span, current_item.span,
                                            current_item.kind.clone()))
                                } else { None };
                            self.report_error(span,
                                ResolutionError::GenericParamsFromOuterItem {
                                    outer_res: res,
                                    has_generic_params,
                                    def_kind,
                                    inner_item: item,
                                    current_self_ty: diag_metadata.and_then(|m|
                                                m.current_self_type.as_ref()).and_then(|ty|
                                            {
                                                self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
                                            }),
                                });
                        }
                        return Res::Err;
                    }
                }
                Res::Def(DefKind::ConstParam, _) => {
                    for rib in ribs {
                        let (has_generic_params, def_kind) =
                            match rib.kind {
                                RibKind::Normal | RibKind::Block(..) |
                                    RibKind::FnOrCoroutine | RibKind::Module(..) |
                                    RibKind::MacroDefinition(..) | RibKind::InlineAsmSym |
                                    RibKind::AssocItem | RibKind::ForwardGenericParamBan(_) =>
                                    continue,
                                RibKind::ConstParamTy => {
                                    if !self.features.generic_const_parameter_types() {
                                        if let Some(span) = finalize {
                                            self.report_error(span,
                                                ResolutionError::ParamInTyOfConstParam {
                                                    name: rib_ident.name,
                                                });
                                        }
                                        return Res::Err;
                                    } else { continue; }
                                }
                                RibKind::ConstantItem(trivial, _, _) => {
                                    if let ConstantHasGenerics::No(cause) = trivial {
                                        if let Some(span) = finalize {
                                            let error =
                                                match cause {
                                                    NoConstantGenericsReason::IsEnumDiscriminant => {
                                                        ResolutionError::ParamInEnumDiscriminant {
                                                            name: rib_ident.name,
                                                            param_kind: ParamKindInEnumDiscriminant::Const,
                                                        }
                                                    }
                                                    NoConstantGenericsReason::NonTrivialConstArg => {
                                                        ResolutionError::ParamInNonTrivialAnonConst {
                                                            is_gca: self.features.gca_const_items(),
                                                            name: rib_ident.name,
                                                            param_kind: ParamKindInNonTrivialAnonConst::Const {
                                                                name: rib_ident.name,
                                                            },
                                                        }
                                                    }
                                                };
                                            self.report_error(span, error);
                                        }
                                        return Res::Err;
                                    }
                                    continue;
                                }
                                RibKind::Item(has_generic_params, def_kind) => {
                                    (has_generic_params, def_kind)
                                }
                            };
                        if let Some(span) = finalize {
                            let item =
                                if let Some(diag_metadata) = diag_metadata &&
                                        let Some(current_item) = diag_metadata.current_item {
                                    let label_span =
                                        current_item.kind.ident().map(|i|
                                                    i.span).unwrap_or(current_item.span);
                                    Some((label_span, current_item.span,
                                            current_item.kind.clone()))
                                } else { None };
                            self.report_error(span,
                                ResolutionError::GenericParamsFromOuterItem {
                                    outer_res: res,
                                    has_generic_params,
                                    def_kind,
                                    inner_item: item,
                                    current_self_ty: diag_metadata.and_then(|m|
                                                m.current_self_type.as_ref()).and_then(|ty|
                                            {
                                                self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
                                            }),
                                });
                        }
                        return Res::Err;
                    }
                }
                _ => {}
            }
            res
        }
    }
}#[instrument(level = "debug", skip(self, all_ribs))]
1475    fn validate_res_from_ribs(
1476        &self,
1477        rib_index: usize,
1478        rib_ident: Ident,
1479        res: Res,
1480        finalize: Option<Span>,
1481        original_rib_ident_def: Ident,
1482        all_ribs: &[Rib<'ra>],
1483        diag_metadata: Option<&DiagMetadata<'_>>,
1484    ) -> Res {
1485        debug!("validate_res_from_ribs({:?})", res);
1486        let ribs = &all_ribs[rib_index + 1..];
1487
1488        // An invalid forward use of a generic parameter from a previous default
1489        // or in a const param ty.
1490        if let RibKind::ForwardGenericParamBan(reason) = all_ribs[rib_index].kind {
1491            if let Some(span) = finalize {
1492                let res_error = if rib_ident.name == kw::SelfUpper {
1493                    ResolutionError::ForwardDeclaredSelf(reason)
1494                } else {
1495                    ResolutionError::ForwardDeclaredGenericParam(rib_ident.name, reason)
1496                };
1497                self.report_error(span, res_error);
1498            }
1499            assert_eq!(res, Res::Err);
1500            return Res::Err;
1501        }
1502
1503        match res {
1504            Res::Local(_) => {
1505                use ResolutionError::*;
1506                let mut res_err = None;
1507
1508                let suggest_closure =
1509                    !ribs.iter().any(|rib| matches!(rib.kind, RibKind::AssocItem));
1510
1511                for rib in ribs {
1512                    match rib.kind {
1513                        RibKind::Normal
1514                        | RibKind::Block(..)
1515                        | RibKind::FnOrCoroutine
1516                        | RibKind::Module(..)
1517                        | RibKind::MacroDefinition(..)
1518                        | RibKind::ForwardGenericParamBan(_) => {
1519                            // Nothing to do. Continue.
1520                        }
1521                        RibKind::Item(..) | RibKind::AssocItem => {
1522                            // This was an attempt to access an upvar inside a
1523                            // named function item. This is not allowed, so we
1524                            // report an error.
1525                            if let Some(span) = finalize {
1526                                // We don't immediately trigger a resolve error, because
1527                                // we want certain other resolution errors (namely those
1528                                // emitted for `ConstantItemRibKind` below) to take
1529                                // precedence.
1530                                res_err = Some((
1531                                    span,
1532                                    CannotCaptureDynamicEnvironmentInFnItem { suggest_closure },
1533                                ));
1534                            }
1535                        }
1536                        RibKind::ConstantItem(_, item, requires_type) => {
1537                            // Still doesn't deal with upvars
1538                            if let Some(span) = finalize {
1539                                let (span, resolution_error) = match item {
1540                                    None if rib_ident.name == kw::SelfLower => {
1541                                        (span, LowercaseSelf)
1542                                    }
1543                                    None => {
1544                                        // If we have a `let name = expr;`, we have the span for
1545                                        // `name` and use that to see if it is followed by a type
1546                                        // specifier. If not, then we know we need to suggest
1547                                        // `const name: Ty = expr;`. This is a heuristic, it will
1548                                        // break down in the presence of macros.
1549                                        let sm = self.tcx.sess.source_map();
1550                                        let type_span = match sm
1551                                            .span_followed_by(original_rib_ident_def.span, ":")
1552                                        {
1553                                            None => {
1554                                                Some(original_rib_ident_def.span.shrink_to_hi())
1555                                            }
1556                                            Some(_) => None,
1557                                        };
1558                                        (
1559                                            rib_ident.span,
1560                                            AttemptToUseNonConstantValueInConstant {
1561                                                ident: original_rib_ident_def,
1562                                                suggestion: "const",
1563                                                current: "let",
1564                                                type_span,
1565                                                requires_type,
1566                                            },
1567                                        )
1568                                    }
1569                                    Some((ident, kind)) => (
1570                                        span,
1571                                        AttemptToUseNonConstantValueInConstant {
1572                                            ident,
1573                                            suggestion: "let",
1574                                            current: kind.as_str(),
1575                                            type_span: None,
1576                                            requires_type,
1577                                        },
1578                                    ),
1579                                };
1580                                self.report_error(span, resolution_error);
1581                            }
1582                            return Res::Err;
1583                        }
1584                        RibKind::ConstParamTy => {
1585                            if let Some(span) = finalize {
1586                                self.report_error(
1587                                    span,
1588                                    ParamInTyOfConstParam { name: rib_ident.name },
1589                                );
1590                            }
1591                            return Res::Err;
1592                        }
1593                        RibKind::InlineAsmSym => {
1594                            if let Some(span) = finalize {
1595                                self.report_error(span, InvalidAsmSym);
1596                            }
1597                            return Res::Err;
1598                        }
1599                    }
1600                }
1601                if let Some((span, res_err)) = res_err {
1602                    self.report_error(span, res_err);
1603                    return Res::Err;
1604                }
1605            }
1606            Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
1607                for rib in ribs {
1608                    let (has_generic_params, def_kind) = match rib.kind {
1609                        RibKind::Normal
1610                        | RibKind::Block(..)
1611                        | RibKind::FnOrCoroutine
1612                        | RibKind::Module(..)
1613                        | RibKind::MacroDefinition(..)
1614                        | RibKind::InlineAsmSym
1615                        | RibKind::AssocItem
1616                        | RibKind::ForwardGenericParamBan(_) => {
1617                            // Nothing to do. Continue.
1618                            continue;
1619                        }
1620
1621                        RibKind::ConstParamTy => {
1622                            let adt_enabled = self.features.min_adt_const_params()
1623                                || self.features.adt_const_params();
1624                            let is_self = matches!(res, Res::SelfTyAlias { .. });
1625                            // We check whether Self depends on generics parameters in `fn type_of`
1626                            if self.features.generic_const_parameter_types()
1627                                || (adt_enabled && is_self)
1628                            {
1629                                continue;
1630                            } else {
1631                                if let Some(span) = finalize {
1632                                    if matches!(res, Res::SelfTyAlias { .. }) {
1633                                        self.report_error(span, ResolutionError::SelfInConstParam);
1634                                    } else {
1635                                        self.report_error(
1636                                            span,
1637                                            ResolutionError::ParamInTyOfConstParam {
1638                                                name: rib_ident.name,
1639                                            },
1640                                        );
1641                                    }
1642                                }
1643                                return Res::Err;
1644                            }
1645                        }
1646
1647                        RibKind::ConstantItem(trivial, _, _) => {
1648                            if let ConstantHasGenerics::No(cause) = trivial
1649                                && !matches!(res, Res::SelfTyAlias { .. })
1650                            {
1651                                if let Some(span) = finalize {
1652                                    let error = match cause {
1653                                        NoConstantGenericsReason::IsEnumDiscriminant => {
1654                                            ResolutionError::ParamInEnumDiscriminant {
1655                                                name: rib_ident.name,
1656                                                param_kind: ParamKindInEnumDiscriminant::Type,
1657                                            }
1658                                        }
1659                                        NoConstantGenericsReason::NonTrivialConstArg => {
1660                                            ResolutionError::ParamInNonTrivialAnonConst {
1661                                                is_gca: self.features.gca_const_items(),
1662                                                name: rib_ident.name,
1663                                                param_kind: ParamKindInNonTrivialAnonConst::Type,
1664                                            }
1665                                        }
1666                                    };
1667                                    let _: ErrorGuaranteed = self.report_error(span, error);
1668                                }
1669
1670                                return Res::Err;
1671                            }
1672
1673                            continue;
1674                        }
1675
1676                        // This was an attempt to use a type parameter outside its scope.
1677                        RibKind::Item(has_generic_params, def_kind) => {
1678                            (has_generic_params, def_kind)
1679                        }
1680                    };
1681
1682                    if let Some(span) = finalize {
1683                        let item = if let Some(diag_metadata) = diag_metadata
1684                            && let Some(current_item) = diag_metadata.current_item
1685                        {
1686                            let label_span = current_item
1687                                .kind
1688                                .ident()
1689                                .map(|i| i.span)
1690                                .unwrap_or(current_item.span);
1691                            Some((label_span, current_item.span, current_item.kind.clone()))
1692                        } else {
1693                            None
1694                        };
1695                        self.report_error(
1696                            span,
1697                            ResolutionError::GenericParamsFromOuterItem {
1698                                outer_res: res,
1699                                has_generic_params,
1700                                def_kind,
1701                                inner_item: item,
1702                                current_self_ty: diag_metadata
1703                                    .and_then(|m| m.current_self_type.as_ref())
1704                                    .and_then(|ty| {
1705                                        self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
1706                                    }),
1707                            },
1708                        );
1709                    }
1710                    return Res::Err;
1711                }
1712            }
1713            Res::Def(DefKind::ConstParam, _) => {
1714                for rib in ribs {
1715                    let (has_generic_params, def_kind) = match rib.kind {
1716                        RibKind::Normal
1717                        | RibKind::Block(..)
1718                        | RibKind::FnOrCoroutine
1719                        | RibKind::Module(..)
1720                        | RibKind::MacroDefinition(..)
1721                        | RibKind::InlineAsmSym
1722                        | RibKind::AssocItem
1723                        | RibKind::ForwardGenericParamBan(_) => continue,
1724
1725                        RibKind::ConstParamTy => {
1726                            if !self.features.generic_const_parameter_types() {
1727                                if let Some(span) = finalize {
1728                                    self.report_error(
1729                                        span,
1730                                        ResolutionError::ParamInTyOfConstParam {
1731                                            name: rib_ident.name,
1732                                        },
1733                                    );
1734                                }
1735                                return Res::Err;
1736                            } else {
1737                                continue;
1738                            }
1739                        }
1740
1741                        RibKind::ConstantItem(trivial, _, _) => {
1742                            if let ConstantHasGenerics::No(cause) = trivial {
1743                                if let Some(span) = finalize {
1744                                    let error = match cause {
1745                                        NoConstantGenericsReason::IsEnumDiscriminant => {
1746                                            ResolutionError::ParamInEnumDiscriminant {
1747                                                name: rib_ident.name,
1748                                                param_kind: ParamKindInEnumDiscriminant::Const,
1749                                            }
1750                                        }
1751                                        NoConstantGenericsReason::NonTrivialConstArg => {
1752                                            ResolutionError::ParamInNonTrivialAnonConst {
1753                                                is_gca: self.features.gca_const_items(),
1754                                                name: rib_ident.name,
1755                                                param_kind: ParamKindInNonTrivialAnonConst::Const {
1756                                                    name: rib_ident.name,
1757                                                },
1758                                            }
1759                                        }
1760                                    };
1761                                    self.report_error(span, error);
1762                                }
1763
1764                                return Res::Err;
1765                            }
1766
1767                            continue;
1768                        }
1769
1770                        RibKind::Item(has_generic_params, def_kind) => {
1771                            (has_generic_params, def_kind)
1772                        }
1773                    };
1774
1775                    // This was an attempt to use a const parameter outside its scope.
1776                    if let Some(span) = finalize {
1777                        let item = if let Some(diag_metadata) = diag_metadata
1778                            && let Some(current_item) = diag_metadata.current_item
1779                        {
1780                            let label_span = current_item
1781                                .kind
1782                                .ident()
1783                                .map(|i| i.span)
1784                                .unwrap_or(current_item.span);
1785                            Some((label_span, current_item.span, current_item.kind.clone()))
1786                        } else {
1787                            None
1788                        };
1789                        self.report_error(
1790                            span,
1791                            ResolutionError::GenericParamsFromOuterItem {
1792                                outer_res: res,
1793                                has_generic_params,
1794                                def_kind,
1795                                inner_item: item,
1796                                current_self_ty: diag_metadata
1797                                    .and_then(|m| m.current_self_type.as_ref())
1798                                    .and_then(|ty| {
1799                                        self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
1800                                    }),
1801                            },
1802                        );
1803                    }
1804                    return Res::Err;
1805                }
1806            }
1807            _ => {}
1808        }
1809
1810        res
1811    }
1812
1813    {}
#[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("maybe_resolve_path",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1813u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        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("opt_ns")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("opt_ns");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_scope");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_import")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_import");
                                                        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(&path)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opt_ns)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_scope)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_import)
                                                            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: PathResult<'ra> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.resolve_path_with_ribs(path, opt_ns, parent_scope, None,
                None, None, None, ignore_import, None)
        }
    }
}#[instrument(level = "debug", skip(self))]
1814    pub(crate) fn maybe_resolve_path<'r>(
1815        self: CmResolver<'r, 'ra, 'tcx>,
1816        path: &[Segment],
1817        opt_ns: Option<Namespace>, // `None` indicates a module path in import
1818        parent_scope: &ParentScope<'ra>,
1819        ignore_import: Option<Import<'ra>>,
1820    ) -> PathResult<'ra> {
1821        self.resolve_path_with_ribs(
1822            path,
1823            opt_ns,
1824            parent_scope,
1825            None,
1826            None,
1827            None,
1828            None,
1829            ignore_import,
1830            None,
1831        )
1832    }
1833    {}
#[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_path",
                                    "rustc_resolve::ident", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1833u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        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("opt_ns")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("opt_ns");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_scope");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("finalize")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("finalize");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_decl")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_decl");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ignore_import")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ignore_import");
                                                        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(&path)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opt_ns)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_scope)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&finalize)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_decl)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ignore_import)
                                                            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: PathResult<'ra> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.resolve_path_with_ribs(path, opt_ns, parent_scope, None,
                finalize, None, ignore_decl, ignore_import, None)
        }
    }
}#[instrument(level = "debug", skip(self))]
1834    pub(crate) fn resolve_path<'r>(
1835        self: CmResolver<'r, 'ra, 'tcx>,
1836        path: &[Segment],
1837        opt_ns: Option<Namespace>, // `None` indicates a module path in import
1838        parent_scope: &ParentScope<'ra>,
1839        finalize: Option<Finalize>,
1840        ignore_decl: Option<Decl<'ra>>,
1841        ignore_import: Option<Import<'ra>>,
1842    ) -> PathResult<'ra> {
1843        self.resolve_path_with_ribs(
1844            path,
1845            opt_ns,
1846            parent_scope,
1847            None,
1848            finalize,
1849            None,
1850            ignore_decl,
1851            ignore_import,
1852            None,
1853        )
1854    }
1855
1856    pub(crate) fn resolve_path_with_ribs<'r>(
1857        mut self: CmResolver<'r, 'ra, 'tcx>,
1858        path: &[Segment],
1859        opt_ns: Option<Namespace>, // `None` indicates a module path in import
1860        parent_scope: &ParentScope<'ra>,
1861        source: Option<PathSource<'_, '_, '_>>,
1862        finalize: Option<Finalize>,
1863        ribs: Option<&PerNS<Vec<Rib<'ra>>>>,
1864        ignore_decl: Option<Decl<'ra>>,
1865        ignore_import: Option<Import<'ra>>,
1866        diag_metadata: Option<&DiagMetadata<'_>>,
1867    ) -> PathResult<'ra> {
1868        let mut module = None;
1869        let mut module_had_parse_errors = !self.mods_with_parse_errors.is_empty()
1870            && self
1871                .mods_with_parse_errors
1872                .contains(&parent_scope.module.nearest_parent_mod().to_def_id());
1873        let mut allow_super = true;
1874        let mut second_binding = None;
1875
1876        // We'll provide more context to the privacy errors later, up to `len`.
1877        let privacy_errors_len = self.privacy_errors.len();
1878        fn record_segment_res<'r, 'ra, 'tcx>(
1879            mut this: CmResolver<'r, 'ra, 'tcx>,
1880            finalize: Option<Finalize>,
1881            res: Res,
1882            id: Option<NodeId>,
1883        ) {
1884            if finalize.is_some()
1885                && let Some(id) = id
1886                && !this.partial_res_map.contains_key(&id)
1887            {
1888                if !(id != ast::DUMMY_NODE_ID) {
    {
        ::core::panicking::panic_fmt(format_args!("Trying to resolve dummy id"));
    }
};assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
1889                this.get_mut().record_partial_res(id, PartialRes::new(res));
1890            }
1891        }
1892
1893        for (segment_idx, &Segment { ident, id, .. }) in path.iter().enumerate() {
1894            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs:1894",
                        "rustc_resolve::ident", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_resolve/src/ident.rs"),
                        ::tracing_core::__macro_support::Option::Some(1894u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_resolve::ident"),
                        ::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_path ident {0} {1:?} {2:?}",
                                                    segment_idx, ident, id) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("resolve_path ident {} {:?} {:?}", segment_idx, ident, id);
1895
1896            let is_last = segment_idx + 1 == path.len();
1897            let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
1898            let name = ident.name;
1899
1900            allow_super &= ns == TypeNS && (name == kw::SelfLower || name == kw::Super);
1901
1902            if ns == TypeNS {
1903                if allow_super && name == kw::Super {
1904                    let parent = if segment_idx == 0 {
1905                        self.resolve_super_in_module(ident, None, parent_scope)
1906                    } else if let Some(ModuleOrUniformRoot::Module(module)) = module {
1907                        self.resolve_super_in_module(ident, Some(module), parent_scope)
1908                    } else {
1909                        None
1910                    };
1911                    if let Some(parent) = parent {
1912                        module = Some(ModuleOrUniformRoot::Module(parent));
1913                        continue;
1914                    }
1915                    let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1916                    let current_module = self.resolve_self(&mut ctxt, parent_scope.module);
1917                    let current_module_path = module_to_string(current_module)
1918                        .map_or_else(|| "crate".to_string(), |path| ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("crate::{0}", path))
    })format!("crate::{path}"));
1919                    return PathResult::failed(
1920                        ident,
1921                        false,
1922                        finalize.is_some(),
1923                        module_had_parse_errors,
1924                        module,
1925                        || {
1926                            (
1927                                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("too many leading `super` keywords within `{0}`",
                current_module_path))
    })format!(
1928                                    "too many leading `super` keywords within `{current_module_path}`"
1929                                ),
1930                                "this `super` would go above the crate root".to_string(),
1931                                None,
1932                                None,
1933                                None,
1934                            )
1935                        },
1936                    );
1937                }
1938                if segment_idx == 0 {
1939                    if name == kw::SelfLower {
1940                        let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1941                        let self_mod = self.resolve_self(&mut ctxt, parent_scope.module);
1942                        if let Some(res) = self_mod.res() {
1943                            record_segment_res(self.reborrow(), finalize, res, id);
1944                        }
1945                        module = Some(ModuleOrUniformRoot::Module(self_mod));
1946                        continue;
1947                    }
1948                    if name == kw::PathRoot && ident.span.at_least_rust_2018() {
1949                        module = Some(ModuleOrUniformRoot::ExternPrelude);
1950                        continue;
1951                    }
1952                    if name == kw::PathRoot
1953                        && ident.span.is_rust_2015()
1954                        && self.tcx.sess.at_least_rust_2018()
1955                    {
1956                        // `::a::b` from 2015 macro on 2018 global edition
1957                        let crate_root = self.resolve_crate_root(ident);
1958                        module = Some(ModuleOrUniformRoot::ModuleAndExternPrelude(crate_root));
1959                        continue;
1960                    }
1961                    if name == kw::PathRoot || name == kw::Crate || name == kw::DollarCrate {
1962                        // `::a::b`, `crate::a::b` or `$crate::a::b`
1963                        let crate_root = self.resolve_crate_root(ident);
1964                        if let Some(res) = crate_root.res() {
1965                            record_segment_res(self.reborrow(), finalize, res, id);
1966                        }
1967                        module = Some(ModuleOrUniformRoot::Module(crate_root));
1968                        continue;
1969                    }
1970                }
1971            }
1972
1973            let allow_trailing_self = is_last && name == kw::SelfLower;
1974
1975            // Report special messages for path segment keywords in wrong positions.
1976            if ident.is_path_segment_keyword() && segment_idx != 0 && !allow_trailing_self {
1977                return PathResult::failed(
1978                    ident,
1979                    false,
1980                    finalize.is_some(),
1981                    module_had_parse_errors,
1982                    module,
1983                    || {
1984                        let name_str = if name == kw::PathRoot {
1985                            "the crate root".to_string()
1986                        } else {
1987                            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}`", name))
    })format!("`{name}`")
1988                        };
1989                        let (message, label) = if segment_idx == 1
1990                            && path[0].ident.name == kw::PathRoot
1991                        {
1992                            (
1993                                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("global paths cannot start with {0}",
                name_str))
    })format!("global paths cannot start with {name_str}"),
1994                                "cannot start with this".to_string(),
1995                            )
1996                        } else if name == kw::SelfLower {
1997                            (
1998                                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`self` in paths can only be used in start position or last position"))
    })format!(
1999                                    "`self` in paths can only be used in start position or last position"
2000                                ),
2001                                "can only be used in path start position or last position"
2002                                    .to_string(),
2003                            )
2004                        } else {
2005                            (
2006                                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0} in paths can only be used in start position",
                name_str))
    })format!("{name_str} in paths can only be used in start position"),
2007                                "can only be used in path start position".to_string(),
2008                            )
2009                        };
2010                        (message, label, None, None, None)
2011                    },
2012                );
2013            }
2014
2015            let binding = if let Some(module) = module {
2016                self.reborrow().resolve_ident_in_module(
2017                    module,
2018                    ident,
2019                    ns,
2020                    parent_scope,
2021                    finalize,
2022                    ignore_decl,
2023                    ignore_import,
2024                )
2025            } else if let Some(ribs) = ribs
2026                && let Some(TypeNS | ValueNS) = opt_ns
2027            {
2028                if !ignore_import.is_none() {
    ::core::panicking::panic("assertion failed: ignore_import.is_none()")
};assert!(ignore_import.is_none());
2029                match self.get_mut().resolve_ident_in_lexical_scope(
2030                    ident,
2031                    ns,
2032                    parent_scope,
2033                    finalize,
2034                    &ribs[ns],
2035                    ignore_decl,
2036                    diag_metadata,
2037                ) {
2038                    // we found a locally-imported or available item/module
2039                    Some(LateDecl::Decl(binding)) => Ok(binding),
2040                    // we found a local variable or type param
2041                    Some(LateDecl::RibDef(res)) => {
2042                        record_segment_res(self.reborrow(), finalize, res, id);
2043                        return PathResult::NonModule(PartialRes::with_unresolved_segments(
2044                            res,
2045                            path.len() - 1,
2046                        ));
2047                    }
2048                    _ => Err(Determinacy::determined(finalize.is_some())),
2049                }
2050            } else {
2051                self.reborrow().resolve_ident_in_scope_set(
2052                    ident,
2053                    ScopeSet::All(ns),
2054                    parent_scope,
2055                    finalize,
2056                    ignore_decl,
2057                    ignore_import,
2058                )
2059            };
2060
2061            match binding {
2062                Ok(binding) => {
2063                    if segment_idx == 1 {
2064                        second_binding = Some(binding);
2065                    }
2066                    let res = binding.res();
2067
2068                    // Mark every privacy error in this path with the res to the last element. This allows us
2069                    // to detect the item the user cares about and either find an alternative import, or tell
2070                    // the user it is not accessible.
2071                    if finalize.is_some() {
2072                        for error in &mut self.get_mut().privacy_errors[privacy_errors_len..] {
2073                            error.outermost_res = Some((res, ident));
2074                            error.source = match source {
2075                                Some(PathSource::Struct(Some(expr)))
2076                                | Some(PathSource::Expr(Some(expr))) => Some(expr.clone()),
2077                                _ => None,
2078                            };
2079                        }
2080                    }
2081
2082                    let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(res);
2083                    if let Res::OpenMod(sym) = binding.res() {
2084                        module = Some(ModuleOrUniformRoot::OpenModule(sym));
2085                        record_segment_res(self.reborrow(), finalize, res, id);
2086                    } else if let Some(def_id) = binding.res().module_like_def_id() {
2087                        if self.mods_with_parse_errors.contains(&def_id) {
2088                            module_had_parse_errors = true;
2089                        }
2090                        module = Some(ModuleOrUniformRoot::Module(self.expect_module(def_id)));
2091                        record_segment_res(self.reborrow(), finalize, res, id);
2092                    } else if res == Res::ToolMod && !is_last && opt_ns.is_some() {
2093                        if binding.is_import() {
2094                            self.dcx().emit_err(diagnostics::ToolModuleImported {
2095                                span: ident.span,
2096                                import: binding.span,
2097                            });
2098                        }
2099                        let res = Res::NonMacroAttr(NonMacroAttrKind::Tool);
2100                        return PathResult::NonModule(PartialRes::new(res));
2101                    } else if res == Res::Err {
2102                        return PathResult::NonModule(PartialRes::new(Res::Err));
2103                    } else if opt_ns.is_some() && (is_last || maybe_assoc) {
2104                        if let Some(finalize) = finalize {
2105                            self.get_mut().lint_if_path_starts_with_module(
2106                                finalize,
2107                                path,
2108                                second_binding,
2109                            );
2110                        }
2111                        record_segment_res(self.reborrow(), finalize, res, id);
2112                        return PathResult::NonModule(PartialRes::with_unresolved_segments(
2113                            res,
2114                            path.len() - segment_idx - 1,
2115                        ));
2116                    } else {
2117                        return PathResult::failed(
2118                            ident,
2119                            is_last,
2120                            finalize.is_some(),
2121                            module_had_parse_errors,
2122                            module,
2123                            || {
2124                                let import_inherent_item_error_flag =
2125                                    self.features.import_trait_associated_functions()
2126                                        && #[allow(non_exhaustive_omitted_patterns)] match res {
    Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union |
        DefKind::ForeignTy, _) => true,
    _ => false,
}matches!(
2127                                            res,
2128                                            Res::Def(
2129                                                DefKind::Struct
2130                                                    | DefKind::Enum
2131                                                    | DefKind::Union
2132                                                    | DefKind::ForeignTy,
2133                                                _
2134                                            )
2135                                        );
2136                                // Show a different error message for items that can have associated items.
2137                                let label = ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{3}` is {0} {1}, not a module{2}",
                res.article(), res.descr(),
                if import_inherent_item_error_flag {
                    " or a trait"
                } else { "" }, ident))
    })format!(
2138                                    "`{ident}` is {} {}, not a module{}",
2139                                    res.article(),
2140                                    res.descr(),
2141                                    if import_inherent_item_error_flag {
2142                                        " or a trait"
2143                                    } else {
2144                                        ""
2145                                    }
2146                                );
2147                                let scope = match &path[..segment_idx] {
2148                                    [.., prev] => {
2149                                        if prev.ident.name == kw::PathRoot {
2150                                            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("the crate root"))
    })format!("the crate root")
2151                                        } else {
2152                                            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}`", prev.ident))
    })format!("`{}`", prev.ident)
2153                                        }
2154                                    }
2155                                    _ => ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("this scope"))
    })format!("this scope"),
2156                                };
2157                                // FIXME: reword, as the reason we expected a module is because of
2158                                // the following path segment.
2159                                let message = ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("cannot find module `{0}` in {1}",
                ident, scope))
    })format!("cannot find module `{ident}` in {scope}");
2160                                let note = if import_inherent_item_error_flag {
2161                                    Some(
2162                                        "cannot import inherent associated items, only trait associated items".to_string(),
2163                                    )
2164                                } else {
2165                                    None
2166                                };
2167                                (message, label, None, note, None)
2168                            },
2169                        );
2170                    }
2171                }
2172                Err(Undetermined) if finalize.is_none() => return PathResult::Indeterminate,
2173                Err(Determined | Undetermined) => {
2174                    if let Some(ModuleOrUniformRoot::Module(module)) = module
2175                        && opt_ns.is_some()
2176                        && !module.is_normal()
2177                    {
2178                        return PathResult::NonModule(PartialRes::with_unresolved_segments(
2179                            module.res().unwrap(),
2180                            path.len() - segment_idx,
2181                        ));
2182                    }
2183
2184                    let mut this = self.reborrow();
2185                    return PathResult::failed(
2186                        ident,
2187                        is_last,
2188                        finalize.is_some(),
2189                        module_had_parse_errors,
2190                        module,
2191                        || {
2192                            let (message, label, suggestion, help) =
2193                                this.get_mut().report_path_resolution_error(
2194                                    path,
2195                                    opt_ns,
2196                                    parent_scope,
2197                                    ribs,
2198                                    ignore_decl,
2199                                    ignore_import,
2200                                    module,
2201                                    segment_idx,
2202                                    ident,
2203                                    diag_metadata,
2204                                );
2205                            (message, label, suggestion, None, help)
2206                        },
2207                    );
2208                }
2209            }
2210        }
2211
2212        if let Some(finalize) = finalize {
2213            self.get_mut().lint_if_path_starts_with_module(finalize, path, second_binding);
2214        }
2215
2216        PathResult::Module(match module {
2217            Some(module) => module,
2218            None if path.is_empty() => ModuleOrUniformRoot::CurrentScope,
2219            _ => ::rustc_span::macros::bug_impl(None,
    format_args!("resolve_path: non-empty path `{0:?}` has no module", path),
    Location::caller())bug!("resolve_path: non-empty path `{:?}` has no module", path),
2220        })
2221    }
2222}