Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,18 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
// Don't add underscore imports to `single_imports`
// because they cannot define any usable names.
if target.name != kw::Underscore {
self.r.per_ns(|this, ns| {
self.r.per_ns_mut(|this, ns| {
let key = BindingKey::new(IdentKey::new(target), ns);
this.resolution_or_default(current_module.to_module(), key, target.span)
.borrow_mut(this)
.borrow_mut(this.cm_token_mut())
.single_imports
.insert(import);
});
}
}
ImportKind::Glob { .. } => current_module.globs.borrow_mut(self.r).push(import),
ImportKind::Glob { .. } => {
current_module.globs.borrow_mut(self.r.cm_token_mut()).push(import)
}
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -1264,7 +1266,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
pub(crate) fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'ra> {
let invoc_id = self.visit_invoc(id);
let module = self.parent_scope.module.expect_local();
module.unexpanded_invocations.borrow_mut(self.r).insert(invoc_id);
module.unexpanded_invocations.borrow_mut(self.r.cm_token_mut()).insert(invoc_id);
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Invocation(invoc_id))
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ impl Resolver<'_, '_> {
let mut check_redundant_imports = FxIndexSet::default();
for module in &self.local_modules {
for (_key, resolution) in self.resolutions(module.to_module()).iter() {
if let Some(decl) = resolution.borrow().best_decl()
if let Some(decl) = resolution.borrow_with_token(self.cm_token()).best_decl()
&& let DeclKind::Import { import, .. } = decl.kind
&& let ImportKind::Single { id, .. } = import.kind
{
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
self.resolutions(parent_scope.module).iter().any(|(key, name_resolution)| {
if key.ns == TypeNS
&& key.ident == *ident
&& let Some(decl) = name_resolution.borrow().best_decl()
&& let Some(decl) = name_resolution.borrow(self).best_decl()
{
match decl.res() {
// No disambiguation needed if the identically named item we
Expand Down Expand Up @@ -3603,7 +3603,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let mut res = false;
let m = r.expect_module(parent_module);
if m.is_local() {
for importer in m.glob_importers.borrow().iter() {
for importer in m.glob_importers.borrow(r).iter() {
if let Some(next_parent_module) = importer.parent_scope.module.opt_def_id()
{
if next_parent_module == module
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_resolve/src/effective_visibilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) {
let module = self.r.expect_module(module_id.to_def_id());
for (_, name_resolution) in self.r.resolutions(module).iter() {
let Some(decl) = name_resolution.borrow().best_decl() else {
let Some(decl) = name_resolution.borrow_with_token(self.r.cm_token_mut()).best_decl()
else {
continue;
};
self.update_decl_chain(decl, ParentId::Def(module_id));
Expand Down Expand Up @@ -310,7 +311,9 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
if self.macro_reachable.insert((module_def_id, defining_mod)) {
let module = self.r.expect_module(module_def_id.to_def_id());
for (_, name_resolution) in self.r.resolutions(module).iter() {
let Some(decl) = name_resolution.borrow().best_decl() else {
let Some(decl) =
name_resolution.borrow_with_token(self.r.cm_token_mut()).best_decl()
else {
continue;
};

Expand Down
25 changes: 15 additions & 10 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
Scope::MacroUsePrelude => match self.macro_use_prelude.get(&ident.name).cloned() {
Some(decl) => Ok(decl),
None => Err(Determinacy::determined(!self.graph_root.has_unexpanded_invocations())),
None => {
Err(Determinacy::determined(!self.graph_root.has_unexpanded_invocations(&self)))
}
},
Scope::BuiltinAttrs => match self.builtin_attr_decls.get(&ident.name) {
Some(decl) => Ok(*decl),
Expand All @@ -727,9 +729,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
finalize.is_some(),
) {
Some(decl) => Ok(decl),
None => {
Err(Determinacy::determined(!self.graph_root.has_unexpanded_invocations()))
}
None => Err(Determinacy::determined(
!self.graph_root.has_unexpanded_invocations(&self),
)),
}
}
Scope::ExternPreludeFlags => {
Expand Down Expand Up @@ -1158,7 +1160,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

if let Some(finalize) = finalize {
// finalize implies that the module is fully expanded
assert!(!module.has_unexpanded_invocations());
assert!(!module.has_unexpanded_invocations(&self));
return self.get_mut().finalize_module_binding(
ident,
orig_ident_span,
Expand Down Expand Up @@ -1195,7 +1197,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

// Check if one of unexpanded macros can still define the name.
if module.has_unexpanded_invocations() {
if module.has_unexpanded_invocations(&self) {
return Err(ControlFlow::Continue(Undetermined));
}

Expand Down Expand Up @@ -1224,7 +1226,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

if let Some(finalize) = finalize {
// finalize implies that the module is fully expanded
assert!(!module.has_unexpanded_invocations());
assert!(!module.has_unexpanded_invocations(&self));
return self.get_mut().finalize_module_binding(
ident,
orig_ident_span,
Expand Down Expand Up @@ -1268,7 +1270,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
if let Some(binding) = binding {
return if binding.determined() || ns == MacroNS || shadowing == Shadowing::Restricted {
return if binding.determined(&self)
|| ns == MacroNS
|| shadowing == Shadowing::Restricted
{
let accessible = self.is_accessible_from(binding.vis(), parent_scope.module);
if accessible { Ok(binding) } else { Err(ControlFlow::Break(Determined)) }
} else {
Expand All @@ -1283,13 +1288,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// scopes we return `Undetermined` with `ControlFlow::Continue`.
// Check if one of unexpanded macros can still define the name,
// if it can then our "no resolution" result is not determined and can be invalidated.
if module.has_unexpanded_invocations() {
if module.has_unexpanded_invocations(&self) {
return Err(ControlFlow::Continue(Undetermined));
}

// Check if one of glob imports can still define the name,
// if it can then our "no resolution" result is not determined and can be invalidated.
for glob_import in module.globs.borrow().iter() {
for glob_import in module.globs.borrow(&self).iter() {
if ignore_import == Some(*glob_import) {
continue;
}
Expand Down
37 changes: 20 additions & 17 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|| max_vis.get().is_none_or(|max_vis| vis.greater_than(max_vis, self.tcx)))
{
// `set` can't fail because this can only happen during "write_import_resolutions"
max_vis.set(Some(vis), self)
max_vis.set(Some(vis), self.cm_token())
}

self.arenas.alloc_decl(DeclData {
Expand Down Expand Up @@ -585,15 +585,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&& glob_decl.ambiguity.get().is_none()
{
// Do not lose glob ambiguities when re-fetching the glob.
glob_decl.ambiguity.set(Some((old_ambig, true)), self);
glob_decl.ambiguity.set(Some((old_ambig, true)), self.cm_token());
}
glob_decl
} else if glob_decl.res() != old_glob_decl.res() {
let warning = self.is_noise_0_7_0(old_glob_decl, glob_decl)
|| self.is_rustybuzz_0_4_0(old_glob_decl, glob_decl)
|| self.is_pdf_0_9_0(old_glob_decl, glob_decl)
|| self.is_net2_0_2_39(old_glob_decl, glob_decl);
old_glob_decl.ambiguity.set(Some((glob_decl, warning)), self);
old_glob_decl.ambiguity.set(Some((glob_decl, warning)), self.cm_token());
old_glob_decl
} else if let old_vis = old_glob_decl.vis()
&& let vis = glob_decl.vis()
Expand All @@ -602,17 +602,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// We are glob-importing the same item but with a different visibility.
// All visibilities here are ordered because all of them are ancestors of `module`.
if vis.greater_than(old_vis, self.tcx) {
old_glob_decl.ambiguity_vis_max.set(Some(glob_decl), self);
old_glob_decl.ambiguity_vis_max.set(Some(glob_decl), self.cm_token());
} else if let old_min_vis = old_glob_decl.min_vis()
&& old_min_vis != vis
&& old_min_vis.greater_than(vis, self.tcx)
{
old_glob_decl.ambiguity_vis_min.set(Some(glob_decl), self);
old_glob_decl.ambiguity_vis_min.set(Some(glob_decl), self.cm_token());
}
old_glob_decl
} else if glob_decl.is_ambiguity_recursive() && !old_glob_decl.is_ambiguity_recursive() {
// Overwriting a non-ambiguous glob import with an ambiguous glob import.
old_glob_decl.ambiguity.set(Some((glob_decl, true)), self);
old_glob_decl.ambiguity.set(Some((glob_decl, true)), self.cm_token());
old_glob_decl
} else {
old_glob_decl
Expand All @@ -639,7 +639,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// because they can be fetched by glob imports from those modules, and bring traits
// into scope both directly and through glob imports.
let key = BindingKey::new_disambiguated(ident, ns, || {
module.underscore_disambiguator.update(self, |d| d + 1);
module.underscore_disambiguator.update(self.cm_token_mut(), |d| d + 1);
module.underscore_disambiguator.get()
});
self.update_local_resolution(module, key, orig_ident_span, |this, resolution| {
Expand Down Expand Up @@ -686,7 +686,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let resolution = &mut *self
.resolution_or_default(module.to_module(), key, orig_ident_span)
.0
.borrow_mut(self);
.borrow_mut(self.cm_token_mut());
let old_decl = resolution.determined_decl();
let old_vis = old_decl.map(|d| d.vis());

Expand All @@ -701,7 +701,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
};

let Ok(glob_importers) = module.glob_importers.try_borrow_mut(self) else {
let Ok(glob_importers) = module.glob_importers.try_borrow_mut(self.cm_token_mut()) else {
return t;
};

Expand Down Expand Up @@ -810,14 +810,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let Some(ImportResolution { imported_module, .. }) = resolution else {
continue;
};
import.imported_module.set(Some(*imported_module), self);
import.imported_module.set(Some(*imported_module), self.cm_token_mut());

if import.is_glob()
&& let ModuleOrUniformRoot::Module(module) = imported_module
&& import.parent_scope.module != *module
&& module.is_local()
{
module.glob_importers.borrow_mut(self).push(import);
module.glob_importers.borrow_mut(self.cm_token_mut()).push(import);
}
}

Expand Down Expand Up @@ -854,7 +854,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ns,
import_decl,
);
decls[ns].set(PendingDecl::Ready(Some(import_decl)), this);
decls[ns].set(
PendingDecl::Ready(Some(import_decl)),
this.cm_token_mut(),
);
}
PendingDecl::Ready(None) => {
// Don't remove underscores from `single_imports`, they were never added.
Expand All @@ -869,7 +872,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
},
);
}
decls[ns].set(PendingDecl::Ready(None), this);
decls[ns].set(PendingDecl::Ready(None), this.cm_token_mut());
}
PendingDecl::Pending => {}
}
Expand Down Expand Up @@ -1003,7 +1006,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
pub(crate) fn lint_reexports(&mut self, exported_ambiguities: FxHashSet<Decl<'ra>>) {
for module in &self.local_modules {
for (key, resolution) in self.resolutions(module.to_module()).iter() {
let resolution = resolution.borrow();
let resolution = resolution.borrow(self);
let Some(binding) = resolution.best_decl() else { continue };

// Report "cannot reexport" errors for exotic cases involving macros 2.0
Expand Down Expand Up @@ -1490,7 +1493,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return None;
} // `use _` is never valid

let resolution = resolution.borrow();
let resolution = resolution.borrow_with_token(self.cm_token_mut());
if let Some(name_binding) = resolution.best_decl() {
match name_binding.kind {
DeclKind::Import { source_decl, .. } => {
Expand Down Expand Up @@ -1800,7 +1803,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
.resolutions(module)
.iter()
.filter_map(|(key, resolution)| {
let res = resolution.borrow();
let res = resolution.borrow(self);
let decl = res.determined_decl()?;
let mut key = *key;
let scope = match key.ident.ctxt.update_unchecked(|ctxt| {
Expand Down Expand Up @@ -1866,7 +1869,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ambig_module_children: &mut LocalDefIdMap<Vec<AmbigModChild>>,
) {
// Since import resolution is finished, globs will not define any more names.
*module.globs.borrow_mut(self) = Vec::new();
*module.globs.borrow_mut(self.cm_token()) = Vec::new();

let Some(def_id) = module.opt_def_id() else { return };

Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
if key.ident.name != assoc_name {
return None;
}
let resolution = resolution.borrow();
let resolution = resolution.borrow_with_token(self.r.cm_token_mut());
let binding = resolution.best_decl()?;
match binding.res() {
Res::Def(DefKind::AssocTy, def_id) => Some(def_id),
Expand Down Expand Up @@ -1164,8 +1164,10 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn lookup_doc_alias_name(&mut self, path: &[Segment], ns: Namespace) -> Option<(DefId, Ident)> {
let find_doc_alias_name = |r: &mut Resolver<'ra, '_>, m: Module<'ra>, item_name: Symbol| {
for resolution in r.resolutions(m).values() {
let Some(did) =
resolution.borrow().best_decl().and_then(|binding| binding.res().opt_def_id())
let Some(did) = resolution
.borrow_with_token(r.cm_token_mut())
.best_decl()
.and_then(|binding| binding.res().opt_def_id())
else {
continue;
};
Expand Down Expand Up @@ -1905,7 +1907,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
.resolutions(module)
.iter()
.filter_map(|(key, resolution)| {
let resolution = resolution.borrow();
let resolution = resolution.borrow_with_token(self.r.cm_token_mut());
resolution.best_decl().map(|binding| binding.res()).and_then(|res| {
if filter_fn(res) {
Some((key.ident.name, resolution.orig_ident_span, res))
Expand Down Expand Up @@ -2766,7 +2768,11 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
.r
.resolutions(*module)
.iter()
.filter_map(|(key, res)| res.borrow().best_decl().map(|binding| (key, binding.res())))
.filter_map(|(key, res)| {
res.borrow_with_token(self.r.cm_token_mut())
.best_decl()
.map(|binding| (key, binding.res()))
})
.filter(|(_, res)| match (kind, res) {
(AssocItemKind::Const(..), Res::Def(DefKind::AssocConst { .. }, _)) => true,
(AssocItemKind::Fn(_), Res::Def(DefKind::AssocFn, _)) => true,
Expand Down
Loading
Loading