1
Fork 0

Suggest making private tuple struct field public

Fix #52144.
This commit is contained in:
Esteban Küber 2023-01-08 01:15:28 +00:00
parent b22c152958
commit ad13d9fbbe
8 changed files with 49 additions and 6 deletions

View file

@ -331,7 +331,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
.iter()
.map(|field| respan(field.span, field.ident.map_or(kw::Empty, |ident| ident.name)))
.collect();
let field_vis = vdata.fields().iter().map(|field| field.vis.span).collect();
self.r.field_names.insert(def_id, field_names);
self.r.field_visibility_spans.insert(def_id, field_vis);
}
fn insert_field_names_extern(&mut self, def_id: DefId) {

View file

@ -1451,6 +1451,26 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
.collect();
if non_visible_spans.len() > 0 {
if let Some(visibility_spans) = self.r.field_visibility_spans.get(&def_id) {
err.multipart_suggestion_verbose(
&format!(
"consider making the field{} publicly accessible",
pluralize!(visibility_spans.len())
),
visibility_spans
.iter()
.map(|span| {
(
*span,
if span.lo() == span.hi() { "pub " } else { "pub" }
.to_string(),
)
})
.collect(),
Applicability::MaybeIncorrect,
);
}
let mut m: MultiSpan = non_visible_spans.clone().into();
non_visible_spans
.into_iter()

View file

@ -881,6 +881,10 @@ pub struct Resolver<'a> {
/// Used for hints during error reporting.
field_names: FxHashMap<DefId, Vec<Spanned<Symbol>>>,
/// Span of the privacy modifier in fields of an item `DefId` accessible with dot syntax.
/// Used for hints during error reporting.
field_visibility_spans: FxHashMap<DefId, Vec<Span>>,
/// All imports known to succeed or fail.
determined_imports: Vec<&'a Import<'a>>,
@ -1268,6 +1272,7 @@ impl<'a> Resolver<'a> {
has_self: FxHashSet::default(),
field_names: FxHashMap::default(),
field_visibility_spans: FxHashMap::default(),
determined_imports: Vec::new(),
indeterminate_imports: Vec::new(),