Skip to content

Commit

Permalink
Remove two _ext methods.
Browse files Browse the repository at this point in the history
`resolve_ident_in_module` is a very thin wrapper around
`resolve_ident_in_module_ext`, and `resolve_ident_in_module_unadjusted`
is a very thin wrapper around `resolve_ident_in_module_unadjusted_ext`.
The wrappers make the call sites slightly more concise, but I don't
think that's worth the extra code and indirection.

This commit removes the two wrappers and removes the `_ext` suffixes
from the inner methods.
  • Loading branch information
nnethercote committed Nov 14, 2024
1 parent e7dffee commit d71c06d
Showing 1 changed file with 13 additions and 56 deletions.
69 changes: 13 additions & 56 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ident,
ns,
parent_scope,
false,
finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
ignore_binding,
None,
Expand Down Expand Up @@ -493,7 +494,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
Scope::CrateRoot => {
let root_ident = Ident::new(kw::PathRoot, ident.span);
let root_module = this.resolve_crate_root(root_ident);
let binding = this.resolve_ident_in_module_ext(
let binding = this.resolve_ident_in_module(
ModuleOrUniformRoot::Module(root_module),
ident,
ns,
Expand All @@ -515,7 +516,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
Scope::Module(module, derive_fallback_lint_id) => {
let adjusted_parent_scope = &ParentScope { module, ..*parent_scope };
let binding = this.resolve_ident_in_module_unadjusted_ext(
let binding = this.resolve_ident_in_module_unadjusted(
ModuleOrUniformRoot::Module(module),
ident,
ns,
Expand Down Expand Up @@ -589,6 +590,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ident,
ns,
parent_scope,
false,
None,
ignore_binding,
ignore_import,
Expand Down Expand Up @@ -747,35 +749,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
parent_scope: &ParentScope<'ra>,
ignore_import: Option<Import<'ra>>,
) -> Result<NameBinding<'ra>, Determinacy> {
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, None, ignore_import)
self.resolve_ident_in_module(module, ident, ns, parent_scope, None, None, ignore_import)
.map_err(|(determinacy, _)| determinacy)
}

#[instrument(level = "debug", skip(self))]
pub(crate) fn resolve_ident_in_module(
&mut self,
module: ModuleOrUniformRoot<'ra>,
ident: Ident,
ns: Namespace,
parent_scope: &ParentScope<'ra>,
finalize: Option<Finalize>,
ignore_binding: Option<NameBinding<'ra>>,
ignore_import: Option<Import<'ra>>,
) -> Result<NameBinding<'ra>, Determinacy> {
self.resolve_ident_in_module_ext(
module,
ident,
ns,
parent_scope,
finalize,
ignore_binding,
ignore_import,
)
.map_err(|(determinacy, _)| determinacy)
}

#[instrument(level = "debug", skip(self))]
fn resolve_ident_in_module_ext(
&mut self,
module: ModuleOrUniformRoot<'ra>,
mut ident: Ident,
Expand All @@ -802,7 +781,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// No adjustments
}
}
self.resolve_ident_in_module_unadjusted_ext(
self.resolve_ident_in_module_unadjusted(
module,
ident,
ns,
Expand All @@ -814,34 +793,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
)
}

#[instrument(level = "debug", skip(self))]
fn resolve_ident_in_module_unadjusted(
&mut self,
module: ModuleOrUniformRoot<'ra>,
ident: Ident,
ns: Namespace,
parent_scope: &ParentScope<'ra>,
finalize: Option<Finalize>,
ignore_binding: Option<NameBinding<'ra>>,
ignore_import: Option<Import<'ra>>,
) -> Result<NameBinding<'ra>, Determinacy> {
self.resolve_ident_in_module_unadjusted_ext(
module,
ident,
ns,
parent_scope,
false,
finalize,
ignore_binding,
ignore_import,
)
.map_err(|(determinacy, _)| determinacy)
}

/// Attempts to resolve `ident` in namespaces `ns` of `module`.
/// Invariant: if `finalize` is `Some`, expansion and import resolution must be complete.
#[instrument(level = "debug", skip(self))]
fn resolve_ident_in_module_unadjusted_ext(
fn resolve_ident_in_module_unadjusted(
&mut self,
module: ModuleOrUniformRoot<'ra>,
ident: Ident,
Expand Down Expand Up @@ -1046,13 +1001,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ignore_binding,
ignore_import,
) {
Err(Determined) => continue,
Err((Determined, _)) => continue,
Ok(binding)
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
{
continue;
}
Ok(_) | Err(Undetermined) => return Err((Undetermined, Weak::No)),
Ok(_) | Err((Undetermined, _)) => return Err((Undetermined, Weak::No)),
}
}

Expand Down Expand Up @@ -1121,19 +1076,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ident,
ns,
adjusted_parent_scope,
false,
None,
ignore_binding,
ignore_import,
);

match result {
Err(Determined) => continue,
Err((Determined, _)) => continue,
Ok(binding)
if !self.is_accessible_from(binding.vis, glob_import.parent_scope.module) =>
{
continue;
}
Ok(_) | Err(Undetermined) => return Err((Undetermined, Weak::Yes)),
Ok(_) | Err((Undetermined, _)) => return Err((Undetermined, Weak::Yes)),
}
}

Expand Down Expand Up @@ -1564,6 +1520,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ignore_binding,
ignore_import,
)
.map_err(|(determinacy, _)| determinacy)
} else if let Some(ribs) = ribs
&& let Some(TypeNS | ValueNS) = opt_ns
{
Expand Down

0 comments on commit d71c06d

Please sign in to comment.