Skip to content

[WIP] Resolve: refactor define into define_local and define_extern #143884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ pub trait ResolverExpand {
fn next_node_id(&mut self) -> NodeId;
fn invocation_parent(&self, id: LocalExpnId) -> LocalDefId;

fn resolve_dollar_crates(&mut self);
fn resolve_dollar_crates(&self);
fn visit_ast_fragment_with_placeholders(
&mut self,
expn_id: LocalExpnId,
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ impl DefKind {
}
}

/// This is a "module" in name resolution sense.
#[inline]
pub fn is_module_like(self) -> bool {
matches!(self, DefKind::Mod | DefKind::Enum | DefKind::Trait)
}

#[inline]
pub fn is_fn_like(self) -> bool {
matches!(
Expand Down Expand Up @@ -720,6 +726,15 @@ impl<Id> Res<Id> {
}
}

/// If this is a "module" in name resolution sense, return its `DefId`.
#[inline]
pub fn module_like_def_id(&self) -> Option<DefId> {
match self {
Res::Def(def_kind, def_id) if def_kind.is_module_like() => Some(*def_id),
_ => None,
}
}

/// A human readable name for the res kind ("function", "module", etc.).
pub fn descr(&self) -> &'static str {
match *self {
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::mem;
use std::sync::Arc;

use rustc_attr_data_structures::Deprecation;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
use rustc_middle::arena::ArenaAllocatable;
Expand Down Expand Up @@ -510,10 +510,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
}
Entry::Vacant(entry) => {
entry.insert(parent);
if matches!(
child.res,
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, _)
) {
if child.res.module_like_def_id().is_some() {
bfs_queue.push_back(def_id);
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3454,9 +3454,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
collect_fn(&child.ident, ns, def_id);
}

if matches!(defkind, DefKind::Mod | DefKind::Enum | DefKind::Trait)
&& seen_defs.insert(def_id)
{
if defkind.is_module_like() && seen_defs.insert(def_id) {
queue.push(def_id);
}
}
Expand Down
Loading
Loading