1#![allow(internal_features)]
11#![feature(arbitrary_self_types)]
12#![feature(const_default)]
13#![feature(const_trait_impl)]
14#![feature(control_flow_into_value)]
15#![feature(default_field_values)]
16#![feature(deref_patterns)]
17#![feature(iter_intersperse)]
18#![feature(option_into_flat_iter)]
19#![feature(rustc_attrs)]
20#![feature(trim_prefix_suffix)]
21#![recursion_limit = "256"]
22use std::cell::RefMut;
25use std::collections::BTreeSet;
26use std::ops::ControlFlow;
27use std::sync::{Arc, OnceLock};
28use std::{fmt, mem};
29
30use diagnostics::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
31use effective_visibilities::EffectiveVisibilitiesVisitor;
32use hygiene::Macros20NormalizedSyntaxContext;
33use imports::{Import, ImportData, ImportKind, NameResolution, PendingDecl};
34use late::{
35 ConstantRequiresType, ForwardGenericParamBanReason, HasGenericParams, PathSource,
36 PatternSource, UnnecessaryQualification,
37};
38pub use macros::registered_lint_tools_ast;
39use macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef};
40use rustc_arena::{DroplessArena, TypedArena};
41use rustc_ast::node_id::NodeMap;
42use rustc_ast::{
43 self as ast, AngleBracketedArg, CRATE_NODE_ID, Crate, DUMMY_NODE_ID, Expr, ExprKind,
44 GenericArg, GenericArgs, Generics, NodeId, Path, attr,
45};
46use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, default};
47use rustc_data_structures::intern::Interned;
48use rustc_data_structures::steal::Steal;
49use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard, WorkerLocal};
50use rustc_data_structures::unord::{UnordItems, UnordMap, UnordSet};
51use rustc_errors::{Applicability, Diag, ErrCode, ErrorGuaranteed, LintBuffer};
52use rustc_expand::base::{DeriveResolution, SyntaxExtension, SyntaxExtensionKind};
53use rustc_feature::{BUILTIN_ATTRIBUTES, Features};
54use rustc_hir::attrs::StrippedCfgItem;
55use rustc_hir::def::Namespace::{self, *};
56use rustc_hir::def::{self, CtorOf, DefKind, MacroKinds, NonMacroAttrKind, PerNS};
57use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
58use rustc_hir::definitions::{PerParentDisambiguatorState, PerParentDisambiguatorsMap};
59use rustc_hir::{PrimTy, TraitCandidate, find_attr};
60use rustc_index::bit_set::DenseBitSet;
61use rustc_lint_defs::builtin::PRIVATE_MACRO_USE;
62use rustc_metadata::creader::CStore;
63use rustc_middle::middle::privacy::EffectiveVisibilities;
64use rustc_middle::middle::resolve::{
65 AmbigModChild, DelegationInfo, DocLinkResMap, MainDefinition, ModChild, PartialRes,
66 PerOwnerResolverData, Reexport, ResolverAstLowering, ResolverGlobalCtxt,
67};
68use rustc_middle::query::Providers;
69use rustc_middle::ty::{self, RegisteredTools, TyCtxt, TyCtxtFeed, Visibility};
70use rustc_middle::{bug, span_bug};
71use rustc_span::def_id::{LocalModId, ModId};
72use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
73use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
74use rustc_structures::CrateType;
75use smallvec::{SmallVec, smallvec};
76use tracing::{debug, instrument};
77
78use crate::diagnostics::impls::{
79 ImportSuggestion, LabelSuggestion, OnUnknownData, StructCtor, Suggestion,
80};
81use crate::imports::{ImportResolution, NameResolutionRef};
82use crate::ref_mut::speculative::SpeculativeFlag;
83use crate::ref_mut::{CmCell, CmRef, CmRefCell};
84
85mod build_reduced_graph;
86mod check_unused;
87mod def_collector;
88mod diagnostics;
89mod effective_visibilities;
90mod ident;
91mod imports;
92mod late;
93mod macros;
94pub mod rustdoc;
95
96type Res = def::Res<NodeId>;
97
98#[derive(#[automatically_derived]
impl ::core::marker::Copy for Determinacy { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Determinacy { }
#[automatically_derived]
impl ::core::clone::Clone for Determinacy {
#[inline]
fn clone(&self) -> Determinacy { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Determinacy { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Determinacy {
#[inline]
fn eq(&self, other: &Determinacy) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for Determinacy {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Determinacy::Determined => "Determined",
Determinacy::Undetermined => "Undetermined",
})
}
}Debug)]
99enum Determinacy {
100 Determined,
101 Undetermined,
102}
103
104impl Determinacy {
105 fn determined(determined: bool) -> Determinacy {
106 if determined { Determinacy::Determined } else { Determinacy::Undetermined }
107 }
108}
109
110#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for Scope<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for Scope<'ra> {
#[inline]
fn clone(&self) -> Scope<'ra> {
let _: ::core::clone::AssertParamIsClone<LocalExpnId>;
let _: ::core::clone::AssertParamIsClone<MacroRulesScopeRef<'ra>>;
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<Option<NodeId>>;
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<Option<NodeId>>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::Copy for Scope<'ra> { }Copy, #[automatically_derived]
impl<'ra> ::core::fmt::Debug for Scope<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Scope::DeriveHelpers(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"DeriveHelpers", &__self_0),
Scope::DeriveHelpersCompat =>
::core::fmt::Formatter::write_str(f, "DeriveHelpersCompat"),
Scope::MacroRules(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MacroRules", &__self_0),
Scope::ModuleNonGlobs(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"ModuleNonGlobs", __self_0, &__self_1),
Scope::ModuleGlobs(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"ModuleGlobs", __self_0, &__self_1),
Scope::MacroUsePrelude =>
::core::fmt::Formatter::write_str(f, "MacroUsePrelude"),
Scope::BuiltinAttrs =>
::core::fmt::Formatter::write_str(f, "BuiltinAttrs"),
Scope::ExternPreludeItems =>
::core::fmt::Formatter::write_str(f, "ExternPreludeItems"),
Scope::ExternPreludeFlags =>
::core::fmt::Formatter::write_str(f, "ExternPreludeFlags"),
Scope::ToolAttributePrelude =>
::core::fmt::Formatter::write_str(f, "ToolAttributePrelude"),
Scope::StdLibPrelude =>
::core::fmt::Formatter::write_str(f, "StdLibPrelude"),
Scope::BuiltinTypes =>
::core::fmt::Formatter::write_str(f, "BuiltinTypes"),
}
}
}Debug)]
112enum Scope<'ra> {
113 DeriveHelpers(LocalExpnId),
115 DeriveHelpersCompat,
119 MacroRules(MacroRulesScopeRef<'ra>),
121 ModuleNonGlobs(Module<'ra>, Option<NodeId>),
125 ModuleGlobs(Module<'ra>, Option<NodeId>),
129 MacroUsePrelude,
131 BuiltinAttrs,
133 ExternPreludeItems,
135 ExternPreludeFlags,
137 ToolAttributePrelude,
139 StdLibPrelude,
141 BuiltinTypes,
143}
144
145#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for ScopeSet<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for ScopeSet<'ra> {
#[inline]
fn clone(&self) -> ScopeSet<'ra> {
let _: ::core::clone::AssertParamIsClone<Namespace>;
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<MacroKind>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::Copy for ScopeSet<'ra> { }Copy, #[automatically_derived]
impl<'ra> ::core::fmt::Debug for ScopeSet<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ScopeSet::All(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "All",
&__self_0),
ScopeSet::Module(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Module",
__self_0, &__self_1),
ScopeSet::ModuleAndExternPrelude(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"ModuleAndExternPrelude", __self_0, &__self_1),
ScopeSet::ExternPrelude =>
::core::fmt::Formatter::write_str(f, "ExternPrelude"),
ScopeSet::Macro(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Macro",
&__self_0),
}
}
}Debug)]
148enum ScopeSet<'ra> {
149 All(Namespace),
151 Module(Namespace, Module<'ra>),
153 ModuleAndExternPrelude(Namespace, Module<'ra>),
155 ExternPrelude,
157 Macro(MacroKind),
159}
160
161#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for ParentScope<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for ParentScope<'ra> {
#[inline]
fn clone(&self) -> ParentScope<'ra> {
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<LocalExpnId>;
let _: ::core::clone::AssertParamIsClone<MacroRulesScopeRef<'ra>>;
let _: ::core::clone::AssertParamIsClone<&'ra [ast::Path]>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::Copy for ParentScope<'ra> { }Copy, #[automatically_derived]
impl<'ra> ::core::fmt::Debug for ParentScope<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "ParentScope",
"module", &self.module, "expansion", &self.expansion,
"macro_rules", &self.macro_rules, "derives", &&self.derives)
}
}Debug)]
166struct ParentScope<'ra> {
167 module: Module<'ra>,
168 expansion: LocalExpnId,
169 macro_rules: MacroRulesScopeRef<'ra>,
170 derives: &'ra [ast::Path],
171}
172
173impl<'ra> ParentScope<'ra> {
174 fn module(module: LocalModule<'ra>, arenas: &'ra ResolverArenas<'ra>) -> ParentScope<'ra> {
177 ParentScope {
178 module: module.to_module(),
179 expansion: LocalExpnId::ROOT,
180 macro_rules: arenas.alloc_macro_rules_scope(MacroRulesScope::Empty),
181 derives: &[],
182 }
183 }
184}
185
186#[derive(#[automatically_derived]
impl ::core::marker::Copy for InvocationParent { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for InvocationParent {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"InvocationParent", "parent_def", &self.parent_def,
"impl_trait_context", &self.impl_trait_context, "in_attr",
&self.in_attr, "owner", &&self.owner)
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InvocationParent { }
#[automatically_derived]
impl ::core::clone::Clone for InvocationParent {
#[inline]
fn clone(&self) -> InvocationParent {
let _: ::core::clone::AssertParamIsClone<LocalDefId>;
let _: ::core::clone::AssertParamIsClone<ImplTraitContext>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<NodeId>;
*self
}
}Clone)]
187struct InvocationParent {
188 parent_def: LocalDefId,
189 impl_trait_context: ImplTraitContext,
190 in_attr: bool,
191 owner: NodeId,
192}
193
194impl InvocationParent {
195 const ROOT: Self = Self {
196 parent_def: CRATE_DEF_ID,
197 impl_trait_context: ImplTraitContext::Existential,
198 in_attr: false,
199 owner: CRATE_NODE_ID,
200 };
201}
202
203#[derive(#[automatically_derived]
impl ::core::marker::Copy for ImplTraitContext { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for ImplTraitContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ImplTraitContext::Existential => "Existential",
ImplTraitContext::Universal => "Universal",
ImplTraitContext::InBinding => "InBinding",
})
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ImplTraitContext { }
#[automatically_derived]
impl ::core::clone::Clone for ImplTraitContext {
#[inline]
fn clone(&self) -> ImplTraitContext { *self }
}Clone)]
204enum ImplTraitContext {
205 Existential,
206 Universal,
207 InBinding,
208}
209
210#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Used { }
#[automatically_derived]
impl ::core::clone::Clone for Used {
#[inline]
fn clone(&self) -> Used { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Used { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Used { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Used {
#[inline]
fn eq(&self, other: &Used) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Used {
#[inline]
fn partial_cmp(&self, other: &Used)
-> ::core::option::Option<::core::cmp::Ordering> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
}
}PartialOrd, #[automatically_derived]
impl ::core::fmt::Debug for Used {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self { Used::Scope => "Scope", Used::Other => "Other", })
}
}Debug)]
225enum Used {
226 Scope,
227 Other,
228}
229
230#[derive(#[automatically_derived]
impl ::core::fmt::Debug for BindingError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "BindingError",
"name", &self.name, "origin", &self.origin, "target",
&self.target, "could_be_path", &&self.could_be_path)
}
}Debug)]
231struct BindingError {
232 name: Ident,
233 origin: Vec<(Span, ast::Pat)>,
234 target: Vec<ast::Pat>,
235 could_be_path: bool,
236}
237
238#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for ResolutionError<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ResolutionError::GenericParamsFromOuterItem {
outer_res: __self_0,
has_generic_params: __self_1,
def_kind: __self_2,
inner_item: __self_3,
current_self_ty: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"GenericParamsFromOuterItem", "outer_res", __self_0,
"has_generic_params", __self_1, "def_kind", __self_2,
"inner_item", __self_3, "current_self_ty", &__self_4),
ResolutionError::NameAlreadyUsedInParameterList(__self_0,
__self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"NameAlreadyUsedInParameterList", __self_0, &__self_1),
ResolutionError::MethodNotMemberOfTrait(__self_0, __self_1,
__self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"MethodNotMemberOfTrait", __self_0, __self_1, &__self_2),
ResolutionError::TypeNotMemberOfTrait(__self_0, __self_1,
__self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"TypeNotMemberOfTrait", __self_0, __self_1, &__self_2),
ResolutionError::ConstNotMemberOfTrait(__self_0, __self_1,
__self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"ConstNotMemberOfTrait", __self_0, __self_1, &__self_2),
ResolutionError::VariableNotBoundInPattern(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"VariableNotBoundInPattern", __self_0, &__self_1),
ResolutionError::VariableBoundWithDifferentMode(__self_0,
__self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"VariableBoundWithDifferentMode", __self_0, &__self_1),
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(__self_0)
=>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"IdentifierBoundMoreThanOnceInParameterList", &__self_0),
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(__self_0)
=>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"IdentifierBoundMoreThanOnceInSamePattern", &__self_0),
ResolutionError::UndeclaredLabel {
name: __self_0, suggestion: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"UndeclaredLabel", "name", __self_0, "suggestion",
&__self_1),
ResolutionError::FailedToResolve {
segment: __self_0,
label: __self_1,
suggestion: __self_2,
help: __self_3,
module: __self_4,
message: __self_5 } => {
let names: &'static _ =
&["segment", "label", "suggestion", "help", "module",
"message"];
let values: &[&dyn ::core::fmt::Debug] =
&[__self_0, __self_1, __self_2, __self_3, __self_4,
&__self_5];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"FailedToResolve", names, values)
}
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem =>
::core::fmt::Formatter::write_str(f,
"CannotCaptureDynamicEnvironmentInFnItem"),
ResolutionError::AttemptToUseNonConstantValueInConstant {
ident: __self_0,
suggestion: __self_1,
current: __self_2,
type_span: __self_3,
requires_type: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"AttemptToUseNonConstantValueInConstant", "ident", __self_0,
"suggestion", __self_1, "current", __self_2, "type_span",
__self_3, "requires_type", &__self_4),
ResolutionError::BindingShadowsSomethingUnacceptable {
shadowing_binding: __self_0,
name: __self_1,
participle: __self_2,
article: __self_3,
shadowed_binding: __self_4,
shadowed_binding_span: __self_5 } => {
let names: &'static _ =
&["shadowing_binding", "name", "participle", "article",
"shadowed_binding", "shadowed_binding_span"];
let values: &[&dyn ::core::fmt::Debug] =
&[__self_0, __self_1, __self_2, __self_3, __self_4,
&__self_5];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"BindingShadowsSomethingUnacceptable", names, values)
}
ResolutionError::ForwardDeclaredGenericParam(__self_0, __self_1)
=>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"ForwardDeclaredGenericParam", __self_0, &__self_1),
ResolutionError::ParamInTyOfConstParam { name: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ParamInTyOfConstParam", "name", &__self_0),
ResolutionError::SelfInConstParam =>
::core::fmt::Formatter::write_str(f, "SelfInConstParam"),
ResolutionError::ParamInNonTrivialAnonConst {
is_gca: __self_0, name: __self_1, param_kind: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"ParamInNonTrivialAnonConst", "is_gca", __self_0, "name",
__self_1, "param_kind", &__self_2),
ResolutionError::ParamInEnumDiscriminant {
name: __self_0, param_kind: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ParamInEnumDiscriminant", "name", __self_0, "param_kind",
&__self_1),
ResolutionError::ForwardDeclaredSelf(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ForwardDeclaredSelf", &__self_0),
ResolutionError::UnreachableLabel {
name: __self_0,
definition_span: __self_1,
suggestion: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"UnreachableLabel", "name", __self_0, "definition_span",
__self_1, "suggestion", &__self_2),
ResolutionError::TraitImplMismatch {
name: __self_0,
kind: __self_1,
trait_path: __self_2,
trait_item_span: __self_3,
code: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"TraitImplMismatch", "name", __self_0, "kind", __self_1,
"trait_path", __self_2, "trait_item_span", __self_3, "code",
&__self_4),
ResolutionError::TraitImplDuplicate {
name: __self_0, trait_item_span: __self_1, old_span: __self_2
} =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"TraitImplDuplicate", "name", __self_0, "trait_item_span",
__self_1, "old_span", &__self_2),
ResolutionError::InvalidAsmSym =>
::core::fmt::Formatter::write_str(f, "InvalidAsmSym"),
ResolutionError::LowercaseSelf =>
::core::fmt::Formatter::write_str(f, "LowercaseSelf"),
ResolutionError::BindingInNeverPattern =>
::core::fmt::Formatter::write_str(f, "BindingInNeverPattern"),
}
}
}Debug)]
239enum ResolutionError<'ra> {
240 GenericParamsFromOuterItem {
242 outer_res: Res,
243 has_generic_params: HasGenericParams,
244 def_kind: DefKind,
245 inner_item: Option<(Span, Span, ast::ItemKind)>,
247 current_self_ty: Option<String>,
248 },
249 NameAlreadyUsedInParameterList(Ident, Span),
252 MethodNotMemberOfTrait(Ident, String, Option<Symbol>),
254 TypeNotMemberOfTrait(Ident, String, Option<Symbol>),
256 ConstNotMemberOfTrait(Ident, String, Option<Symbol>),
258 VariableNotBoundInPattern(BindingError, ParentScope<'ra>),
260 VariableBoundWithDifferentMode(Ident, Span),
262 IdentifierBoundMoreThanOnceInParameterList(Ident),
264 IdentifierBoundMoreThanOnceInSamePattern(Ident),
266 UndeclaredLabel { name: Symbol, suggestion: Option<LabelSuggestion> },
268 FailedToResolve {
270 segment: Symbol,
271 label: String,
272 suggestion: Option<Suggestion>,
273 help: Option<String>,
274 module: Option<ModuleOrUniformRoot<'ra>>,
275 message: String,
276 },
277 CannotCaptureDynamicEnvironmentInFnItem,
279 AttemptToUseNonConstantValueInConstant {
281 ident: Ident,
282 suggestion: &'static str,
283 current: &'static str,
284 type_span: Option<Span>,
285 requires_type: ConstantRequiresType,
286 },
287 BindingShadowsSomethingUnacceptable {
289 shadowing_binding: PatternSource,
290 name: Symbol,
291 participle: &'static str,
292 article: &'static str,
293 shadowed_binding: Res,
294 shadowed_binding_span: Span,
295 },
296 ForwardDeclaredGenericParam(Symbol, ForwardGenericParamBanReason),
298 ParamInTyOfConstParam { name: Symbol },
302 SelfInConstParam,
304 ParamInNonTrivialAnonConst {
308 is_gca: bool,
309 name: Symbol,
310 param_kind: ParamKindInNonTrivialAnonConst,
311 },
312 ParamInEnumDiscriminant { name: Symbol, param_kind: ParamKindInEnumDiscriminant },
316 ForwardDeclaredSelf(ForwardGenericParamBanReason),
318 UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
320 TraitImplMismatch {
322 name: Ident,
323 kind: &'static str,
324 trait_path: String,
325 trait_item_span: Span,
326 code: ErrCode,
327 },
328 TraitImplDuplicate { name: Ident, trait_item_span: Span, old_span: Span },
330 InvalidAsmSym,
332 LowercaseSelf,
334 BindingInNeverPattern,
336}
337
338#[derive(#[automatically_derived]
impl ::core::fmt::Debug for VisResolutionError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
VisResolutionError::Relative2018(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"Relative2018", __self_0, &__self_1),
VisResolutionError::AncestorOnly(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AncestorOnly", &__self_0),
VisResolutionError::FailedToResolve {
span: __self_0,
segment: __self_1,
label: __self_2,
suggestion: __self_3,
help: __self_4,
message: __self_5 } => {
let names: &'static _ =
&["span", "segment", "label", "suggestion", "help",
"message"];
let values: &[&dyn ::core::fmt::Debug] =
&[__self_0, __self_1, __self_2, __self_3, __self_4,
&__self_5];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"FailedToResolve", names, values)
}
VisResolutionError::ExpectedFound(__self_0, __self_1, __self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"ExpectedFound", __self_0, __self_1, &__self_2),
VisResolutionError::Indeterminate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Indeterminate", &__self_0),
VisResolutionError::ModuleOnly(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ModuleOnly", &__self_0),
}
}
}Debug)]
339enum VisResolutionError {
340 Relative2018(Span, ast::Path),
341 AncestorOnly(Span),
342 FailedToResolve {
343 span: Span,
344 segment: Symbol,
345 label: String,
346 suggestion: Option<Suggestion>,
347 help: Option<String>,
348 message: String,
349 },
350 ExpectedFound(Span, String, Res),
351 Indeterminate(Span),
352 ModuleOnly(Span),
353}
354
355#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Segment { }
#[automatically_derived]
impl ::core::clone::Clone for Segment {
#[inline]
fn clone(&self) -> Segment {
let _: ::core::clone::AssertParamIsClone<Ident>;
let _: ::core::clone::AssertParamIsClone<Option<NodeId>>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Segment { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Segment {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f, "Segment",
"ident", &self.ident, "id", &self.id, "has_generic_args",
&self.has_generic_args, "has_lifetime_args",
&self.has_lifetime_args, "args_span", &&self.args_span)
}
}Debug)]
358struct Segment {
359 ident: Ident,
360 id: Option<NodeId>,
361 has_generic_args: bool,
363 has_lifetime_args: bool,
365 args_span: Span,
366}
367
368impl Segment {
369 fn from_path(path: &Path) -> Vec<Segment> {
370 path.segments.iter().map(|s| s.into()).collect()
371 }
372
373 fn from_ident(ident: Ident) -> Segment {
374 Segment {
375 ident,
376 id: None,
377 has_generic_args: false,
378 has_lifetime_args: false,
379 args_span: DUMMY_SP,
380 }
381 }
382
383 fn names_to_string(segments: &[Segment]) -> String {
384 names_to_string(segments.iter().map(|seg| seg.ident.name))
385 }
386}
387
388impl<'a> From<&'a ast::PathSegment> for Segment {
389 fn from(seg: &'a ast::PathSegment) -> Segment {
390 let has_generic_args = seg.args.is_some();
391 let (args_span, has_lifetime_args) = if let Some(args) = seg.args.as_deref() {
392 match args {
393 GenericArgs::AngleBracketed(args) => {
394 let found_lifetimes = args
395 .args
396 .iter()
397 .any(|arg| #[allow(non_exhaustive_omitted_patterns)] match arg {
AngleBracketedArg::Arg(GenericArg::Lifetime(_)) => true,
_ => false,
}matches!(arg, AngleBracketedArg::Arg(GenericArg::Lifetime(_))));
398 (args.span, found_lifetimes)
399 }
400 GenericArgs::Parenthesized(args) => (args.span, true),
401 GenericArgs::ParenthesizedElided(span) => (*span, true),
402 }
403 } else {
404 (DUMMY_SP, false)
405 };
406 Segment {
407 ident: seg.ident,
408 id: Some(seg.id),
409 has_generic_args,
410 has_lifetime_args,
411 args_span,
412 }
413 }
414}
415
416#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for LateDecl<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
LateDecl::Decl(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Decl",
&__self_0),
LateDecl::RibDef(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "RibDef",
&__self_0),
}
}
}Debug, #[automatically_derived]
impl<'ra> ::core::marker::Copy for LateDecl<'ra> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for LateDecl<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for LateDecl<'ra> {
#[inline]
fn clone(&self) -> LateDecl<'ra> {
let _: ::core::clone::AssertParamIsClone<Decl<'ra>>;
let _: ::core::clone::AssertParamIsClone<Res>;
*self
}
}Clone)]
418enum LateDecl<'ra> {
419 Decl(Decl<'ra>),
421 RibDef(Res),
424}
425
426impl<'ra> LateDecl<'ra> {
427 fn res(self) -> Res {
428 match self {
429 LateDecl::Decl(binding) => binding.res(),
430 LateDecl::RibDef(res) => res,
431 }
432 }
433}
434
435#[derive(#[automatically_derived]
impl<'ra> ::core::marker::Copy for ModuleOrUniformRoot<'ra> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for ModuleOrUniformRoot<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for ModuleOrUniformRoot<'ra> {
#[inline]
fn clone(&self) -> ModuleOrUniformRoot<'ra> {
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<Module<'ra>>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::StructuralPartialEq for ModuleOrUniformRoot<'ra> { }
#[automatically_derived]
impl<'ra> ::core::cmp::PartialEq for ModuleOrUniformRoot<'ra> {
#[inline]
fn eq(&self, other: &ModuleOrUniformRoot<'ra>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ModuleOrUniformRoot::Module(__self_0),
ModuleOrUniformRoot::Module(__arg1_0)) =>
__self_0 == __arg1_0,
(ModuleOrUniformRoot::ModuleAndExternPrelude(__self_0),
ModuleOrUniformRoot::ModuleAndExternPrelude(__arg1_0)) =>
__self_0 == __arg1_0,
(ModuleOrUniformRoot::OpenModule(__self_0),
ModuleOrUniformRoot::OpenModule(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'ra> ::core::fmt::Debug for ModuleOrUniformRoot<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ModuleOrUniformRoot::Module(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Module",
&__self_0),
ModuleOrUniformRoot::ModuleAndExternPrelude(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ModuleAndExternPrelude", &__self_0),
ModuleOrUniformRoot::ExternPrelude =>
::core::fmt::Formatter::write_str(f, "ExternPrelude"),
ModuleOrUniformRoot::CurrentScope =>
::core::fmt::Formatter::write_str(f, "CurrentScope"),
ModuleOrUniformRoot::OpenModule(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"OpenModule", &__self_0),
}
}
}Debug)]
436enum ModuleOrUniformRoot<'ra> {
437 Module(Module<'ra>),
439
440 ModuleAndExternPrelude(Module<'ra>),
444
445 ExternPrelude,
448
449 CurrentScope,
453
454 OpenModule(Symbol),
458}
459
460#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for PathResult<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
PathResult::Module(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Module",
&__self_0),
PathResult::NonModule(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"NonModule", &__self_0),
PathResult::Indeterminate =>
::core::fmt::Formatter::write_str(f, "Indeterminate"),
PathResult::Failed {
span: __self_0,
label: __self_1,
suggestion: __self_2,
help: __self_3,
is_error_from_last_segment: __self_4,
module: __self_5,
segment: __self_6,
error_implied_by_parse_error: __self_7,
message: __self_8,
note: __self_9 } => {
let names: &'static _ =
&["span", "label", "suggestion", "help",
"is_error_from_last_segment", "module", "segment",
"error_implied_by_parse_error", "message", "note"];
let values: &[&dyn ::core::fmt::Debug] =
&[__self_0, __self_1, __self_2, __self_3, __self_4,
__self_5, __self_6, __self_7, __self_8, &__self_9];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"Failed", names, values)
}
}
}
}Debug)]
461enum PathResult<'ra> {
462 Module(ModuleOrUniformRoot<'ra>),
463 NonModule(PartialRes),
464 Indeterminate,
465 Failed {
466 span: Span,
467 label: String,
468 suggestion: Option<Suggestion>,
469 help: Option<String>,
470 is_error_from_last_segment: bool,
471 module: Option<ModuleOrUniformRoot<'ra>>,
485 segment: Ident,
487 error_implied_by_parse_error: bool,
488 message: String,
489 note: Option<String>,
490 },
491}
492
493impl<'ra> PathResult<'ra> {
494 fn failed(
495 ident: Ident,
496 is_error_from_last_segment: bool,
497 finalize: bool,
498 error_implied_by_parse_error: bool,
499 module: Option<ModuleOrUniformRoot<'ra>>,
500 label_and_suggestion_and_note: impl FnOnce() -> (
501 String,
502 String,
503 Option<Suggestion>,
504 Option<String>,
505 Option<String>,
506 ),
507 ) -> PathResult<'ra> {
508 let (message, label, suggestion, note, help) = if finalize {
509 label_and_suggestion_and_note()
510 } else {
511 (::alloc::__export::must_use({
::alloc::fmt::format(format_args!("cannot find `{0}` in this scope",
ident))
})format!("cannot find `{ident}` in this scope"), String::new(), None, None, None)
513 };
514 PathResult::Failed {
515 span: ident.span,
516 segment: ident,
517 label,
518 suggestion,
519 help,
520 is_error_from_last_segment,
521 module,
522 error_implied_by_parse_error,
523 message,
524 note,
525 }
526 }
527}
528
529#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ModuleKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ModuleKind::Block =>
::core::fmt::Formatter::write_str(f, "Block"),
ModuleKind::Def(__self_0, __self_1, __self_2, __self_3) =>
::core::fmt::Formatter::debug_tuple_field4_finish(f, "Def",
__self_0, __self_1, __self_2, &__self_3),
}
}
}Debug)]
530enum ModuleKind {
531 Block,
544 Def(DefKind, DefId, NodeId, Option<Symbol>),
554}
555
556impl ModuleKind {
557 fn opt_def_id(&self) -> Option<DefId> {
558 match self {
559 ModuleKind::Def(_, def_id, _, _) => Some(*def_id),
560 _ => None,
561 }
562 }
563
564 fn def_id(&self) -> DefId {
565 self.opt_def_id().expect("`Module::def_id` is called on a block module")
566 }
567
568 fn is_local(&self) -> bool {
569 match self {
570 ModuleKind::Def(_, def_id, ..) => def_id.is_local(),
571 ModuleKind::Block => true,
572 }
573 }
574}
575
576#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for IdentKey { }
#[automatically_derived]
impl ::core::clone::Clone for IdentKey {
#[inline]
fn clone(&self) -> IdentKey {
let _: ::core::clone::AssertParamIsClone<Symbol>;
let _:
::core::clone::AssertParamIsClone<Macros20NormalizedSyntaxContext>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IdentKey { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for IdentKey { }
#[automatically_derived]
impl ::core::cmp::PartialEq for IdentKey {
#[inline]
fn eq(&self, other: &IdentKey) -> bool {
self.name == other.name && self.ctxt == other.ctxt
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IdentKey {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
let _: ::core::cmp::AssertParamIsEq<Macros20NormalizedSyntaxContext>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for IdentKey {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.name, state);
::core::hash::Hash::hash(&self.ctxt, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for IdentKey {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "IdentKey",
"name", &self.name, "ctxt", &&self.ctxt)
}
}Debug)]
587struct IdentKey {
588 name: Symbol,
589 ctxt: Macros20NormalizedSyntaxContext,
590}
591
592impl IdentKey {
593 #[inline]
594 fn new(ident: Ident) -> IdentKey {
595 IdentKey { name: ident.name, ctxt: Macros20NormalizedSyntaxContext::new(ident.span.ctxt()) }
596 }
597
598 #[inline]
599 fn new_adjusted(ident: Ident, expn_id: ExpnId) -> (IdentKey, Option<ExpnId>) {
600 let (ctxt, def) = Macros20NormalizedSyntaxContext::new_adjusted(ident.span.ctxt(), expn_id);
601 (IdentKey { name: ident.name, ctxt }, def)
602 }
603
604 #[inline]
605 fn with_root_ctxt(name: Symbol) -> Self {
606 let ctxt = Macros20NormalizedSyntaxContext::new_unchecked(SyntaxContext::root());
607 IdentKey { name, ctxt }
608 }
609
610 #[inline]
611 fn orig(self, orig_ident_span: Span) -> Ident {
612 Ident::new(self.name, orig_ident_span)
613 }
614}
615
616#[derive(#[automatically_derived]
impl ::core::marker::Copy for BindingKey { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for BindingKey { }
#[automatically_derived]
impl ::core::clone::Clone for BindingKey {
#[inline]
fn clone(&self) -> BindingKey {
let _: ::core::clone::AssertParamIsClone<IdentKey>;
let _: ::core::clone::AssertParamIsClone<Namespace>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for BindingKey { }
#[automatically_derived]
impl ::core::cmp::PartialEq for BindingKey {
#[inline]
fn eq(&self, other: &BindingKey) -> bool {
self.disambiguator == other.disambiguator && self.ident == other.ident
&& self.ns == other.ns
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for BindingKey {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<IdentKey>;
let _: ::core::cmp::AssertParamIsEq<Namespace>;
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for BindingKey {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.ident, state);
::core::hash::Hash::hash(&self.ns, state);
::core::hash::Hash::hash(&self.disambiguator, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for BindingKey {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "BindingKey",
"ident", &self.ident, "ns", &self.ns, "disambiguator",
&&self.disambiguator)
}
}Debug)]
621struct BindingKey {
622 ident: IdentKey,
625 ns: Namespace,
626 disambiguator: u32,
632}
633
634impl BindingKey {
635 fn new(ident: IdentKey, ns: Namespace) -> Self {
636 BindingKey { ident, ns, disambiguator: 0 }
637 }
638
639 fn new_disambiguated(
640 ident: IdentKey,
641 ns: Namespace,
642 disambiguator: impl FnOnce() -> u32,
643 ) -> BindingKey {
644 let disambiguator = if ident.name == kw::Underscore { disambiguator() } else { 0 };
645 BindingKey { ident, ns, disambiguator }
646 }
647}
648
649type ResolutionTable<'ra> = FxIndexMap<BindingKey, NameResolutionRef<'ra>>;
650
651enum Resolutions<'ra> {
652 Local(CmRefCell<ResolutionTable<'ra>>),
653 Extern(OnceLock<ResolutionTable<'ra>>),
654}
655
656impl<'ra> Resolutions<'ra> {
657 fn new(local: bool) -> Self {
658 if local {
659 Resolutions::Local(Default::default())
660 } else {
661 Resolutions::Extern(Default::default())
662 }
663 }
664}
665
666struct ModuleData<'ra> {
678 parent: Option<Module<'ra>>,
680 kind: ModuleKind,
682
683 lazy_resolutions: Resolutions<'ra>,
686 underscore_disambiguator: CmCell<u32>,
688
689 unexpanded_invocations: CmRefCell<FxHashSet<LocalExpnId>>,
691
692 no_implicit_prelude: bool,
694
695 glob_importers: CmRefCell<Vec<Import<'ra>>>,
696 globs: CmRefCell<Vec<Import<'ra>>>,
697
698 traits: CmRefCell<
700 Option<Box<[(Symbol, Decl<'ra>, Option<Module<'ra>>, bool )]>>,
701 >,
702
703 span: Span,
705
706 expansion: ExpnId,
707
708 self_decl: Option<Decl<'ra>>,
711}
712
713#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for Module<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for Module<'ra> {
#[inline]
fn clone(&self) -> Module<'ra> {
let _:
::core::clone::AssertParamIsClone<Interned<'ra,
ModuleData<'ra>>>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::Copy for Module<'ra> { }Copy, #[automatically_derived]
impl<'ra> ::core::marker::StructuralPartialEq for Module<'ra> { }
#[automatically_derived]
impl<'ra> ::core::cmp::PartialEq for Module<'ra> {
#[inline]
fn eq(&self, other: &Module<'ra>) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<'ra> ::core::cmp::Eq for Module<'ra> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Interned<'ra, ModuleData<'ra>>>;
}
}Eq, #[automatically_derived]
impl<'ra> ::core::hash::Hash for Module<'ra> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
716#[rustc_pass_by_value]
717struct Module<'ra>(Interned<'ra, ModuleData<'ra>>);
718
719#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for LocalModule<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for LocalModule<'ra> {
#[inline]
fn clone(&self) -> LocalModule<'ra> {
let _:
::core::clone::AssertParamIsClone<Interned<'ra,
ModuleData<'ra>>>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::Copy for LocalModule<'ra> { }Copy, #[automatically_derived]
impl<'ra> ::core::marker::StructuralPartialEq for LocalModule<'ra> { }
#[automatically_derived]
impl<'ra> ::core::cmp::PartialEq for LocalModule<'ra> {
#[inline]
fn eq(&self, other: &LocalModule<'ra>) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<'ra> ::core::cmp::Eq for LocalModule<'ra> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Interned<'ra, ModuleData<'ra>>>;
}
}Eq, #[automatically_derived]
impl<'ra> ::core::hash::Hash for LocalModule<'ra> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
721#[rustc_pass_by_value]
722struct LocalModule<'ra>(Interned<'ra, ModuleData<'ra>>);
723
724#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'ra> ::core::clone::TrivialClone for ExternModule<'ra> { }
#[automatically_derived]
impl<'ra> ::core::clone::Clone for ExternModule<'ra> {
#[inline]
fn clone(&self) -> ExternModule<'ra> {
let _:
::core::clone::AssertParamIsClone<Interned<'ra,
ModuleData<'ra>>>;
*self
}
}Clone, #[automatically_derived]
impl<'ra> ::core::marker::Copy for ExternModule<'ra> { }Copy, #[automatically_derived]
impl<'ra> ::core::marker::StructuralPartialEq for ExternModule<'ra> { }
#[automatically_derived]
impl<'ra> ::core::cmp::PartialEq for ExternModule<'ra> {
#[inline]
fn eq(&self, other: &ExternModule<'ra>) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<'ra> ::core::cmp::Eq for ExternModule<'ra> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Interned<'ra, ModuleData<'ra>>>;
}
}Eq, #[automatically_derived]
impl<'ra> ::core::hash::Hash for ExternModule<'ra> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
726#[rustc_pass_by_value]
727struct ExternModule<'ra>(Interned<'ra, ModuleData<'ra>>);
728
729impl<'ra> ModuleData<'ra> {
730 fn new(
731 parent: Option<Module<'ra>>,
732 kind: ModuleKind,
733 expansion: ExpnId,
734 span: Span,
735 no_implicit_prelude: bool,
736 vis: Visibility<ModId>,
737 arenas: &'ra ResolverArenas<'ra>,
738 ) -> Self {
739 let lazy_resolutions = Resolutions::new(kind.is_local());
740 let self_decl = match kind {
741 ModuleKind::Def(def_kind, def_id, ..) => {
742 let expn_id = expansion.as_local().unwrap_or(LocalExpnId::ROOT);
743 Some(arenas.new_def_decl(Res::Def(def_kind, def_id), vis, span, expn_id, parent))
744 }
745 ModuleKind::Block => None,
746 };
747 ModuleData {
748 parent,
749 kind,
750 lazy_resolutions,
751 underscore_disambiguator: CmCell::new(0),
752 unexpanded_invocations: Default::default(),
753 no_implicit_prelude,
754 glob_importers: CmRefCell::new(Vec::new()),
755 globs: CmRefCell::new(Vec::new()),
756 traits: CmRefCell::new(None),
757 span,
758 expansion,
759 self_decl,
760 }
761 }
762
763 fn name(&self) -> Option<Symbol> {
765 match self.kind {
766 ModuleKind::Block => None,
767 ModuleKind::Def(.., name) => name,
768 }
769 }
770
771 fn opt_def_id(&self) -> Option<DefId> {
772 self.kind.opt_def_id()
773 }
774
775 fn def_id(&self) -> DefId {
776 self.kind.def_id()
777 }
778
779 fn is_local(&self) -> bool {
780 self.kind.is_local()
781 }
782
783 fn has_unexpanded_invocations<'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> bool {
784 !self.unexpanded_invocations.borrow_checked(r).is_empty()
785 }
786
787 fn res(&self) -> Option<Res> {
788 match self.kind {
789 ModuleKind::Def(kind, def_id, _, _) => Some(Res::Def(kind, def_id)),
790 _ => None,
791 }
792 }
793
794 fn def_kind(&self) -> Option<DefKind> {
795 match self.kind {
796 ModuleKind::Def(def_kind, ..) => Some(def_kind),
797 ModuleKind::Block => None,
798 }
799 }
800}
801
802impl<'ra> Module<'ra> {
803 fn for_each_child<'tcx, R: AsRef<Resolver<'ra, 'tcx>>>(
804 self,
805 resolver: &R,
806 mut f: impl FnMut(&R, IdentKey, Span, Namespace, Decl<'ra>),
807 ) {
808 for (key, name_resolution) in resolver.as_ref().resolutions(self).iter() {
809 let name_resolution = name_resolution.borrow_checked(resolver.as_ref());
810 if let Some(decl) = name_resolution.best_decl() {
811 f(resolver, key.ident, name_resolution.orig_ident_span, key.ns, decl);
812 }
813 }
814 }
815
816 fn for_each_child_mut<'tcx, R: AsMut<Resolver<'ra, 'tcx>>>(
817 self,
818 resolver: &mut R,
819 mut f: impl FnMut(&mut R, IdentKey, Span, Namespace, Decl<'ra>),
820 ) {
821 for (key, name_resolution) in resolver.as_mut().resolutions(self).iter() {
822 let name_resolution = name_resolution.borrow(resolver.as_mut());
823 if let Some(decl) = name_resolution.best_decl() {
824 f(resolver, key.ident, name_resolution.orig_ident_span, key.ns, decl);
825 }
826 }
827 }
828
829 fn ensure_traits<'tcx>(self, resolver: &Resolver<'ra, 'tcx>) {
831 let mut traits = self.traits.borrow_mut_checked(resolver);
832 if traits.is_none() {
833 let mut collected_traits = Vec::new();
834 self.for_each_child(resolver, |r, ident, _, ns, mut decl| {
835 if ns != TypeNS {
836 return;
837 }
838
839 let ambiguous = decl.is_ambiguity_recursive();
840 let mut try_record_trait = |decl: Decl<'ra>| {
841 if let Res::Def(DefKind::Trait | DefKind::TraitAlias, def_id) = decl.res() {
842 collected_traits.push((
843 ident.name,
844 decl,
845 r.as_ref().get_module(def_id),
846 ambiguous,
847 ));
848 true
849 } else {
850 false
851 }
852 };
853 while !try_record_trait(decl)
857 && let Some((_, ambig_decl)) = decl.descent_to_ambiguity()
858 {
859 decl = ambig_decl;
860 }
861 });
862 *traits = Some(collected_traits.into_boxed_slice());
863 }
864 }
865
866 fn is_normal(self) -> bool {
868 self.def_kind() == Some(DefKind::Mod)
869 }
870
871 fn is_trait(self) -> bool {
872 #[allow(non_exhaustive_omitted_patterns)] match self.def_kind() {
Some(DefKind::Trait) => true,
_ => false,
}matches!(self.def_kind(), Some(DefKind::Trait))
873 }
874
875 fn nearest_item_scope(self) -> Module<'ra> {
876 match self.def_kind() {
877 Some(DefKind::Enum | DefKind::Trait) => {
878 self.parent.expect("enum or trait module without a parent")
879 }
880 _ => self,
881 }
882 }
883
884 fn nearest_parent_mod(self) -> ModId {
887 match self.kind {
888 ModuleKind::Def(DefKind::Mod, def_id, _, _) => ModId::new_unchecked(def_id),
889 _ => self.parent.expect("non-root module without parent").nearest_parent_mod(),
890 }
891 }
892
893 fn nearest_parent_mod_node_id(self) -> NodeId {
896 match self.kind {
897 ModuleKind::Def(DefKind::Mod, _, node_id, _) => node_id,
898 _ => self.parent.expect("non-root module without parent").nearest_parent_mod_node_id(),
899 }
900 }
901
902 fn is_ancestor_of(self, mut other: Self) -> bool {
903 while self != other {
904 if let Some(parent) = other.parent {
905 other = parent;
906 } else {
907 return false;
908 }
909 }
910 true
911 }
912
913 #[track_caller]
914 fn expect_local(self) -> LocalModule<'ra> {
915 match self.kind {
916 ModuleKind::Def(_, def_id, _, _) if !def_id.is_local() => {
917 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("unexpected extern module: {0:?}", self))span_bug!(self.span, "unexpected extern module: {self:?}")
918 }
919 ModuleKind::Def(..) | ModuleKind::Block => LocalModule(self.0),
920 }
921 }
922
923 #[track_caller]
924 fn expect_extern(self) -> ExternModule<'ra> {
925 match self.kind {
926 ModuleKind::Def(_, def_id, _, _) if !def_id.is_local() => ExternModule(self.0),
927 ModuleKind::Def(..) | ModuleKind::Block => {
928 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("unexpected local module: {0:?}", self))span_bug!(self.span, "unexpected local module: {self:?}")
929 }
930 }
931 }
932}
933
934impl<'ra> LocalModule<'ra> {
935 fn new(
936 parent: Option<LocalModule<'ra>>,
937 kind: ModuleKind,
938 vis: Visibility<ModId>,
939 expn_id: ExpnId,
940 span: Span,
941 no_implicit_prelude: bool,
942 arenas: &'ra ResolverArenas<'ra>,
943 ) -> LocalModule<'ra> {
944 if !kind.is_local() {
::core::panicking::panic("assertion failed: kind.is_local()")
};assert!(kind.is_local());
945 let parent = parent.map(|m| m.to_module());
946 let data = ModuleData::new(parent, kind, expn_id, span, no_implicit_prelude, vis, arenas);
947 LocalModule(Interned::new_unchecked(arenas.modules.alloc(data)))
949 }
950
951 fn to_module(self) -> Module<'ra> {
952 Module(self.0)
953 }
954}
955
956impl<'ra> ExternModule<'ra> {
957 fn new(
958 parent: Option<ExternModule<'ra>>,
959 kind: ModuleKind,
960 vis: Visibility<ModId>,
961 expn_id: ExpnId,
962 span: Span,
963 no_implicit_prelude: bool,
964 arenas: &'ra ResolverArenas<'ra>,
965 ) -> ExternModule<'ra> {
966 if !!kind.is_local() {
::core::panicking::panic("assertion failed: !kind.is_local()")
};assert!(!kind.is_local());
967 let parent = parent.map(|m| m.to_module());
968 let data = ModuleData::new(parent, kind, expn_id, span, no_implicit_prelude, vis, arenas);
969 ExternModule(Interned::new_unchecked(arenas.modules.alloc(data)))
971 }
972
973 fn to_module(self) -> Module<'ra> {
974 Module(self.0)
975 }
976}
977
978impl<'ra> std::ops::Deref for Module<'ra> {
979 type Target = ModuleData<'ra>;
980
981 fn deref(&self) -> &Self::Target {
982 &self.0
983 }
984}
985
986impl<'ra> std::ops::Deref for LocalModule<'ra> {
987 type Target = ModuleData<'ra>;
988
989 fn deref(&self) -> &Self::Target {
990 &self.0
991 }
992}
993
994impl<'ra> std::ops::Deref for ExternModule<'ra> {
995 type Target = ModuleData<'ra>;
996
997 fn deref(&self) -> &Self::Target {
998 &self.0
999 }
1000}
1001
1002impl<'ra> fmt::Debug for Module<'ra> {
1003 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1004 match self.res() {
1005 None => f.write_fmt(format_args!("block"))write!(f, "block"),
1006 Some(res) => f.write_fmt(format_args!("{0:?}", res))write!(f, "{:?}", res),
1007 }
1008 }
1009}
1010
1011impl<'ra> fmt::Debug for LocalModule<'ra> {
1012 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1013 self.to_module().fmt(f)
1014 }
1015}
1016
1017#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for DeclData<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["kind", "ambiguity", "expansion", "span", "initial_vis",
"ambiguity_vis_max", "ambiguity_vis_min", "parent_module"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.kind, &self.ambiguity, &self.expansion, &self.span,
&self.initial_vis, &self.ambiguity_vis_max,
&self.ambiguity_vis_min, &&self.parent_module];
::core::fmt::Formatter::debug_struct_fields_finish(f, "DeclData",
names, values)
}
}Debug)]
1019struct DeclData<'ra> {
1020 kind: DeclKind<'ra>,
1021 ambiguity: CmCell<Option<(Decl<'ra>, bool )>>,
1022 expansion: LocalExpnId,
1023 span: Span,
1024 initial_vis: Visibility<ModId>,
1025 ambiguity_vis_max: CmCell<Option<Decl<'ra>>>,
1028 ambiguity_vis_min: CmCell<Option<Decl<'ra>>>,
1031 parent_module: Option<Module<'ra>>,
1032}
1033
1034type Decl<'ra> = Interned<'ra, DeclData<'ra>>;
1037
1038#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for DeclKind<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
DeclKind::Def(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Def",
&__self_0),
DeclKind::Import { source_decl: __self_0, import: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Import", "source_decl", __self_0, "import", &__self_1),
}
}
}Debug)]
1040enum DeclKind<'ra> {
1041 Def(Res),
1044 Import { source_decl: Decl<'ra>, import: Import<'ra> },
1046}
1047
1048impl<'ra> DeclKind<'ra> {
1049 fn is_import(&self) -> bool {
1051 #[allow(non_exhaustive_omitted_patterns)] match *self {
DeclKind::Import { .. } => true,
_ => false,
}matches!(*self, DeclKind::Import { .. })
1052 }
1053}
1054
1055#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for PrivacyError<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["ident", "decl", "dedup_span", "outermost_res", "parent_scope",
"single_nested", "source"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.ident, &self.decl, &self.dedup_span, &self.outermost_res,
&self.parent_scope, &self.single_nested, &&self.source];
::core::fmt::Formatter::debug_struct_fields_finish(f, "PrivacyError",
names, values)
}
}Debug)]
1056struct PrivacyError<'ra> {
1057 ident: Ident,
1058 decl: Decl<'ra>,
1059 dedup_span: Span,
1060 outermost_res: Option<(Res, Ident)>,
1061 parent_scope: ParentScope<'ra>,
1062 single_nested: bool,
1064 source: Option<ast::Expr>,
1065}
1066
1067#[derive(#[automatically_derived]
impl<'a> ::core::fmt::Debug for UseError<'a> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["err", "candidates", "node_id", "instead", "suggestion", "path",
"is_call"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.err, &self.candidates, &self.node_id, &self.instead,
&self.suggestion, &self.path, &&self.is_call];
::core::fmt::Formatter::debug_struct_fields_finish(f, "UseError",
names, values)
}
}Debug)]
1068struct UseError<'a> {
1069 err: Diag<'a>,
1070 candidates: Vec<ImportSuggestion>,
1072 node_id: NodeId,
1074 instead: bool,
1076 suggestion: Option<(Span, &'static str, String, Applicability)>,
1078 path: Vec<Segment>,
1081 is_call: bool,
1083}
1084
1085#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for DelayedVisResolutionError<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"DelayedVisResolutionError", "vis", &self.vis, "parent_scope",
&self.parent_scope, "error", &&self.error)
}
}Debug)]
1086struct DelayedVisResolutionError<'ra> {
1087 vis: ast::Visibility,
1088 parent_scope: ParentScope<'ra>,
1089 error: VisResolutionError,
1090}
1091
1092#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AmbiguityKind { }
#[automatically_derived]
impl ::core::clone::Clone for AmbiguityKind {
#[inline]
fn clone(&self) -> AmbiguityKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for AmbiguityKind { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AmbiguityKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AmbiguityKind {
#[inline]
fn eq(&self, other: &AmbiguityKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for AmbiguityKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AmbiguityKind::BuiltinAttr => "BuiltinAttr",
AmbiguityKind::DeriveHelper => "DeriveHelper",
AmbiguityKind::MacroRulesVsModularized =>
"MacroRulesVsModularized",
AmbiguityKind::GlobVsOuter => "GlobVsOuter",
AmbiguityKind::GlobVsGlob => "GlobVsGlob",
AmbiguityKind::GlobVsExpanded => "GlobVsExpanded",
AmbiguityKind::MoreExpandedVsOuter => "MoreExpandedVsOuter",
})
}
}Debug)]
1093enum AmbiguityKind {
1094 BuiltinAttr,
1095 DeriveHelper,
1096 MacroRulesVsModularized,
1097 GlobVsOuter,
1098 GlobVsGlob,
1099 GlobVsExpanded,
1100 MoreExpandedVsOuter,
1101}
1102
1103impl AmbiguityKind {
1104 fn descr(self) -> &'static str {
1105 match self {
1106 AmbiguityKind::BuiltinAttr => "a name conflict with a builtin attribute",
1107 AmbiguityKind::DeriveHelper => "a name conflict with a derive helper attribute",
1108 AmbiguityKind::MacroRulesVsModularized => {
1109 "a conflict between a `macro_rules` name and a non-`macro_rules` name from another module"
1110 }
1111 AmbiguityKind::GlobVsOuter => {
1112 "a conflict between a name from a glob import and an outer scope during import or macro resolution"
1113 }
1114 AmbiguityKind::GlobVsGlob => "multiple glob imports of a name in the same module",
1115 AmbiguityKind::GlobVsExpanded => {
1116 "a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution"
1117 }
1118 AmbiguityKind::MoreExpandedVsOuter => {
1119 "a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution"
1120 }
1121 }
1122 }
1123}
1124
1125#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AmbiguityWarning { }
#[automatically_derived]
impl ::core::clone::Clone for AmbiguityWarning {
#[inline]
fn clone(&self) -> AmbiguityWarning { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for AmbiguityWarning { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AmbiguityWarning { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AmbiguityWarning {
#[inline]
fn eq(&self, other: &AmbiguityWarning) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
1126enum AmbiguityWarning {
1127 GlobImport,
1128 PanicImport,
1129}
1130
1131struct AmbiguityError<'ra> {
1132 kind: AmbiguityKind,
1133 ambig_vis: Option<(Visibility, Visibility)>,
1134 ident: Ident,
1135 b1: Decl<'ra>,
1136 b2: Decl<'ra>,
1137 scope1: Scope<'ra>,
1138 scope2: Scope<'ra>,
1139 warning: Option<AmbiguityWarning>,
1140}
1141
1142impl<'ra> DeclData<'ra> {
1143 fn vis(&self) -> Visibility<ModId> {
1144 self.ambiguity_vis_max.get().map(|d| d.vis()).unwrap_or_else(|| self.initial_vis)
1146 }
1147
1148 fn min_vis(&self) -> Visibility<ModId> {
1149 self.ambiguity_vis_min.get().map(|d| d.vis()).unwrap_or_else(|| self.initial_vis)
1151 }
1152
1153 fn res(&self) -> Res {
1154 match self.kind {
1155 DeclKind::Def(res) => res,
1156 DeclKind::Import { source_decl, .. } => source_decl.res(),
1157 }
1158 }
1159
1160 fn import_source(&self) -> Decl<'ra> {
1161 match self.kind {
1162 DeclKind::Import { source_decl, .. } => source_decl,
1163 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1164 }
1165 }
1166
1167 fn descent_to_ambiguity(self: Decl<'ra>) -> Option<(Decl<'ra>, Decl<'ra>)> {
1168 match self.ambiguity.get() {
1169 Some((ambig_binding, _)) => Some((self, ambig_binding)),
1170 None => match self.kind {
1171 DeclKind::Import { source_decl, .. } => source_decl.descent_to_ambiguity(),
1172 _ => None,
1173 },
1174 }
1175 }
1176
1177 fn is_ambiguity_recursive(&self) -> bool {
1178 self.ambiguity.get().is_some()
1179 || match self.kind {
1180 DeclKind::Import { source_decl, .. } => source_decl.is_ambiguity_recursive(),
1181 _ => false,
1182 }
1183 }
1184
1185 fn is_possibly_imported_variant(&self) -> bool {
1186 match self.kind {
1187 DeclKind::Import { source_decl, .. } => source_decl.is_possibly_imported_variant(),
1188 DeclKind::Def(Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), _)) => {
1189 true
1190 }
1191 DeclKind::Def(..) => false,
1192 }
1193 }
1194
1195 fn is_extern_crate(&self) -> bool {
1196 match self.kind {
1197 DeclKind::Import { import, .. } => {
1198 #[allow(non_exhaustive_omitted_patterns)] match import.kind {
ImportKind::ExternCrate { .. } => true,
_ => false,
}matches!(import.kind, ImportKind::ExternCrate { .. })
1199 }
1200 DeclKind::Def(Res::Def(_, def_id)) => def_id.is_crate_root(),
1201 _ => false,
1202 }
1203 }
1204
1205 fn is_import(&self) -> bool {
1206 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
DeclKind::Import { .. } => true,
_ => false,
}matches!(self.kind, DeclKind::Import { .. })
1207 }
1208
1209 fn is_import_user_facing(&self) -> bool {
1212 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
DeclKind::Import { import, .. } if
!#[allow(non_exhaustive_omitted_patterns)] match import.kind {
ImportKind::MacroExport => true,
_ => false,
} => true,
_ => false,
}matches!(self.kind, DeclKind::Import { import, .. }
1213 if !matches!(import.kind, ImportKind::MacroExport))
1214 }
1215
1216 fn is_glob_import(&self) -> bool {
1217 match self.kind {
1218 DeclKind::Import { import, .. } => import.is_glob(),
1219 _ => false,
1220 }
1221 }
1222
1223 fn is_assoc_item(&self) -> bool {
1224 #[allow(non_exhaustive_omitted_patterns)] match self.res() {
Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy,
_) => true,
_ => false,
}matches!(
1225 self.res(),
1226 Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, _)
1227 )
1228 }
1229
1230 fn macro_kinds(&self) -> Option<MacroKinds> {
1231 self.res().macro_kinds()
1232 }
1233
1234 fn reexport_chain(self: Decl<'ra>) -> SmallVec<[Reexport; 2]> {
1235 let mut reexport_chain = SmallVec::new();
1236 let mut next_binding = self;
1237 while let DeclKind::Import { source_decl, import, .. } = next_binding.kind {
1238 reexport_chain.push(import.simplify());
1239 next_binding = source_decl;
1240 }
1241 reexport_chain
1242 }
1243
1244 fn may_appear_after(&self, invoc_parent_expansion: LocalExpnId, decl: Decl<'_>) -> bool {
1251 let self_parent_expansion = self.expansion;
1255 let other_parent_expansion = decl.expansion;
1256 let certainly_before_other_or_simultaneously =
1257 other_parent_expansion.is_descendant_of(self_parent_expansion);
1258 let certainly_before_invoc_or_simultaneously =
1259 invoc_parent_expansion.is_descendant_of(self_parent_expansion);
1260 !(certainly_before_other_or_simultaneously || certainly_before_invoc_or_simultaneously)
1261 }
1262
1263 fn determined<'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> bool {
1269 match &self.kind {
1270 DeclKind::Import { source_decl, import, .. } if import.is_glob() => {
1271 !import.parent_scope.module.has_unexpanded_invocations(r)
1272 && source_decl.determined(r)
1273 }
1274 _ => true,
1275 }
1276 }
1277}
1278
1279#[derive(#[automatically_derived]
impl<'ra> ::core::fmt::Debug for ExternPreludeEntry<'ra> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ExternPreludeEntry", "item_decl", &self.item_decl, "flag_decl",
&&self.flag_decl)
}
}Debug)]
1280struct ExternPreludeEntry<'ra> {
1281 item_decl: Option<(Decl<'ra>, Span, bool)>,
1285 flag_decl: Option<
1287 CacheCell<(
1288 PendingDecl<'ra>,
1289 bool,
1290 bool,
1291 )>,
1292 >,
1293}
1294
1295impl ExternPreludeEntry<'_> {
1296 fn introduced_by_item(&self) -> bool {
1297 #[allow(non_exhaustive_omitted_patterns)] match self.item_decl {
Some((.., true)) => true,
_ => false,
}matches!(self.item_decl, Some((.., true)))
1298 }
1299
1300 fn flag() -> Self {
1301 ExternPreludeEntry {
1302 item_decl: None,
1303 flag_decl: Some(CacheCell::new((PendingDecl::Pending, false, false))),
1304 }
1305 }
1306
1307 fn open_flag() -> Self {
1308 ExternPreludeEntry {
1309 item_decl: None,
1310 flag_decl: Some(CacheCell::new((PendingDecl::Pending, false, true))),
1311 }
1312 }
1313
1314 fn span(&self) -> Span {
1315 match self.item_decl {
1316 Some((_, span, _)) => span,
1317 None => DUMMY_SP,
1318 }
1319 }
1320}
1321
1322struct DeriveData {
1323 resolutions: Vec<DeriveResolution>,
1324 helper_attrs: Vec<(usize, IdentKey, Span)>,
1325 has_derive_copy: bool,
1328 has_derive_ord: bool,
1329}
1330
1331pub struct ResolverOutputs<'tcx> {
1332 pub global_ctxt: ResolverGlobalCtxt,
1333 pub ast_lowering: ResolverAstLowering<'tcx>,
1334}
1335
1336#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DelegationFnSig {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DelegationFnSig", "has_self", &&self.has_self)
}
}Debug)]
1337struct DelegationFnSig {
1338 pub has_self: bool,
1339}
1340
1341pub struct Resolver<'ra, 'tcx> {
1345 tcx: TyCtxt<'tcx>,
1346
1347 expn_that_defined: UnordMap<LocalDefId, ExpnId> = Default::default(),
1349
1350 graph_root: LocalModule<'ra>,
1351
1352 speculative_flag: SpeculativeFlag,
1354
1355 prelude: Option<Module<'ra>> = None,
1356 extern_prelude: FxIndexMap<IdentKey, ExternPreludeEntry<'ra>>,
1357
1358 field_names: LocalDefIdMap<Vec<Ident>> = Default::default(),
1360 field_defaults: LocalDefIdMap<Vec<Symbol>> = Default::default(),
1361
1362 field_visibility_spans: FxHashMap<DefId, Vec<Span>> = default::fx_hash_map(),
1365
1366 determined_imports: Vec<Import<'ra>> = Vec::new(),
1368
1369 indeterminate_imports: Vec<(Import<'ra>, Option<ImportResolution<'ra>>, usize)> = Vec::new(),
1371
1372 pat_span_map: NodeMap<Span> = Default::default(),
1375
1376 partial_res_map: NodeMap<PartialRes> = Default::default(),
1378 import_use_map: FxHashMap<Import<'ra>, Used> = default::fx_hash_map(),
1380
1381 extern_crate_map: UnordMap<LocalDefId, CrateNum> = Default::default(),
1383 module_children: LocalDefIdMap<Vec<ModChild>> = Default::default(),
1384 ambig_module_children: LocalDefIdMap<Vec<AmbigModChild>> = Default::default(),
1385
1386 block_map: NodeMap<LocalModule<'ra>> = Default::default(),
1401 empty_module: LocalModule<'ra>,
1405 local_modules: Vec<LocalModule<'ra>>,
1407 local_module_map: FxIndexMap<LocalDefId, LocalModule<'ra>>,
1409 extern_module_map: CacheRefCell<FxIndexMap<DefId, ExternModule<'ra>>>,
1411
1412 glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
1414 glob_error: Option<ErrorGuaranteed> = None,
1415 visibilities_for_hashing: Vec<(LocalDefId, Visibility)> = Vec::new(),
1416 used_imports: FxHashSet<NodeId> = default::fx_hash_set(),
1417 maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
1418
1419 privacy_errors: Vec<PrivacyError<'ra>> = Vec::new(),
1421 ambiguity_errors: Vec<AmbiguityError<'ra>> = Vec::new(),
1423 issue_145575_hack_applied: bool = false,
1424 delayed_vis_resolution_errors: Vec<DelayedVisResolutionError<'ra>> = Vec::new(),
1426 macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),
1428
1429 arenas: &'ra WorkerLocal<ResolverArenas<'ra>>,
1430 dummy_decl: Decl<'ra>,
1431 builtin_type_decls: FxHashMap<Symbol, Decl<'ra>>,
1432 builtin_attr_decls: FxHashMap<Symbol, Decl<'ra>>,
1433 registered_attr_tool_decls: FxHashMap<IdentKey, Decl<'ra>>,
1434 macro_names: FxHashSet<IdentKey> = default::fx_hash_set(),
1435 builtin_macros: FxHashMap<Symbol, SyntaxExtensionKind> = default::fx_hash_map(),
1436 registered_attr_tools: &'tcx RegisteredTools,
1437 registered_lint_tools: &'tcx RegisteredTools,
1438 macro_use_prelude: FxIndexMap<Symbol, Decl<'ra>>,
1439 local_macro_map: FxHashMap<LocalDefId, &'ra Arc<SyntaxExtension>> = default::fx_hash_map(),
1441 extern_macro_map: CacheRefCell<FxHashMap<DefId, &'ra Arc<SyntaxExtension>>>,
1443 dummy_ext_bang: &'ra Arc<SyntaxExtension>,
1444 dummy_ext_derive: &'ra Arc<SyntaxExtension>,
1445 non_macro_attr: &'ra Arc<SyntaxExtension>,
1446 local_macro_def_scopes: FxHashMap<LocalDefId, LocalModule<'ra>> = default::fx_hash_map(),
1447 ast_transform_scopes: FxHashMap<LocalExpnId, LocalModule<'ra>> = default::fx_hash_map(),
1448 unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
1449 unused_macro_rules: FxIndexMap<NodeId, (LocalDefId, DenseBitSet<usize>)>,
1451 proc_macro_stubs: FxHashSet<LocalDefId> = default::fx_hash_set(),
1452 single_segment_macro_resolutions:
1454 CmRefCell<Vec<(Ident, MacroKind, ParentScope<'ra>, Option<Decl<'ra>>, Option<Span>)>>,
1455 multi_segment_macro_resolutions:
1456 CmRefCell<Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)>>,
1457 builtin_attrs: Vec<(Ident, ParentScope<'ra>)> = Vec::new(),
1458 containers_deriving_copy: FxHashSet<LocalExpnId> = default::fx_hash_set(),
1462 containers_deriving_ord: FxHashSet<LocalExpnId> = default::fx_hash_set(),
1463 invocation_parent_scopes: FxHashMap<LocalExpnId, ParentScope<'ra>> = default::fx_hash_map(),
1466 output_macro_rules_scopes: FxHashMap<LocalExpnId, MacroRulesScopeRef<'ra>> = default::fx_hash_map(),
1469 macro_rules_scopes: FxHashMap<LocalDefId, MacroRulesScopeRef<'ra>> = default::fx_hash_map(),
1471 helper_attrs: FxHashMap<LocalExpnId, Vec<(IdentKey, Span, Decl<'ra>)>> = default::fx_hash_map(),
1473 derive_data: FxHashMap<LocalExpnId, DeriveData> = default::fx_hash_map(),
1476
1477 name_already_seen: FxHashMap<Symbol, Span> = default::fx_hash_map(),
1479
1480 potentially_unused_imports: Vec<Import<'ra>> = Vec::new(),
1481
1482 potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>> = Vec::new(),
1483
1484 struct_ctors: LocalDefIdMap<StructCtor> = Default::default(),
1488
1489 struct_generics: LocalDefIdMap<Generics> = Default::default(),
1492
1493 lint_buffer: LintBuffer,
1494
1495 next_node_id: NodeId = CRATE_NODE_ID,
1496
1497 owners: NodeMap<PerOwnerResolverData<'tcx>>,
1499
1500 current_owner: PerOwnerResolverData<'tcx>,
1502
1503 disambiguators: LocalDefIdMap<PerParentDisambiguatorState>,
1504
1505 placeholder_field_indices: FxHashMap<NodeId, usize> = default::fx_hash_map(),
1507 invocation_parents: FxHashMap<LocalExpnId, InvocationParent>,
1511
1512 item_generics_num_lifetimes: FxHashMap<LocalDefId, usize> = default::fx_hash_map(),
1514 item_required_generic_args_suggestions: FxHashMap<LocalDefId, String> = default::fx_hash_map(),
1516 delegation_fn_sigs: LocalDefIdMap<DelegationFnSig> = Default::default(),
1517 delegation_infos: FxIndexMap<LocalDefId, DelegationInfo>,
1518
1519 main_def: Option<MainDefinition> = None,
1520 trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
1521 proc_macros: Vec<LocalDefId> = Vec::new(),
1524 confused_type_with_std_module: FxIndexMap<Span, Span>,
1525
1526 stripped_cfg_items: Vec<StrippedCfgItem<NodeId>> = Vec::new(),
1528
1529 effective_visibilities: EffectiveVisibilities,
1530 macro_reachable_adts: FxIndexMap<LocalDefId, FxIndexSet<LocalDefId>>,
1531
1532 doc_link_resolutions: FxIndexMap<LocalModId, DocLinkResMap>,
1533 doc_link_traits_in_scope: FxIndexMap<LocalModId, Vec<DefId>>,
1534 all_macro_rules: UnordSet<Symbol> = Default::default(),
1535
1536 glob_delegation_invoc_ids: FxHashSet<LocalExpnId> = default::fx_hash_set(),
1538 impl_unexpanded_invocations: FxHashMap<LocalDefId, FxHashSet<LocalExpnId>> = default::fx_hash_map(),
1541 impl_binding_keys: FxHashMap<LocalDefId, FxHashSet<BindingKey>> = default::fx_hash_map(),
1544
1545 current_crate_outer_attr_insert_span: Span,
1548
1549 mods_with_parse_errors: FxHashSet<DefId> = default::fx_hash_set(),
1550
1551 all_crate_macros_already_registered: bool = false,
1554
1555 impl_trait_names: FxHashMap<NodeId, Symbol> = default::fx_hash_map(),
1559
1560 on_unknown_data: FxHashMap<LocalDefId, OnUnknownData> = default::fx_hash_map(),
1562 features: &'tcx Features,
1563}
1564
1565#[derive(#[automatically_derived]
impl<'ra> ::core::default::Default for ResolverArenas<'ra> {
#[inline]
fn default() -> ResolverArenas<'ra> {
ResolverArenas {
modules: ::core::default::Default::default(),
imports: ::core::default::Default::default(),
name_resolutions: ::core::default::Default::default(),
ast_paths: ::core::default::Default::default(),
macros: ::core::default::Default::default(),
dropless: ::core::default::Default::default(),
}
}
}Default)]
1568pub struct ResolverArenas<'ra> {
1569 modules: TypedArena<ModuleData<'ra>>,
1570 imports: TypedArena<ImportData<'ra>>,
1571 name_resolutions: TypedArena<CmRefCell<NameResolution<'ra>>>,
1572 ast_paths: TypedArena<ast::Path>,
1573 macros: TypedArena<Arc<SyntaxExtension>>,
1574 dropless: DroplessArena,
1575}
1576
1577impl<'ra> ResolverArenas<'ra> {
1578 fn new_def_decl(
1579 &'ra self,
1580 res: Res,
1581 vis: Visibility<ModId>,
1582 span: Span,
1583 expansion: LocalExpnId,
1584 parent_module: Option<Module<'ra>>,
1585 ) -> Decl<'ra> {
1586 self.alloc_decl(DeclData {
1587 kind: DeclKind::Def(res),
1588 ambiguity: CmCell::new(None),
1589 initial_vis: vis,
1590 ambiguity_vis_max: CmCell::new(None),
1591 ambiguity_vis_min: CmCell::new(None),
1592 span,
1593 expansion,
1594 parent_module,
1595 })
1596 }
1597
1598 fn new_pub_def_decl(&'ra self, res: Res, span: Span, expn_id: LocalExpnId) -> Decl<'ra> {
1599 self.new_def_decl(res, Visibility::Public, span, expn_id, None)
1600 }
1601
1602 fn alloc_decl(&'ra self, data: DeclData<'ra>) -> Decl<'ra> {
1603 Interned::new_unchecked(self.dropless.alloc(data))
1605 }
1606 fn alloc_import(&'ra self, import: ImportData<'ra>) -> Import<'ra> {
1607 Interned::new_unchecked(self.imports.alloc(import))
1609 }
1610 fn alloc_name_resolution(&'ra self, resolution: NameResolution<'ra>) -> NameResolutionRef<'ra> {
1611 Interned::new_unchecked(self.name_resolutions.alloc(CmRefCell::new(resolution)))
1613 }
1614 fn alloc_macro_rules_scope(&'ra self, scope: MacroRulesScope<'ra>) -> MacroRulesScopeRef<'ra> {
1615 self.dropless.alloc(CacheCell::new(scope))
1616 }
1617 fn alloc_macro_rules_decl(&'ra self, decl: MacroRulesDecl<'ra>) -> &'ra MacroRulesDecl<'ra> {
1618 self.dropless.alloc(decl)
1619 }
1620 fn alloc_ast_paths(&'ra self, paths: &[ast::Path]) -> &'ra [ast::Path] {
1621 self.ast_paths.alloc_from_iter(paths.iter().cloned())
1622 }
1623 fn alloc_macro(&'ra self, ext: SyntaxExtension) -> &'ra Arc<SyntaxExtension> {
1624 self.macros.alloc(Arc::new(ext))
1625 }
1626 fn alloc_pattern_spans(&'ra self, spans: impl Iterator<Item = Span>) -> &'ra [Span] {
1627 self.dropless.alloc_from_iter(spans)
1628 }
1629}
1630
1631impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for Resolver<'ra, 'tcx> {
1632 fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> {
1633 self
1634 }
1635}
1636
1637impl<'ra, 'tcx> AsRef<Resolver<'ra, 'tcx>> for Resolver<'ra, 'tcx> {
1638 fn as_ref(&self) -> &Resolver<'ra, 'tcx> {
1639 self
1640 }
1641}
1642
1643impl<'tcx> Resolver<'_, 'tcx> {
1644 fn owner_def_id(&self, owner: NodeId) -> LocalDefId {
1648 self.owners[&owner].def_id
1649 }
1650
1651 fn child_def_id(&self, owner: NodeId, id: NodeId) -> LocalDefId {
1655 self.owners[&owner].node_id_to_def_id[&id]
1656 }
1657
1658 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
1660 self.current_owner.node_id_to_def_id.get(&node).copied()
1661 }
1662
1663 fn local_def_id(&self, node: NodeId) -> LocalDefId {
1665 self.opt_local_def_id(node).unwrap_or_else(|| {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
}panic!("no entry for node id: `{node:?}`"))
1666 }
1667
1668 fn create_def(
1670 &mut self,
1671 parent: LocalDefId,
1672 node_id: ast::NodeId,
1673 name: Option<Symbol>,
1674 def_kind: DefKind,
1675 expn_id: ExpnId,
1676 span: Span,
1677 is_owner: bool,
1678 ) -> TyCtxtFeed<'tcx, LocalDefId> {
1679 if !!self.current_owner.node_id_to_def_id.contains_key(&node_id) {
{
::core::panicking::panic_fmt(format_args!("adding a def for node-id {0:?}, name {1:?}, data {2:?} but a previous def exists: {3:?}",
node_id, name, def_kind,
self.tcx.definitions_untracked().def_key(self.current_owner.node_id_to_def_id[&node_id])));
}
};assert!(
1680 !self.current_owner.node_id_to_def_id.contains_key(&node_id),
1681 "adding a def for node-id {:?}, name {:?}, data {:?} but a previous def exists: {:?}",
1682 node_id,
1683 name,
1684 def_kind,
1685 self.tcx
1686 .definitions_untracked()
1687 .def_key(self.current_owner.node_id_to_def_id[&node_id]),
1688 );
1689
1690 let disambiguator = self.disambiguators.get_or_create(parent);
1691
1692 let feed = self.tcx.create_def(parent, name, def_kind, None, disambiguator);
1694 let def_id = feed.def_id();
1695
1696 if expn_id != ExpnId::root() {
1698 self.expn_that_defined.insert(def_id, expn_id);
1699 }
1700
1701 if true {
{
match (&span.data_untracked().parent, &None) {
(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);
}
}
}
};
};debug_assert_eq!(span.data_untracked().parent, None);
1703 let _id = self.tcx.untracked().source_span.push(span);
1704 if true {
{
match (&_id, &def_id) {
(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);
}
}
}
};
};debug_assert_eq!(_id, def_id);
1705
1706 if node_id != ast::DUMMY_NODE_ID && !is_owner {
1710 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:1710",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1710u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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!("create_def: def_id_to_node_id[{0:?}] <-> {1:?}",
def_id, node_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
1711 self.current_owner.node_id_to_def_id.insert(node_id, def_id);
1712 }
1713
1714 feed
1715 }
1716
1717 fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize {
1718 if let Some(def_id) = def_id.as_local() {
1719 self.item_generics_num_lifetimes[&def_id]
1720 } else {
1721 self.tcx.generics_of(def_id).own_counts().lifetimes
1722 }
1723 }
1724
1725 fn item_required_generic_args_suggestion(&self, def_id: DefId) -> String {
1726 if let Some(def_id) = def_id.as_local() {
1727 self.item_required_generic_args_suggestions.get(&def_id).cloned().unwrap_or_default()
1728 } else {
1729 let required = self
1730 .tcx
1731 .generics_of(def_id)
1732 .own_params
1733 .iter()
1734 .filter_map(|param| match param.kind {
1735 ty::GenericParamDefKind::Lifetime => Some("'_"),
1736 ty::GenericParamDefKind::Type { has_default, .. }
1737 | ty::GenericParamDefKind::Const { has_default } => {
1738 if has_default {
1739 None
1740 } else {
1741 Some("_")
1742 }
1743 }
1744 })
1745 .collect::<Vec<_>>();
1746
1747 if required.is_empty() { String::new() } else { ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", required.join(", ")))
})format!("<{}>", required.join(", ")) }
1748 }
1749 }
1750
1751 pub fn tcx(&self) -> TyCtxt<'tcx> {
1752 self.tcx
1753 }
1754
1755 fn def_id_to_node_id(&self, def_id: LocalDefId) -> NodeId {
1762 self.owners
1763 .items()
1764 .flat_map(|(_, data)| {
1765 data.node_id_to_def_id
1766 .items()
1767 .chain(UnordItems::new([(&data.id, &data.def_id)].into_iter()))
1768 })
1769 .filter(|(_, v)| **v == def_id)
1770 .map(|(k, _)| *k)
1771 .get_only()
1772 .unwrap()
1773 }
1774}
1775
1776impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1777 pub fn new(
1778 tcx: TyCtxt<'tcx>,
1779 attrs: &[ast::Attribute],
1780 crate_span: Span,
1781 current_crate_outer_attr_insert_span: Span,
1782 arenas: &'ra WorkerLocal<ResolverArenas<'ra>>,
1783 ) -> Resolver<'ra, 'tcx> {
1784 let root_def_id = CRATE_DEF_ID.to_def_id();
1785 let graph_root = LocalModule::new(
1786 None,
1787 ModuleKind::Def(DefKind::Mod, root_def_id, CRATE_NODE_ID, None),
1788 Visibility::Public,
1789 ExpnId::root(),
1790 crate_span,
1791 attr::contains_name(attrs, sym::no_implicit_prelude),
1792 arenas,
1793 );
1794 let local_modules = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[graph_root]))vec![graph_root];
1795 let local_module_map = FxIndexMap::from_iter([(CRATE_DEF_ID, graph_root)]);
1796 let empty_module = LocalModule::new(
1797 None,
1798 ModuleKind::Def(DefKind::Mod, root_def_id, CRATE_NODE_ID, None),
1799 Visibility::Public,
1800 ExpnId::root(),
1801 DUMMY_SP,
1802 true,
1803 arenas,
1804 );
1805
1806 let owner_data = PerOwnerResolverData::new(CRATE_NODE_ID, CRATE_DEF_ID);
1807 let crate_feed = tcx.create_local_crate_def_id(crate_span);
1808
1809 crate_feed.def_kind(DefKind::Mod);
1810 let mut owners = NodeMap::default();
1811 owners.insert(CRATE_NODE_ID, owner_data);
1812
1813 let mut invocation_parents = FxHashMap::default();
1814 invocation_parents.insert(LocalExpnId::ROOT, InvocationParent::ROOT);
1815
1816 let extern_prelude = build_extern_prelude(tcx, attrs);
1817 let registered_attr_tools = tcx.registered_attr_tools(());
1818 let registered_lint_tools = tcx.registered_lint_tools(());
1819 let edition = tcx.sess.edition();
1820
1821 let mut resolver = Resolver {
1822 tcx,
1823
1824 graph_root,
1827 speculative_flag: SpeculativeFlag::default(),
1829 extern_prelude,
1830
1831 empty_module,
1832 local_modules,
1833 local_module_map,
1834 extern_module_map: Default::default(),
1835
1836 glob_map: Default::default(),
1837 maybe_unused_trait_imports: Default::default(),
1838
1839 arenas,
1840 dummy_decl: arenas.new_pub_def_decl(Res::Err, DUMMY_SP, LocalExpnId::ROOT),
1841 builtin_type_decls: PrimTy::ALL
1842 .iter()
1843 .map(|prim_ty| {
1844 let res = Res::PrimTy(*prim_ty);
1845 let decl = arenas.new_pub_def_decl(res, DUMMY_SP, LocalExpnId::ROOT);
1846 (prim_ty.name(), decl)
1847 })
1848 .collect(),
1849 builtin_attr_decls: BUILTIN_ATTRIBUTES
1850 .iter()
1851 .map(|builtin_attr| {
1852 let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin(*builtin_attr));
1853 let decl = arenas.new_pub_def_decl(res, DUMMY_SP, LocalExpnId::ROOT);
1854 (*builtin_attr, decl)
1855 })
1856 .collect(),
1857 registered_attr_tool_decls: registered_attr_tools
1858 .iter()
1859 .map(|&ident| {
1860 let res = Res::ToolMod;
1861 let decl = arenas.new_pub_def_decl(res, ident.span, LocalExpnId::ROOT);
1862 (IdentKey::new(ident), decl)
1863 })
1864 .collect(),
1865 registered_attr_tools,
1866 registered_lint_tools,
1867 macro_use_prelude: Default::default(),
1868 extern_macro_map: Default::default(),
1869 dummy_ext_bang: arenas.alloc_macro(SyntaxExtension::dummy_bang(edition)),
1870 dummy_ext_derive: arenas.alloc_macro(SyntaxExtension::dummy_derive(edition)),
1871 non_macro_attr: arenas.alloc_macro(SyntaxExtension::non_macro_attr(edition)),
1872 unused_macros: Default::default(),
1873 unused_macro_rules: Default::default(),
1874 single_segment_macro_resolutions: Default::default(),
1875 multi_segment_macro_resolutions: Default::default(),
1876 lint_buffer: LintBuffer::default(),
1877 owners,
1878 current_owner: PerOwnerResolverData::new(DUMMY_NODE_ID, CRATE_DEF_ID),
1879 invocation_parents,
1880 trait_impls: Default::default(),
1881 confused_type_with_std_module: Default::default(),
1882 stripped_cfg_items: Default::default(),
1883 effective_visibilities: Default::default(),
1884 macro_reachable_adts: Default::default(),
1885 doc_link_resolutions: Default::default(),
1886 doc_link_traits_in_scope: Default::default(),
1887 current_crate_outer_attr_insert_span,
1888 disambiguators: Default::default(),
1889 delegation_infos: Default::default(),
1890 features: tcx.features(),
1891 ..
1892 };
1893
1894 if let Some(directive) = OnUnknownData::from_attrs(&resolver, attrs) {
1895 resolver.on_unknown_data.insert(CRATE_DEF_ID, directive);
1896 }
1897
1898 let root_parent_scope = ParentScope::module(graph_root, resolver.arenas);
1899 resolver.invocation_parent_scopes.insert(LocalExpnId::ROOT, root_parent_scope);
1900 resolver.feed_visibility(crate_feed, Visibility::Public);
1901
1902 resolver
1903 }
1904
1905 fn new_local_module(
1906 &mut self,
1907 parent: Option<LocalModule<'ra>>,
1908 kind: ModuleKind,
1909 expn_id: ExpnId,
1910 span: Span,
1911 no_implicit_prelude: bool,
1912 ) -> LocalModule<'ra> {
1913 let vis =
1914 kind.opt_def_id().map_or(Visibility::Public, |def_id| self.tcx.visibility(def_id));
1915 let module =
1916 LocalModule::new(parent, kind, vis, expn_id, span, no_implicit_prelude, self.arenas);
1917 self.local_modules.push(module);
1918 if let Some(def_id) = module.opt_def_id() {
1919 self.local_module_map.insert(def_id.expect_local(), module);
1920 }
1921 module
1922 }
1923
1924 fn next_node_id(&mut self) -> NodeId {
1925 let start = self.next_node_id;
1926 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
1927 self.next_node_id = ast::NodeId::from_u32(next);
1928 start
1929 }
1930
1931 fn next_node_ids(&mut self, count: usize) -> std::ops::Range<NodeId> {
1932 let start = self.next_node_id;
1933 let end = start.as_usize().checked_add(count).expect("input too large; ran out of NodeIds");
1934 self.next_node_id = ast::NodeId::from_usize(end);
1935 start..self.next_node_id
1936 }
1937
1938 pub fn lint_buffer(&mut self) -> &mut LintBuffer {
1939 &mut self.lint_buffer
1940 }
1941
1942 pub fn arenas() -> ResolverArenas<'ra> {
1943 Default::default()
1944 }
1945
1946 fn feed_visibility(&mut self, feed: TyCtxtFeed<'tcx, LocalDefId>, vis: Visibility) {
1947 feed.visibility(vis.to_mod_id());
1948 self.visibilities_for_hashing.push((feed.def_id(), vis));
1949 }
1950
1951 pub fn into_outputs(self) -> ResolverOutputs<'tcx> {
1952 let proc_macros = self.proc_macros;
1953 let expn_that_defined = self.expn_that_defined;
1954 let extern_crate_map = self.extern_crate_map;
1955 let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
1956 let glob_map = self.glob_map;
1957 let main_def = self.main_def;
1958 let confused_type_with_std_module = self.confused_type_with_std_module;
1959 let effective_visibilities = self.effective_visibilities;
1960
1961 let stripped_cfg_items = self
1962 .stripped_cfg_items
1963 .into_iter()
1964 .filter_map(|item| {
1965 let parent_scope = self.owners.get(&item.parent_scope)?.def_id.to_def_id();
1966 Some(StrippedCfgItem { parent_scope, ident: item.ident, cfg: item.cfg })
1967 })
1968 .collect();
1969 let disambiguators = self
1970 .disambiguators
1971 .into_items()
1972 .map(|(def_id, disamb)| (def_id, Steal::new(disamb)))
1973 .collect();
1974
1975 let global_ctxt = ResolverGlobalCtxt {
1976 expn_that_defined,
1977 visibilities_for_hashing: self.visibilities_for_hashing,
1978 effective_visibilities,
1979 macro_reachable_adts: self.macro_reachable_adts,
1980 extern_crate_map,
1981 module_children: self.module_children,
1982 ambig_module_children: self.ambig_module_children,
1983 glob_map,
1984 maybe_unused_trait_imports,
1985 main_def,
1986 trait_impls: self.trait_impls,
1987 proc_macros,
1988 confused_type_with_std_module,
1989 doc_link_resolutions: self.doc_link_resolutions,
1990 doc_link_traits_in_scope: self.doc_link_traits_in_scope,
1991 all_macro_rules: self.all_macro_rules,
1992 stripped_cfg_items,
1993 delegation_infos: self.delegation_infos,
1994 };
1995 let ast_lowering = ResolverAstLowering {
1996 partial_res_map: self.partial_res_map,
1997 next_node_id: self.next_node_id,
1998 owners: self.owners,
1999 lint_buffer: Steal::new(self.lint_buffer),
2000 disambiguators,
2001 };
2002 ResolverOutputs { global_ctxt, ast_lowering }
2003 }
2004
2005 fn cstore(&self) -> FreezeReadGuard<'_, CStore> {
2006 CStore::from_tcx(self.tcx)
2007 }
2008
2009 fn cstore_mut(&self) -> FreezeWriteGuard<'_, CStore> {
2010 CStore::from_tcx_mut(self.tcx)
2011 }
2012
2013 fn dummy_ext(&self, macro_kind: MacroKind) -> &'ra Arc<SyntaxExtension> {
2014 match macro_kind {
2015 MacroKind::Bang => self.dummy_ext_bang,
2016 MacroKind::Derive => self.dummy_ext_derive,
2017 MacroKind::Attr => self.non_macro_attr,
2018 }
2019 }
2020
2021 fn cm(&self) -> CmResolver<'_, 'ra, 'tcx> {
2023 CmResolver::Ref(self)
2024 }
2025
2026 fn cm_mut(&mut self) -> CmResolver<'_, 'ra, 'tcx> {
2029 if !!self.speculative_flag.is_speculative() {
{
::core::panicking::panic_fmt(format_args!("can\'t mutably borrow speculative resolver"));
}
};assert!(
2030 !self.speculative_flag.is_speculative(),
2031 "can't mutably borrow speculative resolver"
2032 );
2033 CmResolver::Mut(self)
2034 }
2035
2036 fn per_ns<F: FnMut(&Self, Namespace)>(&self, mut f: F) {
2038 f(self, TypeNS);
2039 f(self, ValueNS);
2040 f(self, MacroNS);
2041 }
2042
2043 fn per_ns_mut<F: FnMut(&mut Self, Namespace)>(&mut self, mut f: F) {
2044 f(self, TypeNS);
2045 f(self, ValueNS);
2046 f(self, MacroNS);
2047 }
2048
2049 fn is_builtin_macro(&self, res: Res) -> bool {
2050 self.get_macro(res).is_some_and(|ext| ext.builtin_name.is_some())
2051 }
2052
2053 fn is_specific_builtin_macro(&self, res: Res, symbol: Symbol) -> bool {
2054 self.get_macro(res).is_some_and(|ext| ext.builtin_name == Some(symbol))
2055 }
2056
2057 fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {
2058 loop {
2059 match ctxt.outer_expn_data().macro_def_id {
2060 Some(def_id) => return def_id,
2061 None => ctxt.remove_mark(),
2062 };
2063 }
2064 }
2065
2066 pub fn resolve_crate(&mut self, krate: &Crate) {
2068 self.tcx.sess.time("resolve_crate", || {
2069 self.tcx.sess.time("finalize_imports", || self.finalize_imports());
2070 let exported_ambiguities = self.tcx.sess.time("compute_effective_visibilities", || {
2071 EffectiveVisibilitiesVisitor::compute_effective_visibilities(self, krate)
2072 });
2073 self.tcx.sess.time("lint_reexports", || self.lint_reexports(exported_ambiguities));
2074 self.tcx
2075 .sess
2076 .time("finalize_macro_resolutions", || self.finalize_macro_resolutions(krate));
2077 let (use_items, use_injections) =
2078 self.tcx.sess.time("late_resolve_crate", || self.late_resolve_crate(krate));
2079 self.tcx.sess.time("resolve_main", || self.resolve_main());
2080 self.tcx.sess.time("resolve_check_unused", || self.check_unused(use_items));
2081 self.tcx
2082 .sess
2083 .time("resolve_report_errors", || self.report_errors(krate, use_injections));
2084 self.tcx
2085 .sess
2086 .time("resolve_postprocess", || self.cstore_mut().postprocess(self.tcx, krate));
2087 });
2088
2089 self.tcx.untracked().freeze_cstore();
2091 }
2092
2093 fn traits_in_scope(
2094 &mut self,
2095 current_trait: Option<Module<'ra>>,
2096 parent_scope: &ParentScope<'ra>,
2097 sp: Span,
2098 assoc_item: Option<(Symbol, Namespace)>,
2099 ) -> &'tcx [TraitCandidate<'tcx>] {
2100 let mut found_traits = Vec::new();
2101
2102 if let Some(module) = current_trait {
2103 if self.trait_may_have_item(Some(module), assoc_item) {
2104 let def_id = module.def_id();
2105 found_traits.push(TraitCandidate {
2106 def_id,
2107 import_ids: &[],
2108 lint_ambiguous: false,
2109 });
2110 }
2111 }
2112
2113 let scope_set = ScopeSet::All(TypeNS);
2114 let ctxt = Macros20NormalizedSyntaxContext::new(sp.ctxt());
2115 let cmr = self.cm_mut();
2116 cmr.visit_scopes(scope_set, parent_scope, ctxt, sp, None, |mut this, scope, _, _| {
2117 match scope {
2118 Scope::ModuleNonGlobs(module, _) => {
2119 this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
2120 }
2121 Scope::ModuleGlobs(..) => {
2122 }
2124 Scope::StdLibPrelude => {
2125 if let Some(module) = this.prelude {
2126 this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
2127 }
2128 }
2129 Scope::ExternPreludeItems
2130 | Scope::ExternPreludeFlags
2131 | Scope::ToolAttributePrelude
2132 | Scope::BuiltinTypes => {}
2133 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
2134 }
2135 ControlFlow::<()>::Continue(())
2136 });
2137
2138 self.tcx.hir_arena.alloc_slice(&found_traits)
2139 }
2140
2141 fn traits_in_module(
2142 &mut self,
2143 module: Module<'ra>,
2144 assoc_item: Option<(Symbol, Namespace)>,
2145 found_traits: &mut Vec<TraitCandidate<'tcx>>,
2146 ) {
2147 module.ensure_traits(self);
2148 let traits = module.traits.borrow(self);
2149 for &(trait_name, trait_binding, trait_module, lint_ambiguous) in
2150 traits.as_ref().unwrap().iter()
2151 {
2152 if self.trait_may_have_item(trait_module, assoc_item) {
2153 let def_id = trait_binding.res().def_id();
2154 let import_ids = self.find_transitive_imports(&trait_binding.kind, trait_name);
2155 found_traits.push(TraitCandidate { def_id, import_ids, lint_ambiguous });
2156 }
2157 }
2158 }
2159
2160 fn trait_may_have_item(
2166 &self,
2167 trait_module: Option<Module<'ra>>,
2168 assoc_item: Option<(Symbol, Namespace)>,
2169 ) -> bool {
2170 match (trait_module, assoc_item) {
2171 (Some(trait_module), Some((name, ns))) => self
2172 .resolutions(trait_module)
2173 .iter()
2174 .any(|(key, _name_resolution)| key.ns == ns && key.ident.name == name),
2175 _ => true,
2176 }
2177 }
2178
2179 fn find_transitive_imports(
2180 &mut self,
2181 mut kind: &DeclKind<'_>,
2182 trait_name: Symbol,
2183 ) -> &'tcx [LocalDefId] {
2184 let mut import_ids: SmallVec<[LocalDefId; 1]> = ::smallvec::SmallVec::new()smallvec![];
2185 while let DeclKind::Import { import, source_decl, .. } = kind {
2186 if let Some(def_id) = import.def_id() {
2187 self.maybe_unused_trait_imports.insert(def_id);
2188 import_ids.push(def_id);
2189 }
2190 self.add_to_glob_map(*import, trait_name);
2191 kind = &source_decl.kind;
2192 }
2193
2194 self.tcx.hir_arena.alloc_slice(&import_ids)
2195 }
2196
2197 fn resolutions(&self, module: Module<'ra>) -> CmRef<'ra, ResolutionTable<'ra>> {
2198 match &module.0.0.lazy_resolutions {
2199 Resolutions::Local(local_res) => local_res.borrow_checked(self),
2200 Resolutions::Extern(extern_res) => {
2201 CmRef::Untracked(
2204 extern_res
2206 .get_or_init(|| self.build_reduced_graph_external(module.expect_extern())),
2207 )
2208 }
2209 }
2210 }
2211
2212 fn resolutions_mut(&mut self, module: Module<'ra>) -> RefMut<'ra, ResolutionTable<'ra>> {
2213 match &module.0.0.lazy_resolutions {
2214 Resolutions::Local(local_res) => local_res.borrow_mut(self),
2215 Resolutions::Extern(_) => {
2216 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("Attempted to mutably borrow an extenral resolution table")));
}unreachable!("Attempted to mutably borrow an extenral resolution table")
2219 }
2220 }
2221 }
2222
2223 fn resolution(
2224 &self,
2225 module: Module<'ra>,
2226 key: BindingKey,
2227 ) -> Option<CmRef<'ra, NameResolution<'ra>>> {
2228 self.resolutions(module).get(&key).map(|resolution| resolution.0.borrow_checked(self))
2229 }
2230
2231 #[track_caller]
2232 fn resolution_or_default(
2233 &mut self,
2234 module: Module<'ra>,
2235 key: BindingKey,
2236 orig_ident_span: Span,
2237 ) -> NameResolutionRef<'ra> {
2238 *self.resolutions_mut(module).entry(key).or_insert_with(|| {
2239 self.arenas.alloc_name_resolution(NameResolution::new(orig_ident_span))
2240 })
2241 }
2242
2243 fn matches_previous_ambiguity_error(&self, ambi: &AmbiguityError<'_>) -> bool {
2245 for ambiguity_error in &self.ambiguity_errors {
2246 if ambiguity_error.kind == ambi.kind
2248 && ambiguity_error.ident == ambi.ident
2249 && ambiguity_error.ident.span == ambi.ident.span
2250 && ambiguity_error.b1.span == ambi.b1.span
2251 && ambiguity_error.b2.span == ambi.b2.span
2252 {
2253 return true;
2254 }
2255 }
2256 false
2257 }
2258
2259 fn record_use(&mut self, ident: Ident, used_decl: Decl<'ra>, used: Used) {
2260 if let Some((b2, warning)) = used_decl.ambiguity.get() {
2261 let ambiguity_error = AmbiguityError {
2262 kind: AmbiguityKind::GlobVsGlob,
2263 ambig_vis: None,
2264 ident,
2265 b1: used_decl,
2266 b2,
2267 scope1: Scope::ModuleGlobs(used_decl.parent_module.unwrap(), None),
2268 scope2: Scope::ModuleGlobs(b2.parent_module.unwrap(), None),
2269 warning: if warning { Some(AmbiguityWarning::GlobImport) } else { None },
2270 };
2271 if !self.matches_previous_ambiguity_error(&ambiguity_error) {
2272 self.ambiguity_errors.push(ambiguity_error);
2274 }
2275 }
2276 if let DeclKind::Import { import, source_decl } = used_decl.kind {
2277 if let ImportKind::MacroUse { warn_private: true } = import.kind {
2278 let found_in_stdlib_prelude = self.prelude.is_some_and(|prelude| {
2281 let empty_module = self.empty_module;
2282 let arenas = self.arenas;
2283 self.cm()
2284 .maybe_resolve_ident_in_module(
2285 ModuleOrUniformRoot::Module(prelude),
2286 ident,
2287 MacroNS,
2288 &ParentScope::module(empty_module, arenas),
2289 None,
2290 )
2291 .is_ok()
2292 });
2293 if !found_in_stdlib_prelude {
2294 self.lint_buffer().buffer_lint(
2295 PRIVATE_MACRO_USE,
2296 import.root_id,
2297 ident.span,
2298 diagnostics::MacroIsPrivate { ident },
2299 );
2300 }
2301 }
2302 if used == Used::Scope
2305 && let Some(entry) = self.extern_prelude.get(&IdentKey::new(ident))
2306 && let Some((item_decl, _, false)) = entry.item_decl
2307 && item_decl == used_decl
2308 {
2309 return;
2310 }
2311 let old_used = self.import_use_map.entry(import).or_insert(used);
2312 if *old_used < used {
2313 *old_used = used;
2314 }
2315 if let Some(id) = import.id() {
2316 self.used_imports.insert(id);
2317 }
2318 self.add_to_glob_map(import, ident.name);
2319 self.record_use(ident, source_decl, Used::Other);
2320 }
2321 }
2322
2323 #[inline]
2324 fn add_to_glob_map(&mut self, import: Import<'_>, name: Symbol) {
2325 if let ImportKind::Glob { def_id, .. } = import.kind {
2326 self.glob_map.entry(def_id).or_default().insert(name);
2327 }
2328 }
2329
2330 fn resolve_crate_root(&self, ident: Ident) -> Module<'ra> {
2331 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2331",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2331u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root({0:?})",
ident) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_crate_root({:?})", ident);
2332 let mut ctxt = ident.span.ctxt();
2333 let mark = if ident.name == kw::DollarCrate {
2334 ctxt = ctxt.normalize_to_macro_rules();
2341 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2341",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2341u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root: marks={0:?}",
ctxt.marks().into_iter().map(|(i, t)|
(i.expn_data(), t)).collect::<Vec<_>>()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
2342 "resolve_crate_root: marks={:?}",
2343 ctxt.marks().into_iter().map(|(i, t)| (i.expn_data(), t)).collect::<Vec<_>>()
2344 );
2345 let mut iter = ctxt.marks().into_iter().rev().peekable();
2346 let mut result = None;
2347 while let Some(&(mark, transparency)) = iter.peek() {
2349 if transparency == Transparency::Opaque {
2350 result = Some(mark);
2351 iter.next();
2352 } else {
2353 break;
2354 }
2355 }
2356 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2356",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2356u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root: found opaque mark {0:?} {1:?}",
result, result.map(|r| r.expn_data())) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
2357 "resolve_crate_root: found opaque mark {:?} {:?}",
2358 result,
2359 result.map(|r| r.expn_data())
2360 );
2361 for (mark, transparency) in iter {
2363 if transparency == Transparency::SemiOpaque {
2364 result = Some(mark);
2365 } else {
2366 break;
2367 }
2368 }
2369 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2369",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2369u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root: found semi-opaque mark {0:?} {1:?}",
result, result.map(|r| r.expn_data())) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
2370 "resolve_crate_root: found semi-opaque mark {:?} {:?}",
2371 result,
2372 result.map(|r| r.expn_data())
2373 );
2374 result
2375 } else {
2376 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2376",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2376u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root: not DollarCrate")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_crate_root: not DollarCrate");
2377 ctxt = ctxt.normalize_to_macros_2_0();
2378 ctxt.adjust(ExpnId::root())
2379 };
2380 let module = match mark {
2381 Some(def) => self.expn_def_scope(def),
2382 None => {
2383 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2383",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2383u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root({0:?}): found no mark (ident.span = {1:?})",
ident, ident.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
2384 "resolve_crate_root({:?}): found no mark (ident.span = {:?})",
2385 ident, ident.span
2386 );
2387 return self.graph_root.to_module();
2388 }
2389 };
2390 let module = self.expect_module(
2391 module.opt_def_id().map_or(LOCAL_CRATE, |def_id| def_id.krate).as_def_id(),
2392 );
2393 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2393",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2393u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::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_crate_root({0:?}): got module {1:?} ({2:?}) (ident.span = {3:?})",
ident, module, module.name(), ident.span) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
2394 "resolve_crate_root({:?}): got module {:?} ({:?}) (ident.span = {:?})",
2395 ident,
2396 module,
2397 module.name(),
2398 ident.span
2399 );
2400 module
2401 }
2402
2403 fn resolve_self(&self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> {
2404 let mut module = self.expect_module(module.nearest_parent_mod().to_def_id());
2405 while module.span.ctxt().normalize_to_macros_2_0() != *ctxt {
2406 let parent = module.parent.unwrap_or_else(|| self.expn_def_scope(ctxt.remove_mark()));
2407 module = self.expect_module(parent.nearest_parent_mod().to_def_id());
2408 }
2409 module
2410 }
2411
2412 fn record_partial_res(&mut self, node_id: NodeId, resolution: PartialRes) {
2413 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2413",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2413u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(recording res) recording {0:?} for {1}",
resolution, node_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(recording res) recording {:?} for {}", resolution, node_id);
2414 if let Some(prev_res) = self.partial_res_map.insert(node_id, resolution) {
2415 {
::core::panicking::panic_fmt(format_args!("path resolved multiple times ({0:?} before, {1:?} now)",
prev_res, resolution));
};panic!("path resolved multiple times ({prev_res:?} before, {resolution:?} now)");
2416 }
2417 }
2418
2419 fn record_pat_span(&mut self, node: NodeId, span: Span) {
2420 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs:2420",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2420u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("(recording pat) recording {0:?} for {1:?}",
node, span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("(recording pat) recording {:?} for {:?}", node, span);
2421 self.pat_span_map.insert(node, span);
2422 }
2423
2424 fn is_accessible_from(&self, vis: Visibility<impl Into<DefId>>, module: Module<'ra>) -> bool {
2425 vis.is_accessible_from(module.nearest_parent_mod(), self.tcx)
2426 }
2427
2428 fn disambiguate_macro_rules_vs_modularized(
2429 &self,
2430 macro_rules: Decl<'ra>,
2431 modularized: Decl<'ra>,
2432 ) -> bool {
2433 let macro_rules = macro_rules.parent_module.unwrap();
2441 let modularized = modularized.parent_module.unwrap();
2442 macro_rules.nearest_parent_mod() == modularized.nearest_parent_mod()
2443 && modularized.is_ancestor_of(macro_rules)
2444 }
2445
2446 fn extern_prelude_get_item<'r>(
2447 mut self: CmResolver<'r, 'ra, 'tcx>,
2448 ident: IdentKey,
2449 orig_ident_span: Span,
2450 finalize: bool,
2451 ) -> Option<Decl<'ra>> {
2452 let entry = self.extern_prelude.get(&ident);
2453 entry.and_then(|entry| entry.item_decl).map(|(decl, ..)| {
2454 if finalize {
2455 self.get_mut().record_use(ident.orig(orig_ident_span), decl, Used::Scope);
2456 }
2457 decl
2458 })
2459 }
2460
2461 fn extern_prelude_get_flag(
2462 &self,
2463 ident: IdentKey,
2464 orig_ident_span: Span,
2465 finalize: bool,
2466 ) -> Option<Decl<'ra>> {
2467 let entry = self.extern_prelude.get(&ident);
2468 entry.and_then(|entry| entry.flag_decl.as_ref()).and_then(|flag_decl| {
2469 let (pending_decl, finalized, is_open) = flag_decl.get();
2470 let decl = match pending_decl {
2471 PendingDecl::Ready(decl) => {
2472 if finalize && !finalized && !is_open {
2473 self.cstore_mut().process_path_extern(
2474 self.tcx,
2475 ident.name,
2476 orig_ident_span,
2477 );
2478 }
2479 decl
2480 }
2481 PendingDecl::Pending => {
2482 if true {
if !!finalized {
::core::panicking::panic("assertion failed: !finalized")
};
};debug_assert!(!finalized);
2483 if is_open {
2484 let res = Res::OpenMod(ident.name);
2485 Some(self.arenas.new_pub_def_decl(res, DUMMY_SP, LocalExpnId::ROOT))
2486 } else {
2487 let crate_id = if finalize {
2488 self.cstore_mut().process_path_extern(
2489 self.tcx,
2490 ident.name,
2491 orig_ident_span,
2492 )
2493 } else {
2494 self.cstore_mut().maybe_process_path_extern(self.tcx, ident.name)
2495 };
2496 crate_id.map(|crate_id| {
2497 let def_id = crate_id.as_def_id();
2498 let res = Res::Def(DefKind::Mod, def_id);
2499 self.arenas.new_pub_def_decl(res, DUMMY_SP, LocalExpnId::ROOT)
2500 })
2501 }
2502 }
2503 };
2504 flag_decl.set((PendingDecl::Ready(decl), finalize || finalized, is_open));
2505 decl.or_else(|| finalize.then_some(self.dummy_decl))
2506 })
2507 }
2508
2509 fn resolve_rustdoc_path(
2514 &self,
2515 path_str: &str,
2516 ns: Namespace,
2517 parent_scope: ParentScope<'ra>,
2518 ) -> Option<Res> {
2519 let segments: Result<Vec<_>, ()> = path_str
2520 .split("::")
2521 .enumerate()
2522 .map(|(i, s)| {
2523 let sym = if s.is_empty() {
2524 if i == 0 {
2525 kw::PathRoot
2527 } else {
2528 return Err(()); }
2530 } else {
2531 Symbol::intern(s)
2532 };
2533 Ok(Segment::from_ident(Ident::with_dummy_span(sym)))
2534 })
2535 .collect();
2536 let Ok(segments) = segments else { return None };
2537
2538 match self.cm().maybe_resolve_path(&segments, Some(ns), &parent_scope, None) {
2539 PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
2540 PathResult::NonModule(path_res) => {
2541 path_res.full_res().filter(|res| !#[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::Ctor(..), _) => true,
_ => false,
}matches!(res, Res::Def(DefKind::Ctor(..), _)))
2542 }
2543 PathResult::Module(ModuleOrUniformRoot::ExternPrelude) | PathResult::Failed { .. } => {
2544 None
2545 }
2546 path_result @ (PathResult::Module(..) | PathResult::Indeterminate) => {
2547 ::rustc_middle::util::bug::bug_fmt(format_args!("got invalid path_result: {0:?}",
path_result))bug!("got invalid path_result: {path_result:?}")
2548 }
2549 }
2550 }
2551
2552 fn def_span(&self, def_id: DefId) -> Span {
2554 match def_id.as_local() {
2555 Some(def_id) => self.tcx.source_span(def_id),
2556 None => self.cstore().def_span_untracked(self.tcx(), def_id),
2558 }
2559 }
2560
2561 fn field_idents(&self, def_id: DefId) -> Option<Vec<Ident>> {
2562 match def_id.as_local() {
2563 Some(def_id) => self.field_names.get(&def_id).cloned(),
2564 None if #[allow(non_exhaustive_omitted_patterns)] match self.tcx.def_kind(def_id) {
DefKind::Struct | DefKind::Union | DefKind::Variant => true,
_ => false,
}matches!(
2565 self.tcx.def_kind(def_id),
2566 DefKind::Struct | DefKind::Union | DefKind::Variant
2567 ) =>
2568 {
2569 Some(
2570 self.tcx
2571 .associated_item_def_ids(def_id)
2572 .iter()
2573 .map(|&def_id| {
2574 Ident::new(self.tcx.item_name(def_id), self.tcx.def_span(def_id))
2575 })
2576 .collect(),
2577 )
2578 }
2579 _ => None,
2580 }
2581 }
2582
2583 fn field_defaults(&self, def_id: DefId) -> Option<Vec<Symbol>> {
2584 match def_id.as_local() {
2585 Some(def_id) => self.field_defaults.get(&def_id).cloned(),
2586 None if #[allow(non_exhaustive_omitted_patterns)] match self.tcx.def_kind(def_id) {
DefKind::Struct | DefKind::Union | DefKind::Variant => true,
_ => false,
}matches!(
2587 self.tcx.def_kind(def_id),
2588 DefKind::Struct | DefKind::Union | DefKind::Variant
2589 ) =>
2590 {
2591 Some(
2592 self.tcx
2593 .associated_item_def_ids(def_id)
2594 .iter()
2595 .filter_map(|&def_id| {
2596 self.tcx.default_field(def_id).map(|_| self.tcx.item_name(def_id))
2597 })
2598 .collect(),
2599 )
2600 }
2601 _ => None,
2602 }
2603 }
2604
2605 fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> {
2609 let ExprKind::Path(None, path) = &expr.kind else {
2610 return None;
2611 };
2612 if path.segments.last().unwrap().args.is_some() {
2615 return None;
2616 }
2617
2618 let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
2619
2620 if def_id.is_local() {
2624 return None;
2625 }
2626
2627 {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcLegacyConstGenerics {
fn_indexes, .. }) => {
break 'done Some(fn_indexes);
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(
2628 self.tcx, def_id,
2630 RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes
2631 )
2632 .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
2633 }
2634
2635 fn resolve_main(&mut self) {
2636 let any_exe = self.tcx.crate_types().contains(&CrateType::Executable);
2637 if !any_exe {
2639 return;
2640 }
2641
2642 let module = self.graph_root;
2643 let ident = Ident::with_dummy_span(sym::main);
2644 let parent_scope = &ParentScope::module(module, self.arenas);
2645
2646 let Ok(name_binding) = self.cm().maybe_resolve_ident_in_module(
2647 ModuleOrUniformRoot::Module(module.to_module()),
2648 ident,
2649 ValueNS,
2650 parent_scope,
2651 None,
2652 ) else {
2653 return;
2654 };
2655
2656 let res = name_binding.res();
2657 let is_import = name_binding.is_import();
2658 let span = name_binding.span;
2659 if let Res::Def(DefKind::Fn, _) = res {
2660 self.record_use(ident, name_binding, Used::Other);
2661 }
2662 self.main_def = Some(MainDefinition { res, is_import, span });
2663 }
2664}
2665
2666fn with_owner<'ra, 'tcx, R: AsMut<Resolver<'ra, 'tcx>>, T>(
2667 this: &mut R,
2668 owner: NodeId,
2669 work: impl FnOnce(&mut R) -> T,
2670) -> T {
2671 let tables = this.as_mut().owners.remove(&owner).unwrap();
2672 with_owner_tables(this, owner, tables, work)
2673}
2674
2675{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("with_owner_tables",
"rustc_resolve", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_resolve/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2675u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("owner")
}> =
::tracing::__macro_support::FieldName::new("owner");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("tables")
}> =
::tracing::__macro_support::FieldName::new("tables");
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(&owner)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&tables)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: T = loop {};
return __tracing_attr_fake_return;
}
{
if true {
if !!this.as_mut().owners.contains_key(&owner) {
::core::panicking::panic("assertion failed: !this.as_mut().owners.contains_key(&owner)")
};
};
let resolver = this.as_mut();
let old_owner = mem::replace(&mut resolver.current_owner, tables);
let ret = work(this);
let resolver = this.as_mut();
let overwritten =
resolver.owners.insert(owner,
mem::replace(&mut resolver.current_owner, old_owner));
if !overwritten.is_none() {
::core::panicking::panic("assertion failed: overwritten.is_none()")
};
ret
}
}
}#[instrument(level = "debug", skip(this, work))]
2676fn with_owner_tables<'ra, 'tcx, R: AsMut<Resolver<'ra, 'tcx>>, T>(
2677 this: &mut R,
2678 owner: NodeId,
2679 tables: PerOwnerResolverData<'tcx>,
2680 work: impl FnOnce(&mut R) -> T,
2681) -> T {
2682 debug_assert!(!this.as_mut().owners.contains_key(&owner));
2683 let resolver = this.as_mut();
2684 let old_owner = mem::replace(&mut resolver.current_owner, tables);
2685 let ret = work(this);
2686 let resolver = this.as_mut();
2687 let overwritten =
2688 resolver.owners.insert(owner, mem::replace(&mut resolver.current_owner, old_owner));
2689 assert!(overwritten.is_none());
2690 ret
2691}
2692
2693fn build_extern_prelude<'tcx, 'ra>(
2694 tcx: TyCtxt<'tcx>,
2695 attrs: &[ast::Attribute],
2696) -> FxIndexMap<IdentKey, ExternPreludeEntry<'ra>> {
2697 let mut extern_prelude: FxIndexMap<IdentKey, ExternPreludeEntry<'ra>> = tcx
2698 .sess
2699 .opts
2700 .externs
2701 .iter()
2702 .filter_map(|(name, entry)| {
2703 if entry.add_prelude
2706 && let sym = Symbol::intern(name)
2707 && sym.can_be_raw()
2708 {
2709 Some((IdentKey::with_root_ctxt(sym), ExternPreludeEntry::flag()))
2710 } else {
2711 None
2712 }
2713 })
2714 .collect();
2715
2716 let missing_open_bases: Vec<IdentKey> = extern_prelude
2722 .keys()
2723 .filter_map(|ident| {
2724 let (base, _) = ident.name.as_str().split_once("::")?;
2725 let base_sym = Symbol::intern(base);
2726 base_sym.can_be_raw().then(|| IdentKey::with_root_ctxt(base_sym))
2727 })
2728 .filter(|base_ident| !extern_prelude.contains_key(base_ident))
2729 .collect();
2730
2731 extern_prelude.extend(
2732 missing_open_bases.into_iter().map(|ident| (ident, ExternPreludeEntry::open_flag())),
2733 );
2734
2735 if !attr::contains_name(attrs, sym::no_core) {
2737 extern_prelude.insert(IdentKey::with_root_ctxt(sym::core), ExternPreludeEntry::flag());
2738
2739 if !attr::contains_name(attrs, sym::no_std) {
2740 extern_prelude.insert(IdentKey::with_root_ctxt(sym::std), ExternPreludeEntry::flag());
2741 }
2742 }
2743
2744 extern_prelude
2745}
2746
2747fn names_to_string(names: impl Iterator<Item = Symbol>) -> String {
2748 let mut result = String::new();
2749 for (i, name) in names.enumerate().filter(|(_, name)| *name != kw::PathRoot) {
2750 if i > 0 {
2751 result.push_str("::");
2752 }
2753 if Ident::with_dummy_span(name).is_raw_guess() {
2754 result.push_str("r#");
2755 }
2756 result.push_str(name.as_str());
2757 }
2758 result
2759}
2760
2761fn path_names_to_string(path: &Path) -> String {
2762 names_to_string(path.segments.iter().map(|seg| seg.ident.name))
2763}
2764
2765fn module_to_string(mut module: Module<'_>) -> Option<String> {
2767 let mut names = Vec::new();
2768 while let Some(parent) = module.parent {
2769 names.push(module.name().unwrap_or(sym::opaque_module_name_placeholder));
2770 module = parent;
2771 }
2772 if names.is_empty() {
2773 return None;
2774 }
2775 Some(names_to_string(names.iter().rev().copied()))
2776}
2777
2778#[derive(#[automatically_derived]
impl ::core::marker::Copy for Stage { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Stage { }
#[automatically_derived]
impl ::core::clone::Clone for Stage {
#[inline]
fn clone(&self) -> Stage { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Stage { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Stage {
#[inline]
fn eq(&self, other: &Stage) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for Stage {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self { Stage::Early => "Early", Stage::Late => "Late", })
}
}Debug)]
2779enum Stage {
2780 Early,
2784 Late,
2787}
2788
2789#[derive(#[automatically_derived]
impl ::core::marker::Copy for ImportSummary { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ImportSummary { }
#[automatically_derived]
impl ::core::clone::Clone for ImportSummary {
#[inline]
fn clone(&self) -> ImportSummary {
let _: ::core::clone::AssertParamIsClone<Visibility>;
let _: ::core::clone::AssertParamIsClone<LocalModId>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ImportSummary {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f, "ImportSummary",
"vis", &self.vis, "nearest_parent_mod", &self.nearest_parent_mod,
"is_single", &self.is_single, "priv_macro_use",
&self.priv_macro_use, "span", &&self.span)
}
}Debug)]
2792struct ImportSummary {
2793 vis: Visibility,
2794 nearest_parent_mod: LocalModId,
2795 is_single: bool,
2796 priv_macro_use: bool,
2797 span: Span,
2798}
2799
2800#[derive(#[automatically_derived]
impl ::core::marker::Copy for Finalize { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Finalize { }
#[automatically_derived]
impl ::core::clone::Clone for Finalize {
#[inline]
fn clone(&self) -> Finalize {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Used>;
let _: ::core::clone::AssertParamIsClone<Stage>;
let _: ::core::clone::AssertParamIsClone<Option<ImportSummary>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Finalize {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["node_id", "path_span", "root_span", "report_private", "used",
"stage", "import"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.node_id, &self.path_span, &self.root_span,
&self.report_private, &self.used, &self.stage,
&&self.import];
::core::fmt::Formatter::debug_struct_fields_finish(f, "Finalize",
names, values)
}
}Debug)]
2802struct Finalize {
2803 node_id: NodeId,
2805 path_span: Span,
2808 root_span: Span,
2811 report_private: bool = true,
2814 used: Used = Used::Other,
2816 stage: Stage = Stage::Early,
2818 import: Option<ImportSummary> = None,
2820}
2821
2822impl Finalize {
2823 fn new(node_id: NodeId, path_span: Span) -> Finalize {
2824 Finalize::with_root_span(node_id, path_span, path_span)
2825 }
2826
2827 fn with_root_span(node_id: NodeId, path_span: Span, root_span: Span) -> Finalize {
2828 Finalize { node_id, path_span, root_span, .. }
2829 }
2830}
2831
2832pub fn provide(providers: &mut Providers) {
2833 providers.registered_attr_tools = macros::registered_attr_tools;
2834 providers.registered_lint_tools = macros::registered_lint_tools;
2835}
2836
2837type CmResolver<'r, 'ra, 'tcx> = ref_mut::RefOrMut<'r, Resolver<'ra, 'tcx>>;
2843
2844use std::cell::{Cell as CacheCell, RefCell as CacheRefCell};
2848
2849mod ref_mut {
2850 use std::cell::{BorrowMutError, Cell, Ref, RefCell, RefMut};
2851 use std::fmt;
2852 use std::ops::Deref;
2853
2854 use crate::Resolver;
2855
2856 pub(crate) enum RefOrMut<'a, T> {
2858 Ref(&'a T),
2859 Mut(&'a mut T),
2860 }
2861
2862 impl<'a, T> Deref for RefOrMut<'a, T> {
2863 type Target = T;
2864
2865 fn deref(&self) -> &Self::Target {
2866 match self {
2867 RefOrMut::Ref(r) => r,
2868 RefOrMut::Mut(r) => r,
2869 }
2870 }
2871 }
2872
2873 impl<'a, T> AsRef<T> for RefOrMut<'a, T> {
2874 fn as_ref(&self) -> &T {
2875 &*self
2876 }
2877 }
2878
2879 impl<'a, T> RefOrMut<'a, T> {
2880 pub(crate) fn reborrow(&mut self) -> RefOrMut<'_, T> {
2882 match self {
2883 RefOrMut::Ref(r) => RefOrMut::Ref(r),
2884 RefOrMut::Mut(r) => RefOrMut::Mut(r),
2885 }
2886 }
2887
2888 #[track_caller]
2894 pub(crate) fn get_mut(&mut self) -> &mut T {
2895 match self {
2896 RefOrMut::Ref(_) => {
::core::panicking::panic_fmt(format_args!("can\'t mutably borrow an immutable reference"));
}panic!("can't mutably borrow an immutable reference"),
2897 RefOrMut::Mut(r) => r,
2898 }
2899 }
2900 }
2901
2902 #[derive(#[automatically_derived]
impl<T: ::core::default::Default> ::core::default::Default for CmCell<T> {
#[inline]
fn default() -> CmCell<T> { CmCell(::core::default::Default::default()) }
}Default)]
2904 pub(crate) struct CmCell<T>(Cell<T>);
2905
2906 impl<T: Copy + fmt::Debug> fmt::Debug for CmCell<T> {
2907 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2908 f.debug_tuple("CmCell").field(&self.get()).finish()
2909 }
2910 }
2911
2912 impl<T: Copy> Clone for CmCell<T> {
2913 fn clone(&self) -> CmCell<T> {
2914 CmCell::new(self.get())
2915 }
2916 }
2917
2918 impl<T: Copy> CmCell<T> {
2919 pub(crate) const fn get(&self) -> T {
2920 self.0.get()
2921 }
2922
2923 pub(crate) fn update<'ra, 'tcx>(
2924 &self,
2925 r: &mut Resolver<'ra, 'tcx>,
2926 f: impl FnOnce(T) -> T,
2927 ) {
2928 let old = self.get();
2929 self.set(f(old), r);
2930 }
2931 }
2932
2933 impl<T> CmCell<T> {
2934 pub(crate) const fn new(value: T) -> CmCell<T> {
2935 CmCell(Cell::new(value))
2936 }
2937
2938 pub(crate) fn set<'ra, 'tcx>(&self, val: T, _: &mut Resolver<'ra, 'tcx>) {
2939 self.0.set(val);
2940 }
2941
2942 pub(crate) fn set_checked<'ra, 'tcx>(&self, val: T, r: &Resolver<'ra, 'tcx>) {
2943 if !!r.speculative_flag.is_speculative() {
{
::core::panicking::panic_fmt(format_args!("Cannot mutate `CmCell` during speculative resolution"));
}
};assert!(
2944 !r.speculative_flag.is_speculative(),
2945 "Cannot mutate `CmCell` during speculative resolution"
2946 );
2947 self.0.set(val);
2948 }
2949
2950 pub(crate) fn into_inner(self) -> T {
2951 self.0.into_inner()
2952 }
2953 }
2954
2955 pub(crate) enum CmRef<'b, T> {
2956 Tracked(Ref<'b, T>),
2958 Untracked(&'b T),
2960 }
2961
2962 impl<'b, T> Deref for CmRef<'b, T> {
2963 type Target = T;
2964
2965 fn deref(&self) -> &Self::Target {
2966 match self {
2967 CmRef::Tracked(r) => r,
2968 CmRef::Untracked(r) => r,
2969 }
2970 }
2971 }
2972
2973 pub(crate) mod speculative {
2974 #[derive(#[automatically_derived]
impl ::core::fmt::Debug for SpeculativeFlag {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"SpeculativeFlag", &&self.0)
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for SpeculativeFlag { }
#[automatically_derived]
impl ::core::clone::Clone for SpeculativeFlag {
#[inline]
fn clone(&self) -> SpeculativeFlag {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for SpeculativeFlag { }Copy, #[automatically_derived]
impl ::core::default::Default for SpeculativeFlag {
#[inline]
fn default() -> SpeculativeFlag {
SpeculativeFlag(::core::default::Default::default())
}
}Default)]
2975 pub(crate) struct SpeculativeFlag(bool);
2976
2977 impl SpeculativeFlag {
2978 pub(crate) unsafe fn set(&mut self, value: bool) {
2985 self.0 = value;
2986 }
2987
2988 pub(crate) fn is_speculative(&self) -> bool {
2989 self.0
2990 }
2991 }
2992 }
2993
2994 #[derive(#[automatically_derived]
impl<T: ::core::default::Default> ::core::default::Default for CmRefCell<T> {
#[inline]
fn default() -> CmRefCell<T> {
CmRefCell(::core::default::Default::default())
}
}Default)]
2996 pub(crate) struct CmRefCell<T>(RefCell<T>);
2997
2998 impl<T> CmRefCell<T> {
2999 pub(crate) fn new(value: T) -> CmRefCell<T> {
3000 CmRefCell(RefCell::new(value))
3001 }
3002
3003 #[track_caller]
3004 pub(crate) fn borrow_mut<'ra, 'tcx>(&self, r: &mut Resolver<'ra, 'tcx>) -> RefMut<'_, T> {
3005 self.try_borrow_mut(r).unwrap()
3006 }
3007
3008 #[track_caller]
3009 pub(crate) fn borrow_mut_checked<'ra, 'tcx>(
3010 &self,
3011 r: &Resolver<'ra, 'tcx>,
3012 ) -> RefMut<'_, T> {
3013 self.try_borrow_mut_checked(r).unwrap()
3014 }
3015
3016 #[track_caller]
3017 pub(crate) fn try_borrow_mut_checked<'ra, 'tcx>(
3018 &self,
3019 r: &Resolver<'ra, 'tcx>,
3020 ) -> Result<RefMut<'_, T>, BorrowMutError> {
3021 if !!r.speculative_flag.is_speculative() {
{
::core::panicking::panic_fmt(format_args!("Cannot mutate `CmRefCell` state/value during speculative resolution"));
}
};assert!(
3022 !r.speculative_flag.is_speculative(),
3023 "Cannot mutate `CmRefCell` state/value during speculative resolution"
3024 );
3025 self.0.try_borrow_mut()
3026 }
3027
3028 #[track_caller]
3029 pub(crate) fn try_borrow_mut<'ra, 'tcx>(
3030 &self,
3031 _: &mut Resolver<'ra, 'tcx>,
3032 ) -> Result<RefMut<'_, T>, BorrowMutError> {
3033 self.0.try_borrow_mut()
3034 }
3035
3036 pub(crate) fn borrow<'ra, 'tcx>(&self, _: &mut Resolver<'ra, 'tcx>) -> Ref<'_, T> {
3037 self.0.borrow()
3038 }
3039
3040 pub(crate) fn borrow_checked<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> CmRef<'_, T> {
3041 if r.speculative_flag.is_speculative() {
3042 CmRef::Untracked(unsafe { self.0.try_borrow_unguarded().unwrap() })
3060 } else {
3061 CmRef::Tracked(self.0.borrow())
3062 }
3063 }
3064 }
3065
3066 impl<T: Default> CmRefCell<T> {
3067 pub(crate) fn take<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> T {
3068 if r.speculative_flag.is_speculative() {
3069 {
::core::panicking::panic_fmt(format_args!("not allowed to mutate a CmRefCell during speculative resolution"));
};panic!("not allowed to mutate a CmRefCell during speculative resolution");
3070 }
3071 self.0.take()
3072 }
3073 }
3074}
3075
3076mod hygiene {
3077 use rustc_span::{ExpnId, SyntaxContext};
3078
3079 #[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Macros20NormalizedSyntaxContext {
}
#[automatically_derived]
impl ::core::clone::Clone for Macros20NormalizedSyntaxContext {
#[inline]
fn clone(&self) -> Macros20NormalizedSyntaxContext {
let _: ::core::clone::AssertParamIsClone<SyntaxContext>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Macros20NormalizedSyntaxContext { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Macros20NormalizedSyntaxContext {
}
#[automatically_derived]
impl ::core::cmp::PartialEq for Macros20NormalizedSyntaxContext {
#[inline]
fn eq(&self, other: &Macros20NormalizedSyntaxContext) -> bool {
self.0 == other.0
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Macros20NormalizedSyntaxContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<SyntaxContext>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Macros20NormalizedSyntaxContext {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for Macros20NormalizedSyntaxContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Macros20NormalizedSyntaxContext", &&self.0)
}
}Debug)]
3082 pub(crate) struct Macros20NormalizedSyntaxContext(SyntaxContext);
3083
3084 impl Macros20NormalizedSyntaxContext {
3085 #[inline]
3086 pub(crate) fn new(ctxt: SyntaxContext) -> Macros20NormalizedSyntaxContext {
3087 Macros20NormalizedSyntaxContext(ctxt.normalize_to_macros_2_0())
3088 }
3089
3090 #[inline]
3091 pub(crate) fn new_adjusted(
3092 mut ctxt: SyntaxContext,
3093 expn_id: ExpnId,
3094 ) -> (Macros20NormalizedSyntaxContext, Option<ExpnId>) {
3095 let def = ctxt.normalize_to_macros_2_0_and_adjust(expn_id);
3096 (Macros20NormalizedSyntaxContext(ctxt), def)
3097 }
3098
3099 #[inline]
3100 pub(crate) fn new_unchecked(ctxt: SyntaxContext) -> Macros20NormalizedSyntaxContext {
3101 if true {
{
match (&ctxt, &ctxt.normalize_to_macros_2_0()) {
(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);
}
}
}
};
};debug_assert_eq!(ctxt, ctxt.normalize_to_macros_2_0());
3102 Macros20NormalizedSyntaxContext(ctxt)
3103 }
3104
3105 #[inline]
3107 pub(crate) fn update_unchecked<R>(&mut self, f: impl FnOnce(&mut SyntaxContext) -> R) -> R {
3108 let ret = f(&mut self.0);
3109 if true {
{
match (&self.0, &self.0.normalize_to_macros_2_0()) {
(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);
}
}
}
};
};debug_assert_eq!(self.0, self.0.normalize_to_macros_2_0());
3110 ret
3111 }
3112 }
3113
3114 impl std::ops::Deref for Macros20NormalizedSyntaxContext {
3115 type Target = SyntaxContext;
3116 fn deref(&self) -> &Self::Target {
3117 &self.0
3118 }
3119 }
3120}