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