Skip to content
Merged
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
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(self).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
4 changes: 2 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,7 @@ 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(self.r).best_decl() else {
continue;
};
self.update_decl_chain(decl, ParentId::Def(module_id));
Expand Down Expand Up @@ -310,7 +310,7 @@ 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(self.r).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
18 changes: 13 additions & 5 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

let mut imports_to_resolve = mem::take(&mut self.indeterminate_imports);

self.assert_speculative = true;
// SAFETY: This is a "top-level" function used by the macro expansion code, unless some
// weird thing is done, all `tracked` borrows done in the previous call of
// `resolve_imports` are dropped when that call ended.
unsafe { self.speculative_flag.set(true) };
rustc_data_structures::sync::par_for_each_slice(
&mut imports_to_resolve,
|(import, resolution, indeterminate_count)| {
(*resolution, *indeterminate_count) = self.resolve_import(*import);
},
);
self.assert_speculative = false;
// SAFETY: All `untracked` borrows are dropped after the `par_for_each_slice` call,
// as they cannot escape since they are tied to the `CmRefCell` they borrowed from.
Comment thread
petrochenkov marked this conversation as resolved.
//
// Note: Some `CmRefCell`s are arena allocated and thus have the `'ra` lifetime,
// allowing these borrows to escape, but that does not and should not happen.
unsafe { self.speculative_flag.set(false) };

self.write_import_resolutions(&imports_to_resolve);

Expand Down Expand Up @@ -1003,7 +1011,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 +1498,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return None;
} // `use _` is never valid

let resolution = resolution.borrow();
let resolution = resolution.borrow(self);
if let Some(name_binding) = resolution.best_decl() {
match name_binding.kind {
DeclKind::Import { source_decl, .. } => {
Expand Down Expand Up @@ -1800,7 +1808,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
10 changes: 6 additions & 4 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(self.r);
let binding = resolution.best_decl()?;
match binding.res() {
Res::Def(DefKind::AssocTy, def_id) => Some(def_id),
Expand Down Expand Up @@ -1165,7 +1165,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
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())
resolution.borrow(r).best_decl().and_then(|binding| binding.res().opt_def_id())
else {
continue;
};
Expand Down Expand Up @@ -1905,7 +1905,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
.resolutions(module)
.iter()
.filter_map(|(key, resolution)| {
let resolution = resolution.borrow();
let resolution = resolution.borrow(self.r);
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 +2766,9 @@ 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(self.r).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