resolve: Remove struct_field_visibilities_untracked
This commit is contained in:
parent
901f1c9c62
commit
c05b7bd7d0
5 changed files with 37 additions and 50 deletions
|
@ -789,7 +789,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
|
||||
self.r
|
||||
.struct_constructors
|
||||
.insert(def_id, (ctor_res, ctor_vis.to_def_id(), ret_fields));
|
||||
.insert(local_def_id, (ctor_res, ctor_vis.to_def_id(), ret_fields));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1006,19 +1006,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
}
|
||||
// Record some extra data for better diagnostics.
|
||||
match res {
|
||||
Res::Def(DefKind::Struct, def_id) => {
|
||||
let ctor = self.r.cstore().ctor_untracked(def_id);
|
||||
if let Some((ctor_kind, ctor_def_id)) = ctor {
|
||||
let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
|
||||
let ctor_vis = self.r.tcx.visibility(ctor_def_id);
|
||||
let field_visibilities =
|
||||
self.r.cstore().struct_field_visibilities_untracked(def_id).collect();
|
||||
self.r
|
||||
.struct_constructors
|
||||
.insert(def_id, (ctor_res, ctor_vis, field_visibilities));
|
||||
}
|
||||
self.insert_field_names_extern(def_id)
|
||||
}
|
||||
Res::Def(DefKind::Struct, def_id) => self.insert_field_names_extern(def_id),
|
||||
Res::Def(DefKind::Union, def_id) => self.insert_field_names_extern(def_id),
|
||||
Res::Def(DefKind::AssocFn, def_id) => {
|
||||
if self.r.cstore().fn_has_self_parameter_untracked(def_id, self.r.tcx.sess) {
|
||||
|
|
|
@ -1408,19 +1408,38 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
self.suggest_using_enum_variant(err, source, def_id, span);
|
||||
}
|
||||
(Res::Def(DefKind::Struct, def_id), source) if ns == ValueNS => {
|
||||
let (ctor_def, ctor_vis, fields) =
|
||||
if let Some(struct_ctor) = self.r.struct_constructors.get(&def_id).cloned() {
|
||||
if let PathSource::Expr(Some(parent)) = source {
|
||||
if let ExprKind::Field(..) | ExprKind::MethodCall(..) = parent.kind {
|
||||
bad_struct_syntax_suggestion(def_id);
|
||||
return true;
|
||||
}
|
||||
let struct_ctor = match def_id.as_local() {
|
||||
Some(def_id) => self.r.struct_constructors.get(&def_id).cloned(),
|
||||
None => {
|
||||
let ctor = self.r.cstore().ctor_untracked(def_id);
|
||||
ctor.map(|(ctor_kind, ctor_def_id)| {
|
||||
let ctor_res =
|
||||
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
|
||||
let ctor_vis = self.r.tcx.visibility(ctor_def_id);
|
||||
let field_visibilities = self
|
||||
.r
|
||||
.tcx
|
||||
.associated_item_def_ids(def_id)
|
||||
.iter()
|
||||
.map(|field_id| self.r.tcx.visibility(field_id))
|
||||
.collect();
|
||||
(ctor_res, ctor_vis, field_visibilities)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
let (ctor_def, ctor_vis, fields) = if let Some(struct_ctor) = struct_ctor {
|
||||
if let PathSource::Expr(Some(parent)) = source {
|
||||
if let ExprKind::Field(..) | ExprKind::MethodCall(..) = parent.kind {
|
||||
bad_struct_syntax_suggestion(def_id);
|
||||
return true;
|
||||
}
|
||||
struct_ctor
|
||||
} else {
|
||||
bad_struct_syntax_suggestion(def_id);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
struct_ctor
|
||||
} else {
|
||||
bad_struct_syntax_suggestion(def_id);
|
||||
return true;
|
||||
};
|
||||
|
||||
let is_accessible = self.r.is_accessible_from(ctor_vis, self.parent_scope.module);
|
||||
if !is_expected(ctor_def) || is_accessible {
|
||||
|
|
|
@ -35,7 +35,7 @@ use rustc_errors::{
|
|||
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_hir::def::Namespace::{self, *};
|
||||
use rustc_hir::def::{self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, PartialRes, PerNS};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::DefPathData;
|
||||
use rustc_hir::TraitCandidate;
|
||||
|
@ -1009,7 +1009,7 @@ pub struct Resolver<'a, 'tcx> {
|
|||
/// Table for mapping struct IDs into struct constructor IDs,
|
||||
/// it's not used during normal resolution, only for better error reporting.
|
||||
/// Also includes of list of each fields visibility
|
||||
struct_constructors: DefIdMap<(Res, ty::Visibility<DefId>, Vec<ty::Visibility<DefId>>)>,
|
||||
struct_constructors: LocalDefIdMap<(Res, ty::Visibility<DefId>, Vec<ty::Visibility<DefId>>)>,
|
||||
|
||||
/// Features enabled for this crate.
|
||||
active_features: FxHashSet<Symbol>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue