resolve: Remove inaccessible_ctor_reexport resolver field

Collect the necessary information during error reporting instead of doing it on a good path from the core name resolution infra
This commit is contained in:
Vadim Petrochenkov
2026-04-15 19:45:53 +03:00
parent 9c2e42418c
commit 19c7df6f3f
3 changed files with 16 additions and 23 deletions
-14
View File
@@ -1087,7 +1087,6 @@ fn resolve_ident_in_module_non_globs_unadjusted<'r>(
orig_ident_span,
binding,
parent_scope,
module,
finalize,
shadowing,
);
@@ -1150,7 +1149,6 @@ fn resolve_ident_in_module_globs_unadjusted<'r>(
orig_ident_span,
binding,
parent_scope,
module,
finalize,
shadowing,
);
@@ -1260,7 +1258,6 @@ fn finalize_module_binding(
orig_ident_span: Span,
binding: Option<Decl<'ra>>,
parent_scope: &ParentScope<'ra>,
module: Module<'ra>,
finalize: Finalize,
shadowing: Shadowing,
) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
@@ -1295,17 +1292,6 @@ fn finalize_module_binding(
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
}
// If we encounter a re-export for a type with private fields, it will not be able to
// be constructed through this re-export. We track that case here to expand later
// privacy errors with appropriate information.
if let Res::Def(_, def_id) = binding.res() {
if let Some(ctor) = self.struct_ctor(def_id)
&& ctor.has_private_fields(module, self)
{
self.inaccessible_ctor_reexport.insert(path_span, binding.span);
}
}
self.record_use(ident, binding, used);
return Ok(binding);
}
+16 -4
View File
@@ -2368,16 +2368,28 @@ fn smart_resolve_context_dependent_help(
return true;
};
// A type is re-exported and has an inaccessible constructor because it has fields
// that are inaccessible from the reexport's scope, extend the diagnostic.
let is_accessible = self.r.is_accessible_from(ctor.vis, self.parent_scope.module);
if let Some(use_span) = self.r.inaccessible_ctor_reexport.get(&span)
&& is_accessible
if is_accessible
&& let mod_path = &path[..path.len() - 1]
&& let PathResult::Module(ModuleOrUniformRoot::Module(import_mod)) =
self.resolve_path(mod_path, Some(TypeNS), None, PathSource::Module)
&& ctor.has_private_fields(import_mod, self.r)
&& let Ok(import_decl) = self.r.cm().maybe_resolve_ident_in_module(
ModuleOrUniformRoot::Module(import_mod),
path.last().unwrap().ident,
TypeNS,
&self.parent_scope,
None,
)
{
err.span_note(
*use_span,
import_decl.span,
"the type is accessed through this re-export, but the type's constructor \
is not visible in this import's scope due to private fields",
);
if is_accessible && !ctor.has_private_fields(self.parent_scope.module, self.r) {
if !ctor.has_private_fields(self.parent_scope.module, self.r) {
err.span_suggestion_verbose(
span,
"the type can be constructed directly, because its fields are \
-5
View File
@@ -1285,11 +1285,6 @@ pub struct Resolver<'ra, 'tcx> {
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),
/// When a type is re-exported that has an inaccessible constructor because it has fields that
/// are inaccessible from the import's scope, we mark that as the type won't be able to be built
/// through the re-export. We use this information to extend the existing diagnostic.
inaccessible_ctor_reexport: FxHashMap<Span, Span> = default::fx_hash_map(),
arenas: &'ra ResolverArenas<'ra>,
dummy_decl: Decl<'ra>,
builtin_type_decls: FxHashMap<Symbol, Decl<'ra>>,