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/b6eeb93c992027a03e1fd120b6652546396b142c/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/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_resolve/src/ident.rs:335",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/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/b6eeb93c992027a03e1fd120b6652546396b142c/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/b6eeb93c992027a03e1fd120b6652546396b142c/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/b6eeb93c992027a03e1fd120b6652546396b142c/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/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_resolve/src/ident.rs:1486",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/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::MoveExpr { first_rib, move_expr_span, scope_span }
if rib_index >= first_rib => {
if let Some(span) = finalize {
self.report_error(span,
CannotUseInnerLocalInMoveExpr {
move_expr_span,
ident: original_rib_ident_def,
scope_span,
});
}
return Res::Err;
}
RibKind::Normal | RibKind::Block(..) |
RibKind::FnOrCoroutine | RibKind::MoveExpr { .. } |
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::MoveExpr { .. } |
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::MoveExpr { .. } |
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::MoveExpr { first_rib, move_expr_span, scope_span }
1518 if rib_index >= first_rib =>
1519 {
1520 if let Some(span) = finalize {
1521 self.report_error(
1522 span,
1523 CannotUseInnerLocalInMoveExpr {
1524 move_expr_span,
1525 ident: original_rib_ident_def,
1526 scope_span,
1527 },
1528 );
1529 }
1530 return Res::Err;
1531 }
1532 RibKind::Normal
1533 | RibKind::Block(..)
1534 | RibKind::FnOrCoroutine
1535 | RibKind::MoveExpr { .. }
1536 | RibKind::Module(..)
1537 | RibKind::MacroDefinition(..)
1538 | RibKind::ForwardGenericParamBan(_) => {
1539 }
1541 RibKind::Item(..) | RibKind::AssocItem => {
1542 if let Some(span) = finalize {
1546 res_err = Some((
1551 span,
1552 CannotCaptureDynamicEnvironmentInFnItem { suggest_closure },
1553 ));
1554 }
1555 }
1556 RibKind::ConstantItem(_, item, requires_type) => {
1557 if let Some(span) = finalize {
1559 let (span, resolution_error) = match item {
1560 None if rib_ident.name == kw::SelfLower => {
1561 (span, LowercaseSelf)
1562 }
1563 None => {
1564 let sm = self.tcx.sess.source_map();
1570 let type_span = match sm
1571 .span_followed_by(original_rib_ident_def.span, ":")
1572 {
1573 None => {
1574 Some(original_rib_ident_def.span.shrink_to_hi())
1575 }
1576 Some(_) => None,
1577 };
1578 (
1579 rib_ident.span,
1580 AttemptToUseNonConstantValueInConstant {
1581 ident: original_rib_ident_def,
1582 suggestion: "const",
1583 current: "let",
1584 type_span,
1585 requires_type,
1586 },
1587 )
1588 }
1589 Some((ident, kind)) => (
1590 span,
1591 AttemptToUseNonConstantValueInConstant {
1592 ident,
1593 suggestion: "let",
1594 current: kind.as_str(),
1595 type_span: None,
1596 requires_type,
1597 },
1598 ),
1599 };
1600 self.report_error(span, resolution_error);
1601 }
1602 return Res::Err;
1603 }
1604 RibKind::ConstParamTy => {
1605 if let Some(span) = finalize {
1606 self.report_error(
1607 span,
1608 ParamInTyOfConstParam { name: rib_ident.name },
1609 );
1610 }
1611 return Res::Err;
1612 }
1613 RibKind::InlineAsmSym => {
1614 if let Some(span) = finalize {
1615 self.report_error(span, InvalidAsmSym);
1616 }
1617 return Res::Err;
1618 }
1619 }
1620 }
1621 if let Some((span, res_err)) = res_err {
1622 self.report_error(span, res_err);
1623 return Res::Err;
1624 }
1625 }
1626 Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
1627 for rib in ribs {
1628 let (has_generic_params, def_kind) = match rib.kind {
1629 RibKind::Normal
1630 | RibKind::Block(..)
1631 | RibKind::FnOrCoroutine
1632 | RibKind::MoveExpr { .. }
1633 | RibKind::Module(..)
1634 | RibKind::MacroDefinition(..)
1635 | RibKind::InlineAsmSym
1636 | RibKind::AssocItem
1637 | RibKind::ForwardGenericParamBan(_) => {
1638 continue;
1640 }
1641
1642 RibKind::ConstParamTy => {
1643 let adt_enabled = self.features.min_adt_const_params()
1644 || self.features.adt_const_params();
1645 let is_self = matches!(res, Res::SelfTyAlias { .. });
1646 if self.features.generic_const_parameter_types()
1648 || (adt_enabled && is_self)
1649 {
1650 continue;
1651 } else {
1652 if let Some(span) = finalize {
1653 if matches!(res, Res::SelfTyAlias { .. }) {
1654 self.report_error(span, ResolutionError::SelfInConstParam);
1655 } else {
1656 self.report_error(
1657 span,
1658 ResolutionError::ParamInTyOfConstParam {
1659 name: rib_ident.name,
1660 },
1661 );
1662 }
1663 }
1664 return Res::Err;
1665 }
1666 }
1667
1668 RibKind::ConstantItem(trivial, _, _) => {
1669 if let ConstantHasGenerics::No(cause) = trivial
1670 && !matches!(res, Res::SelfTyAlias { .. })
1671 {
1672 if let Some(span) = finalize {
1673 let error = match cause {
1674 NoConstantGenericsReason::IsEnumDiscriminant => {
1675 ResolutionError::ParamInEnumDiscriminant {
1676 name: rib_ident.name,
1677 param_kind: ParamKindInEnumDiscriminant::Type,
1678 }
1679 }
1680 NoConstantGenericsReason::NonTrivialConstArg => {
1681 ResolutionError::ParamInNonTrivialAnonConst {
1682 is_gca_const_items: self.features.gca_const_items(),
1683 name: rib_ident.name,
1684 param_kind: ParamKindInNonTrivialAnonConst::Type,
1685 }
1686 }
1687 };
1688 let _: ErrorGuaranteed = self.report_error(span, error);
1689 }
1690
1691 return Res::Err;
1692 }
1693
1694 continue;
1695 }
1696
1697 RibKind::Item(has_generic_params, def_kind) => {
1699 (has_generic_params, def_kind)
1700 }
1701 };
1702
1703 if let Some(span) = finalize {
1704 let item = if let Some(diag_metadata) = diag_metadata
1705 && let Some(current_item) = diag_metadata.current_item
1706 {
1707 let label_span = current_item
1708 .kind
1709 .ident()
1710 .map(|i| i.span)
1711 .unwrap_or(current_item.span);
1712 Some((label_span, current_item.span, current_item.kind.clone()))
1713 } else {
1714 None
1715 };
1716 self.report_error(
1717 span,
1718 ResolutionError::GenericParamsFromOuterItem {
1719 outer_res: res,
1720 has_generic_params,
1721 def_kind,
1722 inner_item: item,
1723 current_self_ty: diag_metadata
1724 .and_then(|m| m.current_self_type.as_ref())
1725 .and_then(|ty| {
1726 self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
1727 }),
1728 },
1729 );
1730 }
1731 return Res::Err;
1732 }
1733 }
1734 Res::Def(DefKind::ConstParam, _) => {
1735 for rib in ribs {
1736 let (has_generic_params, def_kind) = match rib.kind {
1737 RibKind::Normal
1738 | RibKind::Block(..)
1739 | RibKind::FnOrCoroutine
1740 | RibKind::MoveExpr { .. }
1741 | RibKind::Module(..)
1742 | RibKind::MacroDefinition(..)
1743 | RibKind::InlineAsmSym
1744 | RibKind::AssocItem
1745 | RibKind::ForwardGenericParamBan(_) => continue,
1746
1747 RibKind::ConstParamTy => {
1748 if !self.features.generic_const_parameter_types() {
1749 if let Some(span) = finalize {
1750 self.report_error(
1751 span,
1752 ResolutionError::ParamInTyOfConstParam {
1753 name: rib_ident.name,
1754 },
1755 );
1756 }
1757 return Res::Err;
1758 } else {
1759 continue;
1760 }
1761 }
1762
1763 RibKind::ConstantItem(trivial, _, _) => {
1764 if let ConstantHasGenerics::No(cause) = trivial {
1765 if let Some(span) = finalize {
1766 let error = match cause {
1767 NoConstantGenericsReason::IsEnumDiscriminant => {
1768 ResolutionError::ParamInEnumDiscriminant {
1769 name: rib_ident.name,
1770 param_kind: ParamKindInEnumDiscriminant::Const,
1771 }
1772 }
1773 NoConstantGenericsReason::NonTrivialConstArg => {
1774 ResolutionError::ParamInNonTrivialAnonConst {
1775 is_gca_const_items: self.features.gca_const_items(),
1776 name: rib_ident.name,
1777 param_kind: ParamKindInNonTrivialAnonConst::Const {
1778 name: rib_ident.name,
1779 },
1780 }
1781 }
1782 };
1783 self.report_error(span, error);
1784 }
1785
1786 return Res::Err;
1787 }
1788
1789 continue;
1790 }
1791
1792 RibKind::Item(has_generic_params, def_kind) => {
1793 (has_generic_params, def_kind)
1794 }
1795 };
1796
1797 if let Some(span) = finalize {
1799 let item = if let Some(diag_metadata) = diag_metadata
1800 && let Some(current_item) = diag_metadata.current_item
1801 {
1802 let label_span = current_item
1803 .kind
1804 .ident()
1805 .map(|i| i.span)
1806 .unwrap_or(current_item.span);
1807 Some((label_span, current_item.span, current_item.kind.clone()))
1808 } else {
1809 None
1810 };
1811 self.report_error(
1812 span,
1813 ResolutionError::GenericParamsFromOuterItem {
1814 outer_res: res,
1815 has_generic_params,
1816 def_kind,
1817 inner_item: item,
1818 current_self_ty: diag_metadata
1819 .and_then(|m| m.current_self_type.as_ref())
1820 .and_then(|ty| {
1821 self.tcx.sess.source_map().span_to_snippet(ty.span).ok()
1822 }),
1823 },
1824 );
1825 }
1826 return Res::Err;
1827 }
1828 }
1829 _ => {}
1830 }
1831
1832 res
1833 }
1834
1835 {}
#[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/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1835u32),
::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))]
1836 pub(crate) fn maybe_resolve_path<'r>(
1837 self: CmResolver<'r, 'ra, 'tcx>,
1838 path: &[Segment],
1839 opt_ns: Option<Namespace>, parent_scope: &ParentScope<'ra>,
1841 ignore_import: Option<Import<'ra>>,
1842 ) -> PathResult<'ra> {
1843 self.resolve_path_with_ribs(
1844 path,
1845 opt_ns,
1846 parent_scope,
1847 None,
1848 None,
1849 None,
1850 None,
1851 ignore_import,
1852 None,
1853 )
1854 }
1855 {}
#[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/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1855u32),
::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))]
1856 pub(crate) fn resolve_path<'r>(
1857 self: CmResolver<'r, 'ra, 'tcx>,
1858 path: &[Segment],
1859 opt_ns: Option<Namespace>, parent_scope: &ParentScope<'ra>,
1861 finalize: Option<Finalize>,
1862 ignore_decl: Option<Decl<'ra>>,
1863 ignore_import: Option<Import<'ra>>,
1864 ) -> PathResult<'ra> {
1865 self.resolve_path_with_ribs(
1866 path,
1867 opt_ns,
1868 parent_scope,
1869 None,
1870 finalize,
1871 None,
1872 ignore_decl,
1873 ignore_import,
1874 None,
1875 )
1876 }
1877
1878 pub(crate) fn resolve_path_with_ribs<'r>(
1879 mut self: CmResolver<'r, 'ra, 'tcx>,
1880 path: &[Segment],
1881 opt_ns: Option<Namespace>, parent_scope: &ParentScope<'ra>,
1883 source: Option<PathSource<'_, '_, '_>>,
1884 finalize: Option<Finalize>,
1885 ribs: Option<&PerNS<Vec<Rib<'ra>>>>,
1886 ignore_decl: Option<Decl<'ra>>,
1887 ignore_import: Option<Import<'ra>>,
1888 diag_metadata: Option<&DiagMetadata<'_>>,
1889 ) -> PathResult<'ra> {
1890 let mut module = None;
1891 let mut module_had_parse_errors = !self.mods_with_parse_errors.is_empty()
1892 && self
1893 .mods_with_parse_errors
1894 .contains(&parent_scope.module.nearest_parent_mod().to_def_id());
1895 let mut allow_super = true;
1896 let mut second_binding = None;
1897
1898 let privacy_errors_len = self.privacy_errors.len();
1900 fn record_segment_res<'r, 'ra, 'tcx>(
1901 mut this: CmResolver<'r, 'ra, 'tcx>,
1902 finalize: Option<Finalize>,
1903 res: Res,
1904 id: Option<NodeId>,
1905 ) {
1906 if finalize.is_some()
1907 && let Some(id) = id
1908 && !this.partial_res_map.contains_key(&id)
1909 {
1910 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");
1911 this.get_mut().record_partial_res(id, PartialRes::new(res));
1912 }
1913 }
1914
1915 for (segment_idx, &Segment { ident, id, .. }) in path.iter().enumerate() {
1916 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_resolve/src/ident.rs:1916",
"rustc_resolve::ident", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_resolve/src/ident.rs"),
::tracing_core::__macro_support::Option::Some(1916u32),
::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);
1917
1918 let is_last = segment_idx + 1 == path.len();
1919 let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
1920 let name = ident.name;
1921
1922 allow_super &= ns == TypeNS && (name == kw::SelfLower || name == kw::Super);
1923
1924 if ns == TypeNS {
1925 if allow_super && name == kw::Super {
1926 let parent = if segment_idx == 0 {
1927 self.resolve_super_in_module(ident, None, parent_scope)
1928 } else if let Some(ModuleOrUniformRoot::Module(module)) = module {
1929 self.resolve_super_in_module(ident, Some(module), parent_scope)
1930 } else {
1931 None
1932 };
1933 if let Some(parent) = parent {
1934 module = Some(ModuleOrUniformRoot::Module(parent));
1935 continue;
1936 }
1937 let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1938 let current_module = self.resolve_self(&mut ctxt, parent_scope.module);
1939 let current_module_path = module_to_string(current_module)
1940 .map_or_else(|| "crate".to_string(), |path| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("crate::{0}", path))
})format!("crate::{path}"));
1941 return PathResult::failed(
1942 ident,
1943 false,
1944 finalize.is_some(),
1945 module_had_parse_errors,
1946 module,
1947 || {
1948 (
1949 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("too many leading `super` keywords within `{0}`",
current_module_path))
})format!(
1950 "too many leading `super` keywords within `{current_module_path}`"
1951 ),
1952 "this `super` would go above the crate root".to_string(),
1953 None,
1954 None,
1955 None,
1956 )
1957 },
1958 );
1959 }
1960 if segment_idx == 0 {
1961 if name == kw::SelfLower {
1962 let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1963 let self_mod = self.resolve_self(&mut ctxt, parent_scope.module);
1964 if let Some(res) = self_mod.res() {
1965 record_segment_res(self.reborrow(), finalize, res, id);
1966 }
1967 module = Some(ModuleOrUniformRoot::Module(self_mod));
1968 continue;
1969 }
1970 if name == kw::PathRoot && ident.span.at_least_rust_2018() {
1971 module = Some(ModuleOrUniformRoot::ExternPrelude);
1972 continue;
1973 }
1974 if name == kw::PathRoot
1975 && ident.span.is_rust_2015()
1976 && self.tcx.sess.at_least_rust_2018()
1977 {
1978 let crate_root = self.resolve_crate_root(ident);
1980 module = Some(ModuleOrUniformRoot::ModuleAndExternPrelude(crate_root));
1981 continue;
1982 }
1983 if name == kw::PathRoot || name == kw::Crate || name == kw::DollarCrate {
1984 let crate_root = self.resolve_crate_root(ident);
1986 if let Some(res) = crate_root.res() {
1987 record_segment_res(self.reborrow(), finalize, res, id);
1988 }
1989 module = Some(ModuleOrUniformRoot::Module(crate_root));
1990 continue;
1991 }
1992 }
1993 }
1994
1995 let allow_trailing_self = is_last && name == kw::SelfLower;
1996
1997 if ident.is_path_segment_keyword() && segment_idx != 0 && !allow_trailing_self {
1999 return PathResult::failed(
2000 ident,
2001 false,
2002 finalize.is_some(),
2003 module_had_parse_errors,
2004 module,
2005 || {
2006 let name_str = if name == kw::PathRoot {
2007 "the crate root".to_string()
2008 } else {
2009 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", name))
})format!("`{name}`")
2010 };
2011 let (message, label) = if segment_idx == 1
2012 && path[0].ident.name == kw::PathRoot
2013 {
2014 (
2015 ::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}"),
2016 "cannot start with this".to_string(),
2017 )
2018 } else if name == kw::SelfLower {
2019 (
2020 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`self` in paths can only be used in start position or last position"))
})format!(
2021 "`self` in paths can only be used in start position or last position"
2022 ),
2023 "can only be used in path start position or last position"
2024 .to_string(),
2025 )
2026 } else {
2027 (
2028 ::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"),
2029 "can only be used in path start position".to_string(),
2030 )
2031 };
2032 (message, label, None, None, None)
2033 },
2034 );
2035 }
2036
2037 let binding = if let Some(module) = module {
2038 self.reborrow().resolve_ident_in_module(
2039 module,
2040 ident,
2041 ns,
2042 parent_scope,
2043 finalize,
2044 ignore_decl,
2045 ignore_import,
2046 )
2047 } else if let Some(ribs) = ribs
2048 && let Some(TypeNS | ValueNS) = opt_ns
2049 {
2050 if !ignore_import.is_none() {
::core::panicking::panic("assertion failed: ignore_import.is_none()")
};assert!(ignore_import.is_none());
2051 match self.get_mut().resolve_ident_in_lexical_scope(
2052 ident,
2053 ns,
2054 parent_scope,
2055 finalize,
2056 &ribs[ns],
2057 ignore_decl,
2058 diag_metadata,
2059 ) {
2060 Some(LateDecl::Decl(binding)) => Ok(binding),
2062 Some(LateDecl::RibDef(res)) => {
2064 record_segment_res(self.reborrow(), finalize, res, id);
2065 return PathResult::NonModule(PartialRes::with_unresolved_segments(
2066 res,
2067 path.len() - 1,
2068 ));
2069 }
2070 _ => Err(Determinacy::determined(finalize.is_some())),
2071 }
2072 } else {
2073 self.reborrow().resolve_ident_in_scope_set(
2074 ident,
2075 ScopeSet::All(ns),
2076 parent_scope,
2077 finalize,
2078 ignore_decl,
2079 ignore_import,
2080 )
2081 };
2082
2083 match binding {
2084 Ok(binding) => {
2085 if segment_idx == 1 {
2086 second_binding = Some(binding);
2087 }
2088 let res = binding.res();
2089
2090 if finalize.is_some() {
2094 for error in &mut self.get_mut().privacy_errors[privacy_errors_len..] {
2095 error.outermost_res = Some((res, ident));
2096 error.source = match source {
2097 Some(PathSource::Struct(Some(expr)))
2098 | Some(PathSource::Expr(Some(expr))) => Some(expr.clone()),
2099 _ => None,
2100 };
2101 }
2102 }
2103
2104 let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(res);
2105 if let Res::OpenMod(sym) = binding.res() {
2106 module = Some(ModuleOrUniformRoot::OpenModule(sym));
2107 record_segment_res(self.reborrow(), finalize, res, id);
2108 } else if let Some(def_id) = binding.res().module_like_def_id() {
2109 if self.mods_with_parse_errors.contains(&def_id) {
2110 module_had_parse_errors = true;
2111 }
2112 module = Some(ModuleOrUniformRoot::Module(self.expect_module(def_id)));
2113 record_segment_res(self.reborrow(), finalize, res, id);
2114 } else if res == Res::ToolMod && !is_last && opt_ns.is_some() {
2115 if binding.is_import() {
2116 self.dcx().emit_err(diagnostics::ToolModuleImported {
2117 span: ident.span,
2118 import: binding.span,
2119 });
2120 }
2121 let res = Res::NonMacroAttr(NonMacroAttrKind::Tool);
2122 return PathResult::NonModule(PartialRes::new(res));
2123 } else if res == Res::Err {
2124 return PathResult::NonModule(PartialRes::new(Res::Err));
2125 } else if opt_ns.is_some() && (is_last || maybe_assoc) {
2126 if let Some(finalize) = finalize {
2127 self.get_mut().lint_if_path_starts_with_module(
2128 finalize,
2129 path,
2130 second_binding,
2131 );
2132 }
2133 record_segment_res(self.reborrow(), finalize, res, id);
2134 return PathResult::NonModule(PartialRes::with_unresolved_segments(
2135 res,
2136 path.len() - segment_idx - 1,
2137 ));
2138 } else {
2139 return PathResult::failed(
2140 ident,
2141 is_last,
2142 finalize.is_some(),
2143 module_had_parse_errors,
2144 module,
2145 || {
2146 let import_inherent_item_error_flag =
2147 self.features.import_trait_associated_functions()
2148 && #[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union |
DefKind::ForeignTy, _) => true,
_ => false,
}matches!(
2149 res,
2150 Res::Def(
2151 DefKind::Struct
2152 | DefKind::Enum
2153 | DefKind::Union
2154 | DefKind::ForeignTy,
2155 _
2156 )
2157 );
2158 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!(
2160 "`{ident}` is {} {}, not a module{}",
2161 res.article(),
2162 res.descr(),
2163 if import_inherent_item_error_flag {
2164 " or a trait"
2165 } else {
2166 ""
2167 }
2168 );
2169 let scope = match &path[..segment_idx] {
2170 [.., prev] => {
2171 if prev.ident.name == kw::PathRoot {
2172 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("the crate root"))
})format!("the crate root")
2173 } else {
2174 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", prev.ident))
})format!("`{}`", prev.ident)
2175 }
2176 }
2177 _ => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("this scope"))
})format!("this scope"),
2178 };
2179 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}");
2182 let note = if import_inherent_item_error_flag {
2183 Some(
2184 "cannot import inherent associated items, only trait associated items".to_string(),
2185 )
2186 } else {
2187 None
2188 };
2189 (message, label, None, note, None)
2190 },
2191 );
2192 }
2193 }
2194 Err(Undetermined) if finalize.is_none() => return PathResult::Indeterminate,
2195 Err(Determined | Undetermined) => {
2196 if let Some(ModuleOrUniformRoot::Module(module)) = module
2197 && opt_ns.is_some()
2198 && !module.is_normal()
2199 {
2200 return PathResult::NonModule(PartialRes::with_unresolved_segments(
2201 module.res().unwrap(),
2202 path.len() - segment_idx,
2203 ));
2204 }
2205
2206 let mut this = self.reborrow();
2207 return PathResult::failed(
2208 ident,
2209 is_last,
2210 finalize.is_some(),
2211 module_had_parse_errors,
2212 module,
2213 || {
2214 let (message, label, suggestion, help) =
2215 this.get_mut().report_path_resolution_error(
2216 path,
2217 opt_ns,
2218 parent_scope,
2219 ribs,
2220 ignore_decl,
2221 ignore_import,
2222 module,
2223 segment_idx,
2224 ident,
2225 diag_metadata,
2226 );
2227 (message, label, suggestion, None, help)
2228 },
2229 );
2230 }
2231 }
2232 }
2233
2234 if let Some(finalize) = finalize {
2235 self.get_mut().lint_if_path_starts_with_module(finalize, path, second_binding);
2236 }
2237
2238 PathResult::Module(match module {
2239 Some(module) => module,
2240 None if path.is_empty() => ModuleOrUniformRoot::CurrentScope,
2241 _ => ::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),
2242 })
2243 }
2244}