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, OrdSpan, 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 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 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 ScopeSet::Module(_, module) | ScopeSet::ModuleAndExternPrelude(_, module) => module,
119 _ => 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 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 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 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, 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, MacroNS => Scope::BuiltinAttrs,
236 },
237 Scope::BuiltinTypes => break, };
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 if derive_fallback_lint_id.is_some()
271 && let Some(parent) = module.parent
272 && module.expansion != parent.expansion
274 && module.expansion.is_descendant_of(parent.expansion)
276 && 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 {}
#[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/7df81381d027710708209f36b98d11b1c88f8d2e/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/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs:335",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/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 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 for (i, rib) in ribs.iter().enumerate().rev() {
335 debug!("walk rib\n{:?}", rib.bindings);
336 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 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 return Some(LateDecl::Decl(binding));
362 } else if let RibKind::Module(module) = rib.kind {
363 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 ident.span.remove_mark();
386 }
387 }
388
389 unreachable!()
390 }
391
392 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 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 let mut innermost_results: SmallVec<[(Decl<'_>, Scope<'_>); 2]> = SmallVec::new();
452 let mut determinacy = Determinacy::Determined;
453
454 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 if innermost_results.is_empty() { finalize } else { None },
473 ignore_decl,
474 ignore_import,
475 ) {
476 Ok(decl) => Ok(decl),
477 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 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 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 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 if let Some(break_result) = break_result {
535 return break_result;
536 }
537
538 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 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 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 ::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 Some(AmbiguityKind::GlobVsExpanded)
900 } else {
901 None
902 };
903
904 if let Some(kind) = ambiguity_error_kind {
905 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 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 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/7df81381d027710708209f36b98d11b1c88f8d2e/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/7df81381d027710708209f36b98d11b1c88f8d2e/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 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 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 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 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 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 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 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 let _cycle_guard = cycle_detection::enter_cycle_detector(module, key)
1195 .map_err(|_| ControlFlow::Continue(Determined))?;
1196
1197 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 if module.has_unexpanded_invocations(&self) {
1212 return Err(ControlFlow::Continue(Undetermined));
1213 }
1214
1215 Err(ControlFlow::Continue(Determined))
1217 }
1218
1219 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 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 let _cycle_guard = cycle_detection::enter_cycle_detector(module, key)
1254 .map_err(|_| ControlFlow::Continue(Determined))?;
1255
1256 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 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 if module.has_unexpanded_invocations(&self) {
1303 return Err(ControlFlow::Continue(Undetermined));
1304 }
1305
1306 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 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
1397 .insert((OrdSpan(path_span), OrdSpan(binding.span)));
1398 }
1399
1400 self.record_use(ident, binding, used);
1401 return Ok(binding);
1402 }
1403
1404 fn single_import_can_define_name<'r>(
1407 mut self: CmResolver<'r, 'ra, 'tcx>,
1408 resolution: &NameResolution<'ra>,
1409 binding: Option<Decl<'ra>>,
1410 ns: Namespace,
1411 ignore_import: Option<Import<'ra>>,
1412 ignore_decl: Option<Decl<'ra>>,
1413 parent_scope: &ParentScope<'ra>,
1414 ) -> bool {
1415 for single_import in &resolution.single_imports {
1416 if let Some(decl) = resolution.non_glob_decl
1417 && let DeclKind::Import { import, .. } = decl.kind
1418 && import == *single_import
1419 {
1420 continue;
1423 }
1424 if ignore_import == Some(*single_import) {
1425 continue;
1426 }
1427 if !self.is_accessible_from(single_import.vis, parent_scope.module) {
1428 continue;
1429 }
1430 if let Some(ignored) = ignore_decl
1431 && let DeclKind::Import { import, .. } = ignored.kind
1432 && import == *single_import
1433 {
1434 continue;
1435 }
1436
1437 let Some(module) = single_import.imported_module.get() else {
1438 return true;
1439 };
1440 let ImportKind::Single { source, target, decls, .. } = &single_import.kind else {
1441 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1442 };
1443 if source != target {
1444 if decls.iter().all(|d| d.get().decl().is_none()) {
1445 return true;
1446 } else if decls[ns].get().decl().is_none() && binding.is_some() {
1447 return true;
1448 }
1449 }
1450
1451 match self.reborrow().resolve_ident_in_module(
1452 module,
1453 *source,
1454 ns,
1455 &single_import.parent_scope,
1456 None,
1457 ignore_decl,
1458 None,
1459 ) {
1460 Err(Determined) => continue,
1461 Ok(binding)
1462 if !self
1463 .is_accessible_from(binding.vis(), single_import.parent_scope.module) =>
1464 {
1465 continue;
1466 }
1467 Ok(_) | Err(Undetermined) => return true,
1468 }
1469 }
1470
1471 false
1472 }
1473
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/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1475u32),
::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/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs:1486",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1486u32),
::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_const_items: 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_const_items: 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))]
1476 fn validate_res_from_ribs(
1477 &self,
1478 rib_index: usize,
1479 rib_ident: Ident,
1480 res: Res,
1481 finalize: Option<Span>,
1482 original_rib_ident_def: Ident,
1483 all_ribs: &[Rib<'ra>],
1484 diag_metadata: Option<&DiagMetadata<'_>>,
1485 ) -> Res {
1486 debug!("validate_res_from_ribs({:?})", res);
1487 let ribs = &all_ribs[rib_index + 1..];
1488
1489 if let RibKind::ForwardGenericParamBan(reason) = all_ribs[rib_index].kind {
1492 if let Some(span) = finalize {
1493 let res_error = if rib_ident.name == kw::SelfUpper {
1494 ResolutionError::ForwardDeclaredSelf(reason)
1495 } else {
1496 ResolutionError::ForwardDeclaredGenericParam(rib_ident.name, reason)
1497 };
1498 self.report_error(span, res_error);
1499 }
1500 assert_eq!(res, Res::Err);
1501 return Res::Err;
1502 }
1503
1504 match res {
1505 Res::Local(_) => {
1506 use ResolutionError::*;
1507 let mut res_err = None;
1508
1509 let suggest_closure =
1510 !ribs.iter().any(|rib| matches!(rib.kind, RibKind::AssocItem));
1511
1512 for rib in ribs {
1513 match rib.kind {
1514 RibKind::Normal
1515 | RibKind::Block(..)
1516 | RibKind::FnOrCoroutine
1517 | RibKind::Module(..)
1518 | RibKind::MacroDefinition(..)
1519 | RibKind::ForwardGenericParamBan(_) => {
1520 }
1522 RibKind::Item(..) | RibKind::AssocItem => {
1523 if let Some(span) = finalize {
1527 res_err = Some((
1532 span,
1533 CannotCaptureDynamicEnvironmentInFnItem { suggest_closure },
1534 ));
1535 }
1536 }
1537 RibKind::ConstantItem(_, item, requires_type) => {
1538 if let Some(span) = finalize {
1540 let (span, resolution_error) = match item {
1541 None if rib_ident.name == kw::SelfLower => {
1542 (span, LowercaseSelf)
1543 }
1544 None => {
1545 let sm = self.tcx.sess.source_map();
1551 let type_span = match sm
1552 .span_followed_by(original_rib_ident_def.span, ":")
1553 {
1554 None => {
1555 Some(original_rib_ident_def.span.shrink_to_hi())
1556 }
1557 Some(_) => None,
1558 };
1559 (
1560 rib_ident.span,
1561 AttemptToUseNonConstantValueInConstant {
1562 ident: original_rib_ident_def,
1563 suggestion: "const",
1564 current: "let",
1565 type_span,
1566 requires_type,
1567 },
1568 )
1569 }
1570 Some((ident, kind)) => (
1571 span,
1572 AttemptToUseNonConstantValueInConstant {
1573 ident,
1574 suggestion: "let",
1575 current: kind.as_str(),
1576 type_span: None,
1577 requires_type,
1578 },
1579 ),
1580 };
1581 self.report_error(span, resolution_error);
1582 }
1583 return Res::Err;
1584 }
1585 RibKind::ConstParamTy => {
1586 if let Some(span) = finalize {
1587 self.report_error(
1588 span,
1589 ParamInTyOfConstParam { name: rib_ident.name },
1590 );
1591 }
1592 return Res::Err;
1593 }
1594 RibKind::InlineAsmSym => {
1595 if let Some(span) = finalize {
1596 self.report_error(span, InvalidAsmSym);
1597 }
1598 return Res::Err;
1599 }
1600 }
1601 }
1602 if let Some((span, res_err)) = res_err {
1603 self.report_error(span, res_err);
1604 return Res::Err;
1605 }
1606 }
1607 Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
1608 for rib in ribs {
1609 let (has_generic_params, def_kind) = match rib.kind {
1610 RibKind::Normal
1611 | RibKind::Block(..)
1612 | RibKind::FnOrCoroutine
1613 | RibKind::Module(..)
1614 | RibKind::MacroDefinition(..)
1615 | RibKind::InlineAsmSym
1616 | RibKind::AssocItem
1617 | RibKind::ForwardGenericParamBan(_) => {
1618 continue;
1620 }
1621
1622 RibKind::ConstParamTy => {
1623 let adt_enabled = self.features.min_adt_const_params()
1624 || self.features.adt_const_params();
1625 let is_self = matches!(res, Res::SelfTyAlias { .. });
1626 if self.features.generic_const_parameter_types()
1628 || (adt_enabled && is_self)
1629 {
1630 continue;
1631 } else {
1632 if let Some(span) = finalize {
1633 if matches!(res, Res::SelfTyAlias { .. }) {
1634 self.report_error(span, ResolutionError::SelfInConstParam);
1635 } else {
1636 self.report_error(
1637 span,
1638 ResolutionError::ParamInTyOfConstParam {
1639 name: rib_ident.name,
1640 },
1641 );
1642 }
1643 }
1644 return Res::Err;
1645 }
1646 }
1647
1648 RibKind::ConstantItem(trivial, _, _) => {
1649 if let ConstantHasGenerics::No(cause) = trivial
1650 && !matches!(res, Res::SelfTyAlias { .. })
1651 {
1652 if let Some(span) = finalize {
1653 let error = match cause {
1654 NoConstantGenericsReason::IsEnumDiscriminant => {
1655 ResolutionError::ParamInEnumDiscriminant {
1656 name: rib_ident.name,
1657 param_kind: ParamKindInEnumDiscriminant::Type,
1658 }
1659 }
1660 NoConstantGenericsReason::NonTrivialConstArg => {
1661 ResolutionError::ParamInNonTrivialAnonConst {
1662 is_gca_const_items: self.features.gca_const_items(),
1663 name: rib_ident.name,
1664 param_kind: ParamKindInNonTrivialAnonConst::Type,
1665 }
1666 }
1667 };
1668 let _: ErrorGuaranteed = self.report_error(span, error);
1669 }
1670
1671 return Res::Err;
1672 }
1673
1674 continue;
1675 }
1676
1677 RibKind::Item(has_generic_params, def_kind) => {
1679 (has_generic_params, def_kind)
1680 }
1681 };
1682
1683 if let Some(span) = finalize {
1684 let item = if let Some(diag_metadata) = diag_metadata
1685 && let Some(current_item) = diag_metadata.current_item
1686 {
1687 let label_span = current_item
1688 .kind
1689 .ident()
1690 .map(|i| i.span)
1691 .unwrap_or(current_item.span);
1692 Some((label_span, current_item.span, current_item.kind.clone()))
1693 } else {
1694 None
1695 };
1696 self.report_error(
1697 span,
1698 ResolutionError::GenericParamsFromOuterItem {
1699 outer_res: res,
1700 has_generic_params,
1701 def_kind,
1702 inner_item: item,
1703 current_self_ty: diag_metadata
1704 .and_then(|m| m.current_self_type.as_ref())
1705 .and_then(|ty| {
1706 self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
1707 }),
1708 },
1709 );
1710 }
1711 return Res::Err;
1712 }
1713 }
1714 Res::Def(DefKind::ConstParam, _) => {
1715 for rib in ribs {
1716 let (has_generic_params, def_kind) = match rib.kind {
1717 RibKind::Normal
1718 | RibKind::Block(..)
1719 | RibKind::FnOrCoroutine
1720 | RibKind::Module(..)
1721 | RibKind::MacroDefinition(..)
1722 | RibKind::InlineAsmSym
1723 | RibKind::AssocItem
1724 | RibKind::ForwardGenericParamBan(_) => continue,
1725
1726 RibKind::ConstParamTy => {
1727 if !self.features.generic_const_parameter_types() {
1728 if let Some(span) = finalize {
1729 self.report_error(
1730 span,
1731 ResolutionError::ParamInTyOfConstParam {
1732 name: rib_ident.name,
1733 },
1734 );
1735 }
1736 return Res::Err;
1737 } else {
1738 continue;
1739 }
1740 }
1741
1742 RibKind::ConstantItem(trivial, _, _) => {
1743 if let ConstantHasGenerics::No(cause) = trivial {
1744 if let Some(span) = finalize {
1745 let error = match cause {
1746 NoConstantGenericsReason::IsEnumDiscriminant => {
1747 ResolutionError::ParamInEnumDiscriminant {
1748 name: rib_ident.name,
1749 param_kind: ParamKindInEnumDiscriminant::Const,
1750 }
1751 }
1752 NoConstantGenericsReason::NonTrivialConstArg => {
1753 ResolutionError::ParamInNonTrivialAnonConst {
1754 is_gca_const_items: self.features.gca_const_items(),
1755 name: rib_ident.name,
1756 param_kind: ParamKindInNonTrivialAnonConst::Const {
1757 name: rib_ident.name,
1758 },
1759 }
1760 }
1761 };
1762 self.report_error(span, error);
1763 }
1764
1765 return Res::Err;
1766 }
1767
1768 continue;
1769 }
1770
1771 RibKind::Item(has_generic_params, def_kind) => {
1772 (has_generic_params, def_kind)
1773 }
1774 };
1775
1776 if let Some(span) = finalize {
1778 let item = if let Some(diag_metadata) = diag_metadata
1779 && let Some(current_item) = diag_metadata.current_item
1780 {
1781 let label_span = current_item
1782 .kind
1783 .ident()
1784 .map(|i| i.span)
1785 .unwrap_or(current_item.span);
1786 Some((label_span, current_item.span, current_item.kind.clone()))
1787 } else {
1788 None
1789 };
1790 self.report_error(
1791 span,
1792 ResolutionError::GenericParamsFromOuterItem {
1793 outer_res: res,
1794 has_generic_params,
1795 def_kind,
1796 inner_item: item,
1797 current_self_ty: diag_metadata
1798 .and_then(|m| m.current_self_type.as_ref())
1799 .and_then(|ty| {
1800 self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
1801 }),
1802 },
1803 );
1804 }
1805 return Res::Err;
1806 }
1807 }
1808 _ => {}
1809 }
1810
1811 res
1812 }
1813
1814 {}
#[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/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1814u32),
::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))]
1815 pub(crate) fn maybe_resolve_path<'r>(
1816 self: CmResolver<'r, 'ra, 'tcx>,
1817 path: &[Segment],
1818 opt_ns: Option<Namespace>, parent_scope: &ParentScope<'ra>,
1820 ignore_import: Option<Import<'ra>>,
1821 ) -> PathResult<'ra> {
1822 self.resolve_path_with_ribs(
1823 path,
1824 opt_ns,
1825 parent_scope,
1826 None,
1827 None,
1828 None,
1829 None,
1830 ignore_import,
1831 None,
1832 )
1833 }
1834 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("resolve_path",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1834u32),
::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))]
1835 pub(crate) fn resolve_path<'r>(
1836 self: CmResolver<'r, 'ra, 'tcx>,
1837 path: &[Segment],
1838 opt_ns: Option<Namespace>, parent_scope: &ParentScope<'ra>,
1840 finalize: Option<Finalize>,
1841 ignore_decl: Option<Decl<'ra>>,
1842 ignore_import: Option<Import<'ra>>,
1843 ) -> PathResult<'ra> {
1844 self.resolve_path_with_ribs(
1845 path,
1846 opt_ns,
1847 parent_scope,
1848 None,
1849 finalize,
1850 None,
1851 ignore_decl,
1852 ignore_import,
1853 None,
1854 )
1855 }
1856
1857 pub(crate) fn resolve_path_with_ribs<'r>(
1858 mut self: CmResolver<'r, 'ra, 'tcx>,
1859 path: &[Segment],
1860 opt_ns: Option<Namespace>, parent_scope: &ParentScope<'ra>,
1862 source: Option<PathSource<'_, '_, '_>>,
1863 finalize: Option<Finalize>,
1864 ribs: Option<&PerNS<Vec<Rib<'ra>>>>,
1865 ignore_decl: Option<Decl<'ra>>,
1866 ignore_import: Option<Import<'ra>>,
1867 diag_metadata: Option<&DiagMetadata<'_>>,
1868 ) -> PathResult<'ra> {
1869 let mut module = None;
1870 let mut module_had_parse_errors = !self.mods_with_parse_errors.is_empty()
1871 && self
1872 .mods_with_parse_errors
1873 .contains(&parent_scope.module.nearest_parent_mod().to_def_id());
1874 let mut allow_super = true;
1875 let mut second_binding = None;
1876
1877 let privacy_errors_len = self.privacy_errors.len();
1879 fn record_segment_res<'r, 'ra, 'tcx>(
1880 mut this: CmResolver<'r, 'ra, 'tcx>,
1881 finalize: Option<Finalize>,
1882 res: Res,
1883 id: Option<NodeId>,
1884 ) {
1885 if finalize.is_some()
1886 && let Some(id) = id
1887 && !this.partial_res_map.contains_key(&id)
1888 {
1889 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");
1890 this.get_mut().record_partial_res(id, PartialRes::new(res));
1891 }
1892 }
1893
1894 for (segment_idx, &Segment { ident, id, .. }) in path.iter().enumerate() {
1895 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs:1895",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1895u32),
::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);
1896
1897 let is_last = segment_idx + 1 == path.len();
1898 let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
1899 let name = ident.name;
1900
1901 allow_super &= ns == TypeNS && (name == kw::SelfLower || name == kw::Super);
1902
1903 if ns == TypeNS {
1904 if allow_super && name == kw::Super {
1905 let parent = if segment_idx == 0 {
1906 self.resolve_super_in_module(ident, None, parent_scope)
1907 } else if let Some(ModuleOrUniformRoot::Module(module)) = module {
1908 self.resolve_super_in_module(ident, Some(module), parent_scope)
1909 } else {
1910 None
1911 };
1912 if let Some(parent) = parent {
1913 module = Some(ModuleOrUniformRoot::Module(parent));
1914 continue;
1915 }
1916 let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1917 let current_module = self.resolve_self(&mut ctxt, parent_scope.module);
1918 let current_module_path = module_to_string(current_module)
1919 .map_or_else(|| "crate".to_string(), |path| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("crate::{0}", path))
})format!("crate::{path}"));
1920 return PathResult::failed(
1921 ident,
1922 false,
1923 finalize.is_some(),
1924 module_had_parse_errors,
1925 module,
1926 || {
1927 (
1928 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("too many leading `super` keywords within `{0}`",
current_module_path))
})format!(
1929 "too many leading `super` keywords within `{current_module_path}`"
1930 ),
1931 "this `super` would go above the crate root".to_string(),
1932 None,
1933 None,
1934 None,
1935 )
1936 },
1937 );
1938 }
1939 if segment_idx == 0 {
1940 if name == kw::SelfLower {
1941 let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1942 let self_mod = self.resolve_self(&mut ctxt, parent_scope.module);
1943 if let Some(res) = self_mod.res() {
1944 record_segment_res(self.reborrow(), finalize, res, id);
1945 }
1946 module = Some(ModuleOrUniformRoot::Module(self_mod));
1947 continue;
1948 }
1949 if name == kw::PathRoot && ident.span.at_least_rust_2018() {
1950 module = Some(ModuleOrUniformRoot::ExternPrelude);
1951 continue;
1952 }
1953 if name == kw::PathRoot
1954 && ident.span.is_rust_2015()
1955 && self.tcx.sess.at_least_rust_2018()
1956 {
1957 let crate_root = self.resolve_crate_root(ident);
1959 module = Some(ModuleOrUniformRoot::ModuleAndExternPrelude(crate_root));
1960 continue;
1961 }
1962 if name == kw::PathRoot || name == kw::Crate || name == kw::DollarCrate {
1963 let crate_root = self.resolve_crate_root(ident);
1965 if let Some(res) = crate_root.res() {
1966 record_segment_res(self.reborrow(), finalize, res, id);
1967 }
1968 module = Some(ModuleOrUniformRoot::Module(crate_root));
1969 continue;
1970 }
1971 }
1972 }
1973
1974 let allow_trailing_self = is_last && name == kw::SelfLower;
1975
1976 if ident.is_path_segment_keyword() && segment_idx != 0 && !allow_trailing_self {
1978 return PathResult::failed(
1979 ident,
1980 false,
1981 finalize.is_some(),
1982 module_had_parse_errors,
1983 module,
1984 || {
1985 let name_str = if name == kw::PathRoot {
1986 "the crate root".to_string()
1987 } else {
1988 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", name))
})format!("`{name}`")
1989 };
1990 let (message, label) = if segment_idx == 1
1991 && path[0].ident.name == kw::PathRoot
1992 {
1993 (
1994 ::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}"),
1995 "cannot start with this".to_string(),
1996 )
1997 } else if name == kw::SelfLower {
1998 (
1999 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`self` in paths can only be used in start position or last position"))
})format!(
2000 "`self` in paths can only be used in start position or last position"
2001 ),
2002 "can only be used in path start position or last position"
2003 .to_string(),
2004 )
2005 } else {
2006 (
2007 ::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"),
2008 "can only be used in path start position".to_string(),
2009 )
2010 };
2011 (message, label, None, None, None)
2012 },
2013 );
2014 }
2015
2016 let binding = if let Some(module) = module {
2017 self.reborrow().resolve_ident_in_module(
2018 module,
2019 ident,
2020 ns,
2021 parent_scope,
2022 finalize,
2023 ignore_decl,
2024 ignore_import,
2025 )
2026 } else if let Some(ribs) = ribs
2027 && let Some(TypeNS | ValueNS) = opt_ns
2028 {
2029 if !ignore_import.is_none() {
::core::panicking::panic("assertion failed: ignore_import.is_none()")
};assert!(ignore_import.is_none());
2030 match self.get_mut().resolve_ident_in_lexical_scope(
2031 ident,
2032 ns,
2033 parent_scope,
2034 finalize,
2035 &ribs[ns],
2036 ignore_decl,
2037 diag_metadata,
2038 ) {
2039 Some(LateDecl::Decl(binding)) => Ok(binding),
2041 Some(LateDecl::RibDef(res)) => {
2043 record_segment_res(self.reborrow(), finalize, res, id);
2044 return PathResult::NonModule(PartialRes::with_unresolved_segments(
2045 res,
2046 path.len() - 1,
2047 ));
2048 }
2049 _ => Err(Determinacy::determined(finalize.is_some())),
2050 }
2051 } else {
2052 self.reborrow().resolve_ident_in_scope_set(
2053 ident,
2054 ScopeSet::All(ns),
2055 parent_scope,
2056 finalize,
2057 ignore_decl,
2058 ignore_import,
2059 )
2060 };
2061
2062 match binding {
2063 Ok(binding) => {
2064 if segment_idx == 1 {
2065 second_binding = Some(binding);
2066 }
2067 let res = binding.res();
2068
2069 if finalize.is_some() {
2073 for error in &mut self.get_mut().privacy_errors[privacy_errors_len..] {
2074 error.outermost_res = Some((res, ident));
2075 error.source = match source {
2076 Some(PathSource::Struct(Some(expr)))
2077 | Some(PathSource::Expr(Some(expr))) => Some(expr.clone()),
2078 _ => None,
2079 };
2080 }
2081 }
2082
2083 let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(res);
2084 if let Res::OpenMod(sym) = binding.res() {
2085 module = Some(ModuleOrUniformRoot::OpenModule(sym));
2086 record_segment_res(self.reborrow(), finalize, res, id);
2087 } else if let Some(def_id) = binding.res().module_like_def_id() {
2088 if self.mods_with_parse_errors.contains(&def_id) {
2089 module_had_parse_errors = true;
2090 }
2091 module = Some(ModuleOrUniformRoot::Module(self.expect_module(def_id)));
2092 record_segment_res(self.reborrow(), finalize, res, id);
2093 } else if res == Res::ToolMod && !is_last && opt_ns.is_some() {
2094 if binding.is_import() {
2095 self.dcx().emit_err(diagnostics::ToolModuleImported {
2096 span: ident.span,
2097 import: binding.span,
2098 });
2099 }
2100 let res = Res::NonMacroAttr(NonMacroAttrKind::Tool);
2101 return PathResult::NonModule(PartialRes::new(res));
2102 } else if res == Res::Err {
2103 return PathResult::NonModule(PartialRes::new(Res::Err));
2104 } else if opt_ns.is_some() && (is_last || maybe_assoc) {
2105 if let Some(finalize) = finalize {
2106 self.get_mut().lint_if_path_starts_with_module(
2107 finalize,
2108 path,
2109 second_binding,
2110 );
2111 }
2112 record_segment_res(self.reborrow(), finalize, res, id);
2113 return PathResult::NonModule(PartialRes::with_unresolved_segments(
2114 res,
2115 path.len() - segment_idx - 1,
2116 ));
2117 } else {
2118 return PathResult::failed(
2119 ident,
2120 is_last,
2121 finalize.is_some(),
2122 module_had_parse_errors,
2123 module,
2124 || {
2125 let import_inherent_item_error_flag =
2126 self.features.import_trait_associated_functions()
2127 && #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union |
DefKind::ForeignTy, _) => true,
_ => false,
}matches!(
2128 res,
2129 Res::Def(
2130 DefKind::Struct
2131 | DefKind::Enum
2132 | DefKind::Union
2133 | DefKind::ForeignTy,
2134 _
2135 )
2136 );
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!(
2139 "`{ident}` is {} {}, not a module{}",
2140 res.article(),
2141 res.descr(),
2142 if import_inherent_item_error_flag {
2143 " or a trait"
2144 } else {
2145 ""
2146 }
2147 );
2148 let scope = match &path[..segment_idx] {
2149 [.., prev] => {
2150 if prev.ident.name == kw::PathRoot {
2151 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("the crate root"))
})format!("the crate root")
2152 } else {
2153 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", prev.ident))
})format!("`{}`", prev.ident)
2154 }
2155 }
2156 _ => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("this scope"))
})format!("this scope"),
2157 };
2158 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}");
2161 let note = if import_inherent_item_error_flag {
2162 Some(
2163 "cannot import inherent associated items, only trait associated items".to_string(),
2164 )
2165 } else {
2166 None
2167 };
2168 (message, label, None, note, None)
2169 },
2170 );
2171 }
2172 }
2173 Err(Undetermined) if finalize.is_none() => return PathResult::Indeterminate,
2174 Err(Determined | Undetermined) => {
2175 if let Some(ModuleOrUniformRoot::Module(module)) = module
2176 && opt_ns.is_some()
2177 && !module.is_normal()
2178 {
2179 return PathResult::NonModule(PartialRes::with_unresolved_segments(
2180 module.res().unwrap(),
2181 path.len() - segment_idx,
2182 ));
2183 }
2184
2185 let mut this = self.reborrow();
2186 return PathResult::failed(
2187 ident,
2188 is_last,
2189 finalize.is_some(),
2190 module_had_parse_errors,
2191 module,
2192 || {
2193 let (message, label, suggestion, help) =
2194 this.get_mut().report_path_resolution_error(
2195 path,
2196 opt_ns,
2197 parent_scope,
2198 ribs,
2199 ignore_decl,
2200 ignore_import,
2201 module,
2202 segment_idx,
2203 ident,
2204 diag_metadata,
2205 );
2206 (message, label, suggestion, None, help)
2207 },
2208 );
2209 }
2210 }
2211 }
2212
2213 if let Some(finalize) = finalize {
2214 self.get_mut().lint_if_path_starts_with_module(finalize, path, second_binding);
2215 }
2216
2217 PathResult::Module(match module {
2218 Some(module) => module,
2219 None if path.is_empty() => ModuleOrUniformRoot::CurrentScope,
2220 _ => ::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),
2221 })
2222 }
2223}